diff --git a/.ci/azure/mac.yml b/.ci/azure/mac.yml deleted file mode 100644 index f1a20fb49b3055..00000000000000 --- a/.ci/azure/mac.yml +++ /dev/null @@ -1,229 +0,0 @@ -trigger: - branches: - include: - - master - - 'releases/*' - paths: - exclude: - - '*/docs/*' - - 'docs/*' - - '*/*.md' - - '*.md' - - '*/layer_tests_summary/*' - - '*/conformance/*' - - 'tests/layer_tests/*' - -pr: - drafts: 'false' - branches: - include: - - 'master' - - 'releases/*' - paths: - exclude: - - '*/docs/*' - - 'docs/*' - - '*/*.md' - - '*.md' - - '*/layer_tests_summary/*' - - '*/conformance/*' - - 'tests/layer_tests/*' - -resources: - repositories: - - repository: openvino_contrib - type: github - endpoint: openvinotoolkit - name: openvinotoolkit/openvino_contrib - ref: master - -variables: - - group: github - -jobs: -- job: Mac - # About 250% of total time (perfomace of Mac hosts is unstable, 360 is max) - timeoutInMinutes: '360' - - pool: - vmImage: 'macOS-11' - - variables: - system.debug: true - VSTS_HTTP_RETRY: 5 - VSTS_HTTP_TIMEOUT: 200 - BUILD_TYPE: Release - REPO_DIR: $(Build.Repository.LocalPath) - OPENVINO_CONTRIB_REPO_DIR: $(REPO_DIR)/../openvino_contrib - WORK_DIR: $(Pipeline.Workspace)/_w - BUILD_DIR: $(WORK_DIR)/build - INSTALL_DIR: $(WORK_DIR)/install_pkg - INSTALL_TEST_DIR: $(INSTALL_DIR)/tests - SETUPVARS: . $(INSTALL_DIR)/setupvars.sh - TMP_DIR: /tmp - CCACHE_DIR: $(WORK_DIR)/ccache/mac - - steps: - - task: UsePythonVersion@0 - inputs: - versionSpec: '3.11.2' - addToPath: true - architecture: 'x64' - githubToken: $(auth_token) - displayName: Setup Python 3.11 - name: setupPython - - - script: | - whoami - uname -a - echo Python3 info ; which python3 ; python3 --version - echo Python info ; which python ; python --version - echo Java info ; which java ; java -version - echo gcc info ; which gcc ; gcc --version - echo cmake info ; which cmake ; cmake --version - xcrun --sdk macosx --show-sdk-version - env - sysctl -a - displayName: 'System info' - - - script: | - set -e - rm -rf $(WORK_DIR) ; mkdir $(WORK_DIR) - rm -rf $(BUILD_DIR) ; mkdir $(BUILD_DIR) - displayName: 'Make dir' - - - checkout: self - clean: 'true' - submodules: 'true' - path: openvino - - - checkout: openvino_contrib - clean: 'true' - submodules: 'true' - path: openvino_contrib - - - script: | - set -e - brew install cython automake - python3 -m pip install -r $(REPO_DIR)/src/frontends/onnx/tests/requirements.txt - # Speed up build - brew install ninja ccache - displayName: 'Install dependencies' - - - script: | - export PATH="/usr/local/opt/cython/bin:$PATH" - cmake \ - -G Ninja \ - -DENABLE_CPPLINT=OFF \ - -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \ - -DCMAKE_COMPILE_WARNING_AS_ERROR=ON \ - -DENABLE_PYTHON=ON \ - -DENABLE_STRICT_DEPENDENCIES=OFF \ - -DOPENVINO_EXTRA_MODULES=$(OPENVINO_CONTRIB_REPO_DIR)/modules \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DBUILD_nvidia_plugin=OFF \ - -S $(REPO_DIR) \ - -B $(BUILD_DIR) - displayName: 'CMake OpenVINO' - - - script: ls -alR $(REPO_DIR)/temp/ - displayName: 'List temp SDKs' - - - task: Cache@2 - inputs: - key: 'ccache | "$(Agent.OS)"' - path: $(CCACHE_DIR) - restoreKeys: | - ccache | "$(Agent.OS)" - displayName: Cache - enabled: 'false' - - - script: ccache --zero-stats --max-size=10G --show-config - displayName: 'Clean ccache stats' - - - script: cmake --build $(BUILD_DIR) --parallel --config $(BUILD_TYPE) - env: - CCACHE_DIR: $(CCACHE_DIR) - CCACHE_TEMPDIR: $(TMP_DIR)/ccache - CCACHE_BASEDIR: $(Pipeline.Workspace) - CCACHE_MAXSIZE: 10G - displayName: 'Build Mac' - - - script: ccache --show-stats - displayName: 'Show ccache stats' - - - script: ls -alR $(REPO_DIR)/bin/ - displayName: 'List bin files' - - - script: cmake -DCMAKE_INSTALL_PREFIX=$(INSTALL_DIR) -P $(BUILD_DIR)/cmake_install.cmake - displayName: 'Install' - - - script: ls -alR $(INSTALL_DIR) - displayName: 'List install files' - - - script: cmake -DCMAKE_INSTALL_PREFIX=$(INSTALL_DIR) -DCOMPONENT=tests -P $(BUILD_DIR)/cmake_install.cmake - displayName: 'Install tests' - - - script: ls -alR $(INSTALL_DIR) - displayName: 'List install files' - - - script: $(SETUPVARS) && $(INSTALL_TEST_DIR)/ov_core_unit_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU* --gtest_output=xml:$(INSTALL_TEST_DIR)/TEST-OVCoreUT.xml - displayName: 'OV Core UT' - enabled: 'false' - - - script: $(SETUPVARS) && $(INSTALL_TEST_DIR)/ov_proxy_plugin_tests --gtest_print_time=1 --gtest_output=xml:$(INSTALL_TEST_DIR)/TEST-OVProxyTests.xml - displayName: 'OV Proxy Plugin Tests' - enabled: 'false' - - - script: $(SETUPVARS) && $(INSTALL_TEST_DIR)/ov_hetero_unit_tests --gtest_print_time=1 --gtest_output=xml:$(INSTALL_TEST_DIR)/TEST-OVHeteroUnitTests.xml - displayName: 'OV Hetero Unit Tests' - enabled: 'false' - - - script: $(SETUPVARS) && $(INSTALL_TEST_DIR)/ov_hetero_func_tests --gtest_print_time=1 --gtest_output=xml:$(INSTALL_TEST_DIR)/TEST-OVHeteroFuncTests.xml - displayName: 'OV Hetero Func Tests' - enabled: 'false' - - - script: $(SETUPVARS) && $(INSTALL_TEST_DIR)/ov_ir_frontend_tests --gtest_print_time=1 --gtest_output=xml:$(INSTALL_TEST_DIR)/TEST-IRFrontend.xml - displayName: 'IR Frontend Tests' - enabled: 'false' - - - script: $(SETUPVARS) && $(INSTALL_TEST_DIR)/ov_onnx_frontend_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU*--gtest_output=xml:$(INSTALL_TEST_DIR)/TEST-ONNXFrontend.xml - displayName: 'ONNX Frontend Tests' - enabled: 'false' - - - script: $(SETUPVARS) && $(INSTALL_TEST_DIR)/ov_cpu_unit_tests --gtest_output=xml:$(INSTALL_TEST_DIR)/TEST-ov_cpu_unit_tests.xml - displayName: 'Intel CPU Unit Tests' - enabled: 'false' - - - script: $(SETUPVARS) && $(INSTALL_TEST_DIR)/ov_auto_unit_tests --gtest_output=xml:$(INSTALL_TEST_DIR)/TEST-ov_auto_unit_tests.xml - displayName: 'AUTO UT' - enabled: 'false' - - - script: $(SETUPVARS) && $(INSTALL_TEST_DIR)/ov_cpu_func_tests --gtest_filter=*smoke* --gtest_print_time=1 --gtest_output=xml:$(INSTALL_TEST_DIR)/TEST-ov_cpu_func_tests.xml - displayName: 'CPU FuncTests' - enabled: 'false' - - - script: | - $(SETUPVARS) && $(INSTALL_TEST_DIR)/InferenceEngineCAPITests --gtest_output=xml:$(INSTALL_TEST_DIR)/TEST-InferenceEngineCAPITests.xml - displayName: 'IE CAPITests' - enabled: 'false' - - - script: | - $(SETUPVARS) && $(INSTALL_TEST_DIR)/ov_capi_test --gtest_output=xml:$(INSTALL_TEST_DIR)/TEST-ov_capi_test.xml - displayName: 'IE CAPITests' - enabled: 'false' - - - task: PublishTestResults@2 - condition: always() - inputs: - testResultsFormat: 'JUnit' # Options: JUnit, NUnit, VSTest, xUnit, cTest - testResultsFiles: '**/TEST-*.xml' - #searchFolder: '$(BUILD_DIR)' - mergeTestResults: false # Optional - #failTaskOnFailedTests: false # Optional - #testRunTitle: 'Pre/Post-Commit' # Optional - buildPlatform: 'x64' # Optional - buildConfiguration: 'Mac' # Optional - #publishRunAttachments: true # Optional diff --git a/.ci/azure/windows.yml b/.ci/azure/windows.yml index a36238fca4a874..9a6aba6a88971e 100644 --- a/.ci/azure/windows.yml +++ b/.ci/azure/windows.yml @@ -66,44 +66,23 @@ jobs: INSTALL_DIR: $(WORK_DIR)\install_pkg INSTALL_TEST_DIR: $(INSTALL_DIR)\tests SETUPVARS: $(INSTALL_DIR)\setupvars.bat - PYTHON_DIR: C:\hostedtoolcache\windows\Python\3.11.2\x64 CMAKE_VERSION: 3.24.0 CMAKE_CMD: $(WORK_DIR)\cmake-$(CMAKE_VERSION)-windows-x86_64\cmake-$(CMAKE_VERSION)-windows-x86_64\bin\cmake.exe OV_CMAKE_TOOLCHAIN_FILE: $(REPO_DIR)\cmake\toolchains\mt.runtime.win32.toolchain.cmake - PYTHON_VENV_DIR: $(WORK_DIR)\.venv - + PYTHON_EXE: C:\hostedtoolcache\windows\Python\3.8.2\x64\python.exe steps: - script: | rd /Q /S $(WORK_DIR) & mkdir $(WORK_DIR) rd /Q /S $(BUILD_DIR) & mkdir $(BUILD_DIR) - rd /Q /S $(WORK_DIR) & mkdir C:\hostedtoolcache\windows\Python\3.11.2 - rd /Q /S $(BUILD_DIR) & mkdir C:\hostedtoolcache\windows\Python\3.11.2\x64 rd /Q /S $(BUILD_SAMPLES_DIR) & mkdir $(BUILD_SAMPLES_DIR) rd /Q /S $(BUILD_SAMPLES_TESTS_DIR) & mkdir $(BUILD_SAMPLES_TESTS_DIR) displayName: 'Make dir' - - script: curl -O https://www.python.org/ftp/python/3.11.2/python-3.11.2-amd64.exe - displayName: 'Download Python' - workingDirectory: $(WORK_DIR) - - - script: | - python-3.11.2-amd64.exe /passive InstallAllUsers=0 Include_launcher=0 TargetDir=C:\hostedtoolcache\windows\Python\3.11.2\x64 && ^ - cp C:\hostedtoolcache\windows\Python\3.8.2\x64.complete C:\hostedtoolcache\windows\Python\3.11.2\x64.complete - displayName: 'Install Python' - workingDirectory: $(WORK_DIR) - - - task: UsePythonVersion@0 - displayName: 'Use Python' - inputs: - versionSpec: '3.11.2' - disableDownloadFromRegistry: true - - script: | powershell -command "Invoke-RestMethod -Headers @{\"Metadata\"=\"true\"} -Method GET -Uri http://169.254.169.254/metadata/instance/compute?api-version=2019-06-01 | format-custom" - tree C:\hostedtoolcache\windows\Python - where python - python --version + where $(PYTHON_EXE) + $(PYTHON_EXE) --version where java java -version wmic computersystem get TotalPhysicalMemory @@ -124,20 +103,20 @@ jobs: path: openvino_contrib - script: | - python -m pip install --upgrade pip + $(PYTHON_EXE) -m pip install --upgrade pip rem For running Python API tests - python -m pip install -r $(REPO_DIR)\src\bindings\python\src\compatibility\openvino\requirements-dev.txt - python -m pip install -r $(REPO_DIR)\src\bindings\python\wheel\requirements-dev.txt - python -m pip install -r $(REPO_DIR)\src\bindings\python\requirements.txt + $(PYTHON_EXE) -m pip install -r $(REPO_DIR)\src\bindings\python\src\compatibility\openvino\requirements-dev.txt + $(PYTHON_EXE) -m pip install -r $(REPO_DIR)\src\bindings\python\wheel\requirements-dev.txt + $(PYTHON_EXE) -m pip install -r $(REPO_DIR)\src\bindings\python\requirements.txt rem For running Paddle frontend unit tests - python -m pip install -r $(REPO_DIR)\src\frontends\paddle\tests\requirements.txt + $(PYTHON_EXE) -m pip install -r $(REPO_DIR)\src\frontends\paddle\tests\requirements.txt rem For running ONNX frontend unit tests - python -m pip install -r $(REPO_DIR)\src\frontends\onnx\tests\requirements.txt + $(PYTHON_EXE) -m pip install -r $(REPO_DIR)\src\frontends\onnx\tests\requirements.txt rem For running TensorFlow frontend unit tests - python -m pip install -r $(REPO_DIR)\src\frontends\tensorflow\tests\requirements.txt + $(PYTHON_EXE) -m pip install -r $(REPO_DIR)\src\frontends\tensorflow\tests\requirements.txt rem For MO unit tests - python -m pip install -r $(REPO_DIR)\tools\mo\requirements.txt - python -m pip install -r $(REPO_DIR)\tools\mo\requirements_dev.txt + $(PYTHON_EXE) -m pip install -r $(REPO_DIR)\tools\mo\requirements.txt + $(PYTHON_EXE) -m pip install -r $(REPO_DIR)\tools\mo\requirements_dev.txt rem Speed up build powershell -command "Invoke-WebRequest https://github.com/Kitware/CMake/releases/download/v$(CMAKE_VERSION)/cmake-$(CMAKE_VERSION)-windows-x86_64.zip -OutFile cmake-$(CMAKE_VERSION)-windows-x86_64.zip" powershell -command "Expand-Archive -Force cmake-$(CMAKE_VERSION)-windows-x86_64.zip" @@ -162,10 +141,10 @@ jobs: -DENABLE_TESTS=ON ^ -DCMAKE_COMPILE_WARNING_AS_ERROR=ON ^ -DENABLE_STRICT_DEPENDENCIES=OFF ^ + -DPython3_EXECUTABLE=$(PYTHON_EXE) ^ -DENABLE_PYTHON=ON ^ -DBUILD_nvidia_plugin=OFF ^ -DCUSTOM_OPERATIONS="calculate_grid;complex_mul;fft;grid_sample;sparse_conv;sparse_conv_transpose" ^ - -DPython3_EXECUTABLE="C:\hostedtoolcache\windows\Python\3.11.2\x64\python.exe" ^ -DOPENVINO_EXTRA_MODULES=$(OPENVINO_CONTRIB_REPO_DIR)\modules ^ -DCMAKE_C_COMPILER:PATH="$(MSVC_COMPILER_PATH)" ^ -DCMAKE_CXX_COMPILER:PATH="$(MSVC_COMPILER_PATH)" ^ @@ -190,7 +169,7 @@ jobs: - script: dir $(INSTALL_DIR) /s displayName: 'List install files' - - script: python -m pip install openvino-dev --find-links=$(INSTALL_DIR)\tools + - script: $(PYTHON_EXE) -m pip install openvino-dev --find-links=$(INSTALL_DIR)\tools displayName: 'Install Wheels' - script: | @@ -215,12 +194,12 @@ jobs: if not exist %USERPROFILE%\Documents\Intel\OpenVINO\openvino_c_samples_build\ exit 1 displayName: 'Build c samples' - - script: python -m pip install -r $(INSTALL_TEST_DIR)\smoke_tests\requirements.txt + - script: $(PYTHON_EXE) -m pip install -r $(INSTALL_TEST_DIR)\smoke_tests\requirements.txt displayName: 'Install dependencies for samples smoke tests' - script: | call $(SETUPVARS) && ^ - python -m pytest $(INSTALL_DIR)\tests\smoke_tests\ --env_conf $(INSTALL_TEST_DIR)\smoke_tests\env_config.yml -s --junitxml=$(INSTALL_TEST_DIR)/TEST-SamplesSmokeTests.xml + $(PYTHON_EXE) -m pytest $(INSTALL_DIR)\tests\smoke_tests\ --env_conf $(INSTALL_TEST_DIR)\smoke_tests\env_config.yml -s --junitxml=$(INSTALL_TEST_DIR)/TEST-SamplesSmokeTests.xml env: IE_APP_PATH: $(INSTALL_DIR)\samples_bin IE_APP_PYTHON_PATH: $(INSTALL_DIR)\samples\python\ diff --git a/.ci/azure/windows_conditional_compilation.yml b/.ci/azure/windows_conditional_compilation.yml index 70c7ebfff239e6..3d2df492194950 100644 --- a/.ci/azure/windows_conditional_compilation.yml +++ b/.ci/azure/windows_conditional_compilation.yml @@ -64,15 +64,6 @@ jobs: SETUPVARS: $(INSTALL_DIR)\setupvars.bat steps: - - task: UsePythonVersion@0 - inputs: - versionSpec: '3.11.2' - addToPath: true - architecture: 'x64' - githubToken: $(auth_token) - displayName: Setup Python 3.11 - name: setupPython - - script: | powershell -command "Invoke-RestMethod -Headers @{\"Metadata\"=\"true\"} -Method GET -Uri http://169.254.169.254/metadata/instance/compute?api-version=2019-06-01 | format-custom" where python diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 3f2178a1c681e5..3727c4d88f6e8b 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -94,6 +94,7 @@ /tests/layer_tests/tensorflow_tests @openvinotoolkit/openvino-tf-frontend-maintainers /tests/layer_tests/jax_tests @openvinotoolkit/openvino-tf-frontend-maintainers /tests/model_hub_tests @openvinotoolkit/openvino-tf-frontend-maintainers +/tests/model_hub_tests/torch_tests @openvinotoolkit/openvino-pytorch-frontend-maintainers # Tools: /tools/ @openvinotoolkit/openvino-tools-maintainers diff --git a/.github/workflows/build_doc.yml b/.github/workflows/build_doc.yml index b7e688d55f8c4a..fca75e99dc4109 100644 --- a/.github/workflows/build_doc.yml +++ b/.github/workflows/build_doc.yml @@ -17,8 +17,8 @@ jobs: - name: Clone OpenVINO uses: actions/checkout@v4 with: - submodules: true - lfs: true + submodules: 'true' + lfs: 'true' - name: Install apt-get dependencies uses: awalsh128/cache-apt-pkgs-action@v1.3.0 diff --git a/.github/workflows/code_style.yml b/.github/workflows/code_style.yml index 0500ba86b12412..dc584a9799079c 100644 --- a/.github/workflows/code_style.yml +++ b/.github/workflows/code_style.yml @@ -60,9 +60,9 @@ jobs: run: cmake -B build - name: Shellcheck cmake target - run: cmake --build build --target ie_shellcheck -j8 + run: cmake --build build --target ov_shellcheck -j8 - # always provide suggestions even for skipped scripts in ie_shellcheck tagret + # always provide suggestions even for skipped scripts in ov_shellcheck tagret - name: ShellCheck action if: always() uses: reviewdog/action-shellcheck@v1 diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index f7d225d075833a..639eca9957928d 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -1,21 +1,25 @@ -name: Tests on Linux (Ubuntu 20.04, Python 3.11) +name: Linux (Ubuntu 20.04, Python 3.11) on: schedule: # at 00:00 on Wednesday and Saturday - cron: '0 0 * * 3,6' workflow_dispatch: pull_request: - paths-ignore: - - '**/docs/**' - - 'docs/**' - - '**/**.md' - - '**.md' + paths: + - '**' + - '!**/docs/**' + - '!docs/**' + - 'docs/snippets/**' + - '!**/**.md' + - '!**.md' push: - paths-ignore: - - '**/docs/**' - - 'docs/**' - - '**/**.md' - - '**.md' + paths: + - '**' + - '!docs/**' + - '!**/docs/**' + - 'docs/snippets/**' + - '!**/**.md' + - '!**.md' branches: - master - 'releases/**' @@ -50,8 +54,8 @@ jobs: OPENVINO_CONTRIB_REPO: /__w/openvino/openvino/openvino_contrib INSTALL_DIR: /__w/openvino/openvino/openvino_install INSTALL_TEST_DIR: /__w/openvino/openvino/tests_install + DEVELOPER_PACKAGE_DIR: /__w/openvino/openvino/developer_package_install BUILD_DIR: /__w/openvino/openvino/openvino_build - OPENVINO_CONTRIB_BUILD_DIR: /__w/openvino/openvino/openvino_contrib_build CCACHE_DIR: /mount/caches/ccache/ubuntu20_x86_64_Release CCACHE_TEMPDIR: /__w/openvino/openvino/ccache_temp CCACHE_MAXSIZE: 50G @@ -75,6 +79,7 @@ jobs: repository: 'openvinotoolkit/openvino_contrib' path: ${{ env.OPENVINO_CONTRIB_REPO }} submodules: 'true' + ref: 'master' # # Dependencies @@ -151,6 +156,7 @@ jobs: run: | cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -P ${BUILD_DIR}/cmake_install.cmake cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_TEST_DIR} -DCOMPONENT=tests -P ${BUILD_DIR}/cmake_install.cmake + cmake -DCMAKE_INSTALL_PREFIX=${DEVELOPER_PACKAGE_DIR} -DCOMPONENT=developer_package -P ${BUILD_DIR}/cmake_install.cmake cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DCOMPONENT=python_wheels -P ${BUILD_DIR}/cmake_install.cmake - name: Pack Artifacts @@ -165,6 +171,10 @@ jobs: tar -czvf ${BUILD_DIR}/openvino_package.tar.gz * popd + pushd ${DEVELOPER_PACKAGE_DIR} + tar -czvf ${BUILD_DIR}/openvino_developer_package.tar.gz * + popd + pushd ${INSTALL_TEST_DIR} tar -czvf ${BUILD_DIR}/openvino_tests.tar.gz * popd @@ -204,6 +214,14 @@ jobs: path: ${{ env.BUILD_DIR }}/openvino_package.tar.gz if-no-files-found: 'error' + - name: Upload openvino developer package + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: + name: openvino_developer_package + path: ${{ env.BUILD_DIR }}/openvino_developer_package.tar.gz + if-no-files-found: 'error' + - name: Upload openvino debian packages if: ${{ always() }} uses: actions/upload-artifact@v3 @@ -304,10 +322,10 @@ jobs: - name: Extract OpenVINO packages run: | pushd ${INSTALL_DIR} - tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} && rm openvino_package.tar.gz || exit 1 + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} popd pushd ${INSTALL_TEST_DIR} - tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} && rm openvino_tests.tar.gz || exit 1 + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} popd - name: Install 'actions/setup-python@v4' dependencies @@ -369,7 +387,7 @@ jobs: uses: actions/upload-artifact@v3 if: ${{ !cancelled() }} with: - name: test-results-cpp + name: test-results-samples path: ${{ env.INSTALL_TEST_DIR }}/TEST*.xml if-no-files-found: 'error' @@ -494,7 +512,6 @@ jobs: ONNX_RUNTIME_BUILD_DIR: /__w/openvino/openvino/onnxruntime/build steps: - - name: Fetch install_build_dependencies.sh uses: actions/checkout@v4 with: @@ -502,6 +519,7 @@ jobs: install_build_dependencies.sh sparse-checkout-cone-mode: false path: ${{ env.OPENVINO_REPO }} + ref: 'master' - name: Install git run: | @@ -525,7 +543,7 @@ jobs: - name: Extract OpenVINO package run: | pushd ${INSTALL_DIR} - tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} && rm openvino_package.tar.gz + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} popd - name: Install OpenVINO dependencies @@ -625,10 +643,10 @@ jobs: - name: Extract OpenVINO packages run: | pushd ${INSTALL_DIR} - tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} && rm openvino_package.tar.gz || exit 1 + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} popd pushd ${INSTALL_TEST_DIR} - tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} && rm openvino_tests.tar.gz || exit 1 + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} popd - name: Install OpenVINO dependencies @@ -742,6 +760,18 @@ jobs: ${INSTALL_TEST_DIR}/ov_cpu_unit_tests --gtest_print_time=1 \ --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-CPUUnitTests.xml + - name: SubgraphsDumper tests + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/subgraphsDumperTests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-SubgraphsDumperTests.xml + + - name: Template OpImpl tests + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/conformanceTests --gtest_print_time=1 --device=TEMPLATE --gtest_filter=*OpImpl*\ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-OpImplTests.xml + - name: AUTO unit tests run: | source ${INSTALL_DIR}/setupvars.sh @@ -871,15 +901,23 @@ jobs: - name: Extract OpenVINO packages run: | pushd ${INSTALL_DIR} - tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} && rm openvino_package.tar.gz || exit 1 + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} popd pushd ${INSTALL_TEST_DIR} - tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} && rm openvino_tests.tar.gz || exit 1 + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} popd - name: Install OpenVINO Python wheels - run: python3 -m pip install openvino-dev[mxnet,caffe,kaldi,onnx,tensorflow2] --find-links=${INSTALL_DIR}/tools + run: | + # Install the core OV wheel + python3 -m pip install ${INSTALL_DIR}/tools/openvino-*.whl + + # Find and install OV dev wheel + pushd ${INSTALL_DIR}/tools + ov_dev_wheel_name=$(find . -name 'openvino_dev*.whl') + python3 -m pip install $ov_dev_wheel_name[mxnet,caffe,kaldi,onnx,tensorflow2,pytorch] + popd # # Tests @@ -925,6 +963,16 @@ jobs: TEST_DEVICE: CPU TEST_PRECISION: FP16 + - name: ONNX Layer Tests + run: | + python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt + # requires 'unit_tests' from 'tools/mo' + export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:$PYTHONPATH + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/onnx_tests -m "not launch_only_if_manually_specified and precommit" --junitxml=${INSTALL_TEST_DIR}/TEST-onnx.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP16 + - name: TensorFlow 1 Layer Tests - TF FE run: | python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt @@ -979,8 +1027,7 @@ jobs: # Skip test_onnx/test_zoo_models and test_onnx/test_backend due to long execution time - ONNX Model Zoo tests are run separately python3 -m pytest -sv ${OPENVINO_REPO}/src/frontends/onnx/tests -k 'not cuda' \ --junitxml=${INSTALL_TEST_DIR}/TEST-onnx_frontend.xml \ - --ignore=${OPENVINO_REPO}/src/frontends/onnx/tests/test_python/test_zoo_models.py \ - --ignore=${OPENVINO_REPO}/src/frontends/onnx/tests/test_python/test_backend.py + --ignore=${OPENVINO_REPO}/src/frontends/onnx/tests/test_python/test_zoo_models.py - name: MO Python API Tests run: | @@ -1059,10 +1106,10 @@ jobs: - name: Extract OpenVINO packages run: | pushd ${INSTALL_DIR} - tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} && rm openvino_package.tar.gz || exit 1 + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} popd pushd ${INSTALL_TEST_DIR} - tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} && rm openvino_tests.tar.gz || exit 1 + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} popd - name: Install OpenVINO dependencies @@ -1105,13 +1152,14 @@ jobs: with: name: test-results-functional-cpu path: | - ${{ env.INSTALL_TEST_DIR }}/TEST*.xml + ${{ env.INSTALL_TEST_DIR }}/temp/*.log + ${{ env.INSTALL_TEST_DIR }}/logs/*.log ${{ env.INSTALL_TEST_DIR }}/logs/failed/*.log ${{ env.INSTALL_TEST_DIR }}/logs/crashed/*.log ${{ env.INSTALL_TEST_DIR }}/logs/hanged/*.log ${{ env.INSTALL_TEST_DIR }}/logs/interapted/*.log - ${{ env.INSTALL_TEST_DIR }}/logs/disabled_tests.log ${{ env.INSTALL_TEST_DIR }}/logs/hash_table.csv + ${{ env.PARALLEL_TEST_CACHE }} if-no-files-found: 'error' TensorFlow_Hub_Models_Tests: @@ -1163,11 +1211,11 @@ jobs: - name: Extract OpenVINO packages run: | pushd ${INSTALL_DIR} - tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} && rm openvino_package.tar.gz || exit 1 + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} popd pushd ${INSTALL_TEST_DIR} - tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} && rm openvino_tests.tar.gz || exit 1 + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} popd - name: Install OpenVINO Python wheels @@ -1238,10 +1286,10 @@ jobs: - name: Extract OpenVINO packages run: | pushd ${INSTALL_DIR} - tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} && rm openvino_package.tar.gz || exit 1 + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} popd pushd ${INSTALL_TEST_DIR} - tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} && rm openvino_tests.tar.gz || exit 1 + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} popd - uses: actions/setup-python@v4 @@ -1286,3 +1334,122 @@ jobs: path: | ${{ env.INSTALL_TEST_DIR }}/TEST*.html if-no-files-found: 'error' + + NVIDIA_Plugin: + name: NVIDIA plugin + needs: Build + defaults: + run: + shell: bash + runs-on: aks-linux-16-cores + container: + image: openvinogithubactions.azurecr.io/dockerhub/nvidia/cuda:11.8.0-runtime-ubuntu20.04 + volumes: + - /mount/caches:/mount/caches + env: + CMAKE_BUILD_TYPE: 'Release' + CMAKE_GENERATOR: 'Ninja Multi-Config' + CMAKE_CUDA_COMPILER_LAUNCHER: ccache + CMAKE_CXX_COMPILER_LAUNCHER: ccache + CMAKE_C_COMPILER_LAUNCHER: ccache + INSTALL_DIR: /__w/openvino/openvino/install + OPENVINO_DEVELOPER_PACKAGE: /__w/openvino/openvino/install/developer_package + OPENVINO_REPO: /__w/openvino/openvino/openvino + OPENVINO_CONTRIB_REPO: /__w/openvino/openvino/openvino_contrib + NVIDIA_BUILD_DIR: /__w/openvino/openvino/nvidia_plugin_build + DEBIAN_FRONTEND: 'noninteractive' + CCACHE_DIR: /mount/caches/ccache/ubuntu20_x86_64_Release + CCACHE_TEMPDIR: /__w/openvino/openvino/ccache_temp + CCACHE_MAXSIZE: 50G + + steps: + - name: Install Prerequisites + run: apt update && apt install -y git ca-certificates + + - name: Download OpenVINO package + uses: actions/download-artifact@v3 + with: + name: openvino_package + path: ${{ env.INSTALL_DIR }} + + - name: Download OpenVINO Developer package + uses: actions/download-artifact@v3 + with: + name: openvino_developer_package + path: ${{ env.INSTALL_DIR }} + + - name: Extract OpenVINO packages + run: | + pushd ${INSTALL_DIR} + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} + popd + + pushd ${INSTALL_DIR} + tar -xzf openvino_developer_package.tar.gz -C ${INSTALL_DIR} + popd + + # TODO: replace with sparse checkout below + - name: Clone OpenVINO + uses: actions/checkout@v4 + with: + path: ${{ env.OPENVINO_REPO }} + + - name: Fetch install_build_dependencies.sh + if: ${{ 'false' }} + uses: actions/checkout@v4 + with: + sparse-checkout: | + install_build_dependencies.sh + sparse-checkout-cone-mode: false + path: ${{ env.OPENVINO_REPO }} + + - name: Clone OpenVINO Contrib + uses: actions/checkout@v4 + with: + repository: 'openvinotoolkit/openvino_contrib' + path: ${{ env.OPENVINO_CONTRIB_REPO }} + ref: 'master' + + # + # Dependencies + # + + - name: Install build dependencies + run: | + ${OPENVINO_REPO}/install_build_dependencies.sh + apt -y --no-install-recommends install software-properties-common + + - name: Install CUDA + run: | + wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin + mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600 + + apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub + add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /" + apt update + apt install -y \ + libcudnn8=8.9.4.*-1+cuda11.8 \ + libcudnn8-dev=8.9.4.*-1+cuda11.8 \ + libcudnn8-samples=8.9.4.*-1+cuda11.8 \ + cuda-runtime-11-8 \ + cuda-11-8 \ + libcutensor1=1.6.1.5-1 \ + libcutensor-dev=1.6.1.5-1 \ + cuda-drivers=520.61.05-1 + + # + # Build + # + + - name: Cmake & Build - NVIDIA Plugin + run: | + source ${INSTALL_DIR}/setupvars.sh + cmake \ + -DOpenVINODeveloperPackage_DIR=${OPENVINO_DEVELOPER_PACKAGE}/cmake \ + -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF \ + -S ${OPENVINO_CONTRIB_REPO}/modules/nvidia_plugin \ + -B ${NVIDIA_BUILD_DIR} + cmake --build ${NVIDIA_BUILD_DIR} --parallel --config ${{ env.CMAKE_BUILD_TYPE }} --verbose -- ov_nvidia_func_tests ov_nvidia_unit_tests + + - name: Show ccache stats + run: ccache --show-stats diff --git a/.github/workflows/linux_conditional_compilation.yml b/.github/workflows/linux_conditional_compilation.yml index b8567d57a6a6cd..cb4470ef496606 100644 --- a/.github/workflows/linux_conditional_compilation.yml +++ b/.github/workflows/linux_conditional_compilation.yml @@ -73,6 +73,7 @@ jobs: repository: 'openvinotoolkit/testdata' path: ${{ env.MODELS_PATH }} lfs: 'true' + ref: 'master' # # Dependencies @@ -110,6 +111,9 @@ jobs: # For running Paddle frontend unit tests python3 -m pip install -r ${OPENVINO_REPO}/src/frontends/paddle/tests/requirements.txt + # see https://github.com/PaddlePaddle/Paddle/issues/55597#issuecomment-1718131420 + wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.19_amd64.deb + apt-get install ./libssl1.1_1.1.1f-1ubuntu2.19_amd64.deb # # Build @@ -230,6 +234,7 @@ jobs: repository: 'openvinotoolkit/testdata' path: ${{ env.MODELS_PATH }} lfs: 'true' + ref: 'master' - name: Download selective build statistics package uses: actions/download-artifact@v3 @@ -303,7 +308,7 @@ jobs: name: openvino_tests path: ${{ env.INSTALL_TEST_DIR }} - - name: Extract OpenVINO packages + - name: Extract OpenVINO tests package run: tar -xvzf ${INSTALL_TEST_DIR}/openvino_tests.tar.gz -C ${INSTALL_TEST_DIR} - name: Install OpenVINO dependencies diff --git a/.github/workflows/linux_cuda.yml b/.github/workflows/linux_cuda.yml deleted file mode 100644 index 7fd90dac00dcf4..00000000000000 --- a/.github/workflows/linux_cuda.yml +++ /dev/null @@ -1,143 +0,0 @@ -name: Linux NVIDIA Plugin (Ubuntu 20.04) -on: - workflow_dispatch: - pull_request: - paths-ignore: - - '**/docs/**' - - 'docs/**' - - '**/**.md' - - '**.md' - - '**/layer_tests_summary/**' - - '**/conformance/**' - push: - paths-ignore: - - '**/docs/**' - - 'docs/**' - - '**/**.md' - - '**.md' - - '**/layer_tests_summary/**' - - '**/conformance/**' - branches: - - master - -concurrency: - # github.ref is not unique in post-commit - group: ${{ github.event_name == 'push' && github.run_id || github.ref }}-linux-nvidia - cancel-in-progress: true - -jobs: - Build: - defaults: - run: - shell: bash - runs-on: aks-linux-16-cores - container: - image: openvinogithubactions.azurecr.io/dockerhub/nvidia/cuda:11.8.0-runtime-ubuntu20.04 - volumes: - - /mount/caches:/mount/caches - env: - CMAKE_BUILD_TYPE: 'Release' - CMAKE_GENERATOR: 'Ninja Multi-Config' - CMAKE_CUDA_COMPILER_LAUNCHER: ccache - CMAKE_CXX_COMPILER_LAUNCHER: ccache - CMAKE_C_COMPILER_LAUNCHER: ccache - OPENVINO_REPO: /__w/openvino/openvino/openvino - OPENVINO_CONTRIB_REPO: /__w/openvino/openvino/openvino_contrib - OV_BUILD_DIR: /__w/openvino/openvino/openvino_build - NVIDIA_BUILD_DIR: /__w/openvino/openvino/nvidia_plugin_build - DEBIAN_FRONTEND: 'noninteractive' - CCACHE_DIR: /mount/caches/ccache/ubuntu20_x86_64_Release - CCACHE_TEMPDIR: /__w/openvino/openvino/ccache_temp - CCACHE_MAXSIZE: 50G - steps: - - - name: Install Prerequisites - run: | - apt update - apt install -y git curl git git-lfs unzip wget - - - name: Clone OpenVINO - uses: actions/checkout@v4 - with: - path: ${{ env.OPENVINO_REPO }} - submodules: 'true' - - - name: Clone OpenVINO Contrib - uses: actions/checkout@v4 - with: - repository: 'openvinotoolkit/openvino_contrib' - path: ${{ env.OPENVINO_CONTRIB_REPO }} - ref: 'master' - - # - # Dependencies - # - - - name: Install build dependencies - run: | - ${OPENVINO_REPO}/install_build_dependencies.sh - - apt -y --no-install-recommends install unzip wget software-properties-common - - - name: Install CUDA - run: | - wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin - mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600 - - apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub - add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /" - apt update - apt install -y \ - libcudnn8=8.9.4.*-1+cuda11.8 \ - libcudnn8-dev=8.9.4.*-1+cuda11.8 \ - libcudnn8-samples=8.9.4.*-1+cuda11.8 \ - cuda-runtime-11-8 \ - cuda-11-8 \ - libcutensor1=1.6.1.5-1 \ - libcutensor-dev=1.6.1.5-1 \ - cuda-drivers=520.61.05-1 - - # - # Build - # - - - name: CMake configure - run: | - cmake \ - -G "${{ env.CMAKE_GENERATOR }}" \ - -DENABLE_CPPLINT=OFF \ - -DENABLE_NCC_STYLE=OFF \ - -DENABLE_SYSTEM_PUGIXML=ON \ - -DENABLE_SYSTEM_OPENCL=ON \ - -DENABLE_STRICT_DEPENDENCIES=OFF \ - -DCMAKE_BUILD_TYPE=${{ env.CMAKE_BUILD_TYPE }} \ - -DENABLE_INTEL_CPU=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 \ - -DENABLE_OV_PYTORCH_FRONTEND=OFF \ - -DENABLE_OV_ONNX_FRONTEND=OFF \ - -DENABLE_PYTHON=OFF \ - -DENABLE_TESTS=ON \ - -DCPACK_GENERATOR=TGZ \ - -DCMAKE_COMPILE_WARNING_AS_ERROR=ON \ - -S ${OPENVINO_REPO} \ - -B ${OV_BUILD_DIR} - - - name: Build - OpenVINO - run: | - cmake --build ${OV_BUILD_DIR} --parallel --config ${{ env.CMAKE_BUILD_TYPE }} --verbose --target ov_dev_targets - - - name: Cmake & Build - NVIDIA Plugin - run: | - cmake \ - -DOpenVINODeveloperPackage_DIR=${OV_BUILD_DIR} \ - -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF \ - -S ${OPENVINO_CONTRIB_REPO}/modules/nvidia_plugin \ - -B ${NVIDIA_BUILD_DIR} - cmake --build ${NVIDIA_BUILD_DIR} --parallel --config ${{ env.CMAKE_BUILD_TYPE }} --verbose -- ov_nvidia_func_tests ov_nvidia_unit_tests - - - name: Show ccache stats - run: ccache --show-stats diff --git a/.github/workflows/mac.yml b/.github/workflows/mac.yml new file mode 100644 index 00000000000000..487536f615a8a6 --- /dev/null +++ b/.github/workflows/mac.yml @@ -0,0 +1,801 @@ +name: macOS (Python 3.11) +on: + workflow_dispatch: + schedule: + # at 00:00 on workdays + - cron: '0 0 * * 1,2,3,4,5' +# pull_request: +# paths-ignore: +# - '**/docs/**' +# - 'docs/**' +# - '**/**.md' +# - '**.md' +# - '**/layer_tests_summary/**' +# - '**/conformance/**' +# push: +# paths-ignore: +# - '**/docs/**' +# - 'docs/**' +# - '**/**.md' +# - '**.md' +# - '**/layer_tests_summary/**' +# - '**/conformance/**' +# branches: +# - master +# - 'releases/**' + +concurrency: + # github.ref is not unique in post-commit + group: ${{ github.event_name == 'push' && github.run_id || github.ref }}-mac-main + cancel-in-progress: true + +env: + PYTHON_VERSION: '3.11' + +jobs: + Build: + defaults: + run: + shell: bash + strategy: + max-parallel: 2 + fail-fast: false + matrix: + include: + - arhitecture: 'x86_64' + machine: 'macos-13-large' + macos_deployment_target: '10.12' + - arhitecture: 'arm64' + machine: 'macos-13-xlarge' + macos_deployment_target: '11.0' + runs-on: ${{ matrix.machine }} + env: + CMAKE_BUILD_TYPE: 'Release' + CMAKE_GENERATOR: 'Ninja Multi-Config' + MACOSX_DEPLOYMENT_TARGET: ${{ matrix.macos_deployment_target }} + CMAKE_CXX_COMPILER_LAUNCHER: ccache + CMAKE_C_COMPILER_LAUNCHER: ccache + OPENVINO_REPO: ${{ github.workspace }}/openvino + OPENVINO_CONTRIB_REPO: ${{ github.workspace }}/openvino_contrib + INSTALL_DIR: ${{ github.workspace }}/openvino_install + INSTALL_TEST_DIR: ${{ github.workspace }}/tests_install + BUILD_DIR: ${{ github.workspace }}/build + steps: + - name: Clone OpenVINO + uses: actions/checkout@v4 + with: + path: 'openvino' + submodules: 'true' + + - name: Clone OpenVINO Contrib + uses: actions/checkout@v4 + with: + repository: 'openvinotoolkit/openvino_contrib' + path: 'openvino_contrib' + + # + # Dependencies + # + + - name: Install build dependencies + run: brew install coreutils ninja scons + + - uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install python dependencies + run: | + # For Python API + python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/wheel/requirements-dev.txt + python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/requirements.txt + + # For running Python API tests + python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/src/compatibility/openvino/requirements-dev.txt + + # For running ONNX frontend unit tests + python3 -m pip install --force-reinstall -r ${{ env.OPENVINO_REPO }}/src/frontends/onnx/tests/requirements.txt + + # For running TensorFlow frontend unit tests + python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/frontends/tensorflow/tests/requirements.txt + + # For running Paddle frontend unit tests + python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/frontends/paddle/tests/requirements.txt + + # + # Build + # + + - name: Setup ccache + uses: hendrikmuhs/ccache-action@v1.2 + with: + max-size: "2000M" + # Should save cache only if run in the master branch of the base repo + # github.ref_name is 'ref/PR_#' in case of the PR, and 'branch_name' when executed on push + save: ${{ github.ref_name == 'master' && 'true' || 'false' }} + verbose: 2 + key: ${{ runner.os }}-${{ matrix.arhitecture }}-main + restore-keys: | + ${{ runner.os }}-${{ matrix.arhitecture }}-main + + - name: CMake configure + run: | + cmake \ + -G "${{ env.CMAKE_GENERATOR }}" \ + -DENABLE_CPPLINT=OFF \ + -DENABLE_NCC_STYLE=OFF \ + -DENABLE_TESTS=ON \ + -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF \ + -DENABLE_STRICT_DEPENDENCIES=OFF \ + -DCMAKE_CXX_COMPILER_LAUNCHER=${{ env.CMAKE_CXX_COMPILER_LAUNCHER }} \ + -DCMAKE_C_COMPILER_LAUNCHER=${{ env.CMAKE_C_COMPILER_LAUNCHER }} \ + -S ${{ env.OPENVINO_REPO }} \ + -B ${{ env.BUILD_DIR }} + + - name: Cmake build - OpenVINO + run: cmake --build ${{ env.BUILD_DIR }} --parallel --config ${{ env.CMAKE_BUILD_TYPE }} + + - name: Show ccache stats + run: ccache --show-stats + + - name: Cmake install - OpenVINO + run: | + cmake -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -P ${{ env.BUILD_DIR }}/cmake_install.cmake + cmake -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_TEST_DIR }} -DCOMPONENT=tests -P ${{ env.BUILD_DIR }}/cmake_install.cmake + cmake -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCOMPONENT=python_wheels -P ${{ env.BUILD_DIR }}/cmake_install.cmake + + - name: Pack Artifacts + run: | + pushd ${{ env.INSTALL_DIR }} + tar -czvf ${{ env.BUILD_DIR }}/openvino_package.tar.gz * + popd + + pushd ${{ env.INSTALL_TEST_DIR }} + tar -czvf ${{ env.BUILD_DIR }}/openvino_tests.tar.gz * + popd + + - name: Cmake & Build - OpenVINO Contrib + run: | + cmake \ + -DBUILD_nvidia_plugin=OFF \ + -DBUILD_java_api=OFF \ + -DCUSTOM_OPERATIONS="calculate_grid;complex_mul;fft;grid_sample;sparse_conv;sparse_conv_transpose" \ + -DOPENVINO_EXTRA_MODULES=${{ env.OPENVINO_CONTRIB_REPO }}/modules \ + -S ${{ env.OPENVINO_REPO }} \ + -B ${{ env.BUILD_DIR }} + cmake --build ${{ env.BUILD_DIR }} --parallel --config ${{ env.CMAKE_BUILD_TYPE }} + + # + # Upload build artifacts + # + + - name: Upload openvino package + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: + name: openvino_package_${{ matrix.arhitecture }} + path: ${{ env.BUILD_DIR }}/openvino_package.tar.gz + if-no-files-found: 'error' + + - name: Upload openvino tests package + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: + name: openvino_tests_${{ matrix.arhitecture }} + path: ${{ env.BUILD_DIR }}/openvino_tests.tar.gz + if-no-files-found: 'error' + + Samples: + needs: Build + defaults: + run: + shell: bash + strategy: + max-parallel: 2 + fail-fast: false + matrix: + include: + - arhitecture: 'x86_64' + machine: 'macos-13' + - arhitecture: 'arm64' + machine: 'macos-13-xlarge' + runs-on: ${{ matrix.machine }} + env: + INSTALL_DIR: ${{ github.workspace }}/install + INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests + BUILD_DIR: ${{ github.workspace }}/build + + steps: + # + # Initialize OpenVINO + # + + - name: Download OpenVINO package + uses: actions/download-artifact@v3 + with: + name: openvino_package_${{ matrix.arhitecture }} + path: ${{ env.INSTALL_DIR }} + + - name: Download OpenVINO tests package + uses: actions/download-artifact@v3 + with: + name: openvino_tests_${{ matrix.arhitecture }} + path: ${{ env.INSTALL_TEST_DIR }} + + - name: Extract OpenVINO packages + run: | + pushd ${INSTALL_DIR} + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} + popd + + pushd ${INSTALL_TEST_DIR} + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} + popd + + - name: Install dependencies + run: brew install coreutils + + - uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Build cpp samples + run: ${INSTALL_DIR}/samples/cpp/build_samples.sh -i ${INSTALL_DIR} -b ${BUILD_DIR}/cpp_samples + env: + CMAKE_COMPILE_WARNING_AS_ERROR: 'ON' + + - name: Build c samples + run: ${INSTALL_DIR}/samples/c/build_samples.sh -i ${INSTALL_DIR} -b ${BUILD_DIR}/c_samples + env: + CMAKE_COMPILE_WARNING_AS_ERROR: 'ON' + + # + # Tests + # + + - name: Samples tests + run: | + export WORKSPACE=${INSTALL_DIR} + export IE_APP_PATH=${INSTALL_DIR}/samples_bin + export IE_APP_PYTHON_PATH=${INSTALL_DIR}/samples/python + export SHARE=${INSTALL_TEST_DIR}/smoke_tests/samples_smoke_tests_data + + python3 -m pip install --ignore-installed PyYAML -r ${INSTALL_TEST_DIR}/smoke_tests/requirements.txt + + source ${INSTALL_DIR}/setupvars.sh + + python3 -m pytest -sv ${INSTALL_TEST_DIR}/smoke_tests \ + --env_conf ${INSTALL_TEST_DIR}/smoke_tests/env_config.yml \ + --junitxml=${INSTALL_TEST_DIR}/TEST-SamplesSmokeTests.xml + + - name: Upload Test Results + uses: actions/upload-artifact@v3 + if: ${{ !cancelled() }} + with: + name: test-results-samples-${{ matrix.arhitecture }} + path: ${{ env.INSTALL_TEST_DIR }}/TEST*.xml + if-no-files-found: 'error' + + CXX_Unit_Tests: + name: C++ Unit tests + needs: Build + defaults: + run: + shell: bash + strategy: + max-parallel: 2 + fail-fast: false + matrix: + include: + - arhitecture: 'x86_64' + machine: 'macos-13' + - arhitecture: 'arm64' + machine: 'macos-13-xlarge' + runs-on: ${{ matrix.machine }} + env: + INSTALL_DIR: ${{ github.workspace }}/install + INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests + + steps: + # + # Dependencies + # + + - name: Download OpenVINO package + uses: actions/download-artifact@v3 + with: + name: openvino_package_${{ matrix.arhitecture }} + path: ${{ env.INSTALL_DIR }} + + - name: Download OpenVINO tests package + uses: actions/download-artifact@v3 + with: + name: openvino_tests_${{ matrix.arhitecture }} + path: ${{ env.INSTALL_TEST_DIR }} + + - name: Extract OpenVINO packages + run: | + pushd ${{ env.INSTALL_DIR }} + tar -xzf openvino_package.tar.gz -C ${{ env.INSTALL_DIR }} && rm openvino_package.tar.gz || exit 1 + popd + pushd ${{ env.INSTALL_TEST_DIR }} + tar -xzf openvino_tests.tar.gz -C ${{ env.INSTALL_DIR }} && rm openvino_tests.tar.gz || exit 1 + popd + + # + # Tests + # + + - name: OpenVINO Core Unit Tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_core_unit_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU* \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-NGraphUT.xml + + - name: OpenVINO Inference Functional Tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_inference_functional_tests --gtest_print_time=1 \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-InferenceFunc.xml + + - name: OpenVINO Inference Unit Tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_inference_unit_tests --gtest_print_time=1 \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-InferenceUnit.xml + + - name: Low Precision Transformations Tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + + # Skips under Ticket: 122660 + skip_filter=${{ matrix.arhitecture == 'arm64' && '--gtest_filter=-*smoke_LPT/FoldFakeQuantizeInTransformations.CompareFunctions*' || '' }} + + ${{ env.INSTALL_TEST_DIR }}/ov_lp_transformations_tests --gtest_print_time=1 "$skip_filter" \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-LpTransformations.xml + + - name: OpenVINO Conditional compilation tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_conditional_compilation_tests --gtest_print_time=1 \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ConditionalCompilation.xml + + - name: IR frontend tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_ir_frontend_tests --gtest_print_time=1 \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-IRFrontend.xml + + - name: PaddlePaddle frontend tests + if: ${{ 'false' }} + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/paddle_tests --gtest_print_time=1 --gtest_filter=*smoke* \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-PaddleTests.xml + + - name: ONNX frontend tests + if: ${{ matrix.arhitecture == 'x86_64' }} # Ticket for ARM64: 122663 + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + + ${{ env.INSTALL_TEST_DIR }}/ov_onnx_frontend_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU* \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ONNXFrontend.xml + + - name: TensorFlow Common tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_tensorflow_common_tests --gtest_print_time=1 \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-TensorFlowCommonFrontend.xml + + - name: TensorFlow frontend tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + + # Skips under Ticket: 122666 + skip_filter=${{ matrix.arhitecture == 'arm64' && '--gtest_filter=-*CompileModelsTests.ModelWithSplitConvConcat*:*NgramCompilation*' || '' }} + + ${{ env.INSTALL_TEST_DIR }}/ov_tensorflow_frontend_tests --gtest_print_time=1 "$skip_filter" \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-TensorFlowFrontend.xml + + - name: TensorFlow Lite frontend tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_tensorflow_lite_frontend_tests --gtest_print_time=1 \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-TensorFlowLiteFrontend.xml + + - name: Transformations func tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + + # Skips under Ticket: 122668 + skip_filter=${{ matrix.arhitecture == 'arm64' && '--gtest_filter=-*TransformationTestsF.CompressQuantizeWeights*:*TransformationTests/CompressQuantizeWeightsTests.FusionTest*' || '' }} + + ${{ env.INSTALL_TEST_DIR }}/ov_transformations_tests --gtest_print_time=1 "$skip_filter" \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-Transformations.xml + + - name: Common test utils tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_util_tests --gtest_print_time=1 \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-commonUtilsTests.xml + + - name: Snippets func tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_snippets_func_tests --gtest_print_time=1 \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-SnippetsFuncTests.xml + + - name: CPU plugin unit tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_cpu_unit_tests --gtest_print_time=1 \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-CPUUnitTests.xml + + - name: SubgraphsDumper tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/subgraphsDumperTests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-SubgraphsDumperTests.xml + + - name: Template OpImpl tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/conformanceTests --gtest_print_time=1 --device=TEMPLATE --gtest_filter="*OpImpl*" \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-TemplateOpImplTests.xml + + - name: AUTO unit tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_auto_unit_tests --gtest_print_time=1 \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ov_auto_unit_tests.xml + + - name: AUTO func Tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_auto_func_tests --gtest_print_time=1 \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ov_auto_func_tests.xml + + - name: Template plugin func tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_template_func_tests --gtest_print_time=1 \ + --gtest_filter=*smoke* \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-TemplateFuncTests.xml + + - name: Inference Engine C API tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/InferenceEngineCAPITests --gtest_print_time=1 \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-InferenceEngineCAPITests.xml + + - name: OpenVINO C API tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_capi_test --gtest_print_time=1 \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-OpenVINOCAPITests.xml + + - name: AutoBatch unit tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_auto_batch_unit_tests --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ov_auto_batch_unit_tests.xml + + - name: AutoBatch func tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_auto_batch_func_tests --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ov_auto_batch_func_tests.xml + + - name: Proxy Plugin func tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_proxy_plugin_tests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-OVProxyTests.xml + + - name: Hetero unit tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_hetero_unit_tests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-OVHeteroUnitTests.xml + + - name: Hetero func tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_hetero_func_tests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-OVHeteroFuncTests.xml + + - name: Upload Test Results + uses: actions/upload-artifact@v3 + if: ${{ always() }} + with: + name: test-results-cpp-${{ matrix.arhitecture }} + path: ${{ env.INSTALL_TEST_DIR }}/TEST*.xml + if-no-files-found: 'error' + + Python_Unit_Tests: + name: Python unit tests + needs: Build + defaults: + run: + shell: bash + strategy: + max-parallel: 2 + fail-fast: false + matrix: + include: + - arhitecture: 'x86_64' + machine: 'macos-13' + - arhitecture: 'arm64' + machine: 'macos-13-xlarge' + runs-on: ${{ matrix.machine }} + env: + OPENVINO_REPO: ${{ github.workspace }}/openvino + OPENVINO_CONTRIB_REPO: ${{ github.workspace }}/openvino_contrib + INSTALL_DIR: ${{ github.workspace }}/install + INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests + LAYER_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/layer_tests + steps: + - name: Clone OpenVINO + uses: actions/checkout@v4 + with: + path: 'openvino' + submodules: 'true' + + # + # Dependencies + # + + - uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Download OpenVINO package + uses: actions/download-artifact@v3 + with: + name: openvino_package_${{ matrix.arhitecture }} + path: ${{ env.INSTALL_DIR }} + + - name: Download OpenVINO tests package + uses: actions/download-artifact@v3 + with: + name: openvino_tests_${{ matrix.arhitecture }} + path: ${{ env.INSTALL_TEST_DIR }} + + - name: Extract OpenVINO packages + run: | + pushd ${{ env.INSTALL_DIR }} + tar -xzf openvino_package.tar.gz -C ${{ env.INSTALL_DIR }} + popd + + pushd ${{ env.INSTALL_TEST_DIR }} + tar -xzf openvino_tests.tar.gz -C ${{ env.INSTALL_DIR }} + popd + + - name: Install Python API tests dependencies + run: | + # For torchvision to OpenVINO preprocessing converter + python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/src/openvino/preprocess/torchvision/requirements.txt + + # TODO: replace with Python API tests requirements + python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_dev.txt + + - name: Install OpenVINO Python wheels + run: | + # Install the core OV wheel + python3 -m pip install ${{ env.INSTALL_DIR }}/tools/openvino-*.whl + + # mxnet is only available on x86_64 + extras_to_install="caffe,kaldi,onnx,tensorflow2,pytorch" + if [[ "${{ matrix.arhitecture }}" == "x86_64" ]]; then + extras_to_install="mxnet,$extras_to_install" + fi + + # Find and install OV dev wheel + pushd ${{ env.INSTALL_DIR }}/tools + ov_dev_wheel_name=$(find . -name 'openvino_dev*.whl') + python3 -m pip install $ov_dev_wheel_name[$extras_to_install] + popd + + - name: Python API 1.0 Tests + run: | + python3 -m pytest -s ${{ env.INSTALL_TEST_DIR }}/pyngraph \ + --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-Pyngraph.xml \ + --ignore=${{ env.INSTALL_TEST_DIR }}/pyngraph/tests_compatibility/test_onnx/test_zoo_models.py \ + --ignore=${{ env.INSTALL_TEST_DIR }}/pyngraph/tests_compatibility/test_onnx/test_backend.py + + - name: Python API 2.0 Tests + run: | + # For python imports to import pybind_mock_frontend + export PYTHONPATH=${{ env.INSTALL_TEST_DIR }}:$PYTHONPATH + # for 'template' extension + export DYLD_LIBRARY_PATH=${{ env.INSTALL_TEST_DIR }}:$DYLD_LIBRARY_PATH + + python3 -m pytest -sv ${{ env.INSTALL_TEST_DIR }}/pyopenvino \ + --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-Pyngraph.xml \ + --ignore=${{ env.INSTALL_TEST_DIR }}/pyopenvino/tests/test_utils/test_utils.py + + - name: MO Python API Tests + run: | + python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt + export PYTHONPATH=${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH + # TODO: remove setupvars.sh from here; currently, it's used for 'test_utils' installed in '/python/openvino' + source ${INSTALL_DIR}/setupvars.sh + + python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/mo_python_api_tests/ --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-test_mo_convert.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP16 + + - name: OVC Python API Tests + run: | + python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt + # TODO: remove setupvars.sh from here; currently, it's used for 'test_utils' installed in '/python/openvino' + source ${{ env.INSTALL_DIR }}/setupvars.sh + + python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/ovc_python_api_tests --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-test_ovc_convert.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP16 + + - name: Model Optimizer unit tests + run: | + export PYTHONPATH=${{ env.INSTALL_TEST_DIR }}:$PYTHONPATH + python3 -m pytest -s ${{ env.INSTALL_TEST_DIR }}/mo/unit_tests \ + --ignore=${{ env.INSTALL_TEST_DIR }}/mo/unit_tests/mo/front/mxnet \ + --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-ModelOptimizer.xml + + - name: PyTorch Layer Tests + run: | + python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt + export PYTHONPATH=${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH + + python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/pytorch_tests -m precommit --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-pytorch.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP16 + + - name: ONNX Layer Tests + run: | + python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt + + export PYTHONPATH=${{ env.OPENVINO_REPO }}/tools/mo/:${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH + + python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/onnx_tests -m "not launch_only_if_manually_specified and precommit" --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-onnx.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP16 + + - name: TensorFlow 1 Layer Tests - TF FE + run: | + python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt + + export PYTHONPATH=${{ env.OPENVINO_REPO }}/tools/mo/:${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH + + python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow_tests/ --use_new_frontend -m precommit_tf_fe --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tf_fe.xml + env: + TEST_DEVICE: CPU + + - name: TensorFlow 2 Layer Tests - TF FE + if: ${{ 'false' }} # Ticket: 123322 + run: | + python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt + export PYTHONPATH=${{ env.OPENVINO_REPO }}/tools/mo/:${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH + + python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow2_keras_tests/ --use_new_frontend -m precommit_tf_fe --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tf2_fe.xml + env: + TEST_DEVICE: CPU + + - name: TensorFlow 1 Layer Tests - Legacy FE + run: | + python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt + export PYTHONPATH=${{ env.OPENVINO_REPO }}/tools/mo/:${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH + + python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow_tests/test_tf_Roll.py --ir_version=10 --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tf_Roll.xml + + - name: TensorFlow 2 Layer Tests - Legacy FE + run: | + python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt + export PYTHONPATH=${{ env.OPENVINO_REPO }}/tools/mo/:${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH + + python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow2_keras_tests/test_tf2_keras_activation.py \ + --ir_version=11 --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tf2_Activation.xml -k "sigmoid" + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP16 + + - name: TensorFlow Lite Layer Tests - TFL FE + run: | + python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt + export PYTHONPATH=${{ env.OPENVINO_REPO }}/tools/mo/:${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH + + python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow_lite_tests/ --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tfl_fe.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP16 + + - name: Python ONNX operators tests + if: ${{ 'false' }} # Ticket: 123325 + run: | + # Skip test_onnx/test_zoo_models and test_onnx/test_backend due to long execution time - ONNX Model Zoo tests are run separately + python3 -m pytest -sv ${{ env.OPENVINO_REPO }}/src/frontends/onnx/tests -k 'not cuda' \ + --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-onnx_frontend.xml \ + --ignore=${{ env.OPENVINO_REPO }}/src/frontends/onnx/tests/test_python/test_zoo_models.py + + - name: Python Frontend tests + run: | + python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt + export PYTHONPATH=${{ env.OPENVINO_REPO }}/tools/mo/:${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH + # to allow 'libtest_builtin_extensions.so' to find 'libopenvino_onnx_frontend.so' + source ${{ env.INSTALL_DIR }}/setupvars.sh + + python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/py_frontend_tests --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-test_py_fontend.xml + + # TODO: install to 'tests' component via cpack + - name: OVC unit tests + run: python3 -m pytest -s ${{ env.OPENVINO_REPO }}/tools/ovc/unit_tests --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-OpenVinoConversion.xml + + - name: Upload Test Results + uses: actions/upload-artifact@v3 + if: ${{ always() }} + with: + name: test-results-python-${{ matrix.arhitecture }} + path: ${{ env.INSTALL_TEST_DIR }}/TEST*.xml + if-no-files-found: 'error' + + CPU_Functional_Tests: + name: CPU functional tests + needs: Build + defaults: + run: + shell: bash + strategy: + max-parallel: 2 + fail-fast: false + matrix: + include: + # ticket: 122001 + # - arhitecture: 'x86_64' + # machine: 'macos-13' + - arhitecture: 'arm64' + machine: 'macos-13-xlarge' + runs-on: ${{ matrix.machine }} + env: + INSTALL_DIR: ${{ github.workspace }}/install + INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests + + steps: + - name: Create Directories + run: mkdir -p ${{ env.INSTALL_DIR }} ${{ env.INSTALL_TEST_DIR }} + + - name: Download OpenVINO package + uses: actions/download-artifact@v3 + with: + name: openvino_package_${{ matrix.arhitecture }} + path: ${{ env.INSTALL_DIR }} + + - name: Download OpenVINO tests package + uses: actions/download-artifact@v3 + with: + name: openvino_tests_${{ matrix.arhitecture }} + path: ${{ env.INSTALL_TEST_DIR }} + + - name: Extract OpenVINO packages + run: | + pushd ${{ env.INSTALL_DIR }} + tar -xzf openvino_package.tar.gz -C ${{ env.INSTALL_DIR }} && rm openvino_package.tar.gz + popd + pushd ${{ env.INSTALL_TEST_DIR }} + tar -xzf openvino_tests.tar.gz -C ${{ env.INSTALL_DIR }} && rm openvino_tests.tar.gz + popd + + - name: CPU plugin func tests + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + + # Skips under Ticket: 122769 + skip_filter=${{ matrix.arhitecture == 'arm64' && '--gtest_filter=-*smoke_nonzero/NonZeroLayerTest.Inference/IS*:*smoke_NormalizeL2_*:*Extension.XmlModelWithExtensionFromDSO*:*Extension.OnnxModelWithExtensionFromDSO*:*ONNXQuantizedModels/QuantizedModelsTests.MaxPool*:*ONNXQuantizedModels/QuantizedModelsTests.Convolution*:**' || '' }} + + ${{ env.INSTALL_TEST_DIR }}/ov_cpu_func_tests --gtest_print_time=1 --gtest_filter=*smoke* "$skip_filter" --gtest_output=xml:"${{ env.INSTALL_TEST_DIR }}/TEST-CPUFuncTests.xml" + + - name: Upload Test Results + uses: actions/upload-artifact@v3 + if: ${{ always() }} + with: + name: test-results-functional-cpu-${{ matrix.arhitecture }} + path: ${{ env.INSTALL_TEST_DIR }}/TEST*.xml + if-no-files-found: 'error' diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 2dd4b218a1e861..e6763d2a696377 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -1,24 +1,27 @@ -name: Tests on Windows (VS 2022, Python 3.11) +name: Windows (VS 2022, Python 3.11) on: - workflow_dispatch: - pull_request: - paths-ignore: - - '**/docs/**' - - 'docs/**' - - '**/**.md' - - '**.md' - - '**/layer_tests_summary/**' - - '**/conformance/**' - push: - paths-ignore: - - '**/docs/**' - - 'docs/**' - - '**/**.md' - - '**.md' - - '**/layer_tests_summary/**' - - '**/conformance/**' - branches: - - master + schedule: + # at 00:00 on workdays + - cron: '0 0 * * 1,2,3,4,5' +# workflow_dispatch: +# pull_request: +# paths-ignore: +# - '**/docs/**' +# - 'docs/**' +# - '**/**.md' +# - '**.md' +# - '**/layer_tests_summary/**' +# - '**/conformance/**' +# push: +# paths-ignore: +# - '**/docs/**' +# - 'docs/**' +# - '**/**.md' +# - '**.md' +# - '**/layer_tests_summary/**' +# - '**/conformance/**' +# branches: +# - master concurrency: # github.ref is not unique in post-commit @@ -26,20 +29,7 @@ concurrency: cancel-in-progress: true env: - CMAKE_BUILD_TYPE: 'Release' - CMAKE_GENERATOR: 'Ninja' - CMAKE_CXX_COMPILER_LAUNCHER: sccache - CMAKE_C_COMPILER_LAUNCHER: sccache - OPENVINO_REPO: "${{ github.workspace }}\\openvino" - OPENVINO_CONTRIB_REPO: "${{ github.workspace }}\\openvino_contrib" - INSTALL_DIR: "${{ github.workspace }}\\install" - INSTALL_TEST_DIR: "${{ github.workspace }}\\install\\tests" - SAMPLES_INSTALL_DIR: "${{ github.workspace }}\\install\\samples" - LAYER_TESTS_INSTALL_DIR: "${{ github.workspace }}\\install\\tests\\layer_tests" - BUILD_DIR: "${{ github.workspace }}\\build" - OV_TEMP: "${{ github.workspace }}\\openvino_temp" - PYTHON_STATIC_ARGS: -m "not dynamic_library" - VCVARSPATH: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvarsall.bat" + PYTHON_VERSION: '3.11' jobs: Build: @@ -47,6 +37,16 @@ jobs: run: shell: pwsh runs-on: windows-latest-8-cores + env: + CMAKE_BUILD_TYPE: 'Release' + CMAKE_GENERATOR: 'Ninja Multi-Config' + CMAKE_CXX_COMPILER_LAUNCHER: sccache + CMAKE_C_COMPILER_LAUNCHER: sccache + OPENVINO_REPO: "${{ github.workspace }}\\openvino" + OPENVINO_CONTRIB_REPO: "${{ github.workspace }}\\openvino_contrib" + INSTALL_DIR: "${{ github.workspace }}\\openvino_install" + INSTALL_TEST_DIR: "${{ github.workspace }}\\tests_install" + BUILD_DIR: "${{ github.workspace }}\\openvino_build" steps: - name: Clone OpenVINO uses: actions/checkout@v4 @@ -59,6 +59,7 @@ jobs: with: repository: 'openvinotoolkit/openvino_contrib' path: 'openvino_contrib' + ref: 'master' # # Dependencies @@ -66,56 +67,35 @@ jobs: - uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: ${{ env.PYTHON_VERSION }} - name: Install python dependencies run: | - # For Python API - python3 -m pip install Scons + # For Python API: build and wheel packaging python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/wheel/requirements-dev.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/requirements.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/requirements_test.txt - - # For running Python API tests python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/src/compatibility/openvino/requirements-dev.txt # For running ONNX frontend unit tests - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/frontends/onnx/tests/requirements.txt + python3 -m pip install --force-reinstall -r ${{ env.OPENVINO_REPO }}/src/frontends/onnx/tests/requirements.txt # For running TensorFlow frontend unit tests python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/frontends/tensorflow/tests/requirements.txt - # For running Paddle frontend unit tests - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/frontends/paddle/tests/requirements.txt + # For running TensorFlow Lite frontend unit tests + python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/frontends/tensorflow_lite/tests/requirements.txt - - name: Install MO dependencies - run: | - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_mxnet.txt ` - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_caffe.txt ` - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_kaldi.txt ` - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_onnx.txt ` - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_tf2.txt ` - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_dev.txt + # For running Paddle frontend unit tests + # python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/frontends/paddle/tests/requirements.txt - name: Install build dependencies - run: | - choco install --no-progress ninja - choco install --no-progress shellcheck - - - name: Get tools versions - run: | - python3 --version - cmake --version + run: choco install --no-progress ninja # # Build # - - name: Get number of CPU cores - uses: SimenB/github-actions-cpu-cores@v2 - id: cpu-cores - - - uses: ilammy/msvc-dev-cmd@v1 + - name: Configure Developer Command Prompt for Microsoft Visual C++ + uses: ilammy/msvc-dev-cmd@v1 - name: Setup sccache uses: hendrikmuhs/ccache-action@v1.2 @@ -132,55 +112,32 @@ jobs: - name: CMake configure run: | - & {{ env.VCVARSPATH }} x64 && cmake -G "Ninja Multi-Config" ` + cmake -G "${{ env.CMAKE_GENERATOR }}" ` -DENABLE_CPPLINT=OFF ` - -DENABLE_ONEDNN_FOR_GPU=OFF ` + -DBUILD_nvidia_plugin=OFF ` -DBUILD_SHARED_LIBS=OFF ` -DENABLE_TESTS=ON ` -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF ` -DENABLE_STRICT_DEPENDENCIES=OFF ` -DENABLE_PYTHON=ON ` - -DBUILD_nvidia_plugin=OFF ` -DCMAKE_DISABLE_FIND_PACKAGE_PkgConfig=ON ` -DCUSTOM_OPERATIONS="calculate_grid;complex_mul;fft;grid_sample;sparse_conv;sparse_conv_transpose" ` - -DOPENVINO_EXTRA_MODULES=${{ env.OPENVINO_CONTRIB_REPO }}\modules ` - -DCMAKE_BUILD_TYPE=Release ` + -DOPENVINO_EXTRA_MODULES=${{ env.OPENVINO_CONTRIB_REPO }}/modules ` -S ${{ env.OPENVINO_REPO }} ` -B ${{ env.BUILD_DIR }} - - name: Build - run: | - & {{ env.VCVARSPATH }} x64 && cmake --build ${{ env.BUILD_DIR }} --parallel ${{ steps.cpu-cores.outputs.count }} --config Release - - - name: Install - run: cmake -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -P ${{ env.BUILD_DIR }}/cmake_install.cmake - - - name: Install Wheels - run: python3 -m pip install openvino-dev --find-links=${{ env.INSTALL_DIR }}\tools - - - name: CMake Samples Tests - run: | - & {{ env.VCVARSPATH }} x64 && cmake -S ${{ env.OPENVINO_REPO }}/tests/samples_tests -B ${{ env.BUILD_DIR }}/samples_tests - - - name: Install Samples Tests - run: cmake -DCOMPONENT=tests -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -P ${{ env.BUILD_DIR }}/samples_tests/cmake_install.cmake - - - name: Install Tests - run: cmake -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCOMPONENT=tests -P ${{ env.BUILD_DIR }}\cmake_install.cmake + - name: Cmake build - OpenVINO + run: cmake --build ${{ env.BUILD_DIR }} --parallel --config ${{ env.CMAKE_BUILD_TYPE }} --verbose - - name: Cmake Layer Tests + - name: Cmake install - OpenVINO run: | - & {{ env.VCVARSPATH }} x64 && cmake -S ${{ env.OPENVINO_REPO }}/tests/layer_tests -B ${{ env.BUILD_DIR }}/layer_tests - - - name: Build Layer Tests - run: cmake --build ${{ env.BUILD_DIR }}/layer_tests --parallel --config Release - - - name: Install Layer Tests - run: cmake -DCOMPONENT=tests -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -P ${{ env.BUILD_DIR }}/layer_tests/cmake_install.cmake + cmake -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -P ${{ env.BUILD_DIR }}/cmake_install.cmake + cmake -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_TEST_DIR }} -DCOMPONENT=tests -P ${{ env.BUILD_DIR }}/cmake_install.cmake + cmake -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCOMPONENT=python_wheels -P ${{ env.BUILD_DIR }}/cmake_install.cmake - name: Pack Artifacts run: | - $file=Get-ChildItem -Path "${{ env.INSTALL_DIR }}" -Exclude "tests" + $file=Get-ChildItem -Path "${{ env.INSTALL_DIR }}" $compress = @{ Path = $file CompressionLevel = "Optimal" @@ -188,7 +145,7 @@ jobs: } Compress-Archive @compress - $file=Get-ChildItem -Path "${{ env.INSTALL_DIR }}\tests" + $file=Get-ChildItem -Path "${{ env.INSTALL_TEST_DIR }}" $compress = @{ Path = $file CompressionLevel = "Optimal" @@ -196,15 +153,78 @@ jobs: } Compress-Archive @compress + - name: Cmake & Build - OpenVINO Contrib + if: ${{ 'false' }} # Ticket: 122441 + run: | + cmake ` + -DBUILD_nvidia_plugin=OFF ` + -DCUSTOM_OPERATIONS="calculate_grid;complex_mul;fft;grid_sample;sparse_conv;sparse_conv_transpose" ` + -DOPENVINO_EXTRA_MODULES=${{ env.OPENVINO_CONTRIB_REPO }}/modules ` + -S ${{ env.OPENVINO_REPO }} ` + -B ${{ env.BUILD_DIR }} + cmake --build ${{ env.BUILD_DIR }} --parallel --config ${{ env.CMAKE_BUILD_TYPE }} --verbose + + - name: Upload openvino package + uses: actions/upload-artifact@v3 + with: + name: openvino_package + path: ${{ env.BUILD_DIR }}/openvino_package.zip + if-no-files-found: 'error' + + - name: Upload openvino tests package + uses: actions/upload-artifact@v3 + with: + name: openvino_tests + path: ${{ env.BUILD_DIR }}/openvino_tests.zip + if-no-files-found: 'error' + + Samples: + needs: Build + defaults: + run: + shell: pwsh + runs-on: windows-latest-8-cores + env: + INSTALL_DIR: "${{ github.workspace }}\\install" + INSTALL_TEST_DIR: "${{ github.workspace }}\\install\\tests" + SAMPLES_INSTALL_DIR: "${{ github.workspace }}\\install\\samples" + BUILD_DIR: "${{ github.workspace }}\\build" + + steps: + - name: Download OpenVINO package + uses: actions/download-artifact@v3 + with: + name: openvino_package + path: ${{ env.INSTALL_DIR }} + + - name: Download OpenVINO tests package + uses: actions/download-artifact@v3 + with: + name: openvino_tests + path: ${{ env.INSTALL_TEST_DIR }} + + - name: Extract OpenVINO packages + run: | + pushd ${{ env.INSTALL_DIR }} + Expand-Archive openvino_package.zip -DestinationPath "${{ env.INSTALL_DIR }}" + popd + pushd ${{ env.INSTALL_TEST_DIR }} + Expand-Archive openvino_tests.zip -DestinationPath "${{ env.INSTALL_DIR }}" + popd + + - uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + - name: Build cpp samples run: | - & {{ env.VCVARSPATH }} x64 - & ${{ env.SAMPLES_INSTALL_DIR }}/cpp/build_samples_msvc.bat -i ${{ env.INSTALL_DIR }} + & ${{ env.SAMPLES_INSTALL_DIR }}/cpp/build_samples_msvc.bat -i ${{ env.INSTALL_DIR }} -b ${{ env.BUILD_DIR }}/cpp_samples + env: + CMAKE_COMPILE_WARNING_AS_ERROR: 'ON' - name: Build c samples run: | - & {{ env.VCVARSPATH }} x64 - & ${{ env.SAMPLES_INSTALL_DIR }}/c/build_samples_msvc.bat -i ${{ env.INSTALL_DIR }} + & ${{ env.SAMPLES_INSTALL_DIR }}/c/build_samples_msvc.bat -i ${{ env.INSTALL_DIR }} -b ${{ env.BUILD_DIR }}/c_samples - name: Samples tests shell: cmd @@ -217,31 +237,16 @@ jobs: SHARE: ${{ env.INSTALL_TEST_DIR }}/smoke_tests/samples_smoke_tests_data WORKSPACE: ${{ env.INSTALL_DIR }} - # Present in the "Build" job due to the fact that these tests require build directory - - name: ONNX frontend tests - shell: cmd - run: | - call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_onnx_frontend_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU* --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ONNXFrontend.xml - - - name: List installed files - run: | - Get-ChildItem -Recurse -Directory ${{ env.INSTALL_DIR }} - - - name: Upload openvino package - uses: actions/upload-artifact@v3 - with: - name: openvino_package - path: ${{ env.BUILD_DIR }}/openvino_package.zip - if-no-files-found: 'error' - - - name: Upload openvino tests package + - name: Upload Test Results uses: actions/upload-artifact@v3 + if: ${{ !cancelled() }} with: - name: openvino_tests - path: ${{ env.BUILD_DIR }}/openvino_tests.zip + name: test-results-samples + path: ${{ env.INSTALL_TEST_DIR }}/TEST*.xml if-no-files-found: 'error' Python_Unit_Tests: + name: Python unit tests needs: Build defaults: run: @@ -252,17 +257,10 @@ jobs: OPENVINO_CONTRIB_REPO: "${{ github.workspace }}\\openvino_contrib" INSTALL_DIR: "${{ github.workspace }}\\install" INSTALL_TEST_DIR: "${{ github.workspace }}\\install\\tests" - SAMPLES_INSTALL_DIR: "${{ github.workspace }}\\install\\samples" LAYER_TESTS_INSTALL_DIR: "${{ github.workspace }}\\install\\tests\\layer_tests" - BUILD_DIR: "${{ github.workspace }}\\build" PYTHON_STATIC_ARGS: -m "not dynamic_library and not template_plugin" steps: - - name: Create Directories - run: | - mkdir ${{ env.INSTALL_DIR }} - mkdir ${{ env.INSTALL_TEST_DIR }} - - name: Download OpenVINO package uses: actions/download-artifact@v3 with: @@ -281,15 +279,9 @@ jobs: Expand-Archive openvino_package.zip -DestinationPath "${{ env.INSTALL_DIR }}" popd pushd ${{ env.INSTALL_TEST_DIR }} - Expand-Archive openvino_tests.zip -DestinationPath "${{ env.INSTALL_TEST_DIR }}" + Expand-Archive openvino_tests.zip -DestinationPath "${{ env.INSTALL_DIR }}" popd - - name: Check extraction - run: | - ls "${{ github.workspace }}" - ls "${{ env.INSTALL_DIR }}" - ls "${{ env.INSTALL_TEST_DIR }}" - - name: Clone OpenVINO uses: actions/checkout@v4 with: @@ -297,107 +289,85 @@ jobs: - uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: ${{ env.PYTHON_VERSION }} - - name: Install python dependencies + - name: Install Python API tests dependencies run: | - # For Python API - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/wheel/requirements-dev.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/requirements.txt - - # For running Python API tests - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/src/compatibility/openvino/requirements-dev.txt - - # For running ONNX frontend unit tests - python3 -m pip install --force-reinstall -r ${{ env.OPENVINO_REPO }}/src/frontends/onnx/tests/requirements.txt - - # For running TensorFlow frontend unit tests - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/frontends/tensorflow/tests/requirements.txt - - # For running Paddle frontend unit tests - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/frontends/paddle/tests/requirements.txt + # For torchvision to OpenVINO preprocessing converter + python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/src/openvino/preprocess/torchvision/requirements.txt - python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt + # TODO: replace with Python API tests requirements + python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_dev.txt - - name: Install MO dependencies + - name: Install OpenVINO Python wheels run: | - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_mxnet.txt ` - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_caffe.txt ` - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_kaldi.txt ` - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_onnx.txt ` - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_tf2.txt ` - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_dev.txt + # Find and install the core OV wheel + $ovCoreWheelPath=Get-ChildItem -Path "${{ env.INSTALL_DIR }}\tools" -Filter openvino-*.whl | % { $_.FullName } + python3 -m pip install "$ovCoreWheelPath" - - name: Install Python wheels - run: | - python3 -m pip install openvino-dev --force-reinstall --find-links=${{ env.INSTALL_DIR }}\tools + # Find and install the dev OV wheel + $ovDevWheelPath=Get-ChildItem -Path "${{ env.INSTALL_DIR }}\tools" -Filter openvino_dev*.whl | % { $_.FullName } + python3 -m pip install "$ovDevWheelPath[mxnet,caffe,kaldi,onnx,tensorflow2,pytorch]" - name: Python API 1.0 Tests shell: cmd run: | - set PYTHONPATH=${{ env.OPENVINO_REPO }}\tools\mo;${{ env.LAYER_TESTS_INSTALL_DIR }};%PYTHONPATH% - call "${{ env.INSTALL_DIR }}\\setupvars.bat" && python3 -m pytest -s ${{ env.INSTALL_TEST_DIR }}/pyngraph ${{ env.PYTHON_STATIC_ARGS }} --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-Pyngraph.xml --ignore=${{ env.INSTALL_TEST_DIR }}/pyngraph/tests_compatibility/test_onnx/test_zoo_models.py --ignore=${{ env.INSTALL_TEST_DIR }}/pyngraph/tests_compatibility/test_onnx/test_backend.py + python3 -m pytest -s ${{ env.INSTALL_TEST_DIR }}/pyngraph ${{ env.PYTHON_STATIC_ARGS }} --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-Pyngraph.xml --ignore=${{ env.INSTALL_TEST_DIR }}/pyngraph/tests_compatibility/test_onnx/test_zoo_models.py - name: Python API 2.0 Tests shell: cmd run: | - set PYTHONPATH=${{ env.OPENVINO_REPO }}\tools\mo;${{ env.LAYER_TESTS_INSTALL_DIR }};%PYTHONPATH% - call "${{ env.INSTALL_DIR }}\\setupvars.bat" && python3 -m pytest -sv ${{ env.INSTALL_TEST_DIR }}/pyopenvino ${{ env.PYTHON_STATIC_ARGS }} --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-Pyngraph.xml --ignore=${{ env.INSTALL_TEST_DIR }}/pyopenvino/tests/test_utils/test_utils.py + set PYTHONPATH=${{ env.LAYER_TESTS_INSTALL_DIR }};%PYTHONPATH% + python3 -m pytest -sv ${{ env.INSTALL_TEST_DIR }}/pyopenvino ${{ env.PYTHON_STATIC_ARGS }} --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-Pyngraph.xml --ignore=${{ env.INSTALL_TEST_DIR }}/pyopenvino/tests/test_utils/test_utils.py - name: Model Optimizer UT shell: cmd run: | + python3 -m pytest -s ${{ env.INSTALL_TEST_DIR }}/mo/unit_tests --ignore=${{ env.INSTALL_TEST_DIR }}/mo/unit_tests/mo/front/mxnet --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-ModelOptimizer.xml - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_mxnet.txt ^ - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_caffe.txt ^ - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_kaldi.txt ^ - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_onnx.txt ^ - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_tf2.txt ^ - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_dev.txt - - set PYTHONPATH=${{ env.OPENVINO_REPO }}\tools\mo;${{ env.LAYER_TESTS_INSTALL_DIR }};${{ env.INSTALL_TEST_DIR }};${{ env.INSTALL_DIR }}\python\python3.11;%PYTHONPATH% - - call "${{ env.INSTALL_DIR }}\\setupvars.bat" && python3 -m pytest -s ${{ env.INSTALL_TEST_DIR }}/mo/unit_tests --ignore=${{ env.INSTALL_TEST_DIR }}/mo/unit_tests/mo/front/mxnet --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-ModelOptimizer.xml - -# Ticket - 115085 -# - name: PyTorch Layer Tests -# shell: cmd -# run: | -# -# python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_mxnet.txt ^ -# -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_caffe.txt ^ -# -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_kaldi.txt ^ -# -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_onnx.txt ^ -# -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_tf2.txt ^ -# -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_dev.txt -# -# python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt -# -# set PYTHONPATH=${{ env.OPENVINO_REPO }}\tools\mo;${{ env.LAYER_TESTS_INSTALL_DIR }};%PYTHONPATH% -# -# call "${{ env.INSTALL_DIR }}\\setupvars.bat" && python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/pytorch_tests -m precommit --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-pytorch.xml -# env: -# TEST_DEVICE: CPU + # Ticket - 115085 + - name: PyTorch Layer Tests + if: ${{ 'false' }} + shell: cmd + run: | + python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt + python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/pytorch_tests -m precommit --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-pytorch.xml + env: + TEST_DEVICE: CPU - - name: TensorFlow 1 Layer Tests - TF FE + - name: ONNX Layer Tests shell: cmd run: | python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt + :: requires 'unit_tests' from 'tools/mo' set PYTHONPATH=${{ env.OPENVINO_REPO }}\tools\mo;${{ env.LAYER_TESTS_INSTALL_DIR }};%PYTHONPATH% + python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/onnx_tests -m "not launch_only_if_manually_specified and precommit" --junitxml=${INSTALL_TEST_DIR}/TEST-onnx.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP16 + + - name: TensorFlow 1 Layer Tests - TF FE + shell: cmd + run: | + python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt - call "${{ env.INSTALL_DIR }}\\setupvars.bat" && python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow_tests/ --use_new_frontend -m precommit_tf_fe --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tf_fe.xml + :: requires 'unit_tests' from 'tools/mo' + set PYTHONPATH=${{ env.OPENVINO_REPO }}\tools\mo;${{ env.LAYER_TESTS_INSTALL_DIR }};%PYTHONPATH% + python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow_tests/ --use_new_frontend -m precommit_tf_fe --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tf_fe.xml env: TEST_DEVICE: CPU + TEST_PRECISION: FP16 - name: TensorFlow 2 Layer Tests - TF FE shell: cmd run: | python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt + :: requires 'unit_tests' from 'tools/mo' set PYTHONPATH=${{ env.OPENVINO_REPO }}\tools\mo;${{ env.LAYER_TESTS_INSTALL_DIR }};%PYTHONPATH% - call "${{ env.INSTALL_DIR }}\\setupvars.bat" && python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow2_keras_tests/ --use_new_frontend -m precommit_tf_fe --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tf2_fe.xml + python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow2_keras_tests/ --use_new_frontend -m precommit_tf_fe --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tf2_fe.xml env: TEST_DEVICE: CPU @@ -405,60 +375,68 @@ jobs: shell: cmd run: | python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt - - set PYTHONPATH=${{ env.OPENVINO_REPO }}\tools\mo;${{ env.LAYER_TESTS_INSTALL_DIR }};%PYTHONPATH% - - call "${{ env.INSTALL_DIR }}\\setupvars.bat" && python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow_tests/test_tf_Roll.py --ir_version=10 --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tf_Roll.xml + python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow_tests/test_tf_Roll.py --ir_version=10 --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tf_Roll.xml - name: TensorFlow 2 Layer Tests - Legacy FE shell: cmd run: | python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt - - set PYTHONPATH=${{ env.OPENVINO_REPO }}\tools\mo;${{ env.LAYER_TESTS_INSTALL_DIR }};%PYTHONPATH% - - call "${{ env.INSTALL_DIR }}\\setupvars.bat" && python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow2_keras_tests/test_tf2_keras_activation.py --ir_version=11 --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tf2_Activation.xml -k "sigmoid" + python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow2_keras_tests/test_tf2_keras_activation.py --ir_version=11 --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tf2_Activation.xml -k "sigmoid" env: TEST_DEVICE: CPU + TEST_PRECISION: FP16 - name: TensorFlow Lite Layer Tests - TFL FE shell: cmd run: | python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt + python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow_lite_tests/ --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tfl_fe.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP16 - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_mxnet.txt ^ - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_caffe.txt ^ - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_kaldi.txt ^ - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_onnx.txt ^ - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_tf2.txt ^ - -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_dev.txt + - name: Python ONNX operators tests + shell: cmd + run: | + :: Skip test_onnx/test_zoo_models and test_onnx/test_backend due to long execution time - ONNX Model Zoo tests are run separately + python3 -m pytest ${{ env.OPENVINO_REPO }}/src/frontends/onnx/tests -k "not cuda" ^ + --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-onnx_frontend.xml ^ + --ignore=${{ env.OPENVINO_REPO }}/src/frontends/onnx/tests/test_python/test_zoo_models.py - set PYTHONPATH=${{ env.OPENVINO_REPO }}\tools\mo;${{ env.LAYER_TESTS_INSTALL_DIR }};%PYTHONPATH% + - name: MO Python API Tests + shell: cmd + run: | + python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt - call "${{ env.INSTALL_DIR }}\\setupvars.bat" && python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow_lite_tests/ --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tfl_fe.xml + :: TODO: remove setupvars.bat from here; currently, it's used for 'test_utils' installed in '/python/openvino' + call "${{ env.INSTALL_DIR }}\\setupvars.bat" && python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/mo_python_api_tests --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-test_mo_convert.xml env: TEST_DEVICE: CPU + TEST_PRECISION: FP16 - - name: MO Python API Tests + - name: OVC Python API Tests shell: cmd run: | python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt - set PYTHONPATH=${{ env.OPENVINO_REPO }}\tools\mo;${{ env.LAYER_TESTS_INSTALL_DIR }};%PYTHONPATH% - - call "${{ env.INSTALL_DIR }}\\setupvars.bat" && python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/mo_python_api_tests --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-test_mo_convert.xml + :: TODO: remove setupvars.sh from here; currently, it's used for 'test_utils' installed in '/python/openvino' + call "${{ env.INSTALL_DIR }}\\setupvars.bat" && python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/ovc_python_api_tests --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-test_ovc_convert.xml env: TEST_DEVICE: CPU + TEST_PRECISION: FP16 - name: Python Frontend tests shell: cmd run: | python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt - set PYTHONPATH=${{ env.OPENVINO_REPO }}\tools\mo;${{ env.LAYER_TESTS_INSTALL_DIR }};%PYTHONPATH% - call "${{ env.INSTALL_DIR }}\\setupvars.bat" && python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/py_frontend_tests --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-test_py_fontend.xml + # TODO: install to 'tests' component via cpack + - name: OVC unit tests + shell: cmd + run: python3 -m pytest -s ${{ env.OPENVINO_REPO }}/tools/ovc/unit_tests --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-OpenVinoConversion.xml + - name: Upload Test Results uses: actions/upload-artifact@v3 if: ${{ !cancelled() }} @@ -468,6 +446,7 @@ jobs: if-no-files-found: 'error' CXX_Unit_Tests: + name: C++ unit tests needs: Build defaults: run: @@ -478,11 +457,6 @@ jobs: INSTALL_TEST_DIR: "${{ github.workspace }}\\install\\tests" steps: - - name: Create Directories - run: | - mkdir ${{ env.INSTALL_DIR }} - mkdir ${{ env.INSTALL_TEST_DIR }} - - name: Download OpenVINO package uses: actions/download-artifact@v3 with: @@ -501,15 +475,9 @@ jobs: Expand-Archive openvino_package.zip -DestinationPath "${{ env.INSTALL_DIR }}" popd pushd ${{ env.INSTALL_TEST_DIR }} - Expand-Archive openvino_tests.zip -DestinationPath "${{ env.INSTALL_TEST_DIR }}" + Expand-Archive openvino_tests.zip -DestinationPath "${{ env.INSTALL_DIR }}" popd - - name: Check extraction - run: | - ls "${{ github.workspace }}" - ls "${{ env.INSTALL_DIR }}" - ls "${{ env.INSTALL_TEST_DIR }}" - - name: OpenVINO Core unit tests shell: cmd run: | @@ -540,17 +508,18 @@ jobs: run: | call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_ir_frontend_tests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-IRFrontend.xml - # - name: PaddlePaddle frontend tests # Disabled in Azure: https://github.com/openvinotoolkit/openvino/blob/master/.ci/azure/linux.yml#L403 - # shell: cmd - # run: | - # call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/paddle_tests --gtest_print_time=1 --gtest_filter=*smoke* --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-PaddleTests.xml + - name: PaddlePaddle frontend tests # Disabled in Azure: https://github.com/openvinotoolkit/openvino/blob/master/.ci/azure/linux.yml#L403 + if: ${{ 'false' }} + shell: cmd + run: | + call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/paddle_tests --gtest_print_time=1 --gtest_filter=*smoke* --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-PaddleTests.xml - # - name: ONNX frontend tests # Present in the "Build" job due to the fact that these tests require build directory - # shell: cmd - # run: | - # call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_onnx_frontend_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU* --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ONNXFrontend.xml + - name: ONNX frontend tests + shell: cmd + run: | + call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_onnx_frontend_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU* --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ONNXFrontend.xml - - name: TensorFlow Common tests + - name: TensorFlow Common frontend tests shell: cmd run: | call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_tensorflow_common_tests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-TensorFlowCommonFrontend.xml @@ -565,11 +534,21 @@ jobs: run: | call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_tensorflow_lite_frontend_tests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-TensorFlowLiteFrontend.xml - - name: Transformations Tests + - name: Transformations func tests shell: cmd 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 + 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 + 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: | @@ -585,22 +564,30 @@ jobs: run: | call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_cpu_unit_tests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-CPUUnitTests.xml - # - name: GNA plugin unit tests # Disabled in Azure: https://github.com/openvinotoolkit/openvino/blob/master/.ci/azure/linux.yml#L434 - # 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: SubgraphsDumper tests + run: | + call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/subgraphsDumperTests --gtest_print_time=1 --gtest_print_time=1 --device=TEMPLATE --gtest_filter="*OpImpl*" --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-SubgraphsDumperTests.xml + + - name: Template OpImpl tests + run: | + call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/conformanceTests --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-TemplateOpImplTests.xml + + - name: GNA plugin unit tests + 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 UT + - name: AUTO unit tests shell: cmd run: | call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_auto_unit_tests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ov_auto_unit_tests.xml - - name: AUTO FuncTests + - name: AUTO func Tests shell: cmd run: | call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_auto_func_tests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ov_auto_func_tests.xml - - name: Template plugin tests + - name: Template plugin func tests shell: cmd run: | call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_template_func_tests --gtest_print_time=1 --gtest_filter=*smoke* --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-TemplateFuncTests.xml @@ -615,12 +602,17 @@ jobs: run: | call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_capi_test --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-OpenVINOCAPITests.xml - - name: AutoBatch FuncTests + - name: AutoBatch unit tests + shell: cmd + run: | + call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_auto_batch_unit_tests --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ov_auto_batch_unit_tests.xml + + - name: AutoBatch func tests shell: cmd run: | call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_auto_batch_func_tests --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ov_auto_batch_func_tests.xml - - name: Proxy Plugin Tests + - name: Proxy Plugin func tests shell: cmd run: | call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_proxy_plugin_tests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-OVProxyTests.xml @@ -644,6 +636,7 @@ jobs: if-no-files-found: 'error' CPU_Functional_Tests: + name: CPU functional tests needs: Build defaults: run: @@ -656,11 +649,6 @@ jobs: PARALLEL_TEST_CACHE: "${{ github.workspace }}\\install\\tests\\test_cache.lst" steps: - - name: Create Directories - run: | - mkdir ${{ env.INSTALL_DIR }} - mkdir ${{ env.INSTALL_TEST_DIR }} - - name: Download OpenVINO package uses: actions/download-artifact@v3 with: @@ -679,20 +667,16 @@ jobs: Expand-Archive openvino_package.zip -DestinationPath "${{ env.INSTALL_DIR }}" popd pushd ${{ env.INSTALL_TEST_DIR }} - Expand-Archive openvino_tests.zip -DestinationPath "${{ env.INSTALL_TEST_DIR }}" + Expand-Archive openvino_tests.zip -DestinationPath "${{ env.INSTALL_DIR }}" popd - - name: Check extraction - run: | - ls "${{ github.workspace }}" - ls "${{ env.INSTALL_DIR }}" - ls "${{ env.INSTALL_TEST_DIR }}" + - uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} - name: Install python dependencies shell: cmd - run: | - python3 -m pip install --upgrade pip - python3 -m pip install -r ${{ github.workspace }}\install\tests\functional_test_utils\layer_tests_summary\requirements.txt + run: python3 -m pip install -r ${{ github.workspace }}\install\tests\functional_test_utils\layer_tests_summary\requirements.txt - name: Restore tests execution time uses: actions/cache/restore@v3 @@ -722,9 +706,11 @@ jobs: name: test-results-functional-cpu path: | ${{ env.INSTALL_TEST_DIR }}/temp/*.log + ${{ env.INSTALL_TEST_DIR }}/logs/*.log ${{ env.INSTALL_TEST_DIR }}/logs/failed/*.log ${{ env.INSTALL_TEST_DIR }}/logs/crashed/*.log ${{ env.INSTALL_TEST_DIR }}/logs/hanged/*.log ${{ env.INSTALL_TEST_DIR }}/logs/interapted/*.log - ${{ env.INSTALL_TEST_DIR }}/logs/*.log + ${{ env.INSTALL_TEST_DIR }}/logs/hash_table.csv + ${{ env.PARALLEL_TEST_CACHE }} if-no-files-found: 'error' diff --git a/.github/workflows/windows_conditional_compilation.yml b/.github/workflows/windows_conditional_compilation.yml index fabd763e1a3f2d..f0a9741aee9537 100644 --- a/.github/workflows/windows_conditional_compilation.yml +++ b/.github/workflows/windows_conditional_compilation.yml @@ -1,4 +1,4 @@ -name: Tests on Windows Conditional Compilation (VS 2022, Python 3.11) +name: Windows Conditional Compilation (VS 2022, Python 3.11) on: workflow_dispatch: schedule: @@ -24,36 +24,30 @@ on: # - master concurrency: - group: ${{ github.head_ref || github.run_id }}-windows-cc + # github.ref is not unique in post-commit + group: ${{ github.event_name == 'push' && github.run_id || github.ref }}-windows-cc cancel-in-progress: true env: - CMAKE_BUILD_TYPE: 'Release' - CMAKE_GENERATOR: 'Ninja' - CMAKE_CXX_COMPILER_LAUNCHER: sccache - CMAKE_C_COMPILER_LAUNCHER: sccache - OPENVINO_REPO: "${{ github.workspace }}\\openvino" - OPENVINO_CONTRIB_REPO: "${{ github.workspace }}\\openvino_contrib" - INSTALL_DIR: "${{ github.workspace }}\\install_pkg" - INSTALL_TEST_DIR: "${{ github.workspace }}\\install\\tests" - SAMPLES_INSTALL_DIR: "${{ github.workspace }}\\install\\samples" - LAYER_TESTS_INSTALL_DIR: "${{ github.workspace }}\\install\\tests\\layer_tests" - BUILD_DIR: "${{ github.workspace }}\\build" - BUILD_DIR_2: "${{ github.workspace }}\\build_s" - MODELS_PATH: "${{ github.workspace }}\\testdata" - OV_TEMP: "${{ github.workspace }}\\openvino_temp" - BUILD_TYPE: "Release" - PYTHON_STATIC_ARGS: -m "not dynamic_library and not template_plugin" - VCVARSPATH: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvarsall.bat" + PYTHON_VERSION: '3.11' jobs: Build: - # TODO: remove. Temporary measure to prevent the workflow from scheduling on forks. - if: ${{ github.repository_owner == 'openvinotoolkit' }} defaults: run: shell: pwsh runs-on: windows-latest-8-cores + env: + CMAKE_BUILD_TYPE: 'Release' + CMAKE_GENERATOR: 'Ninja Multi-Config' + CMAKE_CXX_COMPILER_LAUNCHER: sccache + CMAKE_C_COMPILER_LAUNCHER: sccache + OPENVINO_REPO: "${{ github.workspace }}\\openvino" + INSTALL_DIR: "${{ github.workspace }}\\openvino_install" + INSTALL_TEST_DIR: "${{ github.workspace }}\\tests_install" + BUILD_DIR: "${{ github.workspace }}\\openvino_build" + MODELS_PATH: "${{ github.workspace }}\\testdata" + SELECTIVE_BUILD_STAT_DIR: "${{ github.workspace }}\\selective_build_stat" steps: - name: Clone OpenVINO uses: actions/checkout@v4 @@ -67,6 +61,7 @@ jobs: repository: 'openvinotoolkit/testdata' path: 'testdata' lfs: 'true' + ref: 'master' # # Dependencies @@ -74,21 +69,17 @@ jobs: - uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: ${{ env.PYTHON_VERSION }} - name: Install build dependencies - run: | - choco install --no-progress ninja + run: choco install --no-progress ninja # # Build # - - name: Get number of CPU cores - uses: SimenB/github-actions-cpu-cores@v2 - id: cpu-cores - - - uses: ilammy/msvc-dev-cmd@v1 + - name: Configure Developer Command Prompt for Microsoft Visual C++ + uses: ilammy/msvc-dev-cmd@v1 - name: Setup sccache uses: hendrikmuhs/ccache-action@v1.2 @@ -98,71 +89,227 @@ jobs: # Should save cache only if run in the master branch of the base repo # github.ref_name is 'ref/PR_#' in case of the PR, and 'branch_name' when executed on push save: ${{ github.ref_name == 'master' && 'true' || 'false' }} - key: ${{ github.job }}-windows-cc + key: ${{ github.job }}-${{ runner.os }}-itt restore-keys: | - ${{ github.job }}-windows-cc + ${{ github.job }}-${{ runner.os }}-itt - - name: CMake CC COLLECT + - name: CMake configure - CC COLLECT run: | - & "${{ env.VCVARSPATH }}" x64 && cmake -G Ninja ` + cmake -G "${{ env.CMAKE_GENERATOR }}" ` + -DBUILD_SHARED_LIBS=OFF ` + -DENABLE_TESTS=ON ` -DENABLE_CPPLINT=OFF ` - -DENABLE_GAPI_PREPROCESSING=OFF ` - -DENABLE_PLUGINS_XML=ON ` - -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF ` - -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} ` + -DENABLE_NCC_STYLE=OFF ` + -DENABLE_INTEL_GNA=OFF ` + -DCMAKE_COMPILE_WARNING_AS_ERROR=ON ` -DENABLE_PROFILING_ITT=ON ` -DSELECTIVE_BUILD=COLLECT ` + -DCMAKE_DISABLE_FIND_PACKAGE_PkgConfig=ON ` -S ${{ env.OPENVINO_REPO }} ` -B ${{ env.BUILD_DIR }} - - name: Build CC COLLECT + - name: Cmake build - CC COLLECT run: | - & "${{ env.VCVARSPATH }}" x64 && cmake --build ${{ env.BUILD_DIR }} --parallel ${{ steps.cpu-cores.outputs.count }} --config ${{ env.BUILD_TYPE }} ` - --target openvino_intel_cpu_plugin openvino_ir_frontend benchmark_app sea_itt_lib + cmake --build ${{ env.BUILD_DIR }} --parallel --config ${{ env.CMAKE_BUILD_TYPE }} + cmake --build ${{ env.BUILD_DIR }} --parallel --config ${{ env.CMAKE_BUILD_TYPE }} --target sea_itt_lib - - name: List bin files + - name: Cmake install - OpenVINO + run: cmake -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -P ${{ env.BUILD_DIR }}/cmake_install.cmake + + - name: Build C++ samples - OpenVINO build tree + run: | + cmake -G "${{ env.CMAKE_GENERATOR }}" -DOpenVINO_DIR=${{ env.BUILD_DIR }} -S ${{ env.INSTALL_DIR }}/samples/cpp -B ${{ env.BUILD_DIR }}/cpp_samples + cmake --build ${{ env.BUILD_DIR }}/cpp_samples --parallel --config ${{ env.CMAKE_BUILD_TYPE }} --target hello_query_device + + - name: Build C samples - OpenVINO install tree + run: | + & ${{ env.INSTALL_DIR }}/samples/c/build_samples_msvc.bat -i ${{ env.INSTALL_DIR }} -b ${{ env.BUILD_DIR }}/c_samples + + - name: Ctest - OpenVINO unit tests shell: cmd - run: dir ${{ env.OPENVINO_REPO }}\bin\ /s + run: | + set path=%path%;${{ env.OPENVINO_REPO }}\temp\tbb\bin + ctest -C ${{ env.CMAKE_BUILD_TYPE }} --test-dir ${{ env.BUILD_DIR }} -V -L UNIT - - name: Code usage analysis + - name: Perform code tracing via ITT collector shell: cmd - working-directory: ${{ env.OPENVINO_REPO }} run: | set path=%path%;${{ env.OPENVINO_REPO }}\temp\tbb\bin - call "${{ env.VCVARSPATH }}" && python thirdparty\itt_collector\runtool\sea_runtool.py --bindir ${{ env.OPENVINO_REPO }}\bin\intel64\${{ env.BUILD_TYPE }} -o ${{ env.BUILD_DIR }}\itt_stat ! ${{ env.OPENVINO_REPO }}\bin\intel64\${{ env.BUILD_TYPE }}\benchmark_app.exe -niter 1 -nireq 1 -m ${{ env.MODELS_PATH }}\models\test_model\test_model_fp32.xml -d CPU + + python3 ${{ env.OPENVINO_REPO }}\thirdparty\itt_collector\runtool\sea_runtool.py ^ + --bindir ${{ env.OPENVINO_REPO }}\bin\intel64\${{ env.CMAKE_BUILD_TYPE }} ^ + -o ${{ env.SELECTIVE_BUILD_STAT_DIR }}\itt_stat ! ${{ env.OPENVINO_REPO }}\bin\intel64\${{ env.CMAKE_BUILD_TYPE }}\benchmark_app.exe ^ + -niter 1 ^ + -nireq 1 ^ + -m ${{ env.MODELS_PATH }}\models\test_model\test_model_fp32.xml ^ + -d CPU + + - name: List bin files + shell: cmd + run: dir ${{ env.OPENVINO_REPO }}\bin\ /s - - name: List csv files + - name: List install files shell: cmd - run: dir ${{ env.BUILD_DIR }}\*.csv /s /p + run: dir ${{ env.INSTALL_DIR }} /s - - name: CMake CC ON + - name: Pack Artifacts run: | - & "${{ env.VCVARSPATH }}" x64 && cmake -G "Visual Studio 17 2022" ` - -DCMAKE_VERBOSE_MAKEFILE=ON ` + $file=Get-ChildItem -Path "${{ env.SELECTIVE_BUILD_STAT_DIR }}" + $compress = @{ + Path = $file + CompressionLevel = "Optimal" + DestinationPath = "${{ env.BUILD_DIR }}/openvino_selective_build_stat.zip" + } + Compress-Archive @compress + + $compress = @{ + Path = "${{ env.OPENVINO_REPO }}/bin/intel64/${{ env.CMAKE_BUILD_TYPE }}/ov_cpu_func_tests.exe", "${{ env.OPENVINO_REPO }}/src/tests/test_utils/functional_test_utils/layer_tests_summary", "${{ env.INSTALL_DIR }}/runtime/3rdparty/tbb" + CompressionLevel = "Optimal" + DestinationPath = "${{ env.BUILD_DIR }}/openvino_tests.zip" + } + Compress-Archive @compress + + - name: Upload selective build statistics package + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: + name: openvino_selective_build_stat + path: ${{ env.BUILD_DIR }}/openvino_selective_build_stat.zip + if-no-files-found: 'error' + + - name: Upload OpenVINO tests package + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: + name: openvino_tests + path: ${{ env.BUILD_DIR }}/openvino_tests.zip + if-no-files-found: 'error' + + CC_Build: + name: Conditional Compilation + needs: Build + defaults: + run: + shell: pwsh + runs-on: windows-latest-8-cores + env: + CMAKE_BUILD_TYPE: 'Release' + CMAKE_CXX_COMPILER_LAUNCHER: sccache + CMAKE_C_COMPILER_LAUNCHER: sccache + OPENVINO_REPO: "${{ github.workspace }}\\openvino" + BUILD_DIR: "${{ github.workspace }}\\openvino_build" + MODELS_PATH: "${{ github.workspace }}\\testdata" + SELECTIVE_BUILD_STAT_DIR: "${{ github.workspace }}\\selective_build_stat" + steps: + - name: Clone OpenVINO + uses: actions/checkout@v4 + with: + path: 'openvino' + submodules: 'true' + + - name: Clone test models + uses: actions/checkout@v4 + with: + repository: 'openvinotoolkit/testdata' + path: 'testdata' + lfs: 'true' + ref: 'master' + + - name: Download selective build statistics package + uses: actions/download-artifact@v3 + with: + name: openvino_selective_build_stat + path: ${{ env.SELECTIVE_BUILD_STAT_DIR }} + + - name: Extract selective build statistics package + run: Expand-Archive ${{ env.SELECTIVE_BUILD_STAT_DIR }}/openvino_selective_build_stat.zip -DestinationPath "${{ env.SELECTIVE_BUILD_STAT_DIR }}" + + - name: CMake configure - CC ON + run: | + cmake ` + -DBUILD_SHARED_LIBS=OFF ` -DENABLE_CPPLINT=OFF ` - -DENABLE_GAPI_PREPROCESSING=OFF ` - -DENABLE_PROFILING_ITT=OFF ` -DSELECTIVE_BUILD=ON ` - -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF ` - -DSELECTIVE_BUILD_STAT=${{ env.BUILD_DIR }}\*.csv ` + -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 ` + -DENABLE_OV_PYTORCH_FRONTEND=OFF ` + -DENABLE_OV_ONNX_FRONTEND=OFF ` + -DSELECTIVE_BUILD_STAT=${{ env.SELECTIVE_BUILD_STAT_DIR }}\*.csv ` -S ${{ env.OPENVINO_REPO }} ` - -B ${{ env.BUILD_DIR_2 }} + -B ${{ env.BUILD_DIR }} - - name: Build CC ON - run: | - & "${{ env.VCVARSPATH }}" x64 && cmake --build ${{ env.BUILD_DIR_2 }} --parallel ${{ steps.cpu-cores.outputs.count }} --config ${{ env.BUILD_TYPE }} ` - --target openvino_intel_cpu_plugin openvino_ir_frontend benchmark_app + - name: Cmake build - CC ON + run: cmake --build ${{ env.BUILD_DIR }} --parallel --config ${{ env.CMAKE_BUILD_TYPE }} --target benchmark_app - - name: List bin files ON + - name: List bin files shell: cmd run: dir ${{ env.OPENVINO_REPO }}\bin\ /s - - name: Check conditional_compilation_gen.h header + - name: Run with CC-ed runtime shell: cmd - run: type ${{ env.BUILD_DIR_2 }}\src\common\conditional_compilation\conditional_compilation_gen.h + run: | + set path=%path%;${{ env.OPENVINO_REPO }}\temp\tbb\bin + ${{ env.OPENVINO_REPO }}\bin\intel64\${{ env.CMAKE_BUILD_TYPE }}\benchmark_app.exe -niter 1 -nireq 1 -m ${{ env.MODELS_PATH }}\models\test_model\test_model_fp32.xml -d CPU + + CPU_Functional_Tests: + name: CPU functional tests + needs: Build + defaults: + run: + shell: pwsh + runs-on: windows-latest-8-cores + env: + INSTALL_TEST_DIR: "${{ github.workspace }}\\tests_install" + PARALLEL_TEST_SCRIPT: "${{ github.workspace }}\\tests_install\\layer_tests_summary\\run_parallel.py" + PARALLEL_TEST_CACHE: "${{ github.workspace }}\\tests_install\\test_cache.lst" + + steps: + - name: Download OpenVINO tests package + uses: actions/download-artifact@v3 + with: + name: openvino_tests + path: ${{ env.INSTALL_TEST_DIR }} + + - name: Extract OpenVINO tests package + run: Expand-Archive ${{ env.INSTALL_TEST_DIR }}/openvino_tests.zip -DestinationPath "${{ env.INSTALL_TEST_DIR }}" - - name: Use OpenVINO after CC + - uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install python dependencies for run_parallel.py + run: python3 -m pip install -r ${{ env.INSTALL_TEST_DIR }}/layer_tests_summary/requirements.txt + + # Windows pipeline is in nightly mode, uncomment once there is a consistent cache creation + # - name: Restore tests execution time + # uses: actions/cache/restore@v3 + # with: + # path: ${{ env.PARALLEL_TEST_CACHE }} + # key: ${{ runner.os }}-tests-functional-cpu-stamp-${{ github.sha }} + # restore-keys: | + # ${{ runner.os }}-tests-functional-cpu-stamp + + - name: Intel CPU plugin func tests (parallel) shell: cmd run: | - set path=%path%;${{ env.OPENVINO_REPO }}\temp\tbb\bin - ${{ env.OPENVINO_REPO }}\bin\intel64\${{ env.BUILD_TYPE }}\benchmark_app.exe -niter 1 -nireq 1 -m ${{ env.MODELS_PATH }}\models\test_model\test_model_fp32.xml -d CPU + set path=%path%;${{ env.INSTALL_TEST_DIR }}\tbb\bin;${{ env.INSTALL_TEST_DIR }}\tbb + python3 ${{ env.PARALLEL_TEST_SCRIPT }} -e ${{ env.INSTALL_TEST_DIR }}\ov_cpu_func_tests.exe -w ${{ env.INSTALL_TEST_DIR }} -s suite -rf 0 -- --gtest_print_time=1 --gtest_filter=*smoke* + timeout-minutes: 45 + + - name: Upload Test Results + uses: actions/upload-artifact@v3 + if: ${{ !cancelled() }} + with: + name: test-results-functional-cpu + path: | + ${{ env.INSTALL_TEST_DIR }}/TEST*.xml + ${{ env.INSTALL_TEST_DIR }}/logs/failed/*.log + ${{ env.INSTALL_TEST_DIR }}/logs/crashed/*.log + ${{ env.INSTALL_TEST_DIR }}/logs/hanged/*.log + ${{ env.INSTALL_TEST_DIR }}/logs/interapted/*.log + ${{ env.INSTALL_TEST_DIR }}/logs/disabled_tests.log + if-no-files-found: 'error' diff --git a/CMakeLists.txt b/CMakeLists.txt index b0aceaa39db057..82277e5c875cfb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,7 @@ endif() project(OpenVINO DESCRIPTION "OpenVINO toolkit") -find_package(IEDevScripts REQUIRED +find_package(OpenVINODeveloperScripts REQUIRED PATHS "${OpenVINO_SOURCE_DIR}/cmake/developer_package" NO_CMAKE_FIND_ROOT_PATH NO_DEFAULT_PATH) @@ -81,54 +81,55 @@ file(REMOVE "${CMAKE_BINARY_DIR}/ngraphTargets.cmake") file(REMOVE "${CMAKE_BINARY_DIR}/InferenceEngineTargets.cmake") file(REMOVE "${CMAKE_BINARY_DIR}/OpenVINOTargets.cmake") -# remove exported developer targets to force its regeneration -macro(ov_clean_dev_targets) - foreach(component IN LISTS openvino_export_components) - file(REMOVE "${CMAKE_BINARY_DIR}/${component}_dev_targets.cmake") - file(REMOVE "${CMAKE_BINARY_DIR}/ov_${component}_dev_targets.cmake") - unset(${component} CACHE) - endforeach() - unset(openvino_export_components CACHE) +# remove exported developer targets files to force its regeneration +macro(ov_clean_developer_package_targets) + file(REMOVE "${CMAKE_BINARY_DIR}/inference_engine_developer_package_targets.cmake") + file(REMOVE "${CMAKE_BINARY_DIR}/openvino_developer_package_targets.cmake") + unset(_OPENVINO_DEVELOPER_PACKAGE_TARGETS CACHE) unset(openvino_installed_targets CACHE) endmacro() -ov_clean_dev_targets() +ov_clean_developer_package_targets() -# -# Build -# +function(ov_developer_package_export_targets) + cmake_parse_arguments(EXPORT "" "TARGET;INSTALL_DESTIONATION" "INSTALL_INCLUDE_DIRECTORIES" ${ARGN}) -function(openvino_developer_export_targets) - cmake_parse_arguments(EXPORT "" "COMPONENT" "TARGETS" ${ARGN}) + # to allow exporting of aliased targets with the original names + if(TARGET "${EXPORT_TARGET}") + get_target_property(original_name ${EXPORT_TARGET} ALIASED_TARGET) + if(TARGET "${original_name}") + # replace target with its original name + set(EXPORT_TARGET ${original_name}) + endif() + list(APPEND _OPENVINO_DEVELOPER_PACKAGE_TARGETS ${EXPORT_TARGET}) - if(EXPORT_UNPARSED_ARGUMENTS) - message(FATAL_ERROR "openvino_developer_export_targets has unparsed arguments: ${EXPORT_UNPARSED_ARGUMENTS}") - endif() + if(EXPORT_INSTALL_INCLUDE_DIRECTORIES) + if(NOT EXPORT_INSTALL_DESTIONATION) + set(EXPORT_INSTALL_DESTIONATION "developer_package/include/${EXPORT_TARGET}") + endif() - set(${EXPORT_COMPONENT} "${${EXPORT_COMPONENT}};${EXPORT_TARGETS}") + target_include_directories(${EXPORT_TARGET} INTERFACE "$") - # to allow exporting of aliased targets with the original names - foreach(target_name IN LISTS ${EXPORT_COMPONENT}) - if(TARGET "${target_name}") - get_target_property(original_name ${target_name} ALIASED_TARGET) - if(TARGET "${original_name}") - list(REMOVE_ITEM ${EXPORT_COMPONENT} ${target_name}) - list(APPEND ${EXPORT_COMPONENT} ${original_name}) - endif() + foreach(install_dir IN LISTS EXPORT_INSTALL_INCLUDE_DIRECTORIES) + install(DIRECTORY "${install_dir}" + DESTINATION "${EXPORT_INSTALL_DESTIONATION}" + COMPONENT developer_package EXCLUDE_FROM_ALL) + endforeach() endif() - endforeach() - - list(REMOVE_DUPLICATES ${EXPORT_COMPONENT}) - set(${EXPORT_COMPONENT} "${${EXPORT_COMPONENT}}" CACHE INTERNAL - "A list of OpenVINO ${EXPORT_COMPONENT} exported targets" FORCE) + else() + message(FATAL_ERROR "Internal error: ${target_name} does not represent a cmake target") + endif() - list(APPEND openvino_export_components ${EXPORT_COMPONENT}) - list(REMOVE_DUPLICATES openvino_export_components) - set(openvino_export_components "${openvino_export_components}" CACHE INTERNAL - "A list of OpenVINO exported components" FORCE) + list(REMOVE_DUPLICATES _OPENVINO_DEVELOPER_PACKAGE_TARGETS) + set(_OPENVINO_DEVELOPER_PACKAGE_TARGETS "${_OPENVINO_DEVELOPER_PACKAGE_TARGETS}" CACHE INTERNAL + "A list of OpenVINO Developer Package exported targets" FORCE) endfunction() -# add target with processed tests model zoo +# +# Build +# + if(ENABLE_TESTS) + # add target with processed tests model zoo include(cmake/test_model_zoo.cmake) endif() @@ -162,4 +163,4 @@ endif() # provides a callback function to describe each component in repo include(cmake/packaging/packaging.cmake) -ie_cpack(${IE_CPACK_COMPONENTS_ALL}) +ov_cpack(${OV_CPACK_COMPONENTS_ALL}) diff --git a/README.md b/README.md index adc6f9f2b965ea..489ef7803ccd80 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 [Model Optimizer], [OpenVINO™ Runtime], [Post-Training Optimization Tool], 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, GNA, 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. @@ -48,8 +48,7 @@ source and public models in popular formats such as TensorFlow, ONNX, PaddlePadd * [python](./src/bindings/python) - Python API for OpenVINO™ Runtime * [Plugins](./src/plugins) - contains OpenVINO plugins which are maintained in open-source by the OpenVINO team. For more information, take a look at the [list of supported devices](#supported-hardware-matrix). * [Frontends](./src/frontends) - contains available OpenVINO frontends that allow reading models from the native framework format. -* [Model Optimizer] - is a cross-platform command-line tool that facilitates the transition between training and deployment environments, performs static model analysis, and adjusts deep learning models for optimal execution on end-point target devices. -* [Post-Training Optimization Tool] - is designed to accelerate the inference of deep learning models by applying special methods without model retraining or fine-tuning, for example, post-training 8-bit quantization. +* [OpenVINO Model Converter (OVC)] - is a cross-platform command-line tool that facilitates the transition between training and deployment environments, and adjusts deep learning models for optimal execution on end-point target devices. * [Samples] - applications in C, C++ and Python languages that show basic OpenVINO use cases. ## Supported Hardware matrix @@ -62,7 +61,7 @@ The OpenVINO™ Runtime can infer models on different hardware devices. This sec Device Plugin Library - ShortDescription + Short Description @@ -70,7 +69,7 @@ The OpenVINO™ Runtime can infer models on different hardware devices. This sec CPU Intel CPU openvino_intel_cpu_plugin - Intel Xeon with Intel® Advanced Vector Extensions 2 (Intel® AVX2), Intel® Advanced Vector Extensions 512 (Intel® AVX-512), and AVX512_BF16, Intel Core Processors with Intel AVX2, Intel Atom Processors with Intel® Streaming SIMD Extensions (Intel® SSE) + Intel Xeon with Intel® Advanced Vector Extensions 2 (Intel® AVX2), Intel® Advanced Vector Extensions 512 (Intel® AVX-512), and AVX512_BF16, Intel Core Processors with Intel AVX2, Intel Atom Processors with Intel® Streaming SIMD Extensions (Intel® SSE), Intel® Advanced Matrix Extensions (Intel® AMX) ARM CPU @@ -98,7 +97,7 @@ OpenVINO™ Toolkit also contains several plugins which simplify loading models Plugin Library - ShortDescription + Short Description @@ -129,6 +128,16 @@ OpenVINO™ Toolkit also contains several plugins which simplify loading models OpenVINO™ Toolkit is licensed under [Apache License Version 2.0](LICENSE). By contributing to the project, you agree to the license and copyright terms therein and release your contribution under these terms. +## Telemetry +OpenVINO™ collects software performance and usage data for the purpose of improving OpenVINO™ tools. This data is collected directly by OpenVINO™ or through the use of Google Analytics 4. +You can opt-out at any time by running the command: + +``` bash +opt_in_out --opt_out +``` + +More Information is available at https://docs.openvino.ai/latest/openvino_docs_telemetry_information.html. + ## Documentation ### User documentation @@ -196,6 +205,5 @@ Report questions, issues and suggestions, using: [Open Model Zoo]:https://github.com/openvinotoolkit/open_model_zoo [OpenVINO™ Runtime]:https://docs.openvino.ai/2023.1/openvino_docs_OV_UG_OV_Runtime_User_Guide.html -[Model Optimizer]:https://docs.openvino.ai/2023.1/openvino_docs_MO_DG_Deep_Learning_Model_Optimizer_DevGuide.html -[Post-Training Optimization Tool]:https://docs.openvino.ai/2023.1/pot_introduction.html +[OpenVINO Model Converter (OVC)]:https://docs.openvino.ai/2023.1/openvino_docs_model_processing_introduction.html#convert-a-model-in-cli-ovc [Samples]:https://github.com/openvinotoolkit/openvino/tree/master/samples diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 1d4210f300b058..257263f663bec6 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -5,7 +5,7 @@ cmake_policy(SET CMP0054 NEW) # TODO: fix it, outside of source dir MO cannot find TBB dependency -set_temp_directory(TEMP "${CMAKE_SOURCE_DIR}") +ov_set_temp_directory(TEMP "${CMAKE_SOURCE_DIR}") ## Intel OMP package if(THREADING STREQUAL "OMP") @@ -71,12 +71,16 @@ function(ov_download_tbb) if(NOT DEFINED ENV{TBBROOT} AND (DEFINED ENV{TBB_DIR} OR DEFINED TBB_DIR)) if(DEFINED ENV{TBB_DIR}) - set(TEMP_ROOT $ENV{TBB_DIR}) - elseif (DEFINED TBB_DIR) - set(TEMP_ROOT ${TBB_DIR}) + set(TBB_DIR "$ENV{TBB_DIR}") endif() + set(TEMP_ROOT "${TBB_DIR}") while(NOT EXISTS "${TEMP_ROOT}/include") - get_filename_component(TEMP_ROOT ${TEMP_ROOT} PATH) + get_filename_component(TEMP_ROOT_PARENT ${TEMP_ROOT} PATH) + if(TEMP_ROOT_PARENT STREQUAL TEMP_ROOT) + # to prevent recursion + message(FATAL_ERROR "${TBB_DIR} does not contain 'include' folder. Please, unset TBB_DIR") + endif() + set(TEMP_ROOT "${TEMP_ROOT_PARENT}") endwhile() set(TBBROOT ${TEMP_ROOT}) endif() @@ -100,10 +104,10 @@ function(ov_download_tbb) elseif(LINUX AND X86_64 AND OV_GLIBC_VERSION VERSION_GREATER_EQUAL 2.17) # build oneTBB 2021.2.1 with gcc 4.8 (glibc 2.17) RESOLVE_DEPENDENCY(TBB - ARCHIVE_LIN "oneapi-tbb-2021.2.3-lin.tgz" + ARCHIVE_LIN "oneapi-tbb-2021.2.3-lin-20231012.tgz" TARGET_PATH "${TEMP}/tbb" ENVIRONMENT "TBBROOT" - SHA256 "f3f2edd8e7875b02220f11ab5b201411d5af6822e525e8da5444b4a666514e8b" + SHA256 "6f39d18783b37fdcc15ca137fbf70bc78206848af1a510cada806279fae49718" USE_NEW_LOCATION TRUE) elseif(YOCTO_AARCH64) RESOLVE_DEPENDENCY(TBB @@ -131,10 +135,10 @@ function(ov_download_tbb) elseif(LINUX AND AARCH64 AND OV_GLIBC_VERSION VERSION_GREATER_EQUAL 2.17) # build oneTBB 2021.2.1 with gcc 4.8 (glibc 2.17) RESOLVE_DEPENDENCY(TBB - ARCHIVE_LIN "oneapi-tbb-2021.2.1-lin-arm64-canary.tgz" + ARCHIVE_LIN "oneapi-tbb-2021.2.1-lin-arm64-20231012.tgz" TARGET_PATH "${TEMP}/tbb" ENVIRONMENT "TBBROOT" - SHA256 "042fdac53be65841a970b05d892f4b20b556b06fd3b20d2d0068e49c4fd74f07" + SHA256 "cbb239cbda7ea2937cec7008c12fe628dd44488e1eafd9630f8814f9eb2c13e2" USE_NEW_LOCATION TRUE) elseif(APPLE AND AARCH64) # build oneTBB 2021.2.1 with export MACOSX_DEPLOYMENT_TARGET=11.0 @@ -200,10 +204,10 @@ function(ov_download_tbbbind_2_5) USE_NEW_LOCATION TRUE) elseif(LINUX AND X86_64) RESOLVE_DEPENDENCY(TBBBIND_2_5 - ARCHIVE_LIN "tbbbind_2_5_static_lin_v3.tgz" + ARCHIVE_LIN "tbbbind_2_5_static_lin_v4.tgz" TARGET_PATH "${TEMP}/tbbbind_2_5" ENVIRONMENT "TBBBIND_2_5_ROOT" - SHA256 "d39deb262c06981b5e2d2e3c593e9fc9be62ce4feb91dd4e648e92753659a6b3" + SHA256 "4ebf30246530795f066fb9616e6707c6b17be7a65d29d3518b578a769dd54eea" USE_NEW_LOCATION TRUE) else() # TMP: for Apple Silicon TBB does not provide TBBBind diff --git a/cmake/developer_package/IEDevScriptsConfig.cmake b/cmake/developer_package/OpenVINODeveloperScriptsConfig.cmake similarity index 80% rename from cmake/developer_package/IEDevScriptsConfig.cmake rename to cmake/developer_package/OpenVINODeveloperScriptsConfig.cmake index 95e3c9eea3629f..bc512b9b229b02 100644 --- a/cmake/developer_package/IEDevScriptsConfig.cmake +++ b/cmake/developer_package/OpenVINODeveloperScriptsConfig.cmake @@ -4,10 +4,12 @@ cmake_minimum_required(VERSION 3.13) -if(NOT DEFINED IEDevScripts_DIR) - message(FATAL_ERROR "IEDevScripts_DIR is not defined") +if(NOT DEFINED OpenVINODeveloperScripts_DIR ) + message(FATAL_ERROR "OpenVINODeveloperScripts_DIR is not defined") endif() +set(IEDevScripts_DIR "${OpenVINODeveloperScripts_DIR}") # for BW compatibility + # disable FindPkgConfig.cmake for Android if(ANDROID) # Android toolchain does not provide pkg-config file. So, cmake mistakenly uses @@ -23,13 +25,14 @@ macro(ov_set_if_not_defined var value) endmacro() set(OLD_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}) -set(CMAKE_MODULE_PATH "${IEDevScripts_DIR}") +set(CMAKE_MODULE_PATH "${OpenVINODeveloperScripts_DIR}") -function(set_ci_build_number) - set(repo_root "${CMAKE_SOURCE_DIR}") +function(ov_set_ci_build_number) include(version) - foreach(var CI_BUILD_NUMBER OpenVINO_VERSION OpenVINO_SOVERSION OpenVINO_VERSION_SUFFIX OpenVINO_VERSION_BUILD - OpenVINO_VERSION_MAJOR OpenVINO_VERSION_MINOR OpenVINO_VERSION_PATCH) + ov_parse_ci_build_number("${CMAKE_SOURCE_DIR}") + + foreach(var CI_BUILD_NUMBER OpenVINO_VERSION OpenVINO_SOVERSION OpenVINO_VERSION_SUFFIX + OpenVINO_VERSION_MAJOR OpenVINO_VERSION_MINOR OpenVINO_VERSION_PATCH OpenVINO_VERSION_BUILD) if(NOT DEFINED ${var}) message(FATAL_ERROR "${var} version component is not defined") endif() @@ -42,7 +45,7 @@ ov_set_if_not_defined(Python3_FIND_STRATEGY LOCATION) include(features) -set_ci_build_number() +ov_set_ci_build_number() # # Detect target @@ -67,7 +70,7 @@ endif() # Prepare temporary folder # -function(set_temp_directory temp_variable source_tree_dir) +function(ov_set_temp_directory temp_variable source_tree_dir) if(DEFINED OV_TEMP) message(STATUS "OV_TEMP cmake variable is set : ${OV_TEMP}") file(TO_CMAKE_PATH ${OV_TEMP} temp) @@ -84,6 +87,11 @@ function(set_temp_directory temp_variable source_tree_dir) endif() endfunction() +macro(set_temp_directory) + message(WARNING "'set_temp_directory' is deprecated. Please, use 'ov_set_temp_directory'") + ov_set_temp_directory(${ARGV}) +endmacro() + # # For cross-compilation # @@ -132,44 +140,51 @@ endif() # allow to override default OUTPUT_ROOT root if(NOT DEFINED OUTPUT_ROOT) - if(NOT DEFINED OpenVINO_SOURCE_DIR) - message(FATAL_ERROR "OpenVINO_SOURCE_DIR is not defined") + if(DEFINED OpenVINO_SOURCE_DIR) + # For BW compatiblity, when extra modules are built separately + # but still write its artifacts to OpenVINO source directory + set(OUTPUT_ROOT ${OpenVINO_SOURCE_DIR}) + else() + set(OUTPUT_ROOT ${CMAKE_SOURCE_DIR}) endif() - set(OUTPUT_ROOT ${OpenVINO_SOURCE_DIR}) endif() # Enable postfixes for Debug/Release builds -set(IE_DEBUG_POSTFIX_WIN "d") -set(IE_RELEASE_POSTFIX_WIN "") -set(IE_DEBUG_POSTFIX_LIN "") -set(IE_RELEASE_POSTFIX_LIN "") -set(IE_DEBUG_POSTFIX_MAC "d") -set(IE_RELEASE_POSTFIX_MAC "") +set(OV_DEBUG_POSTFIX_WIN "d") +set(OV_RELEASE_POSTFIX_WIN "") +set(OV_DEBUG_POSTFIX_LIN "") +set(OV_RELEASE_POSTFIX_LIN "") +set(OV_DEBUG_POSTFIX_MAC "d") +set(OV_RELEASE_POSTFIX_MAC "") if(WIN32) - set(IE_DEBUG_POSTFIX ${IE_DEBUG_POSTFIX_WIN}) - set(IE_RELEASE_POSTFIX ${IE_RELEASE_POSTFIX_WIN}) + set(OV_DEBUG_POSTFIX ${OV_DEBUG_POSTFIX_WIN}) + set(OV_RELEASE_POSTFIX ${OV_RELEASE_POSTFIX_WIN}) elseif(APPLE) - set(IE_DEBUG_POSTFIX ${IE_DEBUG_POSTFIX_MAC}) - set(IE_RELEASE_POSTFIX ${IE_RELEASE_POSTFIX_MAC}) + set(OV_DEBUG_POSTFIX ${OV_DEBUG_POSTFIX_MAC}) + set(OV_RELEASE_POSTFIX ${OV_RELEASE_POSTFIX_MAC}) else() - set(IE_DEBUG_POSTFIX ${IE_DEBUG_POSTFIX_LIN}) - set(IE_RELEASE_POSTFIX ${IE_RELEASE_POSTFIX_LIN}) + set(OV_DEBUG_POSTFIX ${OV_DEBUG_POSTFIX_LIN}) + set(OV_RELEASE_POSTFIX ${OV_RELEASE_POSTFIX_LIN}) endif() -set(CMAKE_DEBUG_POSTFIX ${IE_DEBUG_POSTFIX}) -set(CMAKE_RELEASE_POSTFIX ${IE_RELEASE_POSTFIX}) +set(CMAKE_DEBUG_POSTFIX ${OV_DEBUG_POSTFIX}) +set(CMAKE_RELEASE_POSTFIX ${OV_RELEASE_POSTFIX}) # Support CMake multi-configuration for Visual Studio / Ninja or Xcode build if(OV_GENERATOR_MULTI_CONFIG) - set(IE_BUILD_POSTFIX $<$:${IE_DEBUG_POSTFIX}>$<$:${IE_RELEASE_POSTFIX}>) + set(OV_BUILD_POSTFIX $<$:${OV_DEBUG_POSTFIX}>$<$:${OV_RELEASE_POSTFIX}>) else() if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set(IE_BUILD_POSTFIX ${IE_DEBUG_POSTFIX}) + set(OV_BUILD_POSTFIX ${OV_DEBUG_POSTFIX}) else() - set(IE_BUILD_POSTFIX ${IE_RELEASE_POSTFIX}) + set(OV_BUILD_POSTFIX ${OV_RELEASE_POSTFIX}) endif() endif() +add_definitions(-DOV_BUILD_POSTFIX=\"${OV_BUILD_POSTFIX}\") + +# for BW compatibility; removed before 2024.0 +set(IE_BUILD_POSTFIX ${OV_BUILD_POSTFIX}) add_definitions(-DIE_BUILD_POSTFIX=\"${IE_BUILD_POSTFIX}\") ov_set_if_not_defined(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER}) @@ -178,22 +193,9 @@ ov_set_if_not_defined(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FO ov_set_if_not_defined(CMAKE_PDB_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER}) ov_set_if_not_defined(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER}) -if(CPACK_GENERATOR MATCHES "^(DEB|RPM)$") - # to make sure that lib/ is created on Debian - set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Cmake install prefix" FORCE) -endif() - include(packaging/packaging) if(APPLE) - set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON) - - if(DEFINED OV_CPACK_LIBRARYDIR) - set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${OV_CPACK_LIBRARYDIR}") - else() - message(FATAL_ERROR "Internal error: OV_CPACK_LIBRARYDIR is not defined, while it's required to initialize RPATH") - endif() - # WA for Xcode generator + object libraries issue: # https://gitlab.kitware.com/cmake/cmake/issues/20260 # http://cmake.3232098.n2.nabble.com/XCODE-DEPEND-HELPER-make-Deletes-Targets-Before-and-While-They-re-Built-td7598277.html @@ -261,7 +263,7 @@ include(api_validator/api_validator) include(vs_version/vs_version) include(plugins/plugins) include(frontends/frontends) -include(add_ie_target) +include(add_target_helpers) include(CMakePackageConfigHelpers) if(ENABLE_FUZZING) diff --git a/cmake/developer_package/add_ie_target.cmake b/cmake/developer_package/add_target_helpers.cmake similarity index 90% rename from cmake/developer_package/add_ie_target.cmake rename to cmake/developer_package/add_target_helpers.cmake index 2452312d82026a..92f4afbc23bbbe 100644 --- a/cmake/developer_package/add_ie_target.cmake +++ b/cmake/developer_package/add_target_helpers.cmake @@ -9,7 +9,6 @@ ov_add_target( NAME core_lib ADD_CPPLINT ADD_CLANG_FORMAT - DEVELOPER_PACKAGE TYPE ROOT ${CMAKE_CURRENT_SOURCE_DIR} ADDITIONAL_SOURCE_DIRS @@ -23,7 +22,7 @@ ov_add_target( link_dependencies DEPENDENCIES dependencies - ie::important_plugin + openvino::important_plugin OBJECT_FILES object libraries DEFINES @@ -44,9 +43,6 @@ function(ov_add_target) NAME # name of target ROOT # root directory to be used for recursive search of source files ) - set(oneValueOptionalArgs - DEVELOPER_PACKAGE # Enables exporting of the target through the developer package - ) set(multiValueArgs INCLUDES # Extra include directories LINK_LIBRARIES # Link libraries (in form of target name or file name) @@ -58,7 +54,7 @@ function(ov_add_target) LINK_LIBRARIES_WHOLE_ARCHIVE # list of static libraries to link, each object file should be used and not discarded LINK_FLAGS # list of extra commands to linker ) - cmake_parse_arguments(ARG "${options}" "${oneValueRequiredArgs};${oneValueOptionalArgs}" "${multiValueArgs}" ${ARGN} ) + cmake_parse_arguments(ARG "${options}" "${oneValueRequiredArgs}" "${multiValueArgs}" ${ARGN} ) # sanity checks foreach(argName IN LISTS oneValueRequiredArgs) @@ -90,8 +86,7 @@ function(ov_add_target) source_group("include" FILES ${includes}) source_group("src" FILES ${sources}) - set(all_sources) - list(APPEND all_sources ${sources} ${includes} ${ARG_OBJECT_FILES}) + set(all_sources ${sources} ${includes} ${ARG_OBJECT_FILES}) # defining a target if (ARG_TYPE STREQUAL EXECUTABLE) @@ -102,7 +97,7 @@ function(ov_add_target) message(SEND_ERROR "Invalid target type ${ARG_TYPE} specified for target name ${ARG_NAME}") endif() - ieTargetLinkWholeArchive(${ARG_NAME} ${ARG_LINK_LIBRARIES_WHOLE_ARCHIVE}) + ov_target_link_whole_archive(${ARG_NAME} ${ARG_LINK_LIBRARIES_WHOLE_ARCHIVE}) if (ARG_DEFINES) target_compile_definitions(${ARG_NAME} PRIVATE ${ARG_DEFINES}) @@ -129,22 +124,12 @@ function(ov_add_target) # code style ov_add_clang_format_target(${ARG_NAME}_clang FOR_TARGETS ${ARG_NAME}) endif() - if (ARG_DEVELOPER_PACKAGE) - # developer package - openvino_developer_export_targets(COMPONENT ${ARG_DEVELOPER_PACKAGE} - TARGETS ${ARG_NAME}) - endif() if(WIN32) # Provide default compile pdb name equal to target name set_target_properties(${ARG_NAME} PROPERTIES COMPILE_PDB_NAME ${ARG_NAME}) endif() endfunction() -function(addIeTarget) - message(WARNING "'addIeTarget' is deprecated, please, use 'ov_add_target' instead") - ov_add_target(${ARGV}) -endfunction() - #[[ Wrapper function over addIeTarget, that also adds a test with the same name. You could use @@ -187,7 +172,9 @@ function(ov_add_test_target) else() add_test(NAME ${ARG_NAME} COMMAND ${ARG_NAME}) endif() - set_property(TEST ${ARG_NAME} PROPERTY LABELS ${ARG_LABELS}) + if(ARG_LABELS) + set_property(TEST ${ARG_NAME} PROPERTY LABELS ${ARG_LABELS}) + endif() install(TARGETS ${ARG_NAME} RUNTIME DESTINATION tests @@ -195,6 +182,13 @@ function(ov_add_test_target) EXCLUDE_FROM_ALL) endfunction() +# deprecated + +function(addIeTarget) + message(WARNING "'addIeTarget' is deprecated, please, use 'ov_add_target' instead") + ov_add_target(${ARGV}) +endfunction() + function(addIeTargetTest) message(WARNING "'addIeTargetTest' is deprecated, please, use 'ov_add_test_target' instead") ov_add_test_target(${ARGV}) diff --git a/cmake/developer_package/api_validator/api_validator.cmake b/cmake/developer_package/api_validator/api_validator.cmake index a92c766bca25a7..6749366a64db05 100644 --- a/cmake/developer_package/api_validator/api_validator.cmake +++ b/cmake/developer_package/api_validator/api_validator.cmake @@ -29,7 +29,7 @@ if(WIN32) endif() endif() -function(_ie_add_api_validator_post_build_step_recursive) +function(_ov_add_api_validator_post_build_step_recursive) cmake_parse_arguments(API_VALIDATOR "" "TARGET" "" ${ARGN}) get_target_property(LIBRARY_TYPE ${API_VALIDATOR_TARGET} TYPE) @@ -55,9 +55,9 @@ function(_ie_add_api_validator_post_build_step_recursive) continue() endif() if(TARGET "${orig_library}") - _ie_add_api_validator_post_build_step_recursive(TARGET ${orig_library}) + _ov_add_api_validator_post_build_step_recursive(TARGET ${orig_library}) else() - _ie_add_api_validator_post_build_step_recursive(TARGET ${library}) + _ov_add_api_validator_post_build_step_recursive(TARGET ${library}) endif() endif() endforeach() @@ -113,10 +113,10 @@ function(_ov_add_api_validator_post_build_step) endif() # collect targets - _ie_add_api_validator_post_build_step_recursive(TARGET ${API_VALIDATOR_TARGET}) + _ov_add_api_validator_post_build_step_recursive(TARGET ${API_VALIDATOR_TARGET}) if (API_VALIDATOR_EXTRA) foreach(target IN LISTS API_VALIDATOR_EXTRA) - _ie_add_api_validator_post_build_step_recursive(TARGET ${target}) + _ov_add_api_validator_post_build_step_recursive(TARGET ${target}) endforeach() endif() @@ -171,7 +171,7 @@ function(_ov_add_api_validator_post_build_step) -D ONECORE_API_VALIDATOR_EXCLUSION=${ONECORE_API_VALIDATOR_EXCLUSION} -D ONECORE_API_VALIDATOR_OUTPUT=${output_file} -D CMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} - -P "${IEDevScripts_DIR}/api_validator/api_validator_run.cmake") + -P "${OpenVINODeveloperScripts_DIR}/api_validator/api_validator_run.cmake") list(APPEND byproducts_files ${output_file}) unset(target_name) @@ -191,13 +191,15 @@ function(_ov_add_api_validator_post_build_step) endfunction() # -# ie_add_api_validator_post_build_step(TARGET ) +# ov_add_api_validator_post_build_step(TARGET ) # -macro(ov_add_api_validator_post_build_step) - _ov_add_api_validator_post_build_step(${ARGV}) -endmacro() - -macro(ie_add_api_validator_post_build_step) - message(WARNING "ie_add_api_validator_post_build_step is deprecated, use ov_add_api_validator_post_build_step instead") - _ov_add_api_validator_post_build_step(${ARGV}) -endmacro() +function(ov_add_api_validator_post_build_step) + _ov_add_api_validator_post_build_step(${ARGN}) +endfunction() + +# deprecated + +function(ie_add_api_validator_post_build_step) + message(WARNING "'ie_add_api_validator_post_build_step' is deprecated, use 'ov_add_api_validator_post_build_step' instead") + _ov_add_api_validator_post_build_step(${ARGN}) +endfunction() diff --git a/cmake/developer_package/clang_format/clang_format.cmake b/cmake/developer_package/clang_format/clang_format.cmake index e8286ed2e9cd20..57319e48006938 100644 --- a/cmake/developer_package/clang_format/clang_format.cmake +++ b/cmake/developer_package/clang_format/clang_format.cmake @@ -88,10 +88,10 @@ function(ov_add_clang_format_target TARGET_NAME) -D "CLANG_FORMAT=${CLANG_FORMAT}" -D "INPUT_FILE=${source_file}" -D "OUTPUT_FILE=${output_file}" - -P "${IEDevScripts_DIR}/clang_format/clang_format_check.cmake" + -P "${OpenVINODeveloperScripts_DIR}/clang_format/clang_format_check.cmake" DEPENDS "${source_file}" - "${IEDevScripts_DIR}/clang_format/clang_format_check.cmake" + "${OpenVINODeveloperScripts_DIR}/clang_format/clang_format_check.cmake" COMMENT "[clang-format] ${source_file}" VERBATIM) @@ -110,10 +110,10 @@ function(ov_add_clang_format_target TARGET_NAME) -D "CLANG_FORMAT=${CLANG_FORMAT}" -D "INPUT_FILES=${all_input_sources}" -D "EXCLUDE_PATTERNS=${CLANG_FORMAT_EXCLUDE_PATTERNS}" - -P "${IEDevScripts_DIR}/clang_format/clang_format_fix.cmake" + -P "${OpenVINODeveloperScripts_DIR}/clang_format/clang_format_fix.cmake" DEPENDS "${all_input_sources}" - "${IEDevScripts_DIR}/clang_format/clang_format_fix.cmake" + "${OpenVINODeveloperScripts_DIR}/clang_format/clang_format_fix.cmake" COMMENT "[clang-format] ${TARGET_NAME}_fix" VERBATIM) diff --git a/cmake/developer_package/compile_flags/os_flags.cmake b/cmake/developer_package/compile_flags/os_flags.cmake index 0ffdd903dcb46f..c0c878e0183eb0 100644 --- a/cmake/developer_package/compile_flags/os_flags.cmake +++ b/cmake/developer_package/compile_flags/os_flags.cmake @@ -9,31 +9,31 @@ include(CheckCXXCompilerFlag) # ov_disable_deprecated_warnings() # # Disables deprecated warnings generation in current scope (directory, function) -# Defines ie_c_cxx_deprecated varaible which contains C / C++ compiler flags +# Defines ov_c_cxx_deprecated varaible which contains C / C++ compiler flags # macro(ov_disable_deprecated_warnings) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - set(ie_c_cxx_deprecated "/wd4996") + set(ov_c_cxx_deprecated "/wd4996") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") if(WIN32) - set(ie_c_cxx_deprecated "/Qdiag-disable:1478,1786") + set(ov_c_cxx_deprecated "/Qdiag-disable:1478,1786") else() - set(ie_c_cxx_deprecated "-diag-disable=1478,1786") + set(ov_c_cxx_deprecated "-diag-disable=1478,1786") endif() elseif(OV_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNUCXX) - set(ie_c_cxx_deprecated "-Wno-deprecated-declarations") + set(ov_c_cxx_deprecated "-Wno-deprecated-declarations") else() message(WARNING "Unsupported CXX compiler ${CMAKE_CXX_COMPILER_ID}") endif() - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${ie_c_cxx_deprecated}") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${ie_c_cxx_deprecated}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ie_c_cxx_deprecated}") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ie_c_cxx_deprecated}") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${ov_c_cxx_deprecated}") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${ov_c_cxx_deprecated}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ov_c_cxx_deprecated}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ov_c_cxx_deprecated}") endmacro() macro(disable_deprecated_warnings) - message(WARNING "disable_deprecated_warnings is deprecated, use ov_disable_deprecated_warnings instead") + message(WARNING "'disable_deprecated_warnings' is deprecated, use 'ov_disable_deprecated_warnings' instead") ov_disable_deprecated_warnings() endmacro() @@ -41,30 +41,30 @@ endmacro() # ov_deprecated_no_errors() # # Don't threat deprecated warnings as errors in current scope (directory, function) -# Defines ie_c_cxx_deprecated_no_errors varaible which contains C / C++ compiler flags +# Defines ov_c_cxx_deprecated_no_errors varaible which contains C / C++ compiler flags # macro(ov_deprecated_no_errors) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") # show 4996 only for /w4 - set(ie_c_cxx_deprecated_no_errors "/wd4996") + set(ov_c_cxx_deprecated_no_errors "/wd4996") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") if(WIN32) - set(ie_c_cxx_deprecated_no_errors "/Qdiag-warning:1478,1786") + set(ov_c_cxx_deprecated_no_errors "/Qdiag-warning:1478,1786") else() - set(ie_c_cxx_deprecated_no_errors "-diag-warning=1478,1786") + set(ov_c_cxx_deprecated_no_errors "-diag-warning=1478,1786") endif() elseif(OV_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNUCXX) - set(ie_c_cxx_deprecated_no_errors "-Wno-error=deprecated-declarations") + set(ov_c_cxx_deprecated_no_errors "-Wno-error=deprecated-declarations") # Suppress #warning messages - set(ie_c_cxx_deprecated_no_errors "${ie_c_cxx_deprecated_no_errors} -Wno-cpp") + set(ov_c_cxx_deprecated_no_errors "${ov_c_cxx_deprecated_no_errors} -Wno-cpp") else() message(WARNING "Unsupported CXX compiler ${CMAKE_CXX_COMPILER_ID}") endif() - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${ie_c_cxx_deprecated_no_errors}") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${ie_c_cxx_deprecated_no_errors}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ie_c_cxx_deprecated_no_errors}") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ie_c_cxx_deprecated_no_errors}") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${ov_c_cxx_deprecated_no_errors}") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${ov_c_cxx_deprecated_no_errors}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ov_c_cxx_deprecated_no_errors}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ov_c_cxx_deprecated_no_errors}") endmacro() # @@ -74,24 +74,24 @@ endmacro() # macro(ov_dev_package_no_errors) if(OV_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNUCXX) - set(ie_c_cxx_dev_no_errors "-Wno-all") + set(ov_c_cxx_dev_no_errors "-Wno-all") if(SUGGEST_OVERRIDE_SUPPORTED) - set(ie_cxx_dev_no_errors "-Wno-error=suggest-override") + set(ov_cxx_dev_no_errors "-Wno-error=suggest-override") endif() endif() - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${ie_c_cxx_dev_no_errors} ${ie_cxx_dev_no_errors}") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${ie_c_cxx_dev_no_errors}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ie_c_cxx_dev_no_errors} ${ie_cxx_dev_no_errors}") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ie_c_cxx_dev_no_errors}") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${ov_c_cxx_dev_no_errors} ${ov_cxx_dev_no_errors}") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${ov_c_cxx_dev_no_errors}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ov_c_cxx_dev_no_errors} ${ov_cxx_dev_no_errors}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ov_c_cxx_dev_no_errors}") endmacro() # -# ie_sse42_optimization_flags() +# ov_sse42_optimization_flags() # # Provides SSE4.2 compilation flags depending on an OS and a compiler # -macro(ie_sse42_optimization_flags flags) +macro(ov_sse42_optimization_flags flags) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") # No such option for MSVC 2019 elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") @@ -111,11 +111,11 @@ macro(ie_sse42_optimization_flags flags) endmacro() # -# ie_avx2_optimization_flags() +# ov_avx2_optimization_flags() # # Provides AVX2 compilation flags depending on an OS and a compiler # -macro(ie_avx2_optimization_flags flags) +macro(ov_avx2_optimization_flags flags) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") set(${flags} /arch:AVX2) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") @@ -132,12 +132,12 @@ macro(ie_avx2_optimization_flags flags) endmacro() # -# ie_avx512_optimization_flags() +# ov_avx512_optimization_flags() # # Provides common AVX512 compilation flags for AVX512F instruction set support # depending on an OS and a compiler # -macro(ie_avx512_optimization_flags flags) +macro(ov_avx512_optimization_flags flags) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") set(${flags} /arch:AVX512) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") @@ -154,9 +154,9 @@ macro(ie_avx512_optimization_flags flags) endmacro() # -# ie_arm_neon_optimization_flags() +# ov_arm_neon_optimization_flags() # -macro(ie_arm_neon_optimization_flags flags) +macro(ov_arm_neon_optimization_flags flags) if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") message(WARNING "Unsupported CXX compiler ${CMAKE_CXX_COMPILER_ID}") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") @@ -219,7 +219,7 @@ endfunction() # Enables Link Time Optimization compilation # macro(ie_enable_lto) - message(WARNING "ie_add_compiler_flags is deprecated, set INTERPROCEDURAL_OPTIMIZATION_RELEASE target property instead") + message(WARNING "'ie_enable_lto' is deprecated, set 'INTERPROCEDURAL_OPTIMIZATION_RELEASE' target property instead") set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON) endmacro() @@ -236,7 +236,7 @@ macro(ov_add_compiler_flags) endmacro() macro(ie_add_compiler_flags) - message(WARNING "ie_add_compiler_flags is deprecated, use ov_add_compiler_flags instead") + message(WARNING "'ie_add_compiler_flags' is deprecated, use 'ov_add_compiler_flags' instead") ov_add_compiler_flags(${ARGN}) endmacro() @@ -329,15 +329,15 @@ endif() file(RELATIVE_PATH OV_RELATIVE_BIN_PATH ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) -if(${CMAKE_VERSION} VERSION_LESS "3.20") - file(TO_NATIVE_PATH ${OpenVINO_SOURCE_DIR} OV_NATIVE_PROJECT_ROOT_DIR) +if(CMAKE_VERSION VERSION_LESS 3.20) + file(TO_NATIVE_PATH ${CMAKE_SOURCE_DIR} OV_NATIVE_PROJECT_ROOT_DIR) file(TO_NATIVE_PATH ${OV_RELATIVE_BIN_PATH} NATIVE_OV_RELATIVE_BIN_PATH) else() - cmake_path(NATIVE_PATH OpenVINO_SOURCE_DIR OV_NATIVE_PROJECT_ROOT_DIR) + cmake_path(NATIVE_PATH CMAKE_SOURCE_DIR OV_NATIVE_PROJECT_ROOT_DIR) cmake_path(NATIVE_PATH OV_RELATIVE_BIN_PATH NATIVE_OV_RELATIVE_BIN_PATH) endif() -file(RELATIVE_PATH OV_NATIVE_PARENT_PROJECT_ROOT_DIR "${OpenVINO_SOURCE_DIR}/.." ${OpenVINO_SOURCE_DIR}) +file(RELATIVE_PATH OV_NATIVE_PARENT_PROJECT_ROOT_DIR "${CMAKE_SOURCE_DIR}/.." ${CMAKE_SOURCE_DIR}) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") # @@ -392,7 +392,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") if(NOT DEFINED ENV{GITHUB_ACTIONS}) add_compile_options( "$<$:/d1trimfile:${OV_NATIVE_PROJECT_ROOT_DIR}\\>" - "$<$:/d1trimfile:${OpenVINO_SOURCE_DIR}/>") + "$<$:/d1trimfile:${CMAKE_SOURCE_DIR}/>") endif() # diff --git a/cmake/developer_package/coverage/coverage.cmake b/cmake/developer_package/coverage/coverage.cmake index 0a2f6a398967c6..f7573f10a66532 100644 --- a/cmake/developer_package/coverage/coverage.cmake +++ b/cmake/developer_package/coverage/coverage.cmake @@ -16,7 +16,7 @@ endif() set(OV_COVERAGE_REPORTS "${CMAKE_BINARY_DIR}/coverage") -set(OV_COVERAGE_SCRIPT_DIR "${IEDevScripts_DIR}/coverage") +set(OV_COVERAGE_SCRIPT_DIR "${OpenVINODeveloperScripts_DIR}/coverage") include(CMakeParseArguments) @@ -171,9 +171,9 @@ function(ov_coverage_genhtml) endfunction() # -# ie_coverage_remove(INPUT OUTPUT PATTERNS ) +# ov_coverage_remove(INPUT OUTPUT PATTERNS ) # -function(ie_coverage_remove) +function(ov_coverage_remove) cmake_parse_arguments(OV_COVERAGE "" "INPUT;OUTPUT" "PATTERNS" ${ARGN}) set(input_file "${OV_COVERAGE_REPORTS}/${OV_COVERAGE_INPUT}.info") @@ -199,9 +199,9 @@ function(ie_coverage_remove) endfunction() # -# ie_coverage_merge(OUTPUT INPUTS ) +# ov_coverage_merge(OUTPUT INPUTS ) # -function(ie_coverage_merge) +function(ov_coverage_merge) cmake_parse_arguments(OV_COVERAGE "" "OUTPUT" "INPUTS" ${ARGN}) set(output_file "${OV_COVERAGE_REPORTS}/${OV_COVERAGE_OUTPUT}.info") @@ -227,6 +227,8 @@ function(ie_coverage_merge) add_dependencies(ov_coverage_${OV_COVERAGE_OUTPUT}_info ${dependencies}) endfunction() +# deprecated + if(NOT TARGET ie_coverage) add_custom_target(ie_coverage) set_target_properties(ie_coverage PROPERTIES FOLDER coverage) diff --git a/cmake/developer_package/cpplint/cpplint.cmake b/cmake/developer_package/cpplint/cpplint.cmake index e22c8f2e034b96..aa2b4147e0e685 100644 --- a/cmake/developer_package/cpplint/cpplint.cmake +++ b/cmake/developer_package/cpplint/cpplint.cmake @@ -69,17 +69,17 @@ function(add_cpplint_target TARGET_NAME) COMMAND "${CMAKE_COMMAND}" -D "Python3_EXECUTABLE=${Python3_EXECUTABLE}" - -D "CPPLINT_SCRIPT=${IEDevScripts_DIR}/cpplint/cpplint.py" + -D "CPPLINT_SCRIPT=${OpenVINODeveloperScripts_DIR}/cpplint/cpplint.py" -D "INPUT_FILE=${source_file}" -D "OUTPUT_FILE=${output_file}" -D "WORKING_DIRECTORY=${CMAKE_CURRENT_SOURCE_DIR}" -D "SKIP_RETURN_CODE=${ENABLE_CPPLINT_REPORT}" -D "CUSTOM_FILTER=${custom_filter}" - -P "${IEDevScripts_DIR}/cpplint/cpplint_run.cmake" + -P "${OpenVINODeveloperScripts_DIR}/cpplint/cpplint_run.cmake" DEPENDS "${source_file}" - "${IEDevScripts_DIR}/cpplint/cpplint.py" - "${IEDevScripts_DIR}/cpplint/cpplint_run.cmake" + "${OpenVINODeveloperScripts_DIR}/cpplint/cpplint.py" + "${OpenVINODeveloperScripts_DIR}/cpplint/cpplint_run.cmake" COMMENT "[cpplint] ${source_file_relative_root}" VERBATIM) diff --git a/cmake/developer_package/cross_compile/cross_compiled_func.cmake b/cmake/developer_package/cross_compile/cross_compiled_func.cmake index ff68280a687bd0..d82d6a73098b6c 100644 --- a/cmake/developer_package/cross_compile/cross_compiled_func.cmake +++ b/cmake/developer_package/cross_compile/cross_compiled_func.cmake @@ -19,9 +19,9 @@ set(_DEFINE_AVX2 "HAVE_AVX2" ${_DEFINE_AVX}) set(_DEFINE_AVX512F "HAVE_AVX512F" ${_DEFINE_AVX2}) ## Arch specific compile options -ie_avx512_optimization_flags(_FLAGS_AVX512F) -ie_avx2_optimization_flags (_FLAGS_AVX2) -ie_sse42_optimization_flags (_FLAGS_SSE42) +ov_avx512_optimization_flags(_FLAGS_AVX512F) +ov_avx2_optimization_flags (_FLAGS_AVX2) +ov_sse42_optimization_flags (_FLAGS_SSE42) set(_FLAGS_AVX "") ## TBD is not defined for IE project yet set(_FLAGS_ANY "") ## diff --git a/cmake/developer_package/faster_build.cmake b/cmake/developer_package/faster_build.cmake index b0f6a6c8b7b3ef..f70274f465070c 100644 --- a/cmake/developer_package/faster_build.cmake +++ b/cmake/developer_package/faster_build.cmake @@ -20,6 +20,8 @@ function(ov_build_target_faster TARGET_NAME) endif() endfunction() +# deprecated + function(ie_faster_build) message(WARNING "ie_faster_build is deprecated, use ov_build_target_faster instead") ov_build_target_faster(${ARGV}) diff --git a/cmake/developer_package/features.cmake b/cmake/developer_package/features.cmake index bda6eb353bb022..96e927187ccf70 100644 --- a/cmake/developer_package/features.cmake +++ b/cmake/developer_package/features.cmake @@ -6,19 +6,19 @@ include(options) include(target_flags) set (CPACK_GENERATOR "TGZ" CACHE STRING "Cpack generator for OpenVINO") -list (APPEND IE_OPTIONS CPACK_GENERATOR) +list (APPEND OV_OPTIONS CPACK_GENERATOR) # FIXME: there are compiler failures with LTO and Cross-Compile toolchains. Disabling for now, but # this must be addressed in a proper way -ie_dependent_option (ENABLE_LTO "Enable Link Time Optimization" OFF +ov_dependent_option (ENABLE_LTO "Enable Link Time Optimization" OFF "LINUX;EMSCRIPTEN OR NOT CMAKE_CROSSCOMPILING;CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9" OFF) -ie_option (OS_FOLDER "create OS dedicated folder in output" OFF) +ov_option (OS_FOLDER "create OS dedicated folder in output" OFF) if(OV_GENERATOR_MULTI_CONFIG) - ie_option(USE_BUILD_TYPE_SUBFOLDER "Create dedicated sub-folder per build type for output binaries" OFF) + ov_option(USE_BUILD_TYPE_SUBFOLDER "Create dedicated sub-folder per build type for output binaries" OFF) else() - ie_option(USE_BUILD_TYPE_SUBFOLDER "Create dedicated sub-folder per build type for output binaries" ON) + ov_option(USE_BUILD_TYPE_SUBFOLDER "Create dedicated sub-folder per build type for output binaries" ON) endif() if(DEFINED ENV{CI_BUILD_NUMBER} AND NOT (WIN32 OR CMAKE_CROSSCOMPILING)) @@ -27,37 +27,37 @@ else() set(CMAKE_COMPILE_WARNING_AS_ERROR_DEFAULT OFF) endif() -ie_option (CMAKE_COMPILE_WARNING_AS_ERROR "Enable warnings as errors" ${CMAKE_COMPILE_WARNING_AS_ERROR_DEFAULT}) +ov_option (CMAKE_COMPILE_WARNING_AS_ERROR "Enable warnings as errors" ${CMAKE_COMPILE_WARNING_AS_ERROR_DEFAULT}) -ie_dependent_option (ENABLE_QSPECTRE "Enable Qspectre mitigation" OFF "CMAKE_CXX_COMPILER_ID STREQUAL MSVC" OFF) +ov_dependent_option (ENABLE_QSPECTRE "Enable Qspectre mitigation" OFF "CMAKE_CXX_COMPILER_ID STREQUAL MSVC" OFF) -ie_dependent_option (ENABLE_INTEGRITYCHECK "build DLLs with /INTEGRITYCHECK flag" OFF "CMAKE_CXX_COMPILER_ID STREQUAL MSVC" OFF) +ov_dependent_option (ENABLE_INTEGRITYCHECK "build DLLs with /INTEGRITYCHECK flag" OFF "CMAKE_CXX_COMPILER_ID STREQUAL MSVC" OFF) -ie_option (ENABLE_SANITIZER "enable checking memory errors via AddressSanitizer" OFF) +ov_option (ENABLE_SANITIZER "enable checking memory errors via AddressSanitizer" OFF) -ie_option (ENABLE_UB_SANITIZER "enable UndefinedBahavior sanitizer" OFF) +ov_option (ENABLE_UB_SANITIZER "enable UndefinedBahavior sanitizer" OFF) -ie_option (ENABLE_THREAD_SANITIZER "enable checking data races via ThreadSanitizer" OFF) +ov_option (ENABLE_THREAD_SANITIZER "enable checking data races via ThreadSanitizer" OFF) -ie_dependent_option (ENABLE_COVERAGE "enable code coverage" OFF "CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG" OFF) +ov_dependent_option (ENABLE_COVERAGE "enable code coverage" OFF "CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG" OFF) # Defines CPU capabilities -ie_dependent_option (ENABLE_SSE42 "Enable SSE4.2 optimizations" ON "X86_64 OR (X86 AND NOT EMSCRIPTEN)" OFF) +ov_dependent_option (ENABLE_SSE42 "Enable SSE4.2 optimizations" ON "X86_64 OR (X86 AND NOT EMSCRIPTEN)" OFF) -ie_dependent_option (ENABLE_AVX2 "Enable AVX2 optimizations" ON "X86_64 OR (X86 AND NOT EMSCRIPTEN)" OFF) +ov_dependent_option (ENABLE_AVX2 "Enable AVX2 optimizations" ON "X86_64 OR (X86 AND NOT EMSCRIPTEN)" OFF) -ie_dependent_option (ENABLE_AVX512F "Enable AVX512 optimizations" ON "X86_64 OR (X86 AND NOT EMSCRIPTEN)" OFF) +ov_dependent_option (ENABLE_AVX512F "Enable AVX512 optimizations" ON "X86_64 OR (X86 AND NOT EMSCRIPTEN)" OFF) # Type of build, we add this as an explicit option to default it to ON get_property(BUILD_SHARED_LIBS_DEFAULT GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS) -ie_option (BUILD_SHARED_LIBS "Build as a shared library" ${BUILD_SHARED_LIBS_DEFAULT}) +ov_option (BUILD_SHARED_LIBS "Build as a shared library" ${BUILD_SHARED_LIBS_DEFAULT}) # Android does not support SOVERSION # see https://www.opengis.ch/2011/11/23/creating-non-versioned-shared-libraries-for-android/ -ie_dependent_option (ENABLE_LIBRARY_VERSIONING "Enable libraries versioning" ON "NOT WIN32;NOT ANDROID;BUILD_SHARED_LIBS" OFF) +ov_dependent_option (ENABLE_LIBRARY_VERSIONING "Enable libraries versioning" ON "NOT WIN32;NOT ANDROID;BUILD_SHARED_LIBS" OFF) -ie_dependent_option (ENABLE_FASTER_BUILD "Enable build features (PCH, UNITY) to speed up build time" OFF "CMAKE_VERSION VERSION_GREATER_EQUAL 3.16" OFF) +ov_dependent_option (ENABLE_FASTER_BUILD "Enable build features (PCH, UNITY) to speed up build time" OFF "CMAKE_VERSION VERSION_GREATER_EQUAL 3.16" OFF) if(CMAKE_CROSSCOMPILING OR WIN32) set(STYLE_CHECKS_DEFAULT OFF) @@ -65,22 +65,22 @@ else() set(STYLE_CHECKS_DEFAULT ON) endif() -ie_option (ENABLE_CPPLINT "Enable cpplint checks during the build" ${STYLE_CHECKS_DEFAULT}) +ov_option (ENABLE_CPPLINT "Enable cpplint checks during the build" ${STYLE_CHECKS_DEFAULT}) -ie_dependent_option (ENABLE_CPPLINT_REPORT "Build cpplint report instead of failing the build" OFF "ENABLE_CPPLINT" OFF) +ov_dependent_option (ENABLE_CPPLINT_REPORT "Build cpplint report instead of failing the build" OFF "ENABLE_CPPLINT" OFF) -ie_option (ENABLE_CLANG_FORMAT "Enable clang-format checks during the build" ${STYLE_CHECKS_DEFAULT}) +ov_option (ENABLE_CLANG_FORMAT "Enable clang-format checks during the build" ${STYLE_CHECKS_DEFAULT}) -ie_option (ENABLE_NCC_STYLE "Enable ncc style check" ${STYLE_CHECKS_DEFAULT}) +ov_option (ENABLE_NCC_STYLE "Enable ncc style check" ${STYLE_CHECKS_DEFAULT}) -ie_option (ENABLE_UNSAFE_LOCATIONS "skip check for MD5 for dependency" OFF) +ov_option (ENABLE_UNSAFE_LOCATIONS "skip check for MD5 for dependency" OFF) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER_EQUAL 1930) # Visual Studio 2022: 1930-1939 = VS 17.0 (v143 toolset) set(_msvc_version_2022 ON) endif() -ie_dependent_option (ENABLE_FUZZING "instrument build for fuzzing" OFF "OV_COMPILER_IS_CLANG OR _msvc_version_2022" OFF) +ov_dependent_option (ENABLE_FUZZING "instrument build for fuzzing" OFF "OV_COMPILER_IS_CLANG OR _msvc_version_2022" OFF) # # Check features diff --git a/cmake/developer_package/frontends/frontends.cmake b/cmake/developer_package/frontends/frontends.cmake index 78e62101670425..a20b1665fb7d29 100644 --- a/cmake/developer_package/frontends/frontends.cmake +++ b/cmake/developer_package/frontends/frontends.cmake @@ -38,7 +38,7 @@ function(ov_generate_frontends_hpp) ov_target_link_frontends(openvino) set(ov_frontends_hpp "${CMAKE_BINARY_DIR}/src/frontends/common/src/ov_frontends.hpp") - set(frontends_hpp_in "${IEDevScripts_DIR}/frontends/ov_frontends.hpp.in") + set(frontends_hpp_in "${OpenVINODeveloperScripts_DIR}/frontends/ov_frontends.hpp.in") add_custom_command(OUTPUT "${ov_frontends_hpp}" COMMAND @@ -46,10 +46,10 @@ function(ov_generate_frontends_hpp) -D "OV_FRONTENDS_HPP_HEADER_IN=${frontends_hpp_in}" -D "OV_FRONTENDS_HPP_HEADER=${ov_frontends_hpp}" -D "FRONTEND_NAMES=${FRONTEND_NAMES}" - -P "${IEDevScripts_DIR}/frontends/create_frontends_hpp.cmake" + -P "${OpenVINODeveloperScripts_DIR}/frontends/create_frontends_hpp.cmake" DEPENDS "${frontends_hpp_in}" - "${IEDevScripts_DIR}/frontends/create_frontends_hpp.cmake" + "${OpenVINODeveloperScripts_DIR}/frontends/create_frontends_hpp.cmake" COMMENT "Generate ov_frontends.hpp for static build" VERBATIM) @@ -125,17 +125,24 @@ macro(ov_add_frontend) source_group("public include" FILES ${LIBRARY_PUBLIC_HEADERS}) # Generate protobuf file on build time for each '.proto' file in src/proto - file(GLOB proto_files ${frontend_root_dir}/src/proto/*.proto) + set(protofiles_root_dir "${frontend_root_dir}/src/proto") + file(GLOB_RECURSE proto_files ${protofiles_root_dir}/*.proto) foreach(proto_file IN LISTS proto_files) + # filter out standaard google proto files + if(proto_file MATCHES ".*google.*") + continue() + endif() + file(RELATIVE_PATH proto_file_relative "${CMAKE_SOURCE_DIR}" "${proto_file}") - get_filename_component(FILE_DIR ${proto_file} DIRECTORY) get_filename_component(FILE_WE ${proto_file} NAME_WE) - set(OUTPUT_PB_SRC ${CMAKE_CURRENT_BINARY_DIR}/${FILE_WE}.pb.cc) - set(OUTPUT_PB_HEADER ${CMAKE_CURRENT_BINARY_DIR}/${FILE_WE}.pb.h) + file(RELATIVE_PATH relative_path ${protofiles_root_dir} ${proto_file}) + get_filename_component(relative_path ${relative_path} DIRECTORY) + set(OUTPUT_PB_SRC ${CMAKE_CURRENT_BINARY_DIR}/${relative_path}/${FILE_WE}.pb.cc) + set(OUTPUT_PB_HEADER ${CMAKE_CURRENT_BINARY_DIR}/${relative_path}/${FILE_WE}.pb.h) add_custom_command( OUTPUT "${OUTPUT_PB_SRC}" "${OUTPUT_PB_HEADER}" - COMMAND ${PROTOC_EXECUTABLE} ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I ${FILE_DIR} ${FILE_WE}.proto + COMMAND ${PROTOC_EXECUTABLE} ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I ${protofiles_root_dir} ${proto_file} DEPENDS ${PROTOC_DEPENDENCY} ${proto_file} COMMENT "Running C++ protocol buffer compiler (${PROTOC_EXECUTABLE}) on ${proto_file_relative}" VERBATIM diff --git a/cmake/developer_package/ncc_naming_style/ncc_naming_style.cmake b/cmake/developer_package/ncc_naming_style/ncc_naming_style.cmake index cf2f447565ae43..ab6d49552b3156 100644 --- a/cmake/developer_package/ncc_naming_style/ncc_naming_style.cmake +++ b/cmake/developer_package/ncc_naming_style/ncc_naming_style.cmake @@ -6,7 +6,7 @@ if(NOT COMMAND ov_check_pip_packages) message(FATAL_ERROR "Internal error: ncc_naming_style.cmake must be included after ov_check_pip_packages") endif() -set(ncc_style_dir "${IEDevScripts_DIR}/ncc_naming_style") +set(ncc_style_dir "${OpenVINODeveloperScripts_DIR}/ncc_naming_style") set(ncc_style_bin_dir "${CMAKE_CURRENT_BINARY_DIR}/ncc_naming_style") # find python3 diff --git a/cmake/developer_package/options.cmake b/cmake/developer_package/options.cmake index 08593603589ae2..4506d85a027f92 100644 --- a/cmake/developer_package/options.cmake +++ b/cmake/developer_package/options.cmake @@ -2,55 +2,73 @@ # SPDX-License-Identifier: Apache-2.0 # -# Usage: ie_option( "description" [IF ]) - include (CMakeDependentOption) if(POLICY CMP0127) cmake_policy(SET CMP0127 NEW) endif() -macro (ie_option variable description value) +macro(ov_option variable description value) option(${variable} "${description}" ${value}) + list(APPEND OV_OPTIONS ${variable}) list(APPEND IE_OPTIONS ${variable}) endmacro() -# Usage: ov_option( "description" [IF ]) -macro (ov_option variable description value) - ie_option(${variable} "${description}" ${value}) -endmacro() - -macro (ie_dependent_option variable description def_value condition fallback_value) +macro(ov_dependent_option variable description def_value condition fallback_value) cmake_dependent_option(${variable} "${description}" ${def_value} "${condition}" ${fallback_value}) + list(APPEND OV_OPTIONS ${variable}) list(APPEND IE_OPTIONS ${variable}) endmacro() -macro (ie_option_enum variable description value) +macro(ov_option_enum variable description value) set(OPTIONS) set(ONE_VALUE_ARGS) set(MULTI_VALUE_ARGS ALLOWED_VALUES) - cmake_parse_arguments(IE_OPTION_ENUM "${OPTIONS}" "${ONE_VALUE_ARGS}" "${MULTI_VALUE_ARGS}" ${ARGN}) + cmake_parse_arguments(OPTION_ENUM "${OPTIONS}" "${ONE_VALUE_ARGS}" "${MULTI_VALUE_ARGS}" ${ARGN}) - if(NOT ${value} IN_LIST IE_OPTION_ENUM_ALLOWED_VALUES) - message(FATAL_ERROR "variable must be one of ${IE_OPTION_ENUM_ALLOWED_VALUES}") + if(NOT ${value} IN_LIST OPTION_ENUM_ALLOWED_VALUES) + message(FATAL_ERROR "Internal error: variable must be one of ${OPTION_ENUM_ALLOWED_VALUES}") endif() + list(APPEND OV_OPTIONS ${variable}) list(APPEND IE_OPTIONS ${variable}) set(${variable} ${value} CACHE STRING "${description}") - set_property(CACHE ${variable} PROPERTY STRINGS ${IE_OPTION_ENUM_ALLOWED_VALUES}) + set_property(CACHE ${variable} PROPERTY STRINGS ${OPTION_ENUM_ALLOWED_VALUES}) + + unset(OPTIONS) + unset(ONE_VALUE_ARGS) + unset(MULTI_VALUE_ARGS) + unset(OPTION_ENUM_ALLOWED_VALUES) endmacro() -function (print_enabled_features) - if(NOT COMMAND set_ci_build_number) +function (ov_print_enabled_features) + if(NOT COMMAND ov_set_ci_build_number) message(FATAL_ERROR "CI_BUILD_NUMBER is not set yet") endif() message(STATUS "OpenVINO Runtime enabled features: ") message(STATUS "") message(STATUS " CI_BUILD_NUMBER: ${CI_BUILD_NUMBER}") - foreach(_var ${IE_OPTIONS}) + foreach(_var IN LISTS OV_OPTIONS) message(STATUS " ${_var} = ${${_var}}") endforeach() message(STATUS "") endfunction() + +# deprecated + +macro (ie_option variable description value) + message(WARNING "'ie_option' is deprecated, please, use 'ov_option' instead") + ov_option(${variable} "${description}" ${value}) +endmacro() + +macro(ie_dependent_option variable description def_value condition fallback_value) + message(WARNING "'ie_dependent_option' is deprecated, please, use 'ov_dependent_option' instead") + ov_dependent_option(${variable} "${description}" ${def_value} "${condition}" ${fallback_value}) +endmacro() + +function(print_enabled_features) + message(WARNING "'print_enabled_features' is deprecated, please, use 'ov_print_enabled_features' instead") + ov_print_enabled_features() +endfunction() diff --git a/cmake/developer_package/packaging/archive.cmake b/cmake/developer_package/packaging/archive.cmake index 07f29826e4c491..5f259a78d72838 100644 --- a/cmake/developer_package/packaging/archive.cmake +++ b/cmake/developer_package/packaging/archive.cmake @@ -4,6 +4,15 @@ include(GNUInstallDirs) +if(APPLE) + # on macOS versions with SIP enabled, we need to use @rpath + # because DYLD_LIBRARY_PATH is ignored + set(CMAKE_SKIP_INSTALL_RPATH OFF) +else() + # we don't need RPATHs, because setupvars.sh is used + set(CMAKE_SKIP_INSTALL_RPATH ON) +endif() + # # ov_archive_cpack_set_dirs() # @@ -44,11 +53,6 @@ macro(ov_archive_cpack_set_dirs) set(OV_CPACK_ARCHIVEDIR runtime/lib/${ARCH_FOLDER}) endif() set(OV_CPACK_PLUGINSDIR ${OV_CPACK_RUNTIMEDIR}) - - # for BW compatibility - set(IE_CPACK_LIBRARY_PATH ${OV_CPACK_LIBRARYDIR}) - set(IE_CPACK_RUNTIME_PATH ${OV_CPACK_RUNTIMEDIR}) - set(IE_CPACK_ARCHIVE_PATH ${OV_CPACK_ARCHIVEDIR}) endmacro() ov_archive_cpack_set_dirs() diff --git a/cmake/developer_package/packaging/common-libraries.cmake b/cmake/developer_package/packaging/common-libraries.cmake index 85d148db9f08f0..9671d827521d20 100644 --- a/cmake/developer_package/packaging/common-libraries.cmake +++ b/cmake/developer_package/packaging/common-libraries.cmake @@ -47,11 +47,6 @@ macro(ov_common_libraries_cpack_set_dirs) # skipped during common libraries packaging set(OV_CPACK_WHEELSDIR "tools") - - # for BW compatibility - set(IE_CPACK_LIBRARY_PATH ${OV_CPACK_LIBRARYDIR}) - set(IE_CPACK_RUNTIME_PATH ${OV_CPACK_RUNTIMEDIR}) - set(IE_CPACK_ARCHIVE_PATH ${OV_CPACK_ARCHIVEDIR}) endmacro() ov_common_libraries_cpack_set_dirs() @@ -114,6 +109,10 @@ endmacro() ov_define_component_include_rules() if(CPACK_GENERATOR STREQUAL "BREW") - # brew relies on RPATH + # brew relies on RPATHs set(CMAKE_SKIP_INSTALL_RPATH OFF) + set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${OV_CPACK_LIBRARYDIR}") +else() + # we don't need RPATHs, because libraries are searched by standard paths + set(CMAKE_SKIP_INSTALL_RPATH ON) endif() diff --git a/cmake/developer_package/packaging/debian/debian.cmake b/cmake/developer_package/packaging/debian/debian.cmake index c77d680d9409fe..38cd649ad41cc3 100644 --- a/cmake/developer_package/packaging/debian/debian.cmake +++ b/cmake/developer_package/packaging/debian/debian.cmake @@ -45,11 +45,6 @@ macro(ov_debian_cpack_set_dirs) # skipped during debian packaging set(OV_CPACK_WHEELSDIR "tools") - - # for BW compatibility - set(IE_CPACK_LIBRARY_PATH ${OV_CPACK_RUNTIMEDIR}) - set(IE_CPACK_RUNTIME_PATH ${OV_CPACK_RUNTIMEDIR}) - set(IE_CPACK_ARCHIVE_PATH ${OV_CPACK_ARCHIVEDIR}) endmacro() ov_debian_cpack_set_dirs() @@ -134,7 +129,9 @@ macro(ov_debian_specific_settings) # homepage set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://docs.openvino.ai/") # use lintian to check packages in post-build step - set(CPACK_POST_BUILD_SCRIPTS "${IEDevScripts_DIR}/packaging/debian/post_build.cmake") + set(CPACK_POST_BUILD_SCRIPTS "${OpenVINODeveloperScripts_DIR}/packaging/debian/post_build.cmake") + # to make sure that lib/ is created on Debian + set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Cmake install prefix" FORCE) # enable for debug cpack run if(NOT DEFINED CPACK_DEBIAN_PACKAGE_DEBUG) set(CPACK_DEBIAN_PACKAGE_DEBUG OFF) diff --git a/cmake/developer_package/packaging/nsis.cmake b/cmake/developer_package/packaging/nsis.cmake index ac0aeb1f592349..4174037af74f39 100644 --- a/cmake/developer_package/packaging/nsis.cmake +++ b/cmake/developer_package/packaging/nsis.cmake @@ -5,6 +5,8 @@ macro(ov_nsis_specific_settings) # installation directory set(CPACK_PACKAGE_INSTALL_DIRECTORY "Intel") + # License to be embedded in the installer + set(CPACK_RESOURCE_FILE_LICENSE "${OpenVINO_SOURCE_DIR}/LICENSE") # TODO: provide icons # set(CPACK_NSIS_MUI_ICON "") @@ -83,11 +85,6 @@ macro(ov_archive_cpack_set_dirs) set(OV_CPACK_ARCHIVEDIR runtime/lib/${ARCH_FOLDER}) endif() set(OV_CPACK_PLUGINSDIR ${OV_CPACK_RUNTIMEDIR}) - - # for BW compatibility - set(IE_CPACK_LIBRARY_PATH ${OV_CPACK_LIBRARYDIR}) - set(IE_CPACK_RUNTIME_PATH ${OV_CPACK_RUNTIMEDIR}) - set(IE_CPACK_ARCHIVE_PATH ${OV_CPACK_ARCHIVEDIR}) endmacro() ov_nsis_cpack_set_dirs() diff --git a/cmake/developer_package/packaging/packaging.cmake b/cmake/developer_package/packaging/packaging.cmake index ae2d4d643211d6..2279580040f736 100644 --- a/cmake/developer_package/packaging/packaging.cmake +++ b/cmake/developer_package/packaging/packaging.cmake @@ -4,9 +4,6 @@ include(CPackComponent) -# we don't need RPATHs, because setupvars.sh is used -set(CMAKE_SKIP_INSTALL_RPATH ON) - # # ov_install_static_lib( ) # @@ -31,6 +28,29 @@ macro(ov_install_static_lib target comp) endif() endmacro() +# +# ov_set_apple_rpath( ...) +# +# Sets LC_RPATH properties for macOS MACH-O binaries to ensure that libraries can find their dependencies +# when macOS system integrity protection (SIP) is enabled (DYLD_LIBRARY_PATH is ignored in this case). +# Note, that this is important when binaries are dynamically loaded at runtime (e.g. via Python). +# +function(ov_set_apple_rpath TARGET_NAME lib_install_path) + if(APPLE AND CPACK_GENERATOR MATCHES "^(7Z|TBZ2|TGZ|TXZ|TZ|TZST|ZIP)$") + unset(rpath_list) + foreach(dependency_install_path IN LISTS ARGN) + file(RELATIVE_PATH dependency_rpath "/${lib_install_path}" "/${dependency_install_path}") + set(dependency_rpath "@loader_path/${dependency_rpath}") + list(APPEND rpath_list "${dependency_rpath}") + endforeach() + + set_target_properties(${TARGET_NAME} PROPERTIES + MACOSX_RPATH ON + INSTALL_RPATH "${rpath_list}" + INSTALL_NAME_DIR "@rpath") + endif() +endfunction() + # # ov_get_pyversion() # @@ -49,22 +69,22 @@ endfunction() # Wraps original `cpack_add_component` and adds component to internal IE list # function(ov_cpack_add_component name) - if(NOT ${name} IN_LIST IE_CPACK_COMPONENTS_ALL) + if(NOT ${name} IN_LIST OV_CPACK_COMPONENTS_ALL) cpack_add_component(${name} ${ARGN}) # need to store informarion about cpack_add_component arguments in CMakeCache.txt # to restore it later set(_${name}_cpack_component_args "${ARGN}" CACHE INTERNAL "Argument for cpack_add_component for ${name} cpack component" FORCE) - list(APPEND IE_CPACK_COMPONENTS_ALL ${name}) - set(IE_CPACK_COMPONENTS_ALL "${IE_CPACK_COMPONENTS_ALL}" CACHE INTERNAL "" FORCE) + list(APPEND OV_CPACK_COMPONENTS_ALL ${name}) + set(OV_CPACK_COMPONENTS_ALL "${OV_CPACK_COMPONENTS_ALL}" CACHE INTERNAL "" FORCE) endif() endfunction() -foreach(comp IN LISTS IE_CPACK_COMPONENTS_ALL) +foreach(comp IN LISTS OV_CPACK_COMPONENTS_ALL) unset(_${comp}_cpack_component_args) endforeach() -unset(IE_CPACK_COMPONENTS_ALL CACHE) +unset(OV_CPACK_COMPONENTS_ALL CACHE) # create `tests` component if(ENABLE_TESTS) @@ -164,7 +184,7 @@ elseif(CPACK_GENERATOR MATCHES "^(7Z|TBZ2|TGZ|TXZ|TZ|TZST|ZIP)$") include(packaging/archive) endif() -macro(ie_cpack) +macro(ov_cpack) set(CPACK_SOURCE_GENERATOR "") # not used set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OpenVINO™ Toolkit") set(CPACK_COMPONENT_UNSPECIFIED_REQUIRED OFF) @@ -173,8 +193,6 @@ macro(ie_cpack) set(CPACK_PACKAGE_CONTACT "OpenVINO Developers ") set(CPACK_VERBATIM_VARIABLES ON) set(CPACK_COMPONENTS_ALL ${ARGN}) - # TODO: set proper license file for Windows installer - set(CPACK_RESOURCE_FILE_LICENSE "${OpenVINO_SOURCE_DIR}/LICENSE") # default permissions for directories creation set(CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS @@ -223,3 +241,10 @@ macro(ie_cpack) include(CPack) endmacro() + +# deprecated + +macro(ie_cpack) + message(WARNING "'ie_cpack' is deprecated. Please, use 'ov_cpack'") + ov_cpack(${ARGV}) +endmacro() diff --git a/cmake/developer_package/packaging/rpm/rpm.cmake b/cmake/developer_package/packaging/rpm/rpm.cmake index 94efa5955c9e0e..9660226e696582 100644 --- a/cmake/developer_package/packaging/rpm/rpm.cmake +++ b/cmake/developer_package/packaging/rpm/rpm.cmake @@ -36,11 +36,6 @@ macro(ov_rpm_cpack_set_dirs) # skipped during rpm packaging set(OV_CPACK_WHEELSDIR "tools") - - # for BW compatibility - set(IE_CPACK_LIBRARY_PATH ${OV_CPACK_LIBRARYDIR}) - set(IE_CPACK_RUNTIME_PATH ${OV_CPACK_RUNTIMEDIR}) - set(IE_CPACK_ARCHIVE_PATH ${OV_CPACK_ARCHIVEDIR}) endmacro() ov_rpm_cpack_set_dirs() @@ -128,7 +123,7 @@ macro(ov_rpm_specific_settings) # TODO: fix "error: bad date in %changelog" # set(CPACK_RPM_CHANGELOG_FILE "${OpenVINO_SOURCE_DIR}/cmake/developer_package/packaging/rpm/changelog") # use rpmlint to check packages in post-build step - set(CPACK_POST_BUILD_SCRIPTS "${IEDevScripts_DIR}/packaging/rpm/post_build.cmake") + set(CPACK_POST_BUILD_SCRIPTS "${OpenVINODeveloperScripts_DIR}/packaging/rpm/post_build.cmake") # enable for debug cpack run ov_set_if_not_defined(CPACK_RPM_PACKAGE_DEBUG OFF) diff --git a/cmake/developer_package/plugins/plugins.cmake b/cmake/developer_package/plugins/plugins.cmake index 4ab78f5cfabd00..a8ba97ad9fa27d 100644 --- a/cmake/developer_package/plugins/plugins.cmake +++ b/cmake/developer_package/plugins/plugins.cmake @@ -8,7 +8,7 @@ set(PLUGIN_FILES "" CACHE INTERNAL "") function(ov_plugin_get_file_name target_name library_name) set(LIB_PREFIX "${CMAKE_SHARED_MODULE_PREFIX}") - set(LIB_SUFFIX "${IE_BUILD_POSTFIX}${CMAKE_SHARED_MODULE_SUFFIX}") + set(LIB_SUFFIX "${OV_BUILD_POSTFIX}${CMAKE_SHARED_MODULE_SUFFIX}") get_target_property(LIB_NAME ${target_name} OUTPUT_NAME) if (LIB_NAME STREQUAL "LIB_NAME-NOTFOUND") @@ -168,6 +168,7 @@ function(ov_add_plugin) endfunction() function(ie_add_plugin) + message(WARNING "'ie_add_plugin' is deprecated. Please, use 'ov_add_plugin'") ov_add_plugin(${ARGN}) endfunction() @@ -203,7 +204,7 @@ macro(ov_register_in_plugins_xml) -D "OV_CONFIG_OUTPUT_FILE=${config_output_file}" -D "OV_PLUGIN_NAME=${device_name}" -D "OV_CONFIGS_DIR=${CMAKE_BINARY_DIR}/plugins" - -P "${IEDevScripts_DIR}/plugins/unregister_plugin_cmake.cmake" + -P "${OpenVINODeveloperScripts_DIR}/plugins/unregister_plugin_cmake.cmake" COMMENT "Remove ${device_name} from the plugins.xml file" VERBATIM) @@ -232,7 +233,7 @@ macro(ov_register_in_plugins_xml) -D "OV_DEVICE_NAME=${device_name}" -D "OV_PLUGIN_PROPERTIES=${${device_name}_CONFIG}" -D "OV_PLUGIN_LIBRARY_NAME=${library_name}" - -P "${IEDevScripts_DIR}/plugins/create_plugin_file.cmake" + -P "${OpenVINODeveloperScripts_DIR}/plugins/create_plugin_file.cmake" COMMENT "Register ${device_name} device as ${library_name}" VERBATIM) @@ -247,7 +248,7 @@ macro(ov_register_in_plugins_xml) -D "CMAKE_SHARED_MODULE_PREFIX=${CMAKE_SHARED_MODULE_PREFIX}" -D "OV_CONFIG_OUTPUT_FILE=${config_output_file}" -D "OV_CONFIGS_DIR=${CMAKE_BINARY_DIR}/plugins" - -P "${IEDevScripts_DIR}/plugins/register_plugin_cmake.cmake" + -P "${OpenVINODeveloperScripts_DIR}/plugins/register_plugin_cmake.cmake" COMMENT "Registering plugins to plugins.xml config file" VERBATIM) @@ -266,6 +267,7 @@ endmacro() # ie_register_plugins() # macro(ie_register_plugins) + message(WARNING "'ie_register_plugins' is deprecated. Please, use 'ov_register_plugins'") ov_register_plugins(${ARGN}) endmacro() @@ -346,7 +348,7 @@ function(ov_generate_plugins_hpp) else() set(ov_plugins_hpp "${CMAKE_BINARY_DIR}/src/inference/ov_plugins.hpp") endif() - set(plugins_hpp_in "${IEDevScripts_DIR}/plugins/plugins.hpp.in") + set(plugins_hpp_in "${OpenVINODeveloperScripts_DIR}/plugins/plugins.hpp.in") add_custom_command(OUTPUT "${ov_plugins_hpp}" COMMAND @@ -357,10 +359,10 @@ function(ov_generate_plugins_hpp) -D "OV_PLUGINS_HPP_HEADER=${ov_plugins_hpp}" ${device_configs} ${as_extension} - -P "${IEDevScripts_DIR}/plugins/create_plugins_hpp.cmake" + -P "${OpenVINODeveloperScripts_DIR}/plugins/create_plugins_hpp.cmake" DEPENDS "${plugins_hpp_in}" - "${IEDevScripts_DIR}/plugins/create_plugins_hpp.cmake" + "${OpenVINODeveloperScripts_DIR}/plugins/create_plugins_hpp.cmake" COMMENT "Generate ov_plugins.hpp" VERBATIM) diff --git a/cmake/developer_package/plugins/unregister_plugin_cmake.cmake b/cmake/developer_package/plugins/unregister_plugin_cmake.cmake index 11bb3b3822f6be..16543ad39b3925 100644 --- a/cmake/developer_package/plugins/unregister_plugin_cmake.cmake +++ b/cmake/developer_package/plugins/unregister_plugin_cmake.cmake @@ -7,7 +7,7 @@ if(NOT EXISTS "${OV_CONFIG_OUTPUT_FILE}") endif() # remove plugin file -file(REMOVE "${OV_CONFIGS_DIR}/${IE_PLUGIN_NAME}.xml") +file(REMOVE "${OV_CONFIGS_DIR}/${OV_PLUGIN_NAME}.xml") # remove plugin set(newContent "") @@ -15,7 +15,7 @@ file(STRINGS "${OV_CONFIG_OUTPUT_FILE}" content) set(skip_plugin OFF) foreach(line IN LISTS content) - if("${line}" MATCHES "name=\"${IE_PLUGIN_NAME}\"") + if("${line}" MATCHES "name=\"${OV_PLUGIN_NAME}\"") set(skip_plugin ON) endif() diff --git a/cmake/developer_package/python_requirements.cmake b/cmake/developer_package/python_requirements.cmake index 4d031f22c8a4a6..767f130668fea1 100644 --- a/cmake/developer_package/python_requirements.cmake +++ b/cmake/developer_package/python_requirements.cmake @@ -103,7 +103,7 @@ function(ov_check_pip_packages) from check_python_requirements import check_python_requirements ; check_python_requirements('${ARG_REQUIREMENTS_FILE}') ; " - WORKING_DIRECTORY "${IEDevScripts_DIR}" + WORKING_DIRECTORY "${OpenVINODeveloperScripts_DIR}" RESULT_VARIABLE EXIT_CODE OUTPUT_VARIABLE OUTPUT_TEXT ERROR_VARIABLE ERROR_TEXT) diff --git a/cmake/developer_package/shellcheck/shellcheck.cmake b/cmake/developer_package/shellcheck/shellcheck.cmake index 3b18ff02abf359..469a751e04df01 100644 --- a/cmake/developer_package/shellcheck/shellcheck.cmake +++ b/cmake/developer_package/shellcheck/shellcheck.cmake @@ -17,20 +17,20 @@ if(shellcheck_PROGRAM) endif() endif() -function(ie_shellcheck_process) +function(ov_shellcheck_process) if(NOT shellcheck_PROGRAM) message(WARNING "shellcheck tool is not found") return() endif() - cmake_parse_arguments(IE_SHELLCHECK "" "DIRECTORY" "SKIP" ${ARGN}) + cmake_parse_arguments(SHELLCHECK "" "DIRECTORY" "SKIP" ${ARGN}) - set(IE_SHELLCHECK_SCRIPT "${IEDevScripts_DIR}/shellcheck/shellcheck_process.cmake") - file(GLOB_RECURSE scripts "${IE_SHELLCHECK_DIRECTORY}/*.sh") + set(SHELLCHECK_SCRIPT "${OpenVINODeveloperScripts_DIR}/shellcheck/shellcheck_process.cmake") + file(GLOB_RECURSE scripts "${SHELLCHECK_DIRECTORY}/*.sh") foreach(script IN LISTS scripts) # check if we need to skip scripts unset(skip_script) - foreach(skip_directory IN LISTS IE_SHELLCHECK_SKIP) + foreach(skip_directory IN LISTS SHELLCHECK_SKIP) if(script MATCHES "${skip_directory}/*") set(skip_script ON) endif() @@ -39,21 +39,21 @@ function(ie_shellcheck_process) continue() endif() - string(REPLACE "${IE_SHELLCHECK_DIRECTORY}" "${CMAKE_BINARY_DIR}/shellcheck" output_file ${script}) + string(REPLACE "${SHELLCHECK_DIRECTORY}" "${CMAKE_BINARY_DIR}/shellcheck" output_file ${script}) set(output_file "${output_file}.txt") get_filename_component(script_name "${script}" NAME) add_custom_command(OUTPUT ${output_file} COMMAND ${CMAKE_COMMAND} - -D IE_SHELLCHECK_PROGRAM=${shellcheck_PROGRAM} - -D IE_SHELL_SCRIPT=${script} - -D IE_SHELLCHECK_OUTPUT=${output_file} - -P ${IE_SHELLCHECK_SCRIPT} - DEPENDS ${script} ${IE_SHELLCHECK_SCRIPT} + -D SHELLCHECK_PROGRAM=${shellcheck_PROGRAM} + -D SHELL_SCRIPT=${script} + -D SHELLCHECK_OUTPUT=${output_file} + -P ${SHELLCHECK_SCRIPT} + DEPENDS ${script} ${SHELLCHECK_SCRIPT} COMMENT "Check script ${script_name}" VERBATIM) list(APPEND outputs ${output_file}) endforeach() - add_custom_target(ie_shellcheck DEPENDS ${outputs}) + add_custom_target(ov_shellcheck DEPENDS ${outputs}) endfunction() diff --git a/cmake/developer_package/shellcheck/shellcheck_process.cmake b/cmake/developer_package/shellcheck/shellcheck_process.cmake index adc53f9ab51093..f7fe1a299b0c3b 100644 --- a/cmake/developer_package/shellcheck/shellcheck_process.cmake +++ b/cmake/developer_package/shellcheck/shellcheck_process.cmake @@ -2,25 +2,19 @@ # SPDX-License-Identifier: Apache-2.0 # -if(NOT DEFINED IE_SHELLCHECK_PROGRAM) - message(FATAL_ERROR "IE_SHELLCHECK_PROGRAM is not defined") -endif() - -if(NOT DEFINED IE_SHELL_SCRIPT) - message(FATAL_ERROR "IE_SHELL_SCRIPT is not defined") -endif() - -if(NOT DEFINED IE_SHELLCHECK_OUTPUT) - message(FATAL_ERROR "IE_SHELLCHECK_OUTPUT is not defined") -endif() +foreach(var SHELLCHECK_PROGRAM SHELL_SCRIPT SHELLCHECK_OUTPUT) + if(NOT DEFINED ${var}) + message(FATAL_ERROR "${var} is not defined") + endif() +endforeach() set(rules "SC1091,SC2164,SC2162,SC1090") -execute_process(COMMAND ${IE_SHELLCHECK_PROGRAM} --exclude=${rules} ${IE_SHELL_SCRIPT} +execute_process(COMMAND ${SHELLCHECK_PROGRAM} --exclude=${rules} ${SHELL_SCRIPT} OUTPUT_VARIABLE error_message RESULT_VARIABLE exit_code OUTPUT_STRIP_TRAILING_WHITESPACE) -file(WRITE "${IE_SHELLCHECK_OUTPUT}" "${error_message}") +file(WRITE "${SHELLCHECK_OUTPUT}" "${error_message}") if(NOT exit_code EQUAL 0) message(FATAL_ERROR "${error_message}") diff --git a/cmake/developer_package/tbb/TBBConfig.cmake b/cmake/developer_package/tbb/TBBConfig.cmake index a192f6e4a3a884..135e2719d427fe 100644 --- a/cmake/developer_package/tbb/TBBConfig.cmake +++ b/cmake/developer_package/tbb/TBBConfig.cmake @@ -14,13 +14,13 @@ # Path to IE own version of TBBConfig.cmake old TBB version without cmake config. if(APPLE) - set(IE_OWN_TBB_CONFIG tbb/mac) + set(_OV_OWN_TBB_CONFIG tbb/mac) elseif(UNIX) - set(IE_OWN_TBB_CONFIG tbb/lnx) + set(_OV_OWN_TBB_CONFIG tbb/lnx) elseif(WIN) - set(IE_OWN_TBB_CONFIG tbb/win) + set(_OV_OWN_TBB_CONFIG tbb/win) else() - unset(IE_OWN_TBB_CONFIG) + unset(_OV_OWN_TBB_CONFIG) endif() unset(TBB_DIR) @@ -29,8 +29,10 @@ unset(TBB_DIR CACHE) find_package(TBB 2017.0 CONFIG - PATHS "${IEDevScripts_DIR}/${IE_OWN_TBB_CONFIG}" + PATHS "${OpenVINODeveloperScripts_DIR}/${_OV_OWN_TBB_CONFIG}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) find_package_handle_standard_args(TBB CONFIG_MODE) + +unset(_OV_OWN_TBB_CONFIG) diff --git a/cmake/developer_package/version.cmake b/cmake/developer_package/version.cmake index 9a461c43a73499..1b71befe448b76 100644 --- a/cmake/developer_package/version.cmake +++ b/cmake/developer_package/version.cmake @@ -4,50 +4,51 @@ find_package(Git QUIET) -function (branchName VAR) - if(NOT DEFINED repo_root) - message(FATAL_ERROR "repo_root is not defined") - endif() +function(ov_branch_name VAR REPO_ROOT) if(GIT_FOUND) execute_process( COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD - WORKING_DIRECTORY ${repo_root} + WORKING_DIRECTORY ${REPO_ROOT} OUTPUT_VARIABLE GIT_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE) set (${VAR} ${GIT_BRANCH} PARENT_SCOPE) endif() endfunction() -function (commitHash VAR) - if(NOT DEFINED repo_root) - message(FATAL_ERROR "repo_root is not defined") - endif() +function(ov_commit_hash VAR REPO_ROOT) if(GIT_FOUND) execute_process( COMMAND ${GIT_EXECUTABLE} rev-parse --short=11 HEAD - WORKING_DIRECTORY ${repo_root} + WORKING_DIRECTORY ${REPO_ROOT} OUTPUT_VARIABLE GIT_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE) set (${VAR} ${GIT_COMMIT_HASH} PARENT_SCOPE) endif() endfunction() -function (commitNumber VAR) - if(NOT DEFINED repo_root) - message(FATAL_ERROR "repo_root is not defined") - endif() +function(ov_commit_number VAR REPO_ROOT) if(GIT_FOUND) execute_process( COMMAND ${GIT_EXECUTABLE} rev-list --count --first-parent HEAD - WORKING_DIRECTORY ${repo_root} + WORKING_DIRECTORY ${REPO_ROOT} OUTPUT_VARIABLE GIT_COMMIT_NUMBER OUTPUT_STRIP_TRAILING_WHITESPACE) set (${VAR} ${GIT_COMMIT_NUMBER} PARENT_SCOPE) + else() + # set zeros since git is not available + set (${VAR} "000" PARENT_SCOPE) endif() endfunction() -macro(ov_parse_ci_build_number) - set(OpenVINO_VERSION_BUILD 000) +macro(ov_parse_ci_build_number repo_root) + # provides OpenVINO version + # 1. If CI_BUILD_NUMBER is defined, parses this information + # 2. Otherwise, either: + # - parses openvino/core/version.hpp + # - takes from OpenVINOConfig-version.cmake in case of relocatable Developer package + if (DEFINED ENV{CI_BUILD_NUMBER}) + set(CI_BUILD_NUMBER $ENV{CI_BUILD_NUMBER}) + endif() if(CI_BUILD_NUMBER MATCHES "^([0-9]+)\.([0-9]+)\.([0-9]+)\-([0-9]+)\-.*") set(OpenVINO_VERSION_MAJOR ${CMAKE_MATCH_1}) @@ -63,12 +64,9 @@ macro(ov_parse_ci_build_number) message(FATAL_ERROR "Failed to parse CI_BUILD_NUMBER which is ${CI_BUILD_NUMBER}") endif() - if(NOT DEFINED repo_root) - message(FATAL_ERROR "repo_root is not defined") - endif() - - macro(ov_get_hpp_version) + function(ov_compare_version_with_headers) if(NOT DEFINED OpenVINO_SOURCE_DIR) + # if we are not in OpenVINO source tree, let's ignore this comparison return() endif() @@ -101,30 +99,29 @@ macro(ov_parse_ci_build_number) endif() endforeach() - # detect commit number - commitNumber(OpenVINO_VERSION_BUILD_HPP) - if(OpenVINO_VERSION_BUILD STREQUAL "000" AND DEFINED OpenVINO_VERSION_BUILD_HPP) - set(OpenVINO_VERSION_BUILD "${OpenVINO_VERSION_BUILD_HPP}") - else() - set(OpenVINO_VERSION_BUILD_HPP "${OpenVINO_VERSION_BUILD}") - endif() - - set(ov_hpp_version_is_found ON) - endmacro() - - # detect OpenVINO version via openvino/core/version.hpp and ie_version.hpp - ov_get_hpp_version() - - if(ov_hpp_version_is_found) - foreach(var OpenVINO_VERSION_MAJOR OpenVINO_VERSION_MINOR OpenVINO_VERSION_PATCH OpenVINO_VERSION_BUILD) + foreach(var OpenVINO_VERSION_MAJOR OpenVINO_VERSION_MINOR OpenVINO_VERSION_PATCH) if(DEFINED ${var} AND NOT ${var} EQUAL ${var}_HPP) message(FATAL_ERROR "${var} parsed from CI_BUILD_NUMBER (${${var}}) \ and from openvino/core/version.hpp (${${var}_HPP}) are different") else() # CI_BUILD_NUMBER is not defined well, take info from openvino/core/version.hpp as a baseline - set(${var} ${${var}_HPP}) + set(${var} ${${var}_HPP} PARENT_SCOPE) endif() endforeach() + endfunction() + + # detect OpenVINO version via openvino/core/version.hpp and ie_version.hpp + ov_compare_version_with_headers() + + # detect commit number + ov_commit_number(OpenVINO_VERSION_BUILD_FROM_GIT "${repo_root}") + + if(OpenVINO_VERSION_BUILD AND NOT OpenVINO_VERSION_BUILD STREQUAL OpenVINO_VERSION_BUILD_FROM_GIT) + # TODO: replace with FATAL_ERROR once NPU version will be discussed + message(WARNING "OpenVINO_VERSION_BUILD parsed from CI_BUILD_NUMBER (${OpenVINO_VERSION_BUILD}) \ + and determined by git (${OpenVINO_VERSION_BUILD_FROM_GIT}) are different") + else() + set(OpenVINO_VERSION_BUILD "${OpenVINO_VERSION_BUILD_FROM_GIT}") endif() set(OpenVINO_SOVERSION "${OpenVINO_VERSION_MAJOR}${OpenVINO_VERSION_MINOR}${OpenVINO_VERSION_PATCH}") @@ -140,8 +137,8 @@ macro(ov_parse_ci_build_number) if(NOT the_whole_version_is_defined_by_ci) # create CI_BUILD_NUMBER - branchName(GIT_BRANCH) - commitHash(GIT_COMMIT_HASH) + ov_branch_name(GIT_BRANCH "${repo_root}") + ov_commit_hash(GIT_COMMIT_HASH "${repo_root}") if(NOT GIT_BRANCH STREQUAL "master") set(GIT_BRANCH_POSTFIX "-${GIT_BRANCH}") @@ -157,15 +154,9 @@ macro(ov_parse_ci_build_number) endif() endmacro() -# provides OpenVINO version -# 1. If CI_BUILD_NUMBER is defined, parses this information -# 2. Otherwise, parses openvino/core/version.hpp -if (DEFINED ENV{CI_BUILD_NUMBER}) - set(CI_BUILD_NUMBER $ENV{CI_BUILD_NUMBER}) -endif() -ov_parse_ci_build_number() - macro (addVersionDefines FILE) + message(WARNING "'addVersionDefines' is deprecated. Please, use 'ov_add_version_defines'") + set(__version_file ${FILE}) if(NOT IS_ABSOLUTE ${__version_file}) set(__version_file "${CMAKE_CURRENT_SOURCE_DIR}/${__version_file}") @@ -218,7 +209,7 @@ macro (ov_add_version_defines FILE TARGET) $ $) set_target_properties(${TARGET}_version - PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE + PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE $) target_sources(${TARGET} PRIVATE $) diff --git a/cmake/developer_package/vs_version/vs_version.cmake b/cmake/developer_package/vs_version/vs_version.cmake index 6a6209e49cb312..ce7956798291ee 100644 --- a/cmake/developer_package/vs_version/vs_version.cmake +++ b/cmake/developer_package/vs_version/vs_version.cmake @@ -73,7 +73,7 @@ function(ov_add_vs_version_file) set(OV_VS_VER_INTERNALNAME_STR ${VS_VER_NAME}) set(vs_version_output "${CMAKE_CURRENT_BINARY_DIR}/vs_version.rc") - configure_file("${IEDevScripts_DIR}/vs_version/vs_version.rc.in" "${vs_version_output}" @ONLY) + configure_file("${OpenVINODeveloperScripts_DIR}/vs_version/vs_version.rc.in" "${vs_version_output}" @ONLY) source_group("src" FILES ${vs_version_output}) target_sources(${VS_VER_NAME} PRIVATE ${vs_version_output}) diff --git a/cmake/developer_package/whole_archive.cmake b/cmake/developer_package/whole_archive.cmake index ae5d56aa5d0337..0ad00055fbfb0e 100644 --- a/cmake/developer_package/whole_archive.cmake +++ b/cmake/developer_package/whole_archive.cmake @@ -5,15 +5,14 @@ #[[ function links static library without removing any symbol from it. -ieTargetLinkWholeArchive( [ ...]) +ov_target_link_whole_archive( [ ...]) Example: -ieTargetLinkWholeArchive("FunctionalTests" "CommonLib" "AnotherLib") +ov_target_link_whole_archive("FunctionalTests" "CommonLib" "AnotherLib") #]] -function(ieTargetLinkWholeArchive targetName) - set(libs) - foreach(staticLib ${ARGN}) +function(ov_target_link_whole_archive targetName) + foreach(staticLib IN LISTS ARGN) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") # CMake does not support generator expression in LINK_FLAGS, so we workaround it a little bit: # passing same static library as normal link (to get build deps working, and includes too), than using WHOLEARCHIVE option @@ -52,3 +51,10 @@ function(ieTargetLinkWholeArchive targetName) target_link_libraries(${targetName} PRIVATE ${libs}) endif() endfunction() + +# deprecated + +function(ieTargetLinkWholeArchive) + message(WARNING "'ieTargetLinkWholeArchive' is deprecated, use 'ov_target_link_whole_archive' instead") + ov_target_link_whole_archive(${ARGN}) +endfunction() diff --git a/cmake/extra_modules.cmake b/cmake/extra_modules.cmake index afc1dc335b3e55..6c392fcc6eed12 100644 --- a/cmake/extra_modules.cmake +++ b/cmake/extra_modules.cmake @@ -9,13 +9,10 @@ function(ie_generate_dev_package_config) set(OpenCV_FOUND OFF) endif() - foreach(component IN LISTS openvino_export_components) - # export all targets with prefix and use them during extra modules build - export(TARGETS ${${component}} NAMESPACE IE:: - APPEND FILE "${CMAKE_BINARY_DIR}/${component}_dev_targets.cmake") - list(APPEND all_dev_targets ${${component}}) - endforeach() - add_custom_target(ie_dev_targets DEPENDS ${all_dev_targets}) + # export all targets with prefix and use them during extra modules build + export(TARGETS ${_OPENVINO_DEVELOPER_PACKAGE_TARGETS} NAMESPACE IE:: + APPEND FILE "${CMAKE_BINARY_DIR}/inference_engine_developer_package_targets.cmake") + add_custom_target(ie_dev_targets DEPENDS ${_OPENVINO_DEVELOPER_PACKAGE_TARGETS}) set(PATH_VARS "OpenVINO_SOURCE_DIR") if(ENABLE_SAMPLES OR ENABLE_TESTS) @@ -44,20 +41,20 @@ function(ov_generate_dev_package_config) set(OpenCV_FOUND OFF) endif() - foreach(component IN LISTS openvino_export_components) - # filter out targets which are installed by OpenVINOConfig.cmake static build case - set(exported_targets) - foreach(target IN LISTS ${component}) - if(NOT target IN_LIST openvino_installed_targets) - list(APPEND exported_targets ${target}) - endif() - endforeach() - # export all developer targets with prefix and use them during extra modules build - export(TARGETS ${exported_targets} NAMESPACE openvino:: - APPEND FILE "${CMAKE_BINARY_DIR}/ov_${component}_dev_targets.cmake") - list(APPEND all_dev_targets ${${component}}) - endforeach() - add_custom_target(ov_dev_targets DEPENDS ${all_dev_targets}) + # create a helper target to build all developer package targets + add_custom_target(ov_dev_targets DEPENDS ${_OPENVINO_DEVELOPER_PACKAGE_TARGETS}) + + # filter out targets which are installed by OpenVINOConfig.cmake static build case + if(openvino_installed_targets) + list(REMOVE_ITEM _OPENVINO_DEVELOPER_PACKAGE_TARGETS ${openvino_installed_targets}) + endif() + # export all developer targets with prefix and use them during extra modules build + export(TARGETS ${_OPENVINO_DEVELOPER_PACKAGE_TARGETS} NAMESPACE openvino:: + APPEND FILE "${CMAKE_BINARY_DIR}/openvino_developer_package_targets.cmake") + + # + # OpenVINODeveloperPackageConfig.cmake for build tree + # set(PATH_VARS "OpenVINO_SOURCE_DIR") if(ENABLE_SAMPLES OR ENABLE_TESTS) @@ -77,38 +74,91 @@ function(ov_generate_dev_package_config) configure_file("${OpenVINO_SOURCE_DIR}/cmake/templates/OpenVINOConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/OpenVINODeveloperPackageConfig-version.cmake" @ONLY) + + # + # OpenVINODeveloperPackageConfig.cmake for installation tree + # + + set(DEV_PACKAGE_ROOT_DIR developer_package) + set(DEV_PACKAGE_CMAKE_DIR ${DEV_PACKAGE_ROOT_DIR}/cmake) + set(DEVELOPER_PACKAGE_COMPONENT developer_package) + set(DEVELOPER_PACKAGE_EXPORT_SET OpenVINODeveloperTargets) + + # create and install main developer package config files + configure_package_config_file("${OpenVINO_SOURCE_DIR}/cmake/templates/OpenVINODeveloperPackageConfigRelocatable.cmake.in" + "${OpenVINO_BINARY_DIR}/share/OpenVINODeveloperPackageConfig.cmake" + INSTALL_DESTINATION ${DEV_PACKAGE_CMAKE_DIR} + NO_CHECK_REQUIRED_COMPONENTS_MACRO) + + configure_file("${OpenVINO_SOURCE_DIR}/cmake/templates/OpenVINOConfig-version.cmake.in" + "${OpenVINO_BINARY_DIR}/share/OpenVINODeveloperPackageConfig-version.cmake" + @ONLY) + + install(FILES "${OpenVINO_BINARY_DIR}/share/OpenVINODeveloperPackageConfig.cmake" + "${OpenVINO_BINARY_DIR}/share/OpenVINODeveloperPackageConfig-version.cmake" + DESTINATION ${DEV_PACKAGE_CMAKE_DIR} + COMPONENT ${DEVELOPER_PACKAGE_COMPONENT} + EXCLUDE_FROM_ALL) + + # Install whole 'cmake/developer_package' folder + install(DIRECTORY "${OpenVINODeveloperScripts_DIR}/" + DESTINATION "${DEV_PACKAGE_CMAKE_DIR}" + COMPONENT ${DEVELOPER_PACKAGE_COMPONENT} + EXCLUDE_FROM_ALL) + + # Install CMakeLists.txt to read cache variables from + install(FILES "${OpenVINO_BINARY_DIR}/CMakeCache.txt" + DESTINATION ${DEV_PACKAGE_CMAKE_DIR} + COMPONENT ${DEVELOPER_PACKAGE_COMPONENT} + EXCLUDE_FROM_ALL) + + # install developer package targets + install(TARGETS ${_OPENVINO_DEVELOPER_PACKAGE_TARGETS} EXPORT ${DEVELOPER_PACKAGE_EXPORT_SET} + RUNTIME DESTINATION ${DEV_PACKAGE_ROOT_DIR}/bin COMPONENT ${DEVELOPER_PACKAGE_COMPONENT} EXCLUDE_FROM_ALL + ARCHIVE DESTINATION ${DEV_PACKAGE_ROOT_DIR}/lib COMPONENT ${DEVELOPER_PACKAGE_COMPONENT} EXCLUDE_FROM_ALL + LIBRARY DESTINATION ${DEV_PACKAGE_ROOT_DIR}/lib COMPONENT ${DEVELOPER_PACKAGE_COMPONENT} EXCLUDE_FROM_ALL) + + install(EXPORT ${DEVELOPER_PACKAGE_EXPORT_SET} + FILE OpenVINODeveloperPackageTargets.cmake + NAMESPACE openvino:: + DESTINATION ${DEV_PACKAGE_ROOT_DIR}/cmake + COMPONENT ${DEVELOPER_PACKAGE_COMPONENT} + EXCLUDE_FROM_ALL) + + # Note: that OpenCV and gflags are explicitly not installed to simplify relocatable + # OpenVINO Developer package maintainance. OpenVINO_SOURCE_DIR is also unvailable, because + # relocatable developer package can be used on a different machine where OpenVINO repo is not available endfunction() # # Add extra modules # -function(register_extra_modules) +function(_ov_register_extra_modules) set(InferenceEngineDeveloperPackage_DIR "${CMAKE_CURRENT_BINARY_DIR}/build-modules") set(OpenVINODeveloperPackage_DIR "${CMAKE_BINARY_DIR}/build-modules") set(OpenVINO_DIR "${CMAKE_BINARY_DIR}") - function(generate_fake_dev_package NS) + function(_ov_generate_fake_developer_package NS) if(NS STREQUAL "openvino") set(devconfig_file "${OpenVINODeveloperPackage_DIR}/OpenVINODeveloperPackageConfig.cmake") else() set(devconfig_file "${InferenceEngineDeveloperPackage_DIR}/InferenceEngineDeveloperPackageConfig.cmake") endif() - file(REMOVE "${devconfig_file}") + file(REMOVE "${devconfig_file}") file(WRITE "${devconfig_file}" "\# !! AUTOGENERATED: DON'T EDIT !!\n\n") - foreach(targets_list IN LISTS ${openvino_export_components}) - foreach(target IN LISTS targets_list) - file(APPEND "${devconfig_file}" "if(NOT TARGET ${NS}::${target}) - add_library(${NS}::${target} ALIAS ${target}) + foreach(exported_target IN LISTS _OPENVINO_DEVELOPER_PACKAGE_TARGETS) + file(APPEND "${devconfig_file}" "if(NOT TARGET ${NS}::${exported_target}) + add_library(${NS}::${exported_target} ALIAS ${exported_target}) endif()\n") - endforeach() endforeach() endfunction() - generate_fake_dev_package("openvino") - generate_fake_dev_package("IE") + _ov_generate_fake_developer_package("openvino") + # TODO: remove with API 1.0 removal + _ov_generate_fake_developer_package("IE") # detect where OPENVINO_EXTRA_MODULES contains folders with CMakeLists.txt # other folders are supposed to have sub-folders with CMakeLists.txt @@ -155,21 +205,18 @@ endfunction() # Extra modules support # -# this InferenceEngineDeveloperPackageConfig.cmake is not used -# during extra modules build since it's generated after modules -# are configured +# this OpenVINODeveloperPackageConfig.cmake is not used during extra modules build +# since it's generated after modules are configured ie_generate_dev_package_config() ov_generate_dev_package_config() # extra modules must be registered after inference_engine library # and all other OpenVINO Core libraries are creared -# because 'register_extra_modules' creates fake InferenceEngineDeveloperPackageConfig.cmake +# because '_ov_register_extra_modules' creates fake InferenceEngineDeveloperPackageConfig.cmake # with all imported developer targets -register_extra_modules() +_ov_register_extra_modules() -# for static libraries case we need to generate final ov_plugins.hpp -# with all the information about plugins +# we need to generate final ov_plugins.hpp with all the information about plugins ov_generate_plugins_hpp() - -# used for static build +# we need to generate final ov_frontends.hpp with all the information about frontends ov_generate_frontends_hpp() diff --git a/cmake/features.cmake b/cmake/features.cmake index 01a219e0aaf6a4..2e3ef5d4aa82b1 100644 --- a/cmake/features.cmake +++ b/cmake/features.cmake @@ -14,12 +14,12 @@ else() set(ENABLE_INTEL_CPU_DEFAULT ON) endif() -ie_dependent_option (ENABLE_INTEL_CPU "CPU plugin for OpenVINO Runtime" ${ENABLE_INTEL_CPU_DEFAULT} +ov_dependent_option (ENABLE_INTEL_CPU "CPU plugin for OpenVINO Runtime" ${ENABLE_INTEL_CPU_DEFAULT} "RISCV64 OR X86 OR X86_64 OR AARCH64 OR ARM" OFF) -ie_dependent_option (ENABLE_ARM_COMPUTE_CMAKE "Enable ARM Compute build via cmake" OFF "ENABLE_INTEL_CPU" OFF) +ov_dependent_option (ENABLE_ARM_COMPUTE_CMAKE "Enable ARM Compute build via cmake" OFF "ENABLE_INTEL_CPU" OFF) -ie_option (ENABLE_TESTS "unit, behavior and functional tests" OFF) +ov_option (ENABLE_TESTS "unit, behavior and functional tests" OFF) if(ENABLE_TESTS) include(CTest) @@ -32,7 +32,7 @@ else() set(ENABLE_INTEL_GPU_DEFAULT OFF) endif() -ie_dependent_option (ENABLE_INTEL_GPU "GPU OpenCL-based plugin for OpenVINO Runtime" ${ENABLE_INTEL_GPU_DEFAULT} "X86_64 OR AARCH64;NOT APPLE;NOT WINDOWS_STORE;NOT WINDOWS_PHONE" OFF) +ov_dependent_option (ENABLE_INTEL_GPU "GPU OpenCL-based plugin for OpenVINO Runtime" ${ENABLE_INTEL_GPU_DEFAULT} "X86_64 OR AARCH64;NOT APPLE;NOT WINDOWS_STORE;NOT WINDOWS_PHONE" OFF) if (ANDROID OR MINGW OR (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0) OR (NOT BUILD_SHARED_LIBS AND ENABLE_INTEL_CPU)) # oneDNN doesn't support old compilers and android builds for now, so we'll build GPU plugin without oneDNN @@ -42,31 +42,31 @@ else() set(ENABLE_ONEDNN_FOR_GPU_DEFAULT ON) endif() -ie_dependent_option (ENABLE_ONEDNN_FOR_GPU "Enable oneDNN with GPU support" ${ENABLE_ONEDNN_FOR_GPU_DEFAULT} "ENABLE_INTEL_GPU" OFF) +ov_dependent_option (ENABLE_ONEDNN_FOR_GPU "Enable oneDNN with GPU support" ${ENABLE_ONEDNN_FOR_GPU_DEFAULT} "ENABLE_INTEL_GPU" OFF) -ie_option (ENABLE_DEBUG_CAPS "enable OpenVINO debug capabilities at runtime" OFF) -ie_dependent_option (ENABLE_GPU_DEBUG_CAPS "enable GPU debug capabilities at runtime" ON "ENABLE_DEBUG_CAPS;ENABLE_INTEL_GPU" OFF) -ie_dependent_option (ENABLE_CPU_DEBUG_CAPS "enable CPU debug capabilities at runtime" ON "ENABLE_DEBUG_CAPS;ENABLE_INTEL_CPU" OFF) +ov_option (ENABLE_DEBUG_CAPS "enable OpenVINO debug capabilities at runtime" OFF) +ov_dependent_option (ENABLE_GPU_DEBUG_CAPS "enable GPU debug capabilities at runtime" ON "ENABLE_DEBUG_CAPS;ENABLE_INTEL_GPU" OFF) +ov_dependent_option (ENABLE_CPU_DEBUG_CAPS "enable CPU debug capabilities at runtime" ON "ENABLE_DEBUG_CAPS;ENABLE_INTEL_CPU" OFF) -ie_option (ENABLE_PROFILING_ITT "Build with ITT tracing. Optionally configure pre-built ittnotify library though INTEL_VTUNE_DIR variable." OFF) +ov_option (ENABLE_PROFILING_ITT "Build with ITT tracing. Optionally configure pre-built ittnotify library though INTEL_VTUNE_DIR variable." OFF) -ie_option_enum(ENABLE_PROFILING_FILTER "Enable or disable ITT counter groups.\ +ov_option_enum(ENABLE_PROFILING_FILTER "Enable or disable ITT counter groups.\ Supported values:\ ALL - enable all ITT counters (default value)\ FIRST_INFERENCE - enable only first inference time counters" ALL ALLOWED_VALUES ALL FIRST_INFERENCE) -ie_option (ENABLE_PROFILING_FIRST_INFERENCE "Build with ITT tracing of first inference time." ON) +ov_option (ENABLE_PROFILING_FIRST_INFERENCE "Build with ITT tracing of first inference time." ON) -ie_option_enum(SELECTIVE_BUILD "Enable OpenVINO conditional compilation or statistics collection. \ +ov_option_enum(SELECTIVE_BUILD "Enable OpenVINO conditional compilation or statistics collection. \ In case SELECTIVE_BUILD is enabled, the SELECTIVE_BUILD_STAT variable should contain the path to the collected IntelSEAPI statistics. \ Usage: -DSELECTIVE_BUILD=ON -DSELECTIVE_BUILD_STAT=/path/*.csv" OFF ALLOWED_VALUES ON OFF COLLECT) -ie_option (ENABLE_DOCS "Build docs using Doxygen" OFF) +ov_option (ENABLE_DOCS "Build docs using Doxygen" OFF) find_package(PkgConfig QUIET) -ie_dependent_option (ENABLE_PKGCONFIG_GEN "Enable openvino.pc pkg-config file generation" ON "LINUX OR APPLE;PkgConfig_FOUND;BUILD_SHARED_LIBS" OFF) +ov_dependent_option (ENABLE_PKGCONFIG_GEN "Enable openvino.pc pkg-config file generation" ON "LINUX OR APPLE;PkgConfig_FOUND;BUILD_SHARED_LIBS" OFF) # # OpenVINO Runtime specific options @@ -80,14 +80,16 @@ else() set(THREADING_DEFAULT "TBB") endif() +set(THREADING_OPTIONS "TBB" "TBB_AUTO" "SEQ") +if(NOT APPLE) + list(APPEND THREADING_OPTIONS "OMP") +endif() + set(THREADING "${THREADING_DEFAULT}" CACHE STRING "Threading") -set_property(CACHE THREADING PROPERTY STRINGS "TBB" "TBB_AUTO" "OMP" "SEQ") -list (APPEND IE_OPTIONS THREADING) -if (NOT THREADING STREQUAL "TBB" AND - NOT THREADING STREQUAL "TBB_AUTO" AND - NOT THREADING STREQUAL "OMP" AND - NOT THREADING STREQUAL "SEQ") - message(FATAL_ERROR "THREADING should be set to TBB (default), TBB_AUTO, OMP or SEQ") +set_property(CACHE THREADING PROPERTY STRINGS ${THREADING_OPTIONS}) +list (APPEND OV_OPTIONS THREADING) +if(NOT THREADING IN_LIST THREADING_OPTIONS) + message(FATAL_ERROR "THREADING should be set to either ${THREADING_OPTIONS}") endif() if((THREADING STREQUAL "TBB" OR THREADING STREQUAL "TBB_AUTO") AND @@ -97,50 +99,50 @@ else() set(ENABLE_TBBBIND_2_5_DEFAULT OFF) endif() -ie_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) -ie_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_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) -ie_dependent_option (ENABLE_INTEL_GNA "GNA support for OpenVINO Runtime" ON +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) -ie_dependent_option (ENABLE_INTEL_GNA_DEBUG "GNA debug build" OFF "ENABLE_INTEL_GNA" OFF) -ie_dependent_option (ENABLE_V7_SERIALIZE "enables serialization to IR v7" OFF "ENABLE_INTEL_GNA" OFF) -ie_dependent_option (ENABLE_IR_V7_READER "Enables IR v7 reader" ${BUILD_SHARED_LIBS} "ENABLE_TESTS;ENABLE_INTEL_GNA" 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) -ie_dependent_option (ENABLE_GAPI_PREPROCESSING "Enables G-API preprocessing" ON "NOT MINGW64" OFF) +ov_dependent_option (ENABLE_GAPI_PREPROCESSING "Enables G-API preprocessing" ON "NOT MINGW64" OFF) -ie_option (ENABLE_MULTI "Enables MULTI Device Plugin" ON) -ie_option (ENABLE_AUTO "Enables AUTO Device Plugin" ON) -ie_option (ENABLE_AUTO_BATCH "Enables Auto-Batching Plugin" ON) -ie_option (ENABLE_HETERO "Enables Hetero Device Plugin" ON) -ie_option (ENABLE_TEMPLATE "Enable template plugin" ON) +ov_option (ENABLE_MULTI "Enables MULTI Device Plugin" ON) +ov_option (ENABLE_AUTO "Enables AUTO Device Plugin" ON) +ov_option (ENABLE_AUTO_BATCH "Enables Auto-Batching Plugin" ON) +ov_option (ENABLE_HETERO "Enables Hetero Device Plugin" ON) +ov_option (ENABLE_TEMPLATE "Enable template plugin" ON) -ie_dependent_option (ENABLE_PLUGINS_XML "Generate plugins.xml configuration file or not" OFF "BUILD_SHARED_LIBS" OFF) +ov_dependent_option (ENABLE_PLUGINS_XML "Generate plugins.xml configuration file or not" OFF "BUILD_SHARED_LIBS" OFF) -ie_dependent_option (GAPI_TEST_PERF "if GAPI unit tests should examine performance" OFF "ENABLE_TESTS;ENABLE_GAPI_PREPROCESSING" OFF) +ov_dependent_option (GAPI_TEST_PERF "if GAPI unit tests should examine performance" OFF "ENABLE_TESTS;ENABLE_GAPI_PREPROCESSING" OFF) -ie_dependent_option (ENABLE_FUNCTIONAL_TESTS "functional tests" ON "ENABLE_TESTS" OFF) +ov_dependent_option (ENABLE_FUNCTIONAL_TESTS "functional tests" ON "ENABLE_TESTS" OFF) -ie_option (ENABLE_SAMPLES "console samples are part of OpenVINO Runtime package" ON) +ov_option (ENABLE_SAMPLES "console samples are part of OpenVINO Runtime package" ON) set(OPENVINO_EXTRA_MODULES "" CACHE STRING "Extra paths for extra modules to include into OpenVINO build") find_host_package(Python3 QUIET COMPONENTS Interpreter) if(Python3_Interpreter_FOUND) - ie_option(ENABLE_OV_ONNX_FRONTEND "Enable ONNX FrontEnd" ON) + ov_option(ENABLE_OV_ONNX_FRONTEND "Enable ONNX FrontEnd" ON) else() - ie_option(ENABLE_OV_ONNX_FRONTEND "Enable ONNX FrontEnd" OFF) -endif() -ie_option(ENABLE_OV_PADDLE_FRONTEND "Enable PaddlePaddle FrontEnd" ON) -ie_option(ENABLE_OV_IR_FRONTEND "Enable IR FrontEnd" ON) -ie_option(ENABLE_OV_PYTORCH_FRONTEND "Enable PyTorch FrontEnd" ON) -ie_option(ENABLE_OV_IR_FRONTEND "Enable IR FrontEnd" ON) -ie_option(ENABLE_OV_TF_FRONTEND "Enable TensorFlow FrontEnd" ON) -ie_option(ENABLE_OV_TF_LITE_FRONTEND "Enable TensorFlow Lite FrontEnd" ON) -ie_dependent_option(ENABLE_SNAPPY_COMPRESSION "Enables compression support for TF FE" ON + ov_option(ENABLE_OV_ONNX_FRONTEND "Enable ONNX FrontEnd" OFF) +endif() +ov_option(ENABLE_OV_PADDLE_FRONTEND "Enable PaddlePaddle FrontEnd" ON) +ov_option(ENABLE_OV_IR_FRONTEND "Enable IR FrontEnd" ON) +ov_option(ENABLE_OV_PYTORCH_FRONTEND "Enable PyTorch FrontEnd" ON) +ov_option(ENABLE_OV_IR_FRONTEND "Enable IR FrontEnd" ON) +ov_option(ENABLE_OV_TF_FRONTEND "Enable TensorFlow FrontEnd" ON) +ov_option(ENABLE_OV_TF_LITE_FRONTEND "Enable TensorFlow Lite FrontEnd" ON) +ov_dependent_option(ENABLE_SNAPPY_COMPRESSION "Enables compression support for TF FE" ON "ENABLE_OV_TF_FRONTEND" OFF) -ie_dependent_option (ENABLE_STRICT_DEPENDENCIES "Skip configuring \"convinient\" dependencies for efficient parallel builds" ON "ENABLE_TESTS;ENABLE_OV_ONNX_FRONTEND" OFF) +ov_dependent_option (ENABLE_STRICT_DEPENDENCIES "Skip configuring \"convinient\" dependencies for efficient parallel builds" ON "ENABLE_TESTS;ENABLE_OV_ONNX_FRONTEND" OFF) if(CMAKE_HOST_LINUX AND LINUX) # Debian packages are enabled on Ubuntu systems @@ -175,28 +177,28 @@ else() set(ENABLE_SYSTEM_TBB_DEFAULT ${ENABLE_SYSTEM_LIBS_DEFAULT}) endif() -ie_dependent_option (ENABLE_SYSTEM_TBB "Enables use of system TBB" ${ENABLE_SYSTEM_TBB_DEFAULT} +ov_dependent_option (ENABLE_SYSTEM_TBB "Enables use of system TBB" ${ENABLE_SYSTEM_TBB_DEFAULT} "THREADING MATCHES TBB" OFF) # TODO: turn it off by default during the work on cross-os distribution, because pugixml is not # available out of box on all systems (like RHEL, UBI) -ie_option (ENABLE_SYSTEM_PUGIXML "Enables use of system PugiXML" ${ENABLE_SYSTEM_PUGIXML_DEFAULT}) +ov_option (ENABLE_SYSTEM_PUGIXML "Enables use of system PugiXML" ${ENABLE_SYSTEM_PUGIXML_DEFAULT}) # the option is on by default, because we use only flatc compiler and don't use any libraries -ie_dependent_option(ENABLE_SYSTEM_FLATBUFFERS "Enables use of system flatbuffers" ${ENABLE_SYSTEM_FLATBUFFERS_DEFAULT} +ov_dependent_option(ENABLE_SYSTEM_FLATBUFFERS "Enables use of system flatbuffers" ${ENABLE_SYSTEM_FLATBUFFERS_DEFAULT} "ENABLE_OV_TF_LITE_FRONTEND" OFF) -ie_dependent_option (ENABLE_SYSTEM_OPENCL "Enables use of system OpenCL" ${ENABLE_SYSTEM_LIBS_DEFAULT} +ov_dependent_option (ENABLE_SYSTEM_OPENCL "Enables use of system OpenCL" ${ENABLE_SYSTEM_LIBS_DEFAULT} "ENABLE_INTEL_GPU" OFF) # the option is turned off by default, because we compile our own static version of protobuf # with LTO and -fPIC options, while system one does not have such flags -ie_dependent_option (ENABLE_SYSTEM_PROTOBUF "Enables use of system Protobuf" OFF +ov_dependent_option (ENABLE_SYSTEM_PROTOBUF "Enables use of system Protobuf" OFF "ENABLE_OV_ONNX_FRONTEND OR ENABLE_OV_PADDLE_FRONTEND OR ENABLE_OV_TF_FRONTEND" OFF) # the option is turned off by default, because we don't want to have a dependency on libsnappy.so -ie_dependent_option (ENABLE_SYSTEM_SNAPPY "Enables use of system version of Snappy" OFF +ov_dependent_option (ENABLE_SYSTEM_SNAPPY "Enables use of system version of Snappy" OFF "ENABLE_SNAPPY_COMPRESSION" OFF) -ie_dependent_option (ENABLE_PYTHON_PACKAGING "Enables packaging of Python API in APT / YUM" OFF +ov_dependent_option (ENABLE_PYTHON_PACKAGING "Enables packaging of Python API in APT / YUM" OFF "ENABLE_PYTHON;UNIX" OFF) -ie_option(ENABLE_OPENVINO_DEBUG "Enable output for OPENVINO_DEBUG statements" OFF) +ov_option(ENABLE_OPENVINO_DEBUG "Enable output for OPENVINO_DEBUG statements" OFF) if(NOT BUILD_SHARED_LIBS AND ENABLE_OV_TF_FRONTEND) set(FORCE_FRONTENDS_USE_PROTOBUF ON) @@ -216,4 +218,4 @@ if (ENABLE_PROFILING_RAW) add_definitions(-DENABLE_PROFILING_RAW=1) endif() -print_enabled_features() +ov_print_enabled_features() diff --git a/cmake/templates/InferenceEngineConfig.cmake.in b/cmake/templates/InferenceEngineConfig.cmake.in index ef3fad4b9ff0a4..5c4a9ca5c144e2 100644 --- a/cmake/templates/InferenceEngineConfig.cmake.in +++ b/cmake/templates/InferenceEngineConfig.cmake.in @@ -25,6 +25,8 @@ @PACKAGE_INIT@ +message(WARNING "find_package(InferenceEngine) is deprecated and will be removed in 2024.0 release. Please, use find_package(OpenVINO)") + if(NOT DEFINED CMAKE_FIND_PACKAGE_NAME) set(CMAKE_FIND_PACKAGE_NAME InferenceEngine) set(_ie_need_package_name_reset ON) @@ -77,7 +79,7 @@ endforeach() set(PACKAGE_PREFIX_DIR ${_ie_package_prefix_dir}) unset(_ie_package_prefix_dir) -set_and_check(InferenceEngine_INCLUDE_DIRS "@PACKAGE_IE_INCLUDE_DIR@") +set_and_check(InferenceEngine_INCLUDE_DIRS "@PACKAGE_OV_INCLUDE_DIR@") check_required_components(${CMAKE_FIND_PACKAGE_NAME}) diff --git a/cmake/templates/InferenceEngineDeveloperPackageConfig.cmake.in b/cmake/templates/InferenceEngineDeveloperPackageConfig.cmake.in index 4249559e027031..a98b4207e285d2 100644 --- a/cmake/templates/InferenceEngineDeveloperPackageConfig.cmake.in +++ b/cmake/templates/InferenceEngineDeveloperPackageConfig.cmake.in @@ -6,37 +6,39 @@ include(CMakeFindDependencyMacro) +message(WARNING "find_package(InferenceEngineDeveloperPackage) is deprecated and will be removed in 2024.0 release. Please, use find_package(OpenVINODeveloperPackage)") + # TODO: remove after changing [private plugins] set_and_check(OpenVINO_SOURCE_DIR "@OpenVINO_SOURCE_DIR@") # NPU set_and_check(OpenVINO_MAIN_SOURCE_DIR "@OpenVINO_SOURCE_DIR@") # NPU # Variables to export in plugin's projects -set(ie_options "@IE_OPTIONS@") -list(APPEND ie_options CMAKE_CXX_COMPILER_LAUNCHER CMAKE_C_COMPILER_LAUNCHER +set(ov_options "@OV_OPTIONS@") +list(APPEND ov_options CMAKE_CXX_COMPILER_LAUNCHER CMAKE_C_COMPILER_LAUNCHER CMAKE_CXX_LINKER_LAUNCHER CMAKE_C_LINKER_LAUNCHER - CMAKE_SKIP_RPATH CMAKE_INSTALL_PREFIX CPACK_GENERATOR) + CMAKE_INSTALL_PREFIX CPACK_GENERATOR) if(APPLE) - list(APPEND ie_options CMAKE_OSX_ARCHITECTURES CMAKE_OSX_DEPLOYMENT_TARGET) + list(APPEND ov_options CMAKE_OSX_ARCHITECTURES CMAKE_OSX_DEPLOYMENT_TARGET) endif() -get_property(_IE_GENERATOR_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) -if(_IE_GENERATOR_MULTI_CONFIG) - list(APPEND ie_options CMAKE_CONFIGURATION_TYPES) +get_property(_OV_GENERATOR_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(_OV_GENERATOR_MULTI_CONFIG) + list(APPEND ov_options CMAKE_CONFIGURATION_TYPES) if(CMAKE_GENERATOR MATCHES "^Ninja Multi-Config$") - list(APPEND ie_options CMAKE_DEFAULT_BUILD_TYPE) + list(APPEND ov_options CMAKE_DEFAULT_BUILD_TYPE) endif() else() - list(APPEND ie_options CMAKE_BUILD_TYPE) + list(APPEND ov_options CMAKE_BUILD_TYPE) endif() -unset(_IE_GENERATOR_MULTI_CONFIG) +unset(_OV_GENERATOR_MULTI_CONFIG) file(TO_CMAKE_PATH "${CMAKE_CURRENT_LIST_DIR}" cache_path) message(STATUS "The following CMake options are exported from Inference Engine Developer package") message(" ") -foreach(option IN LISTS ie_options) +foreach(option IN LISTS ov_options) if(NOT DEFINED "${option}") load_cache("${cache_path}" READ_WITH_PREFIX "" ${option}) endif() @@ -56,7 +58,7 @@ set(CMAKE_COMPILE_WARNING_AS_ERROR OFF) # Content # -find_dependency(IEDevScripts +find_dependency(OpenVINODeveloperScripts PATHS "${OpenVINO_SOURCE_DIR}/cmake/developer_package" NO_CMAKE_FIND_ROOT_PATH NO_DEFAULT_PATH) @@ -86,9 +88,7 @@ endif() _ov_find_tbb() -foreach(component @openvino_export_components@) - include("${CMAKE_CURRENT_LIST_DIR}/${component}_dev_targets.cmake") -endforeach() +include("${CMAKE_CURRENT_LIST_DIR}/inference_engine_developer_package_targets.cmake") if(TARGET IE::ov_core_dev AND NOT TARGET openvino::core::dev) add_library(openvino::core::dev INTERFACE IMPORTED) @@ -160,13 +160,13 @@ if(ENABLE_SYSTEM_PUGIXML) endif() endif() -set(_IE_nlohmann_json_FOUND "@nlohmann_json_FOUND@") -if(_IE_nlohmann_json_FOUND) +set(_ov_nlohmann_json_FOUND "@nlohmann_json_FOUND@") +if(_ov_nlohmann_json_FOUND) find_dependency(nlohmann_json) set_target_properties(nlohmann_json::nlohmann_json PROPERTIES IMPORTED_GLOBAL ON) add_library(IE::nlohmann_json ALIAS nlohmann_json::nlohmann_json) endif() -unset(_IE_nlohmann_json_FOUND) +unset(_ov_nlohmann_json_FOUND) # inherit OpenCV from main IE project if enabled if("@OpenCV_FOUND@") diff --git a/cmake/templates/OpenVINOConfig.cmake.in b/cmake/templates/OpenVINOConfig.cmake.in index 7dda80d8a312fd..470be5d17b1cf5 100644 --- a/cmake/templates/OpenVINOConfig.cmake.in +++ b/cmake/templates/OpenVINOConfig.cmake.in @@ -176,7 +176,7 @@ macro(_ov_find_tbb) set(enable_system_tbb "@ENABLE_SYSTEM_TBB@") if(NOT enable_system_tbb) - set_and_check(_tbb_dir "@PACKAGE_IE_TBB_DIR@") + set_and_check(_tbb_dir "@PACKAGE_OV_TBB_DIR@") # see https://stackoverflow.com/questions/28070810/cmake-generate-error-on-windows-as-it-uses-as-escape-seq if(DEFINED ENV{TBBROOT}) @@ -218,7 +218,7 @@ macro(_ov_find_tbb) set(install_tbbbind "@install_tbbbind@") if(install_tbbbind) - set_and_check(_tbb_bind_dir "@PACKAGE_IE_TBBBIND_DIR@") + set_and_check(_tbb_bind_dir "@PACKAGE_OV_TBBBIND_DIR@") _ov_find_dependency(TBBBIND_2_5 PATHS ${_tbb_bind_dir} NO_CMAKE_FIND_ROOT_PATH diff --git a/cmake/templates/OpenVINODeveloperPackageConfig.cmake.in b/cmake/templates/OpenVINODeveloperPackageConfig.cmake.in index 074139df5f3bf8..3620bcd091dab5 100644 --- a/cmake/templates/OpenVINODeveloperPackageConfig.cmake.in +++ b/cmake/templates/OpenVINODeveloperPackageConfig.cmake.in @@ -10,17 +10,17 @@ set_and_check(OpenVINO_SOURCE_DIR "@OpenVINO_SOURCE_DIR@") # Variables to export in plugin's projects -set(ov_options "@IE_OPTIONS@") +set(ov_options "@OV_OPTIONS@") list(APPEND ov_options CMAKE_CXX_COMPILER_LAUNCHER CMAKE_C_COMPILER_LAUNCHER CMAKE_CXX_LINKER_LAUNCHER CMAKE_C_LINKER_LAUNCHER - CMAKE_SKIP_RPATH CMAKE_INSTALL_PREFIX CPACK_GENERATOR) + CMAKE_INSTALL_PREFIX CPACK_GENERATOR) if(APPLE) list(APPEND ov_options CMAKE_OSX_ARCHITECTURES CMAKE_OSX_DEPLOYMENT_TARGET) endif() get_property(_OV_GENERATOR_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) -if(_IE_GENERATOR_MULTI_CONFIG) +if(_OV_GENERATOR_MULTI_CONFIG) list(APPEND ov_options CMAKE_CONFIGURATION_TYPES) if(CMAKE_GENERATOR MATCHES "^Ninja Multi-Config$") list(APPEND ov_options CMAKE_DEFAULT_BUILD_TYPE) @@ -42,6 +42,9 @@ foreach(option IN LISTS ov_options) endforeach() message(" ") +# Restore TBB installation directory (requires for proper LC_RPATH on macOS with SIP) +load_cache("${cache_path}" READ_WITH_PREFIX "" TBB_INSTALL_DIR) + # activate generation of plugins.xml set(ENABLE_PLUGINS_XML ON) @@ -61,7 +64,7 @@ set(CMAKE_COMPILE_WARNING_AS_ERROR OFF) # Content # -find_dependency(IEDevScripts +find_dependency(OpenVINODeveloperScripts PATHS "${OpenVINO_SOURCE_DIR}/cmake/developer_package" NO_CMAKE_FIND_ROOT_PATH NO_DEFAULT_PATH) @@ -74,13 +77,7 @@ find_dependency(OpenVINO _ov_find_tbb() _ov_find_pugixml() -foreach(component @openvino_export_components@) - # TODO: remove legacy targets from some tests - # string(FIND "${component}" "_legacy" index) - # if (index EQUAL -1) - include("${CMAKE_CURRENT_LIST_DIR}/ov_${component}_dev_targets.cmake") - # endif() -endforeach() +include("${CMAKE_CURRENT_LIST_DIR}/openvino_developer_package_targets.cmake") # inherit OpenCV from main OpenVINO project if enabled if("@OpenCV_FOUND@") diff --git a/cmake/templates/OpenVINODeveloperPackageConfigRelocatable.cmake.in b/cmake/templates/OpenVINODeveloperPackageConfigRelocatable.cmake.in new file mode 100644 index 00000000000000..a4cdb93d387c58 --- /dev/null +++ b/cmake/templates/OpenVINODeveloperPackageConfigRelocatable.cmake.in @@ -0,0 +1,74 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# + +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) + +# Variables to export in plugin's projects + +set(ov_options "@OV_OPTIONS@") +list(APPEND ov_options CPACK_GENERATOR) + +if(APPLE) + list(APPEND ov_options CMAKE_OSX_ARCHITECTURES CMAKE_OSX_DEPLOYMENT_TARGET) +endif() + +get_property(_OV_GENERATOR_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(_OV_GENERATOR_MULTI_CONFIG) + list(APPEND ov_options CMAKE_CONFIGURATION_TYPES) + if(CMAKE_GENERATOR MATCHES "^Ninja Multi-Config$") + list(APPEND ov_options CMAKE_DEFAULT_BUILD_TYPE) + endif() +else() + list(APPEND ov_options CMAKE_BUILD_TYPE) +endif() +unset(_OV_GENERATOR_MULTI_CONFIG) + +file(TO_CMAKE_PATH "${CMAKE_CURRENT_LIST_DIR}" cache_path) + +message(STATUS "The following CMake options are exported from OpenVINO Developer package") +message(" ") +foreach(option IN LISTS ov_options) + if(NOT DEFINED "${option}") + load_cache("${cache_path}" READ_WITH_PREFIX "" ${option}) + endif() + message(" ${option}: ${${option}}") +endforeach() +message(" ") + +# Restore TBB installation directory (requires for proper LC_RPATH on macOS with SIP) +load_cache("${cache_path}" READ_WITH_PREFIX "" TBB_INSTALL_DIR) + +# activate generation of plugins.xml +set(ENABLE_PLUGINS_XML ON) + +# Disable warning as error for private components +set(CMAKE_COMPILE_WARNING_AS_ERROR OFF) + +# +# Content +# + +# OpenVINO_DIR is supposed to be set as an environment variable +find_dependency(OpenVINO) + +find_dependency(OpenVINODeveloperScripts + PATHS "${CMAKE_CURRENT_LIST_DIR}" + NO_CMAKE_FIND_ROOT_PATH + NO_DEFAULT_PATH) + +_ov_find_tbb() +_ov_find_pugixml() + +include("${CMAKE_CURRENT_LIST_DIR}/OpenVINODeveloperPackageTargets.cmake") +# +# Extra Compile Flags +# + +# don't fail on strict compilation options in 3rd party modules +ov_dev_package_no_errors() + +# Don't threat deprecated API warnings as errors in 3rd party apps +ov_deprecated_no_errors() diff --git a/cmake/templates/ngraphConfig.cmake.in b/cmake/templates/ngraphConfig.cmake.in index ee889b545acd0a..a0111c2302195f 100644 --- a/cmake/templates/ngraphConfig.cmake.in +++ b/cmake/templates/ngraphConfig.cmake.in @@ -42,6 +42,8 @@ include(CMakeFindDependencyMacro) +message(WARNING "find_package(ngraph) is deprecated and will be removed in 2024.0 release. Please, use find_package(OpenVINO)") + find_dependency(OpenVINO PATHS "${CMAKE_CURRENT_LIST_DIR}" "${CMAKE_CURRENT_LIST_DIR}/../openvino${ngraph_VERSION}" diff --git a/docs/OV_Runtime_UG/auto_device_selection.md b/docs/OV_Runtime_UG/auto_device_selection.md index 6b2385683494da..234197a6488b3e 100644 --- a/docs/OV_Runtime_UG/auto_device_selection.md +++ b/docs/OV_Runtime_UG/auto_device_selection.md @@ -56,11 +56,10 @@ The logic behind the choice is as follows: To put it simply, when loading the model to the first device on the list fails, AUTO will try to load it to the next device in line, until one of them succeeds. What is important, **AUTO starts inference with the CPU of the system by default**, as it provides very low latency and can start inference with no additional delays. While the CPU is performing inference, AUTO continues to load the model to the device best suited for the purpose and transfers the task to it when ready. -This way, the devices which are much slower in compiling models, GPU being the best example, do not impede inference at its initial stages. +This way, the devices which are much slower in compiling models, GPU being the best example, do not impact inference at its initial stages. For example, if you use a CPU and a GPU, the first-inference latency of AUTO will be better than that of using GPU alone. -Note that if you choose to exclude CPU from the priority list or disable the initial CPU acceleration feature via ``ov::intel_auto::enable_startup_fallback``, it will be unable to support the initial model compilation stage. - +Note that if you choose to exclude CPU from the priority list or disable the initial CPU acceleration feature via ``ov::intel_auto::enable_startup_fallback``, it will be unable to support the initial model compilation stage. The models with dynamic input/output or stateful :doc:`stateful` operations will be loaded to the CPU if it is in the candidate list. Otherwise, these models will follow the normal flow and be loaded to the device based on priority. .. image:: _static/images/autoplugin_accelerate.svg @@ -91,7 +90,7 @@ Following the OpenVINO™ naming convention, the Automatic Device Selection mode +----------------------------------------------+--------------------------------------------------------------------+ -| Property | Values and Description | +| Property(C++ version) | Values and Description | +==============================================+====================================================================+ | | **Values**: | | | | @@ -170,6 +169,25 @@ Following the OpenVINO™ naming convention, the Automatic Device Selection mode Inference with AUTO is configured similarly to when device plugins are used: you compile the model on the plugin with configuration and execute inference. +The code samples on this page assume following import(Python)/using (C++) are included at the beginning of code snippets. + +.. tab-set:: + + .. tab-item:: Python + :sync: py + + .. doxygensnippet:: docs/snippets/ov_auto.py + :language: python + :fragment: [py_ov_property_import_header] + + .. tab-item:: C++ + :sync: cpp + + .. doxygensnippet:: docs/snippets/AUTO0.cpp + :language: cpp + :fragment: [py_ov_property_import_header] + + Device Candidates and Priority ++++++++++++++++++++++++++++++ @@ -303,7 +321,7 @@ If device priority is specified when using CUMULATIVE_THROUGHPUT, AUTO will run .. code-block:: sh - compiled_model = core.compile_model(model, "AUTO:GPU,CPU", {"PERFORMANCE_HINT" : {"CUMULATIVE_THROUGHPUT"}}) + compiled_model = core.compile_model(model, "AUTO:GPU,CPU", {hints.performance_mode: hints.PerformanceMode.CUMULATIVE_THROUGHPUT}) .. tab-item:: C++ :sync: cpp @@ -322,7 +340,7 @@ If AUTO is used without specifying any device names, and if there are multiple G .. code-block:: sh - compiled_model = core.compile_model(model, "AUTO:GPU.1,GPU.0", {"PERFORMANCE_HINT" : {"CUMULATIVE_THROUGHPUT"}) + compiled_model = core.compile_model(model, "AUTO:GPU.1,GPU.0", {hints.performance_mode: hints.PerformanceMode.CUMULATIVE_THROUGHPUT}) .. tab-item:: C++ :sync: cpp diff --git a/docs/_static/selector-tool/assets/selector-56fddec6.js b/docs/_static/selector-tool/assets/selector-114afa0d.js similarity index 51% rename from docs/_static/selector-tool/assets/selector-56fddec6.js rename to docs/_static/selector-tool/assets/selector-114afa0d.js index 3437a6b4b55dbc..2878b10357074f 100644 --- a/docs/_static/selector-tool/assets/selector-56fddec6.js +++ b/docs/_static/selector-tool/assets/selector-114afa0d.js @@ -1,4 +1,4 @@ -var of=Object.defineProperty;var sf=(e,t,n)=>t in e?of(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var De=(e,t,n)=>(sf(e,typeof t!="symbol"?t+"":t,n),n);function lf(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Ar={},af={get exports(){return Ar},set exports(e){Ar=e}},Ti={},D={},uf={get exports(){return D},set exports(e){D=e}},j={};/** +var af=Object.defineProperty;var uf=(e,t,n)=>t in e?af(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var je=(e,t,n)=>(uf(e,typeof t!="symbol"?t+"":t,n),n);function cf(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Ar={},df={get exports(){return Ar},set exports(e){Ar=e}},Ti={},j={},pf={get exports(){return j},set exports(e){j=e}},D={};/** * @license React * react.production.min.js * @@ -6,7 +6,7 @@ var of=Object.defineProperty;var sf=(e,t,n)=>t in e?of(e,t,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var ro=Symbol.for("react.element"),cf=Symbol.for("react.portal"),df=Symbol.for("react.fragment"),pf=Symbol.for("react.strict_mode"),ff=Symbol.for("react.profiler"),hf=Symbol.for("react.provider"),mf=Symbol.for("react.context"),gf=Symbol.for("react.forward_ref"),vf=Symbol.for("react.suspense"),yf=Symbol.for("react.memo"),_f=Symbol.for("react.lazy"),Aa=Symbol.iterator;function kf(e){return e===null||typeof e!="object"?null:(e=Aa&&e[Aa]||e["@@iterator"],typeof e=="function"?e:null)}var Nc={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Ec=Object.assign,xc={};function ur(e,t,n){this.props=e,this.context=t,this.refs=xc,this.updater=n||Nc}ur.prototype.isReactComponent={};ur.prototype.setState=function(e,t){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")};ur.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function Pc(){}Pc.prototype=ur.prototype;function Vl(e,t,n){this.props=e,this.context=t,this.refs=xc,this.updater=n||Nc}var Fl=Vl.prototype=new Pc;Fl.constructor=Vl;Ec(Fl,ur.prototype);Fl.isPureReactComponent=!0;var za=Array.isArray,Cc=Object.prototype.hasOwnProperty,Dl={current:null},Rc={key:!0,ref:!0,__self:!0,__source:!0};function Tc(e,t,n){var r,o={},i=null,s=null;if(t!=null)for(r in t.ref!==void 0&&(s=t.ref),t.key!==void 0&&(i=""+t.key),t)Cc.call(t,r)&&!Rc.hasOwnProperty(r)&&(o[r]=t[r]);var l=arguments.length-2;if(l===1)o.children=n;else if(1t in e?of(e,t,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var xf=D,Pf=Symbol.for("react.element"),Cf=Symbol.for("react.fragment"),Rf=Object.prototype.hasOwnProperty,Tf=xf.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Lf={key:!0,ref:!0,__self:!0,__source:!0};function Lc(e,t,n){var r,o={},i=null,s=null;n!==void 0&&(i=""+n),t.key!==void 0&&(i=""+t.key),t.ref!==void 0&&(s=t.ref);for(r in t)Rf.call(t,r)&&!Lf.hasOwnProperty(r)&&(o[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps,t)o[r]===void 0&&(o[r]=t[r]);return{$$typeof:Pf,type:e,key:i,ref:s,props:o,_owner:Tf.current}}Ti.Fragment=Cf;Ti.jsx=Lc;Ti.jsxs=Lc;(function(e){e.exports=Ti})(af);const ni=Ar.Fragment,_=Ar.jsx,I=Ar.jsxs;document.body.style.cssText+=` + */var Rf=j,Tf=Symbol.for("react.element"),bf=Symbol.for("react.fragment"),Lf=Object.prototype.hasOwnProperty,If=Rf.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Vf={key:!0,ref:!0,__self:!0,__source:!0};function jc(e,t,n){var r,o={},i=null,s=null;n!==void 0&&(i=""+n),t.key!==void 0&&(i=""+t.key),t.ref!==void 0&&(s=t.ref);for(r in t)Lf.call(t,r)&&!Vf.hasOwnProperty(r)&&(o[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps,t)o[r]===void 0&&(o[r]=t[r]);return{$$typeof:Tf,type:e,key:i,ref:s,props:o,_owner:If.current}}Ti.Fragment=bf;Ti.jsx=jc;Ti.jsxs=jc;(function(e){e.exports=Ti})(df);const ni=Ar.Fragment,_=Ar.jsx,L=Ar.jsxs;document.body.style.cssText+=` overflow: hidden; -`;const If=()=>{const e={type:"size",height:document.body.offsetHeight};window.parent.postMessage(e)};new ResizeObserver(If).observe(document.body);function fe(e){return fe=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},fe(e)}function ct(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function bf(e,t){if(fe(e)!=="object"||e===null)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(fe(r)!=="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function Ic(e){var t=bf(e,"string");return fe(t)==="symbol"?t:String(t)}function $a(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&arguments[1]!==void 0?arguments[1]:{};ct(this,e),this.init(t,n)}return dt(e,[{key:"init",value:function(n){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.prefix=r.prefix||"i18next:",this.logger=n||Df,this.options=r,this.debug=r.debug}},{key:"setDebug",value:function(n){this.debug=n}},{key:"log",value:function(){for(var n=arguments.length,r=new Array(n),o=0;o1?r-1:0),i=1;i-1?l.replace(/###/g,"."):l}function o(){return!e||typeof e=="string"}for(var i=typeof t!="string"?[].concat(t):t.split(".");i.length>1;){if(o())return{};var s=r(i.shift());!e[s]&&n&&(e[s]=new n),Object.prototype.hasOwnProperty.call(e,s)?e=e[s]:e={}}return o()?{}:{obj:e,k:r(i.shift())}}function Ya(e,t,n){var r=Ul(e,t,Object),o=r.obj,i=r.k;o[i]=n}function Af(e,t,n,r){var o=Ul(e,t,Object),i=o.obj,s=o.k;i[s]=i[s]||[],r&&(i[s]=i[s].concat(n)),r||i[s].push(n)}function ri(e,t){var n=Ul(e,t),r=n.obj,o=n.k;if(r)return r[o]}function Ga(e,t,n){var r=ri(e,n);return r!==void 0?r:ri(t,n)}function Dc(e,t,n){for(var r in t)r!=="__proto__"&&r!=="constructor"&&(r in e?typeof e[r]=="string"||e[r]instanceof String||typeof t[r]=="string"||t[r]instanceof String?n&&(e[r]=t[r]):Dc(e[r],t[r],n):e[r]=t[r]);return e}function bn(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}var zf={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};function Mf(e){return typeof e=="string"?e.replace(/[&<>"'\/]/g,function(t){return zf[t]}):e}var Ii=typeof window<"u"&&window.navigator&&typeof window.navigator.userAgentData>"u"&&window.navigator.userAgent&&window.navigator.userAgent.indexOf("MSIE")>-1,$f=[" ",",","?","!",";"];function Bf(e,t,n){t=t||"",n=n||"";var r=$f.filter(function(l){return t.indexOf(l)<0&&n.indexOf(l)<0});if(r.length===0)return!0;var o=new RegExp("(".concat(r.map(function(l){return l==="?"?"\\?":l}).join("|"),")")),i=!o.test(e);if(!i){var s=e.indexOf(n);s>0&&!o.test(e.substring(0,s))&&(i=!0)}return i}function Qa(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function mo(e){for(var t=1;t"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function jc(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:".";if(e){if(e[t])return e[t];for(var r=t.split(n),o=e,i=0;ii+s;)s++,l=r.slice(i,i+s).join(n),a=o[l];if(a===void 0)return;if(a===null)return null;if(t.endsWith(l)){if(typeof a=="string")return a;if(l&&typeof a[l]=="string")return a[l]}var u=r.slice(i+s).join(n);return u?jc(a,u,n):void 0}o=o[r[i]]}return o}}var Wf=function(e){Li(n,e);var t=Kf(n);function n(r){var o,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{ns:["translation"],defaultNS:"translation"};return ct(this,n),o=t.call(this),Ii&&tn.call(Wt(o)),o.data=r||{},o.options=i,o.options.keySeparator===void 0&&(o.options.keySeparator="."),o.options.ignoreJSONStructure===void 0&&(o.options.ignoreJSONStructure=!0),o}return dt(n,[{key:"addNamespaces",value:function(o){this.options.ns.indexOf(o)<0&&this.options.ns.push(o)}},{key:"removeNamespaces",value:function(o){var i=this.options.ns.indexOf(o);i>-1&&this.options.ns.splice(i,1)}},{key:"getResource",value:function(o,i,s){var l=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{},a=l.keySeparator!==void 0?l.keySeparator:this.options.keySeparator,u=l.ignoreJSONStructure!==void 0?l.ignoreJSONStructure:this.options.ignoreJSONStructure,f=[o,i];s&&typeof s!="string"&&(f=f.concat(s)),s&&typeof s=="string"&&(f=f.concat(a?s.split(a):s)),o.indexOf(".")>-1&&(f=o.split("."));var d=ri(this.data,f);return d||!u||typeof s!="string"?d:jc(this.data&&this.data[o]&&this.data[o][i],s,a)}},{key:"addResource",value:function(o,i,s,l){var a=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{silent:!1},u=this.options.keySeparator;u===void 0&&(u=".");var f=[o,i];s&&(f=f.concat(u?s.split(u):s)),o.indexOf(".")>-1&&(f=o.split("."),l=i,i=f[1]),this.addNamespaces(i),Ya(this.data,f,l),a.silent||this.emit("added",o,i,s,l)}},{key:"addResources",value:function(o,i,s){var l=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{silent:!1};for(var a in s)(typeof s[a]=="string"||Object.prototype.toString.apply(s[a])==="[object Array]")&&this.addResource(o,i,a,s[a],{silent:!0});l.silent||this.emit("added",o,i,s)}},{key:"addResourceBundle",value:function(o,i,s,l,a){var u=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{silent:!1},f=[o,i];o.indexOf(".")>-1&&(f=o.split("."),l=s,s=i,i=f[1]),this.addNamespaces(i);var d=ri(this.data,f)||{};l?Dc(d,s,a):d=mo(mo({},d),s),Ya(this.data,f,d),u.silent||this.emit("added",o,i,s)}},{key:"removeResourceBundle",value:function(o,i){this.hasResourceBundle(o,i)&&delete this.data[o][i],this.removeNamespaces(i),this.emit("removed",o,i)}},{key:"hasResourceBundle",value:function(o,i){return this.getResource(o,i)!==void 0}},{key:"getResourceBundle",value:function(o,i){return i||(i=this.options.defaultNS),this.options.compatibilityAPI==="v1"?mo(mo({},{}),this.getResource(o,i)):this.getResource(o,i)}},{key:"getDataByLanguage",value:function(o){return this.data[o]}},{key:"hasLanguageSomeTranslations",value:function(o){var i=this.getDataByLanguage(o),s=i&&Object.keys(i)||[];return!!s.find(function(l){return i[l]&&Object.keys(i[l]).length>0})}},{key:"toJSON",value:function(){return this.data}}]),n}(tn),Uc={processors:{},addPostProcessor:function(t){this.processors[t.name]=t},handle:function(t,n,r,o,i){var s=this;return t.forEach(function(l){s.processors[l]&&(n=s.processors[l].process(n,r,o,i))}),n}};function qa(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function we(e){for(var t=1;t"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}var Xa={},Ja=function(e){Li(n,e);var t=Yf(n);function n(r){var o,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return ct(this,n),o=t.call(this),Ii&&tn.call(Wt(o)),Uf(["resourceStore","languageUtils","pluralResolver","interpolator","backendConnector","i18nFormat","utils"],r,Wt(o)),o.options=i,o.options.keySeparator===void 0&&(o.options.keySeparator="."),o.logger=yt.create("translator"),o}return dt(n,[{key:"changeLanguage",value:function(o){o&&(this.language=o)}},{key:"exists",value:function(o){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{interpolation:{}};if(o==null)return!1;var s=this.resolve(o,i);return s&&s.res!==void 0}},{key:"extractFromKey",value:function(o,i){var s=i.nsSeparator!==void 0?i.nsSeparator:this.options.nsSeparator;s===void 0&&(s=":");var l=i.keySeparator!==void 0?i.keySeparator:this.options.keySeparator,a=i.ns||this.options.defaultNS||[],u=s&&o.indexOf(s)>-1,f=!this.options.userDefinedKeySeparator&&!i.keySeparator&&!this.options.userDefinedNsSeparator&&!i.nsSeparator&&!Bf(o,s,l);if(u&&!f){var d=o.match(this.interpolator.nestingRegexp);if(d&&d.length>0)return{key:o,namespaces:a};var h=o.split(s);(s!==l||s===l&&this.options.ns.indexOf(h[0])>-1)&&(a=h.shift()),o=h.join(l)}return typeof a=="string"&&(a=[a]),{key:o,namespaces:a}}},{key:"translate",value:function(o,i,s){var l=this;if(fe(i)!=="object"&&this.options.overloadTranslationOptionHandler&&(i=this.options.overloadTranslationOptionHandler(arguments)),i||(i={}),o==null)return"";Array.isArray(o)||(o=[String(o)]);var a=i.returnDetails!==void 0?i.returnDetails:this.options.returnDetails,u=i.keySeparator!==void 0?i.keySeparator:this.options.keySeparator,f=this.extractFromKey(o[o.length-1],i),d=f.key,h=f.namespaces,g=h[h.length-1],v=i.lng||this.language,k=i.appendNamespaceToCIMode||this.options.appendNamespaceToCIMode;if(v&&v.toLowerCase()==="cimode"){if(k){var O=i.nsSeparator||this.options.nsSeparator;return a?{res:"".concat(g).concat(O).concat(d),usedKey:d,exactUsedKey:d,usedLng:v,usedNS:g}:"".concat(g).concat(O).concat(d)}return a?{res:d,usedKey:d,exactUsedKey:d,usedLng:v,usedNS:g}:d}var p=this.resolve(o,i),c=p&&p.res,m=p&&p.usedKey||d,y=p&&p.exactUsedKey||d,S=Object.prototype.toString.apply(c),w=["[object Number]","[object Function]","[object RegExp]"],E=i.joinArrays!==void 0?i.joinArrays:this.options.joinArrays,x=!this.i18nFormat||this.i18nFormat.handleAsObject,V=typeof c!="string"&&typeof c!="boolean"&&typeof c!="number";if(x&&c&&V&&w.indexOf(S)<0&&!(typeof E=="string"&&S==="[object Array]")){if(!i.returnObjects&&!this.options.returnObjects){this.options.returnedObjectHandler||this.logger.warn("accessing an object - but returnObjects options is not enabled!");var P=this.options.returnedObjectHandler?this.options.returnedObjectHandler(m,c,we(we({},i),{},{ns:h})):"key '".concat(d," (").concat(this.language,")' returned an object instead of string.");return a?(p.res=P,p):P}if(u){var K=S==="[object Array]",Ce=K?[]:{},Ot=K?y:m;for(var Ze in c)if(Object.prototype.hasOwnProperty.call(c,Ze)){var Tn="".concat(Ot).concat(u).concat(Ze);Ce[Ze]=this.translate(Tn,we(we({},i),{joinArrays:!1,ns:h})),Ce[Ze]===Tn&&(Ce[Ze]=c[Ze])}c=Ce}}else if(x&&typeof E=="string"&&S==="[object Array]")c=c.join(E),c&&(c=this.extendTranslation(c,o,i,s));else{var ft=!1,et=!1,R=i.count!==void 0&&typeof i.count!="string",b=n.hasDefaultValue(i),F=R?this.pluralResolver.getSuffix(v,i.count,i):"",A=i["defaultValue".concat(F)]||i.defaultValue;!this.isValidLookup(c)&&b&&(ft=!0,c=A),this.isValidLookup(c)||(et=!0,c=d);var q=i.missingKeyNoValueFallbackToKey||this.options.missingKeyNoValueFallbackToKey,Nt=q&&et?void 0:c,Ve=b&&A!==c&&this.options.updateMissing;if(et||ft||Ve){if(this.logger.log(Ve?"updateKey":"missingKey",v,g,d,Ve?A:c),u){var Ln=this.resolve(d,we(we({},i),{},{keySeparator:!1}));Ln&&Ln.res&&this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.")}var Fe=[],Et=this.languageUtils.getFallbackCodes(this.options.fallbackLng,i.lng||this.language);if(this.options.saveMissingTo==="fallback"&&Et&&Et[0])for(var Gi=0;Gi1&&arguments[1]!==void 0?arguments[1]:{},l,a,u,f,d;return typeof o=="string"&&(o=[o]),o.forEach(function(h){if(!i.isValidLookup(l)){var g=i.extractFromKey(h,s),v=g.key;a=v;var k=g.namespaces;i.options.fallbackNS&&(k=k.concat(i.options.fallbackNS));var O=s.count!==void 0&&typeof s.count!="string",p=O&&!s.ordinal&&s.count===0&&i.pluralResolver.shouldUseIntlApi(),c=s.context!==void 0&&(typeof s.context=="string"||typeof s.context=="number")&&s.context!=="",m=s.lngs?s.lngs:i.languageUtils.toResolveHierarchy(s.lng||i.language,s.fallbackLng);k.forEach(function(y){i.isValidLookup(l)||(d=y,!Xa["".concat(m[0],"-").concat(y)]&&i.utils&&i.utils.hasLoadedNamespace&&!i.utils.hasLoadedNamespace(d)&&(Xa["".concat(m[0],"-").concat(y)]=!0,i.logger.warn('key "'.concat(a,'" for languages "').concat(m.join(", "),`" won't get resolved as namespace "`).concat(d,'" was not yet loaded'),"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!")),m.forEach(function(S){if(!i.isValidLookup(l)){f=S;var w=[v];if(i.i18nFormat&&i.i18nFormat.addLookupKeys)i.i18nFormat.addLookupKeys(w,v,S,y,s);else{var E;O&&(E=i.pluralResolver.getSuffix(S,s.count,s));var x="".concat(i.options.pluralSeparator,"zero");if(O&&(w.push(v+E),p&&w.push(v+x)),c){var V="".concat(v).concat(i.options.contextSeparator).concat(s.context);w.push(V),O&&(w.push(V+E),p&&w.push(V+x))}}for(var P;P=w.pop();)i.isValidLookup(l)||(u=P,l=i.getResource(S,y,P,s))}}))})}}),{res:l,usedKey:a,exactUsedKey:u,usedLng:f,usedNS:d}}},{key:"isValidLookup",value:function(o){return o!==void 0&&!(!this.options.returnNull&&o===null)&&!(!this.options.returnEmptyString&&o==="")}},{key:"getResource",value:function(o,i,s){var l=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};return this.i18nFormat&&this.i18nFormat.getResource?this.i18nFormat.getResource(o,i,s,l):this.resourceStore.getResource(o,i,s,l)}}],[{key:"hasDefaultValue",value:function(o){var i="defaultValue";for(var s in o)if(Object.prototype.hasOwnProperty.call(o,s)&&i===s.substring(0,i.length)&&o[s]!==void 0)return!0;return!1}}]),n}(tn);function Ji(e){return e.charAt(0).toUpperCase()+e.slice(1)}var Za=function(){function e(t){ct(this,e),this.options=t,this.supportedLngs=this.options.supportedLngs||!1,this.logger=yt.create("languageUtils")}return dt(e,[{key:"getScriptPartFromCode",value:function(n){if(!n||n.indexOf("-")<0)return null;var r=n.split("-");return r.length===2||(r.pop(),r[r.length-1].toLowerCase()==="x")?null:this.formatLanguageCode(r.join("-"))}},{key:"getLanguagePartFromCode",value:function(n){if(!n||n.indexOf("-")<0)return n;var r=n.split("-");return this.formatLanguageCode(r[0])}},{key:"formatLanguageCode",value:function(n){if(typeof n=="string"&&n.indexOf("-")>-1){var r=["hans","hant","latn","cyrl","cans","mong","arab"],o=n.split("-");return this.options.lowerCaseLng?o=o.map(function(i){return i.toLowerCase()}):o.length===2?(o[0]=o[0].toLowerCase(),o[1]=o[1].toUpperCase(),r.indexOf(o[1].toLowerCase())>-1&&(o[1]=Ji(o[1].toLowerCase()))):o.length===3&&(o[0]=o[0].toLowerCase(),o[1].length===2&&(o[1]=o[1].toUpperCase()),o[0]!=="sgn"&&o[2].length===2&&(o[2]=o[2].toUpperCase()),r.indexOf(o[1].toLowerCase())>-1&&(o[1]=Ji(o[1].toLowerCase())),r.indexOf(o[2].toLowerCase())>-1&&(o[2]=Ji(o[2].toLowerCase()))),o.join("-")}return this.options.cleanCode||this.options.lowerCaseLng?n.toLowerCase():n}},{key:"isSupportedCode",value:function(n){return(this.options.load==="languageOnly"||this.options.nonExplicitSupportedLngs)&&(n=this.getLanguagePartFromCode(n)),!this.supportedLngs||!this.supportedLngs.length||this.supportedLngs.indexOf(n)>-1}},{key:"getBestMatchFromCodes",value:function(n){var r=this;if(!n)return null;var o;return n.forEach(function(i){if(!o){var s=r.formatLanguageCode(i);(!r.options.supportedLngs||r.isSupportedCode(s))&&(o=s)}}),!o&&this.options.supportedLngs&&n.forEach(function(i){if(!o){var s=r.getLanguagePartFromCode(i);if(r.isSupportedCode(s))return o=s;o=r.options.supportedLngs.find(function(l){if(l.indexOf(s)===0)return l})}}),o||(o=this.getFallbackCodes(this.options.fallbackLng)[0]),o}},{key:"getFallbackCodes",value:function(n,r){if(!n)return[];if(typeof n=="function"&&(n=n(r)),typeof n=="string"&&(n=[n]),Object.prototype.toString.apply(n)==="[object Array]")return n;if(!r)return n.default||[];var o=n[r];return o||(o=n[this.getScriptPartFromCode(r)]),o||(o=n[this.formatLanguageCode(r)]),o||(o=n[this.getLanguagePartFromCode(r)]),o||(o=n.default),o||[]}},{key:"toResolveHierarchy",value:function(n,r){var o=this,i=this.getFallbackCodes(r||this.options.fallbackLng||[],n),s=[],l=function(u){u&&(o.isSupportedCode(u)?s.push(u):o.logger.warn("rejecting language code not found in supportedLngs: ".concat(u)))};return typeof n=="string"&&n.indexOf("-")>-1?(this.options.load!=="languageOnly"&&l(this.formatLanguageCode(n)),this.options.load!=="languageOnly"&&this.options.load!=="currentOnly"&&l(this.getScriptPartFromCode(n)),this.options.load!=="currentOnly"&&l(this.getLanguagePartFromCode(n))):typeof n=="string"&&l(this.formatLanguageCode(n)),i.forEach(function(a){s.indexOf(a)<0&&l(o.formatLanguageCode(a))}),s}}]),e}(),Qf=[{lngs:["ach","ak","am","arn","br","fil","gun","ln","mfe","mg","mi","oc","pt","pt-BR","tg","tl","ti","tr","uz","wa"],nr:[1,2],fc:1},{lngs:["af","an","ast","az","bg","bn","ca","da","de","dev","el","en","eo","es","et","eu","fi","fo","fur","fy","gl","gu","ha","hi","hu","hy","ia","it","kk","kn","ku","lb","mai","ml","mn","mr","nah","nap","nb","ne","nl","nn","no","nso","pa","pap","pms","ps","pt-PT","rm","sco","se","si","so","son","sq","sv","sw","ta","te","tk","ur","yo"],nr:[1,2],fc:2},{lngs:["ay","bo","cgg","fa","ht","id","ja","jbo","ka","km","ko","ky","lo","ms","sah","su","th","tt","ug","vi","wo","zh"],nr:[1],fc:3},{lngs:["be","bs","cnr","dz","hr","ru","sr","uk"],nr:[1,2,5],fc:4},{lngs:["ar"],nr:[0,1,2,3,11,100],fc:5},{lngs:["cs","sk"],nr:[1,2,5],fc:6},{lngs:["csb","pl"],nr:[1,2,5],fc:7},{lngs:["cy"],nr:[1,2,3,8],fc:8},{lngs:["fr"],nr:[1,2],fc:9},{lngs:["ga"],nr:[1,2,3,7,11],fc:10},{lngs:["gd"],nr:[1,2,3,20],fc:11},{lngs:["is"],nr:[1,2],fc:12},{lngs:["jv"],nr:[0,1],fc:13},{lngs:["kw"],nr:[1,2,3,4],fc:14},{lngs:["lt"],nr:[1,2,10],fc:15},{lngs:["lv"],nr:[1,2,0],fc:16},{lngs:["mk"],nr:[1,2],fc:17},{lngs:["mnk"],nr:[0,1,2],fc:18},{lngs:["mt"],nr:[1,2,11,20],fc:19},{lngs:["or"],nr:[2,1],fc:2},{lngs:["ro"],nr:[1,2,20],fc:20},{lngs:["sl"],nr:[5,1,2,3],fc:21},{lngs:["he","iw"],nr:[1,2,20,21],fc:22}],qf={1:function(t){return+(t>1)},2:function(t){return+(t!=1)},3:function(t){return 0},4:function(t){return t%10==1&&t%100!=11?0:t%10>=2&&t%10<=4&&(t%100<10||t%100>=20)?1:2},5:function(t){return t==0?0:t==1?1:t==2?2:t%100>=3&&t%100<=10?3:t%100>=11?4:5},6:function(t){return t==1?0:t>=2&&t<=4?1:2},7:function(t){return t==1?0:t%10>=2&&t%10<=4&&(t%100<10||t%100>=20)?1:2},8:function(t){return t==1?0:t==2?1:t!=8&&t!=11?2:3},9:function(t){return+(t>=2)},10:function(t){return t==1?0:t==2?1:t<7?2:t<11?3:4},11:function(t){return t==1||t==11?0:t==2||t==12?1:t>2&&t<20?2:3},12:function(t){return+(t%10!=1||t%100==11)},13:function(t){return+(t!==0)},14:function(t){return t==1?0:t==2?1:t==3?2:3},15:function(t){return t%10==1&&t%100!=11?0:t%10>=2&&(t%100<10||t%100>=20)?1:2},16:function(t){return t%10==1&&t%100!=11?0:t!==0?1:2},17:function(t){return t==1||t%10==1&&t%100!=11?0:1},18:function(t){return t==0?0:t==1?1:2},19:function(t){return t==1?0:t==0||t%100>1&&t%100<11?1:t%100>10&&t%100<20?2:3},20:function(t){return t==1?0:t==0||t%100>0&&t%100<20?1:2},21:function(t){return t%100==1?1:t%100==2?2:t%100==3||t%100==4?3:0},22:function(t){return t==1?0:t==2?1:(t<0||t>10)&&t%10==0?2:3}},Xf=["v1","v2","v3"],eu={zero:0,one:1,two:2,few:3,many:4,other:5};function Jf(){var e={};return Qf.forEach(function(t){t.lngs.forEach(function(n){e[n]={numbers:t.nr,plurals:qf[t.fc]}})}),e}var Zf=function(){function e(t){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};ct(this,e),this.languageUtils=t,this.options=n,this.logger=yt.create("pluralResolver"),(!this.options.compatibilityJSON||this.options.compatibilityJSON==="v4")&&(typeof Intl>"u"||!Intl.PluralRules)&&(this.options.compatibilityJSON="v3",this.logger.error("Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.")),this.rules=Jf()}return dt(e,[{key:"addRule",value:function(n,r){this.rules[n]=r}},{key:"getRule",value:function(n){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(this.shouldUseIntlApi())try{return new Intl.PluralRules(n,{type:r.ordinal?"ordinal":"cardinal"})}catch{return}return this.rules[n]||this.rules[this.languageUtils.getLanguagePartFromCode(n)]}},{key:"needsPlural",value:function(n){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=this.getRule(n,r);return this.shouldUseIntlApi()?o&&o.resolvedOptions().pluralCategories.length>1:o&&o.numbers.length>1}},{key:"getPluralFormsOfKey",value:function(n,r){var o=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return this.getSuffixes(n,o).map(function(i){return"".concat(r).concat(i)})}},{key:"getSuffixes",value:function(n){var r=this,o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=this.getRule(n,o);return i?this.shouldUseIntlApi()?i.resolvedOptions().pluralCategories.sort(function(s,l){return eu[s]-eu[l]}).map(function(s){return"".concat(r.options.prepend).concat(s)}):i.numbers.map(function(s){return r.getSuffix(n,s,o)}):[]}},{key:"getSuffix",value:function(n,r){var o=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i=this.getRule(n,o);return i?this.shouldUseIntlApi()?"".concat(this.options.prepend).concat(i.select(r)):this.getSuffixRetroCompatible(i,r):(this.logger.warn("no plural rule found for: ".concat(n)),"")}},{key:"getSuffixRetroCompatible",value:function(n,r){var o=this,i=n.noAbs?n.plurals(r):n.plurals(Math.abs(r)),s=n.numbers[i];this.options.simplifyPluralSuffix&&n.numbers.length===2&&n.numbers[0]===1&&(s===2?s="plural":s===1&&(s=""));var l=function(){return o.options.prepend&&s.toString()?o.options.prepend+s.toString():s.toString()};return this.options.compatibilityJSON==="v1"?s===1?"":typeof s=="number"?"_plural_".concat(s.toString()):l():this.options.compatibilityJSON==="v2"||this.options.simplifyPluralSuffix&&n.numbers.length===2&&n.numbers[0]===1?l():this.options.prepend&&i.toString()?this.options.prepend+i.toString():i.toString()}},{key:"shouldUseIntlApi",value:function(){return!Xf.includes(this.options.compatibilityJSON)}}]),e}();function tu(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function tt(e){for(var t=1;t0&&arguments[0]!==void 0?arguments[0]:{};ct(this,e),this.logger=yt.create("interpolator"),this.options=t,this.format=t.interpolation&&t.interpolation.format||function(n){return n},this.init(t)}return dt(e,[{key:"init",value:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};n.interpolation||(n.interpolation={escapeValue:!0});var r=n.interpolation;this.escape=r.escape!==void 0?r.escape:Mf,this.escapeValue=r.escapeValue!==void 0?r.escapeValue:!0,this.useRawValueToEscape=r.useRawValueToEscape!==void 0?r.useRawValueToEscape:!1,this.prefix=r.prefix?bn(r.prefix):r.prefixEscaped||"{{",this.suffix=r.suffix?bn(r.suffix):r.suffixEscaped||"}}",this.formatSeparator=r.formatSeparator?r.formatSeparator:r.formatSeparator||",",this.unescapePrefix=r.unescapeSuffix?"":r.unescapePrefix||"-",this.unescapeSuffix=this.unescapePrefix?"":r.unescapeSuffix||"",this.nestingPrefix=r.nestingPrefix?bn(r.nestingPrefix):r.nestingPrefixEscaped||bn("$t("),this.nestingSuffix=r.nestingSuffix?bn(r.nestingSuffix):r.nestingSuffixEscaped||bn(")"),this.nestingOptionsSeparator=r.nestingOptionsSeparator?r.nestingOptionsSeparator:r.nestingOptionsSeparator||",",this.maxReplaces=r.maxReplaces?r.maxReplaces:1e3,this.alwaysFormat=r.alwaysFormat!==void 0?r.alwaysFormat:!1,this.resetRegExp()}},{key:"reset",value:function(){this.options&&this.init(this.options)}},{key:"resetRegExp",value:function(){var n="".concat(this.prefix,"(.+?)").concat(this.suffix);this.regexp=new RegExp(n,"g");var r="".concat(this.prefix).concat(this.unescapePrefix,"(.+?)").concat(this.unescapeSuffix).concat(this.suffix);this.regexpUnescape=new RegExp(r,"g");var o="".concat(this.nestingPrefix,"(.+?)").concat(this.nestingSuffix);this.nestingRegexp=new RegExp(o,"g")}},{key:"interpolate",value:function(n,r,o,i){var s=this,l,a,u,f=this.options&&this.options.interpolation&&this.options.interpolation.defaultVariables||{};function d(O){return O.replace(/\$/g,"$$$$")}var h=function(p){if(p.indexOf(s.formatSeparator)<0){var c=Ga(r,f,p);return s.alwaysFormat?s.format(c,void 0,o,tt(tt(tt({},i),r),{},{interpolationkey:p})):c}var m=p.split(s.formatSeparator),y=m.shift().trim(),S=m.join(s.formatSeparator).trim();return s.format(Ga(r,f,y),S,o,tt(tt(tt({},i),r),{},{interpolationkey:y}))};this.resetRegExp();var g=i&&i.missingInterpolationHandler||this.options.missingInterpolationHandler,v=i&&i.interpolation&&i.interpolation.skipOnVariables!==void 0?i.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables,k=[{regex:this.regexpUnescape,safeValue:function(p){return d(p)}},{regex:this.regexp,safeValue:function(p){return s.escapeValue?d(s.escape(p)):d(p)}}];return k.forEach(function(O){for(u=0;l=O.regex.exec(n);){var p=l[1].trim();if(a=h(p),a===void 0)if(typeof g=="function"){var c=g(n,l,i);a=typeof c=="string"?c:""}else if(i&&Object.prototype.hasOwnProperty.call(i,p))a="";else if(v){a=l[0];continue}else s.logger.warn("missed to pass in variable ".concat(p," for interpolating ").concat(n)),a="";else typeof a!="string"&&!s.useRawValueToEscape&&(a=Wa(a));var m=O.safeValue(a);if(n=n.replace(l[0],m),v?(O.regex.lastIndex+=a.length,O.regex.lastIndex-=l[0].length):O.regex.lastIndex=0,u++,u>=s.maxReplaces)break}}),n}},{key:"nest",value:function(n,r){var o=this,i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},s,l,a;function u(g,v){var k=this.nestingOptionsSeparator;if(g.indexOf(k)<0)return g;var O=g.split(new RegExp("".concat(k,"[ ]*{"))),p="{".concat(O[1]);g=O[0],p=this.interpolate(p,a);var c=p.match(/'/g),m=p.match(/"/g);(c&&c.length%2===0&&!m||m.length%2!==0)&&(p=p.replace(/'/g,'"'));try{a=JSON.parse(p),v&&(a=tt(tt({},v),a))}catch(y){return this.logger.warn("failed parsing options string in nesting for key ".concat(g),y),"".concat(g).concat(k).concat(p)}return delete a.defaultValue,g}for(;s=this.nestingRegexp.exec(n);){var f=[];a=tt({},i),a=a.replace&&typeof a.replace!="string"?a.replace:a,a.applyPostProcessor=!1,delete a.defaultValue;var d=!1;if(s[0].indexOf(this.formatSeparator)!==-1&&!/{.*}/.test(s[1])){var h=s[1].split(this.formatSeparator).map(function(g){return g.trim()});s[1]=h.shift(),f=h,d=!0}if(l=r(u.call(this,s[1].trim(),a),a),l&&s[0]===n&&typeof l!="string")return l;typeof l!="string"&&(l=Wa(l)),l||(this.logger.warn("missed to resolve ".concat(s[1]," for nesting ").concat(n)),l=""),d&&(l=f.reduce(function(g,v){return o.format(g,v,i.lng,tt(tt({},i),{},{interpolationkey:s[1].trim()}))},l.trim())),n=n.replace(s[0],l),this.regexp.lastIndex=0}return n}}]),e}();function nu(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function xt(e){for(var t=1;t-1){var r=e.split("(");t=r[0].toLowerCase().trim();var o=r[1].substring(0,r[1].length-1);if(t==="currency"&&o.indexOf(":")<0)n.currency||(n.currency=o.trim());else if(t==="relativetime"&&o.indexOf(":")<0)n.range||(n.range=o.trim());else{var i=o.split(";");i.forEach(function(s){if(s){var l=s.split(":"),a=Ff(l),u=a[0],f=a.slice(1),d=f.join(":").trim().replace(/^'+|'+$/g,"");n[u.trim()]||(n[u.trim()]=d),d==="false"&&(n[u.trim()]=!1),d==="true"&&(n[u.trim()]=!0),isNaN(d)||(n[u.trim()]=parseInt(d,10))}})}}return{formatName:t,formatOptions:n}}function Vn(e){var t={};return function(r,o,i){var s=o+JSON.stringify(i),l=t[s];return l||(l=e(o,i),t[s]=l),l(r)}}var nh=function(){function e(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};ct(this,e),this.logger=yt.create("formatter"),this.options=t,this.formats={number:Vn(function(n,r){var o=new Intl.NumberFormat(n,xt({},r));return function(i){return o.format(i)}}),currency:Vn(function(n,r){var o=new Intl.NumberFormat(n,xt(xt({},r),{},{style:"currency"}));return function(i){return o.format(i)}}),datetime:Vn(function(n,r){var o=new Intl.DateTimeFormat(n,xt({},r));return function(i){return o.format(i)}}),relativetime:Vn(function(n,r){var o=new Intl.RelativeTimeFormat(n,xt({},r));return function(i){return o.format(i,r.range||"day")}}),list:Vn(function(n,r){var o=new Intl.ListFormat(n,xt({},r));return function(i){return o.format(i)}})},this.init(t)}return dt(e,[{key:"init",value:function(n){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{interpolation:{}},o=r.interpolation;this.formatSeparator=o.formatSeparator?o.formatSeparator:o.formatSeparator||","}},{key:"add",value:function(n,r){this.formats[n.toLowerCase().trim()]=r}},{key:"addCached",value:function(n,r){this.formats[n.toLowerCase().trim()]=Vn(r)}},{key:"format",value:function(n,r,o){var i=this,s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{},l=r.split(this.formatSeparator),a=l.reduce(function(u,f){var d=th(f),h=d.formatName,g=d.formatOptions;if(i.formats[h]){var v=u;try{var k=s&&s.formatParams&&s.formatParams[s.interpolationkey]||{},O=k.locale||k.lng||s.locale||s.lng||o;v=i.formats[h](u,O,xt(xt(xt({},g),s),k))}catch(p){i.logger.warn(p)}return v}else i.logger.warn("there was no format function for ".concat(h));return u},n);return a}}]),e}();function ru(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function ou(e){for(var t=1;t"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function ih(e,t){e.pending[t]!==void 0&&(delete e.pending[t],e.pendingCount--)}var sh=function(e){Li(n,e);var t=rh(n);function n(r,o,i){var s,l=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};return ct(this,n),s=t.call(this),Ii&&tn.call(Wt(s)),s.backend=r,s.store=o,s.services=i,s.languageUtils=i.languageUtils,s.options=l,s.logger=yt.create("backendConnector"),s.waitingReads=[],s.maxParallelReads=l.maxParallelReads||10,s.readingCalls=0,s.maxRetries=l.maxRetries>=0?l.maxRetries:5,s.retryTimeout=l.retryTimeout>=1?l.retryTimeout:350,s.state={},s.queue=[],s.backend&&s.backend.init&&s.backend.init(i,l.backend,l),s}return dt(n,[{key:"queueLoad",value:function(o,i,s,l){var a=this,u={},f={},d={},h={};return o.forEach(function(g){var v=!0;i.forEach(function(k){var O="".concat(g,"|").concat(k);!s.reload&&a.store.hasResourceBundle(g,k)?a.state[O]=2:a.state[O]<0||(a.state[O]===1?f[O]===void 0&&(f[O]=!0):(a.state[O]=1,v=!1,f[O]===void 0&&(f[O]=!0),u[O]===void 0&&(u[O]=!0),h[k]===void 0&&(h[k]=!0)))}),v||(d[g]=!0)}),(Object.keys(u).length||Object.keys(f).length)&&this.queue.push({pending:f,pendingCount:Object.keys(f).length,loaded:{},errors:[],callback:l}),{toLoad:Object.keys(u),pending:Object.keys(f),toLoadLanguages:Object.keys(d),toLoadNamespaces:Object.keys(h)}}},{key:"loaded",value:function(o,i,s){var l=o.split("|"),a=l[0],u=l[1];i&&this.emit("failedLoading",a,u,i),s&&this.store.addResourceBundle(a,u,s),this.state[o]=i?-1:2;var f={};this.queue.forEach(function(d){Af(d.loaded,[a],u),ih(d,o),i&&d.errors.push(i),d.pendingCount===0&&!d.done&&(Object.keys(d.loaded).forEach(function(h){f[h]||(f[h]={});var g=d.loaded[h];g.length&&g.forEach(function(v){f[h][v]===void 0&&(f[h][v]=!0)})}),d.done=!0,d.errors.length?d.callback(d.errors):d.callback())}),this.emit("loaded",f),this.queue=this.queue.filter(function(d){return!d.done})}},{key:"read",value:function(o,i,s){var l=this,a=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0,u=arguments.length>4&&arguments[4]!==void 0?arguments[4]:this.retryTimeout,f=arguments.length>5?arguments[5]:void 0;if(!o.length)return f(null,{});if(this.readingCalls>=this.maxParallelReads){this.waitingReads.push({lng:o,ns:i,fcName:s,tried:a,wait:u,callback:f});return}this.readingCalls++;var d=function(k,O){if(l.readingCalls--,l.waitingReads.length>0){var p=l.waitingReads.shift();l.read(p.lng,p.ns,p.fcName,p.tried,p.wait,p.callback)}if(k&&O&&a2&&arguments[2]!==void 0?arguments[2]:{},a=arguments.length>3?arguments[3]:void 0;if(!this.backend)return this.logger.warn("No backend was added via i18next.use. Will not load resources."),a&&a();typeof o=="string"&&(o=this.languageUtils.toResolveHierarchy(o)),typeof i=="string"&&(i=[i]);var u=this.queueLoad(o,i,l,a);if(!u.toLoad.length)return u.pending.length||a(),null;u.toLoad.forEach(function(f){s.loadOne(f)})}},{key:"load",value:function(o,i,s){this.prepareLoading(o,i,{},s)}},{key:"reload",value:function(o,i,s){this.prepareLoading(o,i,{reload:!0},s)}},{key:"loadOne",value:function(o){var i=this,s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"",l=o.split("|"),a=l[0],u=l[1];this.read(a,u,"read",void 0,void 0,function(f,d){f&&i.logger.warn("".concat(s,"loading namespace ").concat(u," for language ").concat(a," failed"),f),!f&&d&&i.logger.log("".concat(s,"loaded namespace ").concat(u," for language ").concat(a),d),i.loaded(o,f,d)})}},{key:"saveMissing",value:function(o,i,s,l,a){var u=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{},f=arguments.length>6&&arguments[6]!==void 0?arguments[6]:function(){};if(this.services.utils&&this.services.utils.hasLoadedNamespace&&!this.services.utils.hasLoadedNamespace(i)){this.logger.warn('did not save key "'.concat(s,'" as the namespace "').concat(i,'" was not yet loaded'),"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");return}if(!(s==null||s==="")){if(this.backend&&this.backend.create){var d=ou(ou({},u),{},{isUpdate:a}),h=this.backend.create.bind(this.backend);if(h.length<6)try{var g;h.length===5?g=h(o,i,s,l,d):g=h(o,i,s,l),g&&typeof g.then=="function"?g.then(function(v){return f(null,v)}).catch(f):f(null,g)}catch(v){f(v)}else h(o,i,s,l,f,d)}!o||!o[0]||this.store.addResource(o[0],i,s,l)}}}]),n}(tn);function iu(){return{debug:!1,initImmediate:!0,ns:["translation"],defaultNS:["translation"],fallbackLng:["dev"],fallbackNS:!1,supportedLngs:!1,nonExplicitSupportedLngs:!1,load:"all",preload:!1,simplifyPluralSuffix:!0,keySeparator:".",nsSeparator:":",pluralSeparator:"_",contextSeparator:"_",partialBundledLanguages:!1,saveMissing:!1,updateMissing:!1,saveMissingTo:"fallback",saveMissingPlurals:!0,missingKeyHandler:!1,missingInterpolationHandler:!1,postProcess:!1,postProcessPassResolved:!1,returnNull:!0,returnEmptyString:!0,returnObjects:!1,joinArrays:!1,returnedObjectHandler:!1,parseMissingKeyHandler:!1,appendNamespaceToMissingKey:!1,appendNamespaceToCIMode:!1,overloadTranslationOptionHandler:function(t){var n={};if(fe(t[1])==="object"&&(n=t[1]),typeof t[1]=="string"&&(n.defaultValue=t[1]),typeof t[2]=="string"&&(n.tDescription=t[2]),fe(t[2])==="object"||fe(t[3])==="object"){var r=t[3]||t[2];Object.keys(r).forEach(function(o){n[o]=r[o]})}return n},interpolation:{escapeValue:!0,format:function(t,n,r,o){return t},prefix:"{{",suffix:"}}",formatSeparator:",",unescapePrefix:"-",nestingPrefix:"$t(",nestingSuffix:")",nestingOptionsSeparator:",",maxReplaces:1e3,skipOnVariables:!0}}}function su(e){return typeof e.ns=="string"&&(e.ns=[e.ns]),typeof e.fallbackLng=="string"&&(e.fallbackLng=[e.fallbackLng]),typeof e.fallbackNS=="string"&&(e.fallbackNS=[e.fallbackNS]),e.supportedLngs&&e.supportedLngs.indexOf("cimode")<0&&(e.supportedLngs=e.supportedLngs.concat(["cimode"])),e}function lu(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function ht(e){for(var t=1;t"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function go(){}function uh(e){var t=Object.getOwnPropertyNames(Object.getPrototypeOf(e));t.forEach(function(n){typeof e[n]=="function"&&(e[n]=e[n].bind(e))})}var oi=function(e){Li(n,e);var t=lh(n);function n(){var r,o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},i=arguments.length>1?arguments[1]:void 0;if(ct(this,n),r=t.call(this),Ii&&tn.call(Wt(r)),r.options=su(o),r.services={},r.logger=yt,r.modules={external:[]},uh(Wt(r)),i&&!r.isInitialized&&!o.isClone){if(!r.options.initImmediate)return r.init(o,i),oo(r,Wt(r));setTimeout(function(){r.init(o,i)},0)}return r}return dt(n,[{key:"init",value:function(){var o=this,i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=arguments.length>1?arguments[1]:void 0;typeof i=="function"&&(s=i,i={}),!i.defaultNS&&i.defaultNS!==!1&&i.ns&&(typeof i.ns=="string"?i.defaultNS=i.ns:i.ns.indexOf("translation")<0&&(i.defaultNS=i.ns[0]));var l=iu();this.options=ht(ht(ht({},l),this.options),su(i)),this.options.compatibilityAPI!=="v1"&&(this.options.interpolation=ht(ht({},l.interpolation),this.options.interpolation)),i.keySeparator!==void 0&&(this.options.userDefinedKeySeparator=i.keySeparator),i.nsSeparator!==void 0&&(this.options.userDefinedNsSeparator=i.nsSeparator);function a(p){return p?typeof p=="function"?new p:p:null}if(!this.options.isClone){this.modules.logger?yt.init(a(this.modules.logger),this.options):yt.init(null,this.options);var u;this.modules.formatter?u=this.modules.formatter:typeof Intl<"u"&&(u=nh);var f=new Za(this.options);this.store=new Wf(this.options.resources,this.options);var d=this.services;d.logger=yt,d.resourceStore=this.store,d.languageUtils=f,d.pluralResolver=new Zf(f,{prepend:this.options.pluralSeparator,compatibilityJSON:this.options.compatibilityJSON,simplifyPluralSuffix:this.options.simplifyPluralSuffix}),u&&(!this.options.interpolation.format||this.options.interpolation.format===l.interpolation.format)&&(d.formatter=a(u),d.formatter.init(d,this.options),this.options.interpolation.format=d.formatter.format.bind(d.formatter)),d.interpolator=new eh(this.options),d.utils={hasLoadedNamespace:this.hasLoadedNamespace.bind(this)},d.backendConnector=new sh(a(this.modules.backend),d.resourceStore,d,this.options),d.backendConnector.on("*",function(p){for(var c=arguments.length,m=new Array(c>1?c-1:0),y=1;y1?c-1:0),y=1;y0&&h[0]!=="dev"&&(this.options.lng=h[0])}!this.services.languageDetector&&!this.options.lng&&this.logger.warn("init: no languageDetector is used and no lng is defined");var g=["getResource","hasResourceBundle","getResourceBundle","getDataByLanguage"];g.forEach(function(p){o[p]=function(){var c;return(c=o.store)[p].apply(c,arguments)}});var v=["addResource","addResources","addResourceBundle","removeResourceBundle"];v.forEach(function(p){o[p]=function(){var c;return(c=o.store)[p].apply(c,arguments),o}});var k=hr(),O=function(){var c=function(y,S){o.isInitialized&&!o.initializedStoreOnce&&o.logger.warn("init: i18next is already initialized. You should call init just once!"),o.isInitialized=!0,o.options.isClone||o.logger.log("initialized",o.options),o.emit("initialized",o.options),k.resolve(S),s(y,S)};if(o.languages&&o.options.compatibilityAPI!=="v1"&&!o.isInitialized)return c(null,o.t.bind(o));o.changeLanguage(o.options.lng,c)};return this.options.resources||!this.options.initImmediate?O():setTimeout(O,0),k}},{key:"loadResources",value:function(o){var i=this,s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:go,l=s,a=typeof o=="string"?o:this.language;if(typeof o=="function"&&(l=o),!this.options.resources||this.options.partialBundledLanguages){if(a&&a.toLowerCase()==="cimode")return l();var u=[],f=function(g){if(g){var v=i.services.languageUtils.toResolveHierarchy(g);v.forEach(function(k){u.indexOf(k)<0&&u.push(k)})}};if(a)f(a);else{var d=this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);d.forEach(function(h){return f(h)})}this.options.preload&&this.options.preload.forEach(function(h){return f(h)}),this.services.backendConnector.load(u,this.options.ns,function(h){!h&&!i.resolvedLanguage&&i.language&&i.setResolvedLanguage(i.language),l(h)})}else l(null)}},{key:"reloadResources",value:function(o,i,s){var l=hr();return o||(o=this.languages),i||(i=this.options.ns),s||(s=go),this.services.backendConnector.reload(o,i,function(a){l.resolve(),s(a)}),l}},{key:"use",value:function(o){if(!o)throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");if(!o.type)throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");return o.type==="backend"&&(this.modules.backend=o),(o.type==="logger"||o.log&&o.warn&&o.error)&&(this.modules.logger=o),o.type==="languageDetector"&&(this.modules.languageDetector=o),o.type==="i18nFormat"&&(this.modules.i18nFormat=o),o.type==="postProcessor"&&Uc.addPostProcessor(o),o.type==="formatter"&&(this.modules.formatter=o),o.type==="3rdParty"&&this.modules.external.push(o),this}},{key:"setResolvedLanguage",value:function(o){if(!(!o||!this.languages)&&!(["cimode","dev"].indexOf(o)>-1))for(var i=0;i-1)&&this.store.hasLanguageSomeTranslations(s)){this.resolvedLanguage=s;break}}}},{key:"changeLanguage",value:function(o,i){var s=this;this.isLanguageChangingTo=o;var l=hr();this.emit("languageChanging",o);var a=function(h){s.language=h,s.languages=s.services.languageUtils.toResolveHierarchy(h),s.resolvedLanguage=void 0,s.setResolvedLanguage(h)},u=function(h,g){g?(a(g),s.translator.changeLanguage(g),s.isLanguageChangingTo=void 0,s.emit("languageChanged",g),s.logger.log("languageChanged",g)):s.isLanguageChangingTo=void 0,l.resolve(function(){return s.t.apply(s,arguments)}),i&&i(h,function(){return s.t.apply(s,arguments)})},f=function(h){!o&&!h&&s.services.languageDetector&&(h=[]);var g=typeof h=="string"?h:s.services.languageUtils.getBestMatchFromCodes(h);g&&(s.language||a(g),s.translator.language||s.translator.changeLanguage(g),s.services.languageDetector&&s.services.languageDetector.cacheUserLanguage&&s.services.languageDetector.cacheUserLanguage(g)),s.loadResources(g,function(v){u(v,g)})};return!o&&this.services.languageDetector&&!this.services.languageDetector.async?f(this.services.languageDetector.detect()):!o&&this.services.languageDetector&&this.services.languageDetector.async?this.services.languageDetector.detect.length===0?this.services.languageDetector.detect().then(f):this.services.languageDetector.detect(f):f(o),l}},{key:"getFixedT",value:function(o,i,s){var l=this,a=function u(f,d){var h;if(fe(d)!=="object"){for(var g=arguments.length,v=new Array(g>2?g-2:0),k=2;k1&&arguments[1]!==void 0?arguments[1]:{};if(!this.isInitialized)return this.logger.warn("hasLoadedNamespace: i18next was not initialized",this.languages),!1;if(!this.languages||!this.languages.length)return this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty",this.languages),!1;var l=this.resolvedLanguage||this.languages[0],a=this.options?this.options.fallbackLng:!1,u=this.languages[this.languages.length-1];if(l.toLowerCase()==="cimode")return!0;var f=function(g,v){var k=i.services.backendConnector.state["".concat(g,"|").concat(v)];return k===-1||k===2};if(s.precheck){var d=s.precheck(this,f);if(d!==void 0)return d}return!!(this.hasResourceBundle(l,o)||!this.services.backendConnector.backend||this.options.resources&&!this.options.partialBundledLanguages||f(l,o)&&(!a||f(u,o)))}},{key:"loadNamespaces",value:function(o,i){var s=this,l=hr();return this.options.ns?(typeof o=="string"&&(o=[o]),o.forEach(function(a){s.options.ns.indexOf(a)<0&&s.options.ns.push(a)}),this.loadResources(function(a){l.resolve(),i&&i(a)}),l):(i&&i(),Promise.resolve())}},{key:"loadLanguages",value:function(o,i){var s=hr();typeof o=="string"&&(o=[o]);var l=this.options.preload||[],a=o.filter(function(u){return l.indexOf(u)<0});return a.length?(this.options.preload=l.concat(a),this.loadResources(function(u){s.resolve(),i&&i(u)}),s):(i&&i(),Promise.resolve())}},{key:"dir",value:function(o){if(o||(o=this.resolvedLanguage||(this.languages&&this.languages.length>0?this.languages[0]:this.language)),!o)return"rtl";var i=["ar","shu","sqr","ssh","xaa","yhd","yud","aao","abh","abv","acm","acq","acw","acx","acy","adf","ads","aeb","aec","afb","ajp","apc","apd","arb","arq","ars","ary","arz","auz","avl","ayh","ayl","ayn","ayp","bbz","pga","he","iw","ps","pbt","pbu","pst","prp","prd","ug","ur","ydd","yds","yih","ji","yi","hbo","men","xmn","fa","jpr","peo","pes","prs","dv","sam","ckb"],s=this.services&&this.services.languageUtils||new Za(iu());return i.indexOf(s.getLanguagePartFromCode(o))>-1||o.toLowerCase().indexOf("-arab")>1?"rtl":"ltr"}},{key:"cloneInstance",value:function(){var o=this,i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:go,l=ht(ht(ht({},this.options),i),{isClone:!0}),a=new n(l);(i.debug!==void 0||i.prefix!==void 0)&&(a.logger=a.logger.clone(i));var u=["store","services","language"];return u.forEach(function(f){a[f]=o[f]}),a.services=ht({},this.services),a.services.utils={hasLoadedNamespace:a.hasLoadedNamespace.bind(a)},a.translator=new Ja(a.services,a.options),a.translator.on("*",function(f){for(var d=arguments.length,h=new Array(d>1?d-1:0),g=1;g0&&arguments[0]!==void 0?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0;return new oi(e,t)});var ce=oi.createInstance();ce.createInstance=oi.createInstance;ce.createInstance;ce.dir;ce.init;ce.loadResources;ce.reloadResources;ce.use;ce.changeLanguage;ce.getFixedT;ce.t;ce.exists;ce.setDefaultNamespace;ce.hasLoadedNamespace;ce.loadNamespaces;ce.loadLanguages;function ch(e,t){if(e==null)return{};var n={},r=Object.keys(e),o,i;for(i=0;i=0)&&(n[o]=e[o]);return n}function Al(e,t){if(e==null)return{};var n=ch(e,t),r,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(o=0;o=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var dh={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},ph=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function au(e){var t={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},n=e.match(/<\/?([^\s]+?)[/\s>]/);if(n&&(t.name=n[1],(dh[n[1]]||e.charAt(e.length-2)==="/")&&(t.voidElement=!0),t.name.startsWith("!--"))){var r=e.indexOf("-->");return{type:"comment",comment:r!==-1?e.slice(4,r):""}}for(var o=new RegExp(ph),i=null;(i=o.exec(e))!==null;)if(i[0].trim())if(i[1]){var s=i[1].trim(),l=[s,""];s.indexOf("=")>-1&&(l=s.split("=")),t.attrs[l[0]]=l[1],o.lastIndex--}else i[2]&&(t.attrs[i[2]]=i[3].trim().substring(1,i[3].length-1));return t}var fh=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,hh=/^\s*$/,mh=Object.create(null);function Ac(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(n){var r=[];for(var o in n)r.push(o+'="'+n[o]+'"');return r.length?" "+r.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(Ac,"")+"";case"comment":return e+""}}var gh={parse:function(e,t){t||(t={}),t.components||(t.components=mh);var n,r=[],o=[],i=-1,s=!1;if(e.indexOf("<")!==0){var l=e.indexOf("<");r.push({type:"text",content:l===-1?e:e.substring(0,l)})}return e.replace(fh,function(a,u){if(s){if(a!=="")return;s=!1}var f,d=a.charAt(1)!=="/",h=a.startsWith("");return{type:"comment",comment:r!==-1?e.slice(4,r):""}}for(var o=new RegExp(mh),i=null;(i=o.exec(e))!==null;)if(i[0].trim())if(i[1]){var s=i[1].trim(),l=[s,""];s.indexOf("=")>-1&&(l=s.split("=")),t.attrs[l[0]]=l[1],o.lastIndex--}else i[2]&&(t.attrs[i[2]]=i[3].trim().substring(1,i[3].length-1));return t}var gh=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,vh=/^\s*$/,yh=Object.create(null);function Kc(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(n){var r=[];for(var o in n)r.push(o+'="'+n[o]+'"');return r.length?" "+r.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(Kc,"")+"";case"comment":return e+""}}var _h={parse:function(e,t){t||(t={}),t.components||(t.components=yh);var n,r=[],o=[],i=-1,s=!1;if(e.indexOf("<")!==0){var l=e.indexOf("<");r.push({type:"text",content:l===-1?e:e.substring(0,l)})}return e.replace(gh,function(a,u){if(s){if(a!=="")return;s=!1}var f,d=a.charAt(1)!=="/",h=a.startsWith(" > **NOTE**: This version is pre-release software and has not undergone full release validation or qualification. No support is offered on pre-release software and APIs/behavior are subject to change. It should NOT be incorporated into any production software/solution and instead should be used only for early testing and integration while awaiting a final release version of this software. +> **NOTE**: OpenVINO™ Development Tools package has been deprecated and will be discontinued with 2024.0 release. To learn more, refer to the [OpenVINO Legacy Features and Components page](https://docs.openvino.ai/2023.1/openvino_legacy_features.html). + Intel® Distribution of OpenVINO™ toolkit is an open-source toolkit for optimizing and deploying AI inference. It can be used to develop applications and solutions based on deep learning tasks, such as: emulation of human vision, automatic speech recognition, natural language processing, recommendation systems, etc. It provides high-performance and rich deployment options, from edge to cloud. OpenVINO™ Development Tools enables you to download models from Open Model Zoo, convert your own models to OpenVINO IR, as well as optimize and tune pre-trained deep learning models. See [What's in the Package](#whats-in-the-package) for more information. @@ -119,8 +121,7 @@ For example, to install and configure the components for working with TensorFlow | Component | Console Script | Description | |------------------|---------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| [Legacy Model conversion API](https://docs.openvino.ai/nightly/openvino_docs_MO_DG_Deep_Learning_Model_Optimizer_DevGuide.html) | `mo` |**Model conversion API** imports, converts, and optimizes models that were trained in popular frameworks to a format usable by OpenVINO components.
Supported frameworks include Caffe\*, TensorFlow\*, MXNet\*, PaddlePaddle\*, and ONNX\*. | -| [Benchmark Tool](https://docs.openvino.ai/nightly/openvino_inference_engine_tools_benchmark_tool_README.html)| `benchmark_app` | **Benchmark Application** allows you to estimate deep learning inference performance on supported devices for synchronous and asynchronous modes. | +| [Legacy Model conversion API](https://docs.openvino.ai/nightly/openvino_docs_MO_DG_Deep_Learning_Model_Optimizer_DevGuide.html) | `mo` |**Model conversion API** imports, converts, and optimizes models that were trained in popular frameworks to a format usable by OpenVINO components.
Supported frameworks include Caffe\*, TensorFlow\*, MXNet\*, PaddlePaddle\*, and ONNX\*. | | | [Accuracy Checker](https://docs.openvino.ai/nightly/omz_tools_accuracy_checker.html) and
[Annotation Converter](https://docs.openvino.ai/nightly/omz_tools_accuracy_checker_annotation_converters.html) | `accuracy_check`
`convert_annotation` |**Accuracy Checker** is a deep learning accuracy validation tool that allows you to collect accuracy metrics against popular datasets. The main advantages of the tool are the flexibility of configuration and a set of supported datasets, preprocessing, postprocessing, and metrics.
**Annotation Converter** is a utility that prepares datasets for evaluation with Accuracy Checker. | | [Post-Training Optimization Tool](https://docs.openvino.ai/nightly/pot_introduction.html)| `pot` |**Post-Training Optimization Tool** allows you to optimize trained models with advanced capabilities, such as quantization and low-precision optimizations, without the need to retrain or fine-tune models. | | [Model Downloader and other Open Model Zoo tools](https://docs.openvino.ai/nightly/omz_tools_downloader.html)| `omz_downloader`
`omz_converter`
`omz_quantizer`
`omz_info_dumper`| **Model Downloader** is a tool for getting access to the collection of high-quality and extremely fast pre-trained deep learning [public](@ref omz_models_group_public) and [Intel](@ref omz_models_group_intel)-trained models. These free pre-trained models can be used to speed up the development and production deployment process without training your own models. The tool downloads model files from online sources and, if necessary, patches them to make them more usable with model conversion API. A number of additional tools are also provided to automate the process of working with downloaded models:
**Model Converter** is a tool for converting Open Model Zoo models that are stored in an original deep learning framework format into the OpenVINO Intermediate Representation (IR) using model conversion API.
**Model Quantizer** is a tool for automatic quantization of full-precision models in the IR format into low-precision versions using the Post-Training Optimization Tool.
**Model Information Dumper** is a helper utility for dumping information about the models to a stable, machine-readable format. | diff --git a/docs/install_guides/pypi-openvino-rt.md b/docs/install_guides/pypi-openvino-rt.md index 157f6959122d45..c5d8dc0de156b6 100644 --- a/docs/install_guides/pypi-openvino-rt.md +++ b/docs/install_guides/pypi-openvino-rt.md @@ -1,11 +1,11 @@ -# OpenVINO™ Runtime +# OpenVINO™ > **NOTE**: This version is pre-release software and has not undergone full release validation or qualification. No support is offered on pre-release software and APIs/behavior are subject to change. It should NOT be incorporated into any production software/solution and instead should be used only for early testing and integration while awaiting a final release version of this software. Intel® Distribution of OpenVINO™ toolkit is an open-source toolkit for optimizing and deploying AI inference. It can be used to develop applications and solutions based on deep learning tasks, such as: emulation of human vision, automatic speech recognition, natural language processing, recommendation systems, etc. It provides high-performance and rich deployment options, from edge to cloud. -If you have already finished developing your models and converting them to the OpenVINO model format, you can install OpenVINO Runtime to deploy your applications on various devices. The [OpenVINO™ Runtime](https://docs.openvino.ai/2023.1/openvino_docs_OV_UG_OV_Runtime_User_Guide.html) Python package includes a set of libraries for an easy inference integration with your products. +If you have already finished developing your models and converting them to the OpenVINO model format, you can install OpenVINO Runtime to deploy your applications on various devices. The [OpenVINO™](https://docs.openvino.ai/2023.1/openvino_docs_OV_UG_OV_Runtime_User_Guide.html) Python package includes a set of libraries for an easy inference integration with your products. ## System Requirements @@ -15,7 +15,7 @@ Before you start the installation, check the supported operating systems and req > **NOTE**: This package can be installed on other versions of Linux and Windows OSes, but only the specific versions above are fully validated. -## Install the OpenVINO™ Runtime Package +## Install OpenVINO™ ### Step 1. Set Up Python Virtual Environment @@ -37,15 +37,16 @@ python3 -m venv openvino_env ### Step 2. Activate Virtual Environment -On Linux and macOS: -```sh -source openvino_env/bin/activate -``` On Windows: ```sh openvino_env\Scripts\activate ``` +On Linux and macOS: +```sh +source openvino_env/bin/activate +``` + ### Step 3. Set Up and Update PIP to the Highest Version Run the command below: @@ -70,6 +71,14 @@ python -c "from openvino.runtime import Core; print(Core().available_devices)" If installation was successful, you will see the list of available devices. +## What's in the Package + +| Component | Content | Description | +|------------------|---------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [OpenVINO Runtime](https://docs.openvino.ai/2023.1/openvino_docs_OV_UG_OV_Runtime_User_Guide.html) | `openvino package` |**OpenVINO Runtime** is a set of C++ libraries with C and Python bindings providing a common API to deliver inference solutions on the platform of your choice. Use the OpenVINO Runtime API to read PyTorch\*, TensorFlow\*, TensorFlow Lite\*, ONNX\*, and PaddlePaddle\* models and execute them on preferred devices. OpenVINO Runtime uses a plugin architecture and includes the following plugins: [CPU](https://docs.openvino.ai/2023.1/openvino_docs_OV_UG_supported_plugins_CPU.html), [GPU](https://docs.openvino.ai/2023.1/openvino_docs_OV_UG_supported_plugins_GPU.html), [Auto Batch](https://docs.openvino.ai/2023.1/openvino_docs_OV_UG_Automatic_Batching.html), [Auto](https://docs.openvino.ai/2023.1/openvino_docs_OV_UG_supported_plugins_AUTO.html), [Hetero](https://docs.openvino.ai/2023.1/openvino_docs_OV_UG_Hetero_execution.html). +| [OpenVINO Model Converter (OVC)](https://docs.openvino.ai/2023.1/openvino_docs_model_processing_introduction.html#convert-a-model-in-cli-ovc) | `ovc` |**OpenVINO Model Converter** converts models that were trained in popular frameworks to a format usable by OpenVINO components.
Supported frameworks include ONNX\*, TensorFlow\*, TensorFlow Lite\*, and PaddlePaddle\*. | +| [Benchmark Tool](https://docs.openvino.ai/2023.1/openvino_inference_engine_tools_benchmark_tool_README.html)| `benchmark_app` | **Benchmark Application** allows you to estimate deep learning inference performance on supported devices for synchronous and asynchronous modes. | + ## Troubleshooting For general troubleshooting steps and issues, see [Troubleshooting Guide for OpenVINO Installation](https://docs.openvino.ai/2023.1/openvino_docs_get_started_guide_troubleshooting.html). The following sections also provide explanations to several error messages. diff --git a/docs/nbdoc/nbdoc.py b/docs/nbdoc/nbdoc.py index bf6c6040b809ab..a890c13c0f2f55 100644 --- a/docs/nbdoc/nbdoc.py +++ b/docs/nbdoc/nbdoc.py @@ -166,7 +166,7 @@ def main(): sourcedir = args.sourcedir outdir = args.outdir - main_tutorials_file = Path('../../docs/tutorials.md').resolve(strict=True) + main_tutorials_file = Path('../../docs/articles_en/learn_openvino/tutorials.md').resolve(strict=True) add_glob_directive(main_tutorials_file) if args.download: diff --git a/docs/requirements.txt b/docs/requirements.txt index 69433a40eb64ff..2e643842f24861 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -44,6 +44,6 @@ sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.3 sphinxcontrib-serializinghtml==1.1.5 toml==0.10.2 -urllib3==1.26.17 +urllib3==1.26.18 zipp==3.4.1 docs/openvino_custom_sphinx_sitemap diff --git a/docs/resources/telemetry_information.md b/docs/resources/telemetry_information.md deleted file mode 100644 index 4340a40923770b..00000000000000 --- a/docs/resources/telemetry_information.md +++ /dev/null @@ -1,89 +0,0 @@ -# OpenVINO™ Telemetry {#openvino_docs_telemetry_information} - -@sphinxdirective - -.. meta:: - :description: Learn about OpenVINO™ telemetry, that with your explicit consent - collects only usage data to simplify debugging and further development. - - -To facilitate debugging and further development, OpenVINO™ asks its users for -a permission to collect telemetry data. It will not be collected -without an explicit consent on your part and will cover only OpenVINO™ usage information. -It does not extend to any other Intel software, hardware, website usage, or other products. - -Google Analytics is used for telemetry purposes. Refer to -`Google Analytics support `__ to understand how the data is collected and processed. - -Enable or disable Telemetry reporting -########################################################### - -First-run consent -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -On the first run of an application that collects telemetry data, you will be prompted -to opt in or out of telemetry collection with the following telemetry message: - -.. code-block:: console - - Intel would like your permission to collect software performance and usage data - for the purpose of improving Intel products and services. This data will be collected - directly by Intel or through the use of Google Analytics. This data will be stored - in countries where Intel or Google operate. - - You can opt-out at any time in the future by running ``opt_in_out --opt_in``. - - More Information is available at docs.openvino.ai. - - Please type ``Y`` to give your consent or ``N`` to decline. - -Choose your preference by typing ``Y`` to enable or ``N`` to disable telemetry. Your choice will -be confirmed by a corresponding disclaimer. If you do not reply to the telemetry message, -your telemetry data will not be collected. - -For the Neural Network Compression Framework (NNCF), which is not a command line application, -the telemetry message will not display. Telemetry data will only be collected from NNCF -if you have explicitly provided consent in another OpenVINO tool. - - -Changing consent decision -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -You can change your data collection decision with the following command lines: - -``opt_in_out --opt_in`` - enable telemetry - -``opt_in_out --opt_out`` - disable telemetry - - -Telemetry Data Collection Details -########################################################### - -.. tab-set:: - - .. tab-item:: Telemetry Data Collected - :sync: telemetry-data-collected - - * Failure reports - * Error reports - * Usage data - - .. tab-item:: Tools Collecting Data - :sync: tools-collecting-data - - * Model conversion API - * Model Downloader - * Accuracy Checker - * Post-Training Optimization Toolkit - * Neural Network Compression Framework - * Model Converter - * Model Quantizer - - .. tab-item:: Telemetry Data Retention - :sync: telemetry-data-retention - - Telemetry data is retained in Google Analytics for a maximum of 26 months. - Any raw data that has reached the 26-month threshold is deleted from Google Analytics on a monthly basis. - - -@endsphinxdirective \ No newline at end of file diff --git a/docs/snippets/AUTO0.cpp b/docs/snippets/AUTO0.cpp index 54d720eb4bcc0d..124bdd900970a7 100644 --- a/docs/snippets/AUTO0.cpp +++ b/docs/snippets/AUTO0.cpp @@ -1,4 +1,6 @@ +//! [py_ov_property_import_header] #include +//! [py_ov_property_import_header] int main() { { diff --git a/docs/snippets/ov_auto.py b/docs/snippets/ov_auto.py index a665b509713f6e..47d8d877ecda24 100644 --- a/docs/snippets/ov_auto.py +++ b/docs/snippets/ov_auto.py @@ -2,10 +2,13 @@ # SPDX-License-Identifier: Apache-2.0 # +#! [py_ov_property_import_header] import openvino as ov import openvino.properties as properties import openvino.properties.device as device import openvino.properties.hint as hints +import openvino.properties.streams as streams +#! [py_ov_property_import_header] import openvino.properties.log as log from openvino.inference_engine import IECore @@ -156,8 +159,23 @@ def part5(): core = ov.Core() # gpu_config and cpu_config will load during compile_model() - compiled_model = core.compile_model(model=model) - compiled_model = core.compile_model(model=model, device_name="AUTO") + gpu_config = { + hints.performance_mode: hints.PerformanceMode.THROUGHPUT, + streams.num: 4 + } + cpu_config = { + hints.performance_mode: hints.PerformanceMode.LATENCY, + streams.num: 8, + properties.enable_profiling: True + } + compiled_model = core.compile_model( + model=model, + device_name="AUTO", + config={ + device.priorities: "GPU,CPU", + device.properties: {'CPU': cpu_config, 'GPU': gpu_config} + } + ) #! [part5] diff --git a/docs/snippets/ov_multi.py b/docs/snippets/ov_multi.py index 1f852faea94c9c..e3ee1aa7bf7158 100644 --- a/docs/snippets/ov_multi.py +++ b/docs/snippets/ov_multi.py @@ -4,6 +4,7 @@ import openvino as ov import openvino.properties as properties import openvino.properties.device as device +import openvino.properties.streams as streams from utils import get_model model = get_model() @@ -96,15 +97,17 @@ def available_devices_2(): def MULTI_4(): #! [MULTI_4] core = ov.Core() - cpu_config = {} - gpu_config = {} + cpu_config = {streams.num : 4} + gpu_config = {streams.num : 8} # When compiling the model on MULTI, configure CPU and GPU # (devices, priorities, and device configurations; gpu_config and cpu_config will load during compile_model() ): compiled_model = core.compile_model( model=model, device_name="MULTI:GPU,CPU", - config={"CPU": "NUM_STREAMS 4", "GPU": "NUM_STREAMS 8"}, + config={ + device.properties: {'CPU': cpu_config, 'GPU': gpu_config} + } ) # Optionally, query the optimal number of requests: diff --git a/docs/snippets/ov_preprocessing.cpp b/docs/snippets/ov_preprocessing.cpp index f559a7a5a1aef4..176953f46691f1 100644 --- a/docs/snippets/ov_preprocessing.cpp +++ b/docs/snippets/ov_preprocessing.cpp @@ -165,7 +165,7 @@ int main() { //! [ov:preprocess:save_headers] void save_example() { - //! [ov:preprocess:save] + //! [ov:preprocess:save_model] // ======== Step 0: read original model ========= ov::Core core; std::shared_ptr model = core.read_model("/path/to/some_model.onnx"); @@ -200,7 +200,7 @@ void save_example() { std::string xml = "/path/to/some_model_saved.xml"; std::string bin = "/path/to/some_model_saved.bin"; ov::serialize(model, xml, bin); - //! [ov:preprocess:save] + //! [ov:preprocess:save_model] } diff --git a/docs/snippets/ov_preprocessing.py b/docs/snippets/ov_preprocessing.py index 23cd30548115ad..8a8f4ce212b4f7 100644 --- a/docs/snippets/ov_preprocessing.py +++ b/docs/snippets/ov_preprocessing.py @@ -184,7 +184,7 @@ def custom_abs(output: Output): model_path = get_path_to_model() serialized_model_path = get_path_to_model() -# ! [ov:preprocess:save] +# ! [ov:preprocess:save_model] # ======== Step 0: read original model ========= core = Core() model = core.read_model(model=model_path) @@ -219,7 +219,7 @@ def custom_abs(output: Output): # ======== Step 3: Save the model ================ serialize(model, serialized_model_path) -# ! [ov:preprocess:save] +# ! [ov:preprocess:save_model] path_to_cache_dir = get_temp_dir() diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index ab5abf8024c045..e2aeebc9c35e7f 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -5,7 +5,8 @@ add_subdirectory(cpp) add_subdirectory(c) -openvino_developer_export_targets(COMPONENT samples TARGETS format_reader ie_samples_utils) +ov_developer_package_export_targets(TARGET format_reader) +ov_developer_package_export_targets(TARGET ie_samples_utils) # # Install diff --git a/samples/c/common/opencv_c_wrapper/CMakeLists.txt b/samples/c/common/opencv_c_wrapper/CMakeLists.txt index 1f2eea3bebcfd2..11ae7efbf35787 100644 --- a/samples/c/common/opencv_c_wrapper/CMakeLists.txt +++ b/samples/c/common/opencv_c_wrapper/CMakeLists.txt @@ -28,6 +28,6 @@ target_include_directories(${TARGET_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/in set_target_properties(${TARGET_NAME} PROPERTIES FOLDER c_samples) -if(COMMAND ov_add_clang_format_target AND NOT IE_SAMPLE_EXCLUDE_CLANG_FORMAT) +if(COMMAND ov_add_clang_format_target) ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}) endif() diff --git a/samples/c/hello_classification/CMakeLists.txt b/samples/c/hello_classification/CMakeLists.txt index 199744115257fd..031b9d44037a89 100644 --- a/samples/c/hello_classification/CMakeLists.txt +++ b/samples/c/hello_classification/CMakeLists.txt @@ -2,6 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 # -ie_add_sample(NAME hello_classification_c +ov_add_sample(NAME hello_classification_c SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/main.c" DEPENDENCIES opencv_c_wrapper) diff --git a/samples/c/hello_nv12_input_classification/CMakeLists.txt b/samples/c/hello_nv12_input_classification/CMakeLists.txt index a517baf9b40ec3..83ae06b52052d6 100644 --- a/samples/c/hello_nv12_input_classification/CMakeLists.txt +++ b/samples/c/hello_nv12_input_classification/CMakeLists.txt @@ -2,5 +2,5 @@ # SPDX-License-Identifier: Apache-2.0 # -ie_add_sample(NAME hello_nv12_input_classification_c +ov_add_sample(NAME hello_nv12_input_classification_c SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/main.c") diff --git a/samples/cpp/CMakeLists.txt b/samples/cpp/CMakeLists.txt index 038895b1c07429..de884bb05d279c 100644 --- a/samples/cpp/CMakeLists.txt +++ b/samples/cpp/CMakeLists.txt @@ -49,18 +49,18 @@ endif() if(OpenVINO_SOURCE_DIR) # in case if samples are built from IE repo - set(IE_MAIN_SAMPLES_DIR "${OpenVINO_SOURCE_DIR}") + set(OV_MAIN_SAMPLES_DIR "${OpenVINO_SOURCE_DIR}") set(OpenVINO_DIR "${CMAKE_BINARY_DIR}") else() # in case if samples are built out of IE repo - set(IE_MAIN_SAMPLES_DIR ${CMAKE_CURRENT_BINARY_DIR}) + set(OV_MAIN_SAMPLES_DIR ${CMAKE_CURRENT_BINARY_DIR}) endif() -set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER}) -set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER}) -set (CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER}) -set (CMAKE_PDB_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER}) -set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER}) +set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OV_MAIN_SAMPLES_DIR}/${BIN_FOLDER}) +set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OV_MAIN_SAMPLES_DIR}/${BIN_FOLDER}) +set (CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY ${OV_MAIN_SAMPLES_DIR}/${BIN_FOLDER}) +set (CMAKE_PDB_OUTPUT_DIRECTORY ${OV_MAIN_SAMPLES_DIR}/${BIN_FOLDER}) +set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OV_MAIN_SAMPLES_DIR}/${BIN_FOLDER}) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS") @@ -155,7 +155,7 @@ if (DEFINED OpenVINO_SOURCE_DIR AND NOT ENABLE_SAMPLES) return() endif() -function(add_samples_to_build) +function(ov_add_samples_to_build) # check each passed sample subdirectory foreach (dir ${ARGN}) if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${dir}) @@ -175,37 +175,37 @@ function(add_samples_to_build) endif() endif() endforeach() -endfunction(add_samples_to_build) +endfunction(ov_add_samples_to_build) include(CMakeParseArguments) # -# ie_add_sample(NAME +# ov_add_sample(NAME # SOURCES # [HEADERS
] # [INCLUDE_DIRECTORIES ] # [DEPENDENCIES ] # [EXCLUDE_CLANG_FORMAT] # -macro(ie_add_sample) +macro(ov_add_sample) set(options EXCLUDE_CLANG_FORMAT) set(oneValueArgs NAME) set(multiValueArgs SOURCES HEADERS DEPENDENCIES INCLUDE_DIRECTORIES) - cmake_parse_arguments(IE_SAMPLE "${options}" "${oneValueArgs}" + cmake_parse_arguments(SAMPLE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) # Create named folders for the sources within the .vcproj # Empty name lists them directly under the .vcproj - source_group("src" FILES ${IE_SAMPLE_SOURCES}) - if(IE_SAMPLE_HEADERS) - source_group("include" FILES ${IE_SAMPLE_HEADERS}) + source_group("src" FILES ${SAMPLE_SOURCES}) + if(SAMPLE_HEADERS) + source_group("include" FILES ${SAMPLE_HEADERS}) endif() # Create executable file from sources - add_executable(${IE_SAMPLE_NAME} ${IE_SAMPLE_SOURCES} ${IE_SAMPLE_HEADERS}) + add_executable(${SAMPLE_NAME} ${SAMPLE_SOURCES} ${SAMPLE_HEADERS}) set(folder_name cpp_samples) - if(IE_SAMPLE_NAME MATCHES ".*_c$") + if(SAMPLE_NAME MATCHES ".*_c$") set(c_sample ON) set(folder_name c_samples) endif() @@ -214,42 +214,54 @@ macro(ie_add_sample) find_package(Threads REQUIRED) find_package(OpenVINO REQUIRED COMPONENTS Runtime) - - # Conan does not generate openvino::runtime::c target - if(c_sample AND TARGET openvino::runtime::c) + if(c_sample) set(ov_link_libraries openvino::runtime::c) else() set(ov_link_libraries openvino::runtime) endif() - set_target_properties(${IE_SAMPLE_NAME} PROPERTIES FOLDER ${folder_name} - COMPILE_PDB_NAME ${IE_SAMPLE_NAME}) + set_target_properties(${SAMPLE_NAME} PROPERTIES FOLDER ${folder_name} + COMPILE_PDB_NAME ${SAMPLE_NAME} + # to ensure out of box LC_RPATH on macOS with SIP + INSTALL_RPATH_USE_LINK_PATH ON) - if(IE_SAMPLE_INCLUDE_DIRECTORIES) - target_include_directories(${IE_SAMPLE_NAME} PRIVATE ${IE_SAMPLE_INCLUDE_DIRECTORIES}) + if(SAMPLE_INCLUDE_DIRECTORIES) + target_include_directories(${SAMPLE_NAME} PRIVATE ${SAMPLE_INCLUDE_DIRECTORIES}) endif() - target_include_directories(${IE_SAMPLE_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../common") + target_include_directories(${SAMPLE_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../common") - target_link_libraries(${IE_SAMPLE_NAME} PRIVATE ${ov_link_libraries} Threads::Threads ${IE_SAMPLE_DEPENDENCIES}) + target_link_libraries(${SAMPLE_NAME} PRIVATE ${ov_link_libraries} Threads::Threads ${SAMPLE_DEPENDENCIES}) - install(TARGETS ${IE_SAMPLE_NAME} + install(TARGETS ${SAMPLE_NAME} RUNTIME DESTINATION samples_bin/ COMPONENT samples_bin EXCLUDE_FROM_ALL) # create global target with all samples / demo apps - if(NOT TARGET ie_samples) - add_custom_target(ie_samples ALL) + if(NOT TARGET ov_samples) + add_custom_target(ov_samples ALL) endif() - add_dependencies(ie_samples ${IE_SAMPLE_NAME}) + add_dependencies(ov_samples ${SAMPLE_NAME}) - if(COMMAND ov_add_clang_format_target AND NOT IE_SAMPLE_EXCLUDE_CLANG_FORMAT) - ov_add_clang_format_target(${IE_SAMPLE_NAME}_clang FOR_SOURCES ${IE_SAMPLE_SOURCES} ${IE_SAMPLE_HEADERS}) + if(COMMAND ov_add_clang_format_target AND NOT SAMPLE_EXCLUDE_CLANG_FORMAT) + ov_add_clang_format_target(${SAMPLE_NAME}_clang FOR_SOURCES ${SAMPLE_SOURCES} ${SAMPLE_HEADERS}) endif() if(COMMAND ov_ncc_naming_style AND NOT c_sample) - ov_ncc_naming_style(FOR_TARGET "${IE_SAMPLE_NAME}" + ov_ncc_naming_style(FOR_TARGET "${SAMPLE_NAME}" SOURCE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}") endif() + + unset(options) + unset(oneValueArgs) + unset(multiValueArgs) + unset(c_sample) + unset(folder_name) + unset(ov_link_libraries) + unset(SAMPLE_NAME) + unset(SAMPLE_HEADERS) + unset(SAMPLE_DEPENDENCIES) + unset(SAMPLE_EXCLUDE_CLANG_FORMAT) + unset(SAMPLE_INCLUDE_DIRECTORIES) endmacro() # collect all samples subdirectories @@ -261,4 +273,4 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty") endif() list(REMOVE_ITEM samples_dirs common) -add_samples_to_build(${samples_dirs}) +ov_add_samples_to_build(${samples_dirs}) diff --git a/samples/cpp/benchmark/sync_benchmark/CMakeLists.txt b/samples/cpp/benchmark/sync_benchmark/CMakeLists.txt index 39a1b86f3f0baf..c9350435612005 100644 --- a/samples/cpp/benchmark/sync_benchmark/CMakeLists.txt +++ b/samples/cpp/benchmark/sync_benchmark/CMakeLists.txt @@ -2,6 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 # -ie_add_sample(NAME sync_benchmark +ov_add_sample(NAME sync_benchmark SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp" DEPENDENCIES ie_samples_utils) diff --git a/samples/cpp/benchmark/throughput_benchmark/CMakeLists.txt b/samples/cpp/benchmark/throughput_benchmark/CMakeLists.txt index 682feee8cef0ca..be9730bf872822 100644 --- a/samples/cpp/benchmark/throughput_benchmark/CMakeLists.txt +++ b/samples/cpp/benchmark/throughput_benchmark/CMakeLists.txt @@ -2,6 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 # -ie_add_sample(NAME throughput_benchmark +ov_add_sample(NAME throughput_benchmark SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp" DEPENDENCIES ie_samples_utils) diff --git a/samples/cpp/benchmark_app/CMakeLists.txt b/samples/cpp/benchmark_app/CMakeLists.txt index c79615130c268a..863c2278058f5f 100644 --- a/samples/cpp/benchmark_app/CMakeLists.txt +++ b/samples/cpp/benchmark_app/CMakeLists.txt @@ -7,7 +7,7 @@ set(TARGET_NAME "benchmark_app") file (GLOB SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) file (GLOB HDR ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp) -ie_add_sample(NAME ${TARGET_NAME} +ov_add_sample(NAME ${TARGET_NAME} SOURCES ${SRC} HEADERS ${HDR} DEPENDENCIES ${GFLAGS_TARGET} format_reader ie_samples_utils) diff --git a/samples/cpp/classification_sample_async/CMakeLists.txt b/samples/cpp/classification_sample_async/CMakeLists.txt index 8b9f4a946f5d87..ea208418b768c6 100644 --- a/samples/cpp/classification_sample_async/CMakeLists.txt +++ b/samples/cpp/classification_sample_async/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # -ie_add_sample(NAME classification_sample_async +ov_add_sample(NAME classification_sample_async SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp" HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/classification_sample_async.h" DEPENDENCIES ${GFLAGS_TARGET} format_reader ie_samples_utils) diff --git a/samples/cpp/common/format_reader/CMakeLists.txt b/samples/cpp/common/format_reader/CMakeLists.txt index 89732ca039a363..7be5f6af757501 100644 --- a/samples/cpp/common/format_reader/CMakeLists.txt +++ b/samples/cpp/common/format_reader/CMakeLists.txt @@ -30,7 +30,7 @@ else() target_compile_definitions(${TARGET_NAME} PRIVATE USE_OPENCV) endif() -target_include_directories(${TARGET_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" +target_include_directories(${TARGET_NAME} PUBLIC "$" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src") set_target_properties(${TARGET_NAME} PROPERTIES FOLDER cpp_samples) diff --git a/samples/cpp/common/utils/CMakeLists.txt b/samples/cpp/common/utils/CMakeLists.txt index 108818b94c0c23..f7dd66d67b58fd 100644 --- a/samples/cpp/common/utils/CMakeLists.txt +++ b/samples/cpp/common/utils/CMakeLists.txt @@ -11,7 +11,7 @@ add_library(${TARGET_NAME} STATIC EXCLUDE_FROM_ALL ${SOURCES}) set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "src") target_include_directories(${TARGET_NAME} - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") + PUBLIC "$") find_package(OpenVINO REQUIRED COMPONENTS Runtime) diff --git a/samples/cpp/hello_classification/CMakeLists.txt b/samples/cpp/hello_classification/CMakeLists.txt index 8eb7dc23ffb83e..1d397db3d3f8ff 100644 --- a/samples/cpp/hello_classification/CMakeLists.txt +++ b/samples/cpp/hello_classification/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # -ie_add_sample(NAME hello_classification +ov_add_sample(NAME hello_classification SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp" DEPENDENCIES format_reader ie_samples_utils) diff --git a/samples/cpp/hello_nv12_input_classification/CMakeLists.txt b/samples/cpp/hello_nv12_input_classification/CMakeLists.txt index d16c619c696581..1e0e73ca8ec35e 100644 --- a/samples/cpp/hello_nv12_input_classification/CMakeLists.txt +++ b/samples/cpp/hello_nv12_input_classification/CMakeLists.txt @@ -2,6 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 # -ie_add_sample(NAME hello_nv12_input_classification +ov_add_sample(NAME hello_nv12_input_classification SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp" DEPENDENCIES format_reader ie_samples_utils) diff --git a/samples/cpp/hello_query_device/CMakeLists.txt b/samples/cpp/hello_query_device/CMakeLists.txt index 6e3f28c2ad163a..b7947a58cf3e60 100644 --- a/samples/cpp/hello_query_device/CMakeLists.txt +++ b/samples/cpp/hello_query_device/CMakeLists.txt @@ -2,6 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 # -ie_add_sample(NAME hello_query_device +ov_add_sample(NAME hello_query_device SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp" DEPENDENCIES ie_samples_utils) diff --git a/samples/cpp/hello_reshape_ssd/CMakeLists.txt b/samples/cpp/hello_reshape_ssd/CMakeLists.txt index b1aa85349b7b86..6405c769f24307 100644 --- a/samples/cpp/hello_reshape_ssd/CMakeLists.txt +++ b/samples/cpp/hello_reshape_ssd/CMakeLists.txt @@ -2,6 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 # -ie_add_sample(NAME hello_reshape_ssd +ov_add_sample(NAME hello_reshape_ssd SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp" DEPENDENCIES format_reader ie_samples_utils) diff --git a/samples/cpp/model_creation_sample/CMakeLists.txt b/samples/cpp/model_creation_sample/CMakeLists.txt index f7d100c6bb0079..9d42ef3602a15b 100644 --- a/samples/cpp/model_creation_sample/CMakeLists.txt +++ b/samples/cpp/model_creation_sample/CMakeLists.txt @@ -4,7 +4,7 @@ set(TARGET_NAME "model_creation_sample") -ie_add_sample(NAME model_creation_sample +ov_add_sample(NAME model_creation_sample SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp" HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/model_creation_sample.hpp" DEPENDENCIES format_reader ie_samples_utils) diff --git a/samples/cpp/speech_sample/CMakeLists.txt b/samples/cpp/speech_sample/CMakeLists.txt index 092ebf14807680..a9e8c0e9d256fa 100644 --- a/samples/cpp/speech_sample/CMakeLists.txt +++ b/samples/cpp/speech_sample/CMakeLists.txt @@ -46,7 +46,7 @@ endif() # add sample -ie_add_sample(NAME speech_sample +ov_add_sample(NAME speech_sample SOURCES ${SRC} HEADERS ${HDR} DEPENDENCIES ${GFLAGS_TARGET} cnpy ie_samples_utils) diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 68833c2fd5b8da..c76904c7270c03 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -15,7 +15,7 @@ set(shellcheck_skip_list "${OpenVINO_SOURCE_DIR}/src/bindings/python/thirdparty/pybind11" "${TEMP}") -ie_shellcheck_process(DIRECTORY "${OpenVINO_SOURCE_DIR}" +ov_shellcheck_process(DIRECTORY "${OpenVINO_SOURCE_DIR}" SKIP ${shellcheck_skip_list}) # diff --git a/src/bindings/c/src/CMakeLists.txt b/src/bindings/c/src/CMakeLists.txt index e491424cb27afb..a6a649ada6e990 100644 --- a/src/bindings/c/src/CMakeLists.txt +++ b/src/bindings/c/src/CMakeLists.txt @@ -32,6 +32,10 @@ set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_REL ov_add_vs_version_file(NAME ${TARGET_NAME} FILEDESCRIPTION "OpenVINO C API Core Runtime library") +ov_set_apple_rpath(${TARGET_NAME} + # openvino_c installed in the same directory as openvino + ${OV_CPACK_RUNTIMEDIR} ${OV_CPACK_RUNTIMEDIR}) + # export set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME runtime::c) @@ -42,6 +46,7 @@ export(TARGETS ${TARGET_NAME} NAMESPACE openvino:: APPEND FILE "${CMAKE_BINARY_DIR}/OpenVINOTargets.cmake") # install + ov_cpack_add_component(${OV_CPACK_COMP_CORE_C} HIDDEN) ov_cpack_add_component(${OV_CPACK_COMP_CORE_C_DEV} HIDDEN) diff --git a/src/bindings/c/src/ov_remote_context.cpp b/src/bindings/c/src/ov_remote_context.cpp index c484ea60b635cc..68e802e256973e 100644 --- a/src/bindings/c/src/ov_remote_context.cpp +++ b/src/bindings/c/src/ov_remote_context.cpp @@ -37,11 +37,11 @@ inline bool check_intel_gpu_property_value_is_ptr(std::string& key) { std::string property_key = va_arg(args_ptr, char*); \ if (check_intel_gpu_property_value_is_ptr(property_key)) { \ ov::Any value = va_arg(args_ptr, void*); \ - property[property_key] = value; \ + property[property_key] = std::move(value); \ } else { \ std::string _value = va_arg(args_ptr, char*); \ ov::Any value = _value; \ - property[property_key] = value; \ + property[property_key] = std::move(value); \ } \ } diff --git a/src/bindings/c/tests/test_model_repo.cpp b/src/bindings/c/tests/test_model_repo.cpp index c221df9e3f8fe9..b7af72817d3b77 100644 --- a/src/bindings/c/tests/test_model_repo.cpp +++ b/src/bindings/c/tests/test_model_repo.cpp @@ -38,7 +38,7 @@ std::string generate_test_xml_file() { plugin_xml_file << ov::util::FileTraits::file_separator; plugin_xml_file << ov::util::FileTraits::library_prefix(); plugin_xml_file << "mock_engine"; - plugin_xml_file << IE_BUILD_POSTFIX; + plugin_xml_file << OV_BUILD_POSTFIX; plugin_xml_file << ov::util::FileTraits::dot_symbol; plugin_xml_file << ov::util::FileTraits::library_ext(); plugin_xml_file << "\" name=\"CUSTOM\">\n"; diff --git a/src/bindings/python/CMakeLists.txt b/src/bindings/python/CMakeLists.txt index c8b55e3b280e01..a2e8945a807776 100644 --- a/src/bindings/python/CMakeLists.txt +++ b/src/bindings/python/CMakeLists.txt @@ -20,7 +20,20 @@ project(OpenVINOPython DESCRIPTION "OpenVINO Runtime Python bindings") if(NOT DEFINED OpenVINO_SOURCE_DIR) find_package(OpenVINODeveloperPackage REQUIRED PATHS "${InferenceEngineDeveloperPackage_DIR}") + + # we assume that OpenVINODeveloperPackage is generated in OpenVINO build tree set(OpenVINO_BINARY_DIR "${OpenVINODeveloperPackage_DIR}") + # but this can be invalid for cases of OpenVINODeveloperPackage relocatable installation + # so, we need to disable wheen generation for this case + if(NOT EXISTS "${OpenVINO_BINARY_DIR}/cmake_install.cmake") + set(OpenVINODeveloperPackage_RELOCATABLE ON) + endif() + + set(OpenVINO_SOURCE_DIR "${OpenVINOPython_SOURCE_DIR}/../../../") +endif() + +if(NOT DEFINED OpenVINODeveloperPackage_RELOCATABLE) + set(OpenVINODeveloperPackage_RELOCATABLE OFF) endif() # @@ -123,17 +136,8 @@ ov_check_python_build_conditions() # check __init__.py files alignment -function(ov_check_init_files_alignment) +function(ov_check_init_files_alignment init_files) # check the files in pairs - list(APPEND init_files - "${OpenVINOPython_SOURCE_DIR}/src/openvino/__init__.py" - "${OpenVINOPython_SOURCE_DIR}/src/compatibility/openvino/__init__.py" - "${OpenVINO_SOURCE_DIR}/tools/mo/openvino/__init__.py" - "${OpenVINO_SOURCE_DIR}/tools/pot/openvino/__init__.py" - "${OpenVINO_SOURCE_DIR}/tools/ovc/openvino/__init__.py" - "${OpenVINO_SOURCE_DIR}/tools/benchmark_tool/openvino/__init__.py" - "${OpenVINO_SOURCE_DIR}/tools/openvino_dev/src/openvino/__init__.py") - list(LENGTH init_files init_files_count) math(EXPR file_loop_range "${init_files_count}-2") foreach(init_file_idx RANGE 0 ${file_loop_range}) @@ -145,14 +149,19 @@ function(ov_check_init_files_alignment) RESULT_VARIABLE compare_result ) if(compare_result EQUAL 1) - message(FATAL_ERROR "The __init__.py files are misaligned: ${file1} and ${file2}") + message(FATAL_ERROR "The runtime __init__.py files are misaligned: ${file1} and ${file2}") endif() endforeach() endfunction() -ov_check_init_files_alignment() +set(INIT_FILES_RUNTIME "${OpenVINOPython_SOURCE_DIR}/src/openvino/__init__.py" + "${OpenVINOPython_SOURCE_DIR}/src/compatibility/openvino/__init__.py" + "${OpenVINO_SOURCE_DIR}/tools/ovc/openvino/__init__.py" + "${OpenVINO_SOURCE_DIR}/tools/benchmark_tool/openvino/__init__.py") + +ov_check_init_files_alignment("${INIT_FILES_RUNTIME}") -ie_option(ENABLE_PYTHON "Enables OpenVINO Python API build" ${ENABLE_PYTHON_DEFAULT}) +ov_option(ENABLE_PYTHON "Enables OpenVINO Python API build" ${ENABLE_PYTHON_DEFAULT}) # # Check for wheel package @@ -196,7 +205,7 @@ endif() # this option should not be a part of OpenVINODeveloperPackage # since wheels can be built only together with main OV build -ie_dependent_option(ENABLE_WHEEL "Build wheel packages for PyPI" ${ENABLE_WHEEL_DEFAULT} "ENABLE_PYTHON" OFF) +ov_dependent_option(ENABLE_WHEEL "Build wheel packages for PyPI" ${ENABLE_WHEEL_DEFAULT} "ENABLE_PYTHON;NOT OpenVINODeveloperPackage_RELOCATABLE" OFF) if(NOT ENABLE_PYTHON) if(CMAKE_SOURCE_DIR STREQUAL OpenVINOPython_SOURCE_DIR) @@ -400,5 +409,5 @@ if(OpenVINODeveloperPackage_FOUND) # provides a callback function to describe each component in repo include("${OpenVINO_SOURCE_DIR}/cmake/packaging/packaging.cmake") - ie_cpack(${IE_CPACK_COMPONENTS_ALL}) + ov_cpack(${OV_CPACK_COMPONENTS_ALL}) endif() diff --git a/src/bindings/python/constraints.txt b/src/bindings/python/constraints.txt index 9178eef451d033..20e888bde84984 100644 --- a/src/bindings/python/constraints.txt +++ b/src/bindings/python/constraints.txt @@ -5,7 +5,7 @@ numpy>=1.16.6,<1.27 # Python bindings, frontends pytest>=5.0,<7.5 pytest-dependency==0.5.1 pytest-html==3.2.0 -pytest-timeout==2.1.0 +pytest-timeout==2.2.0 # Python bindings py>=1.9.0 @@ -17,7 +17,7 @@ patchelf<=0.17.2.1 # Frontends docopt~=0.6.2 paddlepaddle==2.5.1 -tensorflow>=1.15.5,<2.14.0 +tensorflow>=1.15.5,<2.15.0 six~=1.16.0 protobuf>=3.18.1,<4.0.0 onnx==1.14.1 diff --git a/src/bindings/python/requirements.txt b/src/bindings/python/requirements.txt index 72438eeb2ecd91..c4d3c3e35568aa 100644 --- a/src/bindings/python/requirements.txt +++ b/src/bindings/python/requirements.txt @@ -1,3 +1,3 @@ numpy>=1.16.6 singledispatchmethod; python_version<'3.8' -openvino-telemetry>=2023.1.0 +openvino-telemetry>=2023.2.1 diff --git a/src/bindings/python/setup.cfg b/src/bindings/python/setup.cfg index 083c8e1de85cb1..b9b15ef0ca1214 100644 --- a/src/bindings/python/setup.cfg +++ b/src/bindings/python/setup.cfg @@ -13,6 +13,7 @@ setenv = OV_BACKEND = {env:OV_BACKEND:"CPU"} PYTHONPATH = {env:PYTHONPATH} OpenVINO_DIR = {env:OpenVINO_DIR} + CI = True passenv = http_proxy https_proxy diff --git a/src/bindings/python/src/compatibility/ngraph/opset3/ops.py b/src/bindings/python/src/compatibility/ngraph/opset3/ops.py index 82846826111751..7d7c757d9cd5dc 100644 --- a/src/bindings/python/src/compatibility/ngraph/opset3/ops.py +++ b/src/bindings/python/src/compatibility/ngraph/opset3/ops.py @@ -550,9 +550,9 @@ def shuffle_channels(data: Node, axis: int, group: int, name: Optional[str] = No `data_reshaped` = reshape(`data`, [N, group, C / group, H * W]) - `data_trnasposed` = transpose(`data_reshaped`, [0, 2, 1, 3]) + `data_transposed` = transpose(`data_reshaped`, [0, 2, 1, 3]) - `output` = reshape(`data_trnasposed`, [N, C, H, W]) + `output` = reshape(`data_transposed`, [N, C, H, W]) For example: diff --git a/src/bindings/python/src/compatibility/openvino/__init__.py b/src/bindings/python/src/compatibility/openvino/__init__.py index 90552e0befed68..b7dc434f3148cc 100644 --- a/src/bindings/python/src/compatibility/openvino/__init__.py +++ b/src/bindings/python/src/compatibility/openvino/__init__.py @@ -12,47 +12,47 @@ except ImportError: pass -# API 2.0 -try: - # Import all public modules - from openvino import runtime as runtime - from openvino import frontend as frontend - from openvino import helpers as helpers - from openvino import preprocess as preprocess - from openvino import utils as utils - from openvino.runtime import properties as properties - - # Import most important classes and functions from openvino.runtime - from openvino.runtime import Model - from openvino.runtime import Core - from openvino.runtime import CompiledModel - from openvino.runtime import InferRequest - from openvino.runtime import AsyncInferQueue - - from openvino.runtime import Dimension - from openvino.runtime import Strides - from openvino.runtime import PartialShape - from openvino.runtime import Shape - from openvino.runtime import Layout - from openvino.runtime import Type - from openvino.runtime import Tensor - from openvino.runtime import OVAny - - from openvino.runtime import compile_model - from openvino.runtime import get_batch - from openvino.runtime import set_batch - from openvino.runtime import serialize - from openvino.runtime import shutdown - from openvino.runtime import tensor_from_file - from openvino.runtime import save_model - from openvino.runtime import layout_helpers - - # Set version for openvino package - from openvino.runtime import get_version - __version__ = get_version() -except ImportError: - import warnings - warnings.warn("openvino package has problems with imports!", ImportWarning, stacklevel=2) +# # +# # API 2.0 +# # This __init__.py forces checking of runtime modules to propagate errors. +# # It is not compared with init files from openvino-dev package. +# # +# Import all public modules +from openvino import runtime as runtime +from openvino import frontend as frontend +from openvino import helpers as helpers +from openvino import preprocess as preprocess +from openvino import utils as utils +from openvino.runtime import properties as properties + +# Import most important classes and functions from openvino.runtime +from openvino.runtime import Model +from openvino.runtime import Core +from openvino.runtime import CompiledModel +from openvino.runtime import InferRequest +from openvino.runtime import AsyncInferQueue + +from openvino.runtime import Dimension +from openvino.runtime import Strides +from openvino.runtime import PartialShape +from openvino.runtime import Shape +from openvino.runtime import Layout +from openvino.runtime import Type +from openvino.runtime import Tensor +from openvino.runtime import OVAny + +from openvino.runtime import compile_model +from openvino.runtime import get_batch +from openvino.runtime import set_batch +from openvino.runtime import serialize +from openvino.runtime import shutdown +from openvino.runtime import tensor_from_file +from openvino.runtime import save_model +from openvino.runtime import layout_helpers + +# Set version for openvino package +from openvino.runtime import get_version +__version__ = get_version() # Tools try: diff --git a/src/bindings/python/src/compatibility/openvino/cmake/CythonConfig.cmake b/src/bindings/python/src/compatibility/openvino/cmake/CythonConfig.cmake index 8d02cf9890a5be..8eeabf849f49c5 100644 --- a/src/bindings/python/src/compatibility/openvino/cmake/CythonConfig.cmake +++ b/src/bindings/python/src/compatibility/openvino/cmake/CythonConfig.cmake @@ -36,9 +36,12 @@ function( _find_cython_executable ) get_filename_component( _python_path ${Python3_EXECUTABLE} PATH ) file(TO_CMAKE_PATH "$ENV{HOME}" ENV_HOME) find_host_program( CYTHON_EXECUTABLE - NAMES cython cython.bat cython3 - HINTS ${_python_path} ${ENV_HOME}/.local/bin $ENV{HOMEBREW_OPT}/cython/bin + NAMES cython cython.exe cython.bat cython3 + HINTS ${_python_path} + ${ENV_HOME}/.local/bin + $ENV{HOMEBREW_OPT}/cython/bin ${ENV_HOME}/Library/Python/${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/bin + ${_python_path}/Scripts ) else() find_host_program( CYTHON_EXECUTABLE diff --git a/src/bindings/python/src/compatibility/openvino/inference_engine/CMakeLists.txt b/src/bindings/python/src/compatibility/openvino/inference_engine/CMakeLists.txt index 8fcfa90e66236a..be45fe1281b3d1 100644 --- a/src/bindings/python/src/compatibility/openvino/inference_engine/CMakeLists.txt +++ b/src/bindings/python/src/compatibility/openvino/inference_engine/CMakeLists.txt @@ -64,7 +64,7 @@ endif() function(python_ov_disable_deprecated_warnings) ov_disable_deprecated_warnings() set(pyx_file "${CMAKE_CURRENT_BINARY_DIR}/ie_api.cxx" "${CMAKE_CURRENT_BINARY_DIR}/constants.cxx") - set_source_files_properties(${pyx_file} PROPERTIES COMPILE_OPTIONS ${ie_c_cxx_deprecated}) + set_source_files_properties(${pyx_file} PROPERTIES COMPILE_OPTIONS ${ov_c_cxx_deprecated}) endfunction() python_ov_disable_deprecated_warnings() @@ -84,6 +84,10 @@ add_custom_command(TARGET ${TARGET_NAME} COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/__init__.py ) +foreach(target IN LISTS INSTALLED_TARGETS) + ov_set_apple_rpath(${target} ${OV_CPACK_PYTHONDIR}/openvino/inference_engine ${OV_CPACK_RUNTIMEDIR}) +endforeach() + # install install(TARGETS ${INSTALLED_TARGETS} diff --git a/src/bindings/python/src/compatibility/pyngraph/CMakeLists.txt b/src/bindings/python/src/compatibility/pyngraph/CMakeLists.txt index 998c950ff4cc97..8b68d5dde8a5e9 100644 --- a/src/bindings/python/src/compatibility/pyngraph/CMakeLists.txt +++ b/src/bindings/python/src/compatibility/pyngraph/CMakeLists.txt @@ -7,27 +7,25 @@ cmake_minimum_required (VERSION 3.13) project (pyngraph) if(NOT DEFINED OpenVINO_SOURCE_DIR) + find_package(OpenVINO REQUIRED) find_package(OpenVINODeveloperPackage QUIET PATHS "${InferenceEngineDeveloperPackage_DIR}") - find_package(OpenVINO REQUIRED) endif() # Python3_VERSION_MAJOR and Python3_VERSION_MINOR are defined in FindPython3 set(pyversion python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}) -if(OpenVINO_SOURCE_DIR) - if(OV_GENERATOR_MULTI_CONFIG) - set(PYTHON_BRIDGE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/$/python/) - else() - set(PYTHON_BRIDGE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/python/) - endif() - - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) - set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) - set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) - set(CMAKE_PDB_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) +if(OV_GENERATOR_MULTI_CONFIG) + set(PYTHON_BRIDGE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/$/python/) +else() + set(PYTHON_BRIDGE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/python/) endif() +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) +set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) +set(CMAKE_PDB_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) + # compile options if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") @@ -54,41 +52,39 @@ file(GLOB_RECURSE SOURCES *.cpp) pybind11_add_module(_${PROJECT_NAME} MODULE NO_EXTRAS ${SOURCES}) -target_include_directories(_${PROJECT_NAME} PRIVATE "../" "${OpenVINO_SOURCE_DIR}/src/common/transformations/include") +target_include_directories(_${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../") -target_link_libraries(_${PROJECT_NAME} PRIVATE openvino::runtime) +target_link_libraries(_${PROJECT_NAME} PRIVATE openvino::runtime openvino::core::dev) set_target_properties(_${PROJECT_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO}) # perform copy -if(OpenVINO_SOURCE_DIR) - add_custom_command(TARGET _${PROJECT_NAME} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../ngraph ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/ngraph - ) -endif() +add_custom_command(TARGET _${PROJECT_NAME} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../ngraph ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/ngraph +) + +ov_set_apple_rpath(_${PROJECT_NAME} ${OV_CPACK_PYTHONDIR} ${OV_CPACK_RUNTIMEDIR}) # Install -if(OpenVINO_SOURCE_DIR OR OpenVINODeveloperPackage_FOUND) - ov_python_minimal_api(_${PROJECT_NAME}) - ov_add_clang_format_target(_${PROJECT_NAME}_clang FOR_TARGETS _${PROJECT_NAME}) +ov_python_minimal_api(_${PROJECT_NAME}) +ov_add_clang_format_target(_${PROJECT_NAME}_clang FOR_TARGETS _${PROJECT_NAME}) - ov_cpack_add_component(${OV_CPACK_COMP_PYTHON_OPENVINO}_${pyversion} HIDDEN) +ov_cpack_add_component(${OV_CPACK_COMP_PYTHON_OPENVINO}_${pyversion} HIDDEN) - install(TARGETS _${PROJECT_NAME} - DESTINATION ${OV_CPACK_PYTHONDIR} - COMPONENT ${OV_CPACK_COMP_PYTHON_OPENVINO}_${pyversion} - ${OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL}) +install(TARGETS _${PROJECT_NAME} + DESTINATION ${OV_CPACK_PYTHONDIR} + COMPONENT ${OV_CPACK_COMP_PYTHON_OPENVINO}_${pyversion} + ${OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL}) - install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../ngraph - DESTINATION ${OV_CPACK_PYTHONDIR} - COMPONENT ${OV_CPACK_COMP_PYTHON_OPENVINO}_${pyversion} - ${OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL} - USE_SOURCE_PERMISSIONS) +install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../ngraph + DESTINATION ${OV_CPACK_PYTHONDIR} + COMPONENT ${OV_CPACK_COMP_PYTHON_OPENVINO}_${pyversion} + ${OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL} + USE_SOURCE_PERMISSIONS) - install(DIRECTORY ${OpenVINOPython_SOURCE_DIR}/tests_compatibility - DESTINATION tests/${PROJECT_NAME} - COMPONENT tests - EXCLUDE_FROM_ALL) -endif() +install(DIRECTORY ${OpenVINOPython_SOURCE_DIR}/tests_compatibility + DESTINATION tests/${PROJECT_NAME} + COMPONENT tests + EXCLUDE_FROM_ALL) diff --git a/src/bindings/python/src/openvino/__init__.py b/src/bindings/python/src/openvino/__init__.py index 90552e0befed68..b7dc434f3148cc 100644 --- a/src/bindings/python/src/openvino/__init__.py +++ b/src/bindings/python/src/openvino/__init__.py @@ -12,47 +12,47 @@ except ImportError: pass -# API 2.0 -try: - # Import all public modules - from openvino import runtime as runtime - from openvino import frontend as frontend - from openvino import helpers as helpers - from openvino import preprocess as preprocess - from openvino import utils as utils - from openvino.runtime import properties as properties - - # Import most important classes and functions from openvino.runtime - from openvino.runtime import Model - from openvino.runtime import Core - from openvino.runtime import CompiledModel - from openvino.runtime import InferRequest - from openvino.runtime import AsyncInferQueue - - from openvino.runtime import Dimension - from openvino.runtime import Strides - from openvino.runtime import PartialShape - from openvino.runtime import Shape - from openvino.runtime import Layout - from openvino.runtime import Type - from openvino.runtime import Tensor - from openvino.runtime import OVAny - - from openvino.runtime import compile_model - from openvino.runtime import get_batch - from openvino.runtime import set_batch - from openvino.runtime import serialize - from openvino.runtime import shutdown - from openvino.runtime import tensor_from_file - from openvino.runtime import save_model - from openvino.runtime import layout_helpers - - # Set version for openvino package - from openvino.runtime import get_version - __version__ = get_version() -except ImportError: - import warnings - warnings.warn("openvino package has problems with imports!", ImportWarning, stacklevel=2) +# # +# # API 2.0 +# # This __init__.py forces checking of runtime modules to propagate errors. +# # It is not compared with init files from openvino-dev package. +# # +# Import all public modules +from openvino import runtime as runtime +from openvino import frontend as frontend +from openvino import helpers as helpers +from openvino import preprocess as preprocess +from openvino import utils as utils +from openvino.runtime import properties as properties + +# Import most important classes and functions from openvino.runtime +from openvino.runtime import Model +from openvino.runtime import Core +from openvino.runtime import CompiledModel +from openvino.runtime import InferRequest +from openvino.runtime import AsyncInferQueue + +from openvino.runtime import Dimension +from openvino.runtime import Strides +from openvino.runtime import PartialShape +from openvino.runtime import Shape +from openvino.runtime import Layout +from openvino.runtime import Type +from openvino.runtime import Tensor +from openvino.runtime import OVAny + +from openvino.runtime import compile_model +from openvino.runtime import get_batch +from openvino.runtime import set_batch +from openvino.runtime import serialize +from openvino.runtime import shutdown +from openvino.runtime import tensor_from_file +from openvino.runtime import save_model +from openvino.runtime import layout_helpers + +# Set version for openvino package +from openvino.runtime import get_version +__version__ = get_version() # Tools try: diff --git a/src/bindings/python/src/openvino/frontend/pytorch/fx_decoder.py b/src/bindings/python/src/openvino/frontend/pytorch/fx_decoder.py index 45a662e4e45fd1..479e1a5cb1c622 100644 --- a/src/bindings/python/src/openvino/frontend/pytorch/fx_decoder.py +++ b/src/bindings/python/src/openvino/frontend/pytorch/fx_decoder.py @@ -7,10 +7,9 @@ from openvino.frontend.pytorch.py_pytorch_frontend import _FrontEndPytorchDecoder as Decoder from openvino.frontend.pytorch.py_pytorch_frontend import _Type as DecoderType from openvino.runtime import op, PartialShape, Type as OVType, OVAny, Shape -from openvino.frontend.pytorch.utils import maybe_convert_max_int, make_constant, fetch_attr, pt_to_ov_type_map, ov_to_c_type_map +from openvino.frontend.pytorch.utils import maybe_convert_max_int, make_constant, fetch_attr, pt_to_ov_type_map import torch -import ctypes class TorchFXPythonDecoder (Decoder): @@ -224,11 +223,7 @@ def as_constant(self): if self.pt_module.op == 'get_attr': # Extract Constant from FX module field ret = fetch_attr(self.fx_gm, self.pt_module.target) - ovshape = PartialShape(ret.size()) - ovtype = pt_to_ov_type_map[str(ret.type())] - c_type = ctypes.POINTER(ov_to_c_type_map[ovtype]) - data_c_ptr = ctypes.cast(ret.data_ptr(), c_type) - ov_const = op.Constant(ovtype, ovshape.get_shape(), data_c_ptr[:ret.nelement()]) + ov_const = op.Constant(ret.numpy(), shared_memory=True) return ov_const.outputs() @@ -370,7 +365,7 @@ def inlined_inputs(self, index): return result def may_produce_alias(self, in_index: int, out_index: int) -> bool: - if self.get_op_type() in ["aten::conv1d", "aten::conv2d", "aten::conv3d"]: + if self.get_op_type() in ["aten::conv1d", "aten::conv2d", "aten::conv3d", "aten::matmul"]: # AliasDB::may_contain_alias sometimes return True for tensors produced by convnd, we have to workaround that return False try: diff --git a/src/bindings/python/src/openvino/frontend/pytorch/gptq.py b/src/bindings/python/src/openvino/frontend/pytorch/gptq.py new file mode 100644 index 00000000000000..b4bd06552b2a1e --- /dev/null +++ b/src/bindings/python/src/openvino/frontend/pytorch/gptq.py @@ -0,0 +1,140 @@ + +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +# flake8: noqa +# mypy: ignore-errors + +import torch +from functools import partial + +# Wraps a single tensor to a module to prevent it from jit.freezing +# It depends on a tensor dtype whether it will be preserved from freezing. Refer to the decoder code to learn which types will be preserved. +class KeepWeight(torch.nn.Module): + + def __init__(self, weight): + super().__init__() + self.weight = torch.nn.Parameter(weight, requires_grad=False) + + def forward(self): + return self.weight + + +# Produces a pattern that can be captured later and represented as a single u4 constant node +def decompression_pattern(weights): + mask = torch.tensor(15, dtype=torch.uint8).to(weights.device) + return torch.stack((torch.bitwise_and(weights, mask), torch.bitwise_right_shift(weights, 4)), dim=-1) + + +def patched_forward(self, *args, **kwargs): + if hasattr(self, '_hf_hook'): + args, kwargs = self._hf_hook.pre_forward(self, *args, **kwargs) + + x = args[0] + dtype = x.dtype + outshape = x.shape[:-1] + (self.width,) + x = x.view(-1, x.shape[-1]) + groups = self.qzeros.shape[0] + height = self.qweight.shape[0] + + unpacked_weights = decompression_pattern( + self._openvino_u4_compression_submodule_qweights()).contiguous().view(height, -1, 8) + unpacked_weights = torch.transpose( + unpacked_weights, 1, 2).contiguous().view(-1, self.group_size, self.width) + unpacked_zp = decompression_pattern( + self._openvino_u4_compression_submodule_qzeros()).contiguous().view(groups, 1, -1) + + unpacked_zp = unpacked_zp.to(dtype) + 1 + + unpacked_weights = (unpacked_weights.to(dtype) - unpacked_zp) * self.scales + unpacked_weights = unpacked_weights.view(-1, self.width) + + out = x @ unpacked_weights + + out = out.view(outshape) + if self.bias is not None: + out.add_(self.bias) + + if hasattr(self, '_hf_hook'): + out = self._hf_hook.post_forward(self, out) + return out + + +# All the following AutoGPTQ's quant types are supposed to have the same weights packing schema +supported_quant_types = ['triton', 'exllama', 'cuda', 'exllamav2', 'cuda-old'] + + +def patch_model(model): + for name, m in model.named_modules(): + if hasattr(m, '_openvino_patch_orig_forward'): + # already patched, skipping + continue + # TODO: Check module type + is_quantized = getattr(m, 'is_quantized', None) + if is_quantized is not None: + m.is_quantized = False + m.float() # enables tracing on CPU, applied for all modules + if hasattr(m, 'QUANT_TYPE'): + if m.QUANT_TYPE not in supported_quant_types: + raise ValueError( + f'Unsupported QUANT_TYPE == {m.QUANT_TYPE} is discovered for AutoGPTQ model, only the following types are supported: {supported_quant_types}') + if m.bits != 4: + raise ValueError( + f'Unsupported bits == {m.bits} is discovered in module {name} in AutoGPTQ model, only bits == 4 is supported.') + + int4_in_int32 = 8 + groups = m.qzeros.shape[0] + m.width = m.qweight.shape[1] + assert m.group_size == m.qweight.shape[0] * int4_in_int32 // groups + + m._openvino_patch_orig_forward = m.forward + m.forward = partial(patched_forward, m) + + # Keep original field properties to be used when model is returned back to its original state + m._openvino_patch_orig_qweights_type = m.qweight.dtype + m._openvino_patch_orig_qzeros_type = m.qzeros.dtype + m._openvino_patch_orig_scale_shape = m.scales.shape + + m.qweight = m.qweight.view(dtype=torch.uint8) + m.qzeros = m.qzeros.view(dtype=torch.uint8) + + # TODO: Redundant tensor copy? Try to remove m.qweigh and m.qzeros after keeping modified values as submodules + m.add_module( + '_openvino_u4_compression_submodule_qweights', KeepWeight(m.qweight)) + m.add_module('_openvino_u4_compression_submodule_qzeros', + KeepWeight(m.qzeros)) + + m.scales = m.scales.view(-1, 1, m.width) + + +def unpatch_model(model): + for _, m in model.named_modules(): + if hasattr(m, '_openvino_patch_orig_forward'): + try: + m.forward = m._openvino_patch_orig_forward + del m._openvino_patch_orig_forward + + m.qweight = m.qweight.view( + dtype=m._openvino_patch_orig_qweights_type) + del m._openvino_patch_orig_qweights_type + + m.qzeros = m.qzeros.view( + dtype=m._openvino_patch_orig_qzeros_type) + del m._openvino_patch_orig_qzeros_type + + m.scales = m.scales.view(m._openvino_patch_orig_scale_shape) + del m._openvino_patch_orig_scale_shape + + del m._openvino_u4_compression_submodule_qweights + del m._openvino_u4_compression_submodule_qzeros + except Exception as error: + print('[ WARNING ] Exception raised during GPTQ model unpatching. Depending on the exact issue it may lead to broken original model') + print(error) + + +def detect_gptq_model_raw(model): + return model and getattr(model, 'config', None) and getattr(model.config, 'quantization_config', None) and model.config.quantization_config.quant_method == 'gptq' + + +def detect_gptq_model(model): + return detect_gptq_model_raw(model) or getattr(model, 'model', None) and detect_gptq_model_raw(model.model) diff --git a/src/bindings/python/src/openvino/frontend/pytorch/torchdynamo/op_support.py b/src/bindings/python/src/openvino/frontend/pytorch/torchdynamo/op_support.py index 726f3b598bc15e..4a76d90b160553 100644 --- a/src/bindings/python/src/openvino/frontend/pytorch/torchdynamo/op_support.py +++ b/src/bindings/python/src/openvino/frontend/pytorch/torchdynamo/op_support.py @@ -41,6 +41,7 @@ def __init__(self): "torch.ops.aten.arange.default": None, "torch.ops.aten.argmax.default": None, "torch.ops.aten.avg_pool2d.default": None, + "torch.ops.aten.baddbmm.default": None, "torch.ops.aten.bitwise_and.Tensor": None, "torch.ops.aten.bmm.default": None, "torch.ops.aten.cat.default": None, @@ -67,6 +68,7 @@ def __init__(self): "torch.ops.aten.hardswish_.default": None, "torch.ops.aten.hardtanh_.default": None, "torch.ops.aten.index.Tensor": None, + "torch.ops.aten.leaky_relu_.default": None, "torch.ops.aten.lift_fresh_copy.default": None, "torch.ops.aten.linalg_vector_norm.default": None, "torch.ops.aten.lt.Tensor": None, @@ -89,6 +91,7 @@ def __init__(self): "torch.ops.aten.relu.default": None, "torch.ops.aten.relu_.default": None, "torch.ops.aten.rsub.Scalar": None, + "torch.ops.aten._scaled_dot_product_flash_attention.default": None, "torch.ops.aten.select.int": None, "torch.ops.aten.sigmoid.default": None, "torch.ops.aten.silu.default": None, diff --git a/src/bindings/python/src/openvino/frontend/pytorch/ts_decoder.py b/src/bindings/python/src/openvino/frontend/pytorch/ts_decoder.py index 32e62084e89e41..a57393e7638d67 100644 --- a/src/bindings/python/src/openvino/frontend/pytorch/ts_decoder.py +++ b/src/bindings/python/src/openvino/frontend/pytorch/ts_decoder.py @@ -9,6 +9,7 @@ from openvino.runtime import op, PartialShape, Type as OVType, OVAny from openvino.frontend.pytorch.utils import ivalue_to_constant, get_value_from_getattr, pt_to_ov_type_map, prepare_example_inputs_and_model, convert_quantized_tensor from openvino.runtime import opset11 as ops +from openvino.frontend.pytorch import gptq import typing import torch @@ -84,12 +85,32 @@ def _get_scripted_model(self, pt_module, example_inputs=None, skip_freeze=False) if example_inputs is None: scripted = torch.jit.script(pt_module) else: - input_parameters, input_signature, pt_module, self._input_is_list = prepare_example_inputs_and_model(example_inputs, input_params, pt_module) - scripted = torch.jit.trace(pt_module, **input_parameters, strict=False) + input_parameters, input_signature, pt_module, self._input_is_list = prepare_example_inputs_and_model( + example_inputs, input_params, pt_module) + gptq_patched = False + + if gptq.detect_gptq_model(pt_module): + try: + gptq.patch_model(pt_module) + gptq_patched = True + except Exception as error: + print('[ WARNING ] Failed patching of AutoGPTQ model. Error message:\n', error) + print('[ WARNING ] Tracing of the model will likely be unsuccesfull or incorrect') + gptq.unpatch_model(pt_module) + gptq_patched = False + + try: + scripted = torch.jit.trace( + pt_module, **input_parameters, strict=False) + finally: + if gptq_patched: + gptq.unpatch_model(pt_module) + if not skip_freeze: + ops_kind_no_freeze = ["quantize", "aten::as_strided"] for n in scripted.inlined_graph.nodes(): # TODO: switch off freezing for all traced models - if "quantize" in n.kind(): + if any(kind in n.kind() for kind in ops_kind_no_freeze): # do not freeze quantized models skip_freeze = True break @@ -130,6 +151,16 @@ def get_input_shape(self, index: int): raw_input = self._raw_input(index) return self.get_shape_for_value(raw_input) + def get_input_strides(self, index: int) -> typing.List[int]: + raw_input = self._raw_input(index) + if isinstance(raw_input, torch.Value): + inp_type = raw_input.type() + if isinstance(inp_type, torch.TensorType): + strides = inp_type.strides() + if strides: + return strides + return [] + def get_input_type(self, index: int): raw_input = self._raw_input(index) return self.get_type_for_value(raw_input) @@ -169,7 +200,8 @@ def _get_known_type_for_value(self, pt_type): def get_shape_for_value(self, value: torch.Value): if value.isCompleteTensor(): - ps = PartialShape(value.type().sizes()) + # We avoid static shapes, they don't generalize on other inputs + ps = PartialShape([-1] * len(value.type().sizes())) return ps else: # TODO: Recognize types that we can represent as a nested constructs with objects from DecoderType @@ -340,8 +372,8 @@ def input_is_none(self, index: int) -> bool: return False def may_produce_alias(self, in_index: int, out_index: int) -> bool: - if self.get_op_type() in ["aten::conv1d", "aten::conv2d", "aten::conv3d"]: - # AliasDB::may_contain_alias sometimes return True for tensors produced by convnd, we have to workaround that + if self.get_op_type() in ["aten::conv1d", "aten::conv2d", "aten::conv3d", "aten::_convolution", "aten::matmul"]: + # AliasDB::may_contain_alias sometimes return True for tensors produced by convolution or matmul, we have to workaround that return False try: return self.alias_db.may_contain_alias(self._raw_input(in_index), self._raw_output(out_index)) diff --git a/src/bindings/python/src/openvino/frontend/pytorch/utils.py b/src/bindings/python/src/openvino/frontend/pytorch/utils.py index 97d237fb0efda1..a3ac46e701119b 100644 --- a/src/bindings/python/src/openvino/frontend/pytorch/utils.py +++ b/src/bindings/python/src/openvino/frontend/pytorch/utils.py @@ -7,7 +7,6 @@ import torch import numpy as np -import ctypes from openvino.runtime import op, Type as OVType, Shape, Tensor from openvino.runtime import opset11 as ops @@ -132,13 +131,6 @@ def get_value_from_getattr(getattr_node, self_module): "torch.qint32": OVType.i32 } -ov_to_c_type_map = { - OVType.f32: ctypes.c_float, - OVType.f64: ctypes.c_double, - OVType.i32: ctypes.c_int, - OVType.i64: ctypes.c_int64, -} - wrapper_template = """ import torch diff --git a/src/bindings/python/src/openvino/runtime/opset13/__init__.py b/src/bindings/python/src/openvino/runtime/opset13/__init__.py index 66d2b3e9d46096..9cdb7149569ebb 100644 --- a/src/bindings/python/src/openvino/runtime/opset13/__init__.py +++ b/src/bindings/python/src/openvino/runtime/opset13/__init__.py @@ -18,6 +18,10 @@ from openvino.runtime.opset5.ops import batch_norm_inference from openvino.runtime.opset2.ops import batch_to_space from openvino.runtime.opset1.ops import binary_convolution +from openvino.runtime.opset13.ops import bitwise_and +from openvino.runtime.opset13.ops import bitwise_not +from openvino.runtime.opset13.ops import bitwise_or +from openvino.runtime.opset13.ops import bitwise_xor from openvino.runtime.opset3.ops import broadcast from openvino.runtime.opset3.ops import bucketize from openvino.runtime.opset1.ops import ceiling @@ -102,6 +106,7 @@ from openvino.runtime.opset4.ops import mish from openvino.runtime.opset1.ops import mod from openvino.runtime.opset9.ops import multiclass_nms +from openvino.runtime.opset13.ops import multinomial from openvino.runtime.opset1.ops import multiply from openvino.runtime.opset6.ops import mvn from openvino.runtime.opset1.ops import negative diff --git a/src/bindings/python/src/openvino/runtime/opset13/ops.py b/src/bindings/python/src/openvino/runtime/opset13/ops.py index f50d3cd91edaad..fff95b33d234d6 100644 --- a/src/bindings/python/src/openvino/runtime/opset13/ops.py +++ b/src/bindings/python/src/openvino/runtime/opset13/ops.py @@ -8,7 +8,7 @@ from openvino.runtime import Node from openvino.runtime.opset_utils import _get_node_factory -from openvino.runtime.utils.decorators import nameable_op +from openvino.runtime.utils.decorators import binary_op, nameable_op, unary_op from openvino.runtime.utils.types import ( NodeInput, as_nodes, @@ -19,6 +19,136 @@ # -------------------------------------------- ops ------------------------------------------------ +@binary_op +def bitwise_and( + left_node: NodeInput, + right_node: NodeInput, + auto_broadcast: str = "NUMPY", + name: Optional[str] = None, +) -> Node: + """Return node which performs bitwise AND operation on input nodes element-wise. + + For boolean input tensors, operator is equivalent to logical_and. + + :param left_node: Tensor of integer or boolean datatype providing data. + :param right_node: Tensor of integer or boolean datatype providing data. + :param auto_broadcast: The type of broadcasting specifies rules used for auto-broadcasting of input tensors. Defaults to “NUMPY”. + :param name: The optional new name for output node. + :return: The node performing bitwise AND operation on input nodes corresponding elements. + """ + return _get_node_factory_opset13().create( + "BitwiseAnd", + [left_node, right_node], + {"auto_broadcast": auto_broadcast.upper()}, + ) + + +@unary_op +def bitwise_not( + node: NodeInput, + name: Optional[str] = None, +) -> Node: + """Return node which performs bitwise NOT operation on input node element-wise. + + For boolean input tensors, operator is equivalent to logical_not. + + :param node: Tensor of integer or boolean datatype providing data. + :param name: The optional new name for output node. + :return: The node performing bitwise NOT operation on the given tensor. + """ + return _get_node_factory_opset13().create( + "BitwiseNot", + [node], + ) + + +@binary_op +def bitwise_or( + left_node: NodeInput, + right_node: NodeInput, + auto_broadcast: str = "NUMPY", + name: Optional[str] = None, +) -> Node: + """Return node which performs bitwise OR operation on input nodes element-wise. + + For boolean input tensors, operator is equivalent to logical_or. + + :param left_node: Tensor of integer or boolean datatype providing data. + :param right_node: Tensor of integer or boolean datatype providing data. + :param auto_broadcast: The type of broadcasting specifies rules used for auto-broadcasting of input tensors. Defaults to “NUMPY”. + :param name: The optional new name for output node. + :return: The node performing bitwise OR operation on input nodes corresponding elements. + """ + return _get_node_factory_opset13().create( + "BitwiseOr", + [left_node, right_node], + {"auto_broadcast": auto_broadcast.upper()}, + ) + + +@binary_op +def bitwise_xor( + left_node: NodeInput, + right_node: NodeInput, + auto_broadcast: str = "NUMPY", + name: Optional[str] = None, +) -> Node: + """Return node which performs bitwise XOR operation on input nodes element-wise. + + For boolean input tensors, operator is equivalent to logical_xor. + + :param left_node: Tensor of integer or boolean datatype providing data. + :param right_node: Tensor of integer or boolean datatype providing data. + :param auto_broadcast: The type of broadcasting specifies rules used for auto-broadcasting of input tensors. Defaults to “NUMPY”. + :param name: The optional new name for output node. + :return: The node performing bitwise XOR operation on input nodes corresponding elements. + """ + return _get_node_factory_opset13().create( + "BitwiseXor", + [left_node, right_node], + {"auto_broadcast": auto_broadcast.upper()}, + ) + + +@nameable_op +def multinomial( + probs: NodeInput, + num_samples: NodeInput, + convert_type: str, + with_replacement: bool, + log_probs: bool, + global_seed: int = 0, + op_seed: int = 0, +) -> Node: + """Return a node which generates a sequence of class indices sampled from the multinomial distribution. + + :param probs: Tensor with probabilities of floating-point type, and shape [class_size] or [batch_size, class_size]. + :param num_samples: Tensor (scalar or 1D) a single element of type i32 or i64, + specifying the number of samples to draw from the multinomial distribution. + :param convert_type: Specifies the output tensor type, possible values: 'i64', 'i32'. + :param with_replacement: Flag that specifies whether to sample with replacement. + :param log_probs: Flag that specifies whether *probs* should be treated as unnormalized log probabilities. + :param global_seed: Specifies global seed value. Required to be a positive integer or 0. + :param op_seed: Specifies operational seed value. Required to be a positive integer or 0. + + :return: The new node performing Multinomial operation. + """ + inputs = as_nodes(probs, num_samples) + + if global_seed < 0: + raise RuntimeError(f"global_seed should be positive or 0. Got: {global_seed}") + + if op_seed < 0: + raise RuntimeError(f"op_seed should be positive or 0. Got: {op_seed}") + + attributes = { + "convert_type": convert_type, + "with_replacement": with_replacement, + "log_probs": log_probs, + "global_seed": global_seed, + "op_seed": op_seed, + } + return _get_node_factory_opset13().create("Multinomial", inputs, attributes) @nameable_op diff --git a/src/bindings/python/src/openvino/runtime/opset3/ops.py b/src/bindings/python/src/openvino/runtime/opset3/ops.py index 979fda8a782a02..8a1d81d9703ffb 100644 --- a/src/bindings/python/src/openvino/runtime/opset3/ops.py +++ b/src/bindings/python/src/openvino/runtime/opset3/ops.py @@ -575,9 +575,9 @@ def shuffle_channels(data: Node, axis: int, group: int, name: Optional[str] = No `data_reshaped` = reshape(`data`, [N, group, C / group, H * W]) - `data_trnasposed` = transpose(`data_reshaped`, [0, 2, 1, 3]) + `data_transposed` = transpose(`data_reshaped`, [0, 2, 1, 3]) - `output` = reshape(`data_trnasposed`, [N, C, H, W]) + `output` = reshape(`data_transposed`, [N, C, H, W]) For example: diff --git a/src/bindings/python/src/openvino/runtime/utils/types.py b/src/bindings/python/src/openvino/runtime/utils/types.py index 5eeeb021a7c724..aa986d4f873c9c 100644 --- a/src/bindings/python/src/openvino/runtime/utils/types.py +++ b/src/bindings/python/src/openvino/runtime/utils/types.py @@ -23,6 +23,7 @@ openvino_to_numpy_types_map = [ (Type.boolean, bool), + (Type.boolean, np.bool_), (Type.f16, np.float16), (Type.f32, np.float32), (Type.f64, np.float64), @@ -39,6 +40,7 @@ openvino_to_numpy_types_str_map = [ ("boolean", bool), + ("boolean", np.bool_), ("f16", np.float16), ("f32", np.float32), ("f64", np.float64), diff --git a/src/bindings/python/src/pyopenvino/CMakeLists.txt b/src/bindings/python/src/pyopenvino/CMakeLists.txt index 5d5aeeb40021ac..5566c961d1a57b 100644 --- a/src/bindings/python/src/pyopenvino/CMakeLists.txt +++ b/src/bindings/python/src/pyopenvino/CMakeLists.txt @@ -10,19 +10,17 @@ endif() # Python3_VERSION_MAJOR and Python3_VERSION_MINOR are defined by FindPython3 set(pyversion python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}) -if(OpenVINO_SOURCE_DIR) - if(OV_GENERATOR_MULTI_CONFIG) - set(PYTHON_BRIDGE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/$/python/openvino) - else() - set(PYTHON_BRIDGE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/python/openvino) - endif() - - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) - set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) - set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) - set(CMAKE_PDB_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) +if(OV_GENERATOR_MULTI_CONFIG) + set(PYTHON_BRIDGE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/$/python/openvino) +else() + set(PYTHON_BRIDGE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/python/openvino) endif() +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) +set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) +set(CMAKE_PDB_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) + # compile options if(OV_COMPILER_IS_APPLECLANG) @@ -64,15 +62,8 @@ list(FILTER SOURCES EXCLUDE REGEX ".*(frontend/(onnx|tensorflow|paddle|pytorch)) pybind11_add_module(${PROJECT_NAME} MODULE NO_EXTRAS ${SOURCES}) -if(TARGET offline_transformations) - set(OFFLINE_TRANSFORMATIONS_LIB offline_transformations) -else() - set(OFFLINE_TRANSFORMATIONS_LIB openvino::offline_transformations) -endif() - target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..") -target_link_libraries(${PROJECT_NAME} PRIVATE - openvino::runtime::dev openvino::runtime ${OFFLINE_TRANSFORMATIONS_LIB}) +target_link_libraries(${PROJECT_NAME} PRIVATE openvino::core::dev openvino::runtime openvino::offline_transformations) set_target_properties(${PROJECT_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO} OUTPUT_NAME "_pyopenvino") @@ -96,51 +87,56 @@ if(OV_GENERATOR_MULTI_CONFIG) endif() # perform copy -if(OpenVINO_SOURCE_DIR) - add_custom_command(TARGET ${PROJECT_NAME} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory ${OpenVINOPython_SOURCE_DIR}/src/openvino ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} - COMMAND ${CMAKE_COMMAND} -E copy ${OpenVINOPython_SOURCE_DIR}/requirements.txt ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/../requirements.txt - ) -endif() - -if(OpenVINO_SOURCE_DIR OR OpenVINODeveloperPackage_FOUND) - ov_python_minimal_api(${PROJECT_NAME}) - ov_add_clang_format_target(${PROJECT_NAME}_clang FOR_TARGETS ${PROJECT_NAME}) - - ov_cpack_add_component(${OV_CPACK_COMP_PYTHON_OPENVINO}_${pyversion} - HIDDEN) - - install(DIRECTORY ${OpenVINOPython_SOURCE_DIR}/src/openvino - DESTINATION ${OV_CPACK_PYTHONDIR} - COMPONENT ${OV_CPACK_COMP_PYTHON_OPENVINO}_${pyversion} - ${OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL} - USE_SOURCE_PERMISSIONS - PATTERN "test_utils" EXCLUDE - PATTERN "torchvision/requirements.txt" EXCLUDE) - - install(TARGETS ${PROJECT_NAME} - DESTINATION ${OV_CPACK_PYTHONDIR}/openvino - COMPONENT ${OV_CPACK_COMP_PYTHON_OPENVINO}_${pyversion} - ${OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL}) - - ov_cpack_add_component(${OV_CPACK_COMP_OPENVINO_REQ_FILES} HIDDEN) - - install(FILES ${OpenVINOPython_SOURCE_DIR}/requirements.txt - DESTINATION ${OV_CPACK_PYTHONDIR} - COMPONENT ${OV_CPACK_COMP_OPENVINO_REQ_FILES} - ${OV_CPACK_COMP_OPENVINO_REQ_FILES_EXCLUDE_ALL}) - - install(FILES ${OpenVINOPython_SOURCE_DIR}/src/openvino/preprocess/torchvision/requirements.txt - DESTINATION ${OV_CPACK_PYTHONDIR}/openvino/preprocess/torchvision - COMPONENT ${OV_CPACK_COMP_OPENVINO_REQ_FILES} - ${OV_CPACK_COMP_OPENVINO_REQ_FILES_EXCLUDE_ALL}) - - install(DIRECTORY ${OpenVINOPython_SOURCE_DIR}/tests - DESTINATION tests/${PROJECT_NAME} - COMPONENT tests - EXCLUDE_FROM_ALL) -endif() +add_custom_command(TARGET ${PROJECT_NAME} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ${OpenVINOPython_SOURCE_DIR}/src/openvino ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + COMMAND ${CMAKE_COMMAND} -E copy ${OpenVINOPython_SOURCE_DIR}/requirements.txt ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/../requirements.txt + ) + +ov_python_minimal_api(${PROJECT_NAME}) +ov_add_clang_format_target(${PROJECT_NAME}_clang FOR_TARGETS ${PROJECT_NAME}) + +# install steps + +ov_cpack_add_component(${OV_CPACK_COMP_PYTHON_OPENVINO}_${pyversion} + HIDDEN) + +install(DIRECTORY ${OpenVINOPython_SOURCE_DIR}/src/openvino + DESTINATION ${OV_CPACK_PYTHONDIR} + COMPONENT ${OV_CPACK_COMP_PYTHON_OPENVINO}_${pyversion} + ${OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL} + USE_SOURCE_PERMISSIONS + PATTERN "test_utils" EXCLUDE + PATTERN "torchvision/requirements.txt" EXCLUDE) + +install(TARGETS ${PROJECT_NAME} + DESTINATION ${OV_CPACK_PYTHONDIR}/openvino + COMPONENT ${OV_CPACK_COMP_PYTHON_OPENVINO}_${pyversion} + ${OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL}) + +ov_set_apple_rpath(${PROJECT_NAME} ${OV_CPACK_PYTHONDIR}/openvino + # path to OpenVINO C++ libraries + ${OV_CPACK_RUNTIMEDIR} + # pyopenvino also depends on TBB because of: + # pyopenvino => openvino::offline_transformations => TBB optimized openvino::reference + ${TBB_LIB_INSTALL_DIR}) + +ov_cpack_add_component(${OV_CPACK_COMP_OPENVINO_REQ_FILES} HIDDEN) + +install(FILES ${OpenVINOPython_SOURCE_DIR}/requirements.txt + DESTINATION ${OV_CPACK_PYTHONDIR} + COMPONENT ${OV_CPACK_COMP_OPENVINO_REQ_FILES} + ${OV_CPACK_COMP_OPENVINO_REQ_FILES_EXCLUDE_ALL}) + +install(FILES ${OpenVINOPython_SOURCE_DIR}/src/openvino/preprocess/torchvision/requirements.txt + DESTINATION ${OV_CPACK_PYTHONDIR}/openvino/preprocess/torchvision + COMPONENT ${OV_CPACK_COMP_OPENVINO_REQ_FILES} + ${OV_CPACK_COMP_OPENVINO_REQ_FILES_EXCLUDE_ALL}) + +install(DIRECTORY ${OpenVINOPython_SOURCE_DIR}/tests + DESTINATION tests/${PROJECT_NAME} + COMPONENT tests + EXCLUDE_FROM_ALL) if(TARGET ie_wheel) add_dependencies(ie_wheel ${PROJECT_NAME}) diff --git a/src/bindings/python/src/pyopenvino/core/async_infer_queue.cpp b/src/bindings/python/src/pyopenvino/core/async_infer_queue.cpp index 91da7a810e4951..188cbe263edf30 100644 --- a/src/bindings/python/src/pyopenvino/core/async_infer_queue.cpp +++ b/src/bindings/python/src/pyopenvino/core/async_infer_queue.cpp @@ -3,7 +3,6 @@ #include "pyopenvino/core/async_infer_queue.hpp" -#include #include #include diff --git a/src/bindings/python/src/pyopenvino/core/common.cpp b/src/bindings/python/src/pyopenvino/core/common.cpp index b78d3ea4c37bff..7b473929a63396 100644 --- a/src/bindings/python/src/pyopenvino/core/common.cpp +++ b/src/bindings/python/src/pyopenvino/core/common.cpp @@ -8,6 +8,7 @@ #include "Python.h" #include "openvino/core/except.hpp" +#include "openvino/runtime/shared_buffer.hpp" #include "openvino/util/common_util.hpp" #define C_CONTIGUOUS py::detail::npy_api::constants::NPY_ARRAY_C_CONTIGUOUS_ @@ -170,13 +171,12 @@ ov::op::v0::Constant create_copied(ov::Tensor& tensor) { return ov::op::v0::Constant(tensor.get_element_type(), tensor.get_shape(), const_cast(tensor.data())); } -OPENVINO_SUPPRESS_DEPRECATED_START template <> ov::op::v0::Constant create_shared(py::array& array) { // Check if passed array has C-style contiguous memory layout. // If memory is going to be shared it needs to be contiguous before passing to the constructor. if (array_helpers::is_contiguous(array)) { - auto memory = std::make_shared>( + auto memory = std::make_shared>( static_cast(array.ndim() == 0 ? array.mutable_data() : array.mutable_data(0)), array.ndim() == 0 ? array.itemsize() : array.nbytes(), array); @@ -185,7 +185,6 @@ ov::op::v0::Constant create_shared(py::array& array) { // If passed array is not C-style, throw an error. OPENVINO_THROW("SHARED MEMORY MODE FOR THIS CONSTANT IS NOT APPLICABLE! Passed numpy array must be C contiguous."); } -OPENVINO_SUPPRESS_DEPRECATED_END template <> ov::op::v0::Constant create_shared(ov::Tensor& tensor) { diff --git a/src/bindings/python/src/pyopenvino/core/common.hpp b/src/bindings/python/src/pyopenvino/core/common.hpp index 0430470310af61..187f0d87ce5a15 100644 --- a/src/bindings/python/src/pyopenvino/core/common.hpp +++ b/src/bindings/python/src/pyopenvino/core/common.hpp @@ -9,13 +9,12 @@ #include #include -#include -#include #include #include #include #include "Python.h" +#include "openvino/core/type/element_type.hpp" #include "openvino/runtime/compiled_model.hpp" #include "openvino/runtime/infer_request.hpp" #include "openvino/runtime/tensor.hpp" diff --git a/src/bindings/python/src/pyopenvino/core/core.cpp b/src/bindings/python/src/pyopenvino/core/core.cpp index db04ee5bb76d52..734d8ea1ef9ad9 100644 --- a/src/bindings/python/src/pyopenvino/core/core.cpp +++ b/src/bindings/python/src/pyopenvino/core/core.cpp @@ -4,7 +4,6 @@ #include "pyopenvino/core/core.hpp" -#include #include #include diff --git a/src/bindings/python/src/pyopenvino/core/infer_request.cpp b/src/bindings/python/src/pyopenvino/core/infer_request.cpp index 6b087ecaa20cd1..71e73e4dff3720 100644 --- a/src/bindings/python/src/pyopenvino/core/infer_request.cpp +++ b/src/bindings/python/src/pyopenvino/core/infer_request.cpp @@ -3,7 +3,6 @@ #include "pyopenvino/core/infer_request.hpp" -#include #include #include #include diff --git a/src/bindings/python/src/pyopenvino/core/offline_transformations.cpp b/src/bindings/python/src/pyopenvino/core/offline_transformations.cpp index 17a879c72b5244..215a65da3165b0 100644 --- a/src/bindings/python/src/pyopenvino/core/offline_transformations.cpp +++ b/src/bindings/python/src/pyopenvino/core/offline_transformations.cpp @@ -109,7 +109,6 @@ void regmodule_offline_transformations(py::module m) { [](std::shared_ptr model) { ov::pass::Manager manager; manager.register_pass(); - manager.register_pass(); manager.run_passes(model); }, py::arg("model")); diff --git a/src/bindings/python/src/pyopenvino/frontend/frontend_module.cmake b/src/bindings/python/src/pyopenvino/frontend/frontend_module.cmake index f4220bde3aa6ab..5e7a1f2d426288 100644 --- a/src/bindings/python/src/pyopenvino/frontend/frontend_module.cmake +++ b/src/bindings/python/src/pyopenvino/frontend/frontend_module.cmake @@ -25,7 +25,7 @@ function(frontend_module TARGET FRAMEWORK INSTALL_COMPONENT) target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" "${OpenVINOPython_SOURCE_DIR}/src/pyopenvino/utils/") - target_link_libraries(${TARGET_NAME} PRIVATE openvino::runtime openvino::runtime::dev openvino::frontend::${FRAMEWORK}) + target_link_libraries(${TARGET_NAME} PRIVATE openvino::runtime openvino::core::dev openvino::frontend::${FRAMEWORK}) set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO}) @@ -39,8 +39,11 @@ function(frontend_module TARGET FRAMEWORK INSTALL_COMPONENT) COMMAND ${CMAKE_COMMAND} -E copy ${OpenVINOPython_SOURCE_DIR}/src/openvino/frontend/${FRAMEWORK}/__init__.py ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/__init__.py) + set(frontend_install_path ${OV_CPACK_PYTHONDIR}/openvino/frontend/${FRAMEWORK}) install(TARGETS ${TARGET_NAME} - DESTINATION ${OV_CPACK_PYTHONDIR}/openvino/frontend/${FRAMEWORK} + DESTINATION ${frontend_install_path} COMPONENT ${INSTALL_COMPONENT} ${OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL}) + + ov_set_apple_rpath(${TARGET_NAME} ${frontend_install_path} ${OV_CPACK_RUNTIMEDIR}) endfunction() diff --git a/src/bindings/python/src/pyopenvino/frontend/pytorch/decoder.hpp b/src/bindings/python/src/pyopenvino/frontend/pytorch/decoder.hpp index a1136e4cda6f66..024b03b2ff4cd9 100644 --- a/src/bindings/python/src/pyopenvino/frontend/pytorch/decoder.hpp +++ b/src/bindings/python/src/pyopenvino/frontend/pytorch/decoder.hpp @@ -34,6 +34,10 @@ class PyDecoder : public ov::frontend::pytorch::TorchDecoder { PYBIND11_OVERRIDE_PURE(ov::PartialShape, TorchDecoder, get_input_shape, index); } + const std::vector& get_input_strides(size_t index) const override { + PYBIND11_OVERRIDE_PURE(const std::vector&, TorchDecoder, get_input_strides, index); + } + ov::Any get_input_type(size_t index) const override { PYBIND11_OVERRIDE_PURE(ov::Any, TorchDecoder, get_input_type, index); } diff --git a/src/bindings/python/src/pyopenvino/graph/node_factory.cpp b/src/bindings/python/src/pyopenvino/graph/node_factory.cpp index 5c274d1bf3f6bd..7dde2d53b7b89f 100644 --- a/src/bindings/python/src/pyopenvino/graph/node_factory.cpp +++ b/src/bindings/python/src/pyopenvino/graph/node_factory.cpp @@ -17,7 +17,6 @@ #include #include "dict_attribute_visitor.hpp" -#include "ngraph/check.hpp" #include "openvino/core/except.hpp" #include "openvino/core/node.hpp" #include "openvino/core/op_extension.hpp" diff --git a/src/bindings/python/tests/test_graph/test_multinomial.py b/src/bindings/python/tests/test_graph/test_multinomial.py new file mode 100644 index 00000000000000..a1275837cc39d8 --- /dev/null +++ b/src/bindings/python/tests/test_graph/test_multinomial.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np +import pytest + +import openvino.runtime.opset13 as ops +from openvino.runtime import PartialShape, Dimension, Type + + +@pytest.mark.parametrize( + ("probs_shape", "num_samples_shape", "convert_type", "with_replacement", "log_probs", "global_seed", "op_seed", "expected_out_shape"), + [ + ([4, 16], [], "i32", False, True, 7461, 1546, PartialShape([4, -1])), + ([8], [1], "i64", True, False, 0, 0, PartialShape([-1])), + ], +) +def test_multinomial_param_inputs(probs_shape, num_samples_shape, convert_type, with_replacement, log_probs, global_seed, op_seed, expected_out_shape): + probs = ops.parameter(probs_shape, dtype=np.float32) + num_samples = ops.parameter(num_samples_shape, dtype=np.int32) + + op = ops.multinomial(probs, num_samples, + convert_type=convert_type, + with_replacement=with_replacement, + log_probs=log_probs, + global_seed=global_seed, + op_seed=op_seed) + assert op.get_output_size() == 1 + assert op.get_type_name() == "Multinomial" + assert op.get_output_element_type(0) == Type.i32 if convert_type == "i32" else Type.i64 + assert op.get_output_partial_shape(0) == expected_out_shape + + +@pytest.mark.parametrize( + ("probs_array", "num_samples_val", "convert_type", "with_replacement", "log_probs", "global_seed", "op_seed", "expected_out_shape"), + [ + (np.array([0.7, 0.3, 0.6, 0.5]), 3, "i32", False, True, 111, 222, PartialShape([3])), + (np.array([[0.7, 0.3], [0.6, 0.5]]), 2, "i64", True, False, 111, 222, PartialShape([2, 2])), + ], +) +def test_multinomial_const_inputs(probs_array, num_samples_val, convert_type, with_replacement, log_probs, global_seed, op_seed, expected_out_shape): + probs = ops.constant(probs_array, dtype=np.float32) + num_samples = ops.constant(num_samples_val, dtype=np.int32) + + op = ops.multinomial(probs, num_samples, + convert_type=convert_type, + with_replacement=with_replacement, + log_probs=log_probs, + global_seed=global_seed, + op_seed=op_seed) + + assert op.get_output_size() == 1 + assert op.get_type_name() == "Multinomial" + assert op.get_output_element_type(0) == Type.i32 if convert_type == "i32" else Type.i64 + assert op.get_output_partial_shape(0) == expected_out_shape + + +@pytest.mark.parametrize( + ("probs_shape", "num_samples_shape", "convert_type", "with_replacement", "log_probs", "expected_out_shape"), + [ + ([10], [1], "i32", True, True, PartialShape([-1])), + ([2, 16], [], "i64", False, False, PartialShape([2, -1])), + ], +) +def test_multinomial_default_attrs(probs_shape, num_samples_shape, convert_type, with_replacement, log_probs, expected_out_shape): + probs = ops.parameter(probs_shape, dtype=np.float32) + num_samples = ops.parameter(num_samples_shape, dtype=np.int32) + + op = ops.multinomial(probs, num_samples, + convert_type=convert_type, + with_replacement=with_replacement, + log_probs=log_probs) + + assert op.get_output_size() == 1 + assert op.get_type_name() == "Multinomial" + assert op.get_output_element_type(0) == Type.i32 if convert_type == "i32" else Type.i64 + assert op.get_output_partial_shape(0) == expected_out_shape diff --git a/src/bindings/python/tests/test_graph/test_ops_binary.py b/src/bindings/python/tests/test_graph/test_ops_binary.py index c4c55da4731010..a7b7ff2bff63c4 100644 --- a/src/bindings/python/tests/test_graph/test_ops_binary.py +++ b/src/bindings/python/tests/test_graph/test_ops_binary.py @@ -8,7 +8,7 @@ import pytest from openvino.runtime import Type -import openvino.runtime.opset8 as ov +import openvino.runtime.opset13 as ov @pytest.mark.parametrize( @@ -183,3 +183,53 @@ def test_power_v1(): assert node.get_output_size() == 1 assert list(node.get_output_shape(0)) == [8, 4, 6, 5] assert node.get_output_element_type(0) == Type.f32 + + +@pytest.mark.parametrize( + "graph_api_helper", + [ov.bitwise_and, ov.bitwise_or, ov.bitwise_xor], +) +@pytest.mark.parametrize( + "dtype", + [bool, np.int32], +) +@pytest.mark.parametrize( + ("shape_a", "shape_b", "broadcast", "shape_out"), + [ + ([2, 2], [2, 2], "NONE", [2, 2]), + ([2, 1, 5], [1, 4, 5], "NUMPY", [2, 4, 5]), + ([3, 2, 1, 4], [5, 4], "NUMPY", [3, 2, 5, 4]), + ([2, 3, 4, 5], [], "PDPD", [2, 3, 4, 5]), + ([2, 3, 4, 5], [2, 3, 1, 5], "PDPD", [2, 3, 4, 5]), + ], +) +def test_binary_bitwise_op(graph_api_helper, dtype, shape_a, shape_b, broadcast, shape_out): + parameter_a = ov.parameter(shape_a, name="A", dtype=dtype) + parameter_b = ov.parameter(shape_b, name="B", dtype=dtype) + + model = graph_api_helper(parameter_a, parameter_b, broadcast) + + assert model.get_output_size() == 1 + assert list(model.get_output_shape(0)) == shape_out + assert model.get_output_element_type(0) == Type(dtype) + + +@pytest.mark.parametrize( + "graph_api_helper", + [ov.bitwise_and, ov.bitwise_or, ov.bitwise_xor], +) +@pytest.mark.parametrize( + "dtype", + [bool, np.int32], +) +def test_binary_bitwise_op_with_constant(graph_api_helper, dtype): + value_b = np.array([[3, 0], [-7, 21]], dtype=dtype) + + shape = [2, 2] + parameter_a = ov.parameter(shape, name="A", dtype=dtype) + + model = graph_api_helper(parameter_a, value_b) + + assert model.get_output_size() == 1 + assert list(model.get_output_shape(0)) == shape + assert model.get_output_element_type(0) == Type(dtype) diff --git a/src/bindings/python/tests/test_graph/test_ops_unary.py b/src/bindings/python/tests/test_graph/test_ops_unary.py index 745f9b6d9f7fd9..a01b800199e654 100644 --- a/src/bindings/python/tests/test_graph/test_ops_unary.py +++ b/src/bindings/python/tests/test_graph/test_ops_unary.py @@ -6,7 +6,7 @@ import pytest import openvino.runtime as ov_runtime -import openvino.runtime.opset10 as ov +import openvino.runtime.opset13 as ov from openvino.runtime import Shape, Type R_TOLERANCE = 1e-6 # global relative tolerance @@ -203,3 +203,21 @@ def test_gelu_tanh_operator_with_array(): assert model.get_type_name() == "Gelu" assert model.get_output_element_type(0) == ov_runtime.Type.f32 assert list(model.get_output_shape(0)) == [2, 2] + + +@pytest.mark.parametrize( + ("input_data", "dtype"), + [ + (np.array([True, False, True, False]), ov_runtime.Type.boolean), + (np.array([True]), ov_runtime.Type.boolean), + (np.array([False]), ov_runtime.Type.boolean), + (np.array([0, 3, 7, 256], dtype=np.uint16), ov_runtime.Type.u16), + (np.array([[-7, 0], [256, 1]], dtype=np.int32), ov_runtime.Type.i32), + ], +) +def test_bitwise_not(input_data, dtype): + node = ov.bitwise_not(input_data) + assert node.get_output_size() == 1 + assert node.get_type_name() == "BitwiseNot" + assert node.get_output_element_type(0) == dtype + assert list(node.get_output_shape(0)) == list(input_data.shape) diff --git a/src/bindings/python/tests_compatibility/test_onnx/test_onnx_external_data.py b/src/bindings/python/tests_compatibility/test_onnx/test_onnx_external_data.py index ec8f6c49e7ffb6..025c438fedf5d2 100644 --- a/src/bindings/python/tests_compatibility/test_onnx/test_onnx_external_data.py +++ b/src/bindings/python/tests_compatibility/test_onnx/test_onnx_external_data.py @@ -1,15 +1,19 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform import os import numpy as np import ngraph as ng +import pytest from openvino.inference_engine import IECore from tests_compatibility.runtime import get_runtime +@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122712') def test_import_onnx_with_external_data(): model_path = os.path.join(os.path.dirname(__file__), "models/external_data.onnx") ie = IECore() diff --git a/src/bindings/python/tests_compatibility/test_onnx/test_ops_nonlinear.py b/src/bindings/python/tests_compatibility/test_onnx/test_ops_nonlinear.py index 60ab593d097250..7b1ebc7295ce96 100644 --- a/src/bindings/python/tests_compatibility/test_onnx/test_ops_nonlinear.py +++ b/src/bindings/python/tests_compatibility/test_onnx/test_ops_nonlinear.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import onnx import pytest @@ -45,6 +47,8 @@ def relu(x): assert_onnx_import_equals_callable("Relu", relu, [[-3, -2, -1], [1, 2, 3]]) +@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122712') def test_leaky_relu(): def leaky_relu(x, alpha=0.01): return np.maximum(alpha * x, x) @@ -79,6 +83,8 @@ def parametic_relu(x, slope): assert np.allclose(output, expected_output) +@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122712') def test_selu(): # f(x) = gamma * (alpha * exp(x) - alpha) for x <= 0, y = gamma * x for x > 0 def selu(x, alpha=1.67326319217681884765625, gamma=1.05070102214813232421875): diff --git a/src/bindings/python/tests_compatibility/test_onnx/test_ops_unary.py b/src/bindings/python/tests_compatibility/test_onnx/test_ops_unary.py index ddbd8dd53e4a4a..ad7b8e8ffbaf85 100644 --- a/src/bindings/python/tests_compatibility/test_onnx/test_ops_unary.py +++ b/src/bindings/python/tests_compatibility/test_onnx/test_ops_unary.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import onnx import onnx.mapping @@ -210,6 +212,8 @@ def hardmax_2d(data): assert np.allclose(ng_results, [expected]) +@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122712') def test_hardsigmoid(): def hardsigmoid(data, alpha=0.2, beta=0.5): return np.clip(alpha * data + beta, 0, 1) @@ -447,6 +451,8 @@ def test_cast_errors(): @pytest.mark.parametrize("value_type", [pytest.param(np.float64), pytest.param(np.float32)]) +@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122712') def test_constant(value_type): values = np.random.randn(5, 5).astype(value_type) node = onnx.helper.make_node( diff --git a/src/cmake/install_tbb.cmake b/src/cmake/install_tbb.cmake index d5e3e7037ed3f9..a5f7bd19c5856c 100644 --- a/src/cmake/install_tbb.cmake +++ b/src/cmake/install_tbb.cmake @@ -67,13 +67,13 @@ unset(_ov_dynamic_tbbbind_2_5_found) # define variables for OpenVINOConfig.cmake if(THREADING MATCHES "^(TBB|TBB_AUTO)$") - set(IE_TBB_DIR "${TBB_DIR}") - list(APPEND PATH_VARS "IE_TBB_DIR") + set(OV_TBB_DIR "${TBB_DIR}") + list(APPEND PATH_VARS "OV_TBB_DIR") endif() if(install_tbbbind) - set(IE_TBBBIND_DIR "${TBBBIND_2_5_DIR}") - list(APPEND PATH_VARS "IE_TBBBIND_DIR") + set(OV_TBBBIND_DIR "${TBBBIND_2_5_DIR}") + list(APPEND PATH_VARS "OV_TBBBIND_DIR") endif() # install only downloaded | custom TBB, system one is not installed @@ -128,7 +128,7 @@ if(THREADING MATCHES "^(TBB|TBB_AUTO)$" AND endforeach() endforeach() - set(pkg_config_tbb_lib_dir "runtime/3rdparty/tbb/lib") + set(TBB_LIB_INSTALL_DIR "runtime/3rdparty/tbb/lib" CACHE PATH "TBB library install directory" FORCE) elseif(tbb_custom) # for custom TBB we need to install it to our package # to simplify life for our customers @@ -150,14 +150,14 @@ if(THREADING MATCHES "^(TBB|TBB_AUTO)$" AND endif() if(TBB_DIR MATCHES "^${TBBROOT}.*") - file(RELATIVE_PATH IE_TBB_DIR_INSTALL "${TBBROOT}" "${TBB_DIR}") - set(IE_TBB_DIR_INSTALL "${IE_TBBROOT_INSTALL}/${IE_TBB_DIR_INSTALL}") + file(RELATIVE_PATH OV_TBB_DIR_INSTALL "${TBBROOT}" "${TBB_DIR}") + set(OV_TBB_DIR_INSTALL "${IE_TBBROOT_INSTALL}/${OV_TBB_DIR_INSTALL}") else() # TBB_DIR is not a subdirectory of TBBROOT # example: old TBB 2017 with no cmake support at all # - TBBROOT point to actual root of TBB # - TBB_DIR points to cmake/developer_package/tbb/ - set(IE_TBB_DIR_INSTALL "${TBB_DIR}") + set(OV_TBB_DIR_INSTALL "${TBB_DIR}") endif() # try to select proper library directory @@ -183,23 +183,23 @@ if(THREADING MATCHES "^(TBB|TBB_AUTO)$" AND endif() endforeach() - set(pkg_config_tbb_lib_dir "${IE_TBBROOT_INSTALL}/${tbb_libs_dir}") + set(TBB_LIB_INSTALL_DIR "${IE_TBBROOT_INSTALL}/${tbb_libs_dir}" CACHE PATH "TBB library install directory" FORCE) elseif(tbb_downloaded) - set(IE_TBB_DIR_INSTALL "runtime/3rdparty/tbb") + set(OV_TBB_DIR_INSTALL "runtime/3rdparty/tbb") if(WIN32) install(DIRECTORY "${TBBROOT}/bin" - DESTINATION "${IE_TBB_DIR_INSTALL}" + DESTINATION "${OV_TBB_DIR_INSTALL}" COMPONENT tbb) else() install(DIRECTORY "${TBBROOT}/lib" - DESTINATION "${IE_TBB_DIR_INSTALL}" + DESTINATION "${OV_TBB_DIR_INSTALL}" COMPONENT tbb PATTERN "cmake" EXCLUDE) endif() install(FILES "${TBBROOT}/LICENSE" - DESTINATION "${IE_TBB_DIR_INSTALL}" + DESTINATION "${OV_TBB_DIR_INSTALL}" COMPONENT tbb) # install development files @@ -212,49 +212,52 @@ if(THREADING MATCHES "^(TBB|TBB_AUTO)$" AND if(EXISTS "${TBBROOT}/lib/cmake") # oneTBB case install(DIRECTORY "${TBBROOT}/lib/cmake" - DESTINATION "${IE_TBB_DIR_INSTALL}/lib" + DESTINATION "${OV_TBB_DIR_INSTALL}/lib" COMPONENT tbb_dev) else() # tbb2020 case install(FILES "${TBBROOT}/cmake/TBBConfig.cmake" "${TBBROOT}/cmake/TBBConfigVersion.cmake" - DESTINATION "${IE_TBB_DIR_INSTALL}/cmake" + DESTINATION "${OV_TBB_DIR_INSTALL}/cmake" COMPONENT tbb_dev) endif() install(DIRECTORY "${TBBROOT}/include" - DESTINATION "${IE_TBB_DIR_INSTALL}" + DESTINATION "${OV_TBB_DIR_INSTALL}" COMPONENT tbb_dev) if(WIN32) # .lib files are needed only for Windows install(DIRECTORY "${TBBROOT}/lib" - DESTINATION "${IE_TBB_DIR_INSTALL}" + DESTINATION "${OV_TBB_DIR_INSTALL}" COMPONENT tbb_dev PATTERN "cmake" EXCLUDE) endif() - set(pkg_config_tbb_lib_dir "${IE_TBB_DIR_INSTALL}/lib") + set(TBB_LIB_INSTALL_DIR "${OV_TBB_DIR_INSTALL}/lib" CACHE PATH "TBB library install directory" FORCE) else() + unset(TBB_LIB_INSTALL_DIR CACHE) message(WARNING "TBB of unknown origin. TBB files are not installed") endif() unset(tbb_downloaded) unset(tbb_custom) +else() + unset(TBB_LIB_INSTALL_DIR CACHE) endif() # install tbbbind for static OpenVINO case if(install_tbbbind) - set(IE_TBBBIND_DIR_INSTALL "runtime/3rdparty/tbb_bind_2_5") + set(OV_TBBBIND_DIR_INSTALL "runtime/3rdparty/tbb_bind_2_5") install(DIRECTORY "${TBBBIND_2_5_ROOT}/lib" - DESTINATION "${IE_TBBBIND_DIR_INSTALL}" + DESTINATION "${OV_TBBBIND_DIR_INSTALL}" COMPONENT tbb) install(FILES "${TBBBIND_2_5_ROOT}/LICENSE" - DESTINATION "${IE_TBBBIND_DIR_INSTALL}" + DESTINATION "${OV_TBBBIND_DIR_INSTALL}" COMPONENT tbb) install(FILES "${TBBBIND_2_5_ROOT}/cmake/TBBBIND_2_5Config.cmake" - DESTINATION "${IE_TBBBIND_DIR_INSTALL}/cmake" + DESTINATION "${OV_TBBBIND_DIR_INSTALL}/cmake" COMPONENT tbb_dev) endif() diff --git a/src/cmake/openvino.cmake b/src/cmake/openvino.cmake index 73df6bf480719d..7fb6e2fd77bd6b 100644 --- a/src/cmake/openvino.cmake +++ b/src/cmake/openvino.cmake @@ -72,6 +72,14 @@ endif() ov_set_threading_interface_for(${TARGET_NAME}) ov_mark_target_as_cc(${TARGET_NAME}) +if(TBB_FOUND) + if(NOT TBB_LIB_INSTALL_DIR) + message(FATAL_ERROR "Internal error: variable 'TBB_LIB_INSTALL_DIR' is not defined") + endif() + # set LC_RPATH to TBB library directory + ov_set_apple_rpath(${TARGET_NAME} ${OV_CPACK_RUNTIMEDIR} ${TBB_LIB_INSTALL_DIR}) +endif() + # must be called after all target_link_libraries ov_add_api_validator_post_build_step(TARGET ${TARGET_NAME} EXTRA ${TBB_IMPORTED_TARGETS}) @@ -96,29 +104,30 @@ install(TARGETS ${TARGET_NAME} EXPORT OpenVINOTargets # OpenVINO runtime library dev # -# Add openvin::dev target +# Add openvino::runtine::dev target # -add_library(${TARGET_NAME}_dev INTERFACE) -add_library(openvino::runtime::dev ALIAS ${TARGET_NAME}_dev) +add_library(openvino_runtime_dev INTERFACE) +add_library(openvino::runtime::dev ALIAS openvino_runtime_dev) -target_include_directories(${TARGET_NAME}_dev INTERFACE +target_include_directories(openvino_runtime_dev INTERFACE $ $ - $) + $>) -target_compile_definitions(${TARGET_NAME}_dev INTERFACE +target_compile_definitions(openvino_runtime_dev INTERFACE $) -target_link_libraries(${TARGET_NAME}_dev INTERFACE ${TARGET_NAME} openvino::core::dev) +target_link_libraries(openvino_runtime_dev INTERFACE ${TARGET_NAME} openvino::core::dev) -ov_set_threading_interface_for(${TARGET_NAME}_dev) -set_target_properties(${TARGET_NAME}_dev PROPERTIES EXPORT_NAME runtime::dev) +ov_set_threading_interface_for(openvino_runtime_dev) +set_target_properties(openvino_runtime_dev PROPERTIES EXPORT_NAME runtime::dev) -openvino_developer_export_targets(COMPONENT core TARGETS openvino::runtime::dev) +ov_developer_package_export_targets(TARGET openvino::runtime::dev + INSTALL_INCLUDE_DIRECTORIES "${OpenVINO_SOURCE_DIR}/src/inference/dev_api/") # Install static libraries for case BUILD_SHARED_LIBS=OFF -ov_install_static_lib(${TARGET_NAME}_dev ${OV_CPACK_COMP_CORE}) +ov_install_static_lib(openvino_runtime_dev ${OV_CPACK_COMP_CORE}) # # Install OpenVINO runtime @@ -157,7 +166,7 @@ install(EXPORT OpenVINOTargets # build tree -list(APPEND PATH_VARS "IE_INCLUDE_DIR") +list(APPEND PATH_VARS "OV_INCLUDE_DIR") # TODO: remove obsolete variable for API 1.0 before 2024.0 if(ENABLE_INTEL_GNA) list(APPEND PATH_VARS "GNA_PATH") endif() @@ -170,8 +179,8 @@ if(ENABLE_ONEDNN_FOR_GPU) endif() set(PUBLIC_HEADERS_DIR "${OpenVINO_SOURCE_DIR}/src/inference/include") -set(IE_INCLUDE_DIR "${PUBLIC_HEADERS_DIR}/ie") -set(IE_TBB_DIR "${TBB_DIR}") +set(OV_INCLUDE_DIR "${PUBLIC_HEADERS_DIR}/ie") +set(OV_TBB_DIR "${TBB_DIR}") configure_package_config_file("${OpenVINO_SOURCE_DIR}/cmake/templates/InferenceEngineConfig.cmake.in" "${CMAKE_BINARY_DIR}/InferenceEngineConfig.cmake" @@ -190,9 +199,9 @@ list(APPEND INSTALL_PATH_VARS "OPENVINO_LIB_DIR") # will be done by inside OpenVINOConfig.cmak / ACLConfig.cmake string(REPLACE "$" "" OPENVINO_LIB_DIR "${OV_CPACK_LIBRARYDIR}") -set(IE_INCLUDE_DIR "${OV_CPACK_INCLUDEDIR}/ie") -set(IE_TBB_DIR "${IE_TBB_DIR_INSTALL}") -set(IE_TBBBIND_DIR "${IE_TBBBIND_DIR_INSTALL}") +set(OV_INCLUDE_DIR "${OV_CPACK_INCLUDEDIR}/ie") +set(OV_TBB_DIR "${OV_TBB_DIR_INSTALL}") +set(OV_TBBBIND_DIR "${OV_TBBBIND_DIR_INSTALL}") set(GNA_PATH "${OV_CPACK_RUNTIMEDIR}") if(WIN32) set(GNA_PATH "${OV_CPACK_LIBRARYDIR}/../Release") @@ -253,11 +262,11 @@ if(ENABLE_PKGCONFIG_GEN) if(ENABLE_SYSTEM_TBB) set(PKGCONFIG_OpenVINO_PRIVATE_DEPS "-ltbb") elseif(TBB_FOUND) - if(NOT pkg_config_tbb_lib_dir) - message(FATAL_ERROR "Internal error: variable 'pkg_config_tbb_lib_dir' is not defined") + if(NOT TBB_LIB_INSTALL_DIR) + message(FATAL_ERROR "Internal error: variable 'TBB_LIB_INSTALL_DIR' is not defined") endif() - set(PKGCONFIG_OpenVINO_PRIVATE_DEPS "-L\${prefix}/${pkg_config_tbb_lib_dir} -ltbb") + set(PKGCONFIG_OpenVINO_PRIVATE_DEPS "-L\${prefix}/${TBB_LIB_INSTALL_DIR} -ltbb") endif() if(ENABLE_SYSTEM_PUGIXML) diff --git a/src/cmake/ov_parallel.cmake b/src/cmake/ov_parallel.cmake index f669b7b1562d9e..510b207689add7 100644 --- a/src/cmake/ov_parallel.cmake +++ b/src/cmake/ov_parallel.cmake @@ -170,7 +170,7 @@ macro(ov_find_package_tbb) # fallback variant for TBB 2018 and older where TBB have not had cmake interface if(DEFINED TBBROOT OR DEFINED ENV{TBBROOT}) # note: if TBB older than 2017.0 is passed, cmake will skip it and THREADING=SEQ will be used - set(_tbb_paths PATHS "${IEDevScripts_DIR}/tbb") + set(_tbb_paths PATHS "${OpenVINODeveloperScripts_DIR}/tbb") endif() # try to find one more time @@ -261,25 +261,23 @@ function(ov_set_threading_interface_for TARGET_NAME) if(target_type STREQUAL "INTERFACE_LIBRARY") set(LINK_TYPE "INTERFACE") set(COMPILE_DEF_TYPE "INTERFACE") - elseif(target_type STREQUAL "EXECUTABLE" OR target_type STREQUAL "OBJECT_LIBRARY" OR - target_type STREQUAL "MODULE_LIBRARY") + elseif(target_type MATCHES "^(EXECUTABLE|OBJECT_LIBRARY|MODULE_LIBRARY)$") set(LINK_TYPE "PRIVATE") - set(COMPILE_DEF_TYPE "PUBLIC") + set(COMPILE_DEF_TYPE "PRIVATE") elseif(target_type STREQUAL "STATIC_LIBRARY") # Affected libraries: inference_engine_s, openvino_gapi_preproc_s # they don't have TBB in public headers => PRIVATE set(LINK_TYPE "PRIVATE") set(COMPILE_DEF_TYPE "PUBLIC") elseif(target_type STREQUAL "SHARED_LIBRARY") - # Affected libraries: inference_engine only - # TODO: why TBB propogates its headers to inference_engine? + # Affected libraries: 'openvino' only set(LINK_TYPE "PRIVATE") set(COMPILE_DEF_TYPE "PUBLIC") else() message(WARNING "Unknown target type") endif() - function(ie_target_link_libraries TARGET_NAME LINK_TYPE) + function(_ov_target_link_libraries TARGET_NAME LINK_TYPE) target_link_libraries(${TARGET_NAME} ${LINK_TYPE} ${ARGN}) # include directories as SYSTEM @@ -314,7 +312,7 @@ function(ov_set_threading_interface_for TARGET_NAME) if (TBB_FOUND) set(IE_THREAD_DEFINE "IE_THREAD_TBB") set(OV_THREAD_DEFINE "OV_THREAD_TBB") - ie_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} TBB::tbb) + _ov_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} TBB::tbb) target_compile_definitions(${TARGET_NAME} ${COMPILE_DEF_TYPE} TBB_PREVIEW_WAITING_FOR_WORKERS=1) else () set(THREADING "SEQ" PARENT_SCOPE) @@ -365,7 +363,7 @@ function(ov_set_threading_interface_for TARGET_NAME) if (WIN32) target_compile_options(${TARGET_NAME} ${LINK_TYPE} ${OpenMP_CXX_FLAGS} /openmp) target_compile_options(${TARGET_NAME} ${LINK_TYPE} ${OpenMP_CXX_FLAGS} /Qopenmp) - ie_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} "-nodefaultlib:vcomp") + _ov_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} "-nodefaultlib:vcomp") else() target_compile_options(${TARGET_NAME} ${LINK_TYPE} ${OpenMP_CXX_FLAGS} -fopenmp) endif () @@ -373,18 +371,18 @@ function(ov_set_threading_interface_for TARGET_NAME) # Debug binaries are optional. if (OMP_LIBRARIES_DEBUG AND NOT LINUX) if (WIN32) - ie_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} "$<$:${OMP_LIBRARIES_DEBUG}>;$<$>:${OMP_LIBRARIES_RELEASE}>") + _ov_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} "$<$:${OMP_LIBRARIES_DEBUG}>;$<$>:${OMP_LIBRARIES_RELEASE}>") else() # TODO: handle multi-config generators case if (CMAKE_BUILD_TYPE STREQUAL "Debug") - ie_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} ${OMP_LIBRARIES_DEBUG}) + _ov_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} ${OMP_LIBRARIES_DEBUG}) else() - ie_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} ${OMP_LIBRARIES_RELEASE}) + _ov_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} ${OMP_LIBRARIES_RELEASE}) endif () endif () else () # Link Release library to all configurations. - ie_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} ${OMP_LIBRARIES_RELEASE}) + _ov_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} ${OMP_LIBRARIES_RELEASE}) endif () endif () endif () @@ -394,11 +392,13 @@ function(ov_set_threading_interface_for TARGET_NAME) if (NOT THREADING STREQUAL "SEQ") find_package(Threads REQUIRED) - ie_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} Threads::Threads) + _ov_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} Threads::Threads) endif() endfunction(ov_set_threading_interface_for) +# deprecated + function(set_ie_threading_interface_for TARGET_NAME) - message(WARNING "This function is deprecated. Please use ov_set_threading_interface_for(TARGET_NAME) instead.") + message(WARNING "'set_ie_threading_interface_for' is deprecated. Please use 'ov_set_threading_interface_for' instead.") ov_set_threading_interface_for(${TARGET_NAME}) endfunction(set_ie_threading_interface_for) diff --git a/src/common/conditional_compilation/CMakeLists.txt b/src/common/conditional_compilation/CMakeLists.txt index 876558cea5e474..8f5cd90fe22d21 100644 --- a/src/common/conditional_compilation/CMakeLists.txt +++ b/src/common/conditional_compilation/CMakeLists.txt @@ -2,11 +2,12 @@ # SPDX-License-Identifier: Apache-2.0 # -set(TARGET_NAME conditional_compilation) +set(TARGET_NAME openvino_conditional_compilation) add_library(${TARGET_NAME} INTERFACE) add_library(openvino::conditional_compilation ALIAS ${TARGET_NAME}) +set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME conditional_compilation) target_link_libraries(${TARGET_NAME} INTERFACE openvino::itt) @@ -23,9 +24,7 @@ elseif(SELECTIVE_BUILD STREQUAL "ON") find_host_package (Python3 REQUIRED COMPONENTS Interpreter) file(TO_CMAKE_PATH ${SELECTIVE_BUILD_STAT} CMAKE_SELECTIVE_BUILD_STAT) - file(GLOB STAT_FILES ${CMAKE_SELECTIVE_BUILD_STAT}) - if(NOT STAT_FILES) message(FATAL_ERROR "SELECTIVE_BUILD_STAT (${SELECTIVE_BUILD_STAT}) path doesn't contain valid csv files!") endif() @@ -56,12 +55,16 @@ elseif(SELECTIVE_BUILD STREQUAL "ON") ov_force_include(${TARGET_NAME} INTERFACE ${GENERATED_HEADER}) endif() -ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE}) - file(GLOB_RECURSE hdrs ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp) ov_add_clang_format_target(${TARGET_NAME}_clang FOR_SOURCES ${hdrs}) -openvino_developer_export_targets(COMPONENT openvino_common TARGETS openvino::conditional_compilation) if(ENABLE_TESTS) add_subdirectory(tests) endif() + +# install & export + +ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE}) + +ov_developer_package_export_targets(TARGET openvino::conditional_compilation + INSTALL_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include/") diff --git a/src/common/itt/CMakeLists.txt b/src/common/itt/CMakeLists.txt index 512574fd89bc06..4541fa112755a7 100644 --- a/src/common/itt/CMakeLists.txt +++ b/src/common/itt/CMakeLists.txt @@ -36,7 +36,11 @@ endif() target_include_directories(${TARGET_NAME} PUBLIC $) +ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}) + +# install & export + ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE}) -ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}) -openvino_developer_export_targets(COMPONENT openvino_common TARGETS openvino::itt) +ov_developer_package_export_targets(TARGET openvino::itt + INSTALL_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include/") diff --git a/src/common/low_precision_transformations/include/itt.hpp b/src/common/low_precision_transformations/include/itt.hpp index 37e01b9cfc4162..f9388c2facc557 100644 --- a/src/common/low_precision_transformations/include/itt.hpp +++ b/src/common/low_precision_transformations/include/itt.hpp @@ -23,12 +23,12 @@ namespace domains { } // namespace itt } // namespace low_precision } // namespace pass -} // namespace ngraph +} // namespace ov /* * RUN_ON_FUNCTION_SCOPE macro allows to disable the run_on_function pass * MATCHER_SCOPE macro allows to disable the MatcherPass if matcher isn't applied - * INTERNAL_OP_SCOPE macro allows to disable parts of internal nGraph operations if they are not used + * INTERNAL_OP_SCOPE macro allows to disable parts of internal openvino operations if they are not used */ #if defined(SELECTIVE_BUILD_ANALYZER) diff --git a/src/common/low_precision_transformations/include/low_precision/network_helper.hpp b/src/common/low_precision_transformations/include/low_precision/network_helper.hpp index d3c5a04d14df6d..83e486af697ff7 100644 --- a/src/common/low_precision_transformations/include/low_precision/network_helper.hpp +++ b/src/common/low_precision_transformations/include/low_precision/network_helper.hpp @@ -29,7 +29,7 @@ namespace pass { namespace low_precision { /** -* @brief NetworkHelper class encapsulates manipulations with nGraph function. +* @brief NetworkHelper class encapsulates manipulations with ov::Model. */ class LP_TRANSFORMATIONS_API NetworkHelper { public: diff --git a/src/common/low_precision_transformations/src/batch_to_space.cpp b/src/common/low_precision_transformations/src/batch_to_space.cpp index b136d284ed5902..cc80f95707eb70 100644 --- a/src/common/low_precision_transformations/src/batch_to_space.cpp +++ b/src/common/low_precision_transformations/src/batch_to_space.cpp @@ -5,10 +5,9 @@ #include "low_precision/batch_to_space.hpp" #include -#include -#include -#include +#include "openvino/op/batch_to_space.hpp" +#include "openvino/pass/pattern/op/wrap_type.hpp" #include "low_precision/network_helper.hpp" #include "itt.hpp" @@ -20,7 +19,7 @@ BatchToSpaceTransformation::BatchToSpaceTransformation(const Params& params) : L MATCHER_SCOPE(BatchToSpaceTransformation); auto matcher = pattern::wrap_type(); - ngraph::graph_rewrite_callback callback = [this](pattern::Matcher& m) { + ov::graph_rewrite_callback callback = [this](pattern::Matcher& m) { auto op = m.get_match_root(); if (transformation_callback(op)) { return false; @@ -28,7 +27,7 @@ BatchToSpaceTransformation::BatchToSpaceTransformation(const Params& params) : L return transform(*context, m); }; - auto m = std::make_shared(matcher, matcher_name); + auto m = std::make_shared(matcher, matcher_name); this->register_matcher(m, callback); } @@ -45,7 +44,7 @@ bool BatchToSpaceTransformation::canBeTransformed(const TransformationContext& c return dequantization.isPerTensor(); } -bool BatchToSpaceTransformation::transform(TransformationContext& context, ngraph::pattern::Matcher& m) { +bool BatchToSpaceTransformation::transform(TransformationContext& context, ov::pass::pattern::Matcher& m) { if (!canBeTransformed(context, m.get_match_root())) { return false; } diff --git a/src/common/low_precision_transformations/src/network_helper.cpp b/src/common/low_precision_transformations/src/network_helper.cpp index 29d7c9670bb362..b3925c850c5673 100644 --- a/src/common/low_precision_transformations/src/network_helper.cpp +++ b/src/common/low_precision_transformations/src/network_helper.cpp @@ -195,7 +195,7 @@ size_t NetworkHelper::getGroupsCount(std::shared_ptr layer) { } void NetworkHelper::removeLayer(std::shared_ptr layer) { - ngraph::replace_output_update_name(layer->output(0), layer->input_value(0)); + ov::replace_output_update_name(layer->output(0), layer->input_value(0)); } std::shared_ptr NetworkHelper::swapMultiplyAndAdd(std::shared_ptr addAfterMultiply, const int multiplyBranch) { diff --git a/src/common/low_precision_transformations/src/reshape.cpp b/src/common/low_precision_transformations/src/reshape.cpp index 487139077f5c69..0c5f83502df4e8 100644 --- a/src/common/low_precision_transformations/src/reshape.cpp +++ b/src/common/low_precision_transformations/src/reshape.cpp @@ -200,7 +200,7 @@ bool ReshapeTransformation::canBeTransformed(const TransformationContext& contex const auto inputs = op->get_output_target_inputs(0); if (inputs.size() == 1ul) { const auto consumer = inputs.begin()->get_node(); - ignorePerTensorQuantizationCheck = ngraph::as_type(consumer) != nullptr; + ignorePerTensorQuantizationCheck = ov::as_type(consumer) != nullptr; } } diff --git a/src/common/low_precision_transformations/src/space_to_batch.cpp b/src/common/low_precision_transformations/src/space_to_batch.cpp index 0c9200a2f061eb..75bf0f9dbbc559 100644 --- a/src/common/low_precision_transformations/src/space_to_batch.cpp +++ b/src/common/low_precision_transformations/src/space_to_batch.cpp @@ -5,11 +5,9 @@ #include "low_precision/space_to_batch.hpp" #include -#include -#include - -#include +#include "openvino/op/space_to_batch.hpp" +#include "openvino/pass/pattern/op/wrap_type.hpp" #include "low_precision/network_helper.hpp" #include "itt.hpp" @@ -21,7 +19,7 @@ SpaceToBatchTransformation::SpaceToBatchTransformation(const Params& params) : L MATCHER_SCOPE(SpaceToBatchTransformation); auto matcher = pattern::wrap_type(); - ngraph::graph_rewrite_callback callback = [this](pattern::Matcher& m) { + ov::graph_rewrite_callback callback = [this](pattern::Matcher& m) { auto op = m.get_match_root(); if (transformation_callback(op)) { return false; @@ -29,7 +27,7 @@ SpaceToBatchTransformation::SpaceToBatchTransformation(const Params& params) : L return transform(*context, m); }; - auto m = std::make_shared(matcher, matcher_name); + auto m = std::make_shared(matcher, matcher_name); this->register_matcher(m, callback); } @@ -46,7 +44,7 @@ bool SpaceToBatchTransformation::canBeTransformed(const TransformationContext& c return dequantization.isPerTensor(); } -bool SpaceToBatchTransformation::transform(TransformationContext& context, ngraph::pattern::Matcher& m) { +bool SpaceToBatchTransformation::transform(TransformationContext& context, ov::pass::pattern::Matcher& m) { if (!canBeTransformed(context, m.get_match_root())) { return false; } diff --git a/src/common/low_precision_transformations/src/transpose.cpp b/src/common/low_precision_transformations/src/transpose.cpp index e2c098103a5677..eb40b4e183abaa 100644 --- a/src/common/low_precision_transformations/src/transpose.cpp +++ b/src/common/low_precision_transformations/src/transpose.cpp @@ -116,7 +116,7 @@ bool TransposeTransformation::canBeTransformed(const TransformationContext& cont } } if (dequantization.multiply != nullptr) { - const auto mulConst = ov::as_type_ptr(dequantization.multiplyConstant); + const auto mulConst = ov::as_type_ptr(dequantization.multiplyConstant); if (!NetworkHelper::isScalarLike(mulConst)) { return false; } diff --git a/src/common/low_precision_transformations/src/weightable_layer_transformation.cpp b/src/common/low_precision_transformations/src/weightable_layer_transformation.cpp index d3dd47d2107737..dd6995efc6e957 100644 --- a/src/common/low_precision_transformations/src/weightable_layer_transformation.cpp +++ b/src/common/low_precision_transformations/src/weightable_layer_transformation.cpp @@ -163,7 +163,7 @@ bool WeightableLayerTransformation::canBeTransformed(const TransformationContext // // [1] no other consumers for FQ sitting on weights (neither Result node, nor any others - // original code includes separate checks for node being output and other consumers present; for - // ngraph it is a single check for number of consumers). + // openvino it is a single check for number of consumers). // // [2] if weights is anything except a constant with data_type other than i8; this check is overriden by // stronger check from Convolution patter which expects FQ only on weights diff --git a/src/common/low_precision_transformations/tests/get_dequantization_transformation.cpp b/src/common/low_precision_transformations/tests/get_dequantization_transformation.cpp index 0d5bad38902cb4..9c378f33b69406 100644 --- a/src/common/low_precision_transformations/tests/get_dequantization_transformation.cpp +++ b/src/common/low_precision_transformations/tests/get_dequantization_transformation.cpp @@ -26,7 +26,7 @@ using namespace ngraph::builder::subgraph; class GetDequantizationTestValues { public: FakeQuantizeOnData fakeQuantize; - // actual dequantization to create nGraph function to run NetworkHelper::getDequantization + // actual dequantization to create ov::Model to run NetworkHelper::getDequantization DequantizationOperations actualDequantization; DequantizationOperations expectedDequantization; }; diff --git a/src/common/offline_transformations/CMakeLists.txt b/src/common/offline_transformations/CMakeLists.txt index ccd11c7eb3b51d..69335b19be4e7a 100644 --- a/src/common/offline_transformations/CMakeLists.txt +++ b/src/common/offline_transformations/CMakeLists.txt @@ -2,13 +2,13 @@ # SPDX-License-Identifier: Apache-2.0 # -set(TARGET_NAME "offline_transformations") - -file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) -file(GLOB_RECURSE PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp) +set(TARGET_NAME "openvino_offline_transformations") set(PUBLIC_HEADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") +file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) +file(GLOB_RECURSE PUBLIC_HEADERS ${PUBLIC_HEADERS_DIR}/*.hpp) + # Create named folders for the sources within the .vcproj # Empty name lists them directly under the .vcproj @@ -19,19 +19,20 @@ source_group("include" FILES ${PUBLIC_HEADERS}) add_library(${TARGET_NAME} STATIC ${LIBRARY_SRC} ${PUBLIC_HEADERS}) -target_link_libraries(${TARGET_NAME} PRIVATE openvino::runtime::dev openvino::itt openvino::pugixml openvino::reference - openvino::runtime) +add_library(openvino::offline_transformations ALIAS ${TARGET_NAME}) +set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME offline_transformations) -set_source_files_properties(INCLUDE_DIRECTORIES - $) +target_link_libraries(${TARGET_NAME} PRIVATE openvino::core::dev openvino::reference openvino::runtime) -target_include_directories(${TARGET_NAME} PUBLIC ${PUBLIC_HEADERS_DIR} - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src") +target_include_directories(${TARGET_NAME} PUBLIC $ + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src" + $) add_cpplint_target(${TARGET_NAME}_cpplint FOR_TARGETS ${TARGET_NAME}) ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}) -# developer package +# install & export -openvino_developer_export_targets(COMPONENT core TARGETS ${TARGET_NAME}) +ov_developer_package_export_targets(TARGET ${TARGET_NAME} + INSTALL_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include/") diff --git a/src/common/offline_transformations/include/compress_quantize_weights.hpp b/src/common/offline_transformations/include/compress_quantize_weights.hpp index 62119cd907c914..356ff01195ae3f 100644 --- a/src/common/offline_transformations/include/compress_quantize_weights.hpp +++ b/src/common/offline_transformations/include/compress_quantize_weights.hpp @@ -10,7 +10,6 @@ namespace ov { namespace pass { class CompressQuantizeWeights; -class ZeroPointOptimizer; } // namespace pass } // namespace ov @@ -57,36 +56,10 @@ class ZeroPointOptimizer; Transformation prepares quantized constant data for Low Precision pipeline. Such constant data packing reduces IR size (.bin file size) in offline transformations. With that we can skip same calculations in the runtime and make loading of such sub-graphs to the plugin faster. + Additionally zero point can be fused to weights if it doesn't affect accuracy. */ class ov::pass::CompressQuantizeWeights : public ov::pass::MatcherPass { public: OPENVINO_RTTI("CompressQuantizeWeights", "0"); CompressQuantizeWeights(); }; - -/* - if zero_point == 0 we can eliminate Subtract from following dequantization subgraph: - - +-----------------+ - | Constant | - | (low precision) | - +-----------------+ - | - v - +------------------+ - | Convert | - | (to high prec) | - +------------------+ - | - v - +----------+ +------------+ - |zero point|--->| Subtract | - +----------+ +-----+------+ - | - v -*/ -class ov::pass::ZeroPointOptimizer : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ZeroPointOptimizer"); - ZeroPointOptimizer(); -}; diff --git a/src/common/offline_transformations/src/compress_quantize_weigths.cpp b/src/common/offline_transformations/src/compress_quantize_weigths.cpp index f8ff0d9d9f80b8..6c9e4554782a96 100644 --- a/src/common/offline_transformations/src/compress_quantize_weigths.cpp +++ b/src/common/offline_transformations/src/compress_quantize_weigths.cpp @@ -5,95 +5,125 @@ #include "compress_quantize_weights.hpp" #include "openvino/core/rt_info.hpp" #include "openvino/core/validation_util.hpp" -#include "openvino/opsets/opset8.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/convert.hpp" +#include "openvino/op/divide.hpp" +#include "openvino/op/fake_quantize.hpp" +#include "openvino/op/multiply.hpp" +#include "openvino/op/subtract.hpp" #include "openvino/pass/constant_folding.hpp" #include "openvino/pass/pattern/op/or.hpp" #include "openvino/pass/pattern/op/wrap_type.hpp" -#include "transformations/rt_info/decompression.hpp" - -static bool has_dequantization_subgraph(const std::shared_ptr& first_convert) { - auto first_convert_users = first_convert->get_users(); - const auto second_convert = std::find_if(first_convert_users.begin(), - first_convert_users.end(), - [](const std::shared_ptr& n) -> bool { - return ov::is_type(n); - }); - if (second_convert == first_convert_users.end()) - return false; - auto convert_or_subtract_users = (*second_convert)->get_users(); - const auto subtract = std::find_if(convert_or_subtract_users.begin(), - convert_or_subtract_users.end(), - [](const std::shared_ptr& n) -> bool { - return ov::is_type(n); - }); - if (subtract != convert_or_subtract_users.end()) { - convert_or_subtract_users = (*subtract)->get_users(); - } - const auto multiply = std::find_if(convert_or_subtract_users.begin(), - convert_or_subtract_users.end(), - [](const std::shared_ptr& n) -> bool { - return ov::is_type(n); - }); - return multiply != convert_or_subtract_users.end(); -} +#include "openvino/reference/autobroadcast_binop.hpp" +#include "openvino/reference/convert.hpp" +#include "openvino/reference/fake_quantize.hpp" +#include "validation_util.hpp" + +static bool has_dequantization_subgraph(const std::shared_ptr& fq, + std::shared_ptr& convert_to_low_precision, + std::shared_ptr& convert_to_high_precision, + std::shared_ptr& zero_point); + +static bool compute_scale_and_zero_point(const std::shared_ptr& output_low, + const std::shared_ptr& output_high, + size_t levels, + ov::Tensor& scale_tensor, + ov::Tensor& zero_point_tensor, + bool& zero_point_is_zero); + +static std::shared_ptr compress_quantized_weights( + const std::shared_ptr& weights, + const std::shared_ptr& fq, + const std::shared_ptr& input_low, + const std::shared_ptr& input_high, + const std::shared_ptr& output_low, + const std::shared_ptr& output_high, + const std::shared_ptr& convert, + const std::shared_ptr& zero_point, + bool& can_fuse_zero_point); + +static std::shared_ptr compress_quantized_weights( + const std::shared_ptr& weights, + const std::shared_ptr& input_low, + const std::shared_ptr& input_high, + const ov::element::Type& low_precision_type, + size_t levels, + bool zero_point_is_zero, + const ov::Tensor& zero_point_tensor, + bool& can_fuse_zero_point); + +static void replace_with_dequantize_subgraph(const std::shared_ptr& fq, + const std::shared_ptr& new_weights, + const ov::element::Type& high_precision_type, + const ov::Shape& scale_or_zero_point_shape, + const ov::Tensor& scale_tensor, + bool zero_point_is_zero, + const ov::Tensor& zero_point_tensor = {}); ov::pass::CompressQuantizeWeights::CompressQuantizeWeights() { - auto weights_const_pattern = pattern::wrap_type(); - auto weigths_convert_pattern = pattern::wrap_type({weights_const_pattern}); - OutputVector weights_options{weights_const_pattern, weigths_convert_pattern}; + auto weights_const_pattern = pattern::wrap_type(); + auto weights_convert_pattern = pattern::wrap_type({weights_const_pattern}); + OutputVector weights_options{weights_const_pattern, weights_convert_pattern}; auto weights_pattern = std::make_shared(weights_options); - auto input_low_pattern = pattern::wrap_type(); - auto input_high_pattern = pattern::wrap_type(); - auto output_low_pattern = pattern::wrap_type(); - auto output_high_pattern = pattern::wrap_type(); - auto fq_pattern = pattern::wrap_type( + auto input_low_pattern = pattern::wrap_type(); + auto input_high_pattern = pattern::wrap_type(); + auto output_low_pattern = pattern::wrap_type(); + auto output_high_pattern = pattern::wrap_type(); + auto fq_pattern = pattern::wrap_type( {weights_pattern, input_low_pattern, input_high_pattern, output_low_pattern, output_high_pattern}); ov::matcher_pass_callback callback = [=](pattern::Matcher& m) { - auto fq = std::dynamic_pointer_cast(m.get_match_root()); + auto fq = std::dynamic_pointer_cast(m.get_match_root()); if (!fq) return false; - auto levels = fq->get_levels(); - if (levels <= 2 || levels > 256) - return false; - auto quantized_type = element::undefined; - // Currently we support two weights quantize types: i4 and i8 - if (levels <= 16) { - quantized_type = element::i4; - } else if (levels <= 256) { - quantized_type = element::i8; - } + const auto& high_precision_type = fq->get_element_type(); - const auto& pattern_value_map = m.get_pattern_value_map(); - const auto& input_type = fq->get_element_type(); - const auto& fq_data_input = fq->get_input_node_shared_ptr(0); - bool are_weights_decompressed = is_decompression(fq_data_input); - if (are_weights_decompressed) { - unmark_as_decompression(fq_data_input); - } + auto weights = ov::util::constantfold_subgraph(fq->get_input_node_shared_ptr(0)); + if (!weights) + return false; + auto input_low = ov::as_type_ptr(fq->get_input_node_shared_ptr(1)); + if (!input_low) + return false; + auto input_high = ov::as_type_ptr(fq->get_input_node_shared_ptr(2)); + if (!input_high) + return false; + auto output_low = ov::as_type_ptr(fq->get_input_node_shared_ptr(3)); + if (!output_low) + return false; + auto output_high = ov::as_type_ptr(fq->get_input_node_shared_ptr(4)); + if (!output_high) + return false; // skip dequantize part if there is already dequantization subgraph after FakeQuantize - auto fq_users = fq->get_users(); - if (fq_users.size() == 1 && has_dequantization_subgraph(fq_users[0])) { - auto& first_convert = fq_users[0]; - OPENVINO_SUPPRESS_DEPRECATED_START - if (auto new_weights = ov::get_constant_from_source(first_convert)) { - OPENVINO_SUPPRESS_DEPRECATED_END - new_weights->set_friendly_name(first_convert->get_friendly_name()); - replace_node(first_convert, new_weights); - copy_runtime_info(first_convert, new_weights); - // preserve dequantization subgraph for LP transformations - auto weights_users = new_weights->get_users(); - if (weights_users.size() == 1 && ov::is_type(weights_users[0])) { - ov::pass::disable_constant_folding(weights_users[0]); - } - return true; - } else { - if (are_weights_decompressed) { - mark_as_decompression(fq_data_input); - } + std::shared_ptr convert_to_low_precision; + std::shared_ptr convert_to_high_precision; + std::shared_ptr zero_point; + if (has_dequantization_subgraph(fq, convert_to_low_precision, convert_to_high_precision, zero_point)) { + bool can_fuse_zero_point = false; + auto new_weights = compress_quantized_weights(weights, + fq, + input_low, + input_high, + output_low, + output_high, + convert_to_low_precision, + zero_point, + can_fuse_zero_point); + if (!new_weights) return false; + + new_weights->set_friendly_name(convert_to_low_precision->get_friendly_name()); + replace_node(convert_to_low_precision, new_weights); + copy_runtime_info({fq, convert_to_low_precision}, new_weights); + // preserve dequantization subgraph for LP transformations + ov::pass::disable_constant_folding(convert_to_high_precision); + if (can_fuse_zero_point) { + auto subtract = convert_to_high_precision->get_users()[0]; + auto subtract_consumers = subtract->output(0).get_target_inputs(); + auto multiply = *(subtract_consumers.begin()); + multiply.replace_source_output(convert_to_high_precision); } + return true; } else { /* Quantize part @@ -103,33 +133,7 @@ ov::pass::CompressQuantizeWeights::CompressQuantizeWeights() { output_low = -levels / 2 output_high = levels - 1 + output_low The FakeQuantize result is converted to low precision type and then constant folded - */ - std::shared_ptr new_output_low = - op::v0::Constant::create(input_type, Shape{}, {-static_cast(levels / 2)}); - std::shared_ptr new_output_high = - std::make_shared(new_output_low, - op::v0::Constant::create(input_type, Shape{}, {levels - 1})); - const auto& weights_const = pattern_value_map.at(weights_const_pattern); - Output input_low = pattern_value_map.at(input_low_pattern); - Output input_high = pattern_value_map.at(input_high_pattern); - auto quantize = - fq->clone_with_new_inputs({fq_data_input, input_low, input_high, new_output_low, new_output_high}); - // Convert quantized weights to low precision type - std::shared_ptr new_weights = std::make_shared(quantize, quantized_type); - // Constant fold quantized weights - OPENVINO_SUPPRESS_DEPRECATED_START - if (auto constant = ov::get_constant_from_source(new_weights)) { - OPENVINO_SUPPRESS_DEPRECATED_END - new_weights = constant; - } else { - if (are_weights_decompressed) { - mark_as_decompression(fq_data_input); - } - return false; - } - new_weights->set_friendly_name(weights_const.get_node()->get_friendly_name()); - /* Dequantize part is performed by Convert(from low to high precision)->Subtract->Multiply subgraph. +-------------------------+ @@ -153,56 +157,65 @@ ov::pass::CompressQuantizeWeights::CompressQuantizeWeights() { scale = (output_high - output_low) / (new_output_high - new_output_low) zero_point = new_output_low - output_low / scale */ - Output output_low = pattern_value_map.at(output_low_pattern); - Output output_high = pattern_value_map.at(output_high_pattern); - const auto& fq_type = fq->get_output_element_type(0); - const bool should_convert = fq_type.is_real() && fq_type.size() < element::f32.size(); - if (should_convert) { - input_low = std::make_shared(input_low, element::f32); - input_high = std::make_shared(input_high, element::f32); - output_low = std::make_shared(output_low, element::f32); - output_high = std::make_shared(output_high, element::f32); - new_output_low = std::make_shared(new_output_low, element::f32); - new_output_high = std::make_shared(new_output_high, element::f32); - } - auto output_range = std::make_shared(output_high, output_low); - auto input_range = std::make_shared(new_output_high, new_output_low); - std::shared_ptr scale = std::make_shared(output_range, input_range); - auto descaled_output_low = std::make_shared(output_low, scale); - std::shared_ptr shift = std::make_shared(new_output_low, descaled_output_low); - OPENVINO_SUPPRESS_DEPRECATED_START - if (auto constant = ov::get_constant_from_source(scale)) { - OPENVINO_SUPPRESS_DEPRECATED_END - scale = constant; + + auto levels = fq->get_levels(); + if (levels <= 2 || levels > 256) + return false; + auto low_precision_type = element::undefined; + // Currently we support two weights quantize types: i4 and i8 + if (levels <= 16) { + low_precision_type = element::i4; + } else if (levels <= 256) { + low_precision_type = element::i8; } - auto zero = op::v0::Constant::create(scale->get_output_element_type(0), Shape{}, {0}); - auto scale_eq_zero = std::make_shared(scale, zero); - // shift equals to input_low - output_low / scale - // for positions where scale == 0, we put zero as shift - std::shared_ptr zero_point = std::make_shared(scale_eq_zero, zero, shift); - - if (should_convert) { - scale = std::make_shared(scale, fq_type); - zero_point = std::make_shared(zero_point, fq_type); + + bool zero_point_is_zero = true; + PartialShape merged_shape{output_low->get_shape()}; + PartialShape::broadcast_merge_into(merged_shape, output_high->get_shape(), op::AutoBroadcastType::NUMPY); + Shape scale_or_zero_point_shape = merged_shape.to_shape(); + Tensor scale_tensor(high_precision_type, scale_or_zero_point_shape); + Tensor zero_point_tensor(high_precision_type, scale_or_zero_point_shape); + + if (!compute_scale_and_zero_point(output_low, + output_high, + levels, + scale_tensor, + zero_point_tensor, + zero_point_is_zero)) { + return false; } - OPENVINO_SUPPRESS_DEPRECATED_START - if (auto constant = ov::get_constant_from_source(zero_point)) { - OPENVINO_SUPPRESS_DEPRECATED_END - zero_point = constant; + bool can_fuse_zero_point = false; + auto new_weights = compress_quantized_weights(weights, + input_low, + input_high, + low_precision_type, + levels, + zero_point_is_zero, + zero_point_tensor, + can_fuse_zero_point); + if (!new_weights) { + return false; } - OPENVINO_SUPPRESS_DEPRECATED_START - if (auto constant = ov::get_constant_from_source(scale)) { - OPENVINO_SUPPRESS_DEPRECATED_END - scale = constant; + + if (zero_point_is_zero || can_fuse_zero_point) { + replace_with_dequantize_subgraph(fq, + new_weights, + high_precision_type, + scale_or_zero_point_shape, + scale_tensor, + true); + } else { + replace_with_dequantize_subgraph(fq, + new_weights, + high_precision_type, + scale_or_zero_point_shape, + scale_tensor, + zero_point_is_zero, + zero_point_tensor); } - auto convert_to_high_prec = std::make_shared(new_weights, input_type); - auto sub = register_new_node(convert_to_high_prec, zero_point); - auto mul = register_new_node(sub, scale); - mul->set_friendly_name(fq->get_friendly_name()); - copy_runtime_info(fq, {convert_to_high_prec, sub, mul}); - ov::pass::disable_constant_folding(convert_to_high_prec); - replace_node(fq, mul); + + return true; } return true; }; @@ -211,86 +224,622 @@ ov::pass::CompressQuantizeWeights::CompressQuantizeWeights() { this->register_matcher(m, callback); } -ov::pass::ZeroPointOptimizer::ZeroPointOptimizer() { - auto weights_pattern = pattern::wrap_type(); - auto zero_point_pattern = pattern::wrap_type(); - auto convert_pattern = pattern::wrap_type({weights_pattern}); - auto sub_pattern = pattern::wrap_type({convert_pattern, zero_point_pattern}); +static ov::Tensor tensor_from_constant(const std::shared_ptr& constant) { + return ov::Tensor(constant->get_element_type(), constant->get_shape(), const_cast(constant->get_data_ptr())); +} + +static bool evaluate_node(const std::shared_ptr& node, + const ov::TensorVector& input_tensors, + ov::Tensor& output_tensor) { + if (node->get_output_size() != 1) + return false; - ov::matcher_pass_callback callback = [=](pattern::Matcher& m) { - const auto& pattern_value_map = m.get_pattern_value_map(); - auto convert = pattern_value_map.at(convert_pattern).get_node_shared_ptr(); - auto sub = pattern_value_map.at(sub_pattern).get_node_shared_ptr(); - auto weights = - std::dynamic_pointer_cast(pattern_value_map.at(weights_pattern).get_node_shared_ptr()); - if (!weights || weights->get_element_type() != element::i8) - return false; - auto zero_point = - std::dynamic_pointer_cast(pattern_value_map.at(zero_point_pattern).get_node_shared_ptr()); - if (!zero_point) - return false; + ov::TensorVector output_tensors{ov::Tensor(node->get_output_element_type(0), node->get_output_shape(0))}; + if (!node->evaluate(output_tensors, input_tensors)) + return false; - auto zp_value = zero_point->cast_vector(); - if (std::all_of(zp_value.begin(), zp_value.end(), [](float f) -> bool { - return std::fabs(f) <= std::numeric_limits::epsilon(); - })) { - copy_runtime_info(sub, convert); - replace_node(sub, convert); - } + output_tensor = output_tensors[0]; - auto int8_zero_point = std::make_shared( - std::make_shared(zero_point, opset8::Round::RoundMode::HALF_TO_EVEN), - weights->get_element_type()); - auto adj_zero_point = std::make_shared( - zero_point, - std::make_shared(int8_zero_point, convert->get_element_type())); - - OPENVINO_SUPPRESS_DEPRECATED_START - auto adj_zero_point_const = ov::get_constant_from_source(adj_zero_point); - OPENVINO_SUPPRESS_DEPRECATED_END - if (!adj_zero_point_const) - return false; - auto adj_zero_point_val = adj_zero_point_const->cast_vector(); - bool is_adj_zero_point_close_to_zero = - std::all_of(adj_zero_point_val.begin(), adj_zero_point_val.end(), [](float f) -> bool { - return std::fabs(f) < 1e-4; - }); - if (!is_adj_zero_point_close_to_zero) - return false; + return true; +} - auto transformed = std::make_shared( - std::make_shared(std::make_shared(weights, int8_zero_point), - convert->get_element_type()), - adj_zero_point); - auto diff = std::make_shared(sub, transformed); - OPENVINO_SUPPRESS_DEPRECATED_START - auto diff_const = ov::get_constant_from_source(diff); - OPENVINO_SUPPRESS_DEPRECATED_END - if (!diff_const) - return false; - auto diff_val = diff_const->cast_vector(); - bool is_transformed_and_original_equal = std::all_of(diff_val.begin(), diff_val.end(), [](float f) -> bool { - return std::fabs(f) < std::numeric_limits::epsilon(); +static ov::TensorVector get_fake_quantize_input_tensors(const std::shared_ptr& fq) { + ov::Tensor weights_tensor; + + auto fq_input = fq->get_input_node_shared_ptr(0); + auto fq_input_constant = ov::as_type_ptr(fq_input); + + if (!fq_input_constant) { + auto weights = ov::as_type_ptr(fq_input->get_input_node_shared_ptr(0)); + if (!evaluate_node(fq_input, ov::TensorVector{tensor_from_constant(weights)}, weights_tensor)) + return {}; + } else { + weights_tensor = tensor_from_constant(fq_input_constant); + } + + auto in_low = ov::as_type_ptr(fq->get_input_node_shared_ptr(1)); + auto in_high = ov::as_type_ptr(fq->get_input_node_shared_ptr(2)); + auto out_low = ov::as_type_ptr(fq->get_input_node_shared_ptr(3)); + auto out_high = ov::as_type_ptr(fq->get_input_node_shared_ptr(4)); + + return ov::TensorVector{weights_tensor, + tensor_from_constant(in_low), + tensor_from_constant(in_high), + tensor_from_constant(out_low), + tensor_from_constant(out_high)}; +} + +template +static std::shared_ptr get_single_consumer_of_type(const std::shared_ptr& node) { + auto target_inputs = node->output(0).get_target_inputs(); + if (target_inputs.size() != 1) + return nullptr; + auto consumer = ov::as_type(target_inputs.begin()->get_node()); + if (!consumer) + return nullptr; + return consumer->shared_from_this(); +} + +bool has_dequantization_subgraph(const std::shared_ptr& fq, + std::shared_ptr& convert_to_low_precision, + std::shared_ptr& convert_to_high_precision, + std::shared_ptr& zero_point) { + convert_to_low_precision = get_single_consumer_of_type(fq); + if (!convert_to_low_precision) + return false; + convert_to_high_precision = get_single_consumer_of_type(convert_to_low_precision); + if (!convert_to_high_precision) + return false; + auto subtract = get_single_consumer_of_type(convert_to_high_precision); + if (subtract) { + zero_point = subtract->get_input_node_shared_ptr(1); + return get_single_consumer_of_type(subtract) != nullptr; + } else { + return get_single_consumer_of_type(convert_to_high_precision) != nullptr; + } +} + +static std::shared_ptr evaluate_fake_quantize(const std::shared_ptr& quantize, + const std::shared_ptr& convert) { + ov::Tensor quantize_output_tensor; + if (!evaluate_node(quantize, get_fake_quantize_input_tensors(quantize), quantize_output_tensor)) + return nullptr; + ov::Tensor new_weights_tensor; + if (!evaluate_node(convert, {quantize_output_tensor}, new_weights_tensor)) + return nullptr; + return std::make_shared(new_weights_tensor); +} + +void replace_with_dequantize_subgraph(const std::shared_ptr& fq, + const std::shared_ptr& new_weights, + const ov::element::Type& high_precision_type, + const ov::Shape& scale_or_zero_point_shape, + const ov::Tensor& scale_tensor, + bool zero_point_is_zero, + const ov::Tensor& zero_point_tensor) { + ov::pass::NodeRegistry node_registry; + auto convert = node_registry.make(new_weights, high_precision_type); + ov::pass::disable_constant_folding(convert); + std::shared_ptr mul; + auto scale = node_registry.make(scale_tensor); + if (!zero_point_is_zero) { + auto zero_point = node_registry.make(zero_point_tensor); + auto sub = node_registry.make(convert, zero_point); + mul = node_registry.make(sub, scale); + } else { + mul = node_registry.make(convert, scale); + } + mul->set_friendly_name(fq->get_friendly_name()); + copy_runtime_info(fq, node_registry.get()); + replace_node(fq, mul); +} + +template +static void compute_scale_and_zero_point_internal(const std::shared_ptr& output_low, + const std::shared_ptr& output_high, + size_t levels, + ov::Tensor& scale_tensor, + ov::Tensor& zero_point_tensor, + bool& zero_point_is_zero) { + zero_point_is_zero = true; + float input_range = static_cast(levels - 1); + float new_output_low = -static_cast(levels / 2); + T* zero_point = zero_point_tensor.data(); + T* scale = scale_tensor.data(); + ov::reference::autobroadcast_binop( + output_low->get_data_ptr(), + output_high->get_data_ptr(), + scale, + output_low->get_shape(), + output_high->get_shape(), + ov::op::AutoBroadcastType::NUMPY, + [input_range, new_output_low, zero_point, &zero_point_is_zero](float output_low_value, + float output_high_value) mutable { + float output_range = output_high_value - output_low_value; + float scale = output_range / input_range; + float zero_point_value = (new_output_low - output_low_value / scale) * (scale != 0); + zero_point_is_zero = + zero_point_is_zero && std::fabs(zero_point_value) < std::numeric_limits::epsilon(); + *zero_point++ = zero_point_value; + return scale; }); - if (!is_transformed_and_original_equal) - return false; +} - std::shared_ptr new_weights = std::make_shared(weights, int8_zero_point); - OPENVINO_SUPPRESS_DEPRECATED_START - if (auto constant = ov::get_constant_from_source(new_weights)) { - OPENVINO_SUPPRESS_DEPRECATED_END - new_weights = constant; - } else { - return false; +bool compute_scale_and_zero_point(const std::shared_ptr& output_low, + const std::shared_ptr& output_high, + size_t levels, + ov::Tensor& scale_tensor, + ov::Tensor& zero_point_tensor, + bool& zero_point_is_zero) { + const auto type = output_low->get_element_type(); + switch (type) { + case ov::element::Type_t::f32: { + compute_scale_and_zero_point_internal(output_low, + output_high, + levels, + scale_tensor, + zero_point_tensor, + zero_point_is_zero); + break; + } + case ov::element::f16: { + compute_scale_and_zero_point_internal(output_low, + output_high, + levels, + scale_tensor, + zero_point_tensor, + zero_point_is_zero); + break; + } + default: + return false; + } + + return true; +} + +template +static void +transform(const T* first1, const T* const last1, const T* first2, const T* first3, const T* first4, U* out, F& f) { + while (first1 < last1) { + *out++ = f(*first1++, *first2++, *first3++, *first4++); + } +} + +template +static void transform(const T* first1, + const T* const last1, + const T* first2, + const T* first3, + const T* first4, + const T* first5, + const T* first6, + U* out, + F& f) { + while (first1 < last1) { + *out++ = f(*first1++, *first2++, *first3++, *first4++, *first5++, *first6++); + } +} + +template +static void numpy_broadcast_4inputs(const T* weights, + const ov::Shape& weights_shape, + const T* in_low, + const ov::Shape& in_low_shape, + const T* in_high, + const ov::Shape& in_high_shape, + const T* zero_point, + const ov::Shape& zero_point_shape, + U* new_weights, + F& f) { + using namespace ov::reference::fake_quantize_details; + + std::vector output_strides = compute_strides(weights_shape, weights_shape); + std::vector in_low_strides = compute_strides(weights_shape, in_low_shape); + std::vector in_high_strides = compute_strides(weights_shape, in_high_shape); + std::vector zero_point_strides = compute_strides(weights_shape, zero_point_shape); + + size_t num_elements = shape_size(weights_shape); + + size_t weights_inner_stride = num_elements; + size_t in_low_inner_stride = 0; + size_t in_high_inner_stride = 0; + size_t zero_point_inner_stride = 0; + + std::tie(in_low_inner_stride, weights_inner_stride) = + get_inner_stride(num_elements, weights_shape, in_low_shape, weights_inner_stride); + std::tie(in_high_inner_stride, weights_inner_stride) = + get_inner_stride(num_elements, weights_shape, in_high_shape, weights_inner_stride); + std::tie(zero_point_inner_stride, weights_inner_stride) = + get_inner_stride(num_elements, weights_shape, zero_point_shape, weights_inner_stride); + + auto get_outer_strides = + [&output_strides, &in_low_strides, &in_high_strides, &zero_point_strides](size_t flat_index) { + size_t in_low_stride = 0; + size_t in_high_stride = 0; + size_t zero_point_stride = 0; + + for (size_t i = 0; i < output_strides.size(); i++) { + size_t div = flat_index / output_strides[i]; + flat_index = flat_index % output_strides[i]; + in_low_stride += div * in_low_strides[i]; + in_high_stride += div * in_high_strides[i]; + zero_point_stride += div * zero_point_strides[i]; + } + + return std::tuple{in_low_stride, in_high_stride, zero_point_stride}; + }; + + size_t in_low_stride = 0; + size_t in_high_stride = 0; + size_t zero_point_stride = 0; + + if (in_low_inner_stride * in_high_inner_stride * zero_point_inner_stride == 1) { + for (size_t i = 0; i < shape_size(weights_shape); i += weights_inner_stride) { + std::tie(in_low_stride, in_high_stride, zero_point_stride) = get_outer_strides(i); + T in_low_scalar = *(in_low + in_low_stride); + T in_high_scalar = *(in_high + in_high_stride); + T zero_point_scalar = *(zero_point + zero_point_stride); + std::transform(weights, + weights + weights_inner_stride, + new_weights, + [in_low_scalar, in_high_scalar, zero_point_scalar, &f](T w) { + return f(w, in_low_scalar, in_high_scalar, zero_point_scalar); + }); + weights += weights_inner_stride; + new_weights += weights_inner_stride; + } + } else if (in_low_inner_stride > 1 && in_high_inner_stride > 1 && zero_point_inner_stride > 1) { + for (size_t i = 0; i < shape_size(weights_shape); i += weights_inner_stride) { + std::tie(in_low_stride, in_high_stride, zero_point_stride) = get_outer_strides(i); + transform(weights, + weights + weights_inner_stride, + in_low + in_low_stride, + in_high + in_high_stride, + zero_point + zero_point_stride, + new_weights, + f); + weights += weights_inner_stride; + new_weights += weights_inner_stride; } - new_weights->set_friendly_name(weights->get_friendly_name()); - replace_node(weights, new_weights); + } else { + for (size_t i = 0; i < shape_size(weights_shape); i++) { + std::tie(in_low_stride, in_high_stride, zero_point_stride) = get_outer_strides(i); + *new_weights++ = f(*weights++, + *(in_low + in_low_stride), + *(in_high + in_high_stride), + *(zero_point + zero_point_stride)); + } + } +} - copy_runtime_info(sub, convert); - replace_node(sub, convert); - return true; +template +static void numpy_broadcast_6inputs(const T* weights, + const ov::Shape& weights_shape, + const T* in_low, + const ov::Shape& in_low_shape, + const T* in_high, + const ov::Shape& in_high_shape, + const T* out_low, + const ov::Shape& out_low_shape, + const T* out_high, + const ov::Shape& out_high_shape, + const T* zero_point, + const ov::Shape& zero_point_shape, + U* new_weights, + F& f) { + using namespace ov::reference::fake_quantize_details; + + std::vector output_strides = compute_strides(weights_shape, weights_shape); + std::vector in_low_strides = compute_strides(weights_shape, in_low_shape); + std::vector in_high_strides = compute_strides(weights_shape, in_high_shape); + std::vector out_low_strides = compute_strides(weights_shape, out_low_shape); + std::vector out_high_strides = compute_strides(weights_shape, out_high_shape); + std::vector zero_point_strides = compute_strides(weights_shape, zero_point_shape); + + auto get_outer_strides = + [&output_strides, &in_low_strides, &in_high_strides, &out_low_strides, &out_high_strides, &zero_point_strides]( + size_t flat_index) { + size_t in_low_stride = 0; + size_t in_high_stride = 0; + size_t out_low_stride = 0; + size_t out_high_stride = 0; + size_t zero_point_stride = 0; + + for (size_t i = 0; i < output_strides.size(); i++) { + size_t div = flat_index / output_strides[i]; + flat_index = flat_index % output_strides[i]; + in_low_stride += div * in_low_strides[i]; + in_high_stride += div * in_high_strides[i]; + out_low_stride += div * out_low_strides[i]; + out_high_stride += div * out_high_strides[i]; + zero_point_stride += div * zero_point_strides[i]; + } + + return std::tuple{in_low_stride, + in_high_stride, + out_low_stride, + out_high_stride, + zero_point_stride}; + }; + + size_t in_low_stride = 0; + size_t in_high_stride = 0; + size_t out_low_stride = 0; + size_t out_high_stride = 0; + size_t zero_point_stride = 0; + + for (size_t i = 0; i < shape_size(weights_shape); i++) { + std::tie(in_low_stride, in_high_stride, out_low_stride, out_high_stride, zero_point_stride) = + get_outer_strides(i); + *new_weights++ = f(*weights++, + *(in_low + in_low_stride), + *(in_high + in_high_stride), + *(out_low + out_low_stride), + *(out_high + out_high_stride), + *(zero_point + zero_point_stride)); + } +} + +static inline int8_t convert_to_int8(float val) { + return static_cast(std::nearbyint(val)); +} + +static inline int8_t convert_to_int4(float val) { + return static_cast(std::nearbyint(val)) & 0x0f; +} + +static std::shared_ptr create_weights_constant(const ov::Tensor& weights_tensor, + const ov::element::Type& type) { + auto weights = std::make_shared(weights_tensor); + if (weights->get_element_type() != type) { + return ov::util::constantfold_subgraph(std::make_shared(weights, type)); + } + return weights; +} + +template +static std::shared_ptr compress_quantized_weights_internal( + const ov::element::Type& low_precision_type, + const T* weights, + const ov::Shape& weights_shape, + const T* input_low, + const ov::Shape& input_low_shape, + const T* input_high, + const ov::Shape& input_high_shape, + const T* output_low, + const ov::Shape& output_low_shape, + const T* output_high, + const ov::Shape& output_high_shape, + const T* zero_point, + const ov::Shape& zero_point_shape, + size_t levels, + bool& can_fuse_zero_point) { + ov::Tensor compressed_weights_tensor(ov::element::i8, weights_shape); + int8_t* compressed_weights = compressed_weights_tensor.data(); + ov::Tensor compressed_weights_with_fused_zero_point_tensor(ov::element::i8, weights_shape); + int8_t* compressed_weights_with_fused_zero_point = compressed_weights_with_fused_zero_point_tensor.data(); + T levels_minus_one = static_cast(levels - 1); + can_fuse_zero_point = true; + const auto convert_to_low_precision = low_precision_type == ov::element::i4 ? convert_to_int4 : convert_to_int8; + + auto f = + [compressed_weights_with_fused_zero_point, levels_minus_one, convert_to_low_precision, &can_fuse_zero_point]( + T weights_value, + T input_low, + T input_high, + T output_low, + T output_high, + T zero_point) mutable { + int8_t compressed_weights_value = + convert_to_low_precision(ov::reference::fake_quantize_details::quantize(weights_value, + input_low, + input_high, + output_low, + output_high, + levels_minus_one)); + T weights_minus_zero_point = static_cast(compressed_weights_value) - zero_point; + int8_t compressed_weights_with_fused_zero_point_value = convert_to_low_precision(weights_minus_zero_point); + can_fuse_zero_point &= + std::fabs(compressed_weights_with_fused_zero_point_value - weights_minus_zero_point) < 1e-4; + *compressed_weights_with_fused_zero_point++ = compressed_weights_with_fused_zero_point_value; + return compressed_weights_value; + }; + + numpy_broadcast_6inputs(weights, + weights_shape, + input_low, + input_low_shape, + input_high, + input_high_shape, + output_low, + output_low_shape, + output_high, + output_high_shape, + zero_point, + zero_point_shape, + compressed_weights, + f); + + return create_weights_constant( + can_fuse_zero_point ? compressed_weights_with_fused_zero_point_tensor : compressed_weights_tensor, + low_precision_type); +} + +std::shared_ptr compress_quantized_weights( + const std::shared_ptr& weights, + const std::shared_ptr& fq, + const std::shared_ptr& input_low, + const std::shared_ptr& input_high, + const std::shared_ptr& output_low, + const std::shared_ptr& output_high, + const std::shared_ptr& convert, + const std::shared_ptr& zero_point, + bool& can_fuse_zero_point) { + std::shared_ptr new_weights; + const auto& weights_shape = weights->get_shape(); + const auto& type = weights->get_element_type(); + const auto& low_precision_type = convert->get_output_element_type(0); + + if (zero_point == nullptr) + return evaluate_fake_quantize(fq, convert); + + auto zero_point_constant = ov::util::constantfold_subgraph(zero_point); + if (!zero_point_constant) + return nullptr; + + switch (type) { + case ov::element::f32: { + new_weights = compress_quantized_weights_internal(low_precision_type, + weights->get_data_ptr(), + weights_shape, + input_low->get_data_ptr(), + input_low->get_shape(), + input_high->get_data_ptr(), + input_low->get_shape(), + output_low->get_data_ptr(), + output_low->get_shape(), + output_high->get_data_ptr(), + output_low->get_shape(), + zero_point_constant->get_data_ptr(), + zero_point_constant->get_shape(), + fq->get_levels(), + can_fuse_zero_point); + break; + } + case ov::element::f16: { + new_weights = compress_quantized_weights_internal(low_precision_type, + weights->get_data_ptr(), + weights_shape, + input_low->get_data_ptr(), + input_low->get_shape(), + input_high->get_data_ptr(), + input_low->get_shape(), + output_low->get_data_ptr(), + output_low->get_shape(), + output_high->get_data_ptr(), + output_low->get_shape(), + zero_point_constant->get_data_ptr(), + zero_point_constant->get_shape(), + fq->get_levels(), + can_fuse_zero_point); + break; + } + default: + return nullptr; + } + return new_weights; +} + +template +static std::shared_ptr compress_quantized_weights_internal( + const ov::element::Type& low_precision_type, + const T* weights, + const ov::Shape& weights_shape, + const T* input_low, + const ov::Shape& input_low_shape, + const T* input_high, + const ov::Shape& input_high_shape, + const T* zero_point, + const ov::Shape& zero_point_shape, + size_t levels, + bool zero_point_is_zero, + bool& can_fuse_zero_point) { + using namespace ov::reference::fake_quantize_details; + ov::Tensor compressed_weights_tensor(ov::element::i8, weights_shape); + int8_t* compressed_weights = compressed_weights_tensor.data(); + int8_t* compressed_weights_with_fused_zero_point = nullptr; + ov::Tensor compressed_weights_with_fused_zero_point_tensor; + if (!zero_point_is_zero) { + compressed_weights_with_fused_zero_point_tensor = ov::Tensor(ov::element::i8, weights_shape); + compressed_weights_with_fused_zero_point = compressed_weights_with_fused_zero_point_tensor.data(); + } + T levels_minus_one = static_cast(levels - 1); + T output_low = -static_cast(levels / 2); + T output_high = levels_minus_one + output_low; + can_fuse_zero_point = !zero_point_is_zero; + const auto convert_to_low_precision = low_precision_type == ov::element::i4 ? convert_to_int4 : convert_to_int8; + + auto f = [compressed_weights_with_fused_zero_point, + levels_minus_one, + output_low, + output_high, + zero_point_is_zero, + convert_to_low_precision, + &can_fuse_zero_point](T weights_value, T input_low, T input_high, T zero_point) mutable { + int8_t compressed_weights_value = convert_to_low_precision( + quantize(weights_value, input_low, input_high, output_low, output_high, levels_minus_one)); + if (!zero_point_is_zero && can_fuse_zero_point) { + T weights_minus_zero_point = static_cast(compressed_weights_value) - zero_point; + int8_t compressed_weights_with_fused_zero_point_value = convert_to_low_precision(weights_minus_zero_point); + can_fuse_zero_point &= + std::fabs(compressed_weights_with_fused_zero_point_value - weights_minus_zero_point) < 1e-4; + *compressed_weights_with_fused_zero_point++ = compressed_weights_with_fused_zero_point_value; + } + return compressed_weights_value; }; - auto m = std::make_shared(sub_pattern, "ZeroPointOptimizer"); - this->register_matcher(m, callback); + numpy_broadcast_4inputs(weights, + weights_shape, + input_low, + input_low_shape, + input_high, + input_high_shape, + zero_point, + zero_point_shape, + compressed_weights, + f); + + return create_weights_constant( + can_fuse_zero_point ? compressed_weights_with_fused_zero_point_tensor : compressed_weights_tensor, + low_precision_type); +} + +std::shared_ptr compress_quantized_weights( + const std::shared_ptr& weights, + const std::shared_ptr& input_low, + const std::shared_ptr& input_high, + const ov::element::Type& low_precision_type, + size_t levels, + bool zero_point_is_zero, + const ov::Tensor& zero_point_tensor, + bool& can_fuse_zero_point) { + std::shared_ptr new_weights; + const auto& weights_shape = weights->get_shape(); + const auto& type = weights->get_element_type(); + switch (type) { + case ov::element::f32: { + new_weights = compress_quantized_weights_internal(low_precision_type, + weights->get_data_ptr(), + weights_shape, + input_low->get_data_ptr(), + input_low->get_shape(), + input_high->get_data_ptr(), + input_low->get_shape(), + zero_point_tensor.data(), + zero_point_tensor.get_shape(), + levels, + zero_point_is_zero, + can_fuse_zero_point); + break; + } + case ov::element::f16: { + new_weights = compress_quantized_weights_internal(low_precision_type, + weights->get_data_ptr(), + weights_shape, + input_low->get_data_ptr(), + input_low->get_shape(), + input_high->get_data_ptr(), + input_low->get_shape(), + zero_point_tensor.data(), + zero_point_tensor.get_shape(), + levels, + zero_point_is_zero, + can_fuse_zero_point); + break; + } + default: + return nullptr; + } + return new_weights; } diff --git a/src/common/preprocessing/src/CMakeLists.txt b/src/common/preprocessing/src/CMakeLists.txt index dbc3a06369edf7..9e3fd2d3789a02 100644 --- a/src/common/preprocessing/src/CMakeLists.txt +++ b/src/common/preprocessing/src/CMakeLists.txt @@ -37,7 +37,7 @@ if(ENABLE_SSE42) list(APPEND LIBRARY_HEADERS ${SSE_HEADERS}) list(APPEND LIBRARY_SRC ${SSE_SRC}) - ie_sse42_optimization_flags(sse4_2_flags) + ov_sse42_optimization_flags(sse4_2_flags) set_source_files_properties(${SSE_SRC} PROPERTIES COMPILE_OPTIONS "${sse4_2_flags}") add_definitions(-DHAVE_SSE=1) endif() @@ -49,7 +49,7 @@ if(ENABLE_AVX2) list(APPEND LIBRARY_HEADERS ${AVX2_HEADERS}) list(APPEND LIBRARY_SRC ${AVX2_SRC}) - ie_avx2_optimization_flags(avx2_flags) + ov_avx2_optimization_flags(avx2_flags) set_source_files_properties(${AVX2_SRC} PROPERTIES COMPILE_OPTIONS "${avx2_flags}") add_definitions(-DHAVE_AVX2=1) endif() @@ -75,7 +75,7 @@ if(ENABLE_AVX512F AND NOT GNU_5_DEBUG_CASE) endif() if(ARM OR AARCH64) - ie_arm_neon_optimization_flags(neon_flags) + ov_arm_neon_optimization_flags(neon_flags) file(GLOB NEON_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/arm_neon/*.hpp) file(GLOB NEON_SRC ${CMAKE_CURRENT_SOURCE_DIR}/arm_neon/*.cpp) @@ -211,7 +211,7 @@ endif() # developer package -openvino_developer_export_targets(COMPONENT core TARGETS ${TARGET_NAME}) +ov_developer_package_export_targets(TARGET ${TARGET_NAME}) # install diff --git a/src/common/preprocessing/src/ie_preprocess_data.hpp b/src/common/preprocessing/src/ie_preprocess_data.hpp index f16989e230ca90..79d8e84c140b0b 100644 --- a/src/common/preprocessing/src/ie_preprocess_data.hpp +++ b/src/common/preprocessing/src/ie_preprocess_data.hpp @@ -84,7 +84,7 @@ class PreProcessDataPlugin { // 2. in the same folder as libopenvino.so ov::util::FilePath ovLibraryPath = getInferenceEngineLibraryPath(); - ov::util::FilePath libraryName = ov::util::to_file_path(std::string("openvino_gapi_preproc") + std::string(IE_BUILD_POSTFIX)); + ov::util::FilePath libraryName = ov::util::to_file_path(std::string("openvino_gapi_preproc") + std::string(OV_BUILD_POSTFIX)); libraryName = FileUtils::makePluginLibraryName({}, libraryName); std::ostringstream str; diff --git a/src/common/snippets/CMakeLists.txt b/src/common/snippets/CMakeLists.txt index fdc1c83889423d..b3d2db77b77241 100644 --- a/src/common/snippets/CMakeLists.txt +++ b/src/common/snippets/CMakeLists.txt @@ -46,8 +46,9 @@ endif() set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO}) -# install +# install & export ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE}) -openvino_developer_export_targets(COMPONENT ${OV_CPACK_COMP_CORE} TARGETS ${TARGET_NAME}) +ov_developer_package_export_targets(TARGET ${TARGET_NAME} + INSTALL_INCLUDE_DIRECTORIES "${PUBLIC_HEADERS_DIR}/") diff --git a/src/common/snippets/docs/snippets_design_guide.md b/src/common/snippets/docs/snippets_design_guide.md index 83adce2171cccc..2f157b620b9574 100644 --- a/src/common/snippets/docs/snippets_design_guide.md +++ b/src/common/snippets/docs/snippets_design_guide.md @@ -236,7 +236,7 @@ Finally, the `Backend` uses the optimized `IR` to produce executable code. As shown on the figure below, `Snippets` are organized in a very similar way. ```mermaid graph LR - Source[nGraph \n model] + Source[OpenVINO \n model] subgraph Snippets direction LR subgraph Optimizer[Optimizer] @@ -244,10 +244,10 @@ As shown on the figure below, `Snippets` are organized in a very similar way. Data[Data flow \n optimizations] Converter[Convert \n IR] Control[Control flow \n optimizations] - Data-->|nGraph \nIR|Converter + Data-->|OpenVINO \nIR|Converter Converter-->|Linear \nIR|Control end - Frontend[Tokenizer]-->|nGraph \nIR|Data + Frontend[Tokenizer]-->|OpenVINO \nIR|Data Control-->|Linear \nIR|Backend[Generator] end Source --> Frontend @@ -258,13 +258,13 @@ classDef daisy1 fill:#FFE17A, stroke: #FEC91B, color: #262626 class Frontend,Optimizer,Backend steel1 class Source,Executable daisy1 ``` -Instead of a source code, `Snippets` take `nGraph` model as an input. -Then the `Tokenizer` (which is essentially a `Snippets` `Frontend`) parses an input `nGraph model`, and tries to find a part of the model that could be processed by `Snippets`. -If such a part is found, `Tokenizer` converts it to an `nGraph IR` and stores inside a `Subgraph` node. -`nGraph IR` - is one of the two `IR` types used by `Snippets`, it is simply a small `nGraph model` that can contain `Snippets`-specific operations. +Instead of a source code, `Snippets` take `OpenVINO` model as an input. +Then the `Tokenizer` (which is essentially a `Snippets` `Frontend`) parses an input `OpenVINO model`, and tries to find a part of the model that could be processed by `Snippets`. +If such a part is found, `Tokenizer` converts it to an `OpenVINO IR` and stores inside a `Subgraph` node. +`OpenVINO IR` - is one of the two `IR` types used by `Snippets`, it is simply a small `OpenVINO model` that can contain `Snippets`-specific operations. -`nGraph IR` is then passed to the `Optimizer` unit that in turn consists of three subunits. -The purpose of the first subunit is to perform data flow optimizations. The second subunit converts `nGraph IR` (data-flow-oriented representation) to `Linear IR` (control-flow-focused IR). Finally, the third subunit is dedicated to control flow optimizations. +`OpenVINO IR` is then passed to the `Optimizer` unit that in turn consists of three subunits. +The purpose of the first subunit is to perform data flow optimizations. The second subunit converts `OpenVINO IR` (data-flow-oriented representation) to `Linear IR` (control-flow-focused IR). Finally, the third subunit is dedicated to control flow optimizations. After all optimizations, the `Linear IR` is used by the `Generator` (which is `Snippets` `Backend`) to produce executable code, which we will refer to as `Kernel`. As discussed in the Introduction, the purpose of the `Kernel` is to process a part of the initial tensor, and several `Kernels` are usually executed in parallel to process the whole tensor. @@ -280,7 +280,7 @@ The `Snippets` integration into the plugin pipeline is schematically depicted be graph LR subgraph Plugin[ Plugin pipeline ] direction LR - subgraph ngraph[ Transformations on nGraph model ] + subgraph openvino[ Transformations on OpenVINO model ] direction LR common[Common \n Transformations] lpt[Low \n Precision] @@ -305,7 +305,7 @@ The `Snippets` integration into the plugin pipeline is schematically depicted be create-->execute end end - Source[nGraph \n model]-->|Main \n flow|common + Source[OpenVINO \n model]-->|Main \n flow|common convert~~~internal classDef no-bg-color fill:none,stroke-width:0px classDef steel1 fill:#B9D6E5, stroke: #86B3CA, color: #262626 @@ -315,15 +315,15 @@ class tokenize,optimize,generate steel1 class Source,Executable daisy1 class create,execute dafault_node1 ``` -As one can see from the picture, overall plugin pipeline consists of two major blocks: the first block applies transformations to `nGraph model` while the second one works with the internal plugin graph representation. Since `Snippets` is a backend-independent framework, it can't work with the plugin graph or plugin-specific `Ops` directly, so the tokenization is performed immediately before plugin-specific operations are introduced into the graph (`Conversion to Plugin opset`). -`Tokenizer` replaces parts of the `nGraph model` that can be executed by `Snippets` with `ov::op::Subgraph` nGraph nodes. -Each of the nodes stores a piece of the initial `nGraph model` that was replaced by the node. -This piece is stored as an nGraph model itself, which we refer to as `nGraph IR` to distinguish from the original `nGraph model`. +As one can see from the picture, overall plugin pipeline consists of two major blocks: the first block applies transformations to `OpenVINO model` while the second one works with the internal plugin graph representation. Since `Snippets` is a backend-independent framework, it can't work with the plugin graph or plugin-specific `Ops` directly, so the tokenization is performed immediately before plugin-specific operations are introduced into the graph (`Conversion to Plugin opset`). +`Tokenizer` replaces parts of the `OpenVINO model` that can be executed by `Snippets` with `ov::op::Subgraph` OpenVINO nodes. +Each of the nodes stores a piece of the initial `OpenVINO model` that was replaced by the node. +This piece is stored as an OpenVINO model itself, which we refer to as `OpenVINO IR` to distinguish from the original `OpenVINO model`. Note that sometimes the exact type of `IR` is not important in our discussion. -In such cases, we will refer to the `IR` (`nGraph` or `Linear`) as `body function`, or simply `body`. +In such cases, we will refer to the `IR` (`OpenVINO` or `Linear`) as `body function`, or simply `body`. -When the plugin finalizes all `nGraph model` transformations, the model is converted to an internal plugin graph representation. -At this point `ov::op::Subgraph` is converted to `ov::intel_cpu::node::Snippet` which still retains the `nGraph IR`. +When the plugin finalizes all `OpenVINO model` transformations, the model is converted to an internal plugin graph representation. +At this point `ov::op::Subgraph` is converted to `ov::intel_cpu::node::Snippet` which still retains the `OpenVINO IR`. This IR is then optimized and an executable `Kernel` is produced during the `CreateComputePrimitive` stage (`CreatePrimitive()` stage in CPU plugin). Finally, multiple copies of the produced kernel executed in parallel during the `Execute` stage. @@ -332,7 +332,7 @@ To summarize, `Snippets` workflow consists of three major blocks: `Tokenizer`, ` ### Tokenizer -`Tokenizer` is run on an `nGraph model` and its main purpose is to identify subgraphs that are suitable for code generation. +`Tokenizer` is run on an `OpenVINO model` and its main purpose is to identify subgraphs that are suitable for code generation. These subgraphs are then replaced with the `ov::op::Subgraph` node. This stage is called tokenization because the `Tokenizer` employs a greedy algorithm similar to the ones used for parsing input stream of characters into tokens. One of the distinctive features of this algorithm is its flexibility, so it can seamlessly handle arbitrary operations' patterns. @@ -371,8 +371,8 @@ The tokenization algorithm is depicted on the flowchart below. ``` Let us briefly describe the process: 1. If a Node is not supported by `Snippets`, then ignore it and proceed to the next one. -2. If a Node has no `Subgraph` parents, then replace it with `Subgraph` node and copy the initial Node to the `Subgraph's` body (which is in the `nGraph IR` form). -3. If a Node has a single `Subgraph` parent, then attach it to the `Subgraph`. It means copy the Node to the `Subgraph's` body, and remove it from the original `nGraph model`. Note that if the Node has more than one parent, corresponding parents' outputs will be connected with the updated `Subgraph` as shown on the diagram below. +2. If a Node has no `Subgraph` parents, then replace it with `Subgraph` node and copy the initial Node to the `Subgraph's` body (which is in the `OpenVINO IR` form). +3. If a Node has a single `Subgraph` parent, then attach it to the `Subgraph`. It means copy the Node to the `Subgraph's` body, and remove it from the original `OpenVINO model`. Note that if the Node has more than one parent, corresponding parents' outputs will be connected with the updated `Subgraph` as shown on the diagram below. 4. If a Node has multiple `Subgraph` parents, then they will be merged into a single `Subgraph` and the Node will be attached to it. ```mermaid graph LR @@ -409,7 +409,7 @@ If a `Constant` is not scalar, then it can't be tokenized since storing `Constan Please refer to the [collapse_subgraph.cpp](../src/pass/collapse_subgraph.cpp) to gain more insights on the tokenization process. There is however one more aspect of the tokenization process that is worth covering here. -As discussed in the **Plugin integration** section above, the `Tokenizer` is executed before the plugin converts the `nGraph model` to an internal graph representation. +As discussed in the **Plugin integration** section above, the `Tokenizer` is executed before the plugin converts the `OpenVINO model` to an internal graph representation. It means that the tokenized nodes will not be visible to the plugin (since they are hidden inside `Subrgaphs'` body functions), so they will be ignored by plugin optimization passes. In particular, the plugin won't be able to fuse the nodes using the OneDNN post-ops mechanism. This type of fusings is backend-specific, therefore can't be supported by `Snippets` directly, but it's still important from the performance perspective. @@ -424,15 +424,15 @@ Please, refer to the [snippets_mark_skipped.cpp](../../../plugins/intel_cpu/src/ As briefly discussed in the ***Architecture*** section, `Optimizer` consists of two major units: the first one performs data flow optimization, and the second one is focused on control flow. Note however that some data-flow-related passes can be performed only after the control flow optimizations, so the second unit modifies the dataflow as well. Nevertheless, we will refer to the units as `Data flow optimizer` and `Control flow optimizer` to reflect their main purpose. -Keep in mind that, as discussed above, the `Data flow optimizer` operates exclusively on the `nGraph IR`, while the `Control flow optimizer` works with the `Linear IR`. +Keep in mind that, as discussed above, the `Data flow optimizer` operates exclusively on the `OpenVINO IR`, while the `Control flow optimizer` works with the `Linear IR`. We will discuss these units in more detail below. #### Data flow optimizer Before `Data flow optimizer` can modify data flow, it needs to perform a preliminary stage called `Canonicalization`. To understand the stage's purpose we need to make a step back to the tokenization. - The `Tokenizer` saves a part of the initial `nGraph function` in `Subgraph's` body. - The problem is that the `nGraph function` has no information about data layouts that will be used by the `Subgraph's` parents during the `Execution` stage. + The `Tokenizer` saves a part of the initial `OpenVINO function` in `Subgraph's` body. + The problem is that the `OpenVINO function` has no information about data layouts that will be used by the `Subgraph's` parents during the `Execution` stage. This happens because the plugin assigns layouts on internal graph representation well after the tokenization is finished. The purpose of `Canonicalization` is to incorporate the plugin-defined input layouts into the body function. If an input's layout was changed to a blocked one, then the corresponding body input `Parameter` will be reshaped, and new shapes will be propagated through the body function. @@ -485,17 +485,17 @@ The managers will be executed on different stages of the pipeline to enable more #### Control flow optimizer As follows from its name, the main objective of `Control flow optimizer` is to manage and optimize control flow of the kernel. -Since the `nGraph IR` doesn't have an explicit control flow representation, a special control-flow-oriented `IR` was developed. +Since the `OpenVINO IR` doesn't have an explicit control flow representation, a special control-flow-oriented `IR` was developed. It is called `Linear IR` (or simply `LIR`), let's discuss it first, before we consider the transformation pipeline. ##### Linear Intermediate Representation `Linear IR` is specially designed to facilitate manipulations with control flow. -It is called linear, because it is essentially a sequence of `Expressions` (an analog of nGraph `Op`) that represents control flow. +It is called linear, because it is essentially a sequence of `Expressions` (an analog of OpenVINO `Op`) that represents control flow. So if `Expression 1` is followed by `Expression 2` in `LIR` then the code for `Expression 1` will be emitted before the code for `Expression 2`. Note that this doesn't necessarily mean that the `Expression 2` uses the result of `Expression 1`, they can be completely unrelated from the data flow standpoint. The only restriction here is that all the `Expression's` inputs must be ready by the time it is executed. -This restriction is the same as in `nGraph IR`, but an important distinction here is that `LIR` allows to permute `Expressions` while this data-dependency condition is fulfilled. +This restriction is the same as in `OpenVINO IR`, but an important distinction here is that `LIR` allows to permute `Expressions` while this data-dependency condition is fulfilled. So the `LIR` preserves data dependencies, but also allows for a more control on expressions' order that represents control flow. This is a brief rationale behind the linear `IR`, now let's move to the implementation. @@ -536,13 +536,13 @@ flowchart LR class consumers no-bg ``` -`LinearIR` is our graph representation, it's an analog to an nGraph model. +`LinearIR` is our graph representation, it's an analog to an OpenVINO model. It is simply a container for `Expressions`, the order of `Expressions` represents control flow. -`LIR` also incorporates a range of useful methods to manage the `Expressions`, for example `create_expression(...)` to build `Expressions` from nGraph nodes, or `replace_input(...)` to modify data dependencies between `Expressions`. +`LIR` also incorporates a range of useful methods to manage the `Expressions`, for example `create_expression(...)` to build `Expressions` from OpenVINO nodes, or `replace_input(...)` to modify data dependencies between `Expressions`. Please refer to the implementation in [linear_ir.cpp](../src/lowered/linear_ir.cpp) for more details. `Expression` is the main building block of a `Linear IR`. -It contains a pointer to the nGraph node it was created from and a pointer to the emitter it will be mapped to (which is null until `Expression::init_emitter(...)` is called). +It contains a pointer to the OpenVINO node it was created from and a pointer to the emitter it will be mapped to (which is null until `Expression::init_emitter(...)` is called). An `Expression` can have an arbitrary number of inputs and outputs, we will refer to them simply as ports. Every port can be uniquely identified by the `ExpressionPort` class. The `ExpressionPort` contains a pointer to the `Expression` which port it represents, the port type (`input` or `output`) and its index (input/output number). @@ -556,7 +556,7 @@ This information will be used by the control flow optimization pipeline to deter An `Expression` internally stores two separate vectors of input and output `PortDescriptors` which could be accessed by calling `get_input_port_descriptors()` or `get_input_port_descriptor(i)` (and similar for outputs). Finally, `PortConnectors` specify how the `Expression's` ports are connected. -Note that an `Expression` output can be connected to several inputs (like with nGraph nodes), So every `PortConnector` stores one source `ExpressionPort` and a set of consumer `ExpressionPorts` that can be accessed by the `get_source()` or `get_consumers()` methods, respectively. +Note that an `Expression` output can be connected to several inputs (like with OpenVINO nodes), So every `PortConnector` stores one source `ExpressionPort` and a set of consumer `ExpressionPorts` that can be accessed by the `get_source()` or `get_consumers()` methods, respectively. Like with `PortDescriptors`, an `Expression` stores input and output `PortConnectors` in two separate vectors accessed via `get_input_port_connector(i)` (or its output twin). An example on how `PortConnectors` can be used to move between `Expressions` is given on the right side of the above picture. @@ -622,7 +622,7 @@ Please see [assign_registers.cpp](../src/lowered/pass/assign_registers.cpp) and When the `Preparation` is finished, the `Generator` constructs target-specific emitters by calling `init_emitter(target)` method for every `Expression` in the `LinearIR`, where the `target` is a `TargetMachine` instance. The `TargetMachine` is a class that provides generator with target-specific information, such as supported instruction sets, vector register size etc. -`TargetMachine` also maps the nGraph's `DiscreteTypeInfo` (stored in the `Expression`) to the emitter that actually implements the operation. +`TargetMachine` also maps the OpenVINO's `DiscreteTypeInfo` (stored in the `Expression`) to the emitter that actually implements the operation. The mapping is done using the `jitters` map defined in [target_machine.hpp](../include/snippets/target_machine.hpp). In order for this mechanism to work, every `Snippets'` code generation backend should create emitter implementations derived from the `Emitter` base class defined in [emitter.hpp](../include/snippets/emitter.hpp). The backend then should create its own target machine class (derived from the common `TargetMachine`) and populate the `jitters` map, see the [cpu_generator.cpp](../../../plugins/intel_cpu/src/emitters/x64/cpu_generator.cpp) for an implementation example. diff --git a/src/common/snippets/include/snippets/emitter.hpp b/src/common/snippets/include/snippets/emitter.hpp index e1ff08abbf7da2..a2aa4923c2eef4 100644 --- a/src/common/snippets/include/snippets/emitter.hpp +++ b/src/common/snippets/include/snippets/emitter.hpp @@ -12,7 +12,6 @@ namespace ov { namespace snippets { -using code = const uint8_t *; using RegInfo = std::pair, std::vector>; /** diff --git a/src/common/snippets/include/snippets/generator.hpp b/src/common/snippets/include/snippets/generator.hpp index 1651679df15a22..32b44b9e6abc81 100644 --- a/src/common/snippets/include/snippets/generator.hpp +++ b/src/common/snippets/include/snippets/generator.hpp @@ -11,11 +11,32 @@ #include "snippets_isa.hpp" #include "snippets/lowered/linear_ir.hpp" -#include "snippets/lowered/pass/pass.hpp" +#include "snippets/shape_types.hpp" +#include "target_machine.hpp" namespace ov { namespace snippets { + +class Generator; +/** + * @interface LoweringResult + * @brief Holds all relevant information produced during lowering + * @param compiled_snippet pointer to interface class that encapsulates compiled binary code + * @param buffer_scratchpad_size the amount of additional memory required by the binary code to execute. + * Must be allocated and freed by the backend. + */ +class LoweringResult { + friend class Generator; + // Some emitters rely on other precompiled kernels. + // We need to keep the pointers to such emitters alive, so the kernels would still be accessible at runtime. + std::vector> m_saved_emitters{}; + +public: + std::shared_ptr compiled_snippet = nullptr; + size_t buffer_scratchpad_size = 0; +}; + /** * @interface Schedule * @brief Return scheduling information and pointer to generated kernel code @@ -23,27 +44,23 @@ namespace snippets { */ class Schedule { public: + Schedule() = default; /** - * @brief Default constructor - */ - Schedule() : work_size({}), is_flat(false), ptr(nullptr) {} - /** - * @brief Default to create schedule out of specific parameters - * @param ws work size for kernel execution - * @param f can this kernel be linearided to 1D range - * @param p pointer to generated code + * @brief Create schedule out of specific parameters + * @param domain work domain for kernel execution + * @param lr lowering result produced during code generation */ - Schedule(const ov::PartialShape& ws, bool f, code p) : work_size(ws), is_flat(f), ptr(p) {} + Schedule(std::vector&& domain, LoweringResult&& lr) : parallel_exec_domain(domain), lowering_result(lr) {} + Schedule(std::vector domain, LoweringResult&& lr) : parallel_exec_domain(std::move(domain)), lowering_result(lr) {} /** * @brief Returns callable instanse of code pointer */ template K get_callable() const { - return reinterpret_cast(const_cast(ptr)); + return reinterpret_cast(const_cast(lowering_result.compiled_snippet->get_code())); } - ov::PartialShape work_size {}; - bool is_flat {false}; - code ptr {nullptr}; + VectorDims parallel_exec_domain {}; + LoweringResult lowering_result {}; }; /** @@ -56,7 +73,7 @@ class Generator { /** * @brief Default constructor */ - Generator(const std::shared_ptr& t) : target(t), lowered_saved{} {} + Generator(const std::shared_ptr& t) : target(t) {} /** * @brief Default destructor */ @@ -66,17 +83,13 @@ class Generator { * @brief Allows to tweak the lowering process. */ /** - * @brief virtual method any specific implementation should implement - * @param m model in canonical for for table-based code generation - * @param config config with transformation and optimization parameters - * @param compile_params parameters for generated code - * @return pointer to generated code + * @brief generates executable code + * @param linear_ir lowered IR for code generation + * @param result variable to hande the result, only compiled_snippet and m_saved_emitters field will be modified + * @param compile_params compile-time parameters used for code generation + * @return void */ - struct LoweringResult { - LoweringResult(code c) : binary_code(c) {} - code binary_code = nullptr; - }; - LoweringResult generate(lowered::LinearIR& linear_ir, const lowered::Config& config, const void* compile_params = nullptr); + void generate(lowered::LinearIR& linear_ir, LoweringResult& result, const void* compile_params = nullptr) const; /** * @brief gets target machine @@ -100,17 +113,21 @@ class Generator { */ opRegType get_op_reg_type(const std::shared_ptr& op) const; + virtual std::shared_ptr clone() const = 0; + protected: /** * @brief gets register type by specific plugin op type * @return register type */ virtual opRegType get_specific_op_reg_type(const std::shared_ptr& op) const; + /** + * @brief returns true if an emitter can use precompiled kernel. + * @return bool + */ + virtual bool uses_precompiled_kernel(const std::shared_ptr& emitter) const { return false; } std::shared_ptr target; - // todo: we need to save lowered code to access compiled brgemm kernels on execution time (normally lowered is destructed by then). - // This is temporary solution, remove this when kernel caching is implemented. Don't forget to make generate const method. - lowered::LinearIR lowered_saved; }; } // namespace snippets diff --git a/src/common/snippets/include/snippets/itt.hpp b/src/common/snippets/include/snippets/itt.hpp index 0c594165ab5776..4a617f5a06e645 100644 --- a/src/common/snippets/include/snippets/itt.hpp +++ b/src/common/snippets/include/snippets/itt.hpp @@ -9,7 +9,7 @@ #pragma once -#include +#include namespace ov { namespace pass { @@ -26,7 +26,7 @@ OV_CC_DOMAINS(internal_op); /* * RUN_ON_FUNCTION_SCOPE macro allows to disable the run_on_function pass * MATCHER_SCOPE macro allows to disable the MatcherPass if matcher isn't applied - * INTERNAL_OP_SCOPE macro allows to disable parts of internal nGraph operations if they are not used + * INTERNAL_OP_SCOPE macro allows to disable parts of internal openvino operations if they are not used */ #if defined(SELECTIVE_BUILD_ANALYZER) diff --git a/src/common/snippets/include/snippets/lowered/expression.hpp b/src/common/snippets/include/snippets/lowered/expression.hpp index c5a1b2b8cb6f5e..289e52e0f59a73 100644 --- a/src/common/snippets/include/snippets/lowered/expression.hpp +++ b/src/common/snippets/include/snippets/lowered/expression.hpp @@ -74,7 +74,6 @@ class Expression : public std::enable_shared_from_this { std::vector m_loop_ids{}; std::shared_ptr m_shapeInference{nullptr}; }; -using ExpressionPtr = std::shared_ptr; class IOExpression : public Expression { friend class LinearIR; diff --git a/src/common/snippets/include/snippets/lowered/expression_factory.hpp b/src/common/snippets/include/snippets/lowered/expression_factory.hpp index bb238356dfa9d2..f179abf746c313 100644 --- a/src/common/snippets/include/snippets/lowered/expression_factory.hpp +++ b/src/common/snippets/include/snippets/lowered/expression_factory.hpp @@ -27,6 +27,13 @@ class LinearIR::ExpressionFactory { } return create(n, params...); } + template::value, bool>::type = true> + static ExpressionPtr shallow_copy(const std::shared_ptr& expr) { + if (const auto& io_expr = std::dynamic_pointer_cast(expr)) + return std::make_shared(*io_expr); + else + return std::make_shared(*expr); + } private: /* -- Default Builders - initialize input port connectors from parents and create new output port connectors themselves */ diff --git a/src/common/snippets/include/snippets/lowered/linear_ir.hpp b/src/common/snippets/include/snippets/lowered/linear_ir.hpp index fce7a80d9645b1..6d4a357914da39 100644 --- a/src/common/snippets/include/snippets/lowered/linear_ir.hpp +++ b/src/common/snippets/include/snippets/lowered/linear_ir.hpp @@ -21,6 +21,14 @@ class Config { // True if we should check runtime info for nodes to call specific needed transformations bool m_need_fill_tail_register = false; size_t m_loop_depth = 1; + // Some Subgraphs doesn't support domain optimization due to operations' semantics + bool m_enable_domain_optimization = false; + // Minimal advised work amount for parallel execution. + // Set by a backend, typically equals to the number of threads available on the machine. + size_t m_min_parallel_work_amount = 8; + // Minimal advised work amount that should be processed during one call of the executable produced by Subgraph::generate + // Set by a backend, should be large enough to compensate for the kernel call overheads + size_t m_min_kernel_work_amount = 256; }; /* The control flow of Snippets is built on Linear Intermediate Representation (Linear IR). @@ -46,6 +54,7 @@ class LinearIR { const container& get_ops() const {return m_expressions; } const io_container& get_IO_ops() const {return m_io_expressions; } Config get_config() {return m_config; } + void set_loop_depth(size_t loop_depth) { m_config.m_loop_depth = loop_depth; } const ExpressionPtr& get_expr_by_node(const std::shared_ptr& n) const; @@ -103,9 +112,27 @@ class LinearIR { using LoopManagerPtr = std::shared_ptr; const LoopManagerPtr& get_loop_manager() const { return m_loop_manager; } - const std::shared_ptr& get_shape_infer_factory() { return m_shape_infer_factory; } + + IShapeInferSnippets::Result shape_infer(const std::vector& input_shapes); + const std::shared_ptr& get_shape_infer_instance() const {return m_shape_infer; } + VectorDims get_master_shape() const; + LinearIR deep_copy() const; private: + std::shared_ptr m_shape_infer = nullptr; + + class LIRShapeInfer : public ShapeInferSnippetsNode { + public: + using IOExpression = lowered::IOExpression; + explicit LIRShapeInfer(container& body_exprs, io_container& io_exprs); + Result infer(const std::vector& input_shapes) override; + + private: + const std::shared_ptr m_exprs = nullptr; + std::vector> m_input_exprs {}; + std::vector> m_output_exprs {}; + }; + static ov::NodeVector get_ordered_ops(const std::shared_ptr& model); // Default ctor - can be called only from Linear IR initialization as default way ExpressionPtr create_expression(const std::shared_ptr& n, const std::shared_ptr& model = nullptr); diff --git a/src/common/snippets/include/snippets/lowered/pass/insert_broadcastmove.hpp b/src/common/snippets/include/snippets/lowered/pass/insert_broadcastmove.hpp new file mode 100644 index 00000000000000..fe4f9956d81c66 --- /dev/null +++ b/src/common/snippets/include/snippets/lowered/pass/insert_broadcastmove.hpp @@ -0,0 +1,28 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "pass.hpp" + +namespace ov { +namespace snippets { +namespace lowered { +namespace pass { + +/** + * @interface InsertMovebroadcast + * @brief Injects explicit Movebroadcast operations when the most varying dim is broadcasted + * @ingroup snippets + */ +class InsertBroadcastMove : public Pass { +public: + OPENVINO_RTTI("InsertBroadcastMove", "Pass") + bool run(LinearIR& linear_ir) override; +}; + +} // namespace pass +} // namespace lowered +} // namespace snippets +} // namespace ov diff --git a/src/common/snippets/include/snippets/lowered/pass/optimize_domain.hpp b/src/common/snippets/include/snippets/lowered/pass/optimize_domain.hpp new file mode 100644 index 00000000000000..4ae68fc38cf37e --- /dev/null +++ b/src/common/snippets/include/snippets/lowered/pass/optimize_domain.hpp @@ -0,0 +1,68 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "snippets/lowered/pass/pass.hpp" +#include "snippets/shape_types.hpp" + +namespace ov { +namespace snippets { +namespace lowered { +namespace pass { + +/** + * @interface OptimizeDomain + * @brief Collapse input/output dimensions to balance parallel/per-thread load. The pass consists of two steps: + * The pass collapses two last dimensions while none of them is broadcasted and the resulting dim size + * 1. Dimension collapsing: If none of the last two dimensions are broadcasted, the last dimension's size + * is less than min_kernel_work_amount and the remaining dimensions provide work amount larger than + * min_parallel_work_amount (min_kernel_work_amount and min_parallel_work_amount specified in LireanIR config), + * then these two dimensions are collapsed into one and the collapsing attempt is repeated. + * 2. Tile rank increment: Tile rank is the rank of a tensor that processed during one call. If all except + * for the last two dimensions provide work_amount larger than min_parallel_work_amount, then tile_rank + * is incremented. This effectively increases kernel work_amount. + * Examples of graphs before and after this transformations are depicted below. + * @param tile_rank (taken by reference) rank of a tensor that processed during one call. Incremented if dimensions are collapsed. + * @ingroup snippets + */ +// Example: +// min_jit_work_amount = 256 +// min_parallel_work_amount = 4 +// +// Before OptimizeDomain | After OptimizeDomain +// ------------------------------------------------------------------- +// tile_rank = 1 | tile_rank = 2 +// | +// in1 in2 | in1 in2 +// [14, 15, 16, 17] [14, 15, 16, 17] | [1, 14, 15, 272] [1, 14, 15, 272] +// \ / | \ / +// Add | Add +// [14, 15, 16, 17] | [1, 14, 15, 272] +// | | | +// Result | Result +// [14, 15, 16, 17] | [1, 14, 15, 272] + +class OptimizeDomain : public snippets::lowered::pass::Pass { +public: + OPENVINO_RTTI("OptimizeDomain", "Pass") + explicit OptimizeDomain(size_t& tile_rank); + bool run(LinearIR& linear_ir) override; + +private: + size_t& m_tile_rank; + static size_t optimize(std::vector& input_shapes, + VectorDims& master_shape, + size_t total_work_amount, + size_t min_parallel_work_amount, + size_t min_jit_work_amount); + inline static bool can_increase_jit_work_amount(const VectorDims& master_shape, + size_t min_parallel_work_amount, + size_t total_work_amount); +}; + +} // namespace pass +} // namespace lowered +} // namespace snippets +} // namespace ov \ No newline at end of file diff --git a/src/common/snippets/include/snippets/lowered/pass/softmax_decomposition.hpp b/src/common/snippets/include/snippets/lowered/pass/softmax_decomposition.hpp index 8b5634ebb29fa4..795dc0d3725f1c 100644 --- a/src/common/snippets/include/snippets/lowered/pass/softmax_decomposition.hpp +++ b/src/common/snippets/include/snippets/lowered/pass/softmax_decomposition.hpp @@ -18,8 +18,8 @@ namespace pass { */ class SoftmaxDecomposition : public Pass { public: - explicit SoftmaxDecomposition(size_t vector_size); OPENVINO_RTTI("SoftmaxDecomposition", "Pass") + explicit SoftmaxDecomposition(size_t vector_size); bool run(LinearIR& linear_ir) override; private: diff --git a/src/common/snippets/include/snippets/lowered/pass/validate_shapes.hpp b/src/common/snippets/include/snippets/lowered/pass/validate_shapes.hpp new file mode 100644 index 00000000000000..08243c96beedf5 --- /dev/null +++ b/src/common/snippets/include/snippets/lowered/pass/validate_shapes.hpp @@ -0,0 +1,31 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "pass.hpp" + +#include "snippets/lowered/loop_manager.hpp" + +namespace ov { +namespace snippets { +namespace lowered { +namespace pass { + +/** + * @interface ValidateShapes + * @brief The pass checks that there are no dynamic shapes in the IR + * @ingroup snippets + */ +class ValidateShapes : public Pass { +public: + OPENVINO_RTTI("ValidateShapes", "Pass") + ValidateShapes() = default; + bool run(LinearIR& linear_ir) override; +}; + +} // namespace pass +} // namespace lowered +} // namespace snippets +} // namespace ov diff --git a/src/common/snippets/include/snippets/lowered/port_descriptor.hpp b/src/common/snippets/include/snippets/lowered/port_descriptor.hpp index ce3e0c641f254a..551ef1907037ab 100644 --- a/src/common/snippets/include/snippets/lowered/port_descriptor.hpp +++ b/src/common/snippets/include/snippets/lowered/port_descriptor.hpp @@ -38,9 +38,9 @@ class PortDescriptor { PortDescriptor(VectorDims shape, VectorDims subtensor_shape, std::vector layout = {}); PortDescriptor() = default; - VectorDims get_shape() const {return m_tensor_shape;} - VectorDims get_subtensor() const {return m_subtensor_shape;} - std::vector get_layout() const {return m_layout;} + const VectorDims& get_shape() const {return m_tensor_shape;} + const VectorDims& get_subtensor() const {return m_subtensor_shape;} + const std::vector& get_layout() const {return m_layout;} size_t get_reg() const { return m_reg; } void set_shape(const VectorDims& tensor) { m_tensor_shape = tensor; } diff --git a/src/common/snippets/include/snippets/op/brgemm.hpp b/src/common/snippets/include/snippets/op/brgemm.hpp index 50cca60bbbc29d..8ba681fb8e9353 100644 --- a/src/common/snippets/include/snippets/op/brgemm.hpp +++ b/src/common/snippets/include/snippets/op/brgemm.hpp @@ -39,14 +39,6 @@ class Brgemm : public MemoryAccess { bool has_evaluate() const override { return false; } - class ShapeInfer : public IShapeInferSnippets { - protected: - std::vector> m_io_layouts; - public: - explicit ShapeInfer(const std::shared_ptr& n); - Result infer(const std::vector& input_shapes) override; - }; - protected: ov::element::Type get_output_type() const; std::vector get_planar_input_shapes(const std::vector>& inputs) const; diff --git a/src/common/snippets/include/snippets/op/buffer.hpp b/src/common/snippets/include/snippets/op/buffer.hpp index 7a644644dd7417..9f522ed3d45688 100644 --- a/src/common/snippets/include/snippets/op/buffer.hpp +++ b/src/common/snippets/include/snippets/op/buffer.hpp @@ -44,9 +44,10 @@ class Buffer : public ov::op::Op { size_t get_id() const { return m_id; } Type get_type() const { return m_type; } - ov::Shape get_allocation_shape() const { return m_shape; } int64_t get_offset() const { return m_offset; } void set_id(size_t id) { m_id = id; } + const ov::Shape& get_allocation_shape() const { return m_shape; } + void set_allocation_shape(const ov::Shape& allocation_shape) { m_shape = allocation_shape; } void set_offset(int64_t offset) { m_offset = offset; } size_t get_byte_size() const; diff --git a/src/common/snippets/include/snippets/op/loop.hpp b/src/common/snippets/include/snippets/op/loop.hpp index fefc1368bb4307..1fd51649fc65d1 100644 --- a/src/common/snippets/include/snippets/op/loop.hpp +++ b/src/common/snippets/include/snippets/op/loop.hpp @@ -6,7 +6,7 @@ #include "openvino/op/op.hpp" #include "snippets/emitter.hpp" -#include "ngraph/op/parameter.hpp" +#include "openvino/op/parameter.hpp" namespace ov { namespace snippets { diff --git a/src/common/snippets/include/snippets/op/powerstatic.hpp b/src/common/snippets/include/snippets/op/powerstatic.hpp index 5a1d0abb23ffb4..d76fa48e0601aa 100644 --- a/src/common/snippets/include/snippets/op/powerstatic.hpp +++ b/src/common/snippets/include/snippets/op/powerstatic.hpp @@ -5,7 +5,6 @@ #pragma once #include "openvino/op/op.hpp" -#include #include namespace ov { diff --git a/src/common/snippets/include/snippets/op/rank_normalization.hpp b/src/common/snippets/include/snippets/op/rank_normalization.hpp new file mode 100644 index 00000000000000..c1ed530ce05832 --- /dev/null +++ b/src/common/snippets/include/snippets/op/rank_normalization.hpp @@ -0,0 +1,54 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/op/op.hpp" +#include "snippets/shape_inference/shape_inference.hpp" + +namespace ov { +namespace snippets { +namespace op { + +/** + * @interface RankNormalization + * @brief Generated by Canonicalization for rank normalization purposes. It can prepend input shapes with seve1s only first or last dimensions. + * @arg num_prepend - num `1`s that will be inserted at the beginning of the input shape. Any value is allowed. + * @arg num_append - num `1`s that will be inserted at the end of the input shape. Could be either 0 (default) or 1; + * @ingroup snippets + */ + // Note that technically the same goal could be achieved using op::Unsqueeze operation, + // but RankNormalization has a much narrower semantics, and hence allows for an easier control and a more efficient shape infer. + // +class RankNormalization : public ov::op::Op { +public: + OPENVINO_OP("RankNormalization", "SnippetsOpset"); + + RankNormalization() = default; + RankNormalization(const Output& data, size_t num_prepend, size_t num_append); + + 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; + + size_t get_num_append() const { return m_num_append; } + size_t get_num_prepend() const { return m_num_prepend; } + + class ShapeInfer : public IShapeInferSnippets { + size_t m_num_prepend = 0; + size_t m_num_append = 0; + public: + explicit ShapeInfer(const std::shared_ptr& n); + IShapeInferSnippets::Result + infer(const std::vector& input_shapes) override; + }; + +private: + size_t m_num_prepend = 0; + size_t m_num_append = 0; +}; + +} // namespace op +} // namespace snippets +} // namespace ov diff --git a/src/common/snippets/include/snippets/op/scalar.hpp b/src/common/snippets/include/snippets/op/scalar.hpp index 43ecb1aad671cc..2720ffdc062091 100644 --- a/src/common/snippets/include/snippets/op/scalar.hpp +++ b/src/common/snippets/include/snippets/op/scalar.hpp @@ -5,7 +5,7 @@ #pragma once #include "openvino/op/op.hpp" -#include "ngraph/op/constant.hpp" +#include "openvino/op/constant.hpp" namespace ov { namespace snippets { diff --git a/src/common/snippets/include/snippets/op/subgraph.hpp b/src/common/snippets/include/snippets/op/subgraph.hpp index a357c52266bda3..b17031e2a67d1c 100644 --- a/src/common/snippets/include/snippets/op/subgraph.hpp +++ b/src/common/snippets/include/snippets/op/subgraph.hpp @@ -12,6 +12,7 @@ #include "openvino/core/rt_info.hpp" #include "snippets/pass_manager.hpp" #include "snippets/shape_inference/shape_inference.hpp" +#include "snippets/lowered/pass/pass.hpp" #include "snippets/generator.hpp" @@ -68,7 +69,8 @@ class Subgraph : public ov::op::util::SubGraphOp { // // D = < 1, 3, 17, 15, 32> < 0, 1, 2, 3, 4> // E = < 1, 3, 17, 1, 32> < 0, 1, 2, 3, 4> - using BlockedShape = std::tuple; + using Layout = std::vector; + using BlockedShape = std::pair; using BlockedShapeVector = std::vector; Subgraph() = default; @@ -94,41 +96,36 @@ class Subgraph : public ov::op::util::SubGraphOp { const std::shared_ptr& get_generator() const { return m_generator; } std::shared_ptr& get_generator() { return m_generator; } - size_t get_buffer_scratchpad_size() const { return m_buffer_scratchpad; } size_t get_virtual_port_count() const { return m_virtual_port_count; } bool is_quantized() const { return config.m_is_quantized; } bool has_domain_sensitive_ops() const { return config.m_has_domain_sensitive_ops; } - snippets::Schedule generate(const BlockedShapeVector& output_shapes, - const BlockedShapeVector& input_shapes, - const std::vector& data_flow_passes, - const lowered::pass::PassPipeline& control_flow_passes_pre_common, - const lowered::pass::PassPipeline& control_flow_passes_post_common, - const std::shared_ptr& shape_infer_factory = nullptr, - const void* compile_params = nullptr); - snippets::Schedule generate(const BlockedShapeVector& output_shapes, const BlockedShapeVector& input_shapes, const void* compile_params = nullptr); - snippets::Schedule generate(const std::vector& data_flow_passes, - const lowered::pass::PassPipeline& control_flow_passes_pre_common, - const lowered::pass::PassPipeline& control_flow_passes_post_common, - const std::shared_ptr& shape_infer_factory = nullptr, + + snippets::Schedule generate(const BlockedShapeVector& blocked_input_shapes = {}, + const std::vector& input_precisions = {}, + const std::vector& output_precisions = {}, + const std::vector& data_flow_passes = {}, + const lowered::pass::PassPipeline& control_flow_passes_pre_common = {}, + const lowered::pass::PassPipeline& control_flow_passes_post_common = {}, + const std::shared_ptr& factory = nullptr, const void* compile_params = nullptr); - snippets::Schedule generate(const void* compile_params = nullptr); - ov::PartialShape canonicalize(const BlockedShapeVector& output_shapes, const BlockedShapeVector& input_shapes); - ov::PartialShape canonicalized_body_shape_infer(const BlockedShapeVector& input_shapes); - std::vector reshape_body(const std::vector& input_shapes); - std::vector reshape_body(const std::vector& input_shapes); + snippets::Schedule generate_from_linear_ir(const lowered::pass::PassPipeline& backend_passes_pre_common = {}, + const lowered::pass::PassPipeline& backend_passes_post_common = {}, + const void* compile_params = nullptr) const; IShapeInferSnippets::Result shape_infer(const std::vector& input_shapes); // plugin sets generator for a snippet to some specific generator. // it's going to be replaced with Jitters table later void set_generator(std::shared_ptr generator); void set_tile_rank(size_t newRank) {tileRank = newRank;} - void set_virtual_port_count(const size_t count); + void set_virtual_port_count(size_t count); + void set_min_jit_work_amount(size_t jit_work_amount); + void set_min_parallel_work_amount(size_t parallel_work_amount); void print() const; void serialize() const; - void set_master_shape(ov::PartialShape new_shape) {master_shape = std::move(new_shape);} + VectorDims infer_master_shape(); static auto wrap_node_as_subgraph(const std::shared_ptr& node) -> std::shared_ptr; static void fill_empty_output_names(const Output& target_output_node, const Output& replacement_output_node); @@ -141,28 +138,30 @@ class Subgraph : public ov::op::util::SubGraphOp { // Return estimated unique buffer count (upper bound). It's needed for tokenization static auto get_estimated_buffer_count(const ov::NodeVector& ops) -> size_t; static auto is_domain_sensitive_op(const std::shared_ptr& op) -> bool; + + void data_flow_transformations(const BlockedShapeVector& blocked_input_shapes = {}, + const std::vector& input_precisions = {}, + const std::vector& output_precisions = {}, + const std::vector& = {}); std::shared_ptr - convert_body_to_linear_ir(const std::shared_ptr& shape_infer_factory = std::make_shared()) const; + convert_body_to_linear_ir(const std::shared_ptr& shape_infer_factory = std::make_shared()); + std::shared_ptr clone() const; private: - void align_element_types(const BlockedShapeVector& outputShapes, const BlockedShapeVector& inputShapes); - void data_flow_transformations(const std::vector& backend_passes); void control_flow_transformations(lowered::LinearIR& linear_ir, + LoweringResult& lowering_result, const lowered::pass::PassPipeline& backend_passes_pre_common, - const lowered::pass::PassPipeline& backend_passes_post_common); + const lowered::pass::PassPipeline& backend_passes_post_common) const; void init_config(); // Count of Subgraph virtual ports: // - Potential non-scalar Constants that will be created after some transformations (At the moment it's relevant only for FakeQuantize decomposition) // NOTE: To avoid overheads in each calculation of this count (for example, in validate_and_type_infer()), // we should MANUALLY calculate it where it needed. size_t m_virtual_port_count = 0; - size_t m_buffer_scratchpad = 0lu; Shape exec_domain = {}; std::shared_ptr m_generator = nullptr; - ov::PartialShape master_shape; size_t tileRank = 0; // set by plugin to specify the number of dimensions processed in a single kernel call - size_t maxInputRank = 0; std::vector appendOnesForCanonical; std::shared_ptr m_linear_ir = nullptr; @@ -178,32 +177,20 @@ class Subgraph : public ov::op::util::SubGraphOp { // True if body has operations that don't support plugin-side domain optimizations // (e.g. Transpose, Softmax, MatMul in general doesn't support dimensions collapsing) bool m_has_domain_sensitive_ops = false; + // Minimal advised work amount for parallel execution. + // Set by a backend, typically equals to the number of threads available on the machine. + size_t m_min_parallel_work_amount = 8; + // Minimal advised work amount every JIT kernel should process during one execution call + // Set by a backend, should be large enough to compensate for the kernel call overheads + size_t m_min_jit_work_amount = 256; } config; - class ShapeInferSnippetsNode : public IShapeInferSnippets { - public: - const Result& get_last_result() {return m_last_result; } - protected: - Result m_last_result{{}, ShapeInferStatus::success}; - }; - std::shared_ptr m_shape_infer = nullptr; - class NgraphShapeInfer : public ShapeInferSnippetsNode { - std::shared_ptr m_ngraph_body; - ParameterVector m_parameters; - ResultVector m_results; - public: - explicit NgraphShapeInfer(const std::shared_ptr& body); - Result infer(const std::vector& input_shapes) override; - }; - class LIRShapeInfer : public ShapeInferSnippetsNode { - using IOExpression = lowered::IOExpression; - std::shared_ptr m_lir_body; - std::vector> m_param_exprs; - std::vector> m_result_exprs; + class OVShapeInfer : public ShapeInferSnippetsNode { + std::shared_ptr m_ov_body; public: - explicit LIRShapeInfer(const std::shared_ptr& body); + explicit OVShapeInfer(const std::shared_ptr& body); Result infer(const std::vector& input_shapes) override; }; }; diff --git a/src/common/snippets/include/snippets/pass/align_element_types.hpp b/src/common/snippets/include/snippets/pass/align_element_types.hpp new file mode 100644 index 00000000000000..9a8a5ff880aeab --- /dev/null +++ b/src/common/snippets/include/snippets/pass/align_element_types.hpp @@ -0,0 +1,34 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/pass/pass.hpp" +#include "transformations_visibility.hpp" +#include "snippets/op/subgraph.hpp" + +namespace ov { +namespace snippets { +namespace pass { + +/** + * @interface AlignElementTypes + * @brief Align body precision with expected input/output precision. Insert op::ConvertSaturation if necessary. + * @ingroup snippets + */ +class AlignElementTypes: public ov::pass::ModelPass { +public: + OPENVINO_RTTI("AlignElementTypes"); + AlignElementTypes(std::vector input_precisions, + std::vector output_precisions); + bool run_on_model(const std::shared_ptr& m) override; + +private: + std::vector m_input_precisions; + std::vector m_output_precisions; +}; + +} // namespace pass +} // namespace snippets +} // namespace ov diff --git a/src/common/snippets/include/snippets/pass/canonicalization.hpp b/src/common/snippets/include/snippets/pass/canonicalization.hpp new file mode 100644 index 00000000000000..f57218328ca57c --- /dev/null +++ b/src/common/snippets/include/snippets/pass/canonicalization.hpp @@ -0,0 +1,39 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/pass/pass.hpp" +#include "transformations_visibility.hpp" +#include "snippets/op/subgraph.hpp" +#include "snippets/shape_types.hpp" + +namespace ov { +namespace snippets { +namespace pass { + +/** + * @interface Canonicalization + * @brief Canonicalization inserts RankNormalization (ov::op::Unsqueeze analogue) operations to account for: + * - input ranks mismatch, then inputs with smaller ranks are prepeneded with 1 + * - layouts mismatch (only planar + blocked is supported), planar shapes are postpended with 1 + * @ingroup snippets + */ +class Canonicalization: public ov::pass::ModelPass { +public: + OPENVINO_RTTI("Canonicalization"); + using BlockedShapeVector = op::Subgraph::BlockedShapeVector; + using Layout = std::vector; + explicit Canonicalization(const BlockedShapeVector& blocked_input_shapes); + bool run_on_model(const std::shared_ptr& m) override; + +private: + std::vector m_in_shapes; + std::vector m_in_layouts; + bool m_has_dynamic_inputs = false; +}; + +} // namespace pass +} // namespace snippets +} // namespace ov diff --git a/src/common/snippets/include/snippets/pass/propagate_precision.hpp b/src/common/snippets/include/snippets/pass/propagate_precision.hpp index 1f5bd0cf9542bf..6f805cb1b68808 100644 --- a/src/common/snippets/include/snippets/pass/propagate_precision.hpp +++ b/src/common/snippets/include/snippets/pass/propagate_precision.hpp @@ -5,7 +5,7 @@ #pragma once #include -#include +#include "openvino/pass/pass.hpp" #include "snippets/generator.hpp" namespace ov { diff --git a/src/common/snippets/include/snippets/shape_inference/shape_infer_instances.hpp b/src/common/snippets/include/snippets/shape_inference/shape_infer_instances.hpp index 0ca0668111b3cf..af69ad905111e8 100644 --- a/src/common/snippets/include/snippets/shape_inference/shape_infer_instances.hpp +++ b/src/common/snippets/include/snippets/shape_inference/shape_infer_instances.hpp @@ -8,6 +8,11 @@ namespace ov { namespace snippets { + +bool broadcast_merge_into(VectorDims& dst, const VectorDims& src, const ov::op::AutoBroadcastSpec& autob = ov::op::AutoBroadcastType::NUMPY); + +bool merge_into(VectorDims& dst, const VectorDims& src); + class NumpyBroadcastShapeInfer : public IShapeInferSnippets { public: Result infer(const std::vector& input_shapes) override; @@ -56,5 +61,12 @@ class HorizonOpShapeInfer : public IShapeInferSnippets { Result infer(const std::vector& input_shapes) override; }; +class BrgemmShapeInfer : public IShapeInferSnippets { + std::vector> m_io_layouts; +public: + explicit BrgemmShapeInfer(const std::shared_ptr& n); + Result infer(const std::vector& input_shapes) override; +}; + } // namespace snippets } // namespace ov diff --git a/src/common/snippets/include/snippets/shape_inference/shape_inference.hpp b/src/common/snippets/include/snippets/shape_inference/shape_inference.hpp index ad2145d9f59bfc..9066d571cbb4e6 100644 --- a/src/common/snippets/include/snippets/shape_inference/shape_inference.hpp +++ b/src/common/snippets/include/snippets/shape_inference/shape_inference.hpp @@ -37,6 +37,18 @@ class IShapeInferSnippets { virtual Result infer(const std::vector& input_shapes) = 0; }; +/** + * Shape inference class for Subgraph node (both openvino and Linear IRs). + * It stores the result of the last shape inference, so it can be reused in optimization pipeline. + * + */ +class ShapeInferSnippetsNode : public IShapeInferSnippets { +public: + const Result& get_last_result() {return m_last_result; } +protected: + Result m_last_result{{}, ShapeInferStatus::success}; +}; + class IShapeInferSnippetsFactory { public: // Helper type to define specific Makers map values. diff --git a/src/common/snippets/include/snippets/snippets_isa.hpp b/src/common/snippets/include/snippets/snippets_isa.hpp index 87579feebb1796..ba85ae68eeb634 100644 --- a/src/common/snippets/include/snippets/snippets_isa.hpp +++ b/src/common/snippets/include/snippets/snippets_isa.hpp @@ -24,6 +24,7 @@ #include "op/loop.hpp" #include "op/brgemm.hpp" #include "op/vector_buffer.hpp" +#include "op/rank_normalization.hpp" namespace ov { namespace snippets { diff --git a/src/common/snippets/include/snippets/snippets_isa_tbl.hpp b/src/common/snippets/include/snippets/snippets_isa_tbl.hpp index b0a87a8a82a1f9..351770bdab746f 100644 --- a/src/common/snippets/include/snippets/snippets_isa_tbl.hpp +++ b/src/common/snippets/include/snippets/snippets_isa_tbl.hpp @@ -22,6 +22,7 @@ OV_OP(Store, ov::snippets::op) OV_OP(BroadcastMove, ov::snippets::op) OV_OP(Scalar, ov::snippets::op) OV_OP(Nop, ov::snippets::op) +OV_OP(RankNormalization, ov::snippets::op) // Layout-oblivious from opset1 diff --git a/src/common/snippets/include/snippets/target_machine.hpp b/src/common/snippets/include/snippets/target_machine.hpp index a4d15463f2972a..d42779bcd7153c 100644 --- a/src/common/snippets/include/snippets/target_machine.hpp +++ b/src/common/snippets/include/snippets/target_machine.hpp @@ -13,6 +13,15 @@ namespace ov { namespace snippets { + +struct CompiledSnippet { + virtual const uint8_t* get_code() const = 0; + virtual size_t get_code_size() const = 0; + virtual bool empty() const = 0; + virtual ~CompiledSnippet() = default; +}; +using CompiledSnippetPtr = std::shared_ptr; + typedef std::pair(const lowered::ExpressionPtr&)>, std::function(const std::shared_ptr&)>> jitters_value; @@ -33,7 +42,7 @@ class TargetMachine { * @brief finalizes code generation * @return generated kernel binary */ - virtual code get_snippet() const = 0; + virtual CompiledSnippetPtr get_snippet() = 0; /** * @brief gets number of lanes supported by target's vector ISA diff --git a/src/common/snippets/include/snippets/utils.hpp b/src/common/snippets/include/snippets/utils.hpp index 525de3e03b2118..d10930125e0ed0 100644 --- a/src/common/snippets/include/snippets/utils.hpp +++ b/src/common/snippets/include/snippets/utils.hpp @@ -58,6 +58,7 @@ constexpr inline bool implication(bool cause, bool cond) { VectorDims get_planar_vdims(const VectorDims& shape, const std::vector& layout); VectorDims get_planar_vdims(const snippets::lowered::PortDescriptorPtr& port_desc); VectorDims get_planar_vdims(const snippets::lowered::ExpressionPort& expr_port); +bool is_dynamic_vdims(const VectorDims& shape); } // namespace utils } // namespace snippets diff --git a/src/common/snippets/src/generator.cpp b/src/common/snippets/src/generator.cpp index 1d1d733277f99b..cede4c4a6e532c 100644 --- a/src/common/snippets/src/generator.cpp +++ b/src/common/snippets/src/generator.cpp @@ -15,7 +15,7 @@ namespace ov { namespace snippets { -Generator::LoweringResult Generator::generate(lowered::LinearIR& linear_ir, const lowered::Config& config, const void* compile_params) { +void Generator::generate(lowered::LinearIR& linear_ir, LoweringResult& result, const void* compile_params) const { OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::Generator::generate") OV_ITT_TASK_CHAIN(GENERATE, ov::pass::itt::domains::SnippetsTransform, "Snippets::Generator", "::Transformations") if (!target->is_supported()) @@ -28,7 +28,6 @@ Generator::LoweringResult Generator::generate(lowered::LinearIR& linear_ir, cons lowered_pipeline.register_pass(reg_type_mapper); lowered_pipeline.register_pass(); lowered_pipeline.run(linear_ir); - linear_ir.init_emitters(target); OV_ITT_TASK_NEXT(GENERATE, "::EmitCode") @@ -45,12 +44,15 @@ Generator::LoweringResult Generator::generate(lowered::LinearIR& linear_ir, cons } OV_ITT_TASK_NEXT(GENERATE, "::GetSnippet") - // todo: we save lowered to access compiled brgemm kernels on execution time (normally lowered is destructed by then) - // remove this when kernel caching is implemented. Don't forget to make generate const method. - if (config.m_save_expressions) - lowered_saved = linear_ir; - - return { target->get_snippet() }; + // Note: some emitters use precompiled kernels. They need to be saved, so the kernels are accessible at runtime. + if (linear_ir.get_config().m_save_expressions) { + for (const auto& expr : linear_ir) { + const auto& emitter = expr->get_emitter(); + if (uses_precompiled_kernel(emitter)) + result.m_saved_emitters.emplace_back(emitter); + } + } + result.compiled_snippet = target->get_snippet(); } std::shared_ptr Generator::get_target_machine() const { @@ -63,7 +65,8 @@ Generator::opRegType Generator::get_op_reg_type(const std::shared_ptr& op) std::dynamic_pointer_cast(op) || std::dynamic_pointer_cast(op) || std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op)) + std::dynamic_pointer_cast(op) || + std::dynamic_pointer_cast(op)) return gpr2gpr; else if (std::dynamic_pointer_cast(op) || std::dynamic_pointer_cast(op)) diff --git a/src/common/snippets/src/lowered/expression.cpp b/src/common/snippets/src/lowered/expression.cpp index 53ab34049bdceb..e5ebfee952ace5 100644 --- a/src/common/snippets/src/lowered/expression.cpp +++ b/src/common/snippets/src/lowered/expression.cpp @@ -112,6 +112,7 @@ ExpressionPort Expression::get_output_port(size_t i) { } void Expression::updateShapes() { + OPENVINO_ASSERT(m_shapeInference, "Attempt to UpdateShapes without initialized shapeInference"); IShapeInferSnippets::Result result; try { std::vector input_shapes; @@ -121,11 +122,10 @@ void Expression::updateShapes() { input_shapes.reserve(in_connectors.size()); for (size_t i = 0; i < in_connectors.size(); i++) { - const auto& src_port = in_connectors[i]->get_source(); - const auto i_shape = src_port.get_descriptor_ptr()->get_shape(); - // todo: do we really need to store the same shape twice in parent's out_port_desc and this in_port_descs - in_descriptors[i]->set_shape(i_shape); - input_shapes.emplace_back(i_shape); + const auto& src_port_desc = in_connectors[i]->get_source().get_descriptor_ptr(); + in_descriptors[i]->set_shape(src_port_desc->get_shape()); + // Note that input_shape is a reference, so we should always bind it to an object with a longer lifetime + input_shapes.emplace_back(in_descriptors[i]->get_shape()); } result = m_shapeInference->infer(input_shapes); @@ -133,6 +133,8 @@ void Expression::updateShapes() { catch (const std::exception& exp) { OPENVINO_THROW("Shape inference of " + (get_node()->get_friendly_name()) + " failed: " + exp.what()); } + OPENVINO_ASSERT(result.status == ShapeInferStatus::success, + "Shape inference of " + (get_node()->get_friendly_name()) + " didn't return success status"); const auto& out_descriptors = get_output_port_descriptors(); OPENVINO_ASSERT(result.dims.size() == out_descriptors.size(), "shapeInference call returned invalid number of output shapes"); for (size_t i = 0; i < out_descriptors.size(); i++) diff --git a/src/common/snippets/src/lowered/expression_factory.cpp b/src/common/snippets/src/lowered/expression_factory.cpp index 34651fd6dbbbd2..cd5cfe0db74c53 100644 --- a/src/common/snippets/src/lowered/expression_factory.cpp +++ b/src/common/snippets/src/lowered/expression_factory.cpp @@ -69,7 +69,7 @@ ExpressionPtr LinearIR::ExpressionFactory::create(const std::shared_ptr(new IOExpression(res, model->get_result_index(res), linear_ir.m_shape_infer_factory)); create_expression_inputs(linear_ir, expr); - // The Result node don't need output port (because of sense of the node). But each node in ngraph must have one output at least. + // The Result node don't need output port (because of sense of the node). But each node in openvino must have one output at least. // The port descriptors are automatically created in constructor. We manually clean output ports. expr->m_output_port_descriptors.clear(); expr->validate(); @@ -110,7 +110,7 @@ ExpressionPtr LinearIR::ExpressionFactory::create(const std::shared_ptr(last_input.get_expr()->get_node()), "LoopEnd expression expects LoopBegin on last input"); expr->m_input_port_descriptors[inputs.size() - 1] = last_input.get_descriptor_ptr()->clone(); init_expression_inputs(expr, inputs); - // The LoopEnd node don't need output port (because of sense of the node). But each node in ngraph must have one output at least. + // The LoopEnd node don't need output port (because of sense of the node). But each node in openvino must have one output at least. // The port descriptors are automatically created in constructor. We manually clean output ports. expr->m_output_port_descriptors.clear(); expr->validate(); diff --git a/src/common/snippets/src/lowered/linear_ir.cpp b/src/common/snippets/src/lowered/linear_ir.cpp index cc5e5c2fce621e..adf3894f71b8b7 100644 --- a/src/common/snippets/src/lowered/linear_ir.cpp +++ b/src/common/snippets/src/lowered/linear_ir.cpp @@ -9,10 +9,10 @@ #include "snippets/lowered/loop_manager.hpp" #include "snippets/lowered/expression_factory.hpp" #include "snippets/op/serialization_node.hpp" -#include "snippets/utils.hpp" #include "openvino/core/graph_util.hpp" #include "openvino/core/type.hpp" +#include "snippets/utils.hpp" namespace ov { namespace snippets { @@ -41,6 +41,7 @@ LinearIR::LinearIR(const std::shared_ptr& model, const std::shared_pt last_param = it; } } + m_shape_infer = std::make_shared(m_expressions, m_io_expressions); } ExpressionPtr LinearIR::create_expression(const std::shared_ptr& n, const std::shared_ptr& model) { @@ -121,6 +122,59 @@ LinearIR::container LinearIR::deep_copy_range(LinearIR::container::const_iterato return result; } +LinearIR LinearIR::deep_copy() const { + // todo: implement the same functionality using standard copy constructor + auto clone_ports_descriptors = [](std::vector& ports) { + std::for_each(ports.begin(), ports.end(), [](PortDescriptorPtr& pd) { pd = pd->clone(); }); + }; + const auto& original_lir = *this; + LinearIR new_lir; + new_lir.m_config = original_lir.m_config; + new_lir.m_shape_infer = original_lir.m_shape_infer; + NodeVector original_nodes; + original_nodes.reserve(original_lir.m_expressions.size()); + std::unordered_map connectors_map; + for (const auto& orig_expr : original_lir) { + original_nodes.push_back(orig_expr->get_node()); + const auto& copy_expr = ExpressionFactory::shallow_copy(orig_expr); + clone_ports_descriptors(copy_expr->m_input_port_descriptors); + clone_ports_descriptors(copy_expr->m_output_port_descriptors); + + for (auto& orig_con : copy_expr->m_output_port_connectors) { + const auto& copy_source = copy_expr->get_output_port(orig_con->get_source().get_index()); + const auto& copy_con = std::make_shared(copy_source); + connectors_map[orig_con] = copy_con; + orig_con = copy_con; + } + for (size_t i = 0; i < copy_expr->get_input_count(); i++) { + const auto& copy_connector = connectors_map[copy_expr->get_input_port_connector(i)]; + const auto& copy_consumer = copy_expr->get_input_port(i); + copy_connector->add_consumer(copy_consumer); + copy_expr->replace_input(i, copy_connector); + } + + if (auto io_expr = std::dynamic_pointer_cast(copy_expr)) + new_lir.m_io_expressions.push_back(io_expr); + new_lir.m_expressions.push_back(copy_expr); + } + // node_map and expr_map map original node pointer (expression) to a new pointer (expression) + ngraph::NodeMap node_map; + OPENVINO_SUPPRESS_DEPRECATED_START + ngraph::clone_nodes(original_nodes, node_map); + OPENVINO_SUPPRESS_DEPRECATED_END + new_lir.m_node2expression_map.clear(); + for (const auto& copy_expr : new_lir.m_expressions) { + copy_expr->m_source_node = node_map[copy_expr->m_source_node.get()]; + new_lir.m_node2expression_map[copy_expr->m_source_node] = copy_expr; + } + new_lir.m_loop_manager = std::make_shared(); + // It's Ok to share shapeInfer factory, since LIR doesn't change it + new_lir.m_shape_infer_factory = m_shape_infer_factory; + // Note: shapeInfer stores expression pointers. we re-create it, so shape inference is performed on cloned exprs. + new_lir.m_shape_infer = std::make_shared(new_lir.m_expressions, new_lir.m_io_expressions); + return new_lir; +} + void LinearIR::debug_print(bool tds_as_pointers) const { auto print_rinfo = [](const RegInfo& rinfo) { std::cerr << " : {"; @@ -296,6 +350,81 @@ LinearIR::constExprReverseIt LinearIR::find_after(LinearIR::constExprReverseIt i return find(it, crend(), target); } +IShapeInferSnippets::Result LinearIR::shape_infer(const std::vector& input_shapes) { + OPENVINO_ASSERT(m_shape_infer, "Attempt to call shape_infer when the shapeInfer instance was not created"); + return m_shape_infer->infer(input_shapes); +} + +VectorDims LinearIR::get_master_shape() const { + VectorDims master_shape{}; + // Note: inputs and outputs must be broadcastable, so it's enough to broadcast-merge only outputs + std::vector> out_exprs; + for (const auto& ioe : m_io_expressions) { + if (ioe->get_type() == IOExpression::io_type::OUTPUT) + out_exprs.push_back(ioe); + } + // Note: Snippets would benefit from a more generic master_shape calculation approach. + // It will be implemented in the scope of ROI propagation activity (ticket 120505) + const auto& result_parent = out_exprs[0]->get_input_port_connector(0)->get_source().get_expr(); + if (!m_config.m_enable_domain_optimization && out_exprs.size() == 1 && + ov::is_type(result_parent->get_node())) { + master_shape = utils::get_planar_vdims(out_exprs[0]->get_input_port_descriptor(0)); + } else { + for (const auto& oe : out_exprs) { + const auto& port_desc = oe->get_input_port_descriptor(0); + OPENVINO_ASSERT(ov::snippets::broadcast_merge_into(master_shape, port_desc->get_shape()), + "Failed to merge input shapes in infer_master_shape"); + } + } + return master_shape; +} + +LinearIR::LIRShapeInfer::LIRShapeInfer(container& body_exprs, io_container& io_exprs) + : ShapeInferSnippetsNode(), + m_exprs{std::make_shared(body_exprs)} { + // Note that here we rely on the assumption that io_expressions can't be changed after the LIR was created + for (const auto& expr : io_exprs) { + if (expr->get_type() == IOExpression::io_type::INPUT) { + m_input_exprs.push_back(expr); + } else if (expr->get_type() == IOExpression::io_type::OUTPUT) { + m_output_exprs.emplace_back(expr); + } else { + OPENVINO_THROW("Invalid io expression type detected"); + } + } + // Note that if all output shapes are static, as in the case when the first shape infer was performed on nGraph, + // we can treat them as the last result + std::vector outputDims; + outputDims.reserve(m_output_exprs.size()); + for (const auto& expr : m_output_exprs) { + const auto &shape = expr->get_input_port_descriptor(0)->get_shape(); + if (utils::is_dynamic_vdims(shape)) { + outputDims.clear(); + break; + } + outputDims.push_back(shape); + } + m_last_result = {outputDims, ShapeInferStatus::success}; +} + +IShapeInferSnippets::Result LinearIR::LIRShapeInfer::infer(const std::vector& input_shapes) { + OPENVINO_ASSERT(m_input_exprs.size() == input_shapes.size(), "Got invalid number of input shapes in LIR ShapeInfer"); + for (size_t i = 0; i < m_input_exprs.size(); i++) + m_input_exprs[i]->get_output_port_descriptor(0)->set_shape(input_shapes[i]); + + for (const auto& expr : *m_exprs) { + if (expr->needShapeInfer()) + expr->updateShapes(); + } + + std::vector outputDims; + outputDims.reserve(m_output_exprs.size()); + for (const auto& expr : m_output_exprs) { + outputDims.push_back(expr->get_input_port_descriptor(0)->get_shape()); + } + m_last_result = {outputDims, ShapeInferStatus::success}; + return m_last_result; +} }// namespace lowered }// namespace snippets diff --git a/src/common/snippets/src/lowered/pass/assign_registers.cpp b/src/common/snippets/src/lowered/pass/assign_registers.cpp index 638845ec6929ad..7755cfebe7cc38 100644 --- a/src/common/snippets/src/lowered/pass/assign_registers.cpp +++ b/src/common/snippets/src/lowered/pass/assign_registers.cpp @@ -46,12 +46,21 @@ bool AssignRegisters::run(LinearIR& linear_ir) { for (const auto& expr : expressions) { auto op = expr->get_node(); if (const auto io_expr = std::dynamic_pointer_cast(expr)) { - if (io_expr->get_type() == IOExpression::io_type::INPUT) - manually_assigned_gprs[expr->get_output_port_connector(0)] = io_expr->get_index(); - else if (io_expr->get_type() == IOExpression::io_type::OUTPUT) + if (io_expr->get_type() == IOExpression::io_type::INPUT) { + const auto& out_connector = expr->get_output_port_connector(0); + manually_assigned_gprs[out_connector] = io_expr->get_index(); + const auto& consumer_inputs = out_connector->get_consumers(); + const auto& first_consumer = consumer_inputs.begin()->get_expr(); + // TODO [96434]: Support RankNormalization (Reshape) in arbitrary place in pipeline, not just after inputs + if (ov::is_type(first_consumer->get_node())) { + OPENVINO_ASSERT(consumer_inputs.size() == 1, "RankNormalization is supposed to be the only consumer"); + manually_assigned_gprs[first_consumer->get_output_port_connector(0)] = io_expr->get_index(); + } + } else if (io_expr->get_type() == IOExpression::io_type::OUTPUT) { manually_assigned_gprs[expr->get_input_port_connector(0)] = num_parameters + io_expr->get_index(); - else + } else { OPENVINO_THROW("Unsupported io_type detected"); + } } else if (const auto& buffer = ov::as_type_ptr(op)) { const auto buffer_id = buffer->get_id(); // All buffers have one common data pointer diff --git a/src/common/snippets/src/lowered/pass/identify_buffers.cpp b/src/common/snippets/src/lowered/pass/identify_buffers.cpp index 02aabc93ead6ac..d411da67af38d6 100644 --- a/src/common/snippets/src/lowered/pass/identify_buffers.cpp +++ b/src/common/snippets/src/lowered/pass/identify_buffers.cpp @@ -36,7 +36,7 @@ std::vector IdentifyBuffers::create_adjacency_matrix(const LinearIR& linea auto get_buffer_idx = [&](const std::shared_ptr& buffer) { const auto iter = std::find(buffers.cbegin(), buffers.cend(), buffer); - NGRAPH_CHECK(iter != buffers.cend(), "Buffer wasn't find in Buffer system of Subgraph"); + OPENVINO_ASSERT(iter != buffers.cend(), "Buffer wasn't find in Buffer system of Subgraph"); return std::distance(buffers.cbegin(), iter); }; diff --git a/src/common/snippets/src/lowered/pass/insert_broadcastmove.cpp b/src/common/snippets/src/lowered/pass/insert_broadcastmove.cpp new file mode 100644 index 00000000000000..a70698580a61e3 --- /dev/null +++ b/src/common/snippets/src/lowered/pass/insert_broadcastmove.cpp @@ -0,0 +1,90 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "snippets/lowered/pass/insert_broadcastmove.hpp" +#include "snippets/utils.hpp" +#include "snippets/lowered/linear_ir.hpp" +#include "snippets/lowered/loop_manager.hpp" +#include "snippets/snippets_isa.hpp" +#include "snippets/itt.hpp" + +namespace ov { +namespace snippets { +namespace lowered { +namespace pass { + +bool InsertBroadcastMove::run(LinearIR& linear_ir) { + OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::InsertBroadcastMove") + bool modified = false; + const auto& loop_manager = linear_ir.get_loop_manager(); + + auto supports_broadcasting = [](const std::shared_ptr& n) { + return ov::op::util::supports_auto_broadcast(n) || + n->get_autob().m_type == ov::op::AutoBroadcastType::NUMPY || + is_type(n); + }; + auto dont_need_broadcasting = [](const ov::Output& v){ + // We don't need to insert BroadcastMove after the following operations: + // - Scalar has emitter with explicit broadcasting + // - VectorBuffer has scalar output shape to avoid broadcast conflicts and manually shape insertion. + // - Fill can be inserted only after VectorBuffer, and should be ignored as well. + return utils::is_scalar_constant(v.get_node_shared_ptr()) || + ov::is_type(v.get_node_shared_ptr()) || + ov::is_type(v.get_node_shared_ptr()); + }; + for (auto expr_it = linear_ir.begin(); expr_it != linear_ir.end(); expr_it++) { + const auto& expr = *expr_it; + const auto& node = expr->get_node(); + const auto& descriptors = expr->get_input_port_descriptors(); + if (!supports_broadcasting(node) || descriptors.size() < 2) + continue; + const auto& connectors = expr->get_input_port_connectors(); + OPENVINO_ASSERT(connectors.size() == descriptors.size(), + "Invalid expression configuration: connectors and descriptors size mismatch"); + + std::vector last_dims(descriptors.size()); + std::transform(descriptors.begin(), descriptors.end(), last_dims.begin(), + [](const std::shared_ptr& d){ + return d->get_shape().back(); + }); + const auto broadcasted_dim = *std::max_element(last_dims.begin(), last_dims.end()); + for (size_t i = 0; i < last_dims.size(); i++) { + const auto& parent_port = connectors[i]->get_source(); + if (last_dims[i] != broadcasted_dim && + !dont_need_broadcasting(parent_port.get_expr()->get_node())) { + OPENVINO_ASSERT(last_dims[i] == 1, + "Attempt to broadcast non-1 dimension. Target dim: ", broadcasted_dim, + " This dim: ", last_dims[i]); + auto input_shape = descriptors[i]->get_shape(); + // Note that input_shape could be empty (aka ngraph scalar), so we can't just replace the last dim + if (input_shape.empty()) + input_shape.resize(1); + input_shape.back() = last_dims[i]; + const auto broadcast = std::make_shared(node->get_input_source_output(i), utils::vdims_to_pshape(input_shape)); + + PortDescriptorUtils::set_port_descriptor_ptr(broadcast->output(0), connectors[i]->get_source().get_descriptor_ptr()->clone()); + const auto broadcast_expr = linear_ir.create_expression(broadcast, {connectors[i]}); + linear_ir.insert(expr_it, broadcast_expr); + linear_ir.replace_input(expr->get_input_port(i), broadcast_expr->get_output_port_connector(0)); + // Note that BroadcastMove modified the next expr input shape, so we need to set update + // expr's input port descriptor to reflect the changes + expr->get_input_port_descriptor(i)->set_shape(broadcast_expr->get_output_port_descriptor(0)->get_shape()); + + // Copy Loop identifies + const auto& loop_ids = expr->get_loop_ids(); + broadcast_expr->set_loop_ids(loop_ids); + loop_manager->update_loops_port(loop_ids, expr->get_input_port(0), {broadcast_expr->get_input_port(0)}, true); + + modified = true; + } + } + } + return modified; +} + +} // namespace pass +} // namespace lowered +} // namespace snippets +} // namespace ov + diff --git a/src/common/snippets/src/lowered/pass/insert_buffers.cpp b/src/common/snippets/src/lowered/pass/insert_buffers.cpp index 91cbe55ef98b34..da5ffc11c3169d 100644 --- a/src/common/snippets/src/lowered/pass/insert_buffers.cpp +++ b/src/common/snippets/src/lowered/pass/insert_buffers.cpp @@ -35,10 +35,9 @@ std::vector get_buffer_loop_ids(const std::vector& lhs, const st ov::Shape compute_allocation_shape(const LinearIR::LoopManagerPtr& loop_manager, const std::vector& buffer_loop_ids, const std::vector& parent_loop_ids, - const ov::Output& parent_output, + const ExpressionPort& expr_port, const int allocation_rank) { - const auto& port = lowered::PortDescriptorUtils::get_port_descriptor_ptr(parent_output); - const auto planar_shape = utils::get_planar_vdims(port); + const auto& planar_shape = utils::get_planar_vdims(expr_port); const size_t rank = allocation_rank >= 0 ? std::min(static_cast(allocation_rank), planar_shape.size()) : planar_shape.size(); ov::Shape allocation_shape(rank); @@ -123,9 +122,9 @@ void InsertBuffers::insertion(LinearIR& linear_ir, const LinearIR::constExprIt& for (const auto& entry_point : loop_entries) { const auto& entry_port = entry_point.expr_port; const auto& expr = entry_port->get_expr(); - const auto port = entry_port->get_index(); + const auto port_idx = entry_port->get_index(); const auto node = expr->get_node(); - const auto& input_connector = expr->get_input_port_connector(port); + const auto& input_connector = expr->get_input_port_connector(port_idx); const auto& parent_expr_output = input_connector->get_source(); const auto& parent_expr = parent_expr_output.get_expr(); const auto parent_port = parent_expr_output.get_index(); @@ -140,7 +139,7 @@ void InsertBuffers::insertion(LinearIR& linear_ir, const LinearIR::constExprIt& const auto parent_ma = ov::as_type_ptr(parent); const auto node_ma = ov::as_type_ptr(node); bool is_buffer_needed = (parent_ma && parent_ma->is_memory_access_output_port(parent_port)) || - (node_ma && node_ma->is_memory_access_input_port(port)); + (node_ma && node_ma->is_memory_access_input_port(port_idx)); const auto current_loops = expr->get_loop_ids(); const auto parent_loops = parent_expr->get_loop_ids(); const auto buffer_loop_ids = get_buffer_loop_ids(current_loops, parent_loops, is_buffer_needed); @@ -154,7 +153,7 @@ void InsertBuffers::insertion(LinearIR& linear_ir, const LinearIR::constExprIt& const auto allocation_shape = compute_allocation_shape(loop_manager, buffer_loop_ids, parent_loops, - parent->output(parent_port), + parent_expr_output, m_buffer_allocation_rank); const auto buffer = std::make_shared(parent->output(parent_port), allocation_shape); PortDescriptorUtils::set_port_descriptor_ptr(buffer->output(0), parent_expr_output.get_descriptor_ptr()->clone()); @@ -169,7 +168,7 @@ void InsertBuffers::insertion(LinearIR& linear_ir, const LinearIR::constExprIt& for (const auto& exit_point : loop_exits) { const auto& exit_port = exit_point.expr_port; const auto& expr = exit_port->get_expr(); - const auto port = exit_port->get_index(); + const auto port_idx = exit_port->get_index(); const auto node = expr->get_node(); const auto output_connector = exit_port->get_port_connector_ptr(); const auto child_exprs_inputs = output_connector->get_consumers(); @@ -200,7 +199,7 @@ void InsertBuffers::insertion(LinearIR& linear_ir, const LinearIR::constExprIt& const auto child_ma = ov::as_type_ptr(child); const auto node_ma = ov::as_type_ptr(node); bool is_buffer_needed = (child_ma && child_ma->is_memory_access_input_port(child_port)) || - (node_ma && node_ma->is_memory_access_output_port(port)); + (node_ma && node_ma->is_memory_access_output_port(port_idx)); const auto local_buffer_loop_ids = get_buffer_loop_ids(current_loops, child_expr->get_loop_ids(), is_buffer_needed); if (is_buffer_needed) { @@ -247,9 +246,9 @@ void InsertBuffers::insertion(LinearIR& linear_ir, const LinearIR::constExprIt& const auto allocation_shape = compute_allocation_shape(loop_manager, buffer_loop_ids, current_loops, - node->output(port), + *exit_port, m_buffer_allocation_rank); - auto buffer = std::make_shared(node->output(port), allocation_shape); + auto buffer = std::make_shared(node->output(port_idx), allocation_shape); PortDescriptorUtils::set_port_descriptor_ptr(buffer->output(0), exit_port->get_descriptor_ptr()->clone()); // We cannot insert Node output connector on Buffer output because not all consumers of Node needs Buffer // Example: diff --git a/src/common/snippets/src/lowered/pass/insert_load_store.cpp b/src/common/snippets/src/lowered/pass/insert_load_store.cpp index 40f802a649a9e9..ff75a5be0e6c5c 100644 --- a/src/common/snippets/src/lowered/pass/insert_load_store.cpp +++ b/src/common/snippets/src/lowered/pass/insert_load_store.cpp @@ -3,7 +3,7 @@ // #include "snippets/lowered/pass/insert_load_store.hpp" - +#include "snippets/op/rank_normalization.hpp" #include "snippets/lowered/linear_ir.hpp" #include "snippets/lowered/loop_manager.hpp" #include "snippets/snippets_isa.hpp" @@ -24,20 +24,24 @@ size_t InsertLoadStore::get_count(const PortDescriptorPtr& port_desc) const { const auto shape = port_desc->get_shape(); // Find last dimension by layout const auto last_dim_idx = std::find(layout.begin(), layout.end(), layout.size() - 1); - OPENVINO_ASSERT(last_dim_idx != layout.end(), "Load/Store expression have incorrect layout"); + OPENVINO_ASSERT(last_dim_idx != layout.end() && *last_dim_idx < shape.size(), "Load/Store expression have incorrect layout"); const auto dim = shape[*last_dim_idx]; return dim == 1 ? 1 : m_vector_size; } bool InsertLoadStore::insert_load(LinearIR& linear_ir, const LinearIR::constExprIt& data_expr_it) { + std::shared_ptr data_expr = *data_expr_it; + auto consumer_inputs = data_expr->get_output_port_connector(0)->get_consumers(); + const auto& first_consumer = consumer_inputs.begin()->get_expr(); + if (is_type(first_consumer->get_node())) { + OPENVINO_ASSERT(consumer_inputs.size() == 1, "RankNormalization is supposed to be the only consumer"); + data_expr = first_consumer; + } const auto& loop_manager = linear_ir.get_loop_manager(); - const auto& data_expr = *data_expr_it; - const auto& data_node = data_expr->get_node(); + const auto& data_ngraph_output = data_expr->get_node()->output(0); const auto& output_connector = data_expr->get_output_port_connector(0); - const auto consumer_inputs = output_connector->get_consumers(); - bool was_inserted = false; - for (const auto& consumer_input : consumer_inputs) { + for (const auto& consumer_input : output_connector->get_consumers()) { const auto& consumer_expr = consumer_input.get_expr(); const auto port = consumer_input.get_index(); const auto& consumer = consumer_expr->get_node(); @@ -46,7 +50,7 @@ bool InsertLoadStore::insert_load(LinearIR& linear_ir, const LinearIR::constExpr return false; const auto loop_ids = consumer_expr->get_loop_ids(); - const auto load = std::make_shared(data_node->output(0), get_count(data_expr->get_output_port_descriptor(0))); + const auto load = std::make_shared(data_ngraph_output, get_count(data_expr->get_output_port_descriptor(0))); PortDescriptorUtils::set_port_descriptor_ptr(load->output(0), consumer_input.get_descriptor_ptr()->clone()); const auto load_expr = linear_ir.create_expression(load, {output_connector}); linear_ir.insert(linear_ir.find_after(data_expr_it, consumer_expr), load_expr); @@ -55,7 +59,7 @@ bool InsertLoadStore::insert_load(LinearIR& linear_ir, const LinearIR::constExpr load_expr->set_loop_ids(loop_ids); // Need to update all the corresponding Loops with the same Entry Point - const auto prev_entry_point = consumer_input; + const auto& prev_entry_point = consumer_input; const auto new_entry_point = load_expr->get_input_port(0); loop_manager->update_loops_port(loop_ids, prev_entry_point, {new_entry_point}, true); was_inserted = true; @@ -116,20 +120,14 @@ bool InsertLoadStore::run(LinearIR& linear_ir) { const auto& node = expr->get_node(); if (ov::is_type(node)) { modified |= insert_load(linear_ir, expr_it); - continue; - } - if (ov::is_type(node)) { + } else if (ov::is_type(node)) { modified |= insert_store(linear_ir, expr_it); - continue; - } - if (auto buffer = ov::as_type_ptr(node)) { + } else if (auto buffer = ov::as_type_ptr(node)) { modified |= insert_load(linear_ir, expr_it); if (buffer->is_intermediate_memory()) modified |= insert_store(linear_ir, expr_it); - continue; } } - return modified; } diff --git a/src/common/snippets/src/lowered/pass/mark_loops.cpp b/src/common/snippets/src/lowered/pass/mark_loops.cpp index 86246ce61f1be6..05d38e111927c4 100644 --- a/src/common/snippets/src/lowered/pass/mark_loops.cpp +++ b/src/common/snippets/src/lowered/pass/mark_loops.cpp @@ -29,7 +29,8 @@ bool MarkLoops::run(LinearIR& linear_ir) { auto is_not_start_point = [](const std::shared_ptr& node) { return ov::is_type(node) || ov::is_type(node) || - ov::is_type(node); + ov::is_type(node) || + ov::is_type(node); }; auto are_conflicted = [](const ExpressionPort& lhs, const ExpressionPort& rhs) { diff --git a/src/common/snippets/src/lowered/pass/optimize_domain.cpp b/src/common/snippets/src/lowered/pass/optimize_domain.cpp new file mode 100644 index 00000000000000..f2d2fd43baf96c --- /dev/null +++ b/src/common/snippets/src/lowered/pass/optimize_domain.cpp @@ -0,0 +1,137 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "snippets/lowered/pass/optimize_domain.hpp" + +#include "snippets/itt.hpp" +#include "snippets/lowered/linear_ir.hpp" +#include "snippets/snippets_isa.hpp" +#include "snippets/shape_inference/shape_inference.hpp" +#include "snippets/utils.hpp" + + +namespace ov { +namespace snippets { +namespace lowered { +namespace pass { + +OptimizeDomain::OptimizeDomain(size_t& tile_rank) : Pass(), m_tile_rank(tile_rank) { +} +size_t OptimizeDomain::optimize(std::vector& input_shapes, + VectorDims& master_shape, + const size_t total_work_amount, + const size_t min_parallel_work_amount, + const size_t min_jit_work_amount) { + if (master_shape.size() <= 2) + return false; + + auto CollapseLastDim = [](VectorDims& dims) { + OPENVINO_ASSERT(dims.size() >= 2, "CollapseLastDim can't process shape with less than two dims"); + dims[dims.size() - 1] *= dims[dims.size() - 2]; + for (auto i = dims.size() - 2; i > 0; i--) + dims[i] = dims[i - 1]; + dims[0] = 1; + }; + // Check that neither of the two last dims is broadcasted, so they can be collapsed + auto LastDimsNotBroadcasted = [] (const std::vector& input_shapes, const VectorDims& master_shape) { + const auto master_last = *master_shape.rbegin(); + const auto master_prelast = *++master_shape.rbegin(); + return std::all_of(input_shapes.begin(), input_shapes.end(), + [=](const VectorDims& s) { + return *s.rbegin() == master_last && + *++s.rbegin() == master_prelast; + }); + }; + + size_t jit_work_amount = master_shape.back(); + size_t num_dims_collapsed = 0; + while (jit_work_amount < min_jit_work_amount && + can_increase_jit_work_amount(master_shape, min_parallel_work_amount, total_work_amount) && + LastDimsNotBroadcasted(input_shapes, master_shape) && + num_dims_collapsed < master_shape.size() - 1) { + for (auto &s : input_shapes) + CollapseLastDim(s); + + CollapseLastDim(master_shape); + num_dims_collapsed++; + + jit_work_amount = master_shape.back(); + } + return num_dims_collapsed; +} + +inline bool OptimizeDomain::can_increase_jit_work_amount(const VectorDims& master_shape, + const size_t min_parallel_work_amount, + const size_t total_work_amount) { + return master_shape.size() > 2 && + master_shape[master_shape.size() - 1] * master_shape[master_shape.size() - 2] * + min_parallel_work_amount <= total_work_amount; +} +bool OptimizeDomain::run(snippets::lowered::LinearIR& linear_ir) { + OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::OptimizeDomain") + const auto& config = linear_ir.get_config(); + if (linear_ir.empty()) + return false; + m_tile_rank = 1; + if (!config.m_enable_domain_optimization) { + // Note: this is a special case: if optimization is not allowed, always assume 2D tile + m_tile_rank = 2; + return false; + } + OPENVINO_ASSERT(config.m_min_parallel_work_amount != 0, "OptimizeDomain: Min parallel work amount can't equal to zero"); + std::vector input_shapes; + VectorDims master_shape = linear_ir.get_master_shape(); + bool blocked_input_shapes = false; + for (const auto& io_expr : linear_ir.get_IO_ops()) { + if (io_expr->get_type() == snippets::lowered::IOExpression::io_type::INPUT) { + auto consumer_inputs = io_expr->get_output_port_connector(0)->get_consumers(); + const auto& first_consumer = consumer_inputs.begin()->get_expr(); + if (auto rank_norm = as_type_ptr(first_consumer->get_node())) { + // If RankNormalization appends dims, then the appended dims will be broadcasted + // so collapsing is not allowed. We may increment tile rank though. + if (rank_norm->get_num_append() != 0) + blocked_input_shapes = true; + // If RankNormalization prepends dims, then the dims should be ignored during domain optimization + // to avoid passing already incremented shapes to linear_ir.shape_infer() + } + const ExpressionPtr& shape_producing_expr = blocked_input_shapes ? + first_consumer : + io_expr; + const auto& shape = utils::get_planar_vdims(shape_producing_expr->get_output_port_descriptor(0)); + OPENVINO_ASSERT(std::none_of(shape.begin(), shape.end(), + [](size_t d) {return d == snippets::IShapeInferSnippets::DYNAMIC_DIMENSION; }), + "OptimizeDomain pass does not support dynamic shapes"); + input_shapes.emplace_back(shape); + } + } + const auto total_work_amount = std::accumulate(master_shape.begin(), + master_shape.end(), + (size_t)1, + std::multiplies()); + const auto num_dims_collapsed = blocked_input_shapes ? + 0 : + optimize(input_shapes, + master_shape, + total_work_amount, + config.m_min_parallel_work_amount, + config.m_min_kernel_work_amount); + if (num_dims_collapsed > 0) { + std::vector infer_shapes; + infer_shapes.reserve(input_shapes.size()); + for (const auto& is : input_shapes) + infer_shapes.emplace_back(is); + // Need to propagate updated shapes through LIR + linear_ir.shape_infer(infer_shapes); + } + // We can still try to increment tile rank after dimension collapsing + if (can_increase_jit_work_amount(master_shape, config.m_min_parallel_work_amount, total_work_amount) && + num_dims_collapsed != master_shape.size() - 1) + m_tile_rank++; + return num_dims_collapsed > 0; +} + +} // namespace pass +} // namespace lowered +} // namespace snippets +} // namespace ov \ No newline at end of file diff --git a/src/common/snippets/src/lowered/pass/propagate_layout.cpp b/src/common/snippets/src/lowered/pass/propagate_layout.cpp index 7b69c82777d90e..aea3cf99858622 100644 --- a/src/common/snippets/src/lowered/pass/propagate_layout.cpp +++ b/src/common/snippets/src/lowered/pass/propagate_layout.cpp @@ -19,23 +19,25 @@ bool PropagateLayout::run(LinearIR& linear_ir) { if (linear_ir.empty()) return false; - for (auto expr_it = linear_ir.begin(); expr_it != linear_ir.end(); expr_it++) { - const auto& expr = *expr_it; + for (const auto& expr : linear_ir) { const auto io_expr = std::dynamic_pointer_cast(expr); if (!io_expr) continue; const bool is_input = io_expr->get_type() == IOExpression::io_type::INPUT; const auto& connectors = is_input ? expr->get_output_port_connectors() : expr->get_input_port_connectors(); - if (connectors.size() != 1) - OPENVINO_THROW("Parameter/Results should have exactly one output/input"); + OPENVINO_ASSERT(connectors.size() == 1, "Parameter/Results should have exactly one output/input"); // If input - we should be looking downstream, if output - upstream const auto& target_connector = connectors.front(); if (is_input) { - const auto consumer_inputs = target_connector->get_consumers(); // Note that here we consider only the first child (which is usually load), // but often there is another child - LoopEnd + auto consumer_inputs = target_connector->get_consumers(); + const auto& first_consumer = consumer_inputs.begin()->get_expr(); + // If there is a RankNormalization op after a parameter - we should skip it + if (is_type(first_consumer->get_node())) + consumer_inputs = first_consumer->get_output_port_connector(0)->get_consumers(); std::set> child_layouts; for (const auto& child_input : consumer_inputs) { const auto& child = child_input.get_expr(); diff --git a/src/common/snippets/src/lowered/pass/softmax_decomposition.cpp b/src/common/snippets/src/lowered/pass/softmax_decomposition.cpp index e868d75e5dd5ea..b434e0f974beb3 100644 --- a/src/common/snippets/src/lowered/pass/softmax_decomposition.cpp +++ b/src/common/snippets/src/lowered/pass/softmax_decomposition.cpp @@ -44,13 +44,15 @@ bool SoftmaxDecomposition::run(LinearIR& linear_ir) { // Float constant values in byte representation const auto float_min_constant = uint32_t(0xff7fffff); const auto zero_constant = uint32_t(0x00000000); - + const bool is_dynamic = softmax->is_dynamic(); // We need an iterator to the inserted element - auto push_node = [&linear_ir, &expr_it](const std::shared_ptr& n) { + auto push_node = [&linear_ir, &expr_it, is_dynamic](const std::shared_ptr& n) { const auto expr = linear_ir.insert(expr_it, n); + if (is_dynamic) + expr->get()->updateShapes(); return std::make_pair(expr, n); }; - + const ov::PartialShape broadcasted_shape(softmax_expr->get_input_port_descriptor(0)->get_shape()); // Note: VectorBuffer is a special case, since it should go before the initial Load. So we handle it separately const auto& vector_buffer_max = push_node(std::make_shared()); // Init value of vector buffer for ReduceMax is -FLOAT_MIN. @@ -65,9 +67,8 @@ bool SoftmaxDecomposition::run(LinearIR& linear_ir) { std::vector{(*max.first)->get_input_port(0), (*max.first)->get_input_port(1)}, std::vector{(*max.first)->get_output_port(0)}); - const auto broadcast_horizon_max = push_node( - std::make_shared(horizon_max.second, horizon_max.second->get_input_partial_shape(0))); + std::make_shared(horizon_max.second, broadcasted_shape)); const auto vector_buffer_sum = push_node(std::make_shared()); // Init value of vector buffer for ReduceSum is zero. const auto fill_sum = push_node(std::make_shared(vector_buffer_sum.second, 0, zero_constant)); @@ -89,7 +90,7 @@ bool SoftmaxDecomposition::run(LinearIR& linear_ir) { // Divide is expensive operation, so we decompose it into 1 / x * y, where 1 / x is executed outside loop const auto pow = push_node(std::make_shared(horizon_sum.second, -1.f)); - const auto broadcast_pow = push_node(std::make_shared(pow.second, horizon_sum.second->get_input_partial_shape(0))); + const auto broadcast_pow = push_node(std::make_shared(pow.second, broadcasted_shape)); // Mul (pseudo-Divide loop) const auto mul = push_node(std::make_shared(exp.second, broadcast_pow.second)); diff --git a/src/common/snippets/src/lowered/pass/validate_shapes.cpp b/src/common/snippets/src/lowered/pass/validate_shapes.cpp new file mode 100644 index 00000000000000..8d12004313e0bf --- /dev/null +++ b/src/common/snippets/src/lowered/pass/validate_shapes.cpp @@ -0,0 +1,48 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "snippets/lowered/pass/validate_shapes.hpp" + +#include "snippets/lowered/linear_ir.hpp" +#include "snippets/shape_inference/shape_inference.hpp" +#include "snippets/itt.hpp" + +namespace ov { +namespace snippets { +namespace lowered { +namespace pass { + +bool ValidateShapes::run(LinearIR& linear_ir) { + OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::ValidateShapes") + + for (const auto& expr : linear_ir) { + const auto num_inputs = expr->get_input_count(); + const auto& port_connectors = expr->get_input_port_connectors(); + const auto& port_descriptors = expr->get_input_port_descriptors(); + OPENVINO_ASSERT(port_connectors.size() == num_inputs, "Invalid number of port connectors detected"); + OPENVINO_ASSERT(port_descriptors.size() == num_inputs, "Invalid number of port descriptors detected"); + for (size_t i = 0; i < num_inputs; i++) { + const auto& descr = port_descriptors[i]; + const auto& layout = descr->get_layout(); + const auto& shape = descr->get_shape(); + const auto& n = expr->get_node(); + OPENVINO_ASSERT(std::none_of(shape.begin(), shape.end(), + [](size_t d) {return d == IShapeInferSnippets::DYNAMIC_DIMENSION;}), + "Dynamic dimensions are not allowed at this point of pipeline. ", + "Check the expr for node ", n->get_friendly_name()); + OPENVINO_ASSERT(layout.size() == shape.size(), "Layout and shape sizes must match. ", + "Check the expr for node ", n->get_friendly_name()); + const auto& parent_desc = port_connectors[i]->get_source().get_descriptor_ptr(); + const auto& parent_shape = parent_desc->get_shape(); + OPENVINO_ASSERT(parent_shape == shape, "Parent shape must be equal to the expression shape. ", + "Check the expr for node ", n->get_friendly_name()); + } + } + return false; +} + +} // namespace pass +} // namespace lowered +} // namespace snippets +} // namespace ov diff --git a/src/common/snippets/src/lowered/port_descriptor.cpp b/src/common/snippets/src/lowered/port_descriptor.cpp index 96e8c718cc972b..e8c4bdd0626b47 100644 --- a/src/common/snippets/src/lowered/port_descriptor.cpp +++ b/src/common/snippets/src/lowered/port_descriptor.cpp @@ -3,6 +3,7 @@ // #include "snippets/lowered/port_descriptor.hpp" +#include namespace ov { namespace snippets { @@ -12,13 +13,15 @@ size_t PortDescriptor::ServiceDimensions::FULL_DIM = SIZE_MAX; PortDescriptor::PortDescriptor(const ov::Input& in, VectorDims subtensor_shape, std::vector layout) : PortDescriptor(ov::Input(in.get_node(), in.get_index()), std::move(subtensor_shape), std::move(layout)) {} -PortDescriptor::PortDescriptor(const ov::Input& in, VectorDims subtensor_shape, std::vector layout) - : PortDescriptor(in.get_shape(), std::move(subtensor_shape), std::move(layout)) {} + +PortDescriptor::PortDescriptor(const ov::Input& in, std::vector subtensor_shape, std::vector layout) + : PortDescriptor(utils::pshape_to_vdims(in.get_partial_shape()), std::move(subtensor_shape), std::move(layout)) {} PortDescriptor::PortDescriptor(const ov::Output& out, VectorDims subtensor_shape, std::vector layout) : PortDescriptor(ov::Output(out.get_node(), out.get_index()), std::move(subtensor_shape), std::move(layout)) {} -PortDescriptor::PortDescriptor(const ov::Output& out, VectorDims subtensor_shape, std::vector layout) - : PortDescriptor(out.get_shape(), std::move(subtensor_shape), std::move(layout)) {} + +PortDescriptor::PortDescriptor(const ov::Output& out, std::vector subtensor_shape, std::vector layout) + : PortDescriptor(utils::pshape_to_vdims(out.get_partial_shape()), std::move(subtensor_shape), std::move(layout)) {} PortDescriptor::PortDescriptor(VectorDims shape, VectorDims subtensor_shape, std::vector layout) : m_tensor_shape(std::move(shape)), m_layout(std::move(layout)), m_subtensor_shape(std::move(subtensor_shape)) { @@ -30,13 +33,12 @@ void PortDescriptor::validate_arguments() { m_layout.resize(m_tensor_shape.size()); // NCHW layout by default std::iota(m_layout.begin(), m_layout.end(), 0); - } else if (m_layout.size() != m_tensor_shape.size()) { - OPENVINO_THROW("Snippets tensor descriptor: Layout size must be equal to the shape size"); } + OPENVINO_ASSERT(m_layout.size() == m_tensor_shape.size(), "Snippets tensor descriptor: Layout size must be equal to the shape size"); } PortDescriptorPtr PortDescriptor::clone() const { - const auto desc = std::make_shared(m_tensor_shape, m_subtensor_shape, m_layout); + auto desc = std::make_shared(m_tensor_shape, m_subtensor_shape, m_layout); desc->set_reg(m_reg); return desc; } diff --git a/src/common/snippets/src/op/brgemm.cpp b/src/common/snippets/src/op/brgemm.cpp index 1f415a4f64b57f..5cce5d85c13a82 100644 --- a/src/common/snippets/src/op/brgemm.cpp +++ b/src/common/snippets/src/op/brgemm.cpp @@ -127,7 +127,7 @@ ov::PartialShape Brgemm::get_planar_output_shape(const ov::PartialShape& output_ } ov::PartialShape Brgemm::get_output_partial_shape(const std::vector& input_shapes) const { - NGRAPH_CHECK(input_shapes.size() == 2, "BRGEMM expects 2 input shapes for shape inference"); + OPENVINO_ASSERT(input_shapes.size() == 2, "BRGEMM expects 2 input shapes for shape inference"); // Note: All majors checks are missed because Brgemm is transformed from MatMul with whole shape infer support @@ -188,77 +188,6 @@ ov::PartialShape Brgemm::get_output_partial_shape(const std::vector& n) { - for (const auto& in : n->inputs()) { - const auto& port = lowered::PortDescriptorUtils::get_port_descriptor_ptr(in); - m_io_layouts.push_back(port->get_layout()); - } - m_io_layouts.push_back(get_output_layout(n)); -} - -IShapeInferSnippets::Result Brgemm::ShapeInfer::infer(const std::vector& input_shapes) { - OPENVINO_ASSERT(input_shapes.size() == 2, "BRGEMM expects 2 input shapes for shape inference"); - - // Todo: Ideally we should use the layout stored in PortDescriptors. Can we do it? - const auto& arg0_shape = snippets::utils::get_planar_vdims(input_shapes[0].get(), m_io_layouts[0]); - const auto& arg1_shape = snippets::utils::get_planar_vdims(input_shapes[1].get(), m_io_layouts[1]); - - size_t arg0_rank = arg0_shape.size(), arg1_rank = arg1_shape.size(); - - // temporary shapes to calculate output shape - VectorDims arg0_shape_tmp(arg0_shape), arg1_shape_tmp(arg1_shape); - - // one-dimensional tensors unsqueezing is applied to each input independently. - if (arg0_rank == 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}. - arg0_shape_tmp.insert(arg0_shape_tmp.begin(), 1); - arg0_rank = arg0_shape_tmp.size(); - } - if (arg1_rank == 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}. - arg1_shape_tmp.insert(arg1_shape_tmp.end(), 1); - arg1_rank = arg1_shape_tmp.size(); - } - - // add 1 to begin to align shape ranks if needed - if (arg0_rank < arg1_rank) - arg0_shape_tmp.insert(arg0_shape_tmp.begin(), arg1_rank - arg0_rank, 1); - else if (arg0_rank > arg1_rank) - arg1_shape_tmp.insert(arg1_shape_tmp.begin(), arg0_rank - arg1_rank, 1); - - size_t max_rank = arg0_shape_tmp.size(); - VectorDims output_shape(max_rank); - for (size_t i = 0; i < max_rank - 2; ++i) { - if (arg0_shape_tmp[i] == arg1_shape_tmp[i]) { - output_shape[i] = arg0_shape_tmp[i]; - } else { - if (arg0_shape_tmp[i] == 1 || arg0_shape_tmp[i] == DYNAMIC_DIMENSION) - output_shape[i] = arg1_shape_tmp[i]; - else if (arg1_shape_tmp[i] == 1 || arg1_shape_tmp[i] == DYNAMIC_DIMENSION) - output_shape[i] = arg0_shape_tmp[i]; - else - OPENVINO_THROW("Incompatible Brgemm batch dimension"); - } - } - output_shape[output_shape.size() - 2] = arg0_shape_tmp[arg0_shape_tmp.size() - 2]; // M - output_shape[output_shape.size() - 1] = arg1_shape_tmp[arg1_shape_tmp.size() - 1]; // N - - // removing the temporary axes from originally 1D tensors. - if (arg0_shape.size() == 1) { - output_shape.erase(output_shape.begin() + output_shape.size() - 2); - } - if (arg1_shape.size() == 1) { - output_shape.erase(output_shape.begin() + output_shape.size() - 1); - } - output_shape = snippets::utils::get_planar_vdims(output_shape, m_io_layouts[2]); - return {{output_shape}, snippets::ShapeInferStatus::success}; -} - } // namespace op } // namespace snippets } // namespace ov diff --git a/src/common/snippets/src/op/buffer.cpp b/src/common/snippets/src/op/buffer.cpp index 8b703fa0c29a16..615979ec5e3281 100644 --- a/src/common/snippets/src/op/buffer.cpp +++ b/src/common/snippets/src/op/buffer.cpp @@ -46,15 +46,13 @@ bool Buffer::visit_attributes(AttributeVisitor& visitor) { void Buffer::validate_and_infer_types() { INTERNAL_OP_SCOPE(Buffer_validate_and_infer_types); - ov::Shape output_shape; + ov::PartialShape output_shape; if (m_type == Type::NewMemory) { OPENVINO_ASSERT(get_input_size() == 0, "Buffer with new allocated memory must to not have arguments!"); output_shape = m_shape; } else if (m_type == Type::IntermediateMemory) { - const auto& input_shape = get_input_partial_shape(0); - OPENVINO_ASSERT(input_shape.is_static(), "Buffer supports only static input shape"); m_element_type = get_input_element_type(0); - output_shape = input_shape.get_shape(); + output_shape = get_input_partial_shape(0); } else { OPENVINO_THROW("Buffer supports only the following types: NewMemory and IntermediateMemory"); } diff --git a/src/common/snippets/src/op/fill.cpp b/src/common/snippets/src/op/fill.cpp index 437f594cdfc519..05f79495ae1748 100644 --- a/src/common/snippets/src/op/fill.cpp +++ b/src/common/snippets/src/op/fill.cpp @@ -32,7 +32,7 @@ std::shared_ptr Fill::clone_with_new_inputs(const OutputVector& new_args) void Fill::validate_and_infer_types() { INTERNAL_OP_SCOPE(Fill_validate_and_infer_types); const auto in_type = get_input_element_type(0); - NGRAPH_CHECK(in_type.size() == 4, "Fill operation supports only element types with 4 byte size but got:" + std::to_string(in_type.size())); + OPENVINO_ASSERT(in_type.size() == 4, "Fill operation supports only element types with 4 byte size but got:" + std::to_string(in_type.size())); set_output_type(0, get_input_element_type(0), get_input_partial_shape(0)); } diff --git a/src/common/snippets/src/op/load.cpp b/src/common/snippets/src/op/load.cpp index d1a7d0f2cb523e..868ed4294e6dab 100644 --- a/src/common/snippets/src/op/load.cpp +++ b/src/common/snippets/src/op/load.cpp @@ -40,13 +40,13 @@ std::shared_ptr Load::clone_with_new_inputs(const OutputVector& new_args) LoadReshape::LoadReshape(const Output& x, const size_t count, const size_t offset, std::vector order) : Load(x, count, offset), m_order(std::move(order)) { const auto& in_shape = x.get_partial_shape(); - NGRAPH_CHECK(in_shape.is_static(), "LoadReshape supports only static input shapes"); + OPENVINO_ASSERT(in_shape.is_static(), "LoadReshape supports only static input shapes"); const auto in_shape_size = in_shape.size(); - NGRAPH_CHECK(m_order.size() == in_shape_size, "LoadReshape got new_order of invalid size"); - NGRAPH_CHECK(*std::max_element(m_order.begin(), m_order.end()) == in_shape_size - 1 && + OPENVINO_ASSERT(m_order.size() == in_shape_size, "LoadReshape got new_order of invalid size"); + OPENVINO_ASSERT(*std::max_element(m_order.begin(), m_order.end()) == in_shape_size - 1 && *std::min_element(m_order.begin(), m_order.end()) == 0, "LoadReshape detected invalid values in new_order"); const std::set unique_dims(order.begin(), order.end()); - NGRAPH_CHECK(unique_dims.size() == order.size(), "LoadReshape order must not contain repeated elements"); + OPENVINO_ASSERT(unique_dims.size() == order.size(), "LoadReshape order must not contain repeated elements"); constructor_validate_and_infer_types(); } diff --git a/src/common/snippets/src/op/memory_access.cpp b/src/common/snippets/src/op/memory_access.cpp index 117c1bd14e2e7f..f98d72be7f94f5 100644 --- a/src/common/snippets/src/op/memory_access.cpp +++ b/src/common/snippets/src/op/memory_access.cpp @@ -73,25 +73,25 @@ bool MemoryAccess::is_memory_access_output_port(size_t idx) const { void MemoryAccess::set_input_port_descriptor(const PortDescriptor& desc, const size_t i) { const auto it = m_input_ports.find(i); - NGRAPH_CHECK(it != m_input_ports.end(), "Index of input port descriptor should be less than count of input ports"); + OPENVINO_ASSERT(it != m_input_ports.end(), "Index of input port descriptor should be less than count of input ports"); (*it).second = { desc.count, desc.offset, i}; } void MemoryAccess::set_output_port_descriptor(const PortDescriptor& desc, const size_t i) { const auto it = m_output_ports.find(i); - NGRAPH_CHECK(it != m_output_ports.end(), "Index of output port descriptor should be less than count of output ports"); + OPENVINO_ASSERT(it != m_output_ports.end(), "Index of output port descriptor should be less than count of output ports"); (*it).second = { desc.count, desc.offset, i}; } const MemoryAccess::PortDescriptor& MemoryAccess::get_input_port_descriptor(const size_t i) const { const auto it = m_input_ports.find(i); - NGRAPH_CHECK(it != m_input_ports.end(), "Index of input port descriptor should be less than count of input ports"); + OPENVINO_ASSERT(it != m_input_ports.end(), "Index of input port descriptor should be less than count of input ports"); return (*it).second; } const MemoryAccess::PortDescriptor& MemoryAccess::get_output_port_descriptor(const size_t i) const { const auto it = m_output_ports.find(i); - NGRAPH_CHECK(it != m_output_ports.end(), "Index of output port descriptor should be less than count of output ports"); + OPENVINO_ASSERT(it != m_output_ports.end(), "Index of output port descriptor should be less than count of output ports"); return (*it).second; } diff --git a/src/common/snippets/src/op/rank_normalization.cpp b/src/common/snippets/src/op/rank_normalization.cpp new file mode 100644 index 00000000000000..5dfd46492a1946 --- /dev/null +++ b/src/common/snippets/src/op/rank_normalization.cpp @@ -0,0 +1,57 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "snippets/op/rank_normalization.hpp" +#include "snippets/utils.hpp" + +namespace ov { +namespace snippets { +namespace op { + +RankNormalization::RankNormalization(const Output& data, size_t num_prepend, size_t num_append) : + Op({data}), m_num_prepend(num_prepend), m_num_append(num_append) { + constructor_validate_and_infer_types(); +} + + +std::shared_ptr RankNormalization::clone_with_new_inputs(const OutputVector& new_args) const { + check_new_args_count(this, new_args); + return std::make_shared(new_args[0], m_num_prepend, m_num_append); +} + +void RankNormalization::validate_and_infer_types() { + auto new_shape = get_input_partial_shape(0); + // Note: other values are not allowed, only planar + blocked layout combination can be normalized. + NODE_VALIDATION_CHECK(this, utils::one_of(m_num_append, 0lu, 1lu), + "num_append could be only 0 or 1, other values are not allowed."); + new_shape.insert(new_shape.begin(), m_num_prepend, Dimension(1)); + new_shape.insert(new_shape.end(), m_num_append, Dimension(1)); + set_output_type(0, get_input_element_type(0), new_shape); +} + +bool RankNormalization::visit_attributes(AttributeVisitor& visitor) { + visitor.on_attribute("num_prepend", m_num_prepend); + visitor.on_attribute("num_append", m_num_append); + return true; +} + +RankNormalization::ShapeInfer::ShapeInfer(const std::shared_ptr& n) { + const auto& rank_norm = as_type_ptr(n); + OPENVINO_ASSERT(rank_norm, "Invalid operation passed to RankNormalization::ShapeInfer: ", n->get_type_info().name); + m_num_append = rank_norm->m_num_append; + m_num_prepend = rank_norm->m_num_prepend; +} + +IShapeInferSnippets::Result +RankNormalization::ShapeInfer::infer(const std::vector& input_shapes) { + OPENVINO_ASSERT(input_shapes.size() == 1, "Invalid number of input shapes passed to RankNormalization::ShapeInfer::infer"); + VectorDims out_shape = input_shapes[0].get(); + out_shape.insert(out_shape.begin(), m_num_prepend, 1); + out_shape.insert(out_shape.end(), m_num_append, 1); + return {{out_shape}, ShapeInferStatus::success}; +} + +} // namespace op +} // namespace snippets +} // namespace ov \ No newline at end of file diff --git a/src/common/snippets/src/op/scalar.cpp b/src/common/snippets/src/op/scalar.cpp index 029a2e613f28d2..4efd1716a6fb94 100644 --- a/src/common/snippets/src/op/scalar.cpp +++ b/src/common/snippets/src/op/scalar.cpp @@ -4,14 +4,17 @@ #include "snippets/op/scalar.hpp" +namespace ov { +namespace snippets { +namespace op { -std::shared_ptr ov::snippets::op::Scalar::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr Scalar::clone_with_new_inputs(const OutputVector& new_args) const { check_new_args_count(this, new_args); return std::make_shared(*this); } // Scalar currently supports only one-element constants, this could be changed in the future -void ov::snippets::op::Scalar::validate_and_infer_types() { +void Scalar::validate_and_infer_types() { Constant::validate_and_infer_types(); auto out_pshape = get_output_partial_shape(0); NODE_VALIDATION_CHECK(this, out_pshape.is_static(), "Scalar supports only static input shapes"); @@ -20,7 +23,7 @@ void ov::snippets::op::Scalar::validate_and_infer_types() { " shape"); } -bool ov::snippets::op::Scalar::visit_attributes(AttributeVisitor& visitor) { +bool Scalar::visit_attributes(AttributeVisitor& visitor) { auto shape = get_output_shape(0); auto type = get_output_element_type(0); auto value = cast_vector(); @@ -29,3 +32,7 @@ bool ov::snippets::op::Scalar::visit_attributes(AttributeVisitor& visitor) { visitor.on_attribute("value", value); return true; } + +} // namespace op +} // namespace snippets +} // namespace ov \ No newline at end of file diff --git a/src/common/snippets/src/op/subgraph.cpp b/src/common/snippets/src/op/subgraph.cpp index 5e67d6cad9e31c..fccecfa8ab5f32 100644 --- a/src/common/snippets/src/op/subgraph.cpp +++ b/src/common/snippets/src/op/subgraph.cpp @@ -6,9 +6,7 @@ #include "snippets/remarks.hpp" #include "snippets/op/subgraph.hpp" -#include "snippets/op/convert_saturation.hpp" -#include "snippets/pass/insert_movebroadcast.hpp" #include "snippets/pass/broadcast_to_movebroadcast.hpp" #include "snippets/pass/propagate_precision.hpp" #include "snippets/pass/convert_constants.hpp" @@ -17,6 +15,9 @@ #include "snippets/pass/matmul_to_brgemm.hpp" #include "snippets/pass/fuse_transpose_brgemm.hpp" #include "snippets/pass/set_softmax_ports.hpp" +#include "snippets/pass/canonicalization.hpp" +#include "snippets/pass/align_element_types.hpp" +#include "snippets/lowered/pass/validate_shapes.hpp" #include "snippets/utils.hpp" @@ -29,6 +30,7 @@ #include "snippets/lowered/pass/init_loops.hpp" #include "snippets/lowered/pass/insert_buffers.hpp" #include "snippets/lowered/pass/insert_load_store.hpp" +#include "snippets/lowered/pass/insert_broadcastmove.hpp" #include "snippets/lowered/pass/load_movebroadcast_to_broadcastload.hpp" #include "snippets/lowered/pass/allocate_buffers.hpp" #include "snippets/lowered/pass/propagate_layout.hpp" @@ -40,6 +42,7 @@ #include "snippets/lowered/pass/identify_buffers.hpp" #include "snippets/lowered/pass/validate_loops.hpp" #include "snippets/lowered/pass/insert_loops.hpp" +#include "snippets/lowered/pass/optimize_domain.hpp" #include "transformations/utils/utils.hpp" @@ -60,13 +63,21 @@ namespace snippets { namespace op { void Subgraph::set_generator(std::shared_ptr generator) { - m_generator = generator; + m_generator = std::move(generator); } void Subgraph::set_virtual_port_count(const size_t count) { m_virtual_port_count = count; } +void Subgraph::set_min_jit_work_amount(const size_t jit_work_amount) { + config.m_min_jit_work_amount = jit_work_amount; +} + +void Subgraph::set_min_parallel_work_amount(const size_t parallel_work_amount) { + config.m_min_parallel_work_amount = parallel_work_amount; +} + auto Subgraph::is_domain_sensitive_op(const std::shared_ptr& op) -> bool { return ov::is_type(op) || ov::is_type(op) || @@ -151,6 +162,7 @@ Subgraph::Subgraph(const OutputVector& args, const std::shared_ptr& b for (size_t i = 0; i < body->get_output_size(); ++i) m_output_descriptions[0].push_back(std::make_shared(i, i)); m_transformations_allowed = false; + m_shape_infer = std::make_shared(body); } Subgraph::Subgraph(const NodeVector& args, const std::shared_ptr& body) @@ -161,36 +173,6 @@ std::shared_ptr Subgraph::clone_with_new_inputs(const OutputVector& inputs return make_shared(inputs, body().clone()); } -std::vector Subgraph::reshape_body(const std::vector& input_shapes) { - auto& params = body_ptr()->get_parameters(); - OPENVINO_ASSERT(params.size() == input_shapes.size(), "Got invalid number of input shapes to reshape subgraph body"); - for (size_t i = 0; i < params.size(); ++i) { - params[i]->set_partial_shape(input_shapes[i]); - } - body_ptr()->validate_nodes_and_infer_types(); - std::vector output_shapes; - for (const auto& res : body_ptr()->get_results()) { - output_shapes.emplace_back(res->get_input_partial_shape(0)); - } - return output_shapes; -} - -std::vector Subgraph::reshape_body(const std::vector& input_shapes) { - auto& params = body_ptr()->get_parameters(); - OPENVINO_ASSERT(params.size() == input_shapes.size(), "Got invalid number of input shapes to reshape subgraph body"); - for (size_t i = 0; i < params.size(); ++i) { - params[i]->set_partial_shape(input_shapes[i]); - } - body_ptr()->validate_nodes_and_infer_types(); - std::vector output_shapes; - for (const auto& res : body_ptr()->get_results()) { - auto pshape = res->get_input_partial_shape(0); - OPENVINO_ASSERT(pshape.is_static(), "Subgraph inferred dynamic output shape during reshape with static inputs"); - output_shapes.emplace_back(res->get_input_partial_shape(0).get_shape()); - } - return output_shapes; -} - void Subgraph::validate_and_infer_types() { INTERNAL_OP_SCOPE(Subgraph); OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::validate_and_infer_types") @@ -282,7 +264,7 @@ auto Subgraph::wrap_node_as_subgraph(const std::shared_ptr& node) -> s } void Subgraph::fill_empty_output_names(const Output& target_output_node, const Output& replacement_output_node) { - NGRAPH_SUPPRESS_DEPRECATED_START + OPENVINO_SUPPRESS_DEPRECATED_START auto& out_tensor = target_output_node.get_tensor(); const std::string new_name = ov::op::util::get_ie_output_name(replacement_output_node); if (ov::descriptor::get_ov_tensor_legacy_name(out_tensor).empty()) { @@ -291,7 +273,7 @@ void Subgraph::fill_empty_output_names(const Output& target_output_node, c if (!replacement_output_node.get_names().empty()) { out_tensor.set_names(replacement_output_node.get_names()); } - NGRAPH_SUPPRESS_DEPRECATED_END + OPENVINO_SUPPRESS_DEPRECATED_END } auto Subgraph::constant_input_should_be_inside_body(const std::shared_ptr& node) -> bool { @@ -301,166 +283,6 @@ auto Subgraph::constant_input_should_be_inside_body(const std::shared_ptr(node); } -/// -/// \brief Canonization transforms original subgraph and to canonical form suitable for code generation. In particular, -/// it handles supported layout conversions, broadcasts inputs and outputs to a single rank and layout. Canonicalization -/// returns master-shape (max rank + max dimensions over all outputs) that can be used for scheduling. -/// Canonicalization currently supports only the following layout conversions: -/// * None: all inputs have the same layout -/// * Planar + blocked: some inputs have blocked, and some have planar layouts, e.g. + -/// Also there is precision aligning inside body of subgraph during canonicalization -ov::PartialShape snippets::op::Subgraph::canonicalize(const BlockedShapeVector& outputShapes, - const BlockedShapeVector& inputShapes) { - INTERNAL_OP_SCOPE(Subgraph); - OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::canonicalize") - NODE_VALIDATION_CHECK(this, inputShapes.size() == body_ptr()->get_parameters().size(), - "Number of parameters for snippet doesn't match passed to generate method: ", - inputShapes.size(), " vs ", body_ptr()->get_parameters().size(), "."); - - NODE_VALIDATION_CHECK(this, outputShapes.size() == body_ptr()->get_results().size(), - "number of results for snippet doesn't match passed to generate method: ", - outputShapes.size(), " vs ", body_ptr()->get_results().size(), "."); - - auto getMaxRankBlockedShape = [](const BlockedShapeVector& blockedShapes) -> const BlockedShape& { - return *std::max_element(blockedShapes.begin(), blockedShapes.end(), - [&](const BlockedShape& lhs, const BlockedShape& rhs) { - return std::get<0>(lhs).size() < std::get<0>(rhs).size(); - }); - }; - PartialShape baseShape; - AxisVector baseOrder; - std::tie(baseShape, baseOrder, std::ignore) = getMaxRankBlockedShape(inputShapes); - maxInputRank = baseShape.size(); - appendOnesForCanonical.resize(inputShapes.size(), 0); - const bool baseIsBlocked = baseOrder.size() != std::set(baseOrder.begin(), baseOrder.end()).size(); - for (size_t i = 0; i < inputShapes.size(); i++) { - const auto& blockedShape = inputShapes[i]; - PartialShape inShape; - AxisVector inOrder; - element::Type inType; - std::tie(inShape, inOrder, inType) = blockedShape; - const auto inRank = inShape.size(); - NODE_VALIDATION_CHECK(this, inRank <= maxInputRank, "Input rank can't be larger than output rank in snippets."); - if (inRank < maxInputRank) { - appendOnesForCanonical[i] = maxInputRank - inRank; - PartialShape newShape(ov::Shape(maxInputRank, 1)); - // todo: more complicated logics is needed if we want to merge smth else than blocked and planar - if (baseIsBlocked) { - const bool inIsNotBlocked = inOrder.size() == std::set(inOrder.begin(), inOrder.end()).size(); - NODE_VALIDATION_CHECK(this, inIsNotBlocked, "Snippets don't support conversion between blocked layouts of different ranks"); - inShape.insert(inShape.end(), ov::Dimension(1)); - appendOnesForCanonical[i]--; - } - NODE_VALIDATION_CHECK(this, PartialShape::broadcast_merge_into(newShape, inShape, ov::op::AutoBroadcastType::NUMPY), - "Failed to broadcast_merge inputs in snippets canonicalization"); - inShape = std::move(newShape); - } else { - // todo: 4d blocked + 5d planar layouts are not supported: + - NODE_VALIDATION_CHECK(this, - equal(baseOrder.begin(), baseOrder.end(), inOrder.begin()), - "Snippets canonicalization got input shapes of equal ranks but different layouts, which is not supported"); - } - ov::PartialShape tmpPShape(baseShape); - // todo: we need to generalize canonicalization for domain-sensitive ops. E.g. MatMul inputs can't be broadcasted one to another - if (!config.m_has_domain_sensitive_ops) - NODE_VALIDATION_CHECK(this, - PartialShape::broadcast_merge_into(tmpPShape, inShape, ::ov::op::AutoBroadcastType::NUMPY), - "Failed to create broadcastable shapes in snippets canonicalization"); - const auto paramShape = body_ptr()->get_parameters()[i]->get_partial_shape(); - const auto paramType = body_ptr()->get_parameters()[i]->get_element_type(); - if (paramShape.size() != inShape.size() || !equal(paramShape.begin(), paramShape.end(), inShape.begin())) - body_ptr()->replace_parameter(i, std::make_shared(paramType, inShape)); - } - body_ptr()->validate_nodes_and_infer_types(); - - auto skipStartEndOnes = [](const PartialShape& shape) { - auto begin = shape.begin(); - auto end = shape.end(); - while (begin != end && *begin == 1) - begin++; - while (begin != end && *(end - 1) == 1) - end--; - - PartialShape trimmedShape(std::vector(end - begin, 1)); - std::copy(begin, end, trimmedShape.begin()); - return trimmedShape; - }; - - // Check that output shapes are broadcastable => can be scheduled - const auto& body_results = body_ptr()->get_results(); - PartialShape outPShape = body_results[0]->get_input_partial_shape(0); - // todo: we need a slightly more general approach for backward ROI propagation - const auto& result_parent = body_results[0]->get_input_node_shared_ptr(0); - if (body_results.size() == 1 && - ov::is_type(result_parent) && - ov::is_type(result_parent->get_input_node_shared_ptr(0))) { - outPShape = result_parent->get_input_partial_shape(0); - } else { - for (size_t i = 0; i < body_results.size(); i++) { - auto shape_i = body_results[i]->get_input_partial_shape(0); - auto outputShape_i = std::get<0>(outputShapes[i]); - // Check that the produced output shape corresponds to the passed shape - // Some produced shapes may have been changed to be broadcastable (e.g. blocked + planar outputs), - // so we need to remove leading and trailing "1" before the comparison - PartialShape pShape_i(skipStartEndOnes(shape_i)); - bool compatibleWithPassedShape = PartialShape::broadcast_merge_into(pShape_i, - skipStartEndOnes(outputShape_i), - ::ov::op::AutoBroadcastType::NUMPY); - NODE_VALIDATION_CHECK(this, compatibleWithPassedShape, - "Inferred and passed results shapes are incompatible for snippet "); - // Check that output shapes are broadcastable to each other => can be scheduled - bool compatibleWithOtherOutputs = PartialShape::broadcast_merge_into(outPShape, shape_i, - ::ov::op::AutoBroadcastType::NUMPY); - NODE_VALIDATION_CHECK(this, compatibleWithOtherOutputs, - "Snippets output shapes must be numpy broadcastable"); - } - } - - // We should insert Converts after Parameters and Constant and before Results - // to align precision inside Subgraph body that is supported by Plugin - align_element_types(outputShapes, inputShapes); - - master_shape = outPShape; - return master_shape; -} - -ov::PartialShape snippets::op::Subgraph::canonicalized_body_shape_infer(const BlockedShapeVector& inputShapes) { - std::vector normInputShapes; - for (size_t i = 0; i < inputShapes.size(); i++) { - PartialShape inShape = std::get<0>(inputShapes[i]); - const auto inRank = inShape.size(); - if (inRank < maxInputRank) { - PartialShape newShape(ov::Shape(maxInputRank, 1)); - for (size_t ir = 0; ir < inRank; ir++) { - newShape[appendOnesForCanonical[i] + ir] = inShape[ir]; - } - normInputShapes.push_back(newShape.get_shape()); - } else { - normInputShapes.push_back(inShape.get_shape()); - } - } - reshape_body(normInputShapes); - - const auto& body_results = body_ptr()->get_results(); - PartialShape outPShape = body_results[0]->get_input_partial_shape(0); - const auto& result_parent = body_results[0]->get_input_node_shared_ptr(0); - if (body_results.size() == 1 && - ov::is_type(result_parent) && - ov::is_type(result_parent->get_input_node_shared_ptr(0))) { - outPShape = result_parent->get_input_partial_shape(0); - } else { - for (size_t i = 0; i < body_results.size(); i++) { - auto shape_i = body_results[i]->get_input_partial_shape(0); - bool compatibleWithOtherOutputs = PartialShape::broadcast_merge_into(outPShape, shape_i, - ::ov::op::AutoBroadcastType::NUMPY); - NODE_VALIDATION_CHECK(this, compatibleWithOtherOutputs, - "Snippets output shapes must be numpy broadcastable"); - } - } - master_shape = outPShape; - return master_shape; -} - bool Subgraph::check_broadcast(const std::shared_ptr& node) noexcept { const auto elementwise = std::dynamic_pointer_cast(node); return @@ -470,154 +292,109 @@ bool Subgraph::check_broadcast(const std::shared_ptr& node) noex } IShapeInferSnippets::Result Subgraph::shape_infer(const std::vector& input_shapes) { - if (!m_shape_infer && !m_linear_ir) { - OPENVINO_ASSERT(body_ptr(), "Can't create shape infer for Subgraph with an empty body"); - m_shape_infer = std::make_shared(body_ptr()); - } else if (!std::dynamic_pointer_cast(m_shape_infer) && m_linear_ir) { - m_shape_infer = std::make_shared(m_linear_ir); - } + OPENVINO_ASSERT(m_shape_infer, "Attempt to call shape_infer when it's not initialized"); return m_shape_infer->infer(input_shapes); } -Subgraph::NgraphShapeInfer::NgraphShapeInfer(const std::shared_ptr& body) : - m_ngraph_body(body), m_parameters(body->get_parameters()), m_results(body->get_results()) { +Subgraph::OVShapeInfer::OVShapeInfer(const std::shared_ptr& body) : + m_ov_body(body) { + OPENVINO_ASSERT(m_ov_body, "Can't initialize shape infer with empty body"); } -IShapeInferSnippets::Result Subgraph::NgraphShapeInfer::infer(const std::vector& input_shapes) { - OPENVINO_ASSERT(m_parameters.size() == input_shapes.size(), "Got invalid number of input shapes to reshape subgraph body"); - for (size_t i = 0; i < m_parameters.size(); ++i) - m_parameters[i]->set_partial_shape(utils::vdims_to_pshape(input_shapes[i].get())); - m_ngraph_body->validate_nodes_and_infer_types(); +IShapeInferSnippets::Result Subgraph::OVShapeInfer::infer(const std::vector& input_shapes) { + const ParameterVector& parameters = m_ov_body->get_parameters(); + const ResultVector& results = m_ov_body->get_results(); + OPENVINO_ASSERT(parameters.size() == input_shapes.size(), "Got invalid number of input shapes to reshape subgraph body"); + for (size_t i = 0; i < parameters.size(); ++i) + parameters[i]->set_partial_shape(utils::vdims_to_pshape(input_shapes[i].get())); + m_ov_body->validate_nodes_and_infer_types(); std::vector outputDims; - for (const auto& res : m_results) + for (const auto& res : results) outputDims.emplace_back(utils::pshape_to_vdims(res->get_input_partial_shape(0))); m_last_result = {outputDims, ShapeInferStatus::success}; return m_last_result; } -Subgraph::LIRShapeInfer::LIRShapeInfer(const std::shared_ptr& body) : - m_lir_body(body) { - for (const auto& io_expr : m_lir_body->get_IO_ops()) { - switch (io_expr->get_type()) { - case IOExpression::io_type::INPUT : m_param_exprs.push_back(io_expr); break; - case IOExpression::io_type::OUTPUT : m_result_exprs.push_back(io_expr); break; - default : OPENVINO_THROW("Undefined io expression type"); +VectorDims Subgraph::infer_master_shape() { + std::vector output_dims; + if (is_dynamic()) { + // Note that in case of dynamic implementation shapeInfer() is called before PrepareParams, + // so there must be last_result available + // In principle, we can instantiate shape_infer here, but it's not an intended pipeline behavior. + OPENVINO_ASSERT(m_shape_infer, "Can't calculate master_shape when shapeInfer is not initialized"); + output_dims = m_shape_infer->get_last_result().dims; + OPENVINO_ASSERT(!output_dims.empty(), "Can't calculate master_shape before the first shape inference"); + } else { + for (const auto& res : body_ptr()->get_results()) { + const auto& res_input = res->input(0); + OPENVINO_ASSERT(res_input.get_partial_shape().is_static(), "Result have dynamic shape in static pipeline"); + // We need to account to the shape's layout stored in Output rt_info + const auto& planar_shape = utils::get_planar_pshape(res_input.get_source_output()); + output_dims.emplace_back(planar_shape.get_shape()); } } -} -IShapeInferSnippets::Result -Subgraph::LIRShapeInfer::infer(const std::vector& input_shapes) { - OPENVINO_ASSERT(m_param_exprs.size() == input_shapes.size(), "Got invalid number of input shapes in LIR ShapeInfer"); - // todo: check that order of param_exprs is always the same as that of input_shapes - // if not use io_expr index to sort in constructor + if (output_dims.size() == 1) + return output_dims.front(); - for (size_t i = 0; i < m_param_exprs.size(); ++i) { - m_param_exprs[i]->get_output_port_descriptor(0)->set_shape(input_shapes[i]); - } - for (const auto& expr : *m_lir_body) { - if (expr->needShapeInfer()) - expr->updateShapes(); - } - std::vector outputDims; - outputDims.reserve(m_result_exprs.size()); - for (const auto& r : m_result_exprs) { - outputDims.push_back(r->get_input_port_descriptor(0)->get_shape()); - } - m_last_result = {outputDims, ShapeInferStatus::success}; - return m_last_result; + const auto& default_broadcasting = std::make_shared(); + // Note: we have to convert vector to vector> + // because of shape inference interface + std::vector> inputs; + inputs.reserve(output_dims.size()); + for (const auto& d : output_dims) + inputs.emplace_back(d); + return default_broadcasting->infer(inputs).dims.front(); } std::shared_ptr -Subgraph::convert_body_to_linear_ir(const std::shared_ptr& shape_infer_factory) const { +Subgraph::convert_body_to_linear_ir(const std::shared_ptr& shape_infer_factory) { lowered::Config lowering_config; lowering_config.m_save_expressions = config.m_has_domain_sensitive_ops; lowering_config.m_need_fill_tail_register = config.m_has_domain_sensitive_ops; lowering_config.m_loop_depth = tileRank; - - return std::make_shared(body_ptr(), shape_infer_factory, lowering_config); -} - -void Subgraph::align_element_types(const BlockedShapeVector& outputShapes, - const BlockedShapeVector& inputShapes) { - // We should insert Convert before Results to set original output element type if needed - const auto& body_results = body_ptr()->get_results(); - for (size_t i = 0; i < outputShapes.size(); i++) { - const auto needed_out_type = std::get<2>(outputShapes[i]); - if (body_results[i]->get_input_element_type(0) != needed_out_type) { - auto parent_output = body_results[i]->get_input_source_output(0); - std::shared_ptr consumer = body_results[i]; - - // Snippets supports Transpose only after Parameter or before Result nodes - // So we have to insert Convert before Transpose (if there is) on Subgraph outputs - const auto transpose = ov::as_type_ptr(parent_output.get_node_shared_ptr()); - if (transpose) { - OPENVINO_ASSERT(parent_output.get_target_inputs().size() == 1, - "If Result has Transpose on input, this Result must be single consumer of the Transpose"); - parent_output = transpose->get_input_source_output(0); - consumer = transpose; - } - - const auto convert = std::make_shared(parent_output, needed_out_type); - ov::copy_runtime_info(parent_output.get_node_shared_ptr(), convert); - - consumer->set_argument(0, convert); - consumer->validate_and_infer_types(); - if (consumer != body_results[i]) - body_results[i]->validate_and_infer_types(); - } - } - - // We should change existing element type to original for Parameters if needed - const auto& parameters = body_ptr()->get_parameters(); - for (size_t i = 0; i < inputShapes.size(); ++i) { - const auto needed_in_type = std::get<2>(inputShapes[i]); - const auto& parameter = parameters[i]; - const auto original_type = parameter->get_element_type(); - if (original_type != needed_in_type) { - parameter->set_element_type(needed_in_type); - parameter->validate_and_infer_types(); - - auto parent_output = parameter->output(0); - auto consumer_inputs = parent_output.get_target_inputs(); - - // Snippets supports Transpose only after Parameter or before Result nodes - // So we have to insert Convert after Transpose (if there is) on Subgraph inputs - if (std::any_of(consumer_inputs.cbegin(), consumer_inputs.cend(), - [](const ov::Input& input) { return ov::is_type(input.get_node()); })) { - OPENVINO_ASSERT(consumer_inputs.size() == 1, - "If Parameter has Transpose on output, this Transpose must be single consumer of the Parameter"); - const auto transpose = consumer_inputs.begin()->get_node()->shared_from_this(); - transpose->validate_and_infer_types(); - - parent_output = transpose; - consumer_inputs = parent_output.get_target_inputs(); - } - - const auto convert = std::make_shared(parent_output, original_type); - ov::copy_runtime_info(parent_output.get_node_shared_ptr(), convert); - - for (const auto input : consumer_inputs) { - const auto& input_node = input.get_node(); - if (input_node == convert.get()) { - continue; - } - input_node->set_argument(input.get_index(), convert->output(0)); - } - } - } -} - -void Subgraph::data_flow_transformations(const std::vector& backend_passes) { + lowering_config.m_enable_domain_optimization = !config.m_has_domain_sensitive_ops; + lowering_config.m_min_parallel_work_amount = config.m_min_parallel_work_amount; + lowering_config.m_min_kernel_work_amount = config.m_min_jit_work_amount; + + m_linear_ir = std::make_shared(body_ptr(), shape_infer_factory, lowering_config); + m_shape_infer = m_linear_ir->get_shape_infer_instance(); + return m_linear_ir; +} + +std::shared_ptr Subgraph::clone() const { + ov::OutputVector subgraph_node_inputs; + for (const auto &input : input_values()) { + auto new_input = std::make_shared(input.get_element_type(), input.get_partial_shape()); + subgraph_node_inputs.push_back(new_input); + } + std::shared_ptr new_body = body_ptr()->clone(); + auto result = std::make_shared(subgraph_node_inputs, new_body); + // Note: ov::copy_runtime_info accepts only shared_ptr as "from" but never modifies it, + // so we have to cast away constness to copy runtime info + ov::copy_runtime_info(const_pointer_cast(shared_from_this()), result); + result->set_friendly_name(get_friendly_name()); + if (m_linear_ir) + result->m_linear_ir = std::make_shared(m_linear_ir->deep_copy()); + // Note: we don't update shapeInfer here, since it's initialized in the constructor + if (m_generator) + result->m_generator = m_generator->clone(); + return result; +} + +void Subgraph::data_flow_transformations(const BlockedShapeVector& blocked_input_shapes, + const std::vector& input_precisions, + const std::vector& output_precisions, + const std::vector& backend_passes) { INTERNAL_OP_SCOPE(Subgraph); OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::op::data_flow_transformations") - const auto& params = body_ptr()->get_parameters(); - bool inputs_has_dynamic_last_dims = std::any_of(params.begin(), params.end(), - [](const shared_ptr& p) { - return p->get_partial_shape().rbegin()->is_dynamic(); - }); - snippets::pass::Manager manager; + ov::snippets::pass::Manager manager; + if (!blocked_input_shapes.empty()) + manager.register_pass(blocked_input_shapes); + if (!input_precisions.empty() && !output_precisions.empty()) + manager.register_pass(input_precisions, output_precisions); + if (config.m_has_domain_sensitive_ops) { manager.register_pass(); manager.register_pass(); @@ -627,14 +404,6 @@ void Subgraph::data_flow_transformations(const std::vector(); manager.register_pass(); manager.register_pass(); - // todo: presently dynamic pipeline is activated even if the last two dimension are static - // In general, we can use static kernels in this case, but several parameters (src and dst memory pointers for example) - // should be passed as run-time args, so it's a mixed mode: kernel is shape-aware, but some additional runtime args are required - // Presently Broadcasting is organized in the following way: - // * ALL last dims are static => broadcasting is handled via MoveBroadcast and pointer arithmetics (even for dynamic upper dims) - if (!inputs_has_dynamic_last_dims) { - manager.register_pass(); - } manager.register_pass(m_generator->get_target_machine()); manager.register_pass(); @@ -645,11 +414,17 @@ void Subgraph::data_flow_transformations(const std::vectorget_target_machine()->get_lanes(); const int32_t buffer_allocation_rank = static_cast(linear_ir.get_config().m_loop_depth); @@ -666,7 +441,11 @@ void Subgraph::control_flow_transformations(lowered::LinearIR& linear_ir, common_pipeline.register_pass(buffer_allocation_rank); common_pipeline.register_pass(vector_size); common_pipeline.register_pass(); + common_pipeline.register_pass(); common_pipeline.register_pass(); + + common_pipeline.register_pass(); + common_pipeline.register_pass(); common_pipeline.register_pass(); common_pipeline.register_pass(); @@ -686,51 +465,44 @@ void Subgraph::control_flow_transformations(lowered::LinearIR& linear_ir, final_pipeline.register_pass(); final_pipeline.run(linear_ir); - m_buffer_scratchpad = buffer_allocation_pass->get_scratchpad_size(); + lowering_result.buffer_scratchpad_size = buffer_allocation_pass->get_scratchpad_size(); } -snippets::Schedule Subgraph::generate(const BlockedShapeVector& output_shapes, - const BlockedShapeVector& input_shapes, +snippets::Schedule Subgraph::generate(const BlockedShapeVector& blocked_input_shapes, + const std::vector& input_precisions, + const std::vector& output_precisions, + const std::vector& data_flow_backend_passes, + const lowered::pass::PassPipeline& backend_passes_pre_common, + const lowered::pass::PassPipeline& backend_passes_post_common, + const std::shared_ptr& factory, const void* compile_params) { - canonicalize(output_shapes, input_shapes); - return generate(compile_params); -} - -snippets::Schedule Subgraph::generate(const BlockedShapeVector& output_shapes, - const BlockedShapeVector& input_shapes, - const std::vector& data_flow_passes, - const lowered::pass::PassPipeline& control_flow_passes_pre_common, - const lowered::pass::PassPipeline& control_flow_passes_post_common, - const std::shared_ptr& shape_infer_factory, - const void* compile_params) { - canonicalize(output_shapes, input_shapes); - return generate(data_flow_passes, control_flow_passes_pre_common, control_flow_passes_post_common, - shape_infer_factory, compile_params); -} - -snippets::Schedule Subgraph::generate(const void* compile_params) { - return generate({}, {}, {}, nullptr, compile_params); + data_flow_transformations(blocked_input_shapes, input_precisions, output_precisions, data_flow_backend_passes); + convert_body_to_linear_ir(factory); + return generate_from_linear_ir(backend_passes_pre_common, backend_passes_post_common, compile_params); } -snippets::Schedule Subgraph::generate(const std::vector& data_flow_passes, - const lowered::pass::PassPipeline& control_flow_passes_pre_common, - const lowered::pass::PassPipeline& control_flow_passes_post_common, - const std::shared_ptr& shape_infer_factory, - const void* compile_params) { +snippets::Schedule Subgraph::generate_from_linear_ir(const lowered::pass::PassPipeline& backend_passes_pre_common, + const lowered::pass::PassPipeline& backend_passes_post_common, + const void* compile_params) const { INTERNAL_OP_SCOPE(Subgraph); OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::op::generate") - NGRAPH_CHECK(m_generator != nullptr, "generate is called while generator is not set"); - - data_flow_transformations(data_flow_passes); - - lowered::LinearIR linear_ir = *convert_body_to_linear_ir(shape_infer_factory); - control_flow_transformations(linear_ir, control_flow_passes_pre_common, control_flow_passes_post_common); + OPENVINO_ASSERT(m_generator != nullptr, "generate is called while generator is not set"); // actual code emission - const auto& lowering_result = m_generator->generate(linear_ir, linear_ir.get_config(), compile_params); - const auto ptr = lowering_result.binary_code; - - return {master_shape, false /*canBeLinearized*/, ptr}; + // Note: some transformations performed in the generator, e.g. tail insertion, can break shape propagation + // until we fix this behavior, we have to make a copy of LIR before giving it to the generator. + OPENVINO_ASSERT(m_linear_ir, "Attempt to call generate, when linear IR was not initialized"); + auto linear_ir = m_linear_ir->deep_copy(); + LoweringResult lowering_result; + control_flow_transformations(linear_ir, lowering_result, backend_passes_pre_common, backend_passes_post_common); + m_generator->generate(linear_ir, lowering_result, compile_params); + + VectorDims parallel_exec_domain = linear_ir.get_master_shape(); + const size_t loop_depth = linear_ir.get_config().m_loop_depth; + for (size_t i = 0; i < loop_depth; i++) + parallel_exec_domain[parallel_exec_domain.size() - 1 - i] = 1; + + return {parallel_exec_domain, std::move(lowering_result)}; } void Subgraph::print() const { diff --git a/src/common/snippets/src/pass/align_element_types.cpp b/src/common/snippets/src/pass/align_element_types.cpp new file mode 100644 index 00000000000000..da1ab1cb2c038f --- /dev/null +++ b/src/common/snippets/src/pass/align_element_types.cpp @@ -0,0 +1,106 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "snippets/pass/align_element_types.hpp" +#include "snippets/itt.hpp" + +namespace ov { +namespace snippets { + +pass::AlignElementTypes::AlignElementTypes(std::vector input_precisions, + std::vector output_precisions) : + m_input_precisions(std::move(input_precisions)), + m_output_precisions(std::move(output_precisions)) { +} + +bool pass::AlignElementTypes::run_on_model(const std::shared_ptr& m) { + RUN_ON_MODEL_SCOPE(AlignElementTypes); + OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::AlignElementTypes") + bool is_modified = false; + const auto& results = m->get_results(); + const auto& params = m->get_parameters(); + OPENVINO_ASSERT(m_input_precisions.size() == params.size() && m_output_precisions.size() == results.size(), + "Number of parameters for snippet doesn't match passed to the Canonicalization pass. "); + + // We should insert Convert before Results to set original output element type if needed + for (size_t i = 0; i < m_output_precisions.size(); i++) { + const auto needed_out_type = m_output_precisions[i]; + if (results[i]->get_input_element_type(0) != needed_out_type) { + std::shared_ptr consumer = results[i]; + auto parent_output = consumer->get_input_source_output(0); + + // Snippets supports Transpose only after Parameter or before Result nodes + // So we have to insert Convert before Transpose (if there is) on Subgraph outputs + const auto transpose = ov::as_type_ptr(parent_output.get_node_shared_ptr()); + if (transpose) { + OPENVINO_ASSERT(parent_output.get_target_inputs().size() == 1, + "If Result has Transpose on input, this Result must be single consumer of the Transpose"); + parent_output = transpose->get_input_source_output(0); + consumer = transpose; + } + + const auto convert = std::make_shared(parent_output, needed_out_type); + ov::copy_runtime_info(parent_output.get_node_shared_ptr(), convert); + + consumer->set_argument(0, convert); + consumer->validate_and_infer_types(); + if (transpose) + results[i]->validate_and_infer_types(); + is_modified = true; + } + } + + // We should change existing element type to original for Parameters if needed + for (size_t i = 0; i < m_input_precisions.size(); ++i) { + const auto needed_in_type = m_input_precisions[i]; + const auto& parameter = params[i]; + const auto original_type = parameter->get_element_type(); + if (original_type != needed_in_type) { + parameter->set_element_type(needed_in_type); + parameter->validate_and_infer_types(); + + auto parent_output = parameter->output(0); + auto consumer_inputs = parent_output.get_target_inputs(); + + const auto& first_child = consumer_inputs.begin()->get_node()->shared_from_this(); + // Note: RankNormalization of is designed for shape-inference purposes only. + // It does not process any data (nor does it emit any code), so it doesn't require Convert operations + if (is_type(first_child)) { + OPENVINO_ASSERT(consumer_inputs.size() == 1, "RankNormalization is supposed to be the only consumer"); + parent_output = first_child->output(0); + consumer_inputs = parent_output.get_target_inputs(); + } + + // Snippets supports Transpose only after Parameter or before Result nodes + // So we have to insert Convert after Transpose (if there is) on Subgraph inputs + if (std::any_of(consumer_inputs.cbegin(), consumer_inputs.cend(), + [](const ov::Input& input) { return ov::is_type(input.get_node()); })) { + OPENVINO_ASSERT(consumer_inputs.size() == 1, + "If Parameter has Transpose on output, this Transpose must be single consumer of the Parameter"); + const auto transpose = consumer_inputs.begin()->get_node()->shared_from_this(); + transpose->validate_and_infer_types(); + + parent_output = transpose; + consumer_inputs = parent_output.get_target_inputs(); + } + + const auto& convert = std::make_shared(parent_output, original_type); + ov::copy_runtime_info(parent_output.get_node_shared_ptr(), convert); + + for (const auto input : consumer_inputs) { + const auto& input_node = input.get_node(); + if (input_node == convert.get()) { + continue; + } + input_node->set_argument(input.get_index(), convert->output(0)); + } + + is_modified = true; + } + } + return is_modified; +} + +} // namespace snippets +} // namespace ov \ No newline at end of file diff --git a/src/common/snippets/src/pass/broadcast_to_movebroadcast.cpp b/src/common/snippets/src/pass/broadcast_to_movebroadcast.cpp index 65fbbc162a8ada..cd803b163b5bbf 100644 --- a/src/common/snippets/src/pass/broadcast_to_movebroadcast.cpp +++ b/src/common/snippets/src/pass/broadcast_to_movebroadcast.cpp @@ -5,7 +5,7 @@ #include "snippets/itt.hpp" #include "snippets/pass/broadcast_to_movebroadcast.hpp" -#include "snippets/pass/insert_movebroadcast.hpp" +#include "snippets/op/broadcastmove.hpp" #include "openvino/pass/pattern/op/wrap_type.hpp" #include "openvino/opsets/opset1.hpp" @@ -30,15 +30,19 @@ ov::snippets::pass::BroadcastToMoveBroadcast::BroadcastToMoveBroadcast() { const auto target_shape = root->get_output_partial_shape(0); const auto value_shape = root->get_input_partial_shape(0); - if (target_shape.is_dynamic() || value_shape.is_dynamic()) { - return false; + OPENVINO_ASSERT(target_shape.is_static() && value_shape.rank().is_static(), "Broadcast with dynamic target shape is not supported in Snippets"); + // Insert BroadcastMove only if the last dimension needs to be broadcasted. Higher-level dims broadcasting + // will be handled by pointer arithmetics. Note that this behavior should be changed in case of full op::Boradcast support. + Output in_value = root->input_value(0); + if (*target_shape.rbegin() != *value_shape.rbegin()) { + auto broadcasted_shape = value_shape; + *broadcasted_shape.rbegin() = *target_shape.rbegin(); + const auto& broadcast_node = std::make_shared(in_value, broadcasted_shape); + in_value = broadcast_node->output(0); } - const auto broadcast_node = ov::snippets::pass::InsertMoveBroadcast::BroadcastNodeLastDim(root->input_value(0), - target_shape.get_shape(), - value_shape.get_shape()); - replace_output_update_name(root->output(0), broadcast_node); - ov::copy_runtime_info(root, broadcast_node.get_node_shared_ptr()); + replace_output_update_name(root->output(0), in_value); + ov::copy_runtime_info(root, in_value.get_node_shared_ptr()); return true; }; diff --git a/src/common/snippets/src/pass/canonicalization.cpp b/src/common/snippets/src/pass/canonicalization.cpp new file mode 100644 index 00000000000000..23414d2925bf36 --- /dev/null +++ b/src/common/snippets/src/pass/canonicalization.cpp @@ -0,0 +1,84 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "snippets/pass/canonicalization.hpp" +#include "snippets/op/rank_normalization.hpp" +#include "snippets/itt.hpp" +#include "snippets/utils.hpp" +#include "snippets/lowered/port_descriptor.hpp" + +namespace ov { +namespace snippets { + +pass::Canonicalization::Canonicalization(const BlockedShapeVector& blocked_input_shapes) { + m_in_shapes.reserve(blocked_input_shapes.size()); + m_in_layouts.reserve(blocked_input_shapes.size()); + for (const auto& bs : blocked_input_shapes) { + m_has_dynamic_inputs |= utils::is_dynamic_vdims(bs.first); + m_in_shapes.emplace_back(bs.first); + m_in_layouts.emplace_back(bs.second); + // Note: Blocking (if any) must be accounted for in input shapes + OPENVINO_ASSERT(m_in_shapes.back().size() == m_in_layouts.back().size(), "Input shapes and layouts must have the same rank"); + } +} + +bool pass::Canonicalization::run_on_model(const std::shared_ptr& m) { + RUN_ON_MODEL_SCOPE(Canonicalization); + OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::Canonicalization") + bool is_modified = false; + const ParameterVector& params = m->get_parameters(); + OPENVINO_ASSERT(m_in_shapes.size() == params.size(), + "Number of parameters for snippet doesn't match passed to the Canonicalization pass. ", + "Expected: ", m_in_shapes.size(), " Got: ", params.size(), "."); + + // Note that shape rank also incorporates layout, so NCHW16c would have shape rank 5 + auto is_blocked_layout = [](const Layout& l) { + return l.size() != std::set(l.begin(), l.end()).size(); + }; + auto compare_ranks = [](const Layout& l, const Layout& r) { + return l.size() < r.size(); + }; + // Layout with the max rank + const auto& max_rank_it = std::max_element(m_in_layouts.begin(), m_in_layouts.end(), compare_ranks); + Layout base_layout = *max_rank_it; + size_t max_rank = base_layout.size(); + const bool base_is_blocked = is_blocked_layout(base_layout); + + for (size_t i = 0; i < m_in_layouts.size(); i++) { + const auto& i_layout = m_in_layouts[i]; + const auto& i_shape = m_in_shapes[i]; + const auto i_rank = i_layout.size(); + const bool i_is_blocked = is_blocked_layout(i_layout); + // Canonicalization logic briefly: + // * If this input is blocked => Reshape corresponding input parameter, so the following transformations + // will work with a shape of a larger rank. In dynamic case, this shape will be updated during shapeInfer() + // call, but the important thing is that the shape rank won't change. + // * If some of the input shapes is blocked (=> base_is_blocked), but this input is planar, + // then insert RankNormalization op after this input. This is needed, so all shapes inside the body have + // similar ranks. + if (i_is_blocked) { + OPENVINO_ASSERT(base_is_blocked && i_rank == max_rank, "If this shape is blocked, base must also be blocked"); + params[i]->set_partial_shape(snippets::utils::vdims_to_pshape(i_shape)); + is_modified = true; + } else if (i_rank < max_rank) { + size_t num_append = base_is_blocked; + OPENVINO_ASSERT(max_rank >= i_rank + num_append, "Unsupported blocked shapes combination in canonicalization"); + size_t num_prepend = max_rank - i_rank - num_append; + const auto& out = params[i]->output(0); + const auto& target_inputs = out.get_target_inputs(); + auto rank_norm = std::make_shared(out, num_prepend, num_append); + for (auto& in : target_inputs) + in.replace_source_output(rank_norm); + is_modified = true; + } else { + // todo: 4d blocked + 5d planar layouts are not supported: + + OPENVINO_ASSERT(equal(base_layout.begin(), base_layout.end(), i_layout.begin()), + "Canonicalization got input shapes of equal ranks but different layouts, which is not supported"); + } + } + return is_modified; +} + +} // namespace snippets +} // namespace ov \ No newline at end of file diff --git a/src/common/snippets/src/pass/collapse_subgraph.cpp b/src/common/snippets/src/pass/collapse_subgraph.cpp index 9acea3720e9550..6ed1054adac40c 100644 --- a/src/common/snippets/src/pass/collapse_subgraph.cpp +++ b/src/common/snippets/src/pass/collapse_subgraph.cpp @@ -16,7 +16,7 @@ #include "openvino/opsets/opset1.hpp" #include "openvino/core/rt_info.hpp" #include "transformations/utils/utils.hpp" -#include "ngraph/op/util/attr_types.hpp" +#include "openvino/op/util/attr_types.hpp" #include "openvino/core/validation_util.hpp" #include @@ -179,7 +179,10 @@ auto is_supported_op(const std::shared_ptr &n) -> bool { auto has_supported_in_out(const std::shared_ptr &n) -> bool { auto supported = [&n](descriptor::Tensor& t) -> bool { - // Todo: int32 isn't supported in general because i32 emitters are required for bit-exact i32 calculations in some cases + // TODO [122585] Need to add dynamic rank support + if (t.get_partial_shape().rank().is_dynamic()) + return false; + // TODO [105804] int32 isn't supported in general because i32 emitters are required for bit-exact i32 calculations in some cases // So i32 is supported exclusively for transposes and broadcast return TokenizeSnippets::get_supported_element_types().count(t.get_element_type()) != 0 || (t.get_element_type() == ov::element::i32 && diff --git a/src/common/snippets/src/pass/convert_constants.cpp b/src/common/snippets/src/pass/convert_constants.cpp index b5fb81b77dd98a..c374ee010d3446 100644 --- a/src/common/snippets/src/pass/convert_constants.cpp +++ b/src/common/snippets/src/pass/convert_constants.cpp @@ -24,8 +24,7 @@ ov::snippets::pass::ConvertConstantsToScalars::ConvertConstantsToScalars() { // Note that all Constants {1,1,1,1} are converted to Scalar {1} here // This is needed to simplify shape inference, otherwise {1,1,1,1} Constants can increase output rank // Also some operations support only scalar shapes, so we need separate scalars and shape [1] - const auto shape = constant->get_output_shape(0).size() == 0 ? ov::Shape{} : ov::Shape{1}; - auto scalar = std::make_shared(ov::op::v0::Constant(*constant, shape)); + auto scalar = std::make_shared(ov::op::v0::Constant(*constant, ov::Shape{1})); scalar->set_friendly_name(constant->get_friendly_name()); ov::copy_runtime_info(constant, scalar); ov::replace_node(constant, scalar); diff --git a/src/common/snippets/src/pass/hash.cpp b/src/common/snippets/src/pass/hash.cpp index 48dd9586ae4337..cea21e37e861cf 100644 --- a/src/common/snippets/src/pass/hash.cpp +++ b/src/common/snippets/src/pass/hash.cpp @@ -10,13 +10,12 @@ #include #include -#include "ngraph/ops.hpp" -#include "ngraph/opsets/opset.hpp" #include "openvino/core/except.hpp" #include "openvino/core/meta_data.hpp" #include "openvino/core/model.hpp" #include "openvino/op/util/framework_node.hpp" #include "openvino/opsets/opset1.hpp" +#include "openvino/runtime/aligned_buffer.hpp" #include "transformations/rt_info/primitives_priority_attribute.hpp" namespace ov { @@ -169,7 +168,7 @@ class SnippetsHasher : public ov::AttributeVisitor { m_node_type_name(node_type_name) {} void on_adapter(const std::string& name, ov::ValueAccessor& adapter) override { - if (const auto& a = ov::as_type>>(&adapter)) { + if (const auto& a = ov::as_type>>(&adapter)) { m_hash = hash_combine(hash_combine(m_hash, name), a->get()->get_info().variable_id); } else if (const auto& a = ov::as_type>>(&adapter)) { @@ -182,6 +181,17 @@ class SnippetsHasher : public ov::AttributeVisitor { m_hash = hash_combine(m_hash, data[i]); } } + } else if (const auto& a = + ov::as_type>>(&adapter)) { + if (name == "value" && m_node_type_name == "Constant") { + m_hash = hash_combine(m_hash, AttrType::constant); + const int64_t size = a->get()->size(); + m_hash = hash_combine(hash_combine(m_hash, AttrType::size), size); + auto data = static_cast(a->get()->get_ptr()); + for (int64_t i = 0; i < size; i++) { + m_hash = hash_combine(m_hash, data[i]); + } + } } else if (const auto& a = ov::as_type>(&adapter)) { const auto& attrs = a->get(); // Update node attributes in data field diff --git a/src/common/snippets/src/pass/mha_tokenization.cpp b/src/common/snippets/src/pass/mha_tokenization.cpp index 417c7ff043718b..e9f939e8d72d75 100644 --- a/src/common/snippets/src/pass/mha_tokenization.cpp +++ b/src/common/snippets/src/pass/mha_tokenization.cpp @@ -175,7 +175,7 @@ auto update_intermediate_supported_ops(std::shared_ptr& interm_op, ov: interm_op = interm_op->get_output_target_inputs(0).begin()->get_node()->shared_from_this(); } return true; -}; +} } // namespace bool ov::snippets::pass::TokenizeMHASnippets::is_matmul0_supported(const std::shared_ptr& matmul) { diff --git a/src/common/snippets/src/pass/propagate_precision.cpp b/src/common/snippets/src/pass/propagate_precision.cpp index 6ba1f5f3d09ad1..568db74d6a5c0a 100644 --- a/src/common/snippets/src/pass/propagate_precision.cpp +++ b/src/common/snippets/src/pass/propagate_precision.cpp @@ -32,7 +32,7 @@ bool ov::snippets::pass::PropagatePrecision::run_on_model(const std::shared_ptr< auto type_info = op->get_type_info(); std::set supported_precisions; // TODO: At the moment Softmax is decomposed on Linear IR level. - // When Softmax will be decomposed on NGraph level, remove it + // When Softmax will be decomposed on openvino level, remove it if (type_info.is_castable(ov::op::v1::Softmax::get_type_info_static())) { supported_precisions = {{ov::element::f32}}; } else { diff --git a/src/common/snippets/src/pass/set_softmax_ports.cpp b/src/common/snippets/src/pass/set_softmax_ports.cpp index 1651a6d6217495..f8d38d51ec59b5 100644 --- a/src/common/snippets/src/pass/set_softmax_ports.cpp +++ b/src/common/snippets/src/pass/set_softmax_ports.cpp @@ -25,11 +25,9 @@ ov::snippets::pass::SetSoftmaxPorts::SetSoftmaxPorts() { auto root = m.get_match_root(); const auto& pshape = root->get_input_partial_shape(0); - if (pshape.is_dynamic()) - return false; - const auto shape = pshape.get_shape(); - const auto rank = shape.size(); + OPENVINO_ASSERT(!pshape.rank().is_dynamic(), "SetSoftmaxPorts doesn't support dynamic ranks"); + const auto rank = pshape.rank().get_length(); int64_t axis; if (const auto softmax_v8 = ov::as_type_ptr(root)) { @@ -44,7 +42,7 @@ ov::snippets::pass::SetSoftmaxPorts::SetSoftmaxPorts() { OPENVINO_ASSERT(axis < static_cast(rank), "Softmax has incorrect axis"); std::vector subtensor(rank, 1); - for (size_t i = axis; i < rank; ++i) + for (auto i = axis; i < rank; ++i) subtensor[i] = lowered::PortDescriptor::ServiceDimensions::FULL_DIM; lowered::PortDescriptorUtils::set_port_descriptor_ptr(root->input(0), std::make_shared(root->input(0), subtensor)); diff --git a/src/common/snippets/src/pass/softmax_reshape_elimination.cpp b/src/common/snippets/src/pass/softmax_reshape_elimination.cpp index 2f60f1e1155c76..36a0afb7c11325 100644 --- a/src/common/snippets/src/pass/softmax_reshape_elimination.cpp +++ b/src/common/snippets/src/pass/softmax_reshape_elimination.cpp @@ -10,7 +10,7 @@ #include "openvino/core/rt_info.hpp" #include "openvino/pass/pattern/op/wrap_type.hpp" -#include +#include "openvino/core/validation_util.hpp" ov::snippets::pass::SoftmaxReshapeElimination::SoftmaxReshapeElimination() { MATCHER_SCOPE(SoftmaxReshapeElimination); diff --git a/src/common/snippets/src/shape_inference/shape_infer_instances.cpp b/src/common/snippets/src/shape_inference/shape_infer_instances.cpp index b254adbdc64888..61404d208fd5a7 100644 --- a/src/common/snippets/src/shape_inference/shape_infer_instances.cpp +++ b/src/common/snippets/src/shape_inference/shape_infer_instances.cpp @@ -3,11 +3,11 @@ // #include "snippets/shape_inference/shape_infer_instances.hpp" #include "snippets/snippets_isa.hpp" +#include "snippets/utils.hpp" #include "openvino/op/select.hpp" namespace ov { namespace snippets { using Result = IShapeInferSnippets::Result; -namespace { /* * Merge SRC to DST with broadcasting rules defined by the Autobroadcast specifier */ @@ -87,7 +87,6 @@ bool merge_into(VectorDims& dst, const VectorDims& src) { success &= merge_dim(dst[i], dst[i], src[i]); return success; } -} // namespace Result NumpyBroadcastShapeInfer::infer(const std::vector& input_shapes) { OPENVINO_ASSERT(!input_shapes.empty(), "No input shapes were provided for NumpyBroadcastShapeInfer"); @@ -162,5 +161,76 @@ Result HorizonOpShapeInfer::infer(const std::vector& input_shapes return {{output_shapes}, ShapeInferStatus::success}; } +BrgemmShapeInfer::BrgemmShapeInfer(const std::shared_ptr& n) { + for (const auto& in : n->inputs()) { + const auto& port = lowered::PortDescriptorUtils::get_port_descriptor_ptr(in); + m_io_layouts.push_back(port->get_layout()); + } + const auto& port = lowered::PortDescriptorUtils::get_port_descriptor_ptr(n->output(0)); + m_io_layouts.push_back(port->get_layout()); +} + +Result BrgemmShapeInfer::infer(const std::vector& input_shapes) { + OPENVINO_ASSERT(input_shapes.size() == 2 || input_shapes.size() == 3, "BRGEMM expects 2 or 3 input shapes for shape inference"); + + // Todo: Ideally we should use the layout stored in PortDescriptors. Can we do it? + const auto& arg0_shape = ov::snippets::utils::get_planar_vdims(input_shapes[0].get(), m_io_layouts[0]); + const auto& arg1_shape = ov::snippets::utils::get_planar_vdims(input_shapes[1].get(), m_io_layouts[1]); + + size_t arg0_rank = arg0_shape.size(), arg1_rank = arg1_shape.size(); + + // temporary shapes to calculate output shape + VectorDims arg0_shape_tmp(arg0_shape), arg1_shape_tmp(arg1_shape); + + // one-dimensional tensors unsqueezing is applied to each input independently. + if (arg0_rank == 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}. + arg0_shape_tmp.insert(arg0_shape_tmp.begin(), 1); + arg0_rank = arg0_shape_tmp.size(); + } + if (arg1_rank == 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}. + arg1_shape_tmp.insert(arg1_shape_tmp.end(), 1); + arg1_rank = arg1_shape_tmp.size(); + } + + // add 1 to begin to align shape ranks if needed + if (arg0_rank < arg1_rank) + arg0_shape_tmp.insert(arg0_shape_tmp.begin(), arg1_rank - arg0_rank, 1); + else if (arg0_rank > arg1_rank) + arg1_shape_tmp.insert(arg1_shape_tmp.begin(), arg0_rank - arg1_rank, 1); + + size_t max_rank = arg0_shape_tmp.size(); + VectorDims output_shape(max_rank); + for (size_t i = 0; i < max_rank - 2; ++i) { + if (arg0_shape_tmp[i] == arg1_shape_tmp[i]) { + output_shape[i] = arg0_shape_tmp[i]; + } else { + if (arg0_shape_tmp[i] == 1 || arg0_shape_tmp[i] == DYNAMIC_DIMENSION) + output_shape[i] = arg1_shape_tmp[i]; + else if (arg1_shape_tmp[i] == 1 || arg1_shape_tmp[i] == DYNAMIC_DIMENSION) + output_shape[i] = arg0_shape_tmp[i]; + else + OPENVINO_THROW("Incompatible Brgemm batch dimension"); + } + } + output_shape[output_shape.size() - 2] = arg0_shape_tmp[arg0_shape_tmp.size() - 2]; // M + output_shape[output_shape.size() - 1] = arg1_shape_tmp[arg1_shape_tmp.size() - 1]; // N + + // removing the temporary axes from originally 1D tensors. + if (arg0_shape.size() == 1) { + output_shape.erase(output_shape.begin() + output_shape.size() - 2); + } + if (arg1_shape.size() == 1) { + output_shape.erase(output_shape.begin() + output_shape.size() - 1); + } + output_shape = ov::snippets::utils::get_planar_vdims(output_shape, m_io_layouts.back()); + return {{output_shape}, snippets::ShapeInferStatus::success}; +} + } // namespace snippets } // namespace ov diff --git a/src/common/snippets/src/shape_inference/shape_inference.cpp b/src/common/snippets/src/shape_inference/shape_inference.cpp index bc9534f7b08bce..0b9117d05d0477 100644 --- a/src/common/snippets/src/shape_inference/shape_inference.cpp +++ b/src/common/snippets/src/shape_inference/shape_inference.cpp @@ -55,13 +55,15 @@ const IShapeInferSnippetsFactory::TRegistry IShapeInferSnippetsFactory::registry SHAPE_INFER_PREDEFINED(op::Scalar, SingleElementShapeInfer), SHAPE_INFER_PREDEFINED(op::VectorBuffer, SingleElementShapeInfer), SHAPE_INFER_PREDEFINED(op::LoopEnd, EmptyShapeInfer), + SHAPE_INFER_PREDEFINED(op::Kernel, EmptyShapeInfer), SHAPE_INFER_PREDEFINED(op::Nop, EmptyShapeInfer), SHAPE_INFER_OP_SPECIFIC_EXTERNAL(opset1::Select, SelectShapeInfer), + SHAPE_INFER_OP_SPECIFIC_EXTERNAL(op::Brgemm, BrgemmShapeInfer), // Note that Result has no output PortConnectors, so the shape must be empty SHAPE_INFER_PREDEFINED(ov::op::v0::Result, EmptyShapeInfer), // SHAPE_INFER_OP_SPECIFIC(op::LoadReshape), - SHAPE_INFER_OP_SPECIFIC(op::Brgemm), + SHAPE_INFER_OP_SPECIFIC(op::RankNormalization), SHAPE_INFER_OP_SPECIFIC(op::BroadcastLoad), SHAPE_INFER_OP_SPECIFIC(op::BroadcastMove), }; diff --git a/src/common/snippets/src/utils.cpp b/src/common/snippets/src/utils.cpp index 621c6c9bf67426..242391b908dc03 100644 --- a/src/common/snippets/src/utils.cpp +++ b/src/common/snippets/src/utils.cpp @@ -92,7 +92,8 @@ VectorDims pshape_to_vdims(const PartialShape& pshape) { result.reserve(pshape.size()); for (const auto& d : pshape) result.push_back(d.is_dynamic() ? IShapeInferSnippets::DYNAMIC_DIMENSION : d.get_length()); - return result; + // Note: PartialShape could be empty which designates scalar value. However, Scalars are represented as {1} in Snippets + return result.empty() ? VectorDims {1} : result; } ov::PartialShape vdims_to_pshape(const VectorDims& vdims) { @@ -117,8 +118,10 @@ ov::PartialShape get_planar_pshape(const Output& out) { VectorDims get_planar_vdims(const VectorDims& shape, const std::vector& layout) { VectorDims reordered_shape(shape.size()); - for (size_t i = 0; i < layout.size(); i++) + for (size_t i = 0; i < layout.size(); i++) { + OPENVINO_ASSERT(layout[i] < shape.size(), "get_planar_vdims: layout index is greater than the shape size"); reordered_shape[i] = shape[layout[i]]; + } return reordered_shape; } @@ -130,6 +133,10 @@ VectorDims get_planar_vdims(const snippets::lowered::ExpressionPort& expr_port) return get_planar_vdims(expr_port.get_descriptor_ptr()); } +bool is_dynamic_vdims(const VectorDims& shape) { + return std::any_of(shape.cbegin(), shape.cend(), [](size_t v){ return v == IShapeInferSnippets::DYNAMIC_DIMENSION; }); +} + } // namespace utils } // namespace snippets } // namespace ov diff --git a/src/common/snippets/tests/include/lowered/pass/optimize_domain.hpp b/src/common/snippets/tests/include/lowered/pass/optimize_domain.hpp new file mode 100644 index 00000000000000..55edfd639fd9f3 --- /dev/null +++ b/src/common/snippets/tests/include/lowered/pass/optimize_domain.hpp @@ -0,0 +1,36 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include "snippets/shape_types.hpp" + +namespace ov { +namespace test { +namespace snippets { + +struct OptimizeDomainParams { + OptimizeDomainParams() = default; + OptimizeDomainParams(size_t, size_t, std::vector, ov::snippets::VectorDims, size_t); + size_t min_jit_work_amount = 0; + size_t min_parallel_work_amount = 0; + std::vector input_shapes; + ov::snippets::VectorDims exp_master_shape; // Expected master_shape + size_t exp_loop_depth = 0; // Expected loop depth (aka tile rank) +}; + +class OptimizeDomainTest : public testing::TestWithParam { +public: + using VectorDims = ov::snippets::VectorDims; + static std::string getTestCaseName(testing::TestParamInfo obj); +protected: + void SetUp() override; + std::shared_ptr m_model; + OptimizeDomainParams m_domain_opt_params; +}; + +} // namespace snippets +} // namespace test +} // namespace ov diff --git a/src/common/snippets/tests/include/lowering_utils.hpp b/src/common/snippets/tests/include/lowering_utils.hpp index 7ca5ecc47439f4..f2c872f725b7d6 100644 --- a/src/common/snippets/tests/include/lowering_utils.hpp +++ b/src/common/snippets/tests/include/lowering_utils.hpp @@ -6,6 +6,8 @@ #include #include "snippets/op/subgraph.hpp" #include "snippets_helpers.hpp" +#include "snippets/pass_manager.hpp" +#include "snippets/shape_inference/shape_inference.hpp" namespace ov { namespace test { @@ -23,11 +25,17 @@ class DummyEmitter : public ov::snippets::Emitter { void emit_data() const override {} }; +struct DummyCompiledSnippet : public ov::snippets::CompiledSnippet { + const uint8_t* get_code() const override { return nullptr; } + size_t get_code_size() const override { return 0; } + bool empty() const override { return true; } +}; + class DummyTargetMachine : public ov::snippets::TargetMachine { public: DummyTargetMachine(const std::vector& custom_opset = {}); bool is_supported() const override { return true; } - ov::snippets::code get_snippet() const override { return nullptr; } + ov::snippets::CompiledSnippetPtr get_snippet() override { return std::make_shared(); } size_t get_lanes() const override { return 10; } }; @@ -35,6 +43,7 @@ class DummyGenerator : public ov::snippets::Generator { public: DummyGenerator() : ov::snippets::Generator(std::make_shared()) {} DummyGenerator(const std::shared_ptr& t) : ov::snippets::Generator(t) {} + std::shared_ptr clone() const override { return std::make_shared(target); } protected: opRegType get_specific_op_reg_type(const std::shared_ptr& op) const override { return vec2vec; }; @@ -47,16 +56,19 @@ class LoweringTests : public TransformationTestsF { void SetUp() override; void TearDown() override; -protected: static std::shared_ptr getSubgraph(const std::shared_ptr& f); + using IShapeInferSnippetsFactory = ov::snippets::IShapeInferSnippetsFactory; static std::shared_ptr getLoweredSubgraph(const std::shared_ptr& f, const ov::PartialShape& master_shape, const std::vector& backend_passes = {}, const ov::snippets::lowered::pass::PassPipeline& lowered_pre_common = {}, const ov::snippets::lowered::pass::PassPipeline& lowered_post_common = {}, - const std::shared_ptr& generator = nullptr); + const std::shared_ptr& generator = nullptr, + const std::shared_ptr& factory = std::make_shared()); static std::shared_ptr getTokenizedSubgraph(const std::shared_ptr& f); + +protected: ov::PartialShape master_shape{}; }; diff --git a/src/common/snippets/tests/include/pass/canonicalization.hpp b/src/common/snippets/tests/include/pass/canonicalization.hpp index 88f6ebc0336a80..bcb27d08cb1395 100644 --- a/src/common/snippets/tests/include/pass/canonicalization.hpp +++ b/src/common/snippets/tests/include/pass/canonicalization.hpp @@ -5,36 +5,25 @@ #pragma once #include "lowering_utils.hpp" +#include "snippets/op/subgraph.hpp" #include "snippets_helpers.hpp" +#include "snippets/shape_types.hpp" +#include "snippets/pass/canonicalization.hpp" namespace ov { namespace test { namespace snippets { -using BlockedShape = ov::snippets::op::Subgraph::BlockedShape; -using BlockedShapeVector = ov::snippets::op::Subgraph::BlockedShapeVector; - -// todo: implement tests with 3 inputs and two outputs (aka SnippetsCanonicalizationParams3Inputs) -// Note that the expected output shape isn't necessary equal to one of the output blocked_shapes. -// For example, consider the following graph: (1, 2, 2, 1, 8) + (1, 2, 1, 1, 8) + (1, 2, 1, 5, 8) => (1, 2, 2, 1, 8) + (1, 2, 1, 5, 8). -typedef std::tuple< - std::tuple, // Shape & BlockedShape for input 0 - std::tuple, // Shape & BlockedShape for input 0 - BlockedShape, // BlockedShape output shape passed to canonicalize() - Shape // expected output Shape -> canonicalizationParams; - - -class CanonicalizationTests : public LoweringTests, public testing::WithParamInterface { +class CanonicalizationTests : public TransformationTestsF { public: - static std::string getTestCaseName(testing::TestParamInfo obj); + using VectorDims = ov::snippets::VectorDims; + using Layout = std::vector; + virtual void run(); protected: - void SetUp() override; - std::shared_ptr snippets_model; - Shape expected_output_shape; - BlockedShapeVector input_blocked_shapes; - BlockedShapeVector output_blocked_shapes; + std::vector m_input_shapes; + std::vector m_input_layouts; + void prepare_functions(const std::vector& shapes); }; } // namespace snippets diff --git a/src/common/snippets/tests/src/pass/lowered/loop.cpp b/src/common/snippets/tests/src/lowered/pass/loop.cpp similarity index 100% rename from src/common/snippets/tests/src/pass/lowered/loop.cpp rename to src/common/snippets/tests/src/lowered/pass/loop.cpp diff --git a/src/common/snippets/tests/src/lowered/pass/optimize_domain.cpp b/src/common/snippets/tests/src/lowered/pass/optimize_domain.cpp new file mode 100644 index 00000000000000..025c2406ea33ab --- /dev/null +++ b/src/common/snippets/tests/src/lowered/pass/optimize_domain.cpp @@ -0,0 +1,98 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "common_test_utils/common_utils.hpp" +#include "snippets/lowered/pass/optimize_domain.hpp" +#include "snippets/lowered/pass/pass.hpp" +#include "lowered/pass/optimize_domain.hpp" +#include "subgraph_simple.hpp" +#include "lowering_utils.hpp" + +namespace ov { +namespace test { +namespace snippets { +OptimizeDomainParams::OptimizeDomainParams(size_t min_jit_work_amount, + size_t min_parallel_work_amount, + std::vector input_shapes, + ov::snippets::VectorDims exp_master_shape, + size_t exp_loop_depth) : + min_jit_work_amount(min_jit_work_amount), + min_parallel_work_amount(min_parallel_work_amount), + input_shapes(std::move(input_shapes)), + exp_master_shape(std::move(exp_master_shape)), + exp_loop_depth(exp_loop_depth) { +} + +std::string OptimizeDomainTest::getTestCaseName(testing::TestParamInfo obj) { + OptimizeDomainParams domain_opt_params = obj.param; + std::ostringstream result; + result << "MinJitWork=" << domain_opt_params.min_jit_work_amount << "_"; + result << "MinParWork=" << domain_opt_params.min_parallel_work_amount << "_"; + for (size_t i = 0; i < domain_opt_params.input_shapes.size(); i++) + result << "IS[" << i << "]=" << ov::test::utils::partialShape2str({domain_opt_params.input_shapes[i]}) << "_"; + result << "ExpMS=" << ov::test::utils::vec2str(domain_opt_params.exp_master_shape) << "_"; + result << "ExpLD=" << domain_opt_params.exp_loop_depth << "_"; + return result.str(); +} + +void OptimizeDomainTest::SetUp() { + m_domain_opt_params = this->GetParam(); + m_model = std::make_shared(m_domain_opt_params.input_shapes)->getOriginal(); +} + +TEST_P(OptimizeDomainTest, DomainOptimization) { + auto subgraph = LoweringTests::getTokenizedSubgraph(m_model); + subgraph->set_min_jit_work_amount(m_domain_opt_params.min_jit_work_amount); + subgraph->set_min_parallel_work_amount(m_domain_opt_params.min_parallel_work_amount); + auto linear_ir = *subgraph->convert_body_to_linear_ir(); + size_t loop_depth = 1; + ov::snippets::lowered::pass::OptimizeDomain(loop_depth).run(linear_ir); + const auto& master_shape = linear_ir.get_master_shape(); + EXPECT_EQ(loop_depth, m_domain_opt_params.exp_loop_depth) << "Inconsistent loop depth detected"; + EXPECT_THAT(master_shape, testing::ContainerEq(m_domain_opt_params.exp_master_shape)) << "Inconsistent master_shape detected"; +} + +namespace OptimizeDomainTestsInstantiation { + +std::vector dopt_params = { + // No broadcasting => dimensions collapsed + {256, 4, {{14, 15, 1, 17}, {14, 15, 1, 17}}, {1, 1, 14, 255}, 1}, + {256, 4, {{14, 15, 16, 1}, {14, 15, 16, 1}}, {1, 1, 14, 240}, 1}, + // Same dimensions, but larger num threads => collapsing omitted + {256, 18, {{14, 15, 1, 17}, {14, 15, 1, 17}}, {1, 14, 15, 17}, 1}, + {256, 18, {{14, 15, 16, 1}, {14, 15, 16, 1}}, {1, 14, 15, 16}, 1}, + + // No broadcasting => collapsing and loop_depth increment + {256, 4, {{14, 15, 16, 17}, {14, 15, 16, 17}}, {1, 14, 15, 272}, 2}, + // Same dimensions, but smaller jit work amount => collapsing omitted + {16, 4, {{14, 15, 16, 17}, {14, 15, 16, 17}}, {14, 15, 16, 17}, 2}, + // Same dimensions, but higher parallel work amount => collapsing but no loop_depth increment + {256, 18, {{14, 15, 16, 17}, {14, 15, 16, 17}}, {1, 14, 15, 272}, 1}, + + // Broadcasting breaks dimension collapsing => loop depth incremented + {256, 4, {{14, 15, 16, 1}, {14, 15, 1, 17}}, {14, 15, 16, 17}, 2}, + {256, 4, {{14, 15, 1, 17}, {14, 15, 16, 17}}, {14, 15, 16, 17}, 2}, + + // Collapse even if not enough work to cover min_jit_work_amount + {256, 18, {{4, 5, 6, 7}, {4, 5, 6, 7}}, {1, 4, 5, 42}, 1}, + // Same dims, but higher parallel work amount => do not collapse to load all the threads + {256, 32, {{4, 5, 6, 7}, {4, 5, 6, 7}}, {4, 5, 6, 7}, 1}, + + // 2D and 1D shapes are too small, so no collapsing should be done in such cases + {256, 32, {{4, 5}, {4, 5}}, {4, 5}, 1}, + {256, 32, {{5}, {5}}, {5}, 1}, + + // min_parallel_work_amount = 1 is a special case that would cause all dimensions to collapse (up to min_jit_work_amount of course) + {256, 1, {{4, 1, 6, 7}, {4, 1, 6, 7}}, {1, 1, 1, 168}, 1}, +}; + +INSTANTIATE_TEST_SUITE_P(smoke_Snippets_DomainOptimization, OptimizeDomainTest, + ::testing::ValuesIn(dopt_params), + OptimizeDomainTest::getTestCaseName); + +} // namespace OptimizeDomainTestsInstantiation +} // namespace snippets +} // namespace test +} // namespace ov \ No newline at end of file diff --git a/src/common/snippets/tests/src/lowering_utils.cpp b/src/common/snippets/tests/src/lowering_utils.cpp index 83207244ac031f..5d49d38a6af2e7 100644 --- a/src/common/snippets/tests/src/lowering_utils.cpp +++ b/src/common/snippets/tests/src/lowering_utils.cpp @@ -106,13 +106,13 @@ std::shared_ptr const std::vector& backend_passes, const ov::snippets::lowered::pass::PassPipeline& lowered_pre_common, const ov::snippets::lowered::pass::PassPipeline& lowered_post_common, - const std::shared_ptr& generator) { + const std::shared_ptr& generator, + const std::shared_ptr& factory) { auto subgraph = getTokenizedSubgraph(f); subgraph->set_generator(generator == nullptr ? std::make_shared() : generator); - subgraph->set_master_shape(master_shape); subgraph->set_tile_rank(2); // Note: lowered_pipeline would have no effect on subgraph body, since it's applied on linear IR - subgraph->generate(backend_passes, lowered_pre_common, lowered_post_common); + subgraph->generate({}, {}, {}, backend_passes, lowered_pre_common, lowered_post_common, factory); return subgraph; } diff --git a/src/common/snippets/tests/src/pass/canonicalization.cpp b/src/common/snippets/tests/src/pass/canonicalization.cpp index 79b5b97e0579a7..a9311b67598263 100644 --- a/src/common/snippets/tests/src/pass/canonicalization.cpp +++ b/src/common/snippets/tests/src/pass/canonicalization.cpp @@ -5,102 +5,84 @@ #include #include "pass/canonicalization.hpp" #include "common_test_utils/common_utils.hpp" -#include +#include "snippets/pass/canonicalization.hpp" +#include "snippets/op/rank_normalization.hpp" +#include namespace ov { namespace test { namespace snippets { -using ov::snippets::op::Subgraph; - -class SKIP_CanonicalizationTests : public CanonicalizationTests { -public: - void SetUp() override { - GTEST_SKIP(); - } - void TearDown() override{}; -}; - -std::string CanonicalizationTests::getTestCaseName(testing::TestParamInfo obj) { - std::vector> inputs(2); - Subgraph::BlockedShape output; - Shape expectedOutput; - std::tie(inputs[0], inputs[1], output, expectedOutput) = obj.param; - std::ostringstream result; - for (size_t i = 0; i < inputs.size(); i++) { - const auto& blockedshape = std::get<1>(inputs[i]); - // input shape - result << "IS[" << i << "]=" << ov::test::utils::vec2str(std::get<0>(inputs[i])) << "_"; - // input blocked shape - result << "IBS[" << i << "]=" << ov::test::utils::partialShape2str({std::get<0>(blockedshape)}) << "_"; - // input blocked order - result << "IBO[" << i << "]=" << ov::test::utils::vec2str(std::get<1>(blockedshape)) << "_"; - } - // output blocked shape - result << "OBS[0]=" << ov::test::utils::partialShape2str({std::get<0>(output)}) << "_"; - // output blocked order - result << "OBO[0]=" << ov::test::utils::vec2str(std::get<1>(output)) << "_"; - result << "ExpOS[0]=" << ov::test::utils::vec2str(expectedOutput) << "_"; - return result.str(); +namespace { +void normalizeParameter(const std::shared_ptr& par, size_t num_prepend, size_t num_append) { + auto target_inputs = par->get_output_target_inputs(0); + auto rank_norm = std::make_shared(par, + num_prepend, + num_append); + for (auto& t : target_inputs) + t.replace_source_output(rank_norm); } +} // namespace -void CanonicalizationTests::SetUp() { - TransformationTestsF::SetUp(); - std::vector> inputs(2); - output_blocked_shapes.resize(1); - std::tie(inputs[0], inputs[1], output_blocked_shapes[0], expected_output_shape) = this->GetParam(); +void CanonicalizationTests::prepare_functions(const std::vector& shapes) { + std::vector pshapes; + pshapes.reserve(shapes.size()); + for (const auto& v : shapes ) + pshapes.emplace_back(v); + const auto &f = AddFunction(pshapes); + model = f.getOriginal(); + model_ref = model->clone(); +} - input_blocked_shapes = {std::get<1>(inputs[0]), std::get<1>(inputs[1])}; - snippets_model = std::make_shared(std::vector{std::get<0>(inputs[0]), std::get<0>(inputs[1])}); +void CanonicalizationTests::run() { + ASSERT_TRUE(model); + ASSERT_EQ(m_input_shapes.size(), m_input_layouts.size()); + BlockedShapeVector blocked_input_shapes; + blocked_input_shapes.reserve(m_input_shapes.size()); + for (size_t i = 0; i < m_input_shapes.size(); i++) + blocked_input_shapes.emplace_back(m_input_shapes[i], m_input_layouts[i]); + manager.register_pass(blocked_input_shapes); + disable_rt_info_check(); } -TEST_P(CanonicalizationTests, Add) { - model = snippets_model->getOriginal(); - model_ref = snippets_model->getReference(); - auto subgraph = getTokenizedSubgraph(model); - subgraph->set_generator(std::make_shared()); - auto canonical_output_shape = subgraph->canonicalize(output_blocked_shapes, input_blocked_shapes); - ASSERT_TRUE(canonical_output_shape.is_static()); - ASSERT_DIMS_EQ(canonical_output_shape.get_shape(), expected_output_shape); +TEST_F(CanonicalizationTests, smoke_Snippets_Canonicalization_0) { + m_input_shapes = {{2, 3, 10, 64}, {2, 3, 10, 64}}; + m_input_layouts = {{0, 1, 2, 3}, {0, 1, 2, 3}}; + prepare_functions(m_input_shapes); + run(); } namespace CanonicalizationTestsInstantiation { -using ov::snippets::op::Subgraph; -std::vector input_shapes; -Shape expected_output_shape; -Subgraph::BlockedShapeVector input_blocked_shapes; - -using ov::Shape; -ov::element::Type_t prec = ov::element::f32; -std::tuple blockedInput0{{1, 64, 2, 5}, - {{1, 4, 2, 5, 16}, {0, 1, 2, 3, 1}, prec}}; -Subgraph::BlockedShape output{{1, 4, 2, 5, 16}, {0, 1, 2, 3, 1}, prec}; -Shape canonical_shape{1, 4, 2, 5, 16}; - -std::vector> blockedInput1{{{1, 1, 2, 5}, {{1, 1, 2, 5, 1}, {0, 1, 2, 3, 1}, prec}}, - {{1, 1, 2, 1}, {{1, 1, 2, 1, 1}, {0, 1, 2, 3, 1}, prec}}, - {{1, 64, 1, 1}, {{1, 4, 1, 1, 16}, {0, 1, 2, 3, 1}, prec}}}; +TEST_F(CanonicalizationTests, smoke_Snippets_Canonicalization_1) { + m_input_shapes = {{2, 3, 10, 64}, + {10, 64}}; + m_input_layouts = {{0, 1, 2, 3}, + {0, 1}}; + prepare_functions(m_input_shapes); + normalizeParameter(model_ref->get_parameters()[1], 2, 0); + run(); +} -INSTANTIATE_TEST_SUITE_P(smoke_Snippets_BroadcastBlocked, - SKIP_CanonicalizationTests /* CVS-114607 */, - ::testing::Combine(::testing::Values(blockedInput0), - ::testing::ValuesIn(blockedInput1), - ::testing::Values(output), - ::testing::Values(canonical_shape)), - CanonicalizationTests::getTestCaseName); +TEST_F(CanonicalizationTests, smoke_Snippets_Canonicalization_2) { + m_input_shapes = {{2, 3, 10, 64, 16}, + {1, 10, 64}}; + m_input_layouts = {{0, 1, 2, 3, 1}, + {0, 1, 2}}; + prepare_functions({{2, 48, 10, 64}, + {1, 10, 64}}); + const auto& params = model_ref->get_parameters(); + // Note: We can't create functions with mismatching input shapes, + // so we have to set Parameter shapes after the functions were created + // This reproduces Snippets pipeline well, since blocked shapes are set after the tokenization + params[0]->set_partial_shape(PartialShape(m_input_shapes[0])); + model->get_parameters()[0]->set_partial_shape(PartialShape(m_input_shapes[0])); -std::vector> planarInput1{{{1, 1, 2, 5}, {{1, 2, 5}, {0, 1, 2}, prec}}, - {{1, 1, 2, 5}, {{2, 5}, {0, 1}, prec}}, - {{1, 2, 5}, {{2, 5}, {0, 1}, prec}}, - {{2, 5}, {{2, 5}, {0, 1}, prec}}, - {{5}, {{5}, {0}, prec}}}; + normalizeParameter(params[1], 1, 1); + // need to trigger validate..(...) manually to propagate new blocked shapes, + // this is correct since RankNormalization ops re-enables shape propagation for blocked shapes + model_ref->validate_nodes_and_infer_types(); + run(); +} -INSTANTIATE_TEST_SUITE_P(smoke_Snippets_BroadcastPlanar, - SKIP_CanonicalizationTests /* CVS-114607 */, - ::testing::Combine(::testing::Values(blockedInput0), - ::testing::ValuesIn(planarInput1), - ::testing::Values(output), - ::testing::Values(canonical_shape)), - CanonicalizationTests::getTestCaseName); } // namespace CanonicalizationTestsInstantiation } // namespace snippets } // namespace test diff --git a/src/common/transformations/CMakeLists.txt b/src/common/transformations/CMakeLists.txt index 164daec54c2f18..e7d365ca32492e 100644 --- a/src/common/transformations/CMakeLists.txt +++ b/src/common/transformations/CMakeLists.txt @@ -4,11 +4,11 @@ set(TARGET_NAME "inference_engine_transformations") -file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) -file(GLOB_RECURSE PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp) - set(PUBLIC_HEADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") +file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) +file(GLOB_RECURSE PUBLIC_HEADERS ${PUBLIC_HEADERS_DIR}/*.hpp) + # Create named folders for the sources within the .vcproj # Empty name lists them directly under the .vcproj @@ -27,8 +27,8 @@ ov_build_target_faster(${TARGET_NAME}_obj target_link_libraries(${TARGET_NAME}_obj PRIVATE openvino::reference openvino::itt openvino::builders openvino::core::dev openvino::shape_inference) -target_include_directories(${TARGET_NAME}_obj PRIVATE $ - "${CMAKE_CURRENT_SOURCE_DIR}/src") +target_include_directories(${TARGET_NAME}_obj PRIVATE "${PUBLIC_HEADERS_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}/src") ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}_obj) @@ -43,14 +43,14 @@ endif() add_library(${TARGET_NAME} INTERFACE) target_include_directories(${TARGET_NAME} INTERFACE - $ + $ $>) target_link_libraries(${TARGET_NAME} INTERFACE openvino::runtime) # even the Transformations library is supposed to be Plugin API # we still have some code compiled as transformations, but headers are -# part of ngraph core API +# part of openvino core API # so, we need to mark this library as important for ABI free ov_abi_free_target(${TARGET_NAME}_obj) diff --git a/src/common/transformations/include/transformations/common_optimizations/convert_u4_weights_zero_point_to_scalar.hpp b/src/common/transformations/include/transformations/common_optimizations/convert_u4_weights_zero_point_to_scalar.hpp new file mode 100644 index 00000000000000..0b8d31b404090e --- /dev/null +++ b/src/common/transformations/include/transformations/common_optimizations/convert_u4_weights_zero_point_to_scalar.hpp @@ -0,0 +1,26 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/pass/graph_rewrite.hpp" +#include "transformations_visibility.hpp" + +namespace ov { +namespace pass { + +class TRANSFORMATIONS_API ConvertU4WeightsZeroPointToScalar; + +} // namespace pass +} // namespace ov + +/** + * @ingroup ie_transformation_common_api + * @brief Converts U4 weights zero point to scalar if all values are equal + */ +class ov::pass::ConvertU4WeightsZeroPointToScalar : public ov::pass::MatcherPass { +public: + OPENVINO_RTTI("ConvertU4WeightsZeroPointToScalar", "0"); + ConvertU4WeightsZeroPointToScalar(); +}; diff --git a/src/common/transformations/include/transformations/op_conversions/gather_normalize_negative_indices.hpp b/src/common/transformations/include/transformations/op_conversions/gather_normalize_negative_indices.hpp deleted file mode 100644 index bb912f5a980f88..00000000000000 --- a/src/common/transformations/include/transformations/op_conversions/gather_normalize_negative_indices.hpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/pass/graph_rewrite.hpp" -#include "transformations_visibility.hpp" - -namespace ov { -namespace pass { - -class TRANSFORMATIONS_API GatherNegativeConstIndicesNormalize; - -} // namespace pass -} // namespace ov - -/** - * @ingroup ie_transformation_common_api - * @brief GatherNegativeConstIndicesNormalize checks if indices value is negative scalar and - * normalizes it using ShapeOf->Add->Cast subgraph. - * We need to remove this transformation after adding support of negative indices in - * future version of Gather operation. - */ -class ov::pass::GatherNegativeConstIndicesNormalize : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("GatherNegativeConstIndicesNormalize", "0"); - GatherNegativeConstIndicesNormalize(); -}; diff --git a/src/common/transformations/include/transformations/transpose_sinking/ts_cumsum.hpp b/src/common/transformations/include/transformations/transpose_sinking/ts_cumsum.hpp new file mode 100644 index 00000000000000..d8c70e65ad2899 --- /dev/null +++ b/src/common/transformations/include/transformations/transpose_sinking/ts_cumsum.hpp @@ -0,0 +1,41 @@ +// 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/transpose_sinking/ts_base.hpp" +#include "transformations_visibility.hpp" + +namespace ov { +namespace pass { +namespace transpose_sinking { + +class TRANSFORMATIONS_API TSCumSumForward; +class TRANSFORMATIONS_API TSCumSumBackward; + +} // namespace transpose_sinking +} // namespace pass +} // namespace ov + +/** + * @ingroup ie_transformation_common_api + * @brief TSCumSumForward transformation sinks Transpose through CumSum in the forward direction. + */ +class ov::pass::transpose_sinking::TSCumSumForward : public ov::pass::transpose_sinking::TSForwardBase { +public: + OPENVINO_RTTI("ov::pass::TSBinaryForward", "0"); + TSCumSumForward(); +}; + +/** + * @ingroup ie_transformation_common_api + * @brief TSCumSumBackward transformation sinks Transpose through CumSum in the backward direction. + */ +class ov::pass::transpose_sinking::TSCumSumBackward : public ov::pass::MatcherPass { +public: + OPENVINO_RTTI("ov::pass::TSBinaryBackward", "0"); + TSCumSumBackward(); +}; diff --git a/src/common/transformations/include/transformations/transpose_sinking/ts_tile.hpp b/src/common/transformations/include/transformations/transpose_sinking/ts_tile.hpp new file mode 100644 index 00000000000000..cd125ca05639dd --- /dev/null +++ b/src/common/transformations/include/transformations/transpose_sinking/ts_tile.hpp @@ -0,0 +1,41 @@ +// 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/transpose_sinking/ts_base.hpp" +#include "transformations_visibility.hpp" + +namespace ov { +namespace pass { +namespace transpose_sinking { + +class TRANSFORMATIONS_API TSTileForward; +class TRANSFORMATIONS_API TSTileBackward; + +} // namespace transpose_sinking +} // namespace pass +} // namespace ov + +/** + * @ingroup ie_transformation_common_api + * @brief TSTileForward transformation sinks Transpose through Tile in the forward direction. + */ +class ov::pass::transpose_sinking::TSTileForward : public ov::pass::transpose_sinking::TSForwardBase { +public: + OPENVINO_RTTI("ov::pass::TSBinaryForward", "0"); + TSTileForward(); +}; + +/** + * @ingroup ie_transformation_common_api + * @brief TSTileBackward transformation sinks Transpose through Tile in the backward direction. + */ +class ov::pass::transpose_sinking::TSTileBackward : public ov::pass::MatcherPass { +public: + OPENVINO_RTTI("ov::pass::TSBinaryBackward", "0"); + TSTileBackward(); +}; diff --git a/src/common/transformations/src/transformations/common_optimizations/common_optimizations.cpp b/src/common/transformations/src/transformations/common_optimizations/common_optimizations.cpp index 8ad09f95dede3e..4d4cebe5c62222 100644 --- a/src/common/transformations/src/transformations/common_optimizations/common_optimizations.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/common_optimizations.cpp @@ -97,7 +97,6 @@ #include "transformations/op_conversions/detection_output_upgrade.hpp" #include "transformations/op_conversions/einsum_decomposition.hpp" #include "transformations/op_conversions/eye_decomposition.hpp" -#include "transformations/op_conversions/gather_normalize_negative_indices.hpp" #include "transformations/op_conversions/gelu7_downgrade.hpp" #include "transformations/op_conversions/group_normalization_decomposition.hpp" #include "transformations/op_conversions/hsigmoid_decomposition.hpp" @@ -170,7 +169,6 @@ bool ov::pass::CommonOptimizations::run_on_model(const std::shared_ptradd_matcher(); ADD_MATCHER(decomp, SoftSignDecomposition) - ADD_MATCHER(decomp, GatherNegativeConstIndicesNormalize) ADD_MATCHER(decomp, DropoutWithRandomUniformReplacer) ADD_MATCHER(decomp, TransposeReshapeEliminationForMatmul) ADD_MATCHER(decomp, EyeDecomposition) diff --git a/src/common/transformations/src/transformations/common_optimizations/convert_u4_weights_zero_point_to_scalar.cpp b/src/common/transformations/src/transformations/common_optimizations/convert_u4_weights_zero_point_to_scalar.cpp new file mode 100644 index 00000000000000..6313db127ac406 --- /dev/null +++ b/src/common/transformations/src/transformations/common_optimizations/convert_u4_weights_zero_point_to_scalar.cpp @@ -0,0 +1,80 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "transformations/common_optimizations/convert_u4_weights_zero_point_to_scalar.hpp" + +#include "itt.hpp" +#include "openvino/core/rt_info.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/subtract.hpp" +#include "openvino/pass/pattern/op/or.hpp" +#include "openvino/pass/pattern/op/wrap_type.hpp" +#include "openvino/reference/autobroadcast_binop.hpp" +#include "transformations/utils/utils.hpp" + +ov::pass::ConvertU4WeightsZeroPointToScalar::ConvertU4WeightsZeroPointToScalar() { + MATCHER_SCOPE(ConvertU4WeightsZeroPointToScalar); + auto weights_m = pattern::wrap_type(pattern::type_matches(ov::element::u4)); + auto convert_m = pattern::wrap_type({weights_m}, pattern::consumers_count(1)); + + auto float_zp_predicate = [](ov::Output output) -> bool { + return pattern::type_matches_any({ov::element::f32, ov::element::f16})(output) && + pattern::consumers_count(1)(output); + }; + auto float_zero_point_m = pattern::wrap_type(float_zp_predicate); + + auto u4_zp_predicate = [](ov::Output output) -> bool { + return pattern::type_matches(ov::element::u4)(output) && pattern::consumers_count(1)(output); + }; + auto u4_zero_point_m = pattern::wrap_type(u4_zp_predicate); + auto zero_point_convert_m = pattern::wrap_type({u4_zero_point_m}, float_zp_predicate); + + auto zero_point_m = std::make_shared(OutputVector{float_zero_point_m, zero_point_convert_m}); + auto subtract_m = pattern::wrap_type({convert_m, zero_point_m}); + + ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) { + auto& pattern_map = m.get_pattern_value_map(); + auto weights = ov::as_type_ptr(pattern_map.at(weights_m).get_node_shared_ptr()); + std::shared_ptr zero_point; + if (pattern_map.count(float_zero_point_m)) { + const auto& float_zp = pattern_map.at(float_zero_point_m); + zero_point = ov::as_type_ptr(float_zp.get_node_shared_ptr()); + } else { + const auto& u4_zp = pattern_map.at(u4_zero_point_m); + zero_point = ov::as_type_ptr(u4_zp.get_node_shared_ptr()); + } + if (!weights || !zero_point) + return false; + // Due to the matcher specific and Subtract branches similarity, + // weights and zero_point might be mixed up with each other + if (ov::shape_size(weights->get_shape()) < ov::shape_size(zero_point->get_shape())) + std::swap(zero_point, weights); + + auto zero_point_shape = zero_point->get_shape(); + if (ov::shape_size(zero_point_shape) == 1) + return false; + + const auto& weights_shape = weights->get_shape(); + const size_t weights_rank = weights_shape.size(); + const size_t zero_point_rank = zero_point_shape.size(); + // Zero point constant can be converted into scalar only if this does not affect Subtract output shape + if (weights_rank < zero_point_rank) + return false; + + zero_point_shape.insert(zero_point_shape.begin(), weights_rank - zero_point_rank, 1); + for (size_t i = 0; i < weights_rank; ++i) { + if (zero_point_shape[i] > weights_shape[i]) + return false; + } + + float zp_value; + if (!ov::op::util::get_single_value(zero_point, zp_value)) + return false; + const auto new_zp = ov::op::v0::Constant::create(zero_point->get_element_type(), {}, {zp_value}); + return ov::replace_node_update_name(zero_point, new_zp); + }; + + auto m = std::make_shared(subtract_m, matcher_name); + register_matcher(m, callback); +} diff --git a/src/common/transformations/src/transformations/common_optimizations/gru_cell_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/gru_cell_fusion.cpp index e5eae04c640553..5b3aaec614ff17 100644 --- a/src/common/transformations/src/transformations/common_optimizations/gru_cell_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/gru_cell_fusion.cpp @@ -148,6 +148,15 @@ ov::pass::GRUCellFusion::GRUCellFusion() { Bh = rg.make(WRh.get_element_type(), Shape{1, static_cast(hidden_size)}, 0); } + // perform additional check for applicability of the transformation + // without this check, process_weights can fail + if (WR.get_partial_shape()[1] != (hidden_size + input_size)) { + return false; + } + if (WRh.get_partial_shape()[1] != (hidden_size + input_size)) { + return false; + } + Output Wzrh, Rzrh, Bzrh; if (cnt_of_consumers_of_zero_out == 1 && cnt_of_consumers_of_first_out == 2) { tie(Wzrh, Rzrh) = process_weights(rg, false, WR, WRh, input_size, hidden_size, axis_0, axis_1); diff --git a/src/common/transformations/src/transformations/common_optimizations/moc_transformations.cpp b/src/common/transformations/src/transformations/common_optimizations/moc_transformations.cpp index 068e1f27a291e9..86746f176cad7f 100644 --- a/src/common/transformations/src/transformations/common_optimizations/moc_transformations.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/moc_transformations.cpp @@ -21,6 +21,7 @@ #include "transformations/common_optimizations/conv_to_binary_conv.hpp" #include "transformations/common_optimizations/convert_nms_gather_path_to_unsigned.hpp" #include "transformations/common_optimizations/convert_quantize_dequantize.hpp" +#include "transformations/common_optimizations/convert_u4_weights_zero_point_to_scalar.hpp" #include "transformations/common_optimizations/convolution_to_group_convolution_fusion.hpp" #include "transformations/common_optimizations/depth_to_space_fusion.hpp" #include "transformations/common_optimizations/dilated_convolution_converter.hpp" @@ -212,6 +213,7 @@ bool ov::pass::MOCTransformations::run_on_model(const std::shared_ptr ADD_MATCHER(common_fusions, ShuffleChannelsFusion, !m_use_shapes) ADD_MATCHER(common_fusions, NonZeroHorizontalFusion) ADD_MATCHER(common_fusions, AdaptivePoolToReduce) + ADD_MATCHER(common_fusions, ConvertU4WeightsZeroPointToScalar) common_fusions->set_name("ov::pass::CommonFusions"); REGISTER_PASS(manager, BinarizeWeights) diff --git a/src/common/transformations/src/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.cpp b/src/common/transformations/src/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.cpp index f9738929931f21..3304ee3718ab57 100644 --- a/src/common/transformations/src/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.cpp @@ -116,7 +116,7 @@ bool ov::pass::RemoveMultiSubGraphOpDanglingParamsResults::run_on_model(const st } // Remove inputs bool pass_required = false; - std::set> required_inputs; + std::set required_inputs_indices; auto op_inputs = multi_subgraph_op->input_values(); std::vector> to_remove_descriptors_indexes; to_remove_descriptors_indexes.resize(subgraphs_size); @@ -133,7 +133,7 @@ bool ov::pass::RemoveMultiSubGraphOpDanglingParamsResults::run_on_model(const st } else { // collecting required inputs is needed to detect cases where the input // is not needed in a one body, but the other one uses it (for example If case) - required_inputs.insert(op_inputs[body_in_descriptors[i]->m_input_index]); // only unique + required_inputs_indices.insert(body_in_descriptors[i]->m_input_index); } } } @@ -148,7 +148,9 @@ bool ov::pass::RemoveMultiSubGraphOpDanglingParamsResults::run_on_model(const st } }; auto update_op_inputs_desc = [&subgraphs_size](const std::shared_ptr& op, + std::set& required_inputs_indices, uint64_t removed_loop_idx) { + std::set new_required_inputs_indices; for (size_t body_idx = 0; body_idx < subgraphs_size; ++body_idx) { auto& descriptors = op->get_input_descriptions(static_cast(body_idx)); for (auto& desc : descriptors) { @@ -157,6 +159,14 @@ bool ov::pass::RemoveMultiSubGraphOpDanglingParamsResults::run_on_model(const st } } } + for (auto input_index : required_inputs_indices) { + if (input_index > removed_loop_idx) { + new_required_inputs_indices.insert(input_index - 1); + } else { + new_required_inputs_indices.insert(input_index); + } + } + required_inputs_indices = new_required_inputs_indices; }; // Remove dangling body params and input and update input descriptors for (size_t body_idx = 0; body_idx < subgraphs_size; ++body_idx) { @@ -174,13 +184,17 @@ bool ov::pass::RemoveMultiSubGraphOpDanglingParamsResults::run_on_model(const st update_body_param_desc(body_in_descriptors, body_in_descriptors[desc_idx]->m_body_parameter_index); // remove dangling input of MultiSubGraphOp which was not removed earlier - auto& current_input = op_inputs[body_in_descriptors[desc_idx]->m_input_index]; - if (std::count(std::begin(required_inputs), std::end(required_inputs), current_input) == 0 && + auto current_input_idx = body_in_descriptors[desc_idx]->m_input_index; + auto& current_input = op_inputs[current_input_idx]; + // the same input tensor can go to different input ports + if (std::count(std::begin(required_inputs_indices), + std::end(required_inputs_indices), + current_input_idx) == 0 && std::count(std::begin(op_inputs), std::end(op_inputs), current_input) > 0) { - op_inputs.erase(std::next(op_inputs.begin(), body_in_descriptors[desc_idx]->m_input_index)); + op_inputs.erase(std::next(op_inputs.begin(), current_input_idx)); // Move all input indexes (in all bodies) which are after these indicated by // to_remove_descriptors_indexes and are not used in any body - update_op_inputs_desc(multi_subgraph_op, body_in_descriptors[desc_idx]->m_input_index); + update_op_inputs_desc(multi_subgraph_op, required_inputs_indices, current_input_idx); } } else { updated_body_in_descriptors.emplace_back(body_in_descriptors[desc_idx]); diff --git a/src/common/transformations/src/transformations/convert_precision.cpp b/src/common/transformations/src/transformations/convert_precision.cpp index c5e2b13381c9f6..a1e9dd7a820e16 100644 --- a/src/common/transformations/src/transformations/convert_precision.cpp +++ b/src/common/transformations/src/transformations/convert_precision.cpp @@ -1172,6 +1172,7 @@ bool fuse_type_to_constant(const std::shared_ptr& node, new_const->validate_and_infer_types(); new_const->set_friendly_name(constant->get_friendly_name()); + ov::copy_runtime_info(constant, new_const); return true; } return false; diff --git a/src/common/transformations/src/transformations/op_conversions/convert_gather_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_gather_downgrade.cpp index ae0aeb4d99ae8e..4c525f7d3ddbee 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_gather_downgrade.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_gather_downgrade.cpp @@ -48,8 +48,59 @@ pass::ConvertGather8ToGather7::ConvertGather8ToGather7() { if (!gather_v8_node) return false; + auto data = gather_v8_node->input_value(0); + auto indices_constant = + std::dynamic_pointer_cast(gather_v8_node->input_value(1).get_node_shared_ptr()); + auto axis_constant = + std::dynamic_pointer_cast(gather_v8_node->input_value(2).get_node_shared_ptr()); + if (!indices_constant || !axis_constant) + return false; + + auto axis = axis_constant->cast_vector(); + if (axis.size() != 1) { + return false; + } + auto axis_value = axis[0]; + // normalize `axis` value if it is negative + if (axis_value < 0) { + if (!data.get_partial_shape().rank().is_static()) { + return false; + } + axis_value = axis_value + data.get_partial_shape().rank().get_length(); + } + if (data.get_partial_shape().rank().get_length() < axis_value) { + return false; + } + // check `axis` dimension of data tensor is static + if (!data.get_partial_shape()[axis_value].is_static()) { + return false; + } + auto axis_dim = data.get_partial_shape()[axis_value].get_length(); + + auto indices = indices_constant->cast_vector(); + // Check all the indices are not out of bound and check whether normalization is possible for negative values + bool do_indices_normalization = false; + for (size_t i = 0; i < indices.size(); i++) { + if (indices[i] < -axis_dim || indices[i] >= axis_dim) { + return false; + } + if (indices[i] < 0) { + do_indices_normalization = true; + indices[i] = indices[i] + axis_dim; + } + } + + std::shared_ptr new_indices_constant; + if (do_indices_normalization) { + new_indices_constant = std::make_shared(indices_constant->get_element_type(), + indices_constant->get_shape(), + indices); + } else { + new_indices_constant = indices_constant; + } + auto gather_v7_node = make_shared(gather_v8_node->input_value(0), - gather_v8_node->input_value(1), + new_indices_constant, gather_v8_node->input_value(2), gather_v8_node->get_batch_dims()); diff --git a/src/common/transformations/src/transformations/op_conversions/gather_normalize_negative_indices.cpp b/src/common/transformations/src/transformations/op_conversions/gather_normalize_negative_indices.cpp deleted file mode 100644 index 47ff221d82fa86..00000000000000 --- a/src/common/transformations/src/transformations/op_conversions/gather_normalize_negative_indices.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/op_conversions/gather_normalize_negative_indices.hpp" - -#include - -#include "itt.hpp" -#include "openvino/core/rt_info.hpp" -#include "openvino/core/validation_util.hpp" -#include "openvino/op/add.hpp" -#include "openvino/op/constant.hpp" -#include "openvino/op/gather.hpp" -#include "openvino/op/shape_of.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" - -ov::pass::GatherNegativeConstIndicesNormalize::GatherNegativeConstIndicesNormalize() { - MATCHER_SCOPE(GatherNegativeConstIndicesNormalize); - auto data_input = pattern::any_input(pattern::has_static_rank()); - auto axis_input = ov::pass::pattern::wrap_type(); - auto indices_input = ov::pass::pattern::wrap_type(); - auto gather_node = ov::pass::pattern::wrap_type({data_input, indices_input, axis_input}); - - matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) { - auto& pattern_to_output = m.get_pattern_value_map(); - auto gather = pattern_to_output.at(gather_node).get_node_shared_ptr(); - auto data = pattern_to_output.at(data_input); - auto axis_constant = - std::dynamic_pointer_cast(pattern_to_output.at(axis_input).get_node_shared_ptr()); - auto indices_constant = - std::dynamic_pointer_cast(pattern_to_output.at(indices_input).get_node_shared_ptr()); - - if (!gather || !axis_constant || !indices_constant) { - return false; - } - - auto indices = indices_constant->cast_vector(); - if (indices.size() != 1 || indices[0] >= 0) { - return false; - } - - auto axis = axis_constant->cast_vector(); - if (axis.size() != 1) { - return false; - } - - auto axis_value = axis[0]; - - // normalize `axis` value if it is negative - if (axis_value < 0) { - axis_value = axis_value + data.get_partial_shape().rank().get_length(); - } - - if (data.get_partial_shape().rank().get_length() < axis_value) { - return false; - } - - // check `axis` dimension of data tensor is static - if (!data.get_partial_shape()[axis_value].is_static()) { - return false; - } - - auto input_type = indices_constant->get_element_type(); - auto shape_of = std::make_shared(data, input_type); - auto input_gather = - std::make_shared(shape_of, - ov::op::v0::Constant::create(input_type, Shape{}, {axis_value}), - ov::op::v0::Constant::create(input_type, Shape{}, {0})); - - std::shared_ptr add = std::make_shared(input_gather, indices_constant); - OPENVINO_SUPPRESS_DEPRECATED_START - if (auto folded_const = ov::get_constant_from_source(add)) { - OPENVINO_SUPPRESS_DEPRECATED_END - add = folded_const; - } - gather->input(1).replace_source_output(add); - - ov::copy_runtime_info(gather, {shape_of, input_gather, add}); - - return true; - }; - - auto m = std::make_shared(gather_node, matcher_name); - register_matcher(m, callback); -} diff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_cumsum.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_cumsum.cpp new file mode 100644 index 00000000000000..623724f8ccf99f --- /dev/null +++ b/src/common/transformations/src/transformations/transpose_sinking/ts_cumsum.cpp @@ -0,0 +1,92 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "transformations/transpose_sinking/ts_cumsum.hpp" + +#include "itt.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/cum_sum.hpp" +#include "openvino/op/fake_quantize.hpp" +#include "openvino/op/transpose.hpp" +#include "openvino/op/util/op_types.hpp" +#include "openvino/pass/pattern/op/wrap_type.hpp" +#include "transformations/rt_info/transpose_sinking_attr.hpp" +#include "transformations/transpose_sinking/ts_utils.hpp" + +using namespace ov; +using namespace ov::pass::pattern; +using namespace ov::pass::transpose_sinking; +using namespace ov::pass::transpose_sinking::utils; + +#undef CUMSUM_AXIS_INPUT_IDX +#define CUMSUM_AXIS_INPUT_IDX 1 + +TSCumSumForward::TSCumSumForward() { + MATCHER_SCOPE(TSCumSumForward); + + create_pattern(true, {0}); + + auto sinking_transformation = [=](const std::shared_ptr& main_node, + const TransposeInputsInfo& transpose_info) -> bool { + if (transformation_callback(main_node)) { + return false; + } + + bool res = utils::sink_forward::UpdateInputTransposes(main_node, transpose_info, /* input_indexes= */ {0}); + if (!res) + return res; + + const auto transpose_axis_order = transpose_info.transpose_const->get_axis_vector_val(); + auto axis = std::make_shared(element::i32, Shape{}, 0); + const auto& new_axes = ChangeAxes(main_node->input_value(CUMSUM_AXIS_INPUT_IDX), transpose_axis_order, axis); + main_node->input(CUMSUM_AXIS_INPUT_IDX).replace_source_output(new_axes); + + default_outputs_update(main_node, transpose_info); + return true; + }; + transpose_sinking(matcher_name, sinking_transformation); +} + +TSCumSumBackward::TSCumSumBackward() { + MATCHER_SCOPE(TSCumSumBackward); + auto main_node_label = wrap_type([](const Output& output) -> bool { + return has_static_rank()(output) && CheckTransposeConsumers(output); + }); + + auto transpose_const_label = wrap_type(); + + auto transpose_label = wrap_type({main_node_label, transpose_const_label}, + [](const Output& output) -> bool { + return has_static_rank()(output); + }); + matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { + const auto& pattern_to_output = m.get_pattern_value_map(); + auto transpose_const = + as_type_ptr(pattern_to_output.at(transpose_const_label).get_node_shared_ptr()); + auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr(); + auto main_node = pattern_to_output.at(main_node_label).get_node_shared_ptr(); + + if (transformation_callback(main_node)) { + return false; + } + + for (auto& new_node : sink_backward::InsertTransposeBeforeNode(main_node, + transpose_const, + /* input_indexes= */ {0})) { + register_new_node(new_node); + } + + RemoveTransposeConsumers(main_node); + const auto transpose_axis_order = transpose_const->get_axis_vector_val(); + const auto reversed_transpose_order = ReverseTransposeOrder(transpose_axis_order); + auto axis = std::make_shared(element::i32, Shape{}, 0); + auto new_axes = ChangeAxes(main_node->input_value(CUMSUM_AXIS_INPUT_IDX), reversed_transpose_order, axis); + main_node->input(CUMSUM_AXIS_INPUT_IDX).replace_source_output(new_axes); + + main_node->validate_and_infer_types(); + return true; + }; + auto m = std::make_shared(transpose_label, matcher_name); + register_matcher(m, matcher_pass_callback); +} diff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_general.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_general.cpp index 4b4a0835a9da70..ceae4cd45e6397 100644 --- a/src/common/transformations/src/transformations/transpose_sinking/ts_general.cpp +++ b/src/common/transformations/src/transformations/transpose_sinking/ts_general.cpp @@ -13,6 +13,7 @@ #include "transformations/common_optimizations/enable_shapeof_constant_folding.hpp" #include "transformations/transpose_sinking/ts_binary.hpp" #include "transformations/transpose_sinking/ts_concat.hpp" +#include "transformations/transpose_sinking/ts_cumsum.hpp" #include "transformations/transpose_sinking/ts_data_movement.hpp" #include "transformations/transpose_sinking/ts_fuse.hpp" #include "transformations/transpose_sinking/ts_gather.hpp" @@ -23,6 +24,7 @@ #include "transformations/transpose_sinking/ts_slice.hpp" #include "transformations/transpose_sinking/ts_split.hpp" #include "transformations/transpose_sinking/ts_squeeze.hpp" +#include "transformations/transpose_sinking/ts_tile.hpp" #include "transformations/transpose_sinking/ts_unary.hpp" #include "transformations/transpose_sinking/ts_unsqueeze.hpp" #include "transformations/utils/utils.hpp" @@ -31,35 +33,40 @@ using namespace ov::pass::transpose_sinking; TSGeneralForward::TSGeneralForward() { MATCHER_SCOPE(TSGeneralForward); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); + ADD_MATCHER(this, TSUnaryForward); + ADD_MATCHER(this, TSBinaryForward); + ADD_MATCHER(this, TSConcatForward); + ADD_MATCHER(this, TSSplitForward); + ADD_MATCHER(this, TSDataMovementForward); + ADD_MATCHER(this, TSReductionForward); + ADD_MATCHER(this, TSSqueezeForward); + ADD_MATCHER(this, TSUnsqueezeForward); + ADD_MATCHER(this, TSInterpolateForward); + ADD_MATCHER(this, TSSliceForward); + ADD_MATCHER(this, TSGatherForward); + ADD_MATCHER(this, TSShapeOfForward); + ADD_MATCHER(this, TSCumSumForward); + ADD_MATCHER(this, TSTileForward); + ADD_MATCHER(this, TSFuse); } TSGeneralBackward::TSGeneralBackward() { MATCHER_SCOPE(TSGeneralBackward); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); + ADD_MATCHER(this, TSUnaryBackward); + ADD_MATCHER(this, TSUnaryBackward); + ADD_MATCHER(this, TSBinaryBackward); + ADD_MATCHER(this, TSConcatBackward); + ADD_MATCHER(this, TSSplitBackward); + ADD_MATCHER(this, TSDataMovementBackward); + ADD_MATCHER(this, TSReductionBackward); + ADD_MATCHER(this, TSSqueezeBackward); + ADD_MATCHER(this, TSUnsqueezeBackward); + ADD_MATCHER(this, TSInterpolateBackward); + ADD_MATCHER(this, TSSliceBackward); + ADD_MATCHER(this, TSGatherBackward); + ADD_MATCHER(this, TSCumSumBackward); + ADD_MATCHER(this, TSTileBackward); + ADD_MATCHER(this, TSFuse); } bool TSGeneral::run_on_model(const std::shared_ptr& f) { diff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_tile.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_tile.cpp new file mode 100644 index 00000000000000..dda10b0a6cb7b7 --- /dev/null +++ b/src/common/transformations/src/transformations/transpose_sinking/ts_tile.cpp @@ -0,0 +1,93 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "transformations/transpose_sinking/ts_tile.hpp" + +#include "itt.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/fake_quantize.hpp" +#include "openvino/op/tile.hpp" +#include "openvino/op/transpose.hpp" +#include "openvino/op/util/op_types.hpp" +#include "openvino/pass/pattern/op/wrap_type.hpp" +#include "transformations/rt_info/transpose_sinking_attr.hpp" +#include "transformations/transpose_sinking/ts_utils.hpp" + +using namespace ov; +using namespace ov::pass::pattern; +using namespace ov::pass::transpose_sinking; +using namespace ov::pass::transpose_sinking::utils; + +#undef TILE_REPEATS_INPUT_IDX +#define TILE_REPEATS_INPUT_IDX 1 + +TSTileForward::TSTileForward() { + MATCHER_SCOPE(TSTileForward); + + create_pattern(true, {0}); + + auto sinking_transformation = [=](const std::shared_ptr& main_node, + const TransposeInputsInfo& transpose_info) -> bool { + if (transformation_callback(main_node)) { + return false; + } + + bool res = utils::sink_forward::UpdateInputTransposes(main_node, transpose_info, /* input_indexes= */ {0}); + if (!res) + return res; + + const auto transpose_axis_order = transpose_info.transpose_const->get_axis_vector_val(); + auto repeats = std::make_shared(element::i32, Shape{}, 0); + const auto& new_repeats = + ChangeValuesOrder(main_node->input_value(TILE_REPEATS_INPUT_IDX), transpose_axis_order, repeats); + main_node->input(TILE_REPEATS_INPUT_IDX).replace_source_output(new_repeats); + + default_outputs_update(main_node, transpose_info); + return true; + }; + transpose_sinking(matcher_name, sinking_transformation); +} + +TSTileBackward::TSTileBackward() { + MATCHER_SCOPE(TSTileBackward); + auto main_node_label = wrap_type([](const Output& output) -> bool { + return has_static_rank()(output) && CheckTransposeConsumers(output); + }); + + auto transpose_const_label = wrap_type(); + + auto transpose_label = wrap_type({main_node_label, transpose_const_label}, + [](const Output& output) -> bool { + return has_static_rank()(output); + }); + matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { + const auto& pattern_to_output = m.get_pattern_value_map(); + auto transpose_const = + as_type_ptr(pattern_to_output.at(transpose_const_label).get_node_shared_ptr()); + auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr(); + auto main_node = pattern_to_output.at(main_node_label).get_node_shared_ptr(); + + if (transformation_callback(main_node)) { + return false; + } + + for (auto& new_node : sink_backward::InsertTransposeBeforeNode(main_node, + transpose_const, + /* input_indexes= */ {0})) { + register_new_node(new_node); + } + + RemoveTransposeConsumers(main_node); + const auto transpose_axis_order = transpose_const->get_axis_vector_val(); + auto repeats = std::make_shared(element::i32, Shape{}, 0); + auto new_repeats = + ChangeValuesOrder(main_node->input_value(TILE_REPEATS_INPUT_IDX), transpose_axis_order, repeats); + main_node->input(TILE_REPEATS_INPUT_IDX).replace_source_output(new_repeats); + + main_node->validate_and_infer_types(); + return true; + }; + auto m = std::make_shared(transpose_label, matcher_name); + register_matcher(m, matcher_pass_callback); +} diff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_unary.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_unary.cpp index d4b4869c3eb959..5814634e7408f5 100644 --- a/src/common/transformations/src/transformations/transpose_sinking/ts_unary.cpp +++ b/src/common/transformations/src/transformations/transpose_sinking/ts_unary.cpp @@ -16,6 +16,7 @@ #include "openvino/op/logical_not.hpp" #include "openvino/op/softplus.hpp" #include "openvino/op/transpose.hpp" +#include "openvino/pass/pattern/op/or.hpp" #include "openvino/pass/pattern/op/wrap_type.hpp" #include "transformations/rt_info/transpose_sinking_attr.hpp" #include "transformations/transpose_sinking/ts_utils.hpp" @@ -45,8 +46,21 @@ TSUnaryForward::TSUnaryForward() { ov::op::v0::Convert, ov::op::v10::IsInf, ov::op::v10::IsNaN, - ov::op::v10::IsFinite>(true); - transpose_sinking(matcher_name); + ov::op::v10::IsFinite, + ov::op::v0::Selu, + ov::op::v4::Swish, + ov::op::v0::HardSigmoid, + ov::op::v5::LogSoftmax, + ov::op::v1::ConvertLike>(true); + auto ts_unary_sinking_function = [this](const std::shared_ptr& main_node, + const utils::TransposeInputsInfo& transpose_info) -> bool { + bool res = utils::sink_forward::UpdateInputTransposes(main_node, transpose_info, {0}); + if (!res) + return res; + default_outputs_update(main_node, transpose_info); + return true; + }; + transpose_sinking(matcher_name, ts_unary_sinking_function); } TSUnaryBackward::TSUnaryBackward() { @@ -56,15 +70,25 @@ TSUnaryBackward::TSUnaryBackward() { return CheckTransposeConsumers(output); }; - auto unary_label = wrap_type({any_input()}, unary_restrictions); + auto unary_with_1_input_label = wrap_type({any_input()}, unary_restrictions); + + auto unary_with_2_inputs_label = + wrap_type({any_input(), any_input()}, unary_restrictions); + auto unary_with_3_inputs_label = + wrap_type({any_input(), any_input(), any_input()}, + unary_restrictions); + + auto unary_label = std::make_shared( + ov::OutputVector{unary_with_1_input_label, unary_with_2_inputs_label, unary_with_3_inputs_label}); auto transpose_const_label = wrap_type(); @@ -75,12 +99,12 @@ TSUnaryBackward::TSUnaryBackward() { auto transpose_const = as_type_ptr(pattern_to_output.at(transpose_const_label).get_node_shared_ptr()); auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr(); - auto unary = pattern_to_output.at(unary_label).get_node_shared_ptr(); + auto unary = transpose->get_input_node_shared_ptr(0); if (transformation_callback(unary)) { return false; } - for (auto& new_node : sink_backward::InsertTransposeBeforeNode(unary, transpose_const)) { + for (auto& new_node : sink_backward::InsertTransposeBeforeNode(unary, transpose_const, {0})) { register_new_node(new_node); } unary->validate_and_infer_types(); diff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_utils.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_utils.cpp index 177267581eb9be..38073bc8848e17 100644 --- a/src/common/transformations/src/transformations/transpose_sinking/ts_utils.cpp +++ b/src/common/transformations/src/transformations/transpose_sinking/ts_utils.cpp @@ -59,6 +59,7 @@ Output ChangeAxes(const Output& indices, copy_runtime_info(indices.get_node_shared_ptr(), gather); return gather; } + Output ChangeAxes(const Output& indices, const AxisVector& transpose_axis_order, const std::shared_ptr& axis) { diff --git a/src/common/transformations/src/transformations/utils/utils.cpp b/src/common/transformations/src/transformations/utils/utils.cpp index 62b1765e7ba275..b7cde395a66eb5 100644 --- a/src/common/transformations/src/transformations/utils/utils.cpp +++ b/src/common/transformations/src/transformations/utils/utils.cpp @@ -31,6 +31,8 @@ bool get_single_value(const std::shared_ptr& const_node, float return util::normalize_single_value(const_node->get_vector(), value, check_value_range); case element::Type_t::f64: return util::normalize_single_value(const_node->get_vector(), value, check_value_range); + case element::Type_t::i4: + return util::normalize_single_value(const_node->cast_vector(), value, check_value_range); case element::Type_t::i8: return util::normalize_single_value(const_node->get_vector(), value, check_value_range); case element::Type_t::i16: @@ -39,6 +41,8 @@ bool get_single_value(const std::shared_ptr& const_node, float return util::normalize_single_value(const_node->get_vector(), value, check_value_range); case element::Type_t::i64: return util::normalize_single_value(const_node->get_vector(), value, check_value_range); + case element::Type_t::u4: + return util::normalize_single_value(const_node->cast_vector(), value, check_value_range); case element::Type_t::u8: return util::normalize_single_value(const_node->get_vector(), value, check_value_range); case element::Type_t::u16: diff --git a/src/common/transformations/tests/CMakeLists.txt b/src/common/transformations/tests/CMakeLists.txt index 84a4fb6e900edf..7091f5162fea8d 100644 --- a/src/common/transformations/tests/CMakeLists.txt +++ b/src/common/transformations/tests/CMakeLists.txt @@ -15,7 +15,7 @@ ov_add_test_target( LINK_LIBRARIES gmock func_test_utils - offline_transformations + openvino::offline_transformations sharedTestClasses ov_lpt_models ADD_CLANG_FORMAT diff --git a/src/common/transformations/tests/common_optimizations/convert_u4_weights_zero_point_to_scalar.cpp b/src/common/transformations/tests/common_optimizations/convert_u4_weights_zero_point_to_scalar.cpp new file mode 100644 index 00000000000000..8fc896065e9001 --- /dev/null +++ b/src/common/transformations/tests/common_optimizations/convert_u4_weights_zero_point_to_scalar.cpp @@ -0,0 +1,208 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "transformations/common_optimizations/convert_u4_weights_zero_point_to_scalar.hpp" + +#include + +#include "common_test_utils/ov_test_utils.hpp" +#include "openvino/core/model.hpp" +#include "openvino/op/convert.hpp" +#include "openvino/op/multiply.hpp" +#include "openvino/op/shape_of.hpp" +#include "openvino/op/subtract.hpp" +#include "openvino/pass/manager.hpp" + +using namespace testing; +using namespace ov; + +TEST_F(TransformationTestsF, ConvertU4WeightsFloatZeroPointToScalar) { + auto weights_precision = ov::element::u4; + auto decompression_precision = ov::element::f32; + ov::Shape weights_shape{32, 128, 64}; + ov::Shape decompression_shape{32, 1, 64}; + { + auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4}); + auto convert = std::make_shared(weights, decompression_precision); + auto zero_point = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {8.1f}); + auto subtract = std::make_shared(convert, zero_point); + auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f}); + auto multiply = std::make_shared(subtract, scale); + model = std::make_shared(NodeVector{multiply}, ParameterVector{}); + manager.register_pass(); + } + { + ov::Shape scalar_shape{}; + auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4}); + auto convert = std::make_shared(weights, decompression_precision); + auto zero_point = ov::op::v0::Constant::create(decompression_precision, scalar_shape, {8.1f}); + auto subtract = std::make_shared(convert, zero_point); + auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f}); + auto multiply = std::make_shared(subtract, scale); + model_ref = std::make_shared(NodeVector{multiply}, ParameterVector{}); + } + comparator.enable(FunctionsComparator::ACCURACY); + comparator.enable(FunctionsComparator::CONST_VALUES); +} + +TEST_F(TransformationTestsF, ConvertU4WeightsU4ZeroPointToScalar) { + auto weights_precision = ov::element::u4; + auto decompression_precision = ov::element::f32; + ov::Shape weights_shape{32, 128, 64}; + ov::Shape decompression_shape{32, 1, 64}; + { + auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4}); + auto convert = std::make_shared(weights, decompression_precision); + auto zero_point = ov::op::v0::Constant::create(weights_precision, decompression_shape, {8}); + auto zero_point_convert = std::make_shared(zero_point, decompression_precision); + auto subtract = std::make_shared(convert, zero_point_convert); + auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f}); + auto multiply = std::make_shared(subtract, scale); + model = std::make_shared(NodeVector{multiply}, ParameterVector{}); + manager.register_pass(); + } + { + ov::Shape scalar_shape{}; + auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4}); + auto convert = std::make_shared(weights, decompression_precision); + auto zero_point = ov::op::v0::Constant::create(weights_precision, scalar_shape, {8}); + auto zero_point_convert = std::make_shared(zero_point, decompression_precision); + auto subtract = std::make_shared(convert, zero_point_convert); + auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f}); + auto multiply = std::make_shared(subtract, scale); + model_ref = std::make_shared(NodeVector{multiply}, ParameterVector{}); + } + comparator.enable(FunctionsComparator::ACCURACY); + comparator.enable(FunctionsComparator::CONST_VALUES); +} + +TEST_F(TransformationTestsF, ConvertU4WeightsFloatZeroPointToScalarWeightsWithBiggerRank) { + auto weights_precision = ov::element::u4; + auto decompression_precision = ov::element::f32; + ov::Shape weights_shape{32, 128, 64}; + ov::Shape decompression_shape{64}; + { + auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4}); + auto convert = std::make_shared(weights, decompression_precision); + auto zero_point = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {8}); + auto subtract = std::make_shared(convert, zero_point); + auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f}); + auto multiply = std::make_shared(subtract, scale); + model = std::make_shared(NodeVector{multiply}, ParameterVector{}); + manager.register_pass(); + } + { + ov::Shape scalar_shape{}; + auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4}); + auto convert = std::make_shared(weights, decompression_precision); + auto zero_point = ov::op::v0::Constant::create(decompression_precision, scalar_shape, {8}); + auto subtract = std::make_shared(convert, zero_point); + auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f}); + auto multiply = std::make_shared(subtract, scale); + model_ref = std::make_shared(NodeVector{multiply}, ParameterVector{}); + } + comparator.enable(FunctionsComparator::ACCURACY); + comparator.enable(FunctionsComparator::CONST_VALUES); +} + +TEST_F(TransformationTestsF, FuseU4WeightsAndZeroPointNotScalarLikeZP) { + auto weights_precision = ov::element::u8; + auto decompression_precision = ov::element::f32; + ov::Shape weights_shape{32, 128, 64}; + ov::Shape decompression_shape{32, 1, 64}; + auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4}); + auto convert = std::make_shared(weights, decompression_precision); + std::vector zero_point_values(ov::shape_size(decompression_shape), 8); + zero_point_values.back() = 6; + auto zero_point = ov::op::v0::Constant::create(weights_precision, decompression_shape, zero_point_values); + auto zero_point_convert = std::make_shared(zero_point, decompression_precision); + auto subtract = std::make_shared(convert, zero_point_convert); + auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f}); + auto multiply = std::make_shared(subtract, scale); + model = std::make_shared(NodeVector{multiply}, ParameterVector{}); + manager.register_pass(); +} + +TEST_F(TransformationTestsF, FuseU4WeightsAndZeroPointNotU4Weights) { + auto weights_precision = ov::element::u8; + auto decompression_precision = ov::element::f32; + ov::Shape weights_shape{32, 128, 64}; + ov::Shape decompression_shape{32, 1, 64}; + auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4}); + auto convert = std::make_shared(weights, decompression_precision); + auto zero_point = ov::op::v0::Constant::create(weights_precision, decompression_shape, {8}); + auto zero_point_convert = std::make_shared(zero_point, decompression_precision); + auto subtract = std::make_shared(convert, zero_point_convert); + auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f}); + auto multiply = std::make_shared(subtract, scale); + model = std::make_shared(NodeVector{multiply}, ParameterVector{}); + manager.register_pass(); +} + +TEST_F(TransformationTestsF, ConvertU4WeightsFloatZeroPointToScalarAdditionalZPConsumer) { + auto weights_precision = ov::element::u4; + auto decompression_precision = ov::element::f32; + ov::Shape weights_shape{32, 128, 64}; + ov::Shape decompression_shape{32, 1, 64}; + auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4}); + auto convert = std::make_shared(weights, decompression_precision); + auto zero_point = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {8}); + auto zero_point_consumer = std::make_shared(zero_point); + auto subtract = std::make_shared(convert, zero_point); + auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f}); + auto multiply = std::make_shared(subtract, scale); + model = std::make_shared(NodeVector{multiply, zero_point_consumer}, ParameterVector{}); + manager.register_pass(); +} + +TEST_F(TransformationTestsF, ConvertU4WeightsU4ZeroPointToScalarAdditionalZPConsumer) { + auto weights_precision = ov::element::u4; + auto decompression_precision = ov::element::f32; + ov::Shape weights_shape{32, 128, 64}; + ov::Shape decompression_shape{32, 1, 64}; + auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4}); + auto convert = std::make_shared(weights, decompression_precision); + auto zero_point = ov::op::v0::Constant::create(weights_precision, decompression_shape, {8}); + auto zero_point_consumer = std::make_shared(zero_point); + auto zero_point_convert = std::make_shared(zero_point, decompression_precision); + auto subtract = std::make_shared(convert, zero_point_convert); + auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f}); + auto multiply = std::make_shared(subtract, scale); + model = std::make_shared(NodeVector{multiply, zero_point_consumer}, ParameterVector{}); + manager.register_pass(); +} + +TEST_F(TransformationTestsF, ConvertU4WeightsU4ZeroPointToScalarAdditionalZPConvertConsumer) { + auto weights_precision = ov::element::u4; + auto decompression_precision = ov::element::f32; + ov::Shape weights_shape{32, 128, 64}; + ov::Shape decompression_shape{32, 1, 64}; + auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4}); + auto convert = std::make_shared(weights, decompression_precision); + auto zero_point = ov::op::v0::Constant::create(weights_precision, decompression_shape, {8}); + auto zero_point_convert = std::make_shared(zero_point, decompression_precision); + auto zero_point_convert_consumer = std::make_shared(zero_point_convert); + auto subtract = std::make_shared(convert, zero_point_convert); + auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f}); + auto multiply = std::make_shared(subtract, scale); + model = std::make_shared(NodeVector{multiply, zero_point_convert_consumer}, ParameterVector{}); + manager.register_pass(); +} + +TEST_F(TransformationTestsF, ConvertU4WeightsU4ZeroPointToScalarZPWithBiggerRank) { + auto weights_precision = ov::element::u4; + auto decompression_precision = ov::element::f32; + ov::Shape weights_shape{32, 128, 64}; + ov::Shape decompression_shape{1, 32, 1, 64}; + auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4}); + auto convert = std::make_shared(weights, decompression_precision); + auto zero_point = ov::op::v0::Constant::create(weights_precision, decompression_shape, {8}); + auto zero_point_convert = std::make_shared(zero_point, decompression_precision); + auto zero_point_convert_consumer = std::make_shared(zero_point_convert); + auto subtract = std::make_shared(convert, zero_point_convert); + auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f}); + auto multiply = std::make_shared(subtract, scale); + model = std::make_shared(NodeVector{multiply, zero_point_convert_consumer}, ParameterVector{}); + manager.register_pass(); +} diff --git a/src/common/transformations/tests/common_optimizations/fq_mul_fusion_test.cpp b/src/common/transformations/tests/common_optimizations/fq_mul_fusion_test.cpp index 61f43c937be16e..7dcf6a9c44b3c3 100644 --- a/src/common/transformations/tests/common_optimizations/fq_mul_fusion_test.cpp +++ b/src/common/transformations/tests/common_optimizations/fq_mul_fusion_test.cpp @@ -13,7 +13,6 @@ #include "common_test_utils/ov_test_utils.hpp" #include "common_test_utils/test_common.hpp" #include "functional_test_utils/plugin_cache.hpp" -#include "ie_core.hpp" #include "openvino/core/model.hpp" #include "openvino/opsets/opset4.hpp" #include "openvino/pass/manager.hpp" diff --git a/src/common/transformations/tests/common_optimizations/fq_reshape_fusion.cpp b/src/common/transformations/tests/common_optimizations/fq_reshape_fusion.cpp index 8e92a5e3f7797f..8127ad129ef34b 100644 --- a/src/common/transformations/tests/common_optimizations/fq_reshape_fusion.cpp +++ b/src/common/transformations/tests/common_optimizations/fq_reshape_fusion.cpp @@ -10,7 +10,6 @@ #include #include -#include "cnn_network_ngraph_impl.hpp" #include "common_test_utils/ov_test_utils.hpp" #include "openvino/core/model.hpp" #include "openvino/opsets/opset4.hpp" @@ -19,7 +18,6 @@ using namespace ov; using namespace testing; -using namespace InferenceEngine; namespace { @@ -32,8 +30,8 @@ struct FQReshapeFusionTestCase { bool is_negative; }; -class nGraphFQReshapeFusionTests : public ov::test::TestsCommon, - public testing::WithParamInterface> { +class FQReshapeFusionTests : public ov::test::TestsCommon, + public testing::WithParamInterface> { public: std::shared_ptr f, ref_f; @@ -115,7 +113,7 @@ class nGraphFQReshapeFusionTests : public ov::test::TestsCommon, } }; -TEST_P(nGraphFQReshapeFusionTests, ReshapeMatMul) { +TEST_P(FQReshapeFusionTests, ReshapeMatMul) { auto unh = std::make_shared(); pass::Manager manager; manager.register_pass(unh); @@ -134,7 +132,7 @@ TEST_P(nGraphFQReshapeFusionTests, ReshapeMatMul) { INSTANTIATE_TEST_SUITE_P( NGraph, - nGraphFQReshapeFusionTests, + FQReshapeFusionTests, testing::Values( // positive FQReshapeFusionTestCase{{1, 2, 1, 3}, diff --git a/src/common/transformations/tests/common_optimizations/mish_fusion_test.cpp b/src/common/transformations/tests/common_optimizations/mish_fusion_test.cpp index 61d236a6355628..4fa1af8088d6b2 100644 --- a/src/common/transformations/tests/common_optimizations/mish_fusion_test.cpp +++ b/src/common/transformations/tests/common_optimizations/mish_fusion_test.cpp @@ -19,7 +19,7 @@ using namespace ov; using namespace testing; -// LPT to nGraph migration: temporary disabling unexpected not reproduced fails on CI: +// LPT to openvino migration: temporary disabling unexpected not reproduced fails on CI: // https://openvino-ci.intel.com/job/private-ci/job/ie/job/build-linux-ubuntu18_i386/478/ TEST_F(TransformationTestsF, MishFusing) { { diff --git a/src/common/transformations/tests/op_conversions/convert_gather_downgrade_test.cpp b/src/common/transformations/tests/op_conversions/convert_gather_downgrade_test.cpp index 9f8447b9c77302..b38ff9239c5228 100644 --- a/src/common/transformations/tests/op_conversions/convert_gather_downgrade_test.cpp +++ b/src/common/transformations/tests/op_conversions/convert_gather_downgrade_test.cpp @@ -55,7 +55,7 @@ TEST_F(TransformationTestsF, ConvertGather7toGather1_nonzero_batch_dims) { } } -TEST_F(TransformationTestsF, ConvertGather8toGather7) { +TEST_F(TransformationTestsF, ConvertGather8toGather7_param_indices) { { auto data = std::make_shared(element::f32, Shape{2, 3}); auto indices = std::make_shared(element::i32, Shape{2, 2}); @@ -68,15 +68,98 @@ TEST_F(TransformationTestsF, ConvertGather8toGather7) { manager.register_pass(); } +} +TEST_F(TransformationTestsF, ConvertGather8toGather7_const_indices) { { auto data = std::make_shared(element::f32, Shape{2, 3}); - auto indices = std::make_shared(element::i32, Shape{2, 2}); + auto indices = opset8::Constant::create(element::i32, Shape{2, 2}, {0, 1, 2, 0}); auto axis = opset1::Constant::create(element::i32, Shape{1}, {1}); int64_t batch_dims = 1; + auto gather_v8 = std::make_shared(data, indices, axis, batch_dims); + + model = std::make_shared(NodeVector{gather_v8}, ParameterVector{data}); + + manager.register_pass(); + } + + { + auto data = std::make_shared(element::f32, Shape{2, 3}); + auto indices = opset8::Constant::create(element::i32, Shape{2, 2}, {0, 1, 2, 0}); + auto axis = opset1::Constant::create(element::i32, Shape{1}, {1}); + int64_t batch_dims = 1; + + auto gather_v7 = std::make_shared(data, indices, axis, batch_dims); + + model_ref = std::make_shared(NodeVector{gather_v7}, ParameterVector{data}); + } +} + +TEST_F(TransformationTestsF, ConvertGather8toGather7_negative_indices) { + { + auto data = std::make_shared(element::f32, Shape{2, 3}); + auto indices = opset8::Constant::create(element::i32, Shape{2, 2}, {2, 1, 0, -1}); + auto axis = opset1::Constant::create(element::i32, Shape{1}, {1}); + int64_t batch_dims = 1; + + auto gather_v8 = std::make_shared(data, indices, axis, batch_dims); + + model = std::make_shared(NodeVector{gather_v8}, ParameterVector{data}); + + manager.register_pass(); + comparator.enable(FunctionsComparator::CONST_VALUES); + } + + { + auto data = std::make_shared(element::f32, Shape{2, 3}); + auto indices = opset8::Constant::create(element::i32, Shape{2, 2}, {2, 1, 0, 2}); + auto axis = opset1::Constant::create(element::i32, Shape{1}, {1}); + int64_t batch_dims = 1; + + auto gather_v7 = std::make_shared(data, indices, axis, batch_dims); + + model_ref = std::make_shared(NodeVector{gather_v7}, ParameterVector{data}); + } +} + +TEST_F(TransformationTestsF, ConvertGather8toGather7_out_of_bound_indices) { + { + auto data = std::make_shared(element::f32, Shape{2, 3}); + auto indices = opset8::Constant::create(element::i32, Shape{2, 2}, {0, 1, 2, 3}); + auto axis = opset1::Constant::create(element::i32, Shape{1}, {1}); + int64_t batch_dims = 1; + + auto gather_v8 = std::make_shared(data, indices, axis, batch_dims); + + model = std::make_shared(NodeVector{gather_v8}, ParameterVector{data}); + + manager.register_pass(); + } +} + +TEST_F(TransformationTestsF, ConvertGather8toGather7_negative_axis) { + { + auto data = std::make_shared(element::f32, Shape{2, 3}); + auto indices = opset8::Constant::create(element::i32, Shape{2, 2}, {0, 1, 2, 0}); + auto axis = opset1::Constant::create(element::i32, Shape{1}, {-1}); + int64_t batch_dims = 1; + + auto gather_v8 = std::make_shared(data, indices, axis, batch_dims); + + model = std::make_shared(NodeVector{gather_v8}, ParameterVector{data}); + + manager.register_pass(); + } + + { + auto data = std::make_shared(element::f32, Shape{2, 3}); + auto indices = opset8::Constant::create(element::i32, Shape{2, 2}, {0, 1, 2, 0}); + auto axis = opset1::Constant::create(element::i32, Shape{1}, {-1}); + int64_t batch_dims = 1; + auto gather_v7 = std::make_shared(data, indices, axis, batch_dims); - model_ref = std::make_shared(NodeVector{gather_v7}, ParameterVector{data, indices}); + model_ref = std::make_shared(NodeVector{gather_v7}, ParameterVector{data}); } } diff --git a/src/common/transformations/tests/op_conversions/gather_normalize_negative_indices_test.cpp b/src/common/transformations/tests/op_conversions/gather_normalize_negative_indices_test.cpp deleted file mode 100644 index 8f71da2a3361c7..00000000000000 --- a/src/common/transformations/tests/op_conversions/gather_normalize_negative_indices_test.cpp +++ /dev/null @@ -1,252 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/op_conversions/gather_normalize_negative_indices.hpp" - -#include - -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/core/model.hpp" -#include "openvino/core/validation_util.hpp" -#include "openvino/opsets/opset7.hpp" -#include "openvino/pass/manager.hpp" -#include "transformations/init_node_info.hpp" -using namespace ov; -using namespace testing; - -TEST_F(TransformationTestsF, GatherNegativeIndicesNormalize) { - { - auto data = std::make_shared(element::f32, Shape{1, 15, 128}); - auto indices = opset7::Constant::create(element::i32, Shape{}, {-1}); - auto axis = opset7::Constant::create(element::i32, Shape{}, {1}); - - auto gather = std::make_shared(data, indices, axis, 0); - - model = std::make_shared(NodeVector{gather}, ParameterVector{data}); - - manager.register_pass(); - } - - { - auto indices_type = element::i32; - - auto data = std::make_shared(element::f32, Shape{1, 15, 128}); - auto indices = opset7::Constant::create(indices_type, Shape{}, {-1}); - auto axis = opset7::Constant::create(element::i32, Shape{}, {1}); - - auto shape_of = std::make_shared(data, indices_type); - auto input_gather = std::make_shared(shape_of, - opset7::Constant::create(indices_type, Shape{}, {1}), - opset7::Constant::create(indices_type, Shape{}, {0})); - auto add = std::make_shared(input_gather, indices); - OPENVINO_SUPPRESS_DEPRECATED_START - auto const_add = get_constant_from_source(add); - OPENVINO_SUPPRESS_DEPRECATED_END - if (const_add == nullptr) - OPENVINO_THROW("indices should've been constant folded"); - auto gather = std::make_shared(data, const_add, axis); - - model_ref = std::make_shared(NodeVector{gather}, ParameterVector{data}); - } -} - -TEST_F(TransformationTestsF, GatherNegativeIndicesNormalize_neg_axis) { - { - auto data = std::make_shared(element::f32, Shape{1, 15, 128}); - auto indices = opset7::Constant::create(element::i32, Shape{}, {-1}); - auto axis = opset7::Constant::create(element::i32, Shape{}, {-2}); - - auto gather = std::make_shared(data, indices, axis, 0); - - model = std::make_shared(NodeVector{gather}, ParameterVector{data}); - - manager.register_pass(); - } - - { - auto indices_type = element::i32; - - auto data = std::make_shared(element::f32, Shape{1, 15, 128}); - auto indices = opset7::Constant::create(indices_type, Shape{}, {-1}); - auto axis = opset7::Constant::create(element::i32, Shape{}, {-2}); - - auto shape_of = std::make_shared(data, indices_type); - auto input_gather = std::make_shared(shape_of, - opset7::Constant::create(indices_type, Shape{}, {1}), - opset7::Constant::create(indices_type, Shape{}, {0})); - auto add = std::make_shared(input_gather, indices); - OPENVINO_SUPPRESS_DEPRECATED_START - auto const_add = get_constant_from_source(add); - OPENVINO_SUPPRESS_DEPRECATED_END - if (const_add == nullptr) - OPENVINO_THROW("indices should've been constant folded"); - auto gather = std::make_shared(data, const_add, axis); - - model_ref = std::make_shared(NodeVector{gather}, ParameterVector{data}); - } -} - -TEST_F(TransformationTestsF, GatherNegativeIndicesNormalize_dif_input_types) { - { - auto data = std::make_shared(element::f32, Shape{1, 15, 128}); - auto indices = opset7::Constant::create(element::i32, Shape{}, {-1}); - auto axis = opset7::Constant::create(element::i64, Shape{}, {1}); - - auto gather = std::make_shared(data, indices, axis, 0); - - model = std::make_shared(NodeVector{gather}, ParameterVector{data}); - - manager.register_pass(); - } - - { - auto indices_type = element::i32; - - auto data = std::make_shared(element::f32, Shape{1, 15, 128}); - auto indices = opset7::Constant::create(indices_type, Shape{}, {-1}); - auto axis = opset7::Constant::create(element::i64, Shape{}, {1}); - - auto shape_of = std::make_shared(data, indices_type); - auto input_gather = std::make_shared(shape_of, - opset7::Constant::create(indices_type, Shape{}, {1}), - opset7::Constant::create(indices_type, Shape{}, {0})); - auto add = std::make_shared(input_gather, indices); - OPENVINO_SUPPRESS_DEPRECATED_START - auto const_add = get_constant_from_source(add); - OPENVINO_SUPPRESS_DEPRECATED_END - if (const_add == nullptr) - OPENVINO_THROW("indices should've been constant folded"); - auto gather = std::make_shared(data, const_add, axis); - - model_ref = std::make_shared(NodeVector{gather}, ParameterVector{data}); - } -} - -TEST_F(TransformationTestsF, GatherNegativeIndicesNormalize_static_axis_dim) { - { - auto data = std::make_shared(element::f32, PartialShape{DYN, 15, DYN}); - auto indices = opset7::Constant::create(element::i32, Shape{}, {-1}); - auto axis = opset7::Constant::create(element::i32, Shape{}, {1}); - - auto gather = std::make_shared(data, indices, axis, 0); - - model = std::make_shared(NodeVector{gather}, ParameterVector{data}); - - manager.register_pass(); - } - - { - auto indices_type = element::i32; - - auto data = std::make_shared(element::f32, PartialShape{DYN, 15, DYN}); - auto indices = opset7::Constant::create(indices_type, Shape{}, {2}); - auto axis = opset7::Constant::create(element::i32, Shape{}, {1}); - - auto gather = std::make_shared(data, indices, axis); - model_ref = std::make_shared(NodeVector{gather}, ParameterVector{data}); - } -} - -TEST_F(TransformationTestsF, GatherNegativeIndicesNormalize_static_axis_dim_neg_axis) { - { - auto data = std::make_shared(element::f32, PartialShape{DYN, 15, DYN}); - auto indices = opset7::Constant::create(element::i32, Shape{}, {-1}); - auto axis = opset7::Constant::create(element::i32, Shape{}, {-2}); - - auto gather = std::make_shared(data, indices, axis, 0); - - model = std::make_shared(NodeVector{gather}, ParameterVector{data}); - - manager.register_pass(); - } - - { - auto indices_type = element::i32; - - auto data = std::make_shared(element::f32, PartialShape{DYN, 15, DYN}); - auto indices = opset7::Constant::create(indices_type, Shape{}, {2}); - auto axis = opset7::Constant::create(element::i32, Shape{}, {-2}); - - auto gather = std::make_shared(data, indices, axis); - - model_ref = std::make_shared(NodeVector{gather}, ParameterVector{data}); - } -} - -TEST_F(TransformationTestsF, GatherNegativeIndicesNormalize_non_static_axis_dim) { - { - auto data = std::make_shared(element::f32, PartialShape{DYN, DYN, DYN}); - auto indices = opset7::Constant::create(element::i32, Shape{}, {-1}); - auto axis = opset7::Constant::create(element::i32, Shape{}, {1}); - - auto gather = std::make_shared(data, indices, axis, 0); - - model = std::make_shared(NodeVector{gather}, ParameterVector{data}); - - manager.register_pass(); - } - - { - auto indices_type = element::i32; - - auto data = std::make_shared(element::f32, PartialShape{DYN, DYN, DYN}); - auto indices = opset7::Constant::create(indices_type, Shape{}, {-1}); - auto axis = opset7::Constant::create(element::i32, Shape{}, {1}); - - auto gather = std::make_shared(data, indices, axis); - - model_ref = std::make_shared(NodeVector{gather}, ParameterVector{data}); - } -} - -TEST_F(TransformationTestsF, GatherNegativeIndicesNormalize_positive_ind) { - { - auto data = std::make_shared(element::f32, Shape{2, 3}); - auto indices = opset7::Constant::create(element::i32, Shape{}, {1}); - auto axis = opset7::Constant::create(element::i32, Shape{}, {0}); - - auto gather = std::make_shared(data, indices, axis, 0); - - model = std::make_shared(NodeVector{gather}, ParameterVector{data}); - - manager.register_pass(); - } - - { - auto data = std::make_shared(element::f32, Shape{2, 3}); - auto indices = opset7::Constant::create(element::i32, Shape{}, {1}); - auto axis = opset7::Constant::create(element::i32, Shape{}, {0}); - - auto gather = std::make_shared(data, indices, axis); - - model_ref = std::make_shared(NodeVector{gather}, ParameterVector{data}); - } -} - -TEST_F(TransformationTestsF, GatherNegativeIndicesNormalize_non_static_rank) { - { - auto data = std::make_shared(element::f32, PartialShape::dynamic(Rank::dynamic())); - auto indices = opset7::Constant::create(element::i32, Shape{}, {-1}); - auto axis = opset7::Constant::create(element::i32, Shape{}, {0}); - - auto gather = std::make_shared(data, indices, axis, 0); - - model = std::make_shared(NodeVector{gather}, ParameterVector{data}); - - manager.register_pass(); - } - - { - auto data = std::make_shared(element::f32, PartialShape::dynamic()); - auto indices = opset7::Constant::create(element::i32, Shape{}, {-1}); - auto axis = opset7::Constant::create(element::i32, Shape{}, {0}); - - auto gather = std::make_shared(data, indices, axis); - - model_ref = std::make_shared(NodeVector{gather}, ParameterVector{data}); - } -} diff --git a/src/common/transformations/tests/smart_reshape/sr_mimicking_sbs.cpp b/src/common/transformations/tests/smart_reshape/sr_mimicking_sbs.cpp index 5b11259cbaf998..40f954312b7f76 100644 --- a/src/common/transformations/tests/smart_reshape/sr_mimicking_sbs.cpp +++ b/src/common/transformations/tests/smart_reshape/sr_mimicking_sbs.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include #include "common_test_utils/ov_test_utils.hpp" @@ -20,15 +19,9 @@ TEST(SmartReshapeTests, MimickingSBS) { f = std::make_shared(NodeVector{reshape}, ParameterVector{input}); } - InferenceEngine::CNNNetwork network(f); - auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.setBatchSize(2)); - check_unique_names(f, unh); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({12, 4})); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({2, 2, 3, 4})); + EXPECT_ANY_THROW(set_batch(f, 2)); } TEST(SmartReshapeTests, MimickingSBS_1) { @@ -40,15 +33,9 @@ TEST(SmartReshapeTests, MimickingSBS_1) { f = std::make_shared(NodeVector{reshape}, ParameterVector{input}); } - InferenceEngine::CNNNetwork network(f); - auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.setBatchSize(2)); - check_unique_names(f, unh); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({2, 24})); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({2, 2, 3, 4})); + EXPECT_ANY_THROW(set_batch(f, 2)); } TEST(SmartReshapeTests, MimickingSBS_2) { @@ -60,13 +47,7 @@ TEST(SmartReshapeTests, MimickingSBS_2) { f = std::make_shared(NodeVector{reshape}, ParameterVector{input}); } - InferenceEngine::CNNNetwork network(f); - auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.setBatchSize(1)); - check_unique_names(f, unh); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({6, 4})); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({1, 2, 3, 4})); + EXPECT_ANY_THROW(set_batch(f, 1)); } diff --git a/src/common/transformations/tests/smart_reshape/sr_proposal_scales.cpp b/src/common/transformations/tests/smart_reshape/sr_proposal_scales.cpp index 5e8088a9f2371d..06408dc2807d36 100644 --- a/src/common/transformations/tests/smart_reshape/sr_proposal_scales.cpp +++ b/src/common/transformations/tests/smart_reshape/sr_proposal_scales.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include #include "common_test_utils/ov_test_utils.hpp" @@ -39,12 +38,9 @@ TEST(SmartReshapeTests, Proposal1Scales) { f = std::make_shared(NodeVector{proposal}, ParameterVector{input_0, input_1, input_2}); } - InferenceEngine::CNNNetwork network(f); auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.setBatchSize(2)); - check_unique_names(f, unh); - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({600, 5})); + EXPECT_ANY_THROW(set_batch(f, 2)); } TEST(SmartReshapeTests, Proposal1Scales_WithConvert) { @@ -75,12 +71,9 @@ TEST(SmartReshapeTests, Proposal1Scales_WithConvert) { f = std::make_shared(NodeVector{proposal}, ParameterVector{input_0, input_1, input_2}); } - InferenceEngine::CNNNetwork network(f); auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.setBatchSize(2)); - check_unique_names(f, unh); - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({600, 5})); + EXPECT_ANY_THROW(set_batch(f, 2)); } TEST(SmartReshapeTests, Proposal4Scales) { @@ -110,14 +103,9 @@ TEST(SmartReshapeTests, Proposal4Scales) { f = std::make_shared(NodeVector{proposal}, ParameterVector{input_0, input_1, input_2}); } - InferenceEngine::CNNNetwork network(f); - auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.setBatchSize(2)); - check_unique_names(f, unh); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({600, 5})); + EXPECT_ANY_THROW(set_batch(f, 2)); } TEST(SmartReshapeTests, Proposal4Scales_WithConvert) { @@ -148,12 +136,7 @@ TEST(SmartReshapeTests, Proposal4Scales_WithConvert) { f = std::make_shared(NodeVector{proposal}, ParameterVector{input_0, input_1, input_2}); } - InferenceEngine::CNNNetwork network(f); - auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.setBatchSize(2)); - check_unique_names(f, unh); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({600, 5})); + EXPECT_ANY_THROW(set_batch(f, 2)); } diff --git a/src/common/transformations/tests/smart_reshape/sr_reshape_1d.cpp b/src/common/transformations/tests/smart_reshape/sr_reshape_1d.cpp index bad3962e3fd080..d98cb32f258f4d 100644 --- a/src/common/transformations/tests/smart_reshape/sr_reshape_1d.cpp +++ b/src/common/transformations/tests/smart_reshape/sr_reshape_1d.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include #include "common_test_utils/ov_test_utils.hpp" @@ -19,20 +18,16 @@ TEST(SmartReshapeTests, Reshape1d) { f = std::make_shared(NodeVector{reshape}, ParameterVector{input}); } - InferenceEngine::CNNNetwork network(f); - - ASSERT_TRUE( - network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({5})); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); + ASSERT_TRUE(f->get_parameters()[0]->get_partial_shape().compatible({5})); auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.reshape( - InferenceEngine::ICNNNetwork::InputShapes{{f->get_parameters()[0]->get_friendly_name(), {1, 3, 300, 300}}})); + ASSERT_NO_THROW(f->reshape({{1, 3, 300, 300}})); check_unique_names(f, unh); - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({270000})); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({1, 3, 300, 300})); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible({270000})); + ASSERT_TRUE(f->get_parameters()[0]->get_partial_shape().compatible({1, 3, 300, 300})); } TEST(SmartReshapeTests, Reshape1d_negative) { @@ -44,19 +39,10 @@ TEST(SmartReshapeTests, Reshape1d_negative) { f = std::make_shared(NodeVector{reshape}, ParameterVector{input, pattern}); } - InferenceEngine::CNNNetwork network(f); - - ASSERT_TRUE( - network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().is_dynamic()); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); + ASSERT_TRUE(f->get_parameters()[0]->get_partial_shape().is_dynamic()); auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.reshape( - InferenceEngine::ICNNNetwork::InputShapes{{f->get_parameters()[0]->get_friendly_name(), {1, 3, 300, 300}}})); - check_unique_names(f, unh); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({270000})); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({1, 3, 300, 300})); - ASSERT_FALSE(network.getFunction()->get_parameters()[1]->get_output_target_inputs(0).empty()); + EXPECT_ANY_THROW(f->reshape({{1, 3, 300, 300}})); } diff --git a/src/common/transformations/tests/smart_reshape/sr_strided_slice_squeeze.cpp b/src/common/transformations/tests/smart_reshape/sr_strided_slice_squeeze.cpp index 002dc860dfffba..3c9053594ff68c 100644 --- a/src/common/transformations/tests/smart_reshape/sr_strided_slice_squeeze.cpp +++ b/src/common/transformations/tests/smart_reshape/sr_strided_slice_squeeze.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include #include "common_test_utils/ov_test_utils.hpp" @@ -27,19 +26,13 @@ TEST(SmartReshapeTests, SS_Squeeze) { f = std::make_shared(NodeVector{relu}, ParameterVector{input}); } - InferenceEngine::CNNNetwork network(f); - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({3})) - << network.getFunction()->get_results()[0]->get_output_partial_shape(0); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({1, 3})); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible({3})) + << f->get_results()[0]->get_output_partial_shape(0); + ASSERT_TRUE(f->get_parameters()[0]->get_partial_shape().compatible({1, 3})); auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.setBatchSize(2)); - check_unique_names(f, unh); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({3})) - << network.getFunction()->get_results()[0]->get_output_partial_shape(0); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({2, 3})); + EXPECT_ANY_THROW(set_batch(f, 2)); } TEST(SmartReshapeTests, SS_Squeeze_partial_begin_end_mask) { @@ -59,21 +52,19 @@ TEST(SmartReshapeTests, SS_Squeeze_partial_begin_end_mask) { f = std::make_shared(NodeVector{relu}, ParameterVector{input}); } - InferenceEngine::CNNNetwork network(f); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({1, 768})) - << network.getFunction()->get_results()[0]->get_output_partial_shape(0); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({1, 128, 768})); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible({1, 768})) + << f->get_results()[0]->get_output_partial_shape(0); + ASSERT_TRUE(f->get_parameters()[0]->get_partial_shape().compatible({1, 128, 768})); auto unh = std::make_shared(); init_unique_names(f, unh); - auto inputname = network.getFunction()->get_parameters()[0]->get_friendly_name(); - ASSERT_NO_THROW(network.reshape(InferenceEngine::ICNNNetwork::InputShapes{{inputname, {2, 128, 768}}})); + auto inputname = f->get_parameters()[0]->get_friendly_name(); + ASSERT_NO_THROW(f->reshape({{2, 128, 768}})); check_unique_names(f, unh); - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({2, 768})) - << network.getFunction()->get_results()[0]->get_output_partial_shape(0); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({2, 128, 768})); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible({2, 768})) + << f->get_results()[0]->get_output_partial_shape(0); + ASSERT_TRUE(f->get_parameters()[0]->get_partial_shape().compatible({2, 128, 768})); } TEST(SmartReshapeTests, SS_Squeeze_partial_begin_end) { @@ -95,21 +86,19 @@ TEST(SmartReshapeTests, SS_Squeeze_partial_begin_end) { f = std::make_shared(NodeVector{relu}, ParameterVector{input}); } - InferenceEngine::CNNNetwork network(f); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({1, 768})) - << network.getFunction()->get_results()[0]->get_output_partial_shape(0); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({1, 1, 768})); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible({1, 768})) + << f->get_results()[0]->get_output_partial_shape(0); + ASSERT_TRUE(f->get_parameters()[0]->get_partial_shape().compatible({1, 1, 768})); auto unh = std::make_shared(); init_unique_names(f, unh); - auto inputname = network.getFunction()->get_parameters()[0]->get_friendly_name(); - ASSERT_NO_THROW(network.reshape(InferenceEngine::ICNNNetwork::InputShapes{{inputname, {2, 1, 768}}})); + auto inputname = f->get_parameters()[0]->get_friendly_name(); + ASSERT_NO_THROW(f->reshape({{2, 1, 768}})); check_unique_names(f, unh); - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({2, 768})) - << network.getFunction()->get_results()[0]->get_output_partial_shape(0); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({2, 1, 768})); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible({2, 768})) + << f->get_results()[0]->get_output_partial_shape(0); + ASSERT_TRUE(f->get_parameters()[0]->get_partial_shape().compatible({2, 1, 768})); } TEST(SmartReshapeTests, SS_Squeeze_mask_use_negative) { @@ -128,15 +117,13 @@ TEST(SmartReshapeTests, SS_Squeeze_mask_use_negative) { f = std::make_shared(NodeVector{squeeze}, ParameterVector{input}); } - InferenceEngine::CNNNetwork network(f); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({1, 3})) - << network.getFunction()->get_results()[0]->get_output_partial_shape(0); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({1, 3})); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible({1, 3})) + << f->get_results()[0]->get_output_partial_shape(0); + ASSERT_TRUE(f->get_parameters()[0]->get_partial_shape().compatible({1, 3})); auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_ANY_THROW(network.setBatchSize(2)); + ASSERT_ANY_THROW(set_batch(f, 2)); check_unique_names(f, unh); } @@ -156,15 +143,13 @@ TEST(SmartReshapeTests, SS_Squeeze_negative_stride_negative) { f = std::make_shared(NodeVector{relu}, ParameterVector{input}); } - InferenceEngine::CNNNetwork network(f); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({3})) - << network.getFunction()->get_results()[0]->get_output_partial_shape(0); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({1, 3})); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible({3})) + << f->get_results()[0]->get_output_partial_shape(0); + ASSERT_TRUE(f->get_parameters()[0]->get_partial_shape().compatible({1, 3})); auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_ANY_THROW(network.setBatchSize(2)); + ASSERT_ANY_THROW(set_batch(f, 2)); check_unique_names(f, unh); } @@ -185,20 +170,13 @@ TEST(SmartReshapeTests, SS_SharedSqueezes) { f = std::make_shared(NodeVector{relu_1, relu_2}, ParameterVector{input}); } - InferenceEngine::CNNNetwork network(f); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({3})) - << network.getFunction()->get_results()[0]->get_output_partial_shape(0); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({1, 3})); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible({3})) + << f->get_results()[0]->get_output_partial_shape(0); + ASSERT_TRUE(f->get_parameters()[0]->get_partial_shape().compatible({1, 3})); auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.setBatchSize(2)); - check_unique_names(f, unh); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({3})) - << network.getFunction()->get_results()[0]->get_output_partial_shape(0); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({2, 3})); + EXPECT_ANY_THROW(set_batch(f, 2)); } TEST(SmartReshapeTests, SS_SqueezeNegativeAxes) { @@ -218,20 +196,13 @@ TEST(SmartReshapeTests, SS_SqueezeNegativeAxes) { f = std::make_shared(NodeVector{relu}, ParameterVector{input}); } - InferenceEngine::CNNNetwork network(f); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({3, 8, 2})) - << network.getFunction()->get_results()[0]->get_output_partial_shape(0); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({1, 3, 1, 8, 1, 2})); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible({3, 8, 2})) + << f->get_results()[0]->get_output_partial_shape(0); + ASSERT_TRUE(f->get_parameters()[0]->get_partial_shape().compatible({1, 3, 1, 8, 1, 2})); auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.setBatchSize(2)); - check_unique_names(f, unh); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({3, 8, 2})) - << network.getFunction()->get_results()[0]->get_output_partial_shape(0); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({2, 3, 1, 8, 1, 2})); + EXPECT_ANY_THROW(set_batch(f, 2)); } TEST(SmartReshapeTests, Squeeze_SSNegativeAxes) { @@ -250,18 +221,11 @@ TEST(SmartReshapeTests, Squeeze_SSNegativeAxes) { f = std::make_shared(NodeVector{ss}, ParameterVector{input}); } - InferenceEngine::CNNNetwork network(f); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({3, 8, 2})) - << network.getFunction()->get_results()[0]->get_output_partial_shape(0); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({1, 3, 1, 8, 1, 2})); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible({3, 8, 2})) + << f->get_results()[0]->get_output_partial_shape(0); + ASSERT_TRUE(f->get_parameters()[0]->get_partial_shape().compatible({1, 3, 1, 8, 1, 2})); auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.setBatchSize(2)); - check_unique_names(f, unh); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({3, 8, 2})) - << network.getFunction()->get_results()[0]->get_output_partial_shape(0); - ASSERT_TRUE(network.getFunction()->get_parameters()[0]->get_partial_shape().compatible({2, 3, 1, 8, 1, 2})); + EXPECT_ANY_THROW(set_batch(f, 2)); } diff --git a/src/common/transformations/tests/smart_reshape/sr_sub_graph_ops.cpp b/src/common/transformations/tests/smart_reshape/sr_sub_graph_ops.cpp index 9ff6aa84ca7419..25c30db2fa4339 100644 --- a/src/common/transformations/tests/smart_reshape/sr_sub_graph_ops.cpp +++ b/src/common/transformations/tests/smart_reshape/sr_sub_graph_ops.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include #include "common_test_utils/ov_test_utils.hpp" @@ -49,26 +48,17 @@ TEST(SmartReshapeTests, TensorIteratorStaticParameters) { f = std::make_shared(OutputVector{out0, out1, out2, out3}, ParameterVector{X, Y, M}); } - InferenceEngine::CNNNetwork network(f); - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({})); - ASSERT_TRUE(network.getFunction()->get_results()[1]->get_output_partial_shape(0).compatible({1, 1, 1})); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible({})); + ASSERT_TRUE(f->get_results()[1]->get_output_partial_shape(0).compatible({1, 1, 1})); // concat output (seq len = 1, so it means num_iter = 1) - ASSERT_TRUE(network.getFunction()->get_results()[2]->get_output_partial_shape(0).compatible({1, 1, 1})); - ASSERT_TRUE(network.getFunction()->get_results()[3]->get_output_partial_shape(0).compatible({1, 1, 1})); + ASSERT_TRUE(f->get_results()[2]->get_output_partial_shape(0).compatible({1, 1, 1})); + ASSERT_TRUE(f->get_results()[3]->get_output_partial_shape(0).compatible({1, 1, 1})); auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.reshape( - InferenceEngine::ICNNNetwork::InputShapes{{f->get_parameters()[0]->get_friendly_name(), {32, 1, 10}}, - {f->get_parameters()[1]->get_friendly_name(), {32, 10, 1}}, - {f->get_parameters()[2]->get_friendly_name(), {32, 1, 10}}})); - check_unique_names(f, unh); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({})); - ASSERT_TRUE(network.getFunction()->get_results()[1]->get_output_partial_shape(0).compatible({32, 1, 10})); - // concat output - ASSERT_TRUE(network.getFunction()->get_results()[2]->get_output_partial_shape(0).compatible({32, 10, 10})); - ASSERT_TRUE(network.getFunction()->get_results()[3]->get_output_partial_shape(0).compatible({32, 1, 1})); + EXPECT_ANY_THROW(f->reshape({{f->get_parameters()[0]->get_friendly_name(), {32, 1, 10}}, + {f->get_parameters()[1]->get_friendly_name(), {32, 10, 1}}, + {f->get_parameters()[2]->get_friendly_name(), {32, 1, 10}}})); } TEST(SmartReshapeTests, TensorIteratorDynamicParameters) { @@ -109,26 +99,17 @@ TEST(SmartReshapeTests, TensorIteratorDynamicParameters) { f = std::make_shared(OutputVector{out0, out1, out2, out3}, ParameterVector{X, Y, M}); } - InferenceEngine::CNNNetwork network(f); - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({})); - ASSERT_TRUE(network.getFunction()->get_results()[1]->get_output_partial_shape(0).compatible({1, 1, 1})); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible({})); + ASSERT_TRUE(f->get_results()[1]->get_output_partial_shape(0).compatible({1, 1, 1})); // concat output (seq len = 1, so it means num_iter = 1) - ASSERT_TRUE(network.getFunction()->get_results()[2]->get_output_partial_shape(0).compatible({1, 1, 1})); - ASSERT_TRUE(network.getFunction()->get_results()[3]->get_output_partial_shape(0).compatible({1, 1, 1})); + ASSERT_TRUE(f->get_results()[2]->get_output_partial_shape(0).compatible({1, 1, 1})); + ASSERT_TRUE(f->get_results()[3]->get_output_partial_shape(0).compatible({1, 1, 1})); auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.reshape( - InferenceEngine::ICNNNetwork::InputShapes{{f->get_parameters()[0]->get_friendly_name(), {32, 1, 10}}, - {f->get_parameters()[1]->get_friendly_name(), {32, 10, 1}}, - {f->get_parameters()[2]->get_friendly_name(), {32, 1, 10}}})); - check_unique_names(f, unh); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({})); - ASSERT_TRUE(network.getFunction()->get_results()[1]->get_output_partial_shape(0).compatible({32, 1, 10})); - // concat output - ASSERT_TRUE(network.getFunction()->get_results()[2]->get_output_partial_shape(0).compatible({32, 10, 10})); - ASSERT_TRUE(network.getFunction()->get_results()[3]->get_output_partial_shape(0).compatible({32, 1, 1})); + EXPECT_ANY_THROW(f->reshape({{f->get_parameters()[0]->get_friendly_name(), {32, 1, 10}}, + {f->get_parameters()[1]->get_friendly_name(), {32, 10, 1}}, + {f->get_parameters()[2]->get_friendly_name(), {32, 1, 10}}})); } TEST(SmartReshapeTests, LoopStaticParameters) { @@ -174,29 +155,17 @@ TEST(SmartReshapeTests, LoopStaticParameters) { f = std::make_shared(OutputVector{out0, out1, out2, out3}, ParameterVector{X, Y, M}); } - InferenceEngine::CNNNetwork network(f); - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({})); - ASSERT_TRUE( - network.getFunction()->get_results()[1]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible({})); + ASSERT_TRUE(f->get_results()[1]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); // concat output - ASSERT_TRUE( - network.getFunction()->get_results()[2]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); - ASSERT_TRUE( - network.getFunction()->get_results()[3]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); + ASSERT_TRUE(f->get_results()[2]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); + ASSERT_TRUE(f->get_results()[3]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.reshape( - InferenceEngine::ICNNNetwork::InputShapes{{f->get_parameters()[0]->get_friendly_name(), {32, 1, 10}}, - {f->get_parameters()[1]->get_friendly_name(), {32, 10, 1}}, - {f->get_parameters()[2]->get_friendly_name(), {32, 1, 10}}})); - check_unique_names(f, unh); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({})); - ASSERT_TRUE(network.getFunction()->get_results()[1]->get_output_partial_shape(0).compatible({32, 1, 10})); - // concat output - ASSERT_TRUE(network.getFunction()->get_results()[2]->get_output_partial_shape(0).compatible({32, 10, 10})); - ASSERT_TRUE(network.getFunction()->get_results()[3]->get_output_partial_shape(0).compatible({32, 1, 1})); + EXPECT_ANY_THROW(f->reshape({{f->get_parameters()[0]->get_friendly_name(), {32, 1, 10}}, + {f->get_parameters()[1]->get_friendly_name(), {32, 10, 1}}, + {f->get_parameters()[2]->get_friendly_name(), {32, 1, 10}}})); } TEST(SmartReshapeTests, LoopDynamicParameters) { @@ -242,29 +211,17 @@ TEST(SmartReshapeTests, LoopDynamicParameters) { f = std::make_shared(OutputVector{out0, out1, out2, out3}, ParameterVector{X, Y, M}); } - InferenceEngine::CNNNetwork network(f); - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({})); - ASSERT_TRUE( - network.getFunction()->get_results()[1]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible({})); + ASSERT_TRUE(f->get_results()[1]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); // concat output - ASSERT_TRUE( - network.getFunction()->get_results()[2]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); - ASSERT_TRUE( - network.getFunction()->get_results()[3]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); + ASSERT_TRUE(f->get_results()[2]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); + ASSERT_TRUE(f->get_results()[3]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.reshape( - InferenceEngine::ICNNNetwork::InputShapes{{f->get_parameters()[0]->get_friendly_name(), {32, 1, 10}}, - {f->get_parameters()[1]->get_friendly_name(), {32, 10, 1}}, - {f->get_parameters()[2]->get_friendly_name(), {32, 1, 10}}})); - check_unique_names(f, unh); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({})); - ASSERT_TRUE(network.getFunction()->get_results()[1]->get_output_partial_shape(0).compatible({32, 1, 10})); - // concat output - ASSERT_TRUE(network.getFunction()->get_results()[2]->get_output_partial_shape(0).compatible({32, 10, 10})); - ASSERT_TRUE(network.getFunction()->get_results()[3]->get_output_partial_shape(0).compatible({32, 1, 1})); + EXPECT_ANY_THROW(f->reshape({{f->get_parameters()[0]->get_friendly_name(), {32, 1, 10}}, + {f->get_parameters()[1]->get_friendly_name(), {32, 10, 1}}, + {f->get_parameters()[2]->get_friendly_name(), {32, 1, 10}}})); } TEST(SmartReshapeTests, LoopParentParametersUsedInBody) { @@ -314,29 +271,17 @@ TEST(SmartReshapeTests, LoopParentParametersUsedInBody) { f = std::make_shared(OutputVector{out0, out1, out2, out3}, ParameterVector{X, Y, M}); } - InferenceEngine::CNNNetwork network(f); - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({})); - ASSERT_TRUE( - network.getFunction()->get_results()[1]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible({})); + ASSERT_TRUE(f->get_results()[1]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); // concat output - ASSERT_TRUE( - network.getFunction()->get_results()[2]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); - ASSERT_TRUE( - network.getFunction()->get_results()[3]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); + ASSERT_TRUE(f->get_results()[2]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); + ASSERT_TRUE(f->get_results()[3]->get_output_partial_shape(0).compatible(PartialShape::dynamic())); auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.reshape( - InferenceEngine::ICNNNetwork::InputShapes{{f->get_parameters()[0]->get_friendly_name(), {4, 3, 2}}, - {f->get_parameters()[1]->get_friendly_name(), {4, 3, 2}}, - {f->get_parameters()[2]->get_friendly_name(), {4, 3, 2}}})); - check_unique_names(f, unh); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({})); - ASSERT_TRUE(network.getFunction()->get_results()[1]->get_output_partial_shape(0).compatible({4, 3, 2})); - // concat output - ASSERT_TRUE(network.getFunction()->get_results()[2]->get_output_partial_shape(0).compatible({4, 30, 2})); - ASSERT_TRUE(network.getFunction()->get_results()[3]->get_output_partial_shape(0).compatible({4, 3, 2})); + EXPECT_ANY_THROW(f->reshape({{f->get_parameters()[0]->get_friendly_name(), {4, 3, 2}}, + {f->get_parameters()[1]->get_friendly_name(), {4, 3, 2}}, + {f->get_parameters()[2]->get_friendly_name(), {4, 3, 2}}})); } TEST(SmartReshapeTests, TensorIteratorParentParameterUsedInBody) { @@ -381,24 +326,15 @@ TEST(SmartReshapeTests, TensorIteratorParentParameterUsedInBody) { f = std::make_shared(OutputVector{out0, out1, out2, out3}, ParameterVector{X, Y, M}); } - InferenceEngine::CNNNetwork network(f); - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({})); - ASSERT_TRUE(network.getFunction()->get_results()[1]->get_output_partial_shape(0).compatible({1, 1, 1})); + ASSERT_TRUE(f->get_results()[0]->get_output_partial_shape(0).compatible({})); + ASSERT_TRUE(f->get_results()[1]->get_output_partial_shape(0).compatible({1, 1, 1})); // concat output (seq len = 1, so it means num_iter = 1) - ASSERT_TRUE(network.getFunction()->get_results()[2]->get_output_partial_shape(0).compatible({1, 1, 1})); - ASSERT_TRUE(network.getFunction()->get_results()[3]->get_output_partial_shape(0).compatible({1, 1, 1})); + ASSERT_TRUE(f->get_results()[2]->get_output_partial_shape(0).compatible({1, 1, 1})); + ASSERT_TRUE(f->get_results()[3]->get_output_partial_shape(0).compatible({1, 1, 1})); auto unh = std::make_shared(); init_unique_names(f, unh); - ASSERT_NO_THROW(network.reshape( - InferenceEngine::ICNNNetwork::InputShapes{{f->get_parameters()[0]->get_friendly_name(), {32, 1, 10}}, - {f->get_parameters()[1]->get_friendly_name(), {1, 1, 1}}, - {f->get_parameters()[2]->get_friendly_name(), {32, 1, 10}}})); - check_unique_names(f, unh); - - ASSERT_TRUE(network.getFunction()->get_results()[0]->get_output_partial_shape(0).compatible({})); - ASSERT_TRUE(network.getFunction()->get_results()[1]->get_output_partial_shape(0).compatible({32, 1, 10})); - // concat output - ASSERT_TRUE(network.getFunction()->get_results()[2]->get_output_partial_shape(0).compatible({32, 10, 10})); - ASSERT_TRUE(network.getFunction()->get_results()[3]->get_output_partial_shape(0).compatible({32, 1, 1})); + EXPECT_ANY_THROW(f->reshape({{f->get_parameters()[0]->get_friendly_name(), {32, 1, 10}}, + {f->get_parameters()[1]->get_friendly_name(), {1, 1, 1}}, + {f->get_parameters()[2]->get_friendly_name(), {32, 1, 10}}})); } diff --git a/src/common/transformations/tests/transpose_sinking/ts_common_test.cpp b/src/common/transformations/tests/transpose_sinking/ts_common_test.cpp index 9a00aa9773ed4d..1da471f166639b 100644 --- a/src/common/transformations/tests/transpose_sinking/ts_common_test.cpp +++ b/src/common/transformations/tests/transpose_sinking/ts_common_test.cpp @@ -8,12 +8,14 @@ #include "openvino/pass/manager.hpp" #include "transformations/transpose_sinking/ts_binary.hpp" #include "transformations/transpose_sinking/ts_concat.hpp" +#include "transformations/transpose_sinking/ts_cumsum.hpp" #include "transformations/transpose_sinking/ts_data_movement.hpp" #include "transformations/transpose_sinking/ts_interpolate.hpp" #include "transformations/transpose_sinking/ts_reduction.hpp" #include "transformations/transpose_sinking/ts_slice.hpp" #include "transformations/transpose_sinking/ts_split.hpp" #include "transformations/transpose_sinking/ts_squeeze.hpp" +#include "transformations/transpose_sinking/ts_tile.hpp" #include "transformations/transpose_sinking/ts_unary.hpp" #include "transformations/transpose_sinking/ts_unsqueeze.hpp" #include "ts_test_case.hpp" @@ -206,6 +208,30 @@ FactoryPtr CreateInterpolateFactory(const std::string& type_name, bool is_refere return std::make_shared(type_name, is_reference); } +class CumSumFactory : public IFactory { +public: + explicit CumSumFactory(const std::string& type_name) : IFactory(type_name) {} + NodePtr create(const OutputVector& parent_nodes) const override { + return std::make_shared(parent_nodes[0], parent_nodes[1]); + } +}; + +FactoryPtr CreateCumSumFactory(const std::string& type_name) { + return std::make_shared(type_name); +} + +class TileFactory : public IFactory { +public: + explicit TileFactory(const std::string& type_name) : IFactory(type_name) {} + NodePtr create(const OutputVector& parent_nodes) const override { + return std::make_shared(parent_nodes[0], parent_nodes[1]); + } +}; + +FactoryPtr CreateTileFactory(const std::string& type_name) { + return std::make_shared(type_name); +} + class SliceFactory : public IFactory { public: explicit SliceFactory(const std::string& type_name) : IFactory(type_name) {} @@ -285,6 +311,12 @@ FactoryPtr CreateFakeQuantizeFactory(const std::string& type_name) { #undef CREATE_INTERPOLATE_FACTORY #define CREATE_INTERPOLATE_FACTORY(type_name, reference_flag) CreateInterpolateFactory(#type_name, reference_flag) +#undef CREATE_CUMSUM_FACTORY +#define CREATE_CUMSUM_FACTORY(type_name) CreateCumSumFactory(#type_name) + +#undef CREATE_TILE_FACTORY +#define CREATE_TILE_FACTORY(type_name) CreateTileFactory(#type_name) + #undef CREATE_SLICE_FACTORY #define CREATE_SLICE_FACTORY(type_name) CreateSliceFactory(#type_name) @@ -761,6 +793,84 @@ auto test_forward_interpolate = []() { INSTANTIATE_TEST_SUITE_P(TransposeSinkingCommonInterpolateForward, TSTestFixture, test_forward_interpolate()); +auto test_forward_cumsum = []() { + TestCase test_case; + + // Initialize common attributes + test_case.transformation = CREATE_PASS_FACTORY(TSCumSumForward); + test_case.num_main_ops = {1}; + test_case.inputs_to_main = {parameter(element::f32, {1, 2, 48, 80}), + constant(element::i64, {}, std::vector{0})}; + + // Test model description: + test_case.model.preprocess_inputs_to_main = {{set_transpose_for}, {{0}}}; + test_case.model.main_op = {CREATE_CUMSUM_FACTORY(CumSum)}; + test_case.model.model_template = create_model; + + // Reference model description: + auto set_specific_gather_for = [](const vector& idxs, const OutputVector& out_vec) -> OutputVector { + OutputVector result = out_vec; + for (const auto& idx : idxs) { + const auto& out = out_vec[idx]; + vector transpose_order(out_vec[0].get_shape().size()); + iota(transpose_order.begin(), transpose_order.end(), 0); + reverse(transpose_order.begin(), transpose_order.end()); + auto data = make_shared(element::i32, Shape{transpose_order.size()}, transpose_order); + auto axis = make_shared(element::i32, Shape{}, 0); + auto transpose = make_shared(data, out, axis); + result[idx] = transpose; + } + return result; + }; + test_case.model_ref.preprocess_inputs_to_main = {{set_specific_gather_for}, {{1}}}; + test_case.model_ref.main_op = {CREATE_CUMSUM_FACTORY(CumSum)}; + test_case.model_ref.preprocess_outputs_of_main = {{set_transpose_for}, {{0}}}; + test_case.model_ref.model_template = create_model; + + return wrapper(test_case); +}; + +INSTANTIATE_TEST_SUITE_P(TransposeSinkingCommonCumSumForward, TSTestFixture, test_forward_cumsum()); + +auto test_forward_tile = []() { + TestCase test_case; + + // Initialize common attributes + test_case.transformation = CREATE_PASS_FACTORY(TSTileForward); + test_case.num_main_ops = {1}; + test_case.inputs_to_main = {parameter(element::f32, {1, 2, 48, 80}), + constant(element::i64, {4}, std::vector{1, 2, 3, 4})}; + + // Test model description: + test_case.model.preprocess_inputs_to_main = {{set_transpose_for}, {{0}}}; + test_case.model.main_op = {CREATE_TILE_FACTORY(Tile)}; + test_case.model.model_template = create_model; + + // Reference model description: + auto set_specific_gather_for = [](const vector& idxs, const OutputVector& out_vec) -> OutputVector { + OutputVector result = out_vec; + for (const auto& idx : idxs) { + const auto& out = out_vec[idx]; + vector transpose_order(out_vec[0].get_shape().size()); + iota(transpose_order.begin(), transpose_order.end(), 0); + reverse(transpose_order.begin(), transpose_order.end()); + auto data = make_shared(element::i32, Shape{transpose_order.size()}, transpose_order); + auto axis = make_shared(element::i32, Shape{}, 0); + auto transpose = make_shared(out, data, axis); + result[idx] = transpose; + } + return result; + }; + test_case.model_ref.preprocess_inputs_to_main = {{set_specific_gather_for}, {{1}}}; + test_case.model_ref.main_op = {CREATE_TILE_FACTORY(Tile)}; + test_case.model_ref.preprocess_outputs_of_main = {{set_transpose_for}, {{0}}}; + test_case.model_ref.model_template = create_model; + + return wrapper(test_case); +}; + +INSTANTIATE_TEST_SUITE_P(TransposeSinkingCommonTileForward, TSTestFixture, test_forward_tile()); + auto test_forward_squeeze = []() { TestCase test_case; @@ -1262,6 +1372,120 @@ auto test_backward_interpolate = []() { INSTANTIATE_TEST_SUITE_P(TransposeSinkingCommonInterpolateBackward, TSTestFixture, test_backward_interpolate()); +auto test_backward_cumsum = []() { + TestCase test_case; + + // Initialize common attributes + test_case.transformation = CREATE_PASS_FACTORY(TSCumSumBackward); + test_case.num_main_ops = {1}; + test_case.inputs_to_main = {parameter(element::f32, {1, 2, 48, 80}), + constant(element::i64, {}, std::vector{0})}; + + // Test model description: + test_case.model.main_op = {CREATE_CUMSUM_FACTORY(CumSum)}; + test_case.model.preprocess_outputs_of_main = {{set_transpose_for}, {{0}}}; + test_case.model.model_template = create_model; + + // Reference model description: + auto set_specific_gather_for = [](const vector& idxs, const OutputVector& out_vec) -> OutputVector { + OutputVector result = out_vec; + for (const auto& idx : idxs) { + const auto& out = out_vec[idx]; + vector transpose_order(out_vec[0].get_shape().size()); + iota(transpose_order.begin(), transpose_order.end(), 0); + reverse(transpose_order.begin(), transpose_order.end()); + auto data = make_shared(element::i32, Shape{transpose_order.size()}, transpose_order); + auto axis = make_shared(element::i32, Shape{}, 0); + auto transpose = make_shared(data, out, axis); + result[idx] = transpose; + } + return result; + }; + test_case.model_ref.preprocess_inputs_to_main = {{set_transpose_for, set_specific_gather_for}, {{0}, {1}}}; + test_case.model_ref.main_op = {CREATE_CUMSUM_FACTORY(CumSum)}; + test_case.model_ref.model_template = create_model; + + return wrapper(test_case); +}; + +INSTANTIATE_TEST_SUITE_P(TransposeSinkingCommonCumSumBackward, TSTestFixture, test_backward_cumsum()); + +auto test_backward_tile = []() { + TestCase test_case; + + // Initialize common attributes + test_case.transformation = CREATE_PASS_FACTORY(TSTileBackward); + test_case.num_main_ops = {1}; + test_case.inputs_to_main = {parameter(element::f32, {1, 2, 48, 80}), + constant(element::i64, {4}, std::vector{1, 2, 3, 4})}; + + // Test model description: + test_case.model.main_op = {CREATE_TILE_FACTORY(Tile)}; + test_case.model.preprocess_outputs_of_main = {{set_transpose_for}, {{0}}}; + test_case.model.model_template = create_model; + + // Reference model description: + auto set_specific_gather_for = [](const vector& idxs, const OutputVector& out_vec) -> OutputVector { + OutputVector result = out_vec; + for (const auto& idx : idxs) { + const auto& out = out_vec[idx]; + vector transpose_order(out_vec[0].get_shape().size()); + iota(transpose_order.begin(), transpose_order.end(), 0); + reverse(transpose_order.begin(), transpose_order.end()); + auto data = make_shared(element::i32, Shape{transpose_order.size()}, transpose_order); + auto axis = make_shared(element::i32, Shape{}, 0); + auto transpose = make_shared(out, data, axis); + result[idx] = transpose; + } + return result; + }; + test_case.model_ref.preprocess_inputs_to_main = {{set_transpose_for, set_specific_gather_for}, {{0}, {1}}}; + test_case.model_ref.main_op = {CREATE_TILE_FACTORY(Tile)}; + test_case.model_ref.model_template = create_model; + + return wrapper(test_case); +}; + +INSTANTIATE_TEST_SUITE_P(TransposeSinkingCommonTileBackward, TSTestFixture, test_backward_tile()); + +auto test_backward_tile_tf_case = []() { + TestCase test_case; + + // Initialize common attributes + test_case.transformation = CREATE_PASS_FACTORY(TSTileBackward); + test_case.num_main_ops = {1}; + test_case.inputs_to_main = {parameter(element::f32, {2, 1, 1, 128}), + constant(element::i64, {4}, std::vector{1, 1, 88, 1})}; + + // Test model description: + test_case.model.main_op = {CREATE_TILE_FACTORY(Tile)}; + test_case.model.preprocess_outputs_of_main = {{set_transpose_for}, {{0}}}; + test_case.model.model_template = create_model; + + // Reference model description: + auto set_specific_gather_for = [](const vector& idxs, const OutputVector& out_vec) -> OutputVector { + OutputVector result = out_vec; + for (const auto& idx : idxs) { + const auto& out = out_vec[idx]; + vector transpose_order(out_vec[0].get_shape().size()); + iota(transpose_order.begin(), transpose_order.end(), 0); + reverse(transpose_order.begin(), transpose_order.end()); + auto data = make_shared(element::i32, Shape{transpose_order.size()}, transpose_order); + auto axis = make_shared(element::i32, Shape{}, 0); + auto transpose = make_shared(out, data, axis); + result[idx] = transpose; + } + return result; + }; + test_case.model_ref.preprocess_inputs_to_main = {{set_transpose_for, set_specific_gather_for}, {{0}, {1}}}; + test_case.model_ref.main_op = {CREATE_TILE_FACTORY(Tile)}; + test_case.model_ref.model_template = create_model; + + return wrapper(test_case); +}; + +INSTANTIATE_TEST_SUITE_P(TransposeSinkingCommonTileBackwardTfCase, TSTestFixture, test_backward_tile_tf_case()); + auto test_backward_unsqueeze = []() { TestCase test_case; diff --git a/src/common/transformations/tests/transpose_sinking/ts_unary_test.cpp b/src/common/transformations/tests/transpose_sinking/ts_unary_test.cpp index e47f378cb2bace..8076edf43b2eb8 100644 --- a/src/common/transformations/tests/transpose_sinking/ts_unary_test.cpp +++ b/src/common/transformations/tests/transpose_sinking/ts_unary_test.cpp @@ -7,7 +7,7 @@ #include "common_test_utils/ov_test_utils.hpp" #include "gtest/gtest.h" #include "openvino/frontend/manager.hpp" -#include "openvino/opsets/opset10.hpp" +#include "openvino/opsets/opset12.hpp" #include "openvino/pass/manager.hpp" #include "ts_test_utils.hpp" @@ -85,6 +85,37 @@ NodePtr UnaryFactory::create(const OutputVector& inputs) const { return std::make_shared(inputs[0], element::f64); } +template <> +NodePtr UnaryFactory::create(const OutputVector& inputs) const { + auto alpha = std::make_shared(element::f32, Shape{}, 2.0); + auto lambda = std::make_shared(element::f32, Shape{}, 3.0); + return std::make_shared(inputs[0], alpha, lambda); +} + +template <> +NodePtr UnaryFactory::create(const OutputVector& inputs) const { + auto beta = std::make_shared(element::f32, Shape{}, 0.9); + return std::make_shared(inputs[0], beta); +} + +template <> +NodePtr UnaryFactory::create(const OutputVector& inputs) const { + auto alpha = std::make_shared(element::f32, Shape{}, 2.0); + auto beta = std::make_shared(element::f32, Shape{}, 3.0); + return std::make_shared(inputs[0], alpha, beta); +} + +template <> +NodePtr UnaryFactory::create(const OutputVector& inputs) const { + return std::make_shared(inputs[0], 2); +} + +template <> +NodePtr UnaryFactory::create(const OutputVector& inputs) const { + auto like = std::make_shared(element::f64, Shape{}, 1); + return std::make_shared(inputs[0], like); +} + template FactoryPtr CreateUnaryFactory(const std::string& type_name) { return std::make_shared>(type_name); @@ -352,16 +383,18 @@ std::shared_ptr CreateReferenceFunction(const FactoryPtr& unary_facto } // 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)}; + 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), CREATE_UNARY_FACTORY(Selu), + CREATE_UNARY_FACTORY(Swish), CREATE_UNARY_FACTORY(HardSigmoid), CREATE_UNARY_FACTORY(LogSoftmax), + CREATE_UNARY_FACTORY(ConvertLike)}; TEST_P(TransposeSinkingUnaryTestFixture, CompareFunctions) { FactoryPtr unary_factory; diff --git a/src/common/transformations/tests/utils/compress_quantize_weights.cpp b/src/common/transformations/tests/utils/compress_quantize_weights.cpp index 5a62b79bfaabc1..cc31017368863f 100644 --- a/src/common/transformations/tests/utils/compress_quantize_weights.cpp +++ b/src/common/transformations/tests/utils/compress_quantize_weights.cpp @@ -31,6 +31,7 @@ struct CompressQuantizeWeightsParams { std::vector expected_weights; float scale_val; float zero_point_val; + bool fuse_zero_point; }; class CompressQuantizeWeightsTests @@ -66,9 +67,14 @@ class CompressQuantizeWeightsTests auto data = opset8::Constant::create(param.expected_type, param.shape, param.expected_weights); auto convert = std::make_shared(data, element::f32); auto scale = opset8::Constant::create(element::f32, Shape{}, {param.scale_val}); - auto zero_point = opset8::Constant::create(element::f32, Shape{}, {param.zero_point_val}); - auto sub = std::make_shared(convert, zero_point); - auto mul = std::make_shared(sub, scale); + std::shared_ptr mul; + if (!param.fuse_zero_point) { + auto zero_point = opset8::Constant::create(element::f32, Shape{}, {param.zero_point_val}); + auto sub = std::make_shared(convert, zero_point); + mul = std::make_shared(sub, scale); + } else { + mul = std::make_shared(convert, scale); + } model_ref = std::make_shared(mul, ParameterVector{}); } comparator.enable(FunctionsComparator::CmpValues::CONST_VALUES); @@ -89,7 +95,8 @@ static std::vector params = { element::i4, {-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f}, 3.0f, - -0.666667f}, + -0.666667f, + false}, {Shape{2, 3, 1, 1}, {-1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 11.0f}, 0.0f, @@ -100,7 +107,8 @@ static std::vector params = { element::i4, {-8.0f, -5.0f, -4.0f, -2.0f, 0.0f, 7.0f}, 0.333333f, - -5.0f}, + -5.0f, + false}, {Shape{2, 4, 1, 1}, {-1.0f, 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 11.0f}, 1.0f, @@ -109,9 +117,10 @@ static std::vector params = { 6.0f, 17, element::i8, - {-8.0f, -8.0f, -8.0f, -6.0f, -4.0f, -2.0f, 0.0f, 8.0f}, + {-4.0f, -4.0f, -4.0f, -2.0f, 0.0f, 2.0f, 4.0f, 12.0f}, 0.5f, - -4.0f}, + -4.0f, + true}, {Shape{2, 4, 1, 1}, {-1.0f, 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 11.0f}, 1.0f, @@ -122,7 +131,8 @@ static std::vector params = { element::i8, {-128.0f, -128.0f, -128.0f, -96.0f, -64.0f, -32.0f, 0.0f, 127.0f}, 0.0313725f, - -64.25f}, + -64.25f, + false}, }; static element::TypeVector data_precisions = {element::f32, element::f16}; @@ -198,7 +208,7 @@ TEST_F(TransformationTestsF, CompressQuantizeWeightsWithDequantizationSubgraphFP comparator.enable(FunctionsComparator::CmpValues::ACCURACY); } -TEST_F(TransformationTestsF, CompressQuantizeWeightsWithZeroPointOptimizer) { +TEST_F(TransformationTestsF, CompressQuantizeWeightsWithZeroPointEliminated) { { auto data = opset8::Constant::create(element::f32, Shape{3, 1, 1, 1}, {-0.144816, 0.0858578, 0.110928}); auto input_low = opset8::Constant::create(element::f32, Shape{3, 1, 1, 1}, {-0.402659, -0.383148, -0.34054}); @@ -209,7 +219,6 @@ TEST_F(TransformationTestsF, CompressQuantizeWeightsWithZeroPointOptimizer) { model = std::make_shared(NodeVector{fq}, ParameterVector{}); manager.register_pass(); - manager.register_pass(); } { @@ -223,7 +232,7 @@ TEST_F(TransformationTestsF, CompressQuantizeWeightsWithZeroPointOptimizer) { comparator.enable(FunctionsComparator::CmpValues::ACCURACY); } -TEST_F(TransformationTestsF, CompressQuantizeWeightsWithZeroPointOptimizerFP16) { +TEST_F(TransformationTestsF, CompressQuantizeWeightsWithZeroPointEliminatedFP16) { { auto data = opset8::Constant::create(element::f16, Shape{3, 1, 1, 1}, {0.2, 1.2, 1.2}); auto input_low = @@ -239,7 +248,6 @@ TEST_F(TransformationTestsF, CompressQuantizeWeightsWithZeroPointOptimizerFP16) model = std::make_shared(NodeVector{fq}, ParameterVector{}); manager.register_pass(); - manager.register_pass(); } { @@ -253,7 +261,7 @@ TEST_F(TransformationTestsF, CompressQuantizeWeightsWithZeroPointOptimizerFP16) comparator.enable(FunctionsComparator::CmpValues::ACCURACY); } -TEST_F(TransformationTestsF, NegativeCompressQuantizeWeightsWithZeroPointOptimizer) { +TEST_F(TransformationTestsF, NegativeCompressQuantizeWeights) { { auto data = opset8::Constant::create(element::f32, Shape{2, 4, 1, 1}, {-1, 0, 1, 2, 3, 4, 5, 11}); auto input_low = opset8::Constant::create(element::f32, Shape{}, {1}); @@ -264,7 +272,6 @@ TEST_F(TransformationTestsF, NegativeCompressQuantizeWeightsWithZeroPointOptimiz model = std::make_shared(NodeVector{fq}, ParameterVector{}); manager.register_pass(); - manager.register_pass(); } { auto data = opset8::Constant::create(element::i8, Shape{2, 4, 1, 1}, {-128, -128, -128, -96, -64, -32, 0, 127}); @@ -289,7 +296,6 @@ TEST_F(TransformationTestsF, NegativeCompressQuantizeWeightsNonConstantInput) { model = std::make_shared(NodeVector{fq}, ParameterVector{data}); manager.register_pass(); - manager.register_pass(); comparator.enable(FunctionsComparator::CmpValues::CONST_VALUES); comparator.enable(FunctionsComparator::CmpValues::ACCURACY); diff --git a/src/common/transformations/tests/utils/convert_precision.cpp b/src/common/transformations/tests/utils/convert_precision.cpp index 07d6288112214a..1dac080461d16b 100644 --- a/src/common/transformations/tests/utils/convert_precision.cpp +++ b/src/common/transformations/tests/utils/convert_precision.cpp @@ -99,10 +99,11 @@ TEST(TransformationTests, ConvertPrecision_NMS4) { static const precisions_map precisions = {{element::i64, element::i32}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); } @@ -131,8 +132,10 @@ TEST(TransformationTests, ConvertPrecision_NMS5) { pass::Manager manager; static const precisions_map precisions = {{element::i64, element::i32}, {element::f32, element::f16}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); } @@ -154,8 +157,10 @@ TEST(TransformationTests, ConvertPrecision_MatrixNms) { pass::Manager manager; static const precisions_map precisions = {{element::i64, element::i32}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); } @@ -177,8 +182,10 @@ TEST(TransformationTests, ConvertPrecision_MulticlassNms) { pass::Manager manager; static const precisions_map precisions = {{element::i64, element::i32}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); } @@ -195,10 +202,11 @@ TEST(TransformationTests, ConvertPrecision_ShapeOf) { static const precisions_map precisions = {{element::i64, element::i32}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); } @@ -217,10 +225,11 @@ TEST(TransformationTests, ConvertPrecision_Range) { static const precisions_map precisions = {{element::i64, element::i32}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); } @@ -238,10 +247,11 @@ TEST(TransformationTests, ConvertPrecision_ConstantRelu) { static const precisions_map precisions = {{element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); } @@ -258,10 +268,11 @@ TEST(TransformationTests, ConvertPrecision_Convert) { static const precisions_map precisions = {{element::i64, element::i32}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); } @@ -276,6 +287,7 @@ TEST(TransformationTests, ConvertPrecision_ConvertElimination) { f = std::make_shared(NodeVector{convert}, ParameterVector{input}); pass::Manager manager; + manager.register_pass(); manager.register_pass(precisions_map{{element::f16, element::f32}}); manager.run_passes(f); ASSERT_FALSE(has_type(f)); @@ -287,7 +299,7 @@ TEST(TransformationTests, ConvertPrecision_ConvertElimination) { f_ref = std::make_shared(NodeVector{relu}, ParameterVector{input}); } - + ASSERT_NO_THROW(check_rt_info(f)); auto res = compare_functions(f, f_ref); ASSERT_TRUE(res.first) << res.second; } @@ -305,10 +317,11 @@ TEST(TransformationTests, ConvertPrecision_TopK) { static const precisions_map precisions = {{element::i64, element::i32}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); } @@ -325,10 +338,11 @@ TEST(TransformationTests, ConvertPrecision_Unique10) { static const precisions_map precisions = {{element::i64, element::i32}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(model); } - + ASSERT_NO_THROW(check_rt_info(model)); ASSERT_EQ(model->outputs().size(), 4); EXPECT_EQ(model->outputs()[0].get_element_type(), element::f32); EXPECT_EQ(model->outputs()[1].get_element_type(), element::i32); @@ -353,10 +367,11 @@ TEST(TransformationTests, ConvertPrecision_NonZero) { static const precisions_map precisions = {{element::i64, element::i32}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); } @@ -374,10 +389,11 @@ TEST(TransformationTests, ConvertPrecision_Bucketize) { static const precisions_map precisions = {{element::i64, element::i32}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); } @@ -404,6 +420,7 @@ TEST(TransformationTests, ConvertPrecision_Roundings) { static const precisions_map precisions = {{element::i64, element::i32}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); @@ -413,7 +430,7 @@ TEST(TransformationTests, ConvertPrecision_Roundings) { ASSERT_EQ(casted_end->cast_vector(), std::vector({max_int32, max_int32, max_int32, max_int32})); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); } @@ -461,9 +478,11 @@ TEST(TransformationTests, ConvertPrecision_TIBody) { static const precisions_map precisions = {{element::i64, element::i32}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(tensor_iterator->get_body())); @@ -484,10 +503,11 @@ TEST(TransformationTests, ConvertPrecision_Equal) { static const precisions_map precisions = {{element::boolean, element::u8}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); ASSERT_TRUE(has_type(f)); @@ -506,10 +526,11 @@ TEST(TransformationTests, ConvertPrecision_NotEqual) { static const precisions_map precisions = {{element::boolean, element::u8}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); ASSERT_TRUE(has_type(f)); @@ -528,10 +549,11 @@ TEST(TransformationTests, ConvertPrecision_Greater) { static const precisions_map precisions = {{element::boolean, element::u8}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); ASSERT_TRUE(has_type(f)); @@ -550,10 +572,11 @@ TEST(TransformationTests, ConvertPrecision_GreaterEqual) { static const precisions_map precisions = {{element::boolean, element::u8}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); ASSERT_TRUE(has_type(f)); @@ -572,10 +595,11 @@ TEST(TransformationTests, ConvertPrecision_Less) { static const precisions_map precisions = {{element::boolean, element::u8}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); ASSERT_TRUE(has_type(f)); @@ -594,10 +618,11 @@ TEST(TransformationTests, ConvertPrecision_LessEqual) { static const precisions_map precisions = {{element::boolean, element::u8}, {element::f16, element::f32}}; + manager.register_pass(); manager.register_pass(precisions); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); ASSERT_TRUE(has_type(f)); @@ -613,10 +638,11 @@ TEST(TransformationTests, ConvertPrecision_LogicalAnd) { f = std::make_shared(OutputVector{node}, ParameterVector{input1, input2}); pass::Manager manager; + manager.register_pass(); manager.register_pass(precisions_map{{element::boolean, element::u8}}); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_TRUE(has_type(f)); } @@ -631,10 +657,11 @@ TEST(TransformationTests, ConvertPrecision_LogicalOr) { f = std::make_shared(OutputVector{node}, ParameterVector{input1, input2}); pass::Manager manager; + manager.register_pass(); manager.register_pass(precisions_map{{element::boolean, element::u8}}); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_TRUE(has_type(f)); } @@ -649,10 +676,11 @@ TEST(TransformationTests, ConvertPrecision_LogicalXor) { f = std::make_shared(OutputVector{node}, ParameterVector{input1, input2}); pass::Manager manager; + manager.register_pass(); manager.register_pass(precisions_map{{element::boolean, element::u8}}); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_TRUE(has_type(f)); } @@ -666,10 +694,11 @@ TEST(TransformationTests, ConvertPrecision_LogicalNot) { f = std::make_shared(OutputVector{node}, ParameterVector{input1}); pass::Manager manager; + manager.register_pass(); manager.register_pass(precisions_map{{element::boolean, element::u8}}); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_TRUE(has_type(f)); @@ -692,10 +721,11 @@ TEST(TransformationTests, ConvertPrecision_Select) { f = std::make_shared(OutputVector{select}, ParameterVector{input1}); pass::Manager manager; + manager.register_pass(); manager.register_pass(precisions_map{{element::boolean, element::u8}}); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_TRUE(has_type(f)); } @@ -710,11 +740,12 @@ TEST(TransformationTests, ConvertPrecision_TypeRelaxedWithSelect) { f = std::make_shared(OutputVector{select}, ParameterVector{input1}); pass::Manager manager; + manager.register_pass(); manager.register_pass(precisions_map{{element::boolean, element::i32}}); manager.register_pass(precisions_map{{element::i32, element::i64}}); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); ASSERT_TRUE(has_type(f)); @@ -732,10 +763,12 @@ TEST(TransformationTests, ConvertPrecision_TypeRelaxed) { f = std::make_shared(OutputVector{type_relaxed}, ParameterVector{input1}); pass::Manager manager; + manager.register_pass(); manager.register_pass(precisions_map{{element::boolean, element::i32}}); manager.register_pass(precisions_map{{element::i32, element::i64}}); manager.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); ASSERT_FALSE(has_type(f)); ASSERT_TRUE(has_type(f)); @@ -758,10 +791,11 @@ TEST(TransformationTests, ConvertPrecision_Variables) { f = std::make_shared(NodeVector{mul}, ParameterVector{inp}); pass::Manager manager; + manager.register_pass(); manager.register_pass(precisions_map{{element::f16, element::f32}}); manager.run_passes(f); } - + ASSERT_NO_THROW(check_rt_info(f)); ASSERT_FALSE(has_type(f)); } @@ -789,12 +823,13 @@ TEST(TransformationTests, ConvertPrecision_skip_precision_sensitive) { pass::Manager manager; type_to_fuse_map empty_type_to_fuse_map = {}; bool keep_precision_sensitive_in_fp32 = true; + manager.register_pass(); manager.register_pass(precisions_map{{element::f32, element::f16}}, empty_type_to_fuse_map, keep_precision_sensitive_in_fp32); manager.run_passes(model); } - + ASSERT_NO_THROW(check_rt_info(model)); ASSERT_TRUE(has_type(model)); ASSERT_TRUE(interpolate->input_value(2).get_element_type() == element::Type_t::f32); } @@ -823,12 +858,13 @@ TEST(TransformationTests, ConvertPrecision_without_keep_precision_sensitive_in_f pass::Manager manager; type_to_fuse_map empty_type_to_fuse_map = {}; bool keep_precision_sensitive_in_fp32 = false; + manager.register_pass(); manager.register_pass(precisions_map{{element::f32, element::f16}}, empty_type_to_fuse_map, keep_precision_sensitive_in_fp32); manager.run_passes(model); } - + ASSERT_NO_THROW(check_rt_info(model)); ASSERT_FALSE(has_type(model)); ASSERT_TRUE(interpolate->input_value(2).get_element_type() == element::Type_t::f16); } @@ -847,6 +883,7 @@ TEST(TransformationTests, ConvertPrecision_check_marking_does_not_leak_in_trivia type_to_fuse_map empty_type_to_fuse_map = {}; bool keep_precision_sensitive_in_fp32 = true; + manager.register_pass(); manager.register_pass(precisions_map{{element::f32, element::f16}}, empty_type_to_fuse_map, keep_precision_sensitive_in_fp32); @@ -863,7 +900,8 @@ TEST(TransformationTests, ConvertPrecision_check_marking_does_not_leak_in_trivia const auto fc = FunctionsComparator::with_default() .enable(FunctionsComparator::PRECISIONS) - .enable(FunctionsComparator::CONST_VALUES); + .enable(FunctionsComparator::CONST_VALUES) + .enable(FunctionsComparator::CmpValues::RUNTIME_KEYS); const auto res = fc.compare(model, model_ref); ASSERT_TRUE(res.valid) << res.message; } @@ -888,6 +926,7 @@ TEST(TransformationTests, ConvertPrecision_whole_shape_subgraph_is_marked_1) { type_to_fuse_map empty_type_to_fuse_map = {}; bool keep_precision_sensitive_in_fp32 = true; + manager.register_pass(); manager.register_pass(precisions_map{{element::f32, element::f16}}, empty_type_to_fuse_map, keep_precision_sensitive_in_fp32); @@ -909,7 +948,8 @@ TEST(TransformationTests, ConvertPrecision_whole_shape_subgraph_is_marked_1) { const auto fc = FunctionsComparator::with_default() .enable(FunctionsComparator::PRECISIONS) - .enable(FunctionsComparator::CONST_VALUES); + .enable(FunctionsComparator::CONST_VALUES) + .enable(FunctionsComparator::CmpValues::RUNTIME_KEYS); const auto res = fc.compare(model, model_ref); ASSERT_TRUE(res.valid) << res.message; } @@ -943,6 +983,7 @@ TEST(TransformationTests, ConvertPrecision_whole_shape_subgraph_is_marked_2) { type_to_fuse_map empty_type_to_fuse_map = {}; bool keep_precision_sensitive_in_fp32 = true; + manager.register_pass(); manager.register_pass(precisions_map{{element::f32, element::f16}}, empty_type_to_fuse_map, keep_precision_sensitive_in_fp32); @@ -973,7 +1014,8 @@ TEST(TransformationTests, ConvertPrecision_whole_shape_subgraph_is_marked_2) { const auto fc = FunctionsComparator::with_default() .enable(FunctionsComparator::PRECISIONS) - .enable(FunctionsComparator::CONST_VALUES); + .enable(FunctionsComparator::CONST_VALUES) + .enable(FunctionsComparator::CmpValues::RUNTIME_KEYS); const auto res = fc.compare(model, model_ref); ASSERT_TRUE(res.valid) << res.message; } @@ -1024,6 +1066,7 @@ TEST(TransformationTests, ConvertPrecision_whole_shape_subgraph_is_marked_3) { type_to_fuse_map empty_type_to_fuse_map = {}; bool keep_precision_sensitive_in_fp32 = true; + manager.register_pass(); manager.register_pass(precisions_map{{element::f32, element::f16}}, empty_type_to_fuse_map, keep_precision_sensitive_in_fp32); @@ -1071,7 +1114,8 @@ TEST(TransformationTests, ConvertPrecision_whole_shape_subgraph_is_marked_3) { const auto fc = FunctionsComparator::with_default() .enable(FunctionsComparator::PRECISIONS) - .enable(FunctionsComparator::CONST_VALUES); + .enable(FunctionsComparator::CONST_VALUES) + .enable(FunctionsComparator::CmpValues::RUNTIME_KEYS); const auto res = fc.compare(model, model_ref); ASSERT_TRUE(res.valid) << res.message; } @@ -1102,12 +1146,13 @@ TEST(TransformationTests, ConvertCompressedToMixedPrecission_do_not_keep_in_fp32 pass::Manager manager; type_to_fuse_map empty_type_to_fuse_map = {}; bool keep_precision_sensitive_in_fp32 = false; // didn't keep in FP32 intentionally + manager.register_pass(); manager.register_pass(precisions_map{{element::f32, element::f16}}, empty_type_to_fuse_map, keep_precision_sensitive_in_fp32); manager.run_passes(model); } - + ASSERT_NO_THROW(check_rt_info(model)); ASSERT_FALSE(has_type(model)); ASSERT_TRUE(interpolate->input_value(2).get_element_type() == element::Type_t::f16); ASSERT_TRUE(interpolate->output(0).get_partial_shape() == PartialShape({1, 3, 287, 511})); @@ -1143,7 +1188,7 @@ void constant_convert_test(element::Type type_from, } ASSERT_TRUE(actual.size() >= expected.size()); for (size_t i = 0; i < expected.size(); i++) { - ASSERT_EQ(expected[i], actual[i]); + EXPECT_EQ(expected[i], actual[i]) << "Elements with index " << i << " are not equal."; } } @@ -1333,7 +1378,7 @@ TEST(TransformationTests, ConvertPrecision_ConstantConversion_U1ToU4) { constant_convert_test(element::u1, element::u4, std::vector{171}, - {1, 0, 1, 0, 1, 0, 1, 1}); + {0, 1, 0, 1, 0, 1, 1, 1}); } TEST(TransformationTests, ConvertPrecision_keep_precission_sensitive_fp32_with_exp) { diff --git a/src/common/transformations/tests/utils/primitives_priority_test.cpp b/src/common/transformations/tests/utils/primitives_priority_test.cpp index a748477e2b9137..64f6330a1da188 100644 --- a/src/common/transformations/tests/utils/primitives_priority_test.cpp +++ b/src/common/transformations/tests/utils/primitives_priority_test.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include #include @@ -22,8 +21,6 @@ using namespace ov; using namespace testing; -using namespace InferenceEngine; -using namespace InferenceEngine::details; TEST(TransformationTests, ConvBiasFusion) { std::shared_ptr f(nullptr); @@ -46,12 +43,7 @@ TEST(TransformationTests, ConvBiasFusion) { std::unordered_map pp; - InferenceEngine::CNNNetwork network(f); - - // Set PrimitivesPriority to all Convolutions - auto model = network.getFunction(); - ASSERT_NE(nullptr, model); - for (auto& op : model->get_ops()) { + for (auto& op : f->get_ops()) { if (auto conv = std::dynamic_pointer_cast(op)) { auto& rtInfo = conv->get_rt_info(); rtInfo[ov::PrimitivesPriority::get_type_info_static()] = ov::PrimitivesPriority("test"); @@ -59,8 +51,7 @@ TEST(TransformationTests, ConvBiasFusion) { } } - auto clonedNetwork = InferenceEngine::details::cloneNetwork(network); - auto funcs = clonedNetwork.getFunction(); + auto funcs = f->clone(); for (auto& op : funcs->get_ops()) { if (auto conv = std::dynamic_pointer_cast(op)) { diff --git a/src/common/util/CMakeLists.txt b/src/common/util/CMakeLists.txt index faaab5c26d22bc..49f9d1e19cf163 100644 --- a/src/common/util/CMakeLists.txt +++ b/src/common/util/CMakeLists.txt @@ -4,11 +4,11 @@ set(TARGET_NAME openvino_util) -file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) -file(GLOB_RECURSE PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp) - set(UTIL_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include/) +file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) +file(GLOB_RECURSE PUBLIC_HEADERS ${UTIL_INCLUDE_DIR}/*.hpp) + if (WIN32) # Remove linux specific files file(GLOB_RECURSE LIN_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/os/lin/*.cpp @@ -41,13 +41,15 @@ target_link_libraries(${TARGET_NAME} PRIVATE ${CMAKE_DL_LIBS}) if (WIN32) target_link_libraries(${TARGET_NAME} PRIVATE Shlwapi) endif() -target_include_directories(${TARGET_NAME} PUBLIC - $) - -ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE}) +target_include_directories(${TARGET_NAME} PUBLIC $) ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}) ov_ncc_naming_style(FOR_TARGET ${TARGET_NAME} SOURCE_DIRECTORIES ${UTIL_INCLUDE_DIR}) -openvino_developer_export_targets(COMPONENT core TARGETS ${TARGET_NAME}) +# install & export + +ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE}) + +ov_developer_package_export_targets(TARGET ${TARGET_NAME} + INSTALL_INCLUDE_DIRECTORIES "${UTIL_INCLUDE_DIR}/") diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 869b9a02c49272..d389c1862703bf 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -36,25 +36,29 @@ source_group("src" FILES ${LIBRARY_SRC}) source_group("include" FILES ${PUBLIC_HEADERS}) # -# Create ov_core_dev library +# Create openvino_core_dev library # -add_library(ov_core_dev INTERFACE) -add_library(openvino::core::dev ALIAS ov_core_dev) +add_library(openvino_core_dev INTERFACE) +add_library(openvino::core::dev ALIAS openvino_core_dev) -target_include_directories(ov_core_dev INTERFACE +target_include_directories(openvino_core_dev INTERFACE $ $ $ $) -target_link_libraries(ov_core_dev INTERFACE openvino::itt openvino::util) +target_link_libraries(openvino_core_dev INTERFACE openvino::itt openvino::util) -set_target_properties(ov_core_dev PROPERTIES EXPORT_NAME core::dev) -openvino_developer_export_targets(COMPONENT core TARGETS openvino::core::dev) +set_target_properties(openvino_core_dev PROPERTIES EXPORT_NAME core::dev) +ov_developer_package_export_targets(TARGET openvino::core::dev + INSTALL_INCLUDE_DIRECTORIES + "${OV_CORE_DEV_API_PATH}/" + "${OpenVINO_SOURCE_DIR}/src/common/transformations/include/" + "${OpenVINO_SOURCE_DIR}/src/common/low_precision_transformations/include/") # Install interface libraries for case BUILD_SHARED_LIBS=OFF -ov_install_static_lib(ov_core_dev ${OV_CPACK_COMP_CORE}) +ov_install_static_lib(openvino_core_dev ${OV_CPACK_COMP_CORE}) # Fix error LNK1248: image size (...) exceeds maximum allowable size (FFFFFFFF) # the symbolic debugging information will be stored in a separate .pdb file. diff --git a/src/core/builder/CMakeLists.txt b/src/core/builder/CMakeLists.txt index 64ce45a4870921..ee87ece0365d60 100644 --- a/src/core/builder/CMakeLists.txt +++ b/src/core/builder/CMakeLists.txt @@ -4,11 +4,11 @@ set(TARGET_NAME "openvino_builders") -file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) -file(GLOB_RECURSE PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp) - set(BUILDER_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include/) +file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) +file(GLOB_RECURSE PUBLIC_HEADERS ${BUILDER_INCLUDE_DIR}/*.hpp) + # Create named folders for the sources within the .vcproj # Empty name lists them directly under the .vcproj @@ -35,8 +35,9 @@ endif() ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}) -ov_install_static_lib(openvino_builders ${OV_CPACK_COMP_CORE}) +# install & export -# developer package +ov_install_static_lib(openvino_builders ${OV_CPACK_COMP_CORE}) -openvino_developer_export_targets(COMPONENT core TARGETS openvino::builders) +ov_developer_package_export_targets(TARGET openvino::builders + INSTALL_INCLUDE_DIRECTORIES "${BUILDER_INCLUDE_DIR}/") diff --git a/src/core/dev_api/openvino/runtime/aligned_buffer.hpp b/src/core/dev_api/openvino/runtime/aligned_buffer.hpp new file mode 100644 index 00000000000000..7611744f7c4e58 --- /dev/null +++ b/src/core/dev_api/openvino/runtime/aligned_buffer.hpp @@ -0,0 +1,75 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include + +#include "openvino/core/attribute_adapter.hpp" +#include "openvino/core/core_visibility.hpp" + +namespace ov { +/// \brief Allocates a block of memory on the specified alignment. The actual size of the +/// allocated memory is larger than the requested size by the alignment, so allocating 1 +/// byte +/// on 64 byte alignment will allocate 65 bytes. +class OPENVINO_API AlignedBuffer { +public: + // Allocator objects and the allocation interfaces are owned by the + // creators of AlignedBuffers. They need to ensure that the lifetime of + // allocator exceeds the lifetime of this AlignedBuffer. + AlignedBuffer(size_t byte_size, size_t alignment = 64); + + AlignedBuffer(); + virtual ~AlignedBuffer(); + + AlignedBuffer(AlignedBuffer&& other); + AlignedBuffer& operator=(AlignedBuffer&& other); + + size_t size() const { + return m_byte_size; + } + void* get_ptr(size_t offset) const { + return m_aligned_buffer + offset; + } + void* get_ptr() { + return m_aligned_buffer; + } + const void* get_ptr() const { + return m_aligned_buffer; + } + template + T* get_ptr() { + return reinterpret_cast(m_aligned_buffer); + } + template + const T* get_ptr() const { + return reinterpret_cast(m_aligned_buffer); + } + + template + explicit operator T*() { + return get_ptr(); + } + +private: + AlignedBuffer(const AlignedBuffer&) = delete; + AlignedBuffer& operator=(const AlignedBuffer&) = delete; + +protected: + char* m_allocated_buffer; + char* m_aligned_buffer; + size_t m_byte_size; +}; + +template <> +class OPENVINO_API AttributeAdapter> + : public DirectValueAccessor> { +public: + AttributeAdapter(std::shared_ptr& value); + + OPENVINO_RTTI("AttributeAdapter"); +}; + +} // namespace ov diff --git a/src/core/dev_api/openvino/runtime/shared_buffer.hpp b/src/core/dev_api/openvino/runtime/shared_buffer.hpp new file mode 100644 index 00000000000000..1b51bfa07b7ee3 --- /dev/null +++ b/src/core/dev_api/openvino/runtime/shared_buffer.hpp @@ -0,0 +1,31 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/runtime/aligned_buffer.hpp" + +namespace ov { + +/// \brief SharedBuffer class to store pointer to pre-acclocated buffer. +template +class SharedBuffer : public ov::AlignedBuffer { +public: + SharedBuffer(char* data, size_t size, const T& shared_object) : _shared_object(shared_object) { + m_allocated_buffer = data; + m_aligned_buffer = data; + m_byte_size = size; + } + + virtual ~SharedBuffer() { + m_aligned_buffer = nullptr; + m_allocated_buffer = nullptr; + m_byte_size = 0; + } + +private: + T _shared_object; +}; + +} // namespace ov diff --git a/src/core/dev_api/validation_util.hpp b/src/core/dev_api/validation_util.hpp index c214b404798a9c..e93fefd1411eb9 100644 --- a/src/core/dev_api/validation_util.hpp +++ b/src/core/dev_api/validation_util.hpp @@ -78,5 +78,10 @@ bool try_apply_auto_padding(const PartialShape& image_shape, CoordinateDiff& padding_above, CoordinateDiff& padding_below); +/// @brief Get the tensors shapes as ov::PartialShape. +/// +/// @param tensors Input tensors vector to get their shapes. +/// @return Vector of partial shapes same size as input tensor vector. +OPENVINO_API std::vector get_tensors_partial_shapes(const TensorVector& tensors); } // namespace util } // namespace ov diff --git a/src/core/include/ngraph/op/util/op_annotations.hpp b/src/core/include/ngraph/op/util/op_annotations.hpp index dad2aa3b43431a..dec2879f9c837f 100644 --- a/src/core/include/ngraph/op/util/op_annotations.hpp +++ b/src/core/include/ngraph/op/util/op_annotations.hpp @@ -30,7 +30,6 @@ struct NGRAPH_API_DEPRECATED oi_pair { }; /// \brief Base class for annotations added to graph ops - class NGRAPH_API_DEPRECATED NGRAPH_API OpAnnotations { NGRAPH_SUPPRESS_DEPRECATED_START public: diff --git a/src/core/include/ngraph/op/util/slice_plan.hpp b/src/core/include/ngraph/op/util/slice_plan.hpp index a0f99cccaed30c..e47e4ecd80e4f0 100644 --- a/src/core/include/ngraph/op/util/slice_plan.hpp +++ b/src/core/include/ngraph/op/util/slice_plan.hpp @@ -38,6 +38,7 @@ namespace ngraph { // // A SlicePlan is used to collect parameters for these ops. // +// This class is moved to dev API struct NGRAPH_API_DEPRECATED NGRAPH_API SlicePlan { // Parameters for the Slice std::vector begins; diff --git a/src/core/include/ngraph/opsets/opset.hpp b/src/core/include/ngraph/opsets/opset.hpp index 443de5714e4243..3f65437c6d3801 100644 --- a/src/core/include/ngraph/opsets/opset.hpp +++ b/src/core/include/ngraph/opsets/opset.hpp @@ -31,9 +31,7 @@ namespace ngraph { class NGRAPH_API OpSet : public ov::OpSet { public: explicit OpSet(const ov::OpSet& opset); - NGRAPH_SUPPRESS_DEPRECATED_START OpSet(const ngraph::OpSet& opset); - NGRAPH_SUPPRESS_DEPRECATED_END OpSet() = default; /// \brief Insert an op into the opset with a particular name and factory void insert(const std::string& name, const NodeTypeInfo& type_info, FactoryRegistry::Factory factory) { @@ -56,17 +54,20 @@ class NGRAPH_API OpSet : public ov::OpSet { } }; -const NGRAPH_API OpSet& get_opset1(); -const NGRAPH_API OpSet& get_opset2(); -const NGRAPH_API OpSet& get_opset3(); -const NGRAPH_API OpSet& get_opset4(); -const NGRAPH_API OpSet& get_opset5(); -const NGRAPH_API OpSet& get_opset6(); -const NGRAPH_API OpSet& get_opset7(); -const NGRAPH_API OpSet& get_opset8(); -const NGRAPH_API OpSet& get_opset9(); -const NGRAPH_API OpSet& get_opset10(); -const NGRAPH_API OpSet& get_opset11(); -const NGRAPH_API std::map>& get_available_opsets(); +NGRAPH_API_DEPRECATED const NGRAPH_API OpSet& get_opset1(); +NGRAPH_API_DEPRECATED const NGRAPH_API OpSet& get_opset2(); +NGRAPH_API_DEPRECATED const NGRAPH_API OpSet& get_opset3(); +NGRAPH_API_DEPRECATED const NGRAPH_API OpSet& get_opset4(); +NGRAPH_API_DEPRECATED const NGRAPH_API OpSet& get_opset5(); +NGRAPH_API_DEPRECATED const NGRAPH_API OpSet& get_opset6(); +NGRAPH_API_DEPRECATED const NGRAPH_API OpSet& get_opset7(); +NGRAPH_API_DEPRECATED const NGRAPH_API OpSet& get_opset8(); +NGRAPH_API_DEPRECATED const NGRAPH_API OpSet& get_opset9(); +NGRAPH_API_DEPRECATED const NGRAPH_API OpSet& get_opset10(); +NGRAPH_API_DEPRECATED const NGRAPH_API OpSet& get_opset11(); +NGRAPH_API_DEPRECATED const NGRAPH_API OpSet& get_opset12(); +NGRAPH_API_DEPRECATED const NGRAPH_API OpSet& get_opset13(); +NGRAPH_API_DEPRECATED const NGRAPH_API std::map>& +get_available_opsets(); } // namespace ngraph NGRAPH_SUPPRESS_DEPRECATED_END diff --git a/src/core/include/openvino/core/node.hpp b/src/core/include/openvino/core/node.hpp index 860290617709a7..ac1c61ce0f18d3 100644 --- a/src/core/include/openvino/core/node.hpp +++ b/src/core/include/openvino/core/node.hpp @@ -554,21 +554,17 @@ OPENVINO_API void NodeValidationFailure::create(const CheckLocInfo& check_loc_in NODE_VALIDATION_CHECK(std::make_pair(static_cast((node)), &(input_shapes)), __VA_ARGS__) namespace ov { -template -void check_new_args_count(const Node* node, T new_args) { - NODE_VALIDATION_CHECK(node, - new_args.size() == node->input_values().size(), - "clone_with_new_inputs() expected ", - node->input_values().size(), - " argument", - (node->input_values().size() == 1 ? "" : "s"), - " but got ", - new_args.size()); -} -} // namespace ov +/** + * @brief Check new arguments size if match node inputs count. + * + * This check is required in cloning ov::Node. + * + * @param node Pointer to node. + * @param new_args Vector with new outputs to check. + */ +void OPENVINO_API check_new_args_count(const Node* const node, const OutputVector& new_args); -namespace ov { /// \brief Visits a reference to a node that has been registered with the visitor. template <> class OPENVINO_API AttributeAdapter> : public VisitorAdapter { diff --git a/src/core/include/openvino/core/shape.hpp b/src/core/include/openvino/core/shape.hpp index 392bd9c48bd9d5..a04a864a8394fb 100644 --- a/src/core/include/openvino/core/shape.hpp +++ b/src/core/include/openvino/core/shape.hpp @@ -42,19 +42,6 @@ class Shape : public std::vector { OPENVINO_API std::string to_string() const; }; -/** - * @brief Number of elements in spanned by a shape - * @ingroup ov_model_cpp_api - */ -template -size_t shape_size(const SHAPE_TYPE& shape) { - size_t size = 1; - for (auto d : shape) { - size *= d; - } - return size; -} - /** * Number of elements in a subset of dimensions of a shape. * Returns a product of dimensions in a range [start_dim;end_dim) @@ -72,6 +59,15 @@ size_t shape_size(ForwardIt start_dim, const ForwardIt end_dim) { std::multiplies::value_type>()); } +/** + * @brief Number of elements in spanned by a shape + * @ingroup ov_model_cpp_api + */ +template +size_t shape_size(const SHAPE_TYPE& shape) { + return shape_size(shape.begin(), shape.end()); +} + /// Row-major strides for a shape template std::vector row_major_strides(const SHAPE_TYPE& shape) { diff --git a/src/core/include/openvino/op/batch_to_space.hpp b/src/core/include/openvino/op/batch_to_space.hpp index 6609e539087628..2dbbf018913fd3 100644 --- a/src/core/include/openvino/op/batch_to_space.hpp +++ b/src/core/include/openvino/op/batch_to_space.hpp @@ -37,9 +37,7 @@ class OPENVINO_API BatchToSpace : public Op { const Output& block_shape, const Output& crops_begin, const Output& crops_end); - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; - OPENVINO_SUPPRESS_DEPRECATED_END + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool has_evaluate() const override; void validate_and_infer_types() override; diff --git a/src/core/include/openvino/op/constant.hpp b/src/core/include/openvino/op/constant.hpp index 14ee7b3313490e..100ed2f7e18d6f 100644 --- a/src/core/include/openvino/op/constant.hpp +++ b/src/core/include/openvino/op/constant.hpp @@ -12,7 +12,6 @@ # define WAS_OV_LIBRARY_DEFINED_CONSTANT #endif -#include "ngraph/runtime/aligned_buffer.hpp" #include "ngraph/runtime/host_tensor.hpp" #include "ngraph/runtime/shared_buffer.hpp" @@ -21,11 +20,14 @@ # undef WAS_OV_LIBRARY_DEFINED_CONSTANT #endif #include "openvino/core/coordinate_diff.hpp" -#include "openvino/core/node.hpp" #include "openvino/core/type/element_type.hpp" #include "openvino/core/type/element_type_traits.hpp" +#include "openvino/op/op.hpp" namespace ov { + +class AlignedBuffer; + namespace op { namespace v0 { /// \brief Class for constants. @@ -177,13 +179,20 @@ class OPENVINO_API Constant : public Op { /// \param shape The shape of the tensor constant. /// \param data A pointer to pre-allocated shared data. template + OPENVINO_DEPRECATED("This constructor is deprecated and will be removed in 2024.0 release") Constant(const element::Type& type, const Shape& shape, std::shared_ptr> data) : m_element_type(type), m_shape(shape) { - m_data = data; + m_data = legacy_to_ov_aligned_buffer(data); constructor_validate_and_infer_types(); } OPENVINO_SUPPRESS_DEPRECATED_END + Constant(const element::Type& type, const Shape& shape, const std::shared_ptr& data) + : m_element_type(type), + m_shape(shape) { + m_data = data; + constructor_validate_and_infer_types(); + } Constant(const Constant& other); Constant(const Constant& other, const Shape& new_shape); @@ -241,11 +250,7 @@ class OPENVINO_API Constant : public Op { AxisSet get_axis_set_val() const; /// \brief Return data size in bytes - size_t get_byte_size() const { - OPENVINO_SUPPRESS_DEPRECATED_START - return m_data->size(); - OPENVINO_SUPPRESS_DEPRECATED_END - } + size_t get_byte_size() const; /// \brief Wrapper around constructing a shared_ptr of a Constant /// @@ -370,11 +375,8 @@ class OPENVINO_API Constant : public Op { return rc; } - const void* get_data_ptr() const { - OPENVINO_SUPPRESS_DEPRECATED_START - return (m_data ? m_data->get_ptr() : nullptr); - OPENVINO_SUPPRESS_DEPRECATED_END - } + const void* get_data_ptr() const; + template const T* get_data_ptr() const { OPENVINO_ASSERT(sizeof(T) <= m_element_type.size() || shape_size(m_shape) <= 0, "Buffer over-read"); @@ -406,6 +408,11 @@ class OPENVINO_API Constant : public Op { private: Constant(bool memset_allocation, const element::Type& type, const Shape& shape); + OPENVINO_SUPPRESS_DEPRECATED_START + std::shared_ptr legacy_to_ov_aligned_buffer( + const std::shared_ptr& buffer); + OPENVINO_SUPPRESS_DEPRECATED_END + template , typename std::enable_if, typename std::enable_if::type = true> StorageDataType get_element_value(size_t index) const { - return (get_data_ptr()[index / 2] >> (index % 2 ? 0 : 4)) & 0x0F; + return (get_data_ptr()[index / 2] >> (index % 2 ? 4 : 0)) & 0x0F; } template , typename std::enable_if::type = true> StorageDataType get_element_value(size_t index) const { - const uint8_t i4data = (get_data_ptr()[index / 2] >> (index % 2 ? 0 : 4)) & 0x0F; + const uint8_t i4data = (get_data_ptr()[index / 2] >> (index % 2 ? 4 : 0)) & 0x0F; const bool is_negative_number = (i4data >> 3) & 0x01; const int8_t data = is_negative_number ? i4data | 0xF0 : i4data; return data; @@ -485,9 +492,19 @@ class OPENVINO_API Constant : public Op { if (!std::is_same::value) { OPENVINO_ASSERT( !std::numeric_limits::is_signed || std::numeric_limits::lowest() <= c, - "Cannot cast vector from constant. Some values are outside the range."); + "Cannot cast vector from ", + Type, + " constant to ", + element::from(), + ". Some values are outside the range. Example: ", + c); OPENVINO_ASSERT(std::numeric_limits::max() >= c, - "Cannot cast vector from constant. Some values are outside the range."); + "Cannot cast vector from ", + Type, + " constant to ", + element::from(), + ". Some values are outside the range. Example: ", + c); } #if defined(__clang__) # pragma clang diagnostic pop @@ -530,7 +547,7 @@ class OPENVINO_API Constant : public Op { const auto round_element_no = element_number % 2 ? element_number + 1 : element_number; output.reserve(round_element_no); // adds 1 more elements here? std::for_each(source_begin, source_end, [&](IN_T c) { - for (const auto i : {4, 0}) { + for (const auto i : {0, 4}) { const uint8_t data = (c >> i) & 0x0F; output.push_back(data); } @@ -548,7 +565,7 @@ class OPENVINO_API Constant : public Op { const auto round_element_no = element_number % 2 ? element_number + 1 : element_number; output.reserve(round_element_no); // adds 1 more elements here? std::for_each(source_begin, source_end, [&](IN_T c) { - for (const auto i : {4, 0}) { + for (const auto i : {0, 4}) { const uint8_t i4data = (c >> i) & 0x0F; const bool is_negative_number = (i4data >> 3) & 0x01; const int8_t data = is_negative_number ? i4data | 0xF0 : i4data; @@ -627,11 +644,7 @@ class OPENVINO_API Constant : public Op { void allocate_buffer(bool memset_allocation); - void* get_data_ptr_nc() { - OPENVINO_SUPPRESS_DEPRECATED_START - return (m_data ? m_data->get_ptr() : nullptr); - OPENVINO_SUPPRESS_DEPRECATED_END - } + void* get_data_ptr_nc(); template typename element_type_traits::value_type* get_data_ptr_nc() { @@ -663,27 +676,9 @@ class OPENVINO_API Constant : public Op { template , - typename std::enable_if::type = true> - void write_buffer(const std::vector& source) { - auto p = get_data_ptr_nc(); - size_t i = 0; - for (; i < source.size() / 2; i++) { - const auto v1 = value_in_range(source[i * 2]) & 0x0F; - const auto v2 = value_in_range(source[i * 2 + 1]) & 0x0F; - const auto v = (v1 << 4) | v2; - p[i] = static_cast(v); - } - if (source.size() % 2) { - const auto v1 = value_in_range(source[i * 2]) & 0x0F; - const auto v = v1 << 4; - p[i] = static_cast(v); - } - } - - template , - typename std::enable_if::value, bool>::type = true> + typename std::enable_if::value), + bool>::type = true> void write_buffer(const std::vector& source) { auto p = get_data_ptr_nc(); size_t i = 0; @@ -861,9 +856,7 @@ class OPENVINO_API Constant : public Op { element::Type m_element_type; Shape m_shape{}; - OPENVINO_SUPPRESS_DEPRECATED_START - std::shared_ptr m_data; - OPENVINO_SUPPRESS_DEPRECATED_END + std::shared_ptr m_data; mutable std::atomic_bool m_all_elements_bitwise_identical{false}; mutable std::atomic_bool m_all_elements_bitwise_identical_checked{false}; bool m_alloc_buffer_on_visit_attributes = true; diff --git a/src/core/include/openvino/op/eye.hpp b/src/core/include/openvino/op/eye.hpp index feaebafca82264..1096e488aa13eb 100644 --- a/src/core/include/openvino/op/eye.hpp +++ b/src/core/include/openvino/op/eye.hpp @@ -55,9 +55,7 @@ class OPENVINO_API Eye : public Op { m_output_type = output_type; } - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; - OPENVINO_SUPPRESS_DEPRECATED_END + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool has_evaluate() const override; protected: diff --git a/src/core/include/openvino/op/logical_and.hpp b/src/core/include/openvino/op/logical_and.hpp index 6d55f8f3585e0f..382679d16b78e1 100644 --- a/src/core/include/openvino/op/logical_and.hpp +++ b/src/core/include/openvino/op/logical_and.hpp @@ -35,10 +35,7 @@ class OPENVINO_API LogicalAnd : public util::BinaryElementwiseLogical { const AutoBroadcastSpec& auto_broadcast = AutoBroadcastSpec(AutoBroadcastType::NUMPY)); std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - bool visit_attributes(AttributeVisitor& visitor) override; - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; - OPENVINO_SUPPRESS_DEPRECATED_END + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool has_evaluate() const override; }; } // namespace v1 diff --git a/src/core/include/openvino/op/logical_not.hpp b/src/core/include/openvino/op/logical_not.hpp index c5421b8db14a47..052aed0a09ad24 100644 --- a/src/core/include/openvino/op/logical_not.hpp +++ b/src/core/include/openvino/op/logical_not.hpp @@ -24,9 +24,7 @@ class OPENVINO_API LogicalNot : public Op { void validate_and_infer_types() override; std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; - OPENVINO_SUPPRESS_DEPRECATED_END + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool has_evaluate() const override; }; } // namespace v1 diff --git a/src/core/include/openvino/op/logical_or.hpp b/src/core/include/openvino/op/logical_or.hpp index 15c00eea04baf3..1dab36217b175a 100644 --- a/src/core/include/openvino/op/logical_or.hpp +++ b/src/core/include/openvino/op/logical_or.hpp @@ -34,9 +34,7 @@ class OPENVINO_API LogicalOr : public util::BinaryElementwiseLogical { std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; - OPENVINO_SUPPRESS_DEPRECATED_END + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool has_evaluate() const override; }; } // namespace v1 diff --git a/src/core/include/openvino/op/max_pool.hpp b/src/core/include/openvino/op/max_pool.hpp index c1741eef6cb717..534f8b1d067397 100644 --- a/src/core/include/openvino/op/max_pool.hpp +++ b/src/core/include/openvino/op/max_pool.hpp @@ -43,13 +43,8 @@ class OPENVINO_API MaxPool : public op::util::MaxPoolBase { std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; - OPENVINO_SUPPRESS_DEPRECATED_END + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool has_evaluate() const override; - -private: - bool evaluate_maxpool(const HostTensorVector& outputs, const HostTensorVector& inputs) const; }; } // namespace v1 @@ -119,10 +114,8 @@ class OPENVINO_API MaxPool : public op::util::MaxPoolBase { m_axis = axis; } + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool has_evaluate() const override; - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector&, const HostTensorVector&) const override; - OPENVINO_SUPPRESS_DEPRECATED_END private: Strides m_dilations; diff --git a/src/core/include/openvino/op/split.hpp b/src/core/include/openvino/op/split.hpp index 918457c0d84a05..6137f0591cfba1 100644 --- a/src/core/include/openvino/op/split.hpp +++ b/src/core/include/openvino/op/split.hpp @@ -39,9 +39,8 @@ class OPENVINO_API Split : public Op { void set_num_splits(const size_t num_splits) { m_num_splits = num_splits; } - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; - OPENVINO_SUPPRESS_DEPRECATED_END + + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool evaluate_lower(TensorVector& outputs) const override; bool evaluate_upper(TensorVector& outputs) const override; bool has_evaluate() const override; diff --git a/src/core/include/openvino/op/squeeze.hpp b/src/core/include/openvino/op/squeeze.hpp index 28f098be406bf7..e66cfb3d27667a 100644 --- a/src/core/include/openvino/op/squeeze.hpp +++ b/src/core/include/openvino/op/squeeze.hpp @@ -20,11 +20,8 @@ class OPENVINO_API Squeeze : public Op { Squeeze(const Output& data, const Output& axes); Squeeze(const Output& data); - bool visit_attributes(AttributeVisitor& visitor) override; void validate_and_infer_types() override; - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; - OPENVINO_SUPPRESS_DEPRECATED_END + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool has_evaluate() const override; bool evaluate_lower(TensorVector& outputs) const override; bool evaluate_upper(TensorVector& outputs) const override; diff --git a/src/core/include/openvino/op/tile.hpp b/src/core/include/openvino/op/tile.hpp index d7459477dac75a..9cb72cc5adf2ef 100644 --- a/src/core/include/openvino/op/tile.hpp +++ b/src/core/include/openvino/op/tile.hpp @@ -23,7 +23,6 @@ class OPENVINO_API Tile : public Op { /// \param repeats The node producing the per-dimension replication factor Tile(const Output& data, const Output& repeats); - 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; @@ -31,7 +30,7 @@ class OPENVINO_API Tile : public Op { bool evaluate_lower(TensorVector& outputs) const override; bool evaluate_upper(TensorVector& outputs) const override; bool has_evaluate() const override; - bool evaluate(ov::TensorVector& output_values, const ov::TensorVector& input_values) const override; + bool evaluate(ov::TensorVector& outputs, const ov::TensorVector& inputs) const override; bool evaluate_label(TensorLabelVector& output_labels) const override; }; } // namespace v0 diff --git a/src/core/include/openvino/op/topk.hpp b/src/core/include/openvino/op/topk.hpp index 9c2ec7a9ce1492..cfc6ccd6cc5462 100644 --- a/src/core/include/openvino/op/topk.hpp +++ b/src/core/include/openvino/op/topk.hpp @@ -36,7 +36,7 @@ class OPENVINO_API TopK : public util::TopKBase { /// the biggest element of two. /// \param sort Specifies order of output elements and/or indices /// Accepted values: none, index, value - /// \param index_element_type Specyfies type of produced indices + /// \param index_element_type Specifies type of produced indices TopK(const Output& data, const Output& k, const int64_t axis, @@ -53,9 +53,7 @@ class OPENVINO_API TopK : public util::TopKBase { std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; - OPENVINO_SUPPRESS_DEPRECATED_END + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool has_evaluate() const override; protected: @@ -83,7 +81,7 @@ class OPENVINO_API TopK : public util::TopKBase { /// the biggest element of two. /// \param sort Specifies order of output elements and/or indices /// Accepted values: none, index, value - /// \param index_element_type Specyfies type of produced indices + /// \param index_element_type Specifies type of produced indices TopK(const Output& data, const Output& k, const int64_t axis, @@ -99,9 +97,7 @@ class OPENVINO_API TopK : public util::TopKBase { const element::Type& index_element_type = element::i32); std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; - OPENVINO_SUPPRESS_DEPRECATED_END + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool has_evaluate() const override; }; } // namespace v3 @@ -153,9 +149,7 @@ class OPENVINO_API TopK : public util::TopKBase { bool visit_attributes(AttributeVisitor& visitor) override; std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; - OPENVINO_SUPPRESS_DEPRECATED_END + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool has_evaluate() const override; bool get_stable() const { diff --git a/src/core/include/openvino/op/util/framework_node.hpp b/src/core/include/openvino/op/util/framework_node.hpp index 57a6be7a3a34fb..f8a63b38b823e5 100644 --- a/src/core/include/openvino/op/util/framework_node.hpp +++ b/src/core/include/openvino/op/util/framework_node.hpp @@ -81,7 +81,7 @@ class OPENVINO_API FrameworkNode : public MultiSubGraphOp { explicit FrameworkNode(const OutputVector& inputs, size_t output_size = 1, size_t num_subgraphs = 0); - void validate_and_infer_types() override; + virtual void validate_and_infer_types() override; bool visit_attributes(AttributeVisitor& visitor) override; diff --git a/src/core/include/openvino/op/variadic_split.hpp b/src/core/include/openvino/op/variadic_split.hpp index 2d6f751d48d3ba..49cb5dcc714502 100644 --- a/src/core/include/openvino/op/variadic_split.hpp +++ b/src/core/include/openvino/op/variadic_split.hpp @@ -29,25 +29,17 @@ class OPENVINO_API VariadicSplit : public Op { /// outputs. The sum of split_lengths must match data.shape[axis] VariadicSplit(const Output& data, const Output& axis, const Output& split_lengths); - 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_default_output_index() const override { return no_default_index(); } - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; - OPENVINO_SUPPRESS_DEPRECATED_END + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool evaluate_lower(TensorVector& outputs) const override; bool evaluate_upper(TensorVector& outputs) const override; bool has_evaluate() const override; bool evaluate_label(TensorLabelVector& output_labels) const override; - -private: - bool evaluate_variadic_split(const HostTensorVector& outputs, const HostTensorVector& inputs) const; - bool has_axis_and_splits_bound_set() const; }; } // namespace v1 } // namespace op diff --git a/src/core/reference/CMakeLists.txt b/src/core/reference/CMakeLists.txt index 4154a1455ffef0..e868c07c391e96 100644 --- a/src/core/reference/CMakeLists.txt +++ b/src/core/reference/CMakeLists.txt @@ -4,11 +4,11 @@ set(TARGET_NAME "openvino_reference") -file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) -file(GLOB_RECURSE PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp) - set(REF_IMPL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") +file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) +file(GLOB_RECURSE PUBLIC_HEADERS ${REF_IMPL_INCLUDE_DIR}/*.hpp) + # Create named folders for the sources within the .vcproj # Empty name lists them directly under the .vcproj @@ -46,7 +46,9 @@ target_link_libraries(${TARGET_NAME} PRIVATE Threads::Threads openvino::core::de ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}) +# install & export + ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE}) -# developer package -openvino_developer_export_targets(COMPONENT core TARGETS openvino::reference) +ov_developer_package_export_targets(TARGET openvino::reference + INSTALL_INCLUDE_DIRECTORIES "${REF_IMPL_INCLUDE_DIR}/") diff --git a/src/core/reference/include/ngraph/runtime/opt_kernel/reshape.hpp b/src/core/reference/include/ngraph/runtime/opt_kernel/reshape.hpp deleted file mode 100644 index 33f2c5f9465098..00000000000000 --- a/src/core/reference/include/ngraph/runtime/opt_kernel/reshape.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "ngraph/axis_vector.hpp" -#include "ngraph/shape.hpp" - -namespace ngraph { -namespace runtime { -namespace opt_kernel { -void reshape(const char* in, - char* out, - const Shape& in_shape, - const AxisVector& in_axis_order, - const Shape& out_shape, - size_t elem_size); -} -} // namespace runtime -} // namespace ngraph diff --git a/src/core/reference/include/openvino/reference/and.hpp b/src/core/reference/include/openvino/reference/and.hpp index 326e4b59d773af..8f43b045d6398c 100644 --- a/src/core/reference/include/openvino/reference/and.hpp +++ b/src/core/reference/include/openvino/reference/and.hpp @@ -4,31 +4,37 @@ #pragma once -#include +#include +#include #include "openvino/core/shape.hpp" -#include "openvino/op/util/attr_types.hpp" #include "openvino/reference/autobroadcast_binop.hpp" namespace ov { namespace reference { -template +template void logical_and(const T* arg0, const T* arg1, T* out, size_t count) { - for (size_t i = 0; i < count; i++) { - out[i] = static_cast(arg0[i] && arg1[i]); - } + std::transform(arg0, std::next(arg0, count), arg1, out, std::logical_and()); } -template +/** + * @brief Reference implementation of binary elementwise LogicalAnd operator. + * + * @param arg0 Pointer to input 0 data. + * @param arg1 Pointer to input 1 data. + * @param out Pointer to output data. + * @param arg_shape0 Input 0 shape. + * @param arg_shape1 Input 1 shape. + * @param broadcast_spec Broadcast specification mode. + */ +template void logical_and(const T* arg0, const T* arg1, T* out, const Shape& arg0_shape, const Shape& arg1_shape, const op::AutoBroadcastSpec& broadcast_spec) { - autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, [](T x, T y) -> T { - return static_cast(x && y); - }); + autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, std::logical_and()); } } // namespace reference } // namespace ov diff --git a/src/core/reference/include/openvino/reference/convert.hpp b/src/core/reference/include/openvino/reference/convert.hpp index e943e548a8fa4e..bd36b50b03301d 100644 --- a/src/core/reference/include/openvino/reference/convert.hpp +++ b/src/core/reference/include/openvino/reference/convert.hpp @@ -14,7 +14,7 @@ namespace reference { namespace detail { inline void set_u1(uint8_t* buf, size_t idx, uint8_t val) { const size_t byte_idx = idx / 8; - const uint8_t bit_idx = 7 - (idx % 8); + const uint8_t bit_idx = 7 - (idx % 8); // Reversed order of bits if (val) { buf[byte_idx] |= (1 << bit_idx); } else { @@ -24,33 +24,33 @@ inline void set_u1(uint8_t* buf, size_t idx, uint8_t val) { inline uint8_t get_u1(const uint8_t* buf, size_t idx) { const size_t byte_idx = idx / 8; - const uint8_t bit_idx = 7 - (idx % 8); + const uint8_t bit_idx = 7 - (idx % 8); // Reversed order of bits return (buf[byte_idx] & (1 << bit_idx)) ? 1 : 0; } inline void set_u4(uint8_t* buf, size_t idx, uint8_t val) { const size_t byte_idx = idx / 2; - const uint8_t bit_shift = 4 * (++idx % 2); + const uint8_t bit_shift = 4 * (idx % 2); buf[byte_idx] &= ~(0xF << bit_shift); // half byte zeroed buf[byte_idx] |= ((val & 0xF) << bit_shift); // set 1's } inline uint8_t get_u4(const uint8_t* buf, size_t idx) { const size_t byte_idx = idx / 2; - const uint8_t bit_shift = 4 * (++idx % 2); + const uint8_t bit_shift = 4 * (idx % 2); return (buf[byte_idx] >> bit_shift) & 0xF; } inline void set_i4(uint8_t* buf, size_t idx, int8_t val) { const size_t byte_idx = idx / 2; - const uint8_t bit_shift = 4 * (++idx % 2); + const uint8_t bit_shift = 4 * (idx % 2); buf[byte_idx] &= ~(0xF << bit_shift); // half byte zeroed buf[byte_idx] |= ((val & 0xF) << bit_shift); // set 1's } inline int8_t get_i4(const uint8_t* buf, size_t idx) { const size_t byte_idx = idx / 2; - const uint8_t bit_shift = 4 * (++idx % 2); + const uint8_t bit_shift = 4 * (idx % 2); uint8_t val = (buf[byte_idx] >> bit_shift) & 0xF; if (val & 0x08) { // negative number val |= 0xF0; diff --git a/src/core/reference/include/openvino/reference/eye.hpp b/src/core/reference/include/openvino/reference/eye.hpp index 0991637031538f..2cb997c03f0817 100644 --- a/src/core/reference/include/openvino/reference/eye.hpp +++ b/src/core/reference/include/openvino/reference/eye.hpp @@ -7,31 +7,41 @@ #include #include "openvino/core/shape.hpp" -#include "utils/span.hpp" namespace ov { namespace reference { + +/** + * @brief Reference implementation of Eye operator + * + * @param data Pointer to output data. + * @param out_shape Output data size. + * @param diagonal_index Eye diagonal index to populate matrix with ones + */ template void eye(T* data, const Shape& out_shape, const int64_t diagonal_index) { - const int64_t num_matrices = shape_size(span(out_shape).subspan(0, out_shape.size() - 2)); - const int64_t num_rows = out_shape[out_shape.size() - 2]; - const int64_t num_columns = out_shape[out_shape.size() - 1]; + const auto spatial_dims_offset = out_shape.size() - 2; + const int64_t num_columns = out_shape.back(); + const int64_t num_rows = out_shape[spatial_dims_offset]; const int64_t matrix_size = num_rows * num_columns; + const int64_t out_size = shape_size(out_shape); // fill tensor by zero - std::fill(data, data + num_matrices * matrix_size, T(0)); + std::fill(data, std::next(data, out_size), T(0)); // set ones on diagonal - const int64_t shift_by_columns = std::max(diagonal_index, int64_t(0)); - const int64_t count_by_columns = std::max(num_columns - std::abs(diagonal_index), int64_t(0)); - const int64_t count_by_rows = std::max(num_rows - std::abs(diagonal_index), int64_t(0)); + constexpr int64_t zero{0}; + const auto abs_diag_idx = static_cast(std::abs(diagonal_index)); + const int64_t shift_by_columns = std::max(diagonal_index, zero); + const int64_t count_by_columns = std::max(num_columns - abs_diag_idx, zero); + const int64_t count_by_rows = std::max(num_rows - abs_diag_idx, zero); const int64_t count = diagonal_index > 0 ? std::min(count_by_columns, num_rows) : std::min(count_by_rows, num_columns); - for (auto i = 0; i < num_matrices; i++) { - for (auto j = 0; j < count; j++) { + for (auto matrix_offset = zero; matrix_offset < out_size; matrix_offset += matrix_size) { + for (auto j = 0; j < count; ++j) { const int64_t index = (j + shift_by_columns - diagonal_index) * num_columns + j + shift_by_columns; - data[index + i * matrix_size] = static_cast(1); + data[matrix_offset + index] = T{1}; } } } diff --git a/src/core/reference/include/openvino/reference/fake_quantize.hpp b/src/core/reference/include/openvino/reference/fake_quantize.hpp index d0828cd23087d3..2fb30a4a5c492b 100644 --- a/src/core/reference/include/openvino/reference/fake_quantize.hpp +++ b/src/core/reference/include/openvino/reference/fake_quantize.hpp @@ -21,31 +21,86 @@ namespace ov { namespace reference { namespace fake_quantize_details { template -inline T quantize(const T& arg, - const T& in_low, - const T& in_high, - const T& out_low, - const T& out_high, - const size_t& levels) { +static inline T quantize(const T arg, + const T in_low, + const T in_high, + const T out_low, + const T out_high, + const T levels_minus_one) { if (arg <= std::min(in_low, in_high)) { return out_low; } else if (arg > std::max(in_low, in_high)) { return out_high; } - return static_cast(std::nearbyint((arg - in_low) / (in_high - in_low) * (levels - 1)) / (levels - 1) * + return static_cast(std::nearbyint((arg - in_low) / (in_high - in_low) * levels_minus_one) / levels_minus_one * (out_high - out_low) + out_low); } +static std::vector compute_strides(const ov::Shape& out_shape, const ov::Shape& shape); + +static std::tuple get_inner_stride(size_t num_output_elements, + const ov::Shape& output_shape, + const ov::Shape& shape, + size_t current_output_inner_stride); + +template +static void fake_quantize_non_unit_inner_stride(const T* arg, + const T* in_low, + const T* in_high, + const T* out_low, + const T* out_high, + T* out, + const Shape& arg_shape, + T levels_minus_one, + size_t input_inner_stride, + const F& get_outer_strides); + +template +static void fake_quantize_unit_inner_stride(const T* arg, + const T* in_low, + const T* in_high, + const T* out_low, + const T* out_high, + T* out, + const Shape& arg_shape, + T levels_minus_one, + size_t input_inner_stride, + const F& get_outer_strides); + +template +static void fake_quantize_unit_output_intervals_inner_stride(const T* arg, + const T* in_low, + const T* in_high, + const T* out_low, + const T* out_high, + T* out, + const Shape& arg_shape, + T levels_minus_one, + size_t input_inner_stride, + const F& get_outer_strides); + +template +static void fake_quantize_unit_input_intervals_inner_stride(const T* arg, + const T* in_low, + const T* in_high, + const T* out_low, + const T* out_high, + T* out, + const Shape& arg_shape, + T levels_minus_one, + size_t input_inner_stride, + const F& get_outer_strides); + } // namespace fake_quantize_details template -void fake_quantize(const T* const arg, - const T* const in_low, - const T* const in_high, - const T* const out_low, - const T* const out_high, - T* const out, +void fake_quantize(const T* arg, + const T* in_low, + const T* in_high, + const T* out_low, + const T* out_high, + T* out, const Shape& arg_shape, const Shape& in_low_shape, const Shape& in_high_shape, @@ -55,133 +110,452 @@ void fake_quantize(const T* const arg, const op::AutoBroadcastSpec& broadcast) { using namespace fake_quantize_details; + T levels_minus_one = static_cast(levels - 1); + const size_t arg_size = shape_size(arg_shape); + if (shape_size(in_low_shape) == 1 && shape_size(in_high_shape) == 1 && shape_size(out_low_shape) == 1 && shape_size(out_high_shape) == 1) { - const size_t arg_size = shape_size(arg_shape); - const auto q = [=](const T& a) { - return quantize(a, *in_low, *in_high, *out_low, *out_high, levels); - }; for (size_t i = 0; i < arg_size; ++i) { - out[i] = q(arg[i]); - } - } else { - OPENVINO_ASSERT(in_low_shape.size() <= arg_shape.size() && in_high_shape.size() <= arg_shape.size() && - out_low_shape.size() <= arg_shape.size() && out_high_shape.size() <= arg_shape.size(), - "Tensors with input\\output ranges should have rank less or " - "equal to data tensor rank equal to ", - arg_shape.size()); - - Shape arg0_padded_shape = arg_shape; - Shape arg1_padded_shape = in_low_shape; - Shape arg2_padded_shape = in_high_shape; - Shape arg3_padded_shape = out_low_shape; - Shape arg4_padded_shape = out_high_shape; - - size_t max_shape_size = arg_shape.size(); - - while (arg0_padded_shape.size() < max_shape_size) { - arg0_padded_shape.insert(arg0_padded_shape.begin(), 1); + out[i] = quantize(arg[i], *in_low, *in_high, *out_low, *out_high, levels_minus_one); } + return; + } - while (arg1_padded_shape.size() < max_shape_size) { - arg1_padded_shape.insert(arg1_padded_shape.begin(), 1); - } + // clang-format off + /* + * --------------------------------------------------- + * Overview: + * Numpy broadcasted input tensors can be partitioned into two: outer and inner part (which also defines inner + * stride as a product of inner part), so N-dimensional tensors can be processed using two loops. + * + * For example with two inputs [2, 2, 3, 4] and [1, 1, 3, 4] we can have: + * input 1 with shape [2, 2, 3, 4] can be divided into outer part [2, 2] and inner part [3, 4] + * with inner stride = 12 (3 * 4). + * input 2 with shape [1, 1, 3, 4] can be divided into outer part [1, 1] + * and inner part [3, 4] with inner stride = 12 (3 * 4) + * + * Having that, those inputs can be processed by the following: + * + * output_shape = {2, 2, 3, 4}; + * output_inner_stride = 12; + * for (i = 0; i < shape_size(shape); i += output_inner_stride) { + * first_input_stride = i; + * second_input_stride = 0; + * for (j = 0; j < 12; j++) { + * *out++ = f(first_input[first_input_stride + j], second_input[second_input_stride + j]); + * } + * } + * + * --------------------------------------------------- + * How the partitioning is done: + * Partitioning process starts with the last dimension of input tensor shape and it stops when either one of below + * occurs: + * - if the last dimension is equal to 1, partitioning stops at the dimension that is greater than 1 (this + * dimension is not included in the inner part), + * - if the last dimension is greater than 1, partitioning stops at the dimension that is equal to 1 (this + * dimension is not included in the inner part). + * + * Examples: + * tensor_shape=[2, 3, 4, 5], inner_part = [2, 3, 4, 5], inner_stride = 120 + * tensor_shape=[1, 1, 4, 5], inner_part = [4, 5], inner_stride = 20 + * tensor_shape=[2, 3, 1, 1], inner_part = [1, 1], inner_stride = 1 + * + * + * --------------------------------------------------- + * How the output inner stride is calculated: + * Inner part (and inner stride) for every input tensor is determined. Then the size of output inner part is the + * size of inner part with the fewest number of dimensions. + * + * Example with 5 inputs: + * input 1 shape [2, 3, 4, 5], inner_part = [2, 3, 4, 5], inner_stride = 120 + * input 2 shape [1, 3, 4, 5], inner_part = [3, 4, 5], inner_stride = 60 + * input 3 shape [2, 3, 1, 1], inner_part = [1, 1], inner_stride = 1 + * input 4 shape [2, 1, 1, 1], inner_part = [1, 1, 1], inner_stride = 1 + * input 5 shape [1, 1, 1, 1], inner_part = [1, 1, 1, 1], inner_stride = 1 + * + * output shape [2, 3, 4, 5], inner_part = [4, 5], inner_stride = 20 + * + * Inner part with fewest number of elements is [1, 1] for input 3. So the inner part for output shape is [4, 5] + * and output inner stride is 20. + */ + // clang-format on - while (arg2_padded_shape.size() < max_shape_size) { - arg2_padded_shape.insert(arg2_padded_shape.begin(), 1); - } + std::vector output_strides = compute_strides(arg_shape, arg_shape); + std::vector in_low_strides = compute_strides(arg_shape, in_low_shape); + std::vector in_high_strides = compute_strides(arg_shape, in_high_shape); + std::vector out_low_strides = compute_strides(arg_shape, out_low_shape); + std::vector out_high_strides = compute_strides(arg_shape, out_high_shape); - while (arg3_padded_shape.size() < max_shape_size) { - arg3_padded_shape.insert(arg3_padded_shape.begin(), 1); - } + size_t input_inner_stride = arg_size; + size_t in_low_inner_stride = 0; + size_t in_high_inner_stride = 0; + size_t out_low_inner_stride = 0; + size_t out_high_inner_stride = 0; - while (arg4_padded_shape.size() < max_shape_size) { - arg4_padded_shape.insert(arg4_padded_shape.begin(), 1); - } + std::tie(in_low_inner_stride, input_inner_stride) = + get_inner_stride(arg_size, arg_shape, in_low_shape, input_inner_stride); + std::tie(in_high_inner_stride, input_inner_stride) = + get_inner_stride(arg_size, arg_shape, in_high_shape, input_inner_stride); + std::tie(out_low_inner_stride, input_inner_stride) = + get_inner_stride(arg_size, arg_shape, out_low_shape, input_inner_stride); + std::tie(out_high_inner_stride, input_inner_stride) = + get_inner_stride(arg_size, arg_shape, out_high_shape, input_inner_stride); - Shape arg0_squeezed_shape, arg1_squeezed_shape, arg2_squeezed_shape, arg3_squeezed_shape, arg4_squeezed_shape; - AxisSet arg0_squeezed_axes, arg1_squeezed_axes, arg2_squeezed_axes, arg3_squeezed_axes, arg4_squeezed_axes; - Shape output_shape; + auto get_outer_strides = + [&output_strides, &in_low_strides, &in_high_strides, &out_low_strides, &out_high_strides](size_t flat_index) { + size_t in_low_stride = 0; + size_t in_high_stride = 0; + size_t out_low_stride = 0; + size_t out_high_stride = 0; - for (size_t i = 0; i < max_shape_size; i++) { - if (arg1_padded_shape[i] == 1) { - arg1_squeezed_axes.insert(i); - } else { - arg1_squeezed_shape.push_back(arg1_padded_shape[i]); + for (size_t i = 0; i < output_strides.size(); i++) { + size_t div = flat_index / output_strides[i]; + flat_index = flat_index % output_strides[i]; + in_low_stride += div * in_low_strides[i]; + in_high_stride += div * in_high_strides[i]; + out_low_stride += div * out_low_strides[i]; + out_high_stride += div * out_high_strides[i]; } - if (arg2_padded_shape[i] == 1) { - arg2_squeezed_axes.insert(i); - } else { - arg2_squeezed_shape.push_back(arg2_padded_shape[i]); - } + return std::tuple{in_low_stride, + in_high_stride, + out_low_stride, + out_high_stride}; + }; - if (arg0_padded_shape[i] == 1) { - arg0_squeezed_axes.insert(i); - } else { - arg0_squeezed_shape.push_back(arg0_padded_shape[i]); - } + if (in_low_inner_stride > 1 && in_high_inner_stride > 1 && out_low_inner_stride > 1 && out_high_inner_stride > 1) { + fake_quantize_non_unit_inner_stride(arg, + in_low, + in_high, + out_low, + out_high, + out, + arg_shape, + levels_minus_one, + input_inner_stride, + get_outer_strides); + } else if (in_low_inner_stride == 1 && in_high_inner_stride == 1 && out_low_inner_stride == 1 && + out_high_inner_stride == 1) { + fake_quantize_unit_inner_stride(arg, + in_low, + in_high, + out_low, + out_high, + out, + arg_shape, + levels_minus_one, + input_inner_stride, + get_outer_strides); - if (arg3_padded_shape[i] == 1) { - arg3_squeezed_axes.insert(i); - } else { - arg3_squeezed_shape.push_back(arg3_padded_shape[i]); - } + } else if (in_low_inner_stride > 1 && in_high_inner_stride > 1 && out_low_inner_stride == 1 && + out_high_inner_stride == 1) { + fake_quantize_unit_output_intervals_inner_stride(arg, + in_low, + in_high, + out_low, + out_high, + out, + arg_shape, + levels_minus_one, + input_inner_stride, + get_outer_strides); - if (arg4_padded_shape[i] == 1) { - arg4_squeezed_axes.insert(i); - } else { - arg4_squeezed_shape.push_back(arg4_padded_shape[i]); - } + } else if (in_low_inner_stride == 1 && in_high_inner_stride == 1 && out_low_inner_stride > 1 && + out_high_inner_stride > 1) { + fake_quantize_unit_input_intervals_inner_stride(arg, + in_low, + in_high, + out_low, + out_high, + out, + arg_shape, + levels_minus_one, + input_inner_stride, + get_outer_strides); + } else { + size_t in_low_stride = 0; + size_t in_high_stride = 0; + size_t out_low_stride = 0; + size_t out_high_stride = 0; - output_shape.push_back(std::max({arg0_padded_shape[i], - arg2_padded_shape[i], - arg1_padded_shape[i], - arg3_padded_shape[i], - arg4_padded_shape[i]})); + for (size_t i = 0; i < arg_size; i++) { + std::tie(in_low_stride, in_high_stride, out_low_stride, out_high_stride) = get_outer_strides(i); + *out++ = quantize(*arg++, + *(in_low + in_low_stride), + *(in_high + in_high_stride), + *(out_low + out_low_stride), + *(out_high + out_low_stride), + levels_minus_one); } + } +} - CoordinateTransformBasic arg0_transform(arg0_squeezed_shape); - CoordinateTransformBasic arg1_transform(arg1_squeezed_shape); - CoordinateTransformBasic arg2_transform(arg2_squeezed_shape); - CoordinateTransformBasic arg3_transform(arg3_squeezed_shape); - CoordinateTransformBasic arg4_transform(arg4_squeezed_shape); - CoordinateTransformBasic output_transform(output_shape); - - const auto arg0_strides = row_major_strides(arg0_squeezed_shape); - const auto arg1_strides = row_major_strides(arg1_squeezed_shape); - const auto arg2_strides = row_major_strides(arg2_squeezed_shape); - const auto arg3_strides = row_major_strides(arg3_squeezed_shape); - const auto arg4_strides = row_major_strides(arg4_squeezed_shape); - const auto output_strides = row_major_strides(output_shape); - - for (const Coordinate& output_coord : output_transform) { - const auto arg0_coord = util::reduce(output_coord, arg0_squeezed_axes); - const auto arg1_coord = util::reduce(output_coord, arg1_squeezed_axes); - const auto arg2_coord = util::reduce(output_coord, arg2_squeezed_axes); - const auto arg3_coord = util::reduce(output_coord, arg3_squeezed_axes); - const auto arg4_coord = util::reduce(output_coord, arg4_squeezed_axes); - - const size_t arg0_idx = - std::inner_product(arg0_coord.begin(), arg0_coord.end(), arg0_strides.begin(), uint64_t(0)); - const size_t arg1_idx = - std::inner_product(arg1_coord.begin(), arg1_coord.end(), arg1_strides.begin(), uint64_t(0)); - const size_t arg2_idx = - std::inner_product(arg2_coord.begin(), arg2_coord.end(), arg2_strides.begin(), uint64_t(0)); - const size_t arg3_idx = - std::inner_product(arg3_coord.begin(), arg3_coord.end(), arg3_strides.begin(), uint64_t(0)); - const size_t arg4_idx = - std::inner_product(arg4_coord.begin(), arg4_coord.end(), arg4_strides.begin(), uint64_t(0)); - const size_t output_idx = - std::inner_product(output_coord.begin(), output_coord.end(), output_strides.begin(), uint64_t(0)); - out[output_idx] = quantize(arg[arg0_idx], - in_low[arg1_idx], - in_high[arg2_idx], - out_low[arg3_idx], - out_high[arg4_idx], - levels); +namespace fake_quantize_details { +std::vector compute_strides(const ov::Shape& out_shape, const ov::Shape& shape) { + size_t stride = 1; + size_t out_rank = out_shape.size(); + size_t shape_rank = shape.size(); + std::vector strides(out_rank); + for (size_t i = 0; i < out_rank; i++) { + if (i < shape_rank && shape[shape_rank - i - 1] == out_shape[out_rank - i - 1]) { + strides[out_rank - i - 1] = stride; + stride *= shape[shape_rank - i - 1]; + } else { + strides[out_rank - i - 1] = 0; } } + return strides; } + +std::tuple get_inner_stride(size_t num_output_elements, + const ov::Shape& output_shape, + const ov::Shape& shape, + size_t current_output_inner_stride) { + if (shape.size() == 0) + return std::tuple{1, std::min(current_output_inner_stride, num_output_elements)}; + const size_t last = shape.back(); + auto it = std::find_if(shape.rbegin(), shape.rend(), [last](size_t dim) { + return (last == 1 && dim > 1) || (last > 1 && dim == 1); + }); + if (it == shape.rend()) { + const size_t num_elements = shape_size(shape); + return std::tuple{ + num_elements, + last == 1 ? current_output_inner_stride : std::min(current_output_inner_stride, num_elements)}; + } + const size_t idx = std::distance(it, shape.rbegin()) + static_cast(shape.size()); + const size_t inner_stride = + std::accumulate(shape.begin() + idx, shape.end(), static_cast(1), std::multiplies()); + const size_t output_inner_stride = std::accumulate(output_shape.begin() + output_shape.size() - shape.size() + idx, + output_shape.end(), + static_cast(1), + std::multiplies()); + return std::tuple{inner_stride, std::min(current_output_inner_stride, output_inner_stride)}; +} + +template +static void transform(const T* first1, const T* const last1, const T* first2, const T* first3, T* out, const F& f) { + while (first1 < last1) { + *out++ = f(*first1++, *first2++, *first3++); + } +} + +template +static void transform(const T* first1, + const T* const last1, + const T* first2, + const T* first3, + const T* first4, + const T* first5, + T* out, + const F& f) { + while (first1 < last1) { + *out++ = f(*first1++, *first2++, *first3++, *first4++, *first5++); + } +} + +template +static void fake_quantize_loop(const Shape& arg_shape, + const T* arg, + const T* in_low, + const T* in_high, + const T* out_low, + const T* out_high, + T* out, + size_t input_inner_stride, + const F1& get_outer_strides, + const F2& quantize_loop) { + size_t in_low_stride = 0; + size_t in_high_stride = 0; + size_t out_low_stride = 0; + size_t out_high_stride = 0; + + for (size_t i = 0; i < shape_size(arg_shape); i += input_inner_stride) { + std::tie(in_low_stride, in_high_stride, out_low_stride, out_high_stride) = get_outer_strides(i); + quantize_loop(arg, + arg + input_inner_stride, + in_low + in_low_stride, + in_high + in_high_stride, + out_low + out_low_stride, + out_high + out_high_stride, + out); + arg += input_inner_stride; + out += input_inner_stride; + } +} + +template +void fake_quantize_non_unit_inner_stride(const T* arg, + const T* in_low, + const T* in_high, + const T* out_low, + const T* out_high, + T* out, + const Shape& arg_shape, + T levels_minus_one, + size_t input_inner_stride, + const F& get_outer_strides) { + fake_quantize_loop(arg_shape, + arg, + in_low, + in_high, + out_low, + out_high, + out, + input_inner_stride, + get_outer_strides, + [levels_minus_one](const T* input, + const T* const input_end, + const T* in_low, + const T* in_high, + const T* out_low, + const T* out_high, + T* out) { + transform(input, + input_end, + in_low, + in_high, + out_low, + out_high, + out, + [levels_minus_one](T input, T in_low, T in_high, T out_low, T out_high) { + return quantize(input, in_low, in_high, out_low, out_high, levels_minus_one); + }); + }); +} + +template +void fake_quantize_unit_inner_stride(const T* arg, + const T* in_low, + const T* in_high, + const T* out_low, + const T* out_high, + T* out, + const Shape& arg_shape, + T levels_minus_one, + size_t input_inner_stride, + const F& get_outer_strides) { + auto quantize_with_scalar_intervals = [levels_minus_one](const T* input, + const T* const input_end, + const T* in_low, + const T* in_high, + const T* out_low, + const T* out_high, + T* out) { + const auto in_low_scalar = *in_low; + const auto in_high_scalar = *in_high; + const auto out_low_scalar = *out_low; + const auto out_high_scalar = *out_high; + std::transform(input, + input_end, + out, + [levels_minus_one, in_low_scalar, in_high_scalar, out_low_scalar, out_high_scalar](T input) { + return quantize(input, + in_low_scalar, + in_high_scalar, + out_low_scalar, + out_high_scalar, + levels_minus_one); + }); + }; + + fake_quantize_loop(arg_shape, + arg, + in_low, + in_high, + out_low, + out_high, + out, + input_inner_stride, + get_outer_strides, + quantize_with_scalar_intervals); +} + +template +void fake_quantize_unit_output_intervals_inner_stride(const T* arg, + const T* in_low, + const T* in_high, + const T* out_low, + const T* out_high, + T* out, + const Shape& arg_shape, + T levels_minus_one, + size_t input_inner_stride, + const F& get_outer_strides) { + auto quantize_with_scalar_output_intervals = [levels_minus_one](const T* input, + const T* const input_end, + const T* in_low, + const T* in_high, + const T* out_low, + const T* out_high, + T* out) { + const auto out_low_scalar = *out_low; + const auto out_high_scalar = *out_high; + transform(input, + input_end, + in_low, + in_high, + out, + [levels_minus_one, out_low_scalar, out_high_scalar](T input, T in_low, T in_high) { + return quantize(input, in_low, in_high, out_low_scalar, out_high_scalar, levels_minus_one); + }); + }; + + fake_quantize_loop(arg_shape, + arg, + in_low, + in_high, + out_low, + out_high, + out, + input_inner_stride, + get_outer_strides, + quantize_with_scalar_output_intervals); +} + +template +void fake_quantize_unit_input_intervals_inner_stride(const T* arg, + const T* in_low, + const T* in_high, + const T* out_low, + const T* out_high, + T* out, + const Shape& arg_shape, + T levels_minus_one, + size_t input_inner_stride, + const F& get_outer_strides) { + auto quantize_with_scalar_input_intervals = [levels_minus_one](const T* input, + const T* const input_end, + const T* in_low, + const T* in_high, + const T* out_low, + const T* out_high, + T* out) { + const auto in_low_scalar = *in_low; + const auto in_high_scalar = *in_high; + transform(input, + input_end, + out_low, + out_high, + out, + [levels_minus_one, in_low_scalar, in_high_scalar](T input, T out_low, T out_high) { + return quantize(input, in_low_scalar, in_high_scalar, out_low, out_high, levels_minus_one); + }); + }; + + fake_quantize_loop(arg_shape, + arg, + in_low, + in_high, + out_low, + out_high, + out, + input_inner_stride, + get_outer_strides, + quantize_with_scalar_input_intervals); +} + +} // namespace fake_quantize_details + } // namespace reference } // namespace ov diff --git a/src/core/reference/include/openvino/reference/group_convolution_backprop_data.hpp b/src/core/reference/include/openvino/reference/group_convolution_backprop_data.hpp index 66d2a6f431df92..5c410d044cea62 100644 --- a/src/core/reference/include/openvino/reference/group_convolution_backprop_data.hpp +++ b/src/core/reference/include/openvino/reference/group_convolution_backprop_data.hpp @@ -98,35 +98,5 @@ void group_convolution_backprop_data(const T* in, } } } - -// DEPRECATED, can't be removed currently due to arm-plugin dependency -template ::type> -OPENVINO_DEPRECATED("group_convolution_backprop_data function without output_paddings is deprecated, " - "use the one with output_padding.") -void group_convolution_backprop_data(const INPUT* in, - const FILTER* f, - OUTPUT* out, - const Shape& in_shape, - const Shape& filter_shape, - const Shape& out_shape, - const Strides& strides, - const Strides& dilation, - const CoordinateDiff& pads_begin, - const CoordinateDiff& pads_end) { - const CoordinateDiff output_padding(in_shape.size() - 2, 0); - - group_convolution_backprop_data(in, - f, - out, - in_shape, - filter_shape, - out_shape, - strides, - dilation, - pads_begin, - pads_end, - output_padding); -} - } // namespace reference } // namespace ov diff --git a/src/core/reference/include/openvino/reference/logical_not.hpp b/src/core/reference/include/openvino/reference/logical_not.hpp new file mode 100644 index 00000000000000..ca31a824b50d5f --- /dev/null +++ b/src/core/reference/include/openvino/reference/logical_not.hpp @@ -0,0 +1,25 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +namespace ov { +namespace reference { + +/** + * @brief Reference implementation of LogicalNot operator. + * + * @param arg Pointer to input data. + * @param out Pointer to output data. + * @param count Number of elements in input buffer. + */ +template +void logical_not(const T* arg, T* out, const size_t count) { + std::transform(arg, std::next(arg, count), out, std::logical_not()); +} +} // namespace reference +} // namespace ov diff --git a/src/core/reference/include/openvino/reference/matmul.hpp b/src/core/reference/include/openvino/reference/matmul.hpp index b4a09e0f276d94..32ced574949655 100644 --- a/src/core/reference/include/openvino/reference/matmul.hpp +++ b/src/core/reference/include/openvino/reference/matmul.hpp @@ -9,8 +9,8 @@ #include #include -#include "ngraph/runtime/opt_kernel/reshape.hpp" #include "openvino/reference/broadcast.hpp" +#include "openvino/reference/reshape.hpp" namespace ov { namespace reference { @@ -100,12 +100,12 @@ void matmul(const T* arg0, std::vector tmp(shape_size(arg0_shape)); auto axis_vector = details::get_transpose_order(arg0_shape); std::swap(arg0_shape_tmp[arg0_rank - 1], arg0_shape_tmp[arg0_rank - 2]); - ngraph::runtime::opt_kernel::reshape(reinterpret_cast(arg0_data), - reinterpret_cast(tmp.data()), - arg0_shape, - axis_vector, - arg0_shape_tmp, - sizeof(T)); + reshape(reinterpret_cast(arg0_data), + reinterpret_cast(tmp.data()), + arg0_shape, + axis_vector, + arg0_shape_tmp, + sizeof(T)); arg0_new_data.swap(tmp); arg0_data = arg0_new_data.data(); } @@ -114,12 +114,12 @@ void matmul(const T* arg0, std::vector tmp(shape_size(arg1_shape)); auto axis_vector = details::get_transpose_order(arg1_shape); std::swap(arg1_shape_tmp[arg1_rank - 1], arg1_shape_tmp[arg1_rank - 2]); - ngraph::runtime::opt_kernel::reshape(reinterpret_cast(arg1_data), - reinterpret_cast(tmp.data()), - arg1_shape, - axis_vector, - arg1_shape_tmp, - sizeof(T)); + reshape(reinterpret_cast(arg1_data), + reinterpret_cast(tmp.data()), + arg1_shape, + axis_vector, + arg1_shape_tmp, + sizeof(T)); arg1_new_data.swap(tmp); arg1_data = arg1_new_data.data(); } diff --git a/src/core/reference/include/openvino/reference/multinomial.hpp b/src/core/reference/include/openvino/reference/multinomial.hpp index fc141d1204cbea..ce9fe0a52d7c61 100644 --- a/src/core/reference/include/openvino/reference/multinomial.hpp +++ b/src/core/reference/include/openvino/reference/multinomial.hpp @@ -113,8 +113,7 @@ void multinomial(const T* probs, auto batch_size = probs_shape.size() == 2 ? static_cast(probs_shape[0]) : static_cast(1); auto class_size = probs_shape.size() == 2 ? static_cast(probs_shape[1]) : static_cast(probs_shape[0]); - auto samples_size = - probs_shape.size() == 2 ? static_cast(num_samples[0]) : static_cast(probs_shape[0]); + auto samples_size = static_cast(num_samples[0]); // Iterate over each channel in uniform samples std::vector output_samples(total_output_elements_count); @@ -132,8 +131,8 @@ void multinomial(const T* probs, break; } } - // Additional step with replacement - change probability of a given class to 0, and update the cdf - if (with_replacement) { + // Additional step without replacement - change probability of a given class to 0, and update the cdf + if (!with_replacement) { T class_probability = selected_class_idx ? cdf[i_translated + selected_class_idx] - cdf[i_translated + selected_class_idx - 1] : cdf[i_translated + selected_class_idx]; diff --git a/src/core/reference/include/openvino/reference/not.hpp b/src/core/reference/include/openvino/reference/not.hpp deleted file mode 100644 index e0444a8eb73a2a..00000000000000 --- a/src/core/reference/include/openvino/reference/not.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace reference { -template -void logical_not(const T* arg, T* out, size_t count) { - for (size_t i = 0; i < count; i++) { - out[i] = static_cast(!(arg[i])); - } -} -} // namespace reference -} // namespace ov diff --git a/src/core/reference/include/openvino/reference/or.hpp b/src/core/reference/include/openvino/reference/or.hpp index 7e821de63e3c03..4b0d760ec41349 100644 --- a/src/core/reference/include/openvino/reference/or.hpp +++ b/src/core/reference/include/openvino/reference/or.hpp @@ -4,31 +4,38 @@ #pragma once -#include +#include +#include #include "openvino/core/shape.hpp" -#include "openvino/op/util/attr_types.hpp" #include "openvino/reference/autobroadcast_binop.hpp" namespace ov { namespace reference { -template -void logical_or(const T* arg0, const T* arg1, T* out, size_t count) { - for (size_t i = 0; i < count; i++) { - out[i] = static_cast(arg0[i] || arg1[i]); - } + +template +void logical_or(const T* arg0, const T* arg1, T* out, const size_t count) { + std::transform(arg0, std::next(arg0, count), arg1, out, std::logical_or()); } -template +/** + * @brief Reference implementation of binary elementwise LogicalOr operator. + * + * @param arg0 Pointer to input 0 data. + * @param arg1 Pointer to input 1 data. + * @param out Pointer to output data. + * @param arg_shape0 Input 0 shape. + * @param arg_shape1 Input 1 shape. + * @param broadcast_spec Broadcast specification mode. + */ +template void logical_or(const T* arg0, const T* arg1, T* out, const Shape& arg0_shape, const Shape& arg1_shape, const op::AutoBroadcastSpec& broadcast_spec) { - autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, [](T x, T y) -> T { - return static_cast(x || y); - }); + autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, std::logical_or()); } } // namespace reference } // namespace ov diff --git a/src/core/reference/include/openvino/reference/range.hpp b/src/core/reference/include/openvino/reference/range.hpp index cc9cb2f643ae06..c8fb5c5084b0f5 100644 --- a/src/core/reference/include/openvino/reference/range.hpp +++ b/src/core/reference/include/openvino/reference/range.hpp @@ -14,7 +14,7 @@ namespace ov { namespace reference { // Return type is `void`, only enabled if `T` is a built-in FP -// type, or nGraph's `bfloat16` or `float16` type. +// type, or OpenVINO's `bfloat16` or `float16` type. template typename std::enable_if::value || std::is_same::value || std::is_same::value>::type diff --git a/src/core/reference/include/openvino/reference/reshape.hpp b/src/core/reference/include/openvino/reference/reshape.hpp index b3cdd12df47e06..2e4cb37e163140 100644 --- a/src/core/reference/include/openvino/reference/reshape.hpp +++ b/src/core/reference/include/openvino/reference/reshape.hpp @@ -9,11 +9,35 @@ namespace ov { namespace reference { -void reshape(const char* arg, + +/** + * @brief Basic reshape operation, without axes reorder. + * + * @param in Pointer to input data. + * @param out Pointer to output data. + * @param in_shape Input data shape. + * @param out_shape Output data shape. + * @param elem_size Single data element size im bytes. + */ +inline void reshape(const char* in, char* out, const Shape& in_shape, size_t elem_size) { + std::memcpy(out, in, shape_size(in_shape) * elem_size); +} + +/** + * @brief Permutes data shape and axes. + * + * @param in Pointer to input data. + * @param out Pointer to output data. + * @param in_shape Input data shape. + * @param axes_order Axes order. + * @param out_shape Output data shape. + * @param elem_size Single data element size im bytes. + */ +void reshape(const char* in, char* out, const Shape& in_shape, - const AxisVector& in_axis_order, + const AxisVector& axes_order, const Shape& out_shape, size_t elem_size); -} +} // namespace reference } // namespace ov diff --git a/src/core/reference/include/openvino/reference/reverse.hpp b/src/core/reference/include/openvino/reference/reverse.hpp index b4ea16c50130af..2eeb6afff5048b 100644 --- a/src/core/reference/include/openvino/reference/reverse.hpp +++ b/src/core/reference/include/openvino/reference/reverse.hpp @@ -4,9 +4,8 @@ #pragma once -#include - -#include "openvino/reference/utils/coordinate_transform.hpp" +#include "openvino/core/axis_set.hpp" +#include "openvino/core/shape.hpp" namespace ov { namespace reference { diff --git a/src/core/reference/include/openvino/reference/split.hpp b/src/core/reference/include/openvino/reference/split.hpp index dcbede1883a409..6e3564ed035bb1 100644 --- a/src/core/reference/include/openvino/reference/split.hpp +++ b/src/core/reference/include/openvino/reference/split.hpp @@ -4,17 +4,28 @@ #pragma once -#include +#include -#include "openvino/reference/slice.hpp" +#include "openvino/core/shape.hpp" namespace ov { namespace reference { + +/** + * @brief Reference implementation of Split operator. + * + * @param data Pointer to input data. + * @param data_shape Input data shape. + * @param elem_size Size of single element type. + * @param axis Axis used for split input data. + * @param num_splits Number of splits + * @param out_data Pointer to output data pointers (must have size of num_splits) + */ void split(const char* data, const Shape& data_shape, size_t elem_size, int64_t axis, size_t num_splits, char** out_data); -} +} // namespace reference } // namespace ov diff --git a/src/core/reference/include/openvino/reference/topk.hpp b/src/core/reference/include/openvino/reference/topk.hpp index c84fb54e9962bb..76ce901eb27f9a 100644 --- a/src/core/reference/include/openvino/reference/topk.hpp +++ b/src/core/reference/include/openvino/reference/topk.hpp @@ -8,7 +8,7 @@ #include #include -#include "openvino/op/topk.hpp" +#include "openvino/op/util/attr_types.hpp" #include "openvino/reference/utils/coordinate_index.hpp" #include "openvino/reference/utils/coordinate_transform.hpp" @@ -17,23 +17,11 @@ namespace reference { // This used to be lambda expressions but MSVC had difficulty compiling it. This way is more explicit. template inline bool compare_max(const std::tuple& a, const std::tuple& b) { -// this is intentional to be able to compare floats directly -// without using relative or absolute tolerance -#if defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wfloat-equal" -#endif - if (std::get<0>(a) == std::get<0>(b)) { + if (std::get<0>(a) != std::get<0>(b)) { + return D ? std::get<0>(a) > std::get<0>(b) : std::get<0>(a) < std::get<0>(b); + } else { return std::get<1>(a) < std::get<1>(b); } -#if defined(__GNUC__) -# pragma GCC diagnostic pop -#endif - - if (D) - return std::get<0>(a) > std::get<0>(b); - else - return std::get<0>(a) < std::get<0>(b); } template @@ -41,63 +29,76 @@ inline bool compare_indices_ascending(const std::tuple& a, const std::tupl return std::get<1>(a) < std::get<1>(b); } -// TopK reference implementation provides stable indices output +/** + * @brief Reference implementation fo TopK operator + * + * @param arg Pointer to input data. + * @param out_indices Pointer to output indicies. + * @param out_values Pointer to output values. + * @param in_shape Input data shape. + * @param out_shape Output data (values, indicies) shape. + * @param axis Axis for search of top K elements. + * @param k Number to find of top elements. + * @param compute_max Select mode of find max or min. + * @param sort Sorting type. + */ template void topk(const T* arg, U* out_indices, T* out_values, const Shape& in_shape, const Shape& out_shape, - size_t axis, - size_t k, - bool compute_max, - op::TopKSortType sort = op::TopKSortType::NONE) { - using namespace std; + const size_t axis, + const size_t k, + const bool compute_max, + const op::TopKSortType sort = op::TopKSortType::NONE) { // Create temp vector for sorting. - vector> workspace(in_shape[axis]); - vector in_strides = row_major_strides(in_shape); - vector out_strides = row_major_strides(out_shape); - auto in_axis_stride = in_strides[axis]; - auto out_axis_stride = out_strides[axis]; + std::vector> workspace(in_shape[axis]); + const auto in_strides = row_major_strides(in_shape); + const auto out_strides = row_major_strides(out_shape); + const auto in_axis_stride = in_strides[axis]; + const auto out_axis_stride = out_strides[axis]; // Iterate over elements with 0 index at "axis" dimension auto traverse_shape = in_shape; traverse_shape[axis] = 1; CoordinateTransformBasic traverse_transform(traverse_shape); - for (const Coordinate& coord : traverse_transform) { + for (const auto& coord : traverse_transform) { auto arg_index = coordinate_index(coord, in_shape); auto out_index = coordinate_index(coord, out_shape); // Fill the temp vector U i = 0; - for (tuple& entry : workspace) { - get<0>(entry) = arg[arg_index]; - get<1>(entry) = i; + for (auto& entry : workspace) { + std::get<0>(entry) = arg[arg_index]; + std::get<1>(entry) = i; arg_index += in_axis_stride; - i++; - } - // Sort the temp vector - if (compute_max) { - nth_element(workspace.begin(), workspace.begin() + k, workspace.end(), compare_max); - } else { - nth_element(workspace.begin(), workspace.begin() + k, workspace.end(), compare_max); + ++i; } - // Write temp vector to output + + const auto cmp_func = compute_max ? compare_max : compare_max; + + typename std::decay::type sort_func; switch (sort) { - case op::TopKSortType::NONE: - break; case op::TopKSortType::SORT_INDICES: - std::sort(workspace.begin(), workspace.begin() + k, compare_indices_ascending); + sort_func = compare_indices_ascending; break; case op::TopKSortType::SORT_VALUES: - if (compute_max) - std::sort(workspace.begin(), workspace.begin() + k, compare_max); - else - std::sort(workspace.begin(), workspace.begin() + k, compare_max); + sort_func = cmp_func; + break; + default: + sort_func = nullptr; + break; } - for (size_t j = 0; j < k; j++) { + + std::nth_element(workspace.begin(), workspace.begin() + k, workspace.end(), cmp_func); + if (sort_func) { + std::sort(workspace.begin(), workspace.begin() + k, sort_func); + } + + for (size_t j = 0; j < k; ++j) { const auto& entry = workspace[j]; - out_values[out_index] = get<0>(entry); - out_indices[out_index] = get<1>(entry); + out_values[out_index] = std::get<0>(entry); + out_indices[out_index] = std::get<1>(entry); out_index += out_axis_stride; } } diff --git a/src/core/reference/src/op/convert.cpp b/src/core/reference/src/op/convert.cpp index 2846802d6c43ed..f89cc28a8139de 100644 --- a/src/core/reference/src/op/convert.cpp +++ b/src/core/reference/src/op/convert.cpp @@ -7,7 +7,7 @@ #if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64) # include "jit_generator.hpp" -using namespace ngraph::runtime; +using namespace ov::runtime; #endif namespace ov { diff --git a/src/core/reference/src/op/depth_to_space.cpp b/src/core/reference/src/op/depth_to_space.cpp index 0a0d33596d4961..19024002ea0526 100644 --- a/src/core/reference/src/op/depth_to_space.cpp +++ b/src/core/reference/src/op/depth_to_space.cpp @@ -7,8 +7,8 @@ #include #include -#include "ngraph/runtime/opt_kernel/reshape.hpp" #include "openvino/core/except.hpp" +#include "openvino/reference/reshape.hpp" namespace ov { namespace reference { @@ -96,7 +96,7 @@ void depth_to_space(const char* const in, post_transpose_shape[axis_idx] = dispersed_shape[axes_order[axis_idx]]; } - ngraph::runtime::opt_kernel::reshape(in, out, dispersed_shape, axes_order, post_transpose_shape, elem_size); + reshape(in, out, dispersed_shape, axes_order, post_transpose_shape, elem_size); } } // namespace reference diff --git a/src/core/reference/src/op/einsum.cpp b/src/core/reference/src/op/einsum.cpp index abe8f8c14ba547..271982c3986e7f 100644 --- a/src/core/reference/src/op/einsum.cpp +++ b/src/core/reference/src/op/einsum.cpp @@ -249,14 +249,6 @@ Shape compute_matmul_output_shape(const Shape& common_sub_shape, return matmul_output_shape; } -/// @brief Prepares default order axis vector -/// -AxisVector get_default_order(size_t rank) { - AxisVector default_order(rank); - std::iota(begin(default_order), end(default_order), 0); - return default_order; -} - /// \brief Update a vector of inputs and subscripts by removing items for /// inputs with indices input_ind1 and input_ind2 and inserted new input and /// the corresponsing subscript in the tail @@ -296,15 +288,12 @@ ov::Tensor unsqueeze_input(const ov::Tensor& input, std::vector& unsque } auto output = ov::Tensor(input.get_element_type(), output_shape); - const auto order = get_default_order(input_shape.size()); const auto element_type = input.get_element_type(); - reference::reshape(reinterpret_cast(input.data()), - reinterpret_cast(output.data()), - input_shape, - order, - output_shape, - element_type.size()); + reshape(static_cast(input.data()), + static_cast(output.data()), + input_shape, + element_type.size()); return output; } @@ -653,14 +642,11 @@ ov::Tensor reshape_input_for_matmul(const ov::Tensor& input, const auto element_type = input.get_element_type(); const auto& input_shape = input.get_shape(); auto output = ov::Tensor(element_type, new_shape); - const auto order = get_default_order(input_shape.size()); - - reference::reshape(reinterpret_cast(input.data()), - reinterpret_cast(output.data()), - input_shape, - order, - new_shape, - element_type.size()); + + reshape(static_cast(input.data()), + static_cast(output.data()), + input_shape, + element_type.size()); return output; } @@ -930,13 +916,10 @@ void contract_two_inputs(ov::TensorVector& inputs, back_shape.insert(back_shape.end(), separate2_sub_shape.begin(), separate2_sub_shape.end()); auto contract_output = ov::Tensor(matmul_output.get_element_type(), back_shape); - const auto order = get_default_order(matmul_output.get_shape().size()); - reference::reshape(reinterpret_cast(matmul_output.data()), - reinterpret_cast(contract_output.data()), - matmul_output.get_shape(), - order, - back_shape, - matmul_output.get_element_type().size()); + reshape(static_cast(matmul_output.data()), + static_cast(contract_output.data()), + matmul_output.get_shape(), + matmul_output.get_element_type().size()); update_operands(inputs, input_subscripts, input_ind1, input_ind2, contract_output, resultant_subscript); } diff --git a/src/core/reference/src/op/jit_generator.cpp b/src/core/reference/src/op/jit_generator.cpp index 99f224dc68b802..e0585ae442cf07 100644 --- a/src/core/reference/src/op/jit_generator.cpp +++ b/src/core/reference/src/op/jit_generator.cpp @@ -12,9 +12,9 @@ # include # include "jit_generator.hpp" -# include "ngraph/type/float16.hpp" +# include "openvino/core/type/float16.hpp" -namespace ngraph { +namespace ov { namespace runtime { namespace jit { using namespace Xbyak; @@ -186,6 +186,6 @@ void Generator::copy(const Xbyak::Reg64& dst, const Xbyak::Reg64& src, co } } // namespace jit } // namespace runtime -} // namespace ngraph +} // namespace ov #endif // OPENVINO_ARCH_X86 || OPENVINO_ARCH_X86_64 diff --git a/src/core/reference/src/op/jit_generator.hpp b/src/core/reference/src/op/jit_generator.hpp index 9e8900abf6345f..e6da95c0440da5 100644 --- a/src/core/reference/src/op/jit_generator.hpp +++ b/src/core/reference/src/op/jit_generator.hpp @@ -11,12 +11,9 @@ #include #include -namespace ngraph -{ - namespace runtime - { - namespace jit - { +namespace ov { +namespace runtime { +namespace jit { #ifdef XBYAK64 static const Xbyak::Operand::Code abi_save_gpr_regs[] = { Xbyak::Operand::RBX, @@ -94,4 +91,4 @@ namespace ngraph }; } } -} + } // namespace ov diff --git a/src/core/reference/src/op/reshape.cpp b/src/core/reference/src/op/reshape.cpp index dec23afda868d7..efbf0933fc32e6 100644 --- a/src/core/reference/src/op/reshape.cpp +++ b/src/core/reference/src/op/reshape.cpp @@ -8,12 +8,290 @@ #include #include "openvino/core/except.hpp" +#include "openvino/core/parallel.hpp" #include "openvino/reference/utils/coordinate_range.hpp" #include "openvino/reference/utils/coordinate_transform.hpp" namespace ov { namespace reference { namespace { +static size_t get_threshold() { + // TODO: find a better way, not hardcoded value + return (1 << 9) * parallel_get_num_threads(); +} + +static inline void copy_element(char* out, const char* in, size_t elem_size) { +#define CASE(type) \ + case sizeof(type): \ + *reinterpret_cast(out) = *reinterpret_cast(in); \ + break; + + switch (elem_size) { + CASE(int32_t) + CASE(int64_t) + CASE(int16_t) + CASE(int8_t) + default: + std::memcpy(out, in, elem_size); + break; + } +#undef CASE +} + +void reshape_2D(const char* in, + char* out, + const Shape& in_shape, + const AxisVector& axes_order, + const Shape& out_shape, + size_t elem_size) { + size_t num_elements = shape_size(in_shape); + if (num_elements <= get_threshold()) { + for (size_t i = 0; i < out_shape[0]; i++) { + size_t off = i; + for (size_t j = 0; j < out_shape[1]; j++) { + copy_element(out, in + off * elem_size, elem_size); + out += elem_size; + off += out_shape[0]; + } + } + } else { + ov::parallel_for2d(out_shape[0], out_shape[1], [in, out, &out_shape, elem_size](size_t i, size_t j) { + size_t in_off = j * out_shape[0] + i; + size_t out_off = i * out_shape[1] + j; + copy_element(out + out_off * elem_size, in + in_off * elem_size, elem_size); + }); + } +} + +static std::vector get_strides(size_t rank, size_t elem_size, const AxisVector& order, const Shape& in_shape) { + std::vector rev_order(rank); + for (size_t i = 0; i < rank; i++) { + rev_order[order[i]] = i; + } + + std::vector strides(rank); + strides[rev_order[rank - 1]] = elem_size; + for (size_t i = rank - 1; i > 0; i--) { + strides[rev_order[i - 1]] = strides[rev_order[i]] * in_shape[i]; + } + + return strides; +} + +void reshape_3D(const char* in, + char* out, + const Shape& in_shape, + const AxisVector& axes_order, + const Shape& out_shape, + size_t elem_size) { + size_t num_elements = shape_size(in_shape); + if (num_elements <= get_threshold()) { + const auto strides = get_strides(3, elem_size, axes_order, in_shape); + + size_t off_0 = 0; + for (size_t i = 0; i < out_shape[0]; i++) { + size_t off_1 = off_0; + for (size_t j = 0; j < out_shape[1]; j++) { + size_t in_off = off_1; + for (size_t k = 0; k < out_shape[2]; k++) { + copy_element(out, in + in_off, elem_size); + out += elem_size; + in_off += strides[2]; + } + off_1 += strides[1]; + } + off_0 += strides[0]; + } + } else { + ov::parallel_for3d(out_shape[0], + out_shape[1], + out_shape[2], + [in, out, axes_order, &in_shape, &out_shape, elem_size](size_t i, size_t j, size_t k) { + size_t in_indexes[3]; + in_indexes[axes_order[0]] = i; + in_indexes[axes_order[1]] = j; + in_indexes[axes_order[2]] = k; + size_t in_off = + (in_indexes[0] * in_shape[1] + in_indexes[1]) * in_shape[2] + in_indexes[2]; + size_t out_off = (i * out_shape[1] + j) * out_shape[2] + k; + copy_element(out + out_off * elem_size, in + in_off * elem_size, elem_size); + }); + } +} + +void reshape_4D(const char* in, + char* out, + const Shape& in_shape, + const AxisVector& axes_order, + const Shape& out_shape, + size_t elem_size) { + size_t num_elements = shape_size(in_shape); + if (num_elements <= get_threshold()) { + const auto strides = get_strides(4, elem_size, axes_order, in_shape); + + size_t off_0 = 0; + for (size_t i = 0; i < out_shape[0]; i++) { + size_t off_1 = off_0; + for (size_t j = 0; j < out_shape[1]; j++) { + size_t off_2 = off_1; + for (size_t k = 0; k < out_shape[2]; k++) { + size_t in_off = off_2; + for (size_t l = 0; l < out_shape[3]; l++) { + copy_element(out, in + in_off, elem_size); + out += elem_size; + in_off += strides[3]; + } + off_2 += strides[2]; + } + off_1 += strides[1]; + } + off_0 += strides[0]; + } + } else { + ov::parallel_for4d( + out_shape[0], + out_shape[1], + out_shape[2], + out_shape[3], + [in, out, axes_order, &in_shape, &out_shape, elem_size](size_t i, size_t j, size_t k, size_t l) { + size_t in_indexes[4]; + in_indexes[axes_order[0]] = i; + in_indexes[axes_order[1]] = j; + in_indexes[axes_order[2]] = k; + in_indexes[axes_order[3]] = l; + size_t in_off = + ((in_indexes[0] * in_shape[1] + in_indexes[1]) * in_shape[2] + in_indexes[2]) * in_shape[3] + + in_indexes[3]; + size_t out_off = ((i * out_shape[1] + j) * out_shape[2] + k) * out_shape[3] + l; + copy_element(out + out_off * elem_size, in + in_off * elem_size, elem_size); + }); + } +} + +void reshape_5D(const char* in, + char* out, + const Shape& in_shape, + const AxisVector& axes_order, + const Shape& out_shape, + size_t elem_size) { + size_t num_elements = shape_size(in_shape); + if (num_elements <= get_threshold()) { + const auto strides = get_strides(5, elem_size, axes_order, in_shape); + + size_t off_0 = 0; + for (size_t i = 0; i < out_shape[0]; i++) { + size_t off_1 = off_0; + for (size_t j = 0; j < out_shape[1]; j++) { + size_t off_2 = off_1; + for (size_t k = 0; k < out_shape[2]; k++) { + size_t off_3 = off_2; + for (size_t l = 0; l < out_shape[3]; l++) { + size_t in_off = off_3; + for (size_t m = 0; m < out_shape[4]; m++) { + copy_element(out, in + in_off, elem_size); + out += elem_size; + in_off += strides[4]; + } + off_3 += strides[3]; + } + off_2 += strides[2]; + } + off_1 += strides[1]; + } + off_0 += strides[0]; + } + } else { + ov::parallel_for5d( + out_shape[0], + out_shape[1], + out_shape[2], + out_shape[3], + out_shape[4], + [in, out, axes_order, &in_shape, &out_shape, elem_size](size_t i, size_t j, size_t k, size_t l, size_t m) { + size_t in_indexes[5]; + in_indexes[axes_order[0]] = i; + in_indexes[axes_order[1]] = j; + in_indexes[axes_order[2]] = k; + in_indexes[axes_order[3]] = l; + in_indexes[axes_order[4]] = m; + size_t in_off = + (((in_indexes[0] * in_shape[1] + in_indexes[1]) * in_shape[2] + in_indexes[2]) * in_shape[3] + + in_indexes[3]) * + in_shape[4] + + in_indexes[4]; + size_t out_off = (((i * out_shape[1] + j) * out_shape[2] + k) * out_shape[3] + l) * out_shape[4] + m; + copy_element(out + out_off * elem_size, in + in_off * elem_size, elem_size); + }); + } +} + +void reshape_6D(const char* in, + char* out, + const Shape& in_shape, + const AxisVector& axes_order, + const Shape& out_shape, + size_t elem_size) { + size_t num_elements = shape_size(in_shape); + if (num_elements <= get_threshold()) { + const auto strides = get_strides(6, elem_size, axes_order, in_shape); + + size_t off_0 = 0; + for (size_t i = 0; i < out_shape[0]; i++) { + size_t off_1 = off_0; + for (size_t j = 0; j < out_shape[1]; j++) { + size_t off_2 = off_1; + for (size_t k = 0; k < out_shape[2]; k++) { + size_t off_3 = off_2; + for (size_t l = 0; l < out_shape[3]; l++) { + size_t off_4 = off_3; + for (size_t m = 0; m < out_shape[4]; m++) { + size_t in_off = off_4; + for (size_t n = 0; n < out_shape[5]; n++) { + copy_element(out, in + in_off, elem_size); + out += elem_size; + in_off += strides[5]; + } + off_4 += strides[4]; + } + off_3 += strides[3]; + } + off_2 += strides[2]; + } + off_1 += strides[1]; + } + off_0 += strides[0]; + } + } else { + ov::parallel_for6d( + out_shape[0], + out_shape[1], + out_shape[2], + out_shape[3], + out_shape[4], + out_shape[5], + [=, &axes_order, &in_shape, &out_shape](size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) { + size_t in_indexes[6]; + in_indexes[axes_order[0]] = i; + in_indexes[axes_order[1]] = j; + in_indexes[axes_order[2]] = k; + in_indexes[axes_order[3]] = l; + in_indexes[axes_order[4]] = m; + in_indexes[axes_order[5]] = n; + size_t in_off = + ((((in_indexes[0] * in_shape[1] + in_indexes[1]) * in_shape[2] + in_indexes[2]) * in_shape[3] + + in_indexes[3]) * + in_shape[4] + + in_indexes[4]) * + in_shape[5] + + in_indexes[5]; + size_t out_off = ((((i * out_shape[1] + j) * out_shape[2] + k) * out_shape[3] + l) * out_shape[4] + m) * + out_shape[5] + + n; + copy_element(out + out_off * elem_size, in + in_off * elem_size, elem_size); + }); + } +} + std::vector reorder(const std::vector& origin, const AxisVector& order) { std::vector reordered = origin; auto out = begin(reordered); @@ -24,30 +302,76 @@ std::vector reorder(const std::vector& origin, const AxisVector& } return reordered; } + +void reshape_ND(const char* in, + char* out, + const Shape& in_shape, + const AxisVector& axes_order, + const Shape& out_shape, + size_t elem_size) { + char* output = out; + const char* const output_end = out + shape_size(out_shape) * elem_size; + const auto axis_strides = reorder(row_major_strides(in_shape), axes_order); + for (const auto& coordinate : CoordinateTransformBasic(reorder(in_shape, axes_order))) { + if (output >= output_end) { + break; + } + const auto elem_offset = std::inner_product(begin(coordinate), end(coordinate), begin(axis_strides), 0ll); + const auto input = in + elem_offset * elem_size; + copy_element(output, input, elem_size); + output += elem_size; + } +} + +bool no_axis_reordering(const AxisVector& axis_order) { + auto tmp = axis_order; + std::sort(begin(tmp), end(tmp)); + tmp.erase(std::unique(begin(tmp), end(tmp)), end(tmp)); + return tmp == axis_order; +} } // namespace -void reshape(const char* arg, +void reshape(const char* in, char* out, const Shape& in_shape, - const AxisVector& in_axis_order, + const AxisVector& axes_order, const Shape& out_shape, size_t elem_size) { + if (no_axis_reordering(axes_order)) { + std::memcpy(out, in, shape_size(in_shape) * elem_size); + return; + } + if (shape_size(in_shape) == 1) { - std::memcpy(out, arg, elem_size); + copy_element(out, in, elem_size); return; } - char* output = out; - const char* const output_end = out + shape_size(out_shape) * elem_size; - const auto axis_strides = reorder(row_major_strides(in_shape), in_axis_order); - for (const auto& coordinate : CoordinateTransformBasic(reorder(in_shape, in_axis_order))) { - if (output >= output_end) { - break; - } - const auto elem_offset = std::inner_product(begin(coordinate), end(coordinate), begin(axis_strides), 0ll); - const auto input = arg + elem_offset * elem_size; - std::memcpy(output, input, elem_size); - output += elem_size; + switch (in_shape.size()) { + case 0: + copy_element(out, in, elem_size); + break; + case 1: + std::memcpy(out, in, in_shape[0] * elem_size); + break; + case 2: + reshape_2D(in, out, in_shape, axes_order, out_shape, elem_size); + break; + case 3: + reshape_3D(in, out, in_shape, axes_order, out_shape, elem_size); + break; + case 4: + reshape_4D(in, out, in_shape, axes_order, out_shape, elem_size); + break; + case 5: + reshape_5D(in, out, in_shape, axes_order, out_shape, elem_size); + break; + case 6: + reshape_6D(in, out, in_shape, axes_order, out_shape, elem_size); + break; + default: + reshape_ND(in, out, in_shape, axes_order, out_shape, elem_size); + break; } } } // namespace reference diff --git a/src/core/reference/src/op/shuffle_channels.cpp b/src/core/reference/src/op/shuffle_channels.cpp index 487d951153834b..bc46c80afb0962 100644 --- a/src/core/reference/src/op/shuffle_channels.cpp +++ b/src/core/reference/src/op/shuffle_channels.cpp @@ -4,7 +4,7 @@ #include "openvino/reference/shuffle_channels.hpp" -#include "ngraph/runtime/opt_kernel/reshape.hpp" +#include "openvino/reference/reshape.hpp" namespace ov { namespace reference { @@ -42,7 +42,7 @@ void shuffle_channels(const char* arg, reshaped_input_shape[1], reshaped_input_shape[3]}; AxisVector axis_vector{0, 2, 1, 3}; - ngraph::runtime::opt_kernel::reshape(arg, out, reshaped_input_shape, axis_vector, transposed_shape, elem_size); + reshape(arg, out, reshaped_input_shape, axis_vector, transposed_shape, elem_size); // Reshaped 4D tensor is interpreted as ND output tensor with original shape of data // input diff --git a/src/core/reference/src/op/space_to_depth.cpp b/src/core/reference/src/op/space_to_depth.cpp index 247efe39412362..67790a7b56a61c 100644 --- a/src/core/reference/src/op/space_to_depth.cpp +++ b/src/core/reference/src/op/space_to_depth.cpp @@ -6,8 +6,8 @@ #include -#include "ngraph/runtime/opt_kernel/reshape.hpp" #include "openvino/core/except.hpp" +#include "openvino/reference/reshape.hpp" namespace ov { namespace reference { @@ -84,7 +84,7 @@ void space_to_depth(const char* const in, post_transpose_shape[axis_idx] = dispersed_shape[axes_order[axis_idx]]; } - ngraph::runtime::opt_kernel::reshape(in, out, dispersed_shape, axes_order, post_transpose_shape, elem_size); + reshape(in, out, dispersed_shape, axes_order, post_transpose_shape, elem_size); } } // namespace reference } // namespace ov diff --git a/src/core/reference/src/op/split.cpp b/src/core/reference/src/op/split.cpp index 6186bdd5af941d..855fc29c4a1be9 100644 --- a/src/core/reference/src/op/split.cpp +++ b/src/core/reference/src/op/split.cpp @@ -6,35 +6,43 @@ #include -#include +#include -using namespace ov; +#include "openvino/core/coordinate.hpp" +#include "openvino/reference/slice.hpp" -void reference::split(const char* data, - const Shape& data_shape, - size_t elem_size, - int64_t axis, - size_t num_splits, - char** out_data) { +namespace ov { +namespace reference { + +void split(const char* data, + const Shape& data_shape, + const size_t elem_size, + const int64_t axis, + const size_t num_splits, + char** out_data) { const size_t part_length = data_shape.at(axis) / num_splits; - Shape output_shape = data_shape; - output_shape.at(axis) = part_length; + auto output_shape = data_shape; + output_shape[axis] = part_length; - std::vector lower_bounds(data_shape.size(), 0); - std::vector upper_bounds = data_shape; - upper_bounds.at(axis) = part_length; + Coordinate lower_bounds(data_shape.size(), 0); + Coordinate upper_bounds = output_shape; + auto& lb_at_axis = lower_bounds[axis]; + auto& ub_at_axis = upper_bounds[axis]; - for (size_t i = 0; i < num_splits; ++i) { + const auto out_last = std::next(out_data, num_splits); + for (auto out_first = out_data; out_first != out_last; ++out_first) { reference::slice(data, - out_data[i], + *out_first, data_shape, lower_bounds, upper_bounds, Strides(lower_bounds.size(), 1), output_shape, elem_size); - lower_bounds.at(axis) += part_length; - upper_bounds.at(axis) += part_length; + lb_at_axis += part_length; + ub_at_axis += part_length; } } +} // namespace reference +} // namespace ov diff --git a/src/core/reference/src/op/strided_slice.cpp b/src/core/reference/src/op/strided_slice.cpp index 2ff07ba8500308..cad9dee20d02be 100644 --- a/src/core/reference/src/op/strided_slice.cpp +++ b/src/core/reference/src/op/strided_slice.cpp @@ -8,18 +8,20 @@ #include -#include "ngraph/runtime/aligned_buffer.hpp" -#include "ngraph/runtime/opt_kernel/reshape.hpp" - -using namespace ov; -NGRAPH_SUPPRESS_DEPRECATED_START - -void reference::strided_slice(const char* arg, - char* out, - const Shape& arg_shape, - const op::util::SlicePlan& sp, - size_t elem_type) { - auto hasZeroDims = [](const ov::Shape& shape) -> bool { +#include "openvino/reference/reshape.hpp" +#include "openvino/reference/reverse.hpp" +#include "openvino/reference/slice.hpp" +#include "openvino/runtime/aligned_buffer.hpp" + +namespace ov { +namespace reference { + +void strided_slice(const char* arg, + char* out, + const Shape& arg_shape, + const op::util::SlicePlan& sp, + size_t elem_type) { + auto hasZeroDims = [](const Shape& shape) -> bool { return std::any_of(shape.begin(), shape.end(), [](const size_t& dim) { return dim == 0; }); @@ -28,7 +30,7 @@ void reference::strided_slice(const char* arg, return; } - ngraph::runtime::AlignedBuffer slice_out_buffer(shape_size(sp.reshape_in_shape) * elem_type); + ov::AlignedBuffer slice_out_buffer(shape_size(sp.reshape_in_shape) * elem_type); slice(reinterpret_cast(arg), slice_out_buffer.get_ptr(), arg_shape, @@ -38,13 +40,8 @@ void reference::strided_slice(const char* arg, sp.reshape_in_shape, elem_type); - ngraph::runtime::AlignedBuffer reshape_out_buffer(shape_size(sp.reshape_out_shape) * elem_type); - ngraph::runtime::opt_kernel::reshape(slice_out_buffer.get_ptr(), - reshape_out_buffer.get_ptr(), - sp.reshape_in_shape, - ngraph::get_default_order(sp.reshape_in_shape.size()), - sp.reshape_out_shape, - elem_type); + ov::AlignedBuffer reshape_out_buffer(shape_size(sp.reshape_out_shape) * elem_type); + reshape(slice_out_buffer.get_ptr(), reshape_out_buffer.get_ptr(), sp.reshape_in_shape, elem_type); reverse(reshape_out_buffer.get_ptr(), out, @@ -53,3 +50,5 @@ void reference::strided_slice(const char* arg, sp.reverse_axes, elem_type); } +} // namespace reference +} // namespace ov diff --git a/src/core/reference/src/op/tile.cpp b/src/core/reference/src/op/tile.cpp index f88e56392a26a8..0a3132e32b4807 100644 --- a/src/core/reference/src/op/tile.cpp +++ b/src/core/reference/src/op/tile.cpp @@ -5,65 +5,56 @@ #include "openvino/reference/tile.hpp" #include -#include #include -#include -using namespace ov; - -namespace { -/// \brief For each axis calculates the product of inner axes -/// If dims has shape (2, 3, 4) then for 2 (first axis) the inner axes would be (3, 4) -/// and for 3 (second axis) it would be (4) -/// If dims has shape(2, 3, 4) then the output vector would be (3 * 4, 4, 1) -/// The outermost axis is not used. For innermost axis it is always 1. -/// \param[in] dims Shape of the output -/// -/// \return Vector containing calculated values for each axis. -std::vector create_pitches(const Shape& dims) { - std::vector pitch; - pitch.resize(dims.size() - 1); - std::partial_sum(dims.rbegin(), dims.rend() - 1, pitch.rbegin(), std::multiplies()); - pitch.push_back(1); - return pitch; -} -} // namespace - -void reference::tile(const char* arg, - char* out, - const Shape& in_shape, - const Shape& out_shape, - const size_t elem_size, - const std::vector& repeats) { - Shape in_shape_expanded(in_shape); - in_shape_expanded.insert(in_shape_expanded.begin(), out_shape.size() - in_shape.size(), 1); - size_t block_size = 0; - int64_t num_repeats = 0; - const int input_rank = static_cast(in_shape_expanded.size()); - const int64_t last_dim = in_shape_expanded[input_rank - 1]; - const std::vector pitches = create_pitches(out_shape); - const char* copy = nullptr; - - std::vector indices(in_shape_expanded.size() - 1, 0); - size_t axis = indices.size(); +namespace ov { +namespace reference { +/** + * @brief Reference implementation of Tile operator + * + * @param arg Pointer to input data. + * @param out Pointer to output data. + * @param in_shape Input data shape. + * @param out_shape Output data shape. + * @param elem_size Single data element size im bytes. + * @param repeats Vector with repeats values for axes (same rank as out_shape). + */ +void tile(const char* arg, + char* out, + const Shape& in_shape, + const Shape& out_shape, + const size_t elem_size, + const std::vector& repeats) { if (std::all_of(repeats.begin(), repeats.end(), [](int64_t repeat) { return repeat == 0; })) { return; } + decltype(arg) copy_from; + typename std::decay::type block_size; + typename std::decay::type num_repeats; + + auto in_shape_expanded = in_shape; + in_shape_expanded.insert(in_shape_expanded.begin(), out_shape.size() - in_shape.size(), 1); + const auto last_dim = in_shape_expanded.back(); + const auto pitches = row_major_strides(out_shape); + + std::vector indices(in_shape_expanded.size() - 1, 0); + auto axis = indices.size(); + // Copy and repeat data for innermost axis as many times as described in the repeats parameter while (axis <= indices.size()) { block_size = last_dim * elem_size; - memcpy(out, arg, block_size); + std::memcpy(out, arg, block_size); out += block_size; arg += block_size; - copy = out - block_size; - num_repeats = repeats[input_rank - 1] - 1; + copy_from = out - block_size; + num_repeats = repeats.back() - 1; for (int64_t i = 0; i < num_repeats; ++i) { - memcpy(out, copy, block_size); + std::memcpy(out, copy_from, block_size); out += block_size; } @@ -75,14 +66,16 @@ void reference::tile(const char* arg, } indices[axis] = 0; - ptrdiff_t pitch = pitches[axis] * in_shape_expanded[axis]; + auto pitch = pitches[axis] * in_shape_expanded[axis]; block_size = pitch * elem_size; - copy = out - block_size; + copy_from = out - block_size; num_repeats = repeats[axis] - 1; - for (int64_t i = 0; i < num_repeats; i++) { - memcpy(out, copy, block_size); + for (int64_t i = 0; i < num_repeats; ++i) { + std::memcpy(out, copy_from, block_size); out += block_size; } } } } +} // namespace reference +} // namespace ov diff --git a/src/core/reference/src/op/transpose.cpp b/src/core/reference/src/op/transpose.cpp index 5b893ccc5697ed..fbc38ebde38012 100644 --- a/src/core/reference/src/op/transpose.cpp +++ b/src/core/reference/src/op/transpose.cpp @@ -9,8 +9,8 @@ #include #include -#include "ngraph/runtime/opt_kernel/reshape.hpp" #include "openvino/core/shape.hpp" +#include "openvino/reference/reshape.hpp" namespace ov { namespace reference { @@ -20,10 +20,10 @@ void transpose(const char* data, size_t element_size, const int64_t* axes_order, Shape out_shape) { - // To reuse opt_kernel::reshape axes order vector has to be converted to AxisVector + // To reuse reference::reshape axes order vector has to be converted to AxisVector // Negative axes are not supported, it is validated by transpose evaluate method std::vector axis_vector(axes_order, axes_order + data_shape.size()); - ngraph::runtime::opt_kernel::reshape(data, out, data_shape, axis_vector, out_shape, element_size); + reshape(data, out, data_shape, axis_vector, out_shape, element_size); } } // namespace reference } // namespace ov diff --git a/src/core/reference/src/runtime/opt_kernel/reshape.cpp b/src/core/reference/src/runtime/opt_kernel/reshape.cpp deleted file mode 100644 index e0ca720845c3a0..00000000000000 --- a/src/core/reference/src/runtime/opt_kernel/reshape.cpp +++ /dev/null @@ -1,375 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "ngraph/runtime/opt_kernel/reshape.hpp" - -#include -#include - -#include "openvino/core/parallel.hpp" -#include "openvino/reference/reshape.hpp" - -using namespace ngraph; - -namespace { -void reshape_in0(const char* in, - char* out, - const Shape& in_shape, - const AxisVector& in_axis_order, - const Shape& out_shape, - size_t elem_size) { - memcpy(out, in, elem_size); -} - -void reshape_in1(const char* in, - char* out, - const Shape& in_shape, - const AxisVector& in_axis_order, - const Shape& out_shape, - size_t elem_size) { - size_t size[1]; - size_t in_index[1]; - size_t* map_index[1]; - for (size_t i = 0; i < 1; i++) { - size[i] = in_shape[in_axis_order[i]]; - map_index[in_axis_order[i]] = &in_index[i]; - } - for (in_index[0] = 0; in_index[0] < size[0]; ++in_index[0]) { - memcpy(out, in + *map_index[0] * elem_size, elem_size); - out += elem_size; - } -} - -static size_t get_threshold() { - // TODO: find a better way, not hardcoded value - return (1 << 9) * parallel_get_num_threads(); -} - -static inline void copy_element(char* out, const char* in, size_t elem_size) { -#define CASE(type) \ - case sizeof(type): \ - *reinterpret_cast(out) = *reinterpret_cast(in); \ - break; - - switch (elem_size) { - CASE(int32_t) - CASE(int64_t) - CASE(int16_t) - CASE(int8_t) - default: - std::memcpy(out, in, elem_size); - break; - } -#undef CASE -} - -void reshape_in2(const char* in, - char* out, - const Shape& in_shape, - const AxisVector& in_axis_order, - const Shape& out_shape, - size_t elem_size) { - size_t num_elements = shape_size(in_shape); - if (num_elements <= get_threshold()) { - for (size_t i = 0; i < out_shape[0]; i++) { - size_t off = i; - for (size_t j = 0; j < out_shape[1]; j++) { - copy_element(out, in + off * elem_size, elem_size); - out += elem_size; - off += out_shape[0]; - } - } - } else { - ov::parallel_for2d(out_shape[0], out_shape[1], [in, out, &out_shape, elem_size](size_t i, size_t j) { - size_t in_off = j * out_shape[0] + i; - size_t out_off = i * out_shape[1] + j; - copy_element(out + out_off * elem_size, in + in_off * elem_size, elem_size); - }); - } -} - -static std::vector get_strides(size_t rank, size_t elem_size, const AxisVector& order, const Shape& in_shape) { - std::vector rev_order(rank); - for (size_t i = 0; i < rank; i++) { - rev_order[order[i]] = i; - } - - std::vector strides(rank); - strides[rev_order[rank - 1]] = elem_size; - for (size_t i = rank - 1; i > 0; i--) { - strides[rev_order[i - 1]] = strides[rev_order[i]] * in_shape[i]; - } - - return strides; -} - -void reshape_in3(const char* in, - char* out, - const Shape& in_shape, - const AxisVector& in_axis_order, - const Shape& out_shape, - size_t elem_size) { - size_t num_elements = shape_size(in_shape); - if (num_elements <= get_threshold()) { - const auto strides = get_strides(3, elem_size, in_axis_order, in_shape); - - size_t off_0 = 0; - for (size_t i = 0; i < out_shape[0]; i++) { - size_t off_1 = off_0; - for (size_t j = 0; j < out_shape[1]; j++) { - size_t in_off = off_1; - for (size_t k = 0; k < out_shape[2]; k++) { - copy_element(out, in + in_off, elem_size); - out += elem_size; - in_off += strides[2]; - } - off_1 += strides[1]; - } - off_0 += strides[0]; - } - } else { - ov::parallel_for3d(out_shape[0], - out_shape[1], - out_shape[2], - [in, out, in_axis_order, &in_shape, &out_shape, elem_size](size_t i, size_t j, size_t k) { - size_t in_indexes[3]; - in_indexes[in_axis_order[0]] = i; - in_indexes[in_axis_order[1]] = j; - in_indexes[in_axis_order[2]] = k; - size_t in_off = - (in_indexes[0] * in_shape[1] + in_indexes[1]) * in_shape[2] + in_indexes[2]; - size_t out_off = (i * out_shape[1] + j) * out_shape[2] + k; - copy_element(out + out_off * elem_size, in + in_off * elem_size, elem_size); - }); - } -} - -void reshape_in4(const char* in, - char* out, - const Shape& in_shape, - const AxisVector& in_axis_order, - const Shape& out_shape, - size_t elem_size) { - size_t num_elements = shape_size(in_shape); - if (num_elements <= get_threshold()) { - const auto strides = get_strides(4, elem_size, in_axis_order, in_shape); - - size_t off_0 = 0; - for (size_t i = 0; i < out_shape[0]; i++) { - size_t off_1 = off_0; - for (size_t j = 0; j < out_shape[1]; j++) { - size_t off_2 = off_1; - for (size_t k = 0; k < out_shape[2]; k++) { - size_t in_off = off_2; - for (size_t l = 0; l < out_shape[3]; l++) { - copy_element(out, in + in_off, elem_size); - out += elem_size; - in_off += strides[3]; - } - off_2 += strides[2]; - } - off_1 += strides[1]; - } - off_0 += strides[0]; - } - } else { - ov::parallel_for4d( - out_shape[0], - out_shape[1], - out_shape[2], - out_shape[3], - [in, out, in_axis_order, &in_shape, &out_shape, elem_size](size_t i, size_t j, size_t k, size_t l) { - size_t in_indexes[4]; - in_indexes[in_axis_order[0]] = i; - in_indexes[in_axis_order[1]] = j; - in_indexes[in_axis_order[2]] = k; - in_indexes[in_axis_order[3]] = l; - size_t in_off = - ((in_indexes[0] * in_shape[1] + in_indexes[1]) * in_shape[2] + in_indexes[2]) * in_shape[3] + - in_indexes[3]; - size_t out_off = ((i * out_shape[1] + j) * out_shape[2] + k) * out_shape[3] + l; - copy_element(out + out_off * elem_size, in + in_off * elem_size, elem_size); - }); - } -} - -void reshape_in5(const char* in, - char* out, - const Shape& in_shape, - const AxisVector& in_axis_order, - const Shape& out_shape, - size_t elem_size) { - size_t num_elements = shape_size(in_shape); - if (num_elements <= get_threshold()) { - const auto strides = get_strides(5, elem_size, in_axis_order, in_shape); - - size_t off_0 = 0; - for (size_t i = 0; i < out_shape[0]; i++) { - size_t off_1 = off_0; - for (size_t j = 0; j < out_shape[1]; j++) { - size_t off_2 = off_1; - for (size_t k = 0; k < out_shape[2]; k++) { - size_t off_3 = off_2; - for (size_t l = 0; l < out_shape[3]; l++) { - size_t in_off = off_3; - for (size_t m = 0; m < out_shape[4]; m++) { - copy_element(out, in + in_off, elem_size); - out += elem_size; - in_off += strides[4]; - } - off_3 += strides[3]; - } - off_2 += strides[2]; - } - off_1 += strides[1]; - } - off_0 += strides[0]; - } - } else { - ov::parallel_for5d( - out_shape[0], - out_shape[1], - out_shape[2], - out_shape[3], - out_shape[4], - [in, out, in_axis_order, &in_shape, &out_shape, elem_size](size_t i, - size_t j, - size_t k, - size_t l, - size_t m) { - size_t in_indexes[5]; - in_indexes[in_axis_order[0]] = i; - in_indexes[in_axis_order[1]] = j; - in_indexes[in_axis_order[2]] = k; - in_indexes[in_axis_order[3]] = l; - in_indexes[in_axis_order[4]] = m; - size_t in_off = - (((in_indexes[0] * in_shape[1] + in_indexes[1]) * in_shape[2] + in_indexes[2]) * in_shape[3] + - in_indexes[3]) * - in_shape[4] + - in_indexes[4]; - size_t out_off = (((i * out_shape[1] + j) * out_shape[2] + k) * out_shape[3] + l) * out_shape[4] + m; - copy_element(out + out_off * elem_size, in + in_off * elem_size, elem_size); - }); - } -} - -void reshape_in6(const char* in, - char* out, - const Shape& in_shape, - const AxisVector& in_axis_order, - const Shape& out_shape, - size_t elem_size) { - size_t num_elements = shape_size(in_shape); - if (num_elements <= get_threshold()) { - const auto strides = get_strides(6, elem_size, in_axis_order, in_shape); - - size_t off_0 = 0; - for (size_t i = 0; i < out_shape[0]; i++) { - size_t off_1 = off_0; - for (size_t j = 0; j < out_shape[1]; j++) { - size_t off_2 = off_1; - for (size_t k = 0; k < out_shape[2]; k++) { - size_t off_3 = off_2; - for (size_t l = 0; l < out_shape[3]; l++) { - size_t off_4 = off_3; - for (size_t m = 0; m < out_shape[4]; m++) { - size_t in_off = off_4; - for (size_t n = 0; n < out_shape[5]; n++) { - copy_element(out, in + in_off, elem_size); - out += elem_size; - in_off += strides[5]; - } - off_4 += strides[4]; - } - off_3 += strides[3]; - } - off_2 += strides[2]; - } - off_1 += strides[1]; - } - off_0 += strides[0]; - } - } else { - ov::parallel_for6d( - out_shape[0], - out_shape[1], - out_shape[2], - out_shape[3], - out_shape[4], - out_shape[5], - [in, out, in_axis_order, &in_shape, &out_shape, elem_size](size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n) { - size_t in_indexes[6]; - in_indexes[in_axis_order[0]] = i; - in_indexes[in_axis_order[1]] = j; - in_indexes[in_axis_order[2]] = k; - in_indexes[in_axis_order[3]] = l; - in_indexes[in_axis_order[4]] = m; - in_indexes[in_axis_order[5]] = n; - size_t in_off = - ((((in_indexes[0] * in_shape[1] + in_indexes[1]) * in_shape[2] + in_indexes[2]) * in_shape[3] + - in_indexes[3]) * - in_shape[4] + - in_indexes[4]) * - in_shape[5] + - in_indexes[5]; - size_t out_off = ((((i * out_shape[1] + j) * out_shape[2] + k) * out_shape[3] + l) * out_shape[4] + m) * - out_shape[5] + - n; - copy_element(out + out_off * elem_size, in + in_off * elem_size, elem_size); - }); - } -} - -bool no_axis_reordering(const AxisVector& axis_order) { - auto tmp = axis_order; - std::sort(begin(tmp), end(tmp)); - tmp.erase(std::unique(begin(tmp), end(tmp)), end(tmp)); - return tmp == axis_order; -} - -} // namespace -void runtime::opt_kernel::reshape(const char* in, - char* out, - const Shape& in_shape, - const AxisVector& in_axis_order, - const Shape& out_shape, - size_t elem_size) { - if (no_axis_reordering(in_axis_order)) { - std::memcpy(out, in, shape_size(in_shape) * elem_size); - return; - } - - switch (in_shape.size()) { - case 0: - reshape_in0(in, out, in_shape, in_axis_order, out_shape, elem_size); - break; - case 1: - reshape_in1(in, out, in_shape, in_axis_order, out_shape, elem_size); - break; - case 2: - reshape_in2(in, out, in_shape, in_axis_order, out_shape, elem_size); - break; - case 3: - reshape_in3(in, out, in_shape, in_axis_order, out_shape, elem_size); - break; - case 4: - reshape_in4(in, out, in_shape, in_axis_order, out_shape, elem_size); - break; - case 5: - reshape_in5(in, out, in_shape, in_axis_order, out_shape, elem_size); - break; - case 6: - reshape_in6(in, out, in_shape, in_axis_order, out_shape, elem_size); - break; - default: - ov::reference::reshape(in, out, in_shape, in_axis_order, out_shape, elem_size); - break; - } -} diff --git a/src/core/shape_inference/CMakeLists.txt b/src/core/shape_inference/CMakeLists.txt index b04f0cf8573b85..db862ac520d0b5 100644 --- a/src/core/shape_inference/CMakeLists.txt +++ b/src/core/shape_inference/CMakeLists.txt @@ -4,11 +4,11 @@ set(TARGET_NAME "openvino_shape_inference") -file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) -file(GLOB_RECURSE PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp) - set(SHAPE_INFER_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") +file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) +file(GLOB_RECURSE PUBLIC_HEADERS ${SHAPE_INFER_INCLUDE_DIR}/*.hpp) + # Create named folders for the sources within the .vcproj # Empty name lists them directly under the .vcproj @@ -24,7 +24,7 @@ set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME shape_inference) target_include_directories(${TARGET_NAME} PUBLIC $ $ - $>) + $) ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}) @@ -32,7 +32,9 @@ if(NOT BUILD_SHARED_LIBS) target_compile_definitions(${TARGET_NAME} PUBLIC OPENVINO_STATIC_LIBRARY) endif() +# developer package + ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE}) -# developer package -openvino_developer_export_targets(COMPONENT core TARGETS ${TARGET_NAME}) +ov_developer_package_export_targets(TARGET ${TARGET_NAME} + INSTALL_INCLUDE_DIRECTORIES "${SHAPE_INFER_INCLUDE_DIR}/") diff --git a/src/core/src/bound_evaluate.cpp b/src/core/src/bound_evaluate.cpp index cf3dc5bf21e3da..1b1093b871c657 100644 --- a/src/core/src/bound_evaluate.cpp +++ b/src/core/src/bound_evaluate.cpp @@ -479,13 +479,13 @@ bool ov::interval_bound_evaluator(const Node* node, return fully_defined; } -bool ov::tensor_is_positive(const Tensor& bound) { +bool ov::tensor_is_non_negative(const Tensor& bound) { const auto bound_constant = std::make_shared(bound.get_element_type(), bound.get_shape(), bound.data()); const auto zero_constant = op::v0::Constant::create(bound.get_element_type(), {1}, {0}); OutputVector greater(1); - bool folded = std::make_shared(bound_constant, zero_constant) + bool folded = std::make_shared(bound_constant, zero_constant) ->constant_fold(greater, {bound_constant, zero_constant}); OPENVINO_ASSERT(folded); @@ -500,6 +500,50 @@ bool ov::tensor_is_positive(const Tensor& bound) { return std::dynamic_pointer_cast(all[0].get_node_shared_ptr())->cast_vector()[0]; } +bool ov::tensor_has_max_value(const Tensor& bound) { + const auto bound_constant = + std::make_shared(bound.get_element_type(), bound.get_shape(), bound.data()); + OPENVINO_SUPPRESS_DEPRECATED_START + auto max_constant = ngraph::get_constant_max_of_type(bound.get_element_type()); + OPENVINO_SUPPRESS_DEPRECATED_END + OutputVector equal(1); + + bool folded = std::make_shared(bound_constant, max_constant) + ->constant_fold(equal, {bound_constant, max_constant}); + OPENVINO_ASSERT(folded); + + auto axes_vector = std::vector(equal[0].get_shape().size()); + std::iota(axes_vector.begin(), axes_vector.end(), 0); + const auto axes = op::v0::Constant::create(element::i64, {axes_vector.size()}, axes_vector); + + OutputVector all(1); + folded = std::make_shared(equal[0], axes)->constant_fold(all, {equal[0], axes}); + OPENVINO_ASSERT(folded && ov::is_type(all[0].get_node_shared_ptr())); + OPENVINO_ASSERT(all[0].get_shape() == Shape{}); + return std::dynamic_pointer_cast(all[0].get_node_shared_ptr())->cast_vector()[0]; +} + +bool ov::tensor_has_zero_value(const Tensor& bound) { + const auto bound_constant = + std::make_shared(bound.get_element_type(), bound.get_shape(), bound.data()); + const auto zero_constant = op::v0::Constant::create(bound.get_element_type(), {1}, {0}); + OutputVector equal(1); + + bool folded = std::make_shared(bound_constant, zero_constant) + ->constant_fold(equal, {bound_constant, zero_constant}); + OPENVINO_ASSERT(folded); + + auto axes_vector = std::vector(equal[0].get_shape().size()); + std::iota(axes_vector.begin(), axes_vector.end(), 0); + const auto axes = op::v0::Constant::create(element::i64, {axes_vector.size()}, axes_vector); + + OutputVector all(1); + folded = std::make_shared(equal[0], axes)->constant_fold(all, {equal[0], axes}); + OPENVINO_ASSERT(folded && ov::is_type(all[0].get_node_shared_ptr())); + OPENVINO_ASSERT(all[0].get_shape() == Shape{}); + return std::dynamic_pointer_cast(all[0].get_node_shared_ptr())->cast_vector()[0]; +} + bool ov::has_and_set_equal_bounds(const Output& source) { if (op::util::is_constant(source.get_node_shared_ptr())) return true; @@ -509,7 +553,7 @@ bool ov::has_and_set_equal_bounds(const Output& source) { } bool ov::have_node_inputs_bounds_set(const Node* const node, const size_t first_idx, const size_t last_idx) { - bool have_bound_set = last_idx <= node->get_input_size(); + bool have_bound_set = last_idx < node->get_input_size(); for (size_t i = first_idx; have_bound_set && (i <= last_idx); ++i) { have_bound_set = node->get_input_tensor(i).has_and_set_bound(); } diff --git a/src/core/src/bound_evaluate.hpp b/src/core/src/bound_evaluate.hpp index 297f69d661f131..952343a7d0076b 100644 --- a/src/core/src/bound_evaluate.hpp +++ b/src/core/src/bound_evaluate.hpp @@ -9,8 +9,14 @@ namespace ov { // bool could_propagate(const Output& output, std::vector& order); -/// \brief Checks if all the elements of the bound Tensor are positive -bool tensor_is_positive(const Tensor& bound); +/// \brief Checks if all the elements of the bound Tensor are non-negative +bool tensor_is_non_negative(const Tensor& bound); + +/// \brief Checks if any element of the bound Tensor has max possible value +bool tensor_has_max_value(const Tensor& bound); + +/// \brief Checks if any element of the bound Tensor has zero value +bool tensor_has_zero_value(const Tensor& bound); /// \brief Estimates upper bound for node output tensors using only upper bounds of the nodes /// inputs. diff --git a/src/core/src/graph_util.cpp b/src/core/src/graph_util.cpp index 93457bd17083e3..4c6a4d0f33e516 100644 --- a/src/core/src/graph_util.cpp +++ b/src/core/src/graph_util.cpp @@ -10,30 +10,17 @@ #include #include -#include "ngraph/descriptor/input.hpp" -#include "ngraph/descriptor/output.hpp" -#include "ngraph/function.hpp" -#include "ngraph/log.hpp" -#include "ngraph/node.hpp" -#include "ngraph/op/broadcast.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/op/parameter.hpp" -#include "ngraph/op/result.hpp" -#include "ngraph/op/tensor_iterator.hpp" -#include "ngraph/op/util/op_types.hpp" -#include "ngraph/opsets/opset5.hpp" -#include "ngraph/opsets/opset8.hpp" -#include "ngraph/pass/manager.hpp" -#include "ngraph/pass/visualize_tree.hpp" -#include "ngraph/rt_info.hpp" -#include "ngraph/util.hpp" #include "openvino/core/descriptor/tensor.hpp" +#include "openvino/core/rt_info.hpp" +#include "openvino/op/broadcast.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/util/op_types.hpp" +#include "openvino/pass/manager.hpp" +#include "openvino/pass/visualize_tree.hpp" #include "transformations/common_optimizations/compress_float_constants.hpp" #include "transformations/common_optimizations/fused_names_cleanup.hpp" #include "transformations/common_optimizations/mark_precision_sensitive_shapeof_subgraphs.hpp" -using namespace std; - namespace { void clone_ov_nodes(const std::vector>& nodes, @@ -49,7 +36,7 @@ void clone_ov_nodes(const std::vector>& nodes, } std::vector> cloned_dependencies; for (const auto& dependency : node->get_control_dependencies()) { - shared_ptr& dependent = node_map.at(dependency.get()); + std::shared_ptr& dependent = node_map.at(dependency.get()); if (find(cloned_dependencies.begin(), cloned_dependencies.end(), dependent) == cloned_dependencies.end()) { cloned_dependencies.push_back(dependent); @@ -161,7 +148,7 @@ void replace_node(const std::shared_ptr& target, const OutputVector& repla OPENVINO_ASSERT(target->get_output_size() == replacement_values.size()); - unordered_set> replacement_nodes; + std::unordered_set> replacement_nodes; // For each of target's output O with replacement output O_rep: // For each O's connected downstream input I: // Change I's connected upstream output to O_rep @@ -179,15 +166,15 @@ void replace_node(const std::shared_ptr& target, const OutputVector& repla } void replace_node(const std::shared_ptr& target, const std::shared_ptr& replacement) { - auto default_output_order = vector(target->get_output_size()); + auto default_output_order = std::vector(target->get_output_size()); std::iota(default_output_order.begin(), default_output_order.end(), 0); replace_node(target, replacement, default_output_order); } void replace_nodes(const std::shared_ptr& f, - const unordered_map, shared_ptr>& - parameter_replacement_map, - const unordered_map, shared_ptr>& body_replacement_map) { + const std::unordered_map, + std::shared_ptr>& parameter_replacement_map, + const std::unordered_map, std::shared_ptr>& body_replacement_map) { auto& params = f->get_parameters(); for (size_t i = 0; i < params.size(); i++) { @@ -231,7 +218,7 @@ std::shared_ptr clone_ov_model(const Model& func, std::unordered_map node : func.get_results()) { + for (std::shared_ptr node : func.get_results()) { auto result = ov::as_type_ptr(node_map.at(node.get())); if (!result) { OPENVINO_THROW("Results should be of type op::Result"); @@ -240,7 +227,7 @@ std::shared_ptr clone_ov_model(const Model& func, std::unordered_map(node_map.at(node.get()))); + cloned_sinks.push_back(std::static_pointer_cast(node_map.at(node.get()))); } std::vector> cloned_params; @@ -273,8 +260,8 @@ bool compare_constants(const std::shared_ptr& n1, const std::shared_ptr(n1)->get_value_strings() != - static_pointer_cast(n2)->get_value_strings()) { + if (std::static_pointer_cast(n1)->get_value_strings() != + std::static_pointer_cast(n2)->get_value_strings()) { return false; } @@ -332,7 +319,8 @@ bool replace_output_update_name(Output output, const Output& replace bool replace_node_update_name(const std::shared_ptr& target, const std::shared_ptr& replacement) { for (auto& output : target->output(0).get_target_inputs()) { - if (ov::as_type(replacement->input_value(0).get_node()) && + if (replacement->get_input_size() > 0 && + ov::as_type(replacement->input_value(0).get_node()) && ov::as_type(output.get_node())) { return false; } @@ -368,7 +356,8 @@ void save_model(const std::shared_ptr& m, const std::string& ou OPENVINO_SUPPRESS_DEPRECATED_START -ngraph::NodeVector ngraph::find_common_args(std::shared_ptr node1, std::shared_ptr node2) { +namespace ngraph { +ov::NodeVector find_common_args(std::shared_ptr node1, std::shared_ptr node2) { std::unordered_set> node1_args; auto compute_node1_args = [&node1_args](const std::shared_ptr& node) { @@ -396,15 +385,15 @@ ngraph::NodeVector ngraph::find_common_args(std::shared_ptr node1, std::sh } // Check if all paths from X to a result go through Y -bool ngraph::is_post_dominated(Node* X, Node* Y) { +bool is_post_dominated(Node* X, Node* Y) { std::unordered_set visited; std::stack> stack; stack.push(X); while (stack.size() > 0) { - ngraph::Node* curr = stack.top(); + ov::Node* curr = stack.top(); visited.insert(curr); - if (ngraph::op::is_output(curr)) { + if (ov::op::util::is_output(curr)) { return false; } stack.pop(); @@ -419,8 +408,8 @@ bool ngraph::is_post_dominated(Node* X, Node* Y) { return true; } -std::vector> ngraph::clone_nodes(const std::vector>& nodes, - NodeMap& node_map) { +std::vector> clone_nodes(const std::vector>& nodes, + NodeMap& node_map) { // for each node in topological order auto sorted_nodes = topological_sort(nodes); for (const auto& node : sorted_nodes) { @@ -433,7 +422,7 @@ std::vector> ngraph::clone_nodes(const std::vector } std::vector> cloned_dependencies; for (auto& dependency : node->get_control_dependencies()) { - shared_ptr& dependent = node_map.at(dependency.get()); + std::shared_ptr& dependent = node_map.at(dependency.get()); if (find(cloned_dependencies.begin(), cloned_dependencies.end(), dependent) == cloned_dependencies.end()) { cloned_dependencies.push_back(dependent); @@ -463,18 +452,18 @@ std::vector> ngraph::clone_nodes(const std::vector // create and return vector of cloned nodes // order matches input vector (not necessarily topological) - std::vector> cloned_nodes; + std::vector> cloned_nodes; for (const auto& node : nodes) { cloned_nodes.push_back(node_map.at(node.get())); } return cloned_nodes; } -std::list> ngraph::clone_nodes(const std::vector>& nodes, - RawNodeOutputMap& output_map) { +std::list> clone_nodes(const std::vector>& nodes, + RawNodeOutputMap& output_map) { // for each node in topological order auto sorted_nodes = topological_sort(nodes); - std::list> cloned_nodes; + std::list> cloned_nodes; for (const auto& node : sorted_nodes) { auto node_outputs = node->outputs(); for (const auto& value : node_outputs) { @@ -488,7 +477,7 @@ std::list> ngraph::clone_nodes(const std::vectorget_control_dependencies()) { for (const auto& dependency_value : dependency->outputs()) { - shared_ptr dependent = output_map.at(dependency_value).get_node_shared_ptr(); + std::shared_ptr dependent = output_map.at(dependency_value).get_node_shared_ptr(); if (find(cloned_dependencies.begin(), cloned_dependencies.end(), dependent) == cloned_dependencies.end()) { cloned_dependencies.push_back(dependent); @@ -514,8 +503,8 @@ std::list> ngraph::clone_nodes(const std::vector& reduce_constant) { - if (auto rc = ov::as_type_ptr(reduce_constant.get_node_shared_ptr())) { +bool is_equal_to_const_value(const std::string& const_value, const Output& reduce_constant) { + if (auto rc = ov::as_type_ptr(reduce_constant.get_node_shared_ptr())) { return (rc->get_all_data_elements_bitwise_identical() && rc->convert_value_to_string(0) == const_value); } else { return false; @@ -535,28 +524,28 @@ bool ngraph::is_equal_to_const_value(const std::string& const_value, const Outpu // | +------[2]------> | | | +------[6]------> | | +------[10]-----> | // | <------[3]------+ | | | <------[7]------+ | | <------[11]-----+ | // +-----+ +-----+ | +-----+ +-----+ +-----+ +-----+ -pair, shared_ptr> ngraph::insert_result_parameter_split( - const shared_ptr& src_node, - const shared_ptr& dst_node) { +std::pair, std::shared_ptr> insert_result_parameter_split( + const std::shared_ptr& src_node, + const std::shared_ptr& dst_node) { if (src_node->get_output_size() != 1) { OPENVINO_THROW("Multiple output per op not supported in graph partition yet."); } // Make parameter node - shared_ptr par_node = - make_shared(src_node->get_output_element_type(0), src_node->get_output_shape(0)); + std::shared_ptr par_node = + std::make_shared(src_node->get_output_element_type(0), src_node->get_output_shape(0)); // Fix input / output among src, dst and par std::vector> dst_inputs = get_inputs_from(*src_node, *dst_node); - NGRAPH_CHECK(dst_inputs.size() == 1, - "insert_result_parameter_split encountered more than " - "one input between the source and destination nodes"); + OPENVINO_ASSERT(dst_inputs.size() == 1, + "insert_result_parameter_split encountered more than " + "one input between the source and destination nodes"); auto& dst_input = dst_inputs[0]; std::vector> src_outputs = get_outputs_to(*src_node, *dst_node); - NGRAPH_CHECK(src_outputs.size() == 1, - "insert_result_parameter_split encountered more than " - "one output between the source and destination nodes"); + OPENVINO_ASSERT(src_outputs.size() == 1, + "insert_result_parameter_split encountered more than " + "one output between the source and destination nodes"); auto& src_output = src_outputs[0]; // Remove [0] @@ -567,7 +556,7 @@ pair, shared_ptr> ngraph:: // Add res node // Add [4], [5], [6], [7] - shared_ptr res_node = make_shared(src_node); + std::shared_ptr res_node = std::make_shared(src_node); return make_pair(res_node, par_node); } @@ -612,58 +601,59 @@ pair, shared_ptr> ngraph:: // Typically new_node is connected to src_node already. The reason we don't create `new_node` // inside the function and return it (similar to ngraph::insert_result_parameter_split) is that // we'll have to templatize its function to call new_node's constructor. -void ngraph::insert_new_node_between(const shared_ptr& src_node, - const shared_ptr& dst_node, - const shared_ptr& new_node) { +void insert_new_node_between(const std::shared_ptr& src_node, + const std::shared_ptr& dst_node, + const std::shared_ptr& new_node) { // Fix input / output std::vector> dst_inputs = get_inputs_from(*src_node, *dst_node); - NGRAPH_CHECK(dst_inputs.size() == 1, - "insert_new_node_between encountered more than one " - "input between the source and destination nodes"); + OPENVINO_ASSERT(dst_inputs.size() == 1, + "insert_new_node_between encountered more than one " + "input between the source and destination nodes"); auto& dst_input = dst_inputs[0]; std::vector> src_outputs = get_outputs_to(*src_node, *dst_node); - NGRAPH_CHECK(src_outputs.size() == 1, - "insert_new_node_between encountered more than one " - "output between the source and destination nodes"); + OPENVINO_ASSERT(src_outputs.size() == 1, + "insert_new_node_between encountered more than one " + "output between the source and destination nodes"); auto& src_output = src_outputs[0]; src_output.remove_target_input(dst_input); // Remove [0] dst_input.replace_source_output(new_node->output(0)); // Remove [0] (again), add [8], remove [1], add [9] } -std::shared_ptr ngraph::make_zero(const element::Type& element_type, const Shape& shape) { - auto zero = op::Constant::create(element_type, Shape{}, {0.0}); +std::shared_ptr make_zero(const element::Type& element_type, const Shape& shape) { + auto zero = ov::op::v0::Constant::create(element_type, Shape{}, {0.0}); if (shape.size() > 0) { - return std::make_shared(zero, - op::Constant::create(element::u64, Shape{shape.size()}, shape)); + return std::make_shared( + zero, + op::v0::Constant::create(element::u64, Shape{shape.size()}, shape)); } return zero; } -std::shared_ptr ngraph::make_constant_from_string(std::string val, - const element::Type& element_type, - const Shape& shape) { +std::shared_ptr make_constant_from_string(std::string val, + const element::Type& element_type, + const Shape& shape) { auto cvals = std::vector(shape_size(shape), val); - return std::make_shared(element_type, shape, cvals); + return std::make_shared(element_type, shape, cvals); } -bool ngraph::is_zero(const Output& reduce_constant) { +bool is_zero(const Output& reduce_constant) { auto result_bool = is_equal_to_const_value("0", reduce_constant); return result_bool; } -bool ngraph::is_one(const Output& reduce_constant) { +bool is_one(const Output& reduce_constant) { auto result_bool = is_equal_to_const_value("1", reduce_constant); return result_bool; } -ngraph::NodeVector ngraph::get_subgraph_outputs(const NodeVector& nodes, - const NodeVector& exclusions, - bool ignore_unused, - bool ignore_output_duplicates) { - std::set> exclusions_set(exclusions.begin(), exclusions.end()); - std::set> nodes_set(nodes.begin(), nodes.end()); +ov::NodeVector get_subgraph_outputs(const NodeVector& nodes, + const NodeVector& exclusions, + bool ignore_unused, + bool ignore_output_duplicates) { + std::set> exclusions_set(exclusions.begin(), exclusions.end()); + std::set> nodes_set(nodes.begin(), nodes.end()); NodeVector outputs; @@ -684,7 +674,7 @@ ngraph::NodeVector ngraph::get_subgraph_outputs(const NodeVector& nodes, return outputs; } -ngraph::NodeVector ngraph::extract_subgraph(const NodeVector& results, const NodeVector& args) { +ov::NodeVector extract_subgraph(const NodeVector& results, const NodeVector& args) { NodeVector subgraph; traverse_nodes( results, @@ -695,15 +685,15 @@ ngraph::NodeVector ngraph::extract_subgraph(const NodeVector& results, const Nod return subgraph; } -bool ngraph::is_used(Node* node) { +bool is_used(Node* node) { std::unordered_set instances_seen; std::stack> stack; stack.push(node); while (stack.size() > 0) { - ngraph::Node* n = stack.top(); + ov::Node* n = stack.top(); if (instances_seen.count(n) == 0) { - if (ngraph::op::is_output(n)) { + if (ov::op::util::is_output(n)) { return true; } instances_seen.insert(n); @@ -718,7 +708,7 @@ bool ngraph::is_used(Node* node) { return false; } -size_t ngraph::get_user_count(Node* node) { +size_t get_user_count(Node* node) { size_t count = 0; for (const auto& node_user : node->get_users()) { count += is_used(node_user.get()); @@ -726,13 +716,13 @@ size_t ngraph::get_user_count(Node* node) { return count; } -bool ngraph::is_strided(const Strides& strides) { +bool is_strided(const Strides& strides) { return std::any_of(strides.begin(), strides.end(), [](size_t stride) { return stride != 1; }); } -bool ngraph::is_valid_rank(const std::shared_ptr& node, std::vector valid_ranks) { +bool is_valid_rank(const std::shared_ptr& node, std::vector valid_ranks) { auto node_rank = node->get_shape().size(); for (auto rank : valid_ranks) { if (rank == node_rank) { @@ -742,15 +732,15 @@ bool ngraph::is_valid_rank(const std::shared_ptr& node, std::vector f, - const std::string& filename, - std::function& attributes)> attributes) { - ngraph::pass::Manager pass_manager; - pass_manager.register_pass(filename, attributes); +void plot_graph(std::shared_ptr f, + const std::string& filename, + std::function& attributes)> attributes) { + ov::pass::Manager pass_manager; + pass_manager.register_pass(filename, attributes); pass_manager.run_passes(std::move(f)); } -std::vector> ngraph::get_inputs_from(Node& src, Node& dst) { +std::vector> get_inputs_from(Node& src, Node& dst) { std::vector> result; for (auto& input : dst.inputs()) { @@ -762,7 +752,7 @@ std::vector> ngraph::get_inputs_from(Node& src, Node return result; } -std::vector> ngraph::get_outputs_to(Node& src, Node& dst) { +std::vector> get_outputs_to(Node& src, Node& dst) { std::vector> result; for (auto& output : src.outputs()) { @@ -783,10 +773,10 @@ std::vector> ngraph::get_outputs_to(Node& src, Node return result; } -static bool check_for_cycles_bkwd(const std::shared_ptr& node, - std::deque>& path, - std::unordered_set>& path_set, - ngraph::NodeVector& cycle_nodes) { +static bool check_for_cycles_bkwd(const std::shared_ptr& node, + std::deque>& path, + std::unordered_set>& path_set, + ov::NodeVector& cycle_nodes) { path.push_back(node); path_set.insert(node); for (size_t i = 0; i < node->inputs().size(); i++) { @@ -808,10 +798,10 @@ static bool check_for_cycles_bkwd(const std::shared_ptr& node, return false; } -static bool check_for_cycles_fwd(const std::shared_ptr& node, - std::deque>& path, - std::unordered_set>& path_set, - ngraph::NodeVector& cycle_nodes) { +static bool check_for_cycles_fwd(const std::shared_ptr& node, + std::deque>& path, + std::unordered_set>& path_set, + ov::NodeVector& cycle_nodes) { path.push_back(node); path_set.insert(node); for (auto& arg : node->get_users()) { @@ -832,7 +822,7 @@ static bool check_for_cycles_fwd(const std::shared_ptr& node, return false; } -bool ngraph::check_for_cycles(const ngraph::Function* func, ngraph::NodeVector& cycle_nodes, bool& is_bkwd_cycle) { +bool check_for_cycles(const ov::Model* func, ov::NodeVector& cycle_nodes, bool& is_bkwd_cycle) { for (const auto& res : func->get_results()) { std::deque> path; // mirror of path stack for faster cycle check @@ -865,3 +855,5 @@ bool ngraph::check_for_cycles(const ngraph::Function* func, ngraph::NodeVector& // no cycles return false; } + +} // namespace ngraph diff --git a/src/core/src/node.cpp b/src/core/src/node.cpp index ee2c454bb6a235..492f0dec1e3a04 100644 --- a/src/core/src/node.cpp +++ b/src/core/src/node.cpp @@ -844,6 +844,17 @@ bool ov::Node::visit_attributes(AttributeVisitor&) { } namespace ov { +void check_new_args_count(const Node* const node, const OutputVector& new_args) { + NODE_VALIDATION_CHECK(node, + new_args.size() == node->input_values().size(), + "clone_with_new_inputs() expected ", + node->input_values().size(), + " argument", + (node->input_values().size() == 1 ? "" : "s"), + " but got ", + new_args.size()); +} + AttributeAdapter>::AttributeAdapter(std::shared_ptr& value) : m_ref(value) {} bool AttributeAdapter>::visit_attributes(AttributeVisitor& visitor) { diff --git a/src/core/src/op/batch_to_space.cpp b/src/core/src/op/batch_to_space.cpp index e9c4acb2253e69..0b522b5156b017 100644 --- a/src/core/src/op/batch_to_space.cpp +++ b/src/core/src/op/batch_to_space.cpp @@ -2,33 +2,23 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/batch_to_space.hpp" - -#include -#include -#include -#include -#include -#include -#include +#include "openvino/op/batch_to_space.hpp" +#include "batch_to_space_shape_inference.hpp" #include "itt.hpp" -#include "ngraph/builder/make_constant.hpp" -#include "ngraph/node.hpp" -#include "ngraph/opsets/opset3.hpp" -#include "ngraph/runtime/opt_kernel/reshape.hpp" -#include "ngraph/shape.hpp" #include "openvino/op/util/precision_sensitive_attribute.hpp" #include "openvino/op/util/slice_plan.hpp" +#include "openvino/reference/reshape.hpp" #include "openvino/reference/strided_slice.hpp" -using namespace std; -using namespace ngraph; +namespace ov { +namespace op { +namespace v1 { -ngraph::op::v1::BatchToSpace::BatchToSpace(const ngraph::Output& data, - const ngraph::Output& block_shape, - const ngraph::Output& crops_begin, - const ngraph::Output& crops_end) +BatchToSpace::BatchToSpace(const Output& data, + const Output& block_shape, + const Output& crops_begin, + const Output& crops_end) : Op({data, block_shape, crops_begin, crops_end}) { ov::mark_as_precision_sensitive(input(1)); ov::mark_as_precision_sensitive(input(2)); @@ -36,7 +26,7 @@ ngraph::op::v1::BatchToSpace::BatchToSpace(const ngraph::Output& d constructor_validate_and_infer_types(); } -void op::v1::BatchToSpace::validate_and_infer_types() { +void BatchToSpace::validate_and_infer_types() { OV_OP_SCOPE(v1_BatchToSpace_validate_and_infer_types); const auto& data_et = get_input_element_type(0); @@ -66,30 +56,29 @@ void op::v1::BatchToSpace::validate_and_infer_types() { set_output_type(0, data_et, output_shape); } -std::shared_ptr ngraph::op::v1::BatchToSpace::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr BatchToSpace::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_BatchToSpace_clone_with_new_inputs); 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)); + return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2), new_args.at(3)); } -bool ngraph::op::v1::BatchToSpace::visit_attributes(ngraph::AttributeVisitor& visitor) { +bool BatchToSpace::visit_attributes(AttributeVisitor& visitor) { OV_OP_SCOPE(v1_BatchToSpace_visit_attributes); return true; } -OPENVINO_SUPPRESS_DEPRECATED_START namespace { -bool batch_to_space_evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) { - auto data = inputs[0]; - const auto elem_size = data->get_element_type().size(); +bool batch_to_space_evaluate(TensorVector& outputs, const TensorVector& inputs) { + const auto& in = inputs[0]; + const auto elem_size = in.get_element_type().size(); - auto data_shape = data->get_shape(); + auto data_shape = in.get_shape(); - auto const block_values_size = shape_size(inputs[1]->get_shape()); + auto const block_values_size = shape_size(inputs[1].get_shape()); - const auto* block_values = inputs[1]->get_data_ptr(); - const auto* crops_begin_values = inputs[2]->get_data_ptr(); - const auto* crops_end_values = inputs[3]->get_data_ptr(); + const auto* block_values = inputs[1].data(); + const auto* crops_begin_values = inputs[2].data(); + const auto* crops_end_values = inputs[3].data(); ov::Shape dispersed_shape(1); dispersed_shape.insert(dispersed_shape.end(), data_shape.begin(), data_shape.end()); @@ -101,7 +90,13 @@ bool batch_to_space_evaluate(const HostTensorVector& outputs, const HostTensorVe return false; } - auto* flat_data = data->get_data_ptr(); + auto* in_first = static_cast(in.data()); + + // Copy input tensor to not overwrite evaluate's inputs tensors passed as const. + // The evaluate algorithm should be improved to avoid additional data copy. + auto flat_in = Tensor(in.get_element_type(), data_shape); + auto* flat_data = static_cast(flat_in.data()); + std::memcpy(flat_data, in_first, flat_in.get_byte_size()); std::vector dispersed_data(shape_size(data_shape) * elem_size); ov::Shape post_transpose_shape(axes_order.size()); @@ -110,99 +105,90 @@ bool batch_to_space_evaluate(const HostTensorVector& outputs, const HostTensorVe for (size_t block_idx = 1; block_idx < block_values_size; ++block_idx) { dispersed_shape[0] = block_values[block_idx]; dispersed_shape[1] /= block_values[block_idx]; - runtime::opt_kernel::reshape(flat_data, - dispersed_data.data(), - data_shape, - plain_axes_order, - dispersed_shape, - elem_size); - - size_t val = 1; - for (size_t axis_idx = 0; axis_idx <= block_values_size; ++axis_idx) { + ov::reference::reshape(flat_data, + dispersed_data.data(), + data_shape, + plain_axes_order, + dispersed_shape, + elem_size); + + for (size_t axis_idx = 0, val = 1; axis_idx <= block_values_size; ++axis_idx) { if ((block_idx + 1) == axis_idx) { axes_order[axis_idx] = 0; } else { axes_order[axis_idx] = val; - val++; + ++val; } } + for (size_t axis_idx = 0; axis_idx < axes_order.size(); ++axis_idx) { post_transpose_shape[axis_idx] = dispersed_shape[axes_order[axis_idx]]; } - runtime::opt_kernel::reshape(dispersed_data.data(), - post_transpose_data.data(), - dispersed_shape, - axes_order, - post_transpose_shape, - elem_size); + ov::reference::reshape(dispersed_data.data(), + post_transpose_data.data(), + dispersed_shape, + axes_order, + post_transpose_shape, + elem_size); squeezed_shape[0] = dispersed_shape[1]; squeezed_shape[block_idx] *= block_values[block_idx]; dispersed_shape[block_idx + 1] = squeezed_shape[block_idx]; - runtime::opt_kernel::reshape(post_transpose_data.data(), - flat_data, - post_transpose_shape, - plain_axes_order, - squeezed_shape, - elem_size); + ov::reference::reshape(post_transpose_data.data(), + flat_data, + post_transpose_shape, + plain_axes_order, + squeezed_shape, + elem_size); data_shape = squeezed_shape; } - std::vector upperbounds_values(data_shape.size()); + std::vector upper_bounds_values(data_shape.size()); for (size_t i = 0; i < data_shape.size(); ++i) { - upperbounds_values[i] = data_shape[i] - crops_end_values[i]; + upper_bounds_values[i] = data_shape[i] - crops_end_values[i]; } std::vector begin_mask(data_shape.size(), 0); std::vector end_mask(data_shape.size(), 0); - std::vector begins(shape_size(inputs[2]->get_shape())); - begins.assign(crops_begin_values, crops_begin_values + shape_size(inputs[2]->get_shape())); + std::vector begins(shape_size(inputs[2].get_shape())); + begins.assign(crops_begin_values, crops_begin_values + shape_size(inputs[2].get_shape())); std::vector default_strides(begins.size(), 1); const auto slice_plan = ov::op::util::make_slice_plan(data_shape, begins, - upperbounds_values, + upper_bounds_values, default_strides, begin_mask, end_mask, AxisSet(), AxisSet(), AxisSet()); - ov::reference::strided_slice(flat_data, outputs[0]->get_data_ptr(), data_shape, slice_plan, elem_size); + ov::reference::strided_slice(flat_data, static_cast(outputs[0].data()), data_shape, slice_plan, elem_size); return true; } } // namespace -bool ngraph::op::v1::BatchToSpace::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { +bool BatchToSpace::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v1_BatchToSpace_evaluate); - OPENVINO_SUPPRESS_DEPRECATED_START - OPENVINO_ASSERT(validate_host_tensor_vector(inputs, 4)); - OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); - OPENVINO_SUPPRESS_DEPRECATED_END - - if (outputs[0]->get_partial_shape().is_dynamic()) { - std::vector input_shapes; - input_shapes.reserve(inputs.size()); + OPENVINO_ASSERT(outputs.size() == 1); - for (size_t i = 0; i < inputs.size(); ++i) { - input_shapes.push_back(inputs[i]->get_partial_shape()); - if (input_shapes.back().is_dynamic()) { - return false; - } - } - - const auto output_shape = shape_infer(this, input_shapes, ov::make_tensor_accessor(inputs)).front().to_shape(); - - outputs[0]->set_element_type(inputs[0]->get_element_type()); - outputs[0]->set_shape(output_shape); + std::vector input_shapes; + for (const auto& in : inputs) { + input_shapes.emplace_back(in.get_shape()); } + const auto output_shape = shape_infer(this, input_shapes, ov::make_tensor_accessor(inputs)).front().to_shape(); + outputs[0].set_shape(output_shape); + return batch_to_space_evaluate(outputs, inputs); } -bool ngraph::op::v1::BatchToSpace::has_evaluate() const { +bool BatchToSpace::has_evaluate() const { OV_OP_SCOPE(v1_BatchToSpace_has_evaluate); return !get_input_partial_shape(0).is_dynamic() && get_input_shape(0).size() >= 2 && get_input_shape(0).size() <= shape_size(get_input_shape(1)); } +} // namespace v1 +} // namespace op +} // namespace ov diff --git a/src/core/src/op/ceiling.cpp b/src/core/src/op/ceiling.cpp index 8b8f9e96f2503f..c46ed21ae03ebc 100644 --- a/src/core/src/op/ceiling.cpp +++ b/src/core/src/op/ceiling.cpp @@ -44,7 +44,7 @@ bool Ceiling::evaluate(TensorVector& outputs, const TensorVector& inputs) const outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply( + return IfTypeOf::apply( inputs[0].get_element_type(), inputs[0], outputs[0], @@ -62,6 +62,7 @@ bool Ceiling::has_evaluate() const { case element::u16: case element::u32: case element::u64: + case element::f16: case element::f32: return true; default: diff --git a/src/core/src/op/constant.cpp b/src/core/src/op/constant.cpp index 27d9e000b64dec..2fe3d024fd9551 100644 --- a/src/core/src/op/constant.cpp +++ b/src/core/src/op/constant.cpp @@ -10,8 +10,10 @@ #include #include "itt.hpp" +#include "ngraph/runtime/aligned_buffer.hpp" #include "ngraph/runtime/host_tensor.hpp" #include "ngraph/runtime/tensor.hpp" +#include "openvino/runtime/shared_buffer.hpp" template static inline std::string to_cpp_string(T value) { @@ -27,6 +29,14 @@ static inline std::string to_cpp_string(T value) { } return rc; } +OPENVINO_SUPPRESS_DEPRECATED_START +std::shared_ptr ov::op::v0::Constant::legacy_to_ov_aligned_buffer( + const std::shared_ptr& buffer) { + return std::make_shared>>(buffer->get_ptr(), + buffer->size(), + buffer); +} +OPENVINO_SUPPRESS_DEPRECATED_END OPENVINO_SUPPRESS_DEPRECATED_START ov::op::v0::Constant::Constant(const std::shared_ptr& tensor) { @@ -35,7 +45,7 @@ ov::op::v0::Constant::Constant(const std::shared_ptr& t // Share data from HostTensor if we work with it // And copy data in other cas if (auto hostTensor = std::dynamic_pointer_cast(tensor)) { - m_data = std::make_shared>>( + m_data = std::make_shared>>( static_cast(hostTensor->get_data_ptr()), tensor->get_size_in_bytes(), tensor); @@ -51,12 +61,10 @@ OPENVINO_SUPPRESS_DEPRECATED_END ov::op::v0::Constant::Constant(const ov::Tensor& tensor) { m_element_type = tensor.get_element_type(); m_shape = tensor.get_shape(); - OPENVINO_SUPPRESS_DEPRECATED_START // Share data from ov::Tensor - m_data = std::make_shared>(static_cast(tensor.data()), - tensor.get_byte_size(), - tensor); - OPENVINO_SUPPRESS_DEPRECATED_END + m_data = std::make_shared>(static_cast(tensor.data()), + tensor.get_byte_size(), + tensor); constructor_validate_and_infer_types(); } @@ -211,12 +219,10 @@ ov::op::v0::Constant::Constant(bool memset_allocation, const element::Type& type } void ov::op::v0::Constant::allocate_buffer(bool memset_allocation) { - OPENVINO_SUPPRESS_DEPRECATED_START - m_data = std::make_shared(mem_size(), host_alignment()); + m_data = std::make_shared(mem_size(), host_alignment()); if (memset_allocation) { std::memset(m_data->get_ptr(), 0, m_data->size()); } - OPENVINO_SUPPRESS_DEPRECATED_END } ov::op::v0::Constant::Constant(const element::Type& type, const ov::Shape& shape, const void* data) @@ -316,6 +322,18 @@ std::string ov::op::v0::Constant::convert_value_to_string(size_t index) const { return rc; } +size_t ov::op::v0::Constant::get_byte_size() const { + return m_data->size(); +} + +const void* ov::op::v0::Constant::get_data_ptr() const { + return (m_data ? m_data->get_ptr() : nullptr); +} + +void* ov::op::v0::Constant::get_data_ptr_nc() { + return (m_data ? m_data->get_ptr() : nullptr); +} + std::vector ov::op::v0::Constant::get_value_strings() const { std::vector rc; diff --git a/src/core/src/op/eye.cpp b/src/core/src/op/eye.cpp index 77e4082792e2f6..4f1ecca6d47ad7 100644 --- a/src/core/src/op/eye.cpp +++ b/src/core/src/op/eye.cpp @@ -4,62 +4,48 @@ #include "openvino/op/eye.hpp" +#include "element_visitor.hpp" #include "eye_shape_inference.hpp" #include "itt.hpp" -#include "ngraph/validation_util.hpp" +#include "openvino/core/validation_util.hpp" #include "openvino/reference/eye.hpp" -OPENVINO_SUPPRESS_DEPRECATED_START namespace ov { namespace op { namespace eye { -namespace { -template -bool evaluate(const ngraph::HostTensorPtr& out, const int64_t diagonal_index) { - ov::reference::eye(out->get_data_ptr(), out->get_shape(), diagonal_index); - return true; -} -bool evaluate_eye(const ngraph::HostTensorPtr& out, const int64_t diagonal_index) { - bool rc = true; - switch (out->get_element_type()) { - OPENVINO_TYPE_CASE(evaluate, i8, out, diagonal_index); - OPENVINO_TYPE_CASE(evaluate, u8, out, diagonal_index); - OPENVINO_TYPE_CASE(evaluate, f16, out, diagonal_index); - OPENVINO_TYPE_CASE(evaluate, bf16, out, diagonal_index); - OPENVINO_TYPE_CASE(evaluate, i32, out, diagonal_index); - OPENVINO_TYPE_CASE(evaluate, f32, out, diagonal_index); - OPENVINO_TYPE_CASE(evaluate, f64, out, diagonal_index); - OPENVINO_TYPE_CASE(evaluate, i64, out, diagonal_index); - default: - rc = false; - break; +struct Evaluate : element::NoAction { + using element::NoAction::visit; + + template > + static result_type visit(Tensor& out, const Shape& out_shape, const int64_t diagonal_idx) { + reference::eye(out.data(), out_shape, diagonal_idx); + return true; } - return rc; -} -} // namespace +}; } // namespace eye -ov::op::v9::Eye::Eye(const Output& num_rows, - const Output& num_columns, - const Output& diagonal_index, - const Output& batch_shape, - const ov::element::Type& out_type) +namespace v9 { +Eye::Eye(const Output& num_rows, + const Output& num_columns, + const Output& diagonal_index, + const Output& batch_shape, + const ov::element::Type& out_type) : Op({num_rows, num_columns, diagonal_index, batch_shape}), m_output_type(out_type) { constructor_validate_and_infer_types(); } -ov::op::v9::Eye::Eye(const Output& num_rows, - const Output& num_columns, - const Output& diagonal_index, - const ov::element::Type& out_type) +Eye::Eye(const Output& num_rows, + const Output& num_columns, + const Output& diagonal_index, + const ov::element::Type& out_type) : Op({num_rows, num_columns, diagonal_index}), m_output_type(out_type) { constructor_validate_and_infer_types(); } -void ov::op::v9::Eye::validate_and_infer_types() { +void Eye::validate_and_infer_types() { OV_OP_SCOPE(v9_Eye_validate_and_infer_types); for (size_t i = 0; i < get_input_size(); ++i) { @@ -78,81 +64,72 @@ void ov::op::v9::Eye::validate_and_infer_types() { set_output_type(0, get_out_type(), output_shape); } -bool ov::op::v9::Eye::visit_attributes(ov::AttributeVisitor& visitor) { +bool Eye::visit_attributes(ov::AttributeVisitor& visitor) { OV_OP_SCOPE(v9_Eye_visit_attributes); visitor.on_attribute("output_type", m_output_type); return true; } -std::shared_ptr ov::op::v9::Eye::clone_with_new_inputs(const ov::OutputVector& new_args) const { +std::shared_ptr Eye::clone_with_new_inputs(const ov::OutputVector& new_args) const { OV_OP_SCOPE(v9_Eye_clone_with_new_inputs); check_new_args_count(this, new_args); - if (new_args.size() == 3) { - return std::make_shared(new_args[0], new_args[1], new_args[2], m_output_type); - } else if (new_args.size() == 4) { - return std::make_shared(new_args[0], new_args[1], new_args[2], new_args[3], m_output_type); - } else { + + switch (new_args.size()) { + case 3: + return std::make_shared(new_args[0], new_args[1], new_args[2], m_output_type); + case 4: + return std::make_shared(new_args[0], new_args[1], new_args[2], new_args[3], m_output_type); + default: OPENVINO_THROW("Eye has incorrect input number: ", new_args.size()); } } -bool ov::op::v9::Eye::has_evaluate() const { +bool Eye::has_evaluate() const { OV_OP_SCOPE(v9_Eye_has_evaluate); switch (m_output_type) { - case ov::element::i8: - case ov::element::u8: - case ov::element::f16: - case ov::element::bf16: - case ov::element::i32: - case ov::element::f32: - case ov::element::i64: + case element::bf16: + case element::f16: + case element::f32: + case element::f64: + case element::i8: + case element::i32: + case element::i64: + case element::u8: return true; default: - break; + return false; } - return false; } -bool ov::op::v9::Eye::evaluate(const ngraph::HostTensorVector& outputs, const ngraph::HostTensorVector& inputs) const { +bool Eye::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v9_Eye_evaluate); - OPENVINO_SUPPRESS_DEPRECATED_START - OPENVINO_ASSERT(ngraph::validate_host_tensor_vector(inputs, get_input_size()), "Invalid Eye input TensorVector."); - OPENVINO_ASSERT(ngraph::validate_host_tensor_vector(outputs, 1), "Invalid Eye output TensorVector."); - OPENVINO_SUPPRESS_DEPRECATED_END - - int64_t diagonal_index; - - if (get_input_size() > 1) { - const auto& diagonal_index_data = inputs[2]; - - switch (diagonal_index_data->get_element_type()) { - case element::i32: - diagonal_index = diagonal_index_data->get_data_ptr()[0]; - break; - case element::i64: - diagonal_index = diagonal_index_data->get_data_ptr()[0]; - break; - default: - OPENVINO_THROW("Unsupported type of input `diagonal_index` in Eye operation: ", - diagonal_index_data->get_element_type().to_string()); - } - } else { - diagonal_index = 0; - } - - std::vector input_shapes; - input_shapes.reserve(inputs.size()); - - for (size_t i = 0; i < inputs.size(); ++i) { - input_shapes.push_back(inputs[i]->get_partial_shape()); - } + OPENVINO_ASSERT(outputs.size() == 1); + // Inputs size and shapes checked by shape_infer + const auto input_shapes = ov::util::get_tensors_partial_shapes(inputs); const auto output_shape = shape_infer(this, input_shapes, make_tensor_accessor(inputs)).front().to_shape(); - outputs[0]->set_element_type(get_out_type()); - outputs[0]->set_shape(output_shape); + int64_t diagonal_index; + const auto& diagonal_tensor = inputs[2]; + switch (diagonal_tensor.get_element_type()) { + case element::i32: + diagonal_index = diagonal_tensor.data>()[0]; + break; + case element::i64: + diagonal_index = diagonal_tensor.data>()[0]; + break; + default: + OPENVINO_THROW("Unsupported type of input `diagonal_index` in Eye operation: ", + diagonal_tensor.get_element_type().to_string()); + } - return eye::evaluate_eye(outputs[0], diagonal_index); + outputs[0].set_shape(output_shape); + using namespace ov::element; + return IfTypeOf::apply(outputs[0].get_element_type(), + outputs[0], + output_shape, + diagonal_index); } +} // namespace v9 } // namespace op } // namespace ov diff --git a/src/core/src/op/logical_and.cpp b/src/core/src/op/logical_and.cpp index d6f451715a564d..fe8bd612ed2d85 100644 --- a/src/core/src/op/logical_and.cpp +++ b/src/core/src/op/logical_and.cpp @@ -2,83 +2,53 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/logical_and.hpp" + #include "itt.hpp" -#include "ngraph/op/and.hpp" -#include "ngraph/runtime/host_tensor.hpp" -#include "ngraph/validation_util.hpp" #include "openvino/reference/and.hpp" +#include "utils.hpp" -using namespace std; -using namespace ngraph; - -op::v1::LogicalAnd::LogicalAnd(const Output& arg0, - const Output& arg1, - const AutoBroadcastSpec& auto_broadcast) +namespace ov { +namespace op { +namespace v1 { +LogicalAnd::LogicalAnd(const Output& arg0, const Output& arg1, const AutoBroadcastSpec& auto_broadcast) : BinaryElementwiseLogical(arg0, arg1, auto_broadcast) { constructor_validate_and_infer_types(); } -bool op::v1::LogicalAnd::visit_attributes(AttributeVisitor& visitor) { - OV_OP_SCOPE(v1_LogicalAnd_visit_attributes); - BinaryElementwiseLogical::visit_attributes(visitor); - return true; -} - -shared_ptr op::v1::LogicalAnd::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr LogicalAnd::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_LogicalAnd_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), this->get_autob()); + return std::make_shared(new_args.at(0), new_args.at(1), get_autob()); } -OPENVINO_SUPPRESS_DEPRECATED_START -namespace logand { -namespace { -template -bool evaluate(const HostTensorPtr& arg0, - const HostTensorPtr& arg1, - const HostTensorPtr& out, - const op::AutoBroadcastSpec& broadcast_spec) { - ov::reference::logical_and(arg0->get_data_ptr(), - arg1->get_data_ptr(), - out->get_data_ptr(), - arg0->get_shape(), - arg1->get_shape(), - broadcast_spec); - return true; -} - -bool evaluate_logand(const HostTensorPtr& arg0, - const HostTensorPtr& arg1, - const HostTensorPtr& out, - const op::AutoBroadcastSpec& broadcast_spec) { - bool rc = true; - out->set_broadcast(broadcast_spec, arg0, arg1); - switch (arg0->get_element_type()) { - OPENVINO_TYPE_CASE(evaluate_logand, boolean, arg0, arg1, out, broadcast_spec); - default: - rc = false; - break; - } - return rc; -} -} // namespace -} // namespace logand - -bool op::v1::LogicalAnd::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { +bool LogicalAnd::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v1_LogicalAnd_evaluate); - OPENVINO_SUPPRESS_DEPRECATED_START - OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 2)); - OPENVINO_SUPPRESS_DEPRECATED_END - return logand::evaluate_logand(inputs[0], inputs[1], outputs[0], get_autob()); + OPENVINO_ASSERT(outputs.size() == 1); + OPENVINO_ASSERT(inputs.size() == 2); + + const auto& shape_0 = inputs[0].get_shape(); + const auto& shape_1 = inputs[1].get_shape(); + outputs[0].set_shape(infer_broadcast_shape(this, shape_0, shape_1)); + + if (inputs[0].get_element_type() == element::boolean) { + using T = fundamental_type_for; + reference::logical_and(inputs[0].data(), + inputs[1].data(), + outputs[0].data(), + shape_0, + shape_1, + get_autob()); + return true; + } else { + return false; + } } -bool op::v1::LogicalAnd::has_evaluate() const { +bool LogicalAnd::has_evaluate() const { OV_OP_SCOPE(v1_LogicalAnd_has_evaluate); - switch (get_input_element_type(0)) { - case ngraph::element::boolean: - return true; - default: - break; - } - return false; + return get_input_element_type(0) == element::boolean; } +} // namespace v1 +} // namespace op +} // namespace ov diff --git a/src/core/src/op/logical_not.cpp b/src/core/src/op/logical_not.cpp index 7ed4971861766a..db9f939463651a 100644 --- a/src/core/src/op/logical_not.cpp +++ b/src/core/src/op/logical_not.cpp @@ -2,22 +2,34 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/logical_not.hpp" + +#include "element_visitor.hpp" #include "itt.hpp" -#include "ngraph/op/not.hpp" -#include "ngraph/op/op.hpp" -#include "ngraph/op/util/elementwise_args.hpp" -#include "ngraph/runtime/host_tensor.hpp" -#include "ngraph/validation_util.hpp" -#include "openvino/reference/not.hpp" +#include "openvino/reference/logical_not.hpp" + +namespace ov { +namespace op { +namespace logical_not { -using namespace ngraph; -using namespace std; +struct Evaluate : element::NoAction { + using element::NoAction::visit; -op::v1::LogicalNot::LogicalNot(const Output& arg) : Op({arg}) { + template > + static result_type visit(const Tensor& in, Tensor& out, const size_t count) { + reference::logical_not(in.data(), out.data(), count); + return true; + } +}; +} // namespace logical_not + +namespace v1 { + +LogicalNot::LogicalNot(const Output& arg) : Op({arg}) { constructor_validate_and_infer_types(); } -void op::v1::LogicalNot::validate_and_infer_types() { +void LogicalNot::validate_and_infer_types() { OV_OP_SCOPE(v1_LogicalNot_validate_and_infer_types); const auto& element_type = get_input_element_type(0); // No boolean element_type validation for backward compatibility @@ -25,64 +37,43 @@ void op::v1::LogicalNot::validate_and_infer_types() { set_output_type(0, element_type, arg_pshape); } -shared_ptr op::v1::LogicalNot::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr LogicalNot::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_LogicalNot_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0)); -} - -OPENVINO_SUPPRESS_DEPRECATED_START -namespace notop { -namespace { -template -inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { - using T = typename element_type_traits::value_type; - ov::reference::logical_not(arg0->get_data_ptr(), out->get_data_ptr(), count); - return true; + return std::make_shared(new_args.at(0)); } -bool evaluate_not(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { - bool rc = true; - out->set_unary(arg0); +bool LogicalNot::evaluate(TensorVector& outputs, const TensorVector& inputs) const { + OV_OP_SCOPE(v1_LogicalNot_evaluate); + OPENVINO_ASSERT(outputs.size() == 1); + OPENVINO_ASSERT(inputs.size() == 1); - switch (arg0->get_element_type()) { - OPENVINO_TYPE_CASE(evaluate_not, boolean, arg0, out, count); - OPENVINO_TYPE_CASE(evaluate_not, i32, arg0, out, count); - OPENVINO_TYPE_CASE(evaluate_not, i64, arg0, out, count); - OPENVINO_TYPE_CASE(evaluate_not, u32, arg0, out, count); - OPENVINO_TYPE_CASE(evaluate_not, u64, arg0, out, count); - OPENVINO_TYPE_CASE(evaluate_not, f16, arg0, out, count); - OPENVINO_TYPE_CASE(evaluate_not, f32, arg0, out, count); - default: - rc = false; - break; - } - return rc; -} -} // namespace -} // namespace notop + outputs[0].set_shape(inputs[0].get_shape()); -bool op::v1::LogicalNot::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { - OV_OP_SCOPE(v1_LogicalNot_evaluate); - OPENVINO_SUPPRESS_DEPRECATED_START - OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); - OPENVINO_SUPPRESS_DEPRECATED_END - return notop::evaluate_not(inputs[0], outputs[0], inputs[0]->get_element_count()); + using namespace ov::element; + return IfTypeOf::apply( + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } -bool op::v1::LogicalNot::has_evaluate() const { +bool LogicalNot::has_evaluate() const { OV_OP_SCOPE(v1_LogicalNot_has_evaluate); switch (get_input_element_type(0)) { - case ngraph::element::boolean: - case ngraph::element::i32: - case ngraph::element::i64: - case ngraph::element::u32: - case ngraph::element::u64: - case ngraph::element::f16: - case ngraph::element::f32: + case element::boolean: + case element::f16: + case element::f32: + case element::i32: + case element::i64: + case element::u32: + case element::u64: return true; default: - break; + return false; } - return false; } + +} // namespace v1 +} // namespace op +} // namespace ov diff --git a/src/core/src/op/logical_or.cpp b/src/core/src/op/logical_or.cpp index c473e6c12e385f..403089318de314 100644 --- a/src/core/src/op/logical_or.cpp +++ b/src/core/src/op/logical_or.cpp @@ -2,77 +2,54 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/logical_or.hpp" + #include "itt.hpp" -#include "ngraph/op/or.hpp" -#include "ngraph/runtime/host_tensor.hpp" -#include "ngraph/validation_util.hpp" #include "openvino/reference/or.hpp" +#include "utils.hpp" -using namespace std; -using namespace ngraph; +namespace ov { +namespace op { +namespace v1 { -op::v1::LogicalOr::LogicalOr(const Output& arg0, - const Output& arg1, - const AutoBroadcastSpec& auto_broadcast) +LogicalOr::LogicalOr(const Output& arg0, const Output& arg1, const AutoBroadcastSpec& auto_broadcast) : BinaryElementwiseLogical(arg0, arg1, auto_broadcast) { constructor_validate_and_infer_types(); } -shared_ptr op::v1::LogicalOr::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr LogicalOr::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_LogicalOr_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), this->get_autob()); -} - -OPENVINO_SUPPRESS_DEPRECATED_START -namespace logor { -namespace { -template -bool evaluate(const HostTensorPtr& arg0, - const HostTensorPtr& arg1, - const HostTensorPtr& out, - const op::AutoBroadcastSpec& broadcast_spec) { - ov::reference::logical_or(arg0->get_data_ptr(), - arg1->get_data_ptr(), - out->get_data_ptr(), - arg0->get_shape(), - arg1->get_shape(), - broadcast_spec); - return true; -} - -bool evaluate_logor(const HostTensorPtr& arg0, - const HostTensorPtr& arg1, - const HostTensorPtr& out, - const op::AutoBroadcastSpec& broadcast_spec) { - bool rc = true; - out->set_broadcast(broadcast_spec, arg0, arg1); - switch (arg0->get_element_type()) { - OPENVINO_TYPE_CASE(evaluate_logor, boolean, arg0, arg1, out, broadcast_spec); - default: - rc = false; - break; - } - return rc; + return std::make_shared(new_args.at(0), new_args.at(1), get_autob()); } -} // namespace -} // namespace logor -bool op::v1::LogicalOr::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { +bool LogicalOr::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v1_LogicalOr_evaluate); - OPENVINO_SUPPRESS_DEPRECATED_START - OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 2)); - OPENVINO_SUPPRESS_DEPRECATED_END - return logor::evaluate_logor(inputs[0], inputs[1], outputs[0], get_autob()); + OPENVINO_ASSERT(outputs.size() == 1); + OPENVINO_ASSERT(inputs.size() == 2); + + const auto& shape_0 = inputs[0].get_shape(); + const auto& shape_1 = inputs[1].get_shape(); + outputs[0].set_shape(infer_broadcast_shape(this, shape_0, shape_1)); + + if (inputs[0].get_element_type() == element::boolean) { + using T = fundamental_type_for; + reference::logical_or(inputs[0].data(), + inputs[1].data(), + outputs[0].data(), + shape_0, + shape_1, + get_autob()); + return true; + } else { + return false; + } } -bool op::v1::LogicalOr::has_evaluate() const { +bool LogicalOr::has_evaluate() const { OV_OP_SCOPE(v1_LogicalOr_has_evaluate); - switch (get_input_element_type(0)) { - case ngraph::element::boolean: - return true; - default: - break; - } - return false; + return get_input_element_type(0) == element::boolean; } +} // namespace v1 +} // namespace op +} // namespace ov diff --git a/src/core/src/op/max_pool.cpp b/src/core/src/op/max_pool.cpp index d40c13644cd3cd..df74c1e6a105b6 100644 --- a/src/core/src/op/max_pool.cpp +++ b/src/core/src/op/max_pool.cpp @@ -2,32 +2,30 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/max_pool.hpp" +#include "openvino/op/max_pool.hpp" #include "itt.hpp" #include "max_pool_shape_inference.hpp" -#include "ngraph/attribute_visitor.hpp" -#include "ngraph/op/add.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/runtime/host_tensor.hpp" -#include "ngraph/validation_util.hpp" +#include "openvino/core/attribute_visitor.hpp" +#include "openvino/core/validation_util.hpp" #include "openvino/reference/max_pool.hpp" -using namespace std; -using namespace ngraph; +namespace ov { +namespace op { +namespace v1 { -op::v1::MaxPool::MaxPool(const Output& arg, - const Strides& strides, - const ov::Shape& pads_begin, - const ov::Shape& pads_end, - const ov::Shape& kernel, - const op::RoundingType rounding_type, - const PadType auto_pad) - : op::util::MaxPoolBase(arg, strides, pads_begin, pads_end, kernel, rounding_type, auto_pad) { +MaxPool::MaxPool(const Output& arg, + const Strides& strides, + const Shape& pads_begin, + const Shape& pads_end, + const Shape& kernel, + const RoundingType rounding_type, + const PadType auto_pad) + : util::MaxPoolBase(arg, strides, pads_begin, pads_end, kernel, rounding_type, auto_pad) { constructor_validate_and_infer_types(); } -bool ngraph::op::v1::MaxPool::visit_attributes(AttributeVisitor& visitor) { +bool MaxPool::visit_attributes(AttributeVisitor& visitor) { OV_OP_SCOPE(v1_MaxPool_visit_attributes); visitor.on_attribute("strides", m_strides); visitor.on_attribute("pads_begin", m_pads_begin); @@ -38,7 +36,7 @@ bool ngraph::op::v1::MaxPool::visit_attributes(AttributeVisitor& visitor) { return true; } -void op::v1::MaxPool::validate_and_infer_types() { +void MaxPool::validate_and_infer_types() { OV_OP_SCOPE(v1_MaxPool_validate_and_infer_types); OPENVINO_SUPPRESS_DEPRECATED_START @@ -47,219 +45,105 @@ void op::v1::MaxPool::validate_and_infer_types() { set_output_type(0, get_input_element_type(0), output_shapes.front()); } -shared_ptr op::v1::MaxPool::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr MaxPool::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_MaxPool_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - m_strides, - m_pads_begin, - m_pads_end, - m_kernel, - m_rounding_type, - m_auto_pad); + return std::make_shared(new_args.at(0), + m_strides, + m_pads_begin, + m_pads_end, + m_kernel, + m_rounding_type, + m_auto_pad); } -OPENVINO_SUPPRESS_DEPRECATED_START namespace maxpool { -namespace { -template -inline bool evaluate(const HostTensorPtr& arg, - const HostTensorPtr& out, - const ov::Shape& out_shape, - const ov::Shape& window_shape, - const Strides& window_movement_strides, - const ov::Shape& padding_below, - const ov::Shape& padding_above) { - using T = typename element_type_traits::value_type; - out->set_shape(out_shape); - ov::reference::max_pool(arg->get_data_ptr(), - out->get_data_ptr(), - arg->get_shape(), - out_shape, - window_shape, - window_movement_strides, - padding_below, - padding_above); - return true; -} - -bool evaluate_maxpool(const HostTensorPtr& arg, - const HostTensorPtr& out, - const ov::Shape& out_shape, - const ov::Shape& kernel, - const Strides& strides, - const ov::Shape& pad_begin, - const ov::Shape& pad_end) { - bool rc = true; - auto arg_shape = arg->get_shape(); +struct Evaluate : element::NoAction { + using element::NoAction::visit; - switch (out->get_element_type()) { - OPENVINO_TYPE_CASE(evaluate_maxpool, i32, arg, out, out_shape, kernel, strides, pad_begin, pad_end); - OPENVINO_TYPE_CASE(evaluate_maxpool, i64, arg, out, out_shape, kernel, strides, pad_begin, pad_end); - OPENVINO_TYPE_CASE(evaluate_maxpool, u32, arg, out, out_shape, kernel, strides, pad_begin, pad_end); - OPENVINO_TYPE_CASE(evaluate_maxpool, u64, arg, out, out_shape, kernel, strides, pad_begin, pad_end); - OPENVINO_TYPE_CASE(evaluate_maxpool, f16, arg, out, out_shape, kernel, strides, pad_begin, pad_end); - OPENVINO_TYPE_CASE(evaluate_maxpool, f32, arg, out, out_shape, kernel, strides, pad_begin, pad_end); - default: - rc = false; - break; + template > + static result_type visit(const Tensor& in, + Tensor& out, + const Shape& in_shape, + const Shape& out_shape, + const Shape& kernel, + const Strides& strides, + const Shape& pads_begin, + const Shape& pads_end) { + reference::max_pool(in.data(), + out.data(), + in_shape, + out_shape, + kernel, + strides, + pads_begin, + pads_end); + return true; } - return rc; -} -} // namespace +}; } // namespace maxpool -bool op::v1::MaxPool::evaluate_maxpool(const HostTensorVector& outputs, const HostTensorVector& inputs) const { - const auto input_shapes = std::vector{inputs[0]->get_partial_shape()}; +bool MaxPool::evaluate(TensorVector& outputs, const TensorVector& inputs) const { + OV_OP_SCOPE(v1_MaxPool_evaluate); + const auto input_shapes = std::vector{inputs[0].get_shape()}; auto pads_begin = m_pads_begin; auto pads_end = m_pads_end; - auto out_shape = shape_infer(this, input_shapes, pads_begin, pads_end).front(); + const auto output_shape = shape_infer(this, input_shapes, pads_begin, pads_end).front(); - return maxpool::evaluate_maxpool(inputs[0], - outputs[0], - out_shape.get_shape(), - get_kernel(), - get_strides(), - get_pads_begin(), - get_pads_end()); -} -bool op::v1::MaxPool::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { - OV_OP_SCOPE(v1_MaxPool_evaluate); - return evaluate_maxpool(outputs, inputs); + outputs[0].set_shape(output_shape.get_shape()); + using namespace ov::element; + return IfTypeOf::apply(inputs[0].get_element_type(), + inputs[0], + outputs[0], + inputs[0].get_shape(), + outputs[0].get_shape(), + get_kernel(), + get_strides(), + get_pads_begin(), + get_pads_end()); } -bool op::v1::MaxPool::has_evaluate() const { +bool MaxPool::has_evaluate() const { OV_OP_SCOPE(v1_MaxPool_has_evaluate); switch (get_input_element_type(0)) { - case ngraph::element::i32: - case ngraph::element::i64: - case ngraph::element::u32: - case ngraph::element::u64: - case ngraph::element::f16: - case ngraph::element::f32: + case element::i32: + case element::i64: + case element::u32: + case element::u64: + case element::f16: + case element::f32: return true; default: - break; + return false; } - return false; } +} // namespace v1 +} // namespace op +} // namespace ov // ------------------------------ V8 ------------------------------ +namespace ov { +namespace op { +namespace v8 { -namespace maxpool_v8 { -namespace { -template -inline bool evaluate(const HostTensorPtr& data, - const HostTensorPtr& values, - const HostTensorPtr& indices, - const ov::Shape& out_shape, - const ov::Shape& kernel, - const Strides& strides, - const Strides& dilations, - const ov::Shape& pads_begin, - const ov::Shape& pads_end, - const int64_t axis) { - using Values_t = typename element_type_traits::value_type; - using Indices_t = typename element_type_traits::value_type; - ov::reference::max_pool(data->get_data_ptr(), - values->get_data_ptr(), - indices->get_data_ptr(), - data->get_shape(), - out_shape, - kernel, - strides, - dilations, - pads_begin, - pads_end, - axis); - return true; -} - -bool evaluate_maxpool(const HostTensorPtr& data, - const HostTensorPtr& values, - const HostTensorPtr& indices, - const ov::Shape& out_shape, - const ov::Shape& kernel, - const Strides& strides, - const Strides& dilations, - const ov::Shape& pads_begin, - const ov::Shape& pads_end, - const int64_t axis) { -#define EVAL_MAX_POOL_8(data_et, index_et) \ - OPENVINO_2_TYPES_CASE(maxpool_v8::evaluate_maxpool, \ - data_et, \ - index_et, \ - data, \ - values, \ - indices, \ - out_shape, \ - kernel, \ - strides, \ - dilations, \ - pads_begin, \ - pads_end, \ - axis) - - bool rc = true; - switch (indices->get_element_type()) { - case element::Type_t::i32: { - switch (data->get_element_type()) { - EVAL_MAX_POOL_8(i8, i32); - EVAL_MAX_POOL_8(i32, i32); - EVAL_MAX_POOL_8(i64, i32); - EVAL_MAX_POOL_8(u8, i32); - EVAL_MAX_POOL_8(u32, i32); - EVAL_MAX_POOL_8(u64, i32); - EVAL_MAX_POOL_8(f16, i32); - EVAL_MAX_POOL_8(f32, i32); - default: - rc = false; - break; - } - } break; - case element::Type_t::i64: { - switch (data->get_element_type()) { - EVAL_MAX_POOL_8(i8, i64); - EVAL_MAX_POOL_8(i32, i64); - EVAL_MAX_POOL_8(i64, i64); - EVAL_MAX_POOL_8(u8, i64); - EVAL_MAX_POOL_8(u32, i64); - EVAL_MAX_POOL_8(u64, i64); - EVAL_MAX_POOL_8(f16, i64); - EVAL_MAX_POOL_8(f32, i64); - default: - rc = false; - break; - } - } break; - default: - rc = false; - break; - } - - return rc; -} -} // namespace -} // namespace maxpool_v8 - -op::v8::MaxPool::MaxPool(const Output& arg, - const Strides& strides, - const Strides& dilations, - const ov::Shape& pads_begin, - const ov::Shape& pads_end, - const ov::Shape& kernel, - const op::RoundingType rounding_type, - const PadType auto_pad, - const element::Type index_element_type, - const int64_t axis) - : op::util::MaxPoolBase(arg, strides, pads_begin, pads_end, kernel, rounding_type, auto_pad), +MaxPool::MaxPool(const Output& arg, + const Strides& strides, + const Strides& dilations, + const Shape& pads_begin, + const Shape& pads_end, + const Shape& kernel, + const RoundingType rounding_type, + const PadType auto_pad, + const element::Type index_element_type, + const int64_t axis) + : util::MaxPoolBase(arg, strides, pads_begin, pads_end, kernel, rounding_type, auto_pad), m_dilations{dilations}, m_index_element_type{index_element_type}, m_axis{axis} { constructor_validate_and_infer_types(); } -bool ngraph::op::v8::MaxPool::visit_attributes(AttributeVisitor& visitor) { +bool MaxPool::visit_attributes(AttributeVisitor& visitor) { OV_OP_SCOPE(v8_MaxPool_visit_attributes); visitor.on_attribute("strides", m_strides); visitor.on_attribute("dilations", m_dilations); @@ -273,13 +157,13 @@ bool ngraph::op::v8::MaxPool::visit_attributes(AttributeVisitor& visitor) { return true; } -void op::v8::MaxPool::validate_and_infer_types() { +void MaxPool::validate_and_infer_types() { OV_OP_SCOPE(v8_MaxPool_validate_and_infer_types); const auto input_shape = get_input_partial_shape(0); if (input_shape.rank().is_static()) { OPENVINO_SUPPRESS_DEPRECATED_START - m_axis = ngraph::normalize_axis(this, m_axis, input_shape.rank()); + m_axis = normalize_axis(this, m_axis, input_shape.rank()); OPENVINO_SUPPRESS_DEPRECATED_END } @@ -290,55 +174,126 @@ void op::v8::MaxPool::validate_and_infer_types() { set_output_type(1, m_index_element_type, output_shapes[1]); } -shared_ptr op::v8::MaxPool::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr MaxPool::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v8_MaxPool_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - m_strides, - m_dilations, - m_pads_begin, - m_pads_end, - m_kernel, - m_rounding_type, - m_auto_pad, - m_index_element_type, - m_axis); + return std::make_shared(new_args.at(0), + m_strides, + m_dilations, + m_pads_begin, + m_pads_end, + m_kernel, + m_rounding_type, + m_auto_pad, + m_index_element_type, + m_axis); } -bool op::v8::MaxPool::has_evaluate() const { - OV_OP_SCOPE(v8_MaxPool_has_evaluate); - switch (get_input_element_type(0)) { - case ngraph::element::i8: - case ngraph::element::i32: - case ngraph::element::i64: - case ngraph::element::u8: - case ngraph::element::u32: - case ngraph::element::u64: - case ngraph::element::f16: - case ngraph::element::f32: - return true; - default: - break; +namespace maxpool { +struct Evaluate : element::NoAction { + using element::NoAction::visit; + + template > + static result_type visit(const Tensor& in, + Tensor& out_values, + Tensor& out_indices, + const Shape& in_shape, + const Shape& out_shape, + const Shape& kernel, + const Strides& strides, + const Strides& dilations, + const Shape& pads_begin, + const Shape& pads_end, + const int64_t axis) { + using namespace ov::element; + return IfTypeOf::apply(out_indices.get_element_type(), + in.data(), + out_values.data(), + out_indices, + in_shape, + out_shape, + kernel, + strides, + dilations, + pads_begin, + pads_end, + axis); } - return false; -} -bool op::v8::MaxPool::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { +private: + struct EvalByIdxType : public element::NoAction { + using element::NoAction::visit; + + template > + static result_type visit(const T* in_data, + T* out_values_data, + Tensor& out_indices, + const Shape& in_shape, + const Shape& out_shape, + const Shape& kernel, + const Strides& strides, + const Strides& dilations, + const Shape& pads_begin, + const Shape& pads_end, + const int64_t axis) { + reference::max_pool(in_data, + out_values_data, + out_indices.data(), + in_shape, + out_shape, + kernel, + strides, + dilations, + pads_begin, + pads_end, + axis); + return true; + } + }; +}; +} // namespace maxpool + +bool MaxPool::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v8_MaxPool_evaluate); - const auto input_shapes = std::vector{inputs[0]->get_partial_shape()}; + const auto input_shapes = std::vector{inputs[0].get_shape()}; auto pads_begin = m_pads_begin; auto pads_end = m_pads_end; - auto out_shape = shape_infer(this, input_shapes, pads_begin, pads_end).front(); + const auto output_shape = shape_infer(this, input_shapes, pads_begin, pads_end).front(); - return maxpool_v8::evaluate_maxpool(inputs[0], - outputs[0], - outputs[1], - out_shape.get_shape(), - get_kernel(), - get_strides(), - get_dilations(), - get_pads_begin(), - get_pads_end(), - get_axis()); + outputs[0].set_shape(output_shape.get_shape()); + using namespace ov::element; + return IfTypeOf::apply(inputs[0].get_element_type(), + inputs[0], + outputs[0], + outputs[1], + inputs[0].get_shape(), + outputs[0].get_shape(), + get_kernel(), + get_strides(), + get_dilations(), + get_pads_begin(), + get_pads_end(), + get_axis()); } + +bool MaxPool::has_evaluate() const { + OV_OP_SCOPE(v8_MaxPool_has_evaluate); + switch (get_input_element_type(0)) { + case element::i8: + case element::i32: + case element::i64: + case element::u8: + case element::u32: + case element::u64: + case element::f16: + case element::f32: + return true; + default: + return false; + } +} + +} // namespace v8 +} // namespace op +} // namespace ov diff --git a/src/core/src/op/multinomial.cpp b/src/core/src/op/multinomial.cpp index 0dd4a93867d74a..d8e6a967f38b58 100644 --- a/src/core/src/op/multinomial.cpp +++ b/src/core/src/op/multinomial.cpp @@ -6,11 +6,9 @@ #include -#include "bound_evaluate.hpp" #include "itt.hpp" #include "multinomial_shape_inference.hpp" #include "openvino/core/attribute_visitor.hpp" -#include "openvino/op/constant.hpp" #include "openvino/op/util/op_types.hpp" #include "openvino/reference/multinomial.hpp" @@ -60,7 +58,7 @@ void op::v13::Multinomial::validate_and_infer_types() { std::shared_ptr op::v13::Multinomial::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v13_Multinomial_clone_with_new_inputs); - check_new_args_count(this, new_args); + check_new_args_count(this, new_args); return std::make_shared(new_args.at(0), new_args.at(1), @@ -116,12 +114,13 @@ namespace multinomial { namespace validate { void input_types(const Node* op) { NODE_VALIDATION_CHECK(op, - op->get_input_element_type(0).is_real(), + op->get_input_element_type(0).is_real() || op->get_input_element_type(0).is_dynamic(), "Expected floating point type as element type for the 'probs' input."); - NODE_VALIDATION_CHECK(op, - op->get_input_element_type(1).is_integral_number(), - "Expected integer type as element type for the 'num_samples' input."); + NODE_VALIDATION_CHECK( + op, + op->get_input_element_type(1).is_integral_number() || op->get_input_element_type(1).is_dynamic(), + "Expected integer type as element type for the 'num_samples' input."); } } // namespace validate } // namespace multinomial diff --git a/src/core/src/op/random_uniform.cpp b/src/core/src/op/random_uniform.cpp index 296b115979c8f7..b07044960f44c9 100644 --- a/src/core/src/op/random_uniform.cpp +++ b/src/core/src/op/random_uniform.cpp @@ -92,6 +92,8 @@ bool RandomUniform::evaluate(TensorVector& outputs, const TensorVector& inputs) const auto& t_out = get_out_type(); OPENVINO_ASSERT(validate::out_et(t_out), "Unsupported type of RandomUniform: " + t_out.get_type_name()); + outputs[0].set_shape(out_shape); + auto state = ov::reference::random_uniform(out_dims.data(), static_cast(inputs[1].data()), static_cast(inputs[2].data()), diff --git a/src/core/src/op/range.cpp b/src/core/src/op/range.cpp index 6285391ae56e06..204161ce10ac7b 100644 --- a/src/core/src/op/range.cpp +++ b/src/core/src/op/range.cpp @@ -144,37 +144,46 @@ bool evaluate(const HostTensorPtr& out, const HostTensorPtr& step, int version) { using T = typename element_type_traits::value_type; - T start_val; - T stop_val; - T step_val; + double start_val; + double stop_val; + double step_val; if (version < 4) { - start_val = *start->get_data_ptr(); - stop_val = *stop->get_data_ptr(); - step_val = *step->get_data_ptr(); + start_val = static_cast(*start->get_data_ptr()); + stop_val = static_cast(*stop->get_data_ptr()); + step_val = static_cast(*step->get_data_ptr()); if (!(check_value(start_val) && check_value(stop_val) && check_value(step_val) && (step_val != static_cast(0)))) { return false; } } else { - if (!(get_casted_value(start, &start_val) && get_casted_value(stop, &stop_val) && - get_casted_value(step, &step_val))) { + if (!(get_casted_value(start, &start_val) && get_casted_value(stop, &stop_val) && + get_casted_value(step, &step_val))) { return false; } } int64_t out_size = 0; + if (ov::element::Type(ET).is_integral_number()) { + start_val = std::trunc(start_val); + stop_val = std::trunc(stop_val); + step_val = std::trunc(step_val); + } + int64_t steps = static_cast(std::ceil(double(stop_val - start_val) / step_val)); if (steps > 0) { out_size = steps; } ov::Shape out_shape = ov::Shape({static_cast(out_size)}); out->set_shape(out_shape); - ov::reference::range(&start_val, &step_val, shape_size(out_shape), out->get_data_ptr()); + + T start_val_casted = static_cast(start_val); + T step_val_casted = static_cast(step_val); + ov::reference::range(&start_val_casted, &step_val_casted, shape_size(out_shape), out->get_data_ptr()); return true; } -bool evaluate_power(const HostTensorPtr& out, +bool evaluate_range(const HostTensorPtr& out, const HostTensorPtr& start, const HostTensorPtr& stop, const HostTensorPtr& step, @@ -209,7 +218,7 @@ bool op::v4::Range::evaluate(const HostTensorVector& outputs, const HostTensorVe HostTensorPtr start = inputs[0]; HostTensorPtr stop = inputs[1]; HostTensorPtr step = inputs[2]; - return rangeop::evaluate_power(out, start, stop, step, m_output_type, 4); + return rangeop::evaluate_range(out, start, stop, step, m_output_type, 4); } bool op::v4::Range::has_evaluate() const { @@ -381,7 +390,7 @@ bool op::v0::Range::evaluate(const HostTensorVector& outputs, const HostTensorVe HostTensorPtr start = inputs[0]; HostTensorPtr stop = inputs[1]; HostTensorPtr step = inputs[2]; - return rangeop::evaluate_power(out, start, stop, step, start->get_element_type(), 0); + return rangeop::evaluate_range(out, start, stop, step, start->get_element_type(), 0); } bool op::v0::Range::has_evaluate() const { diff --git a/src/core/src/op/reduce_prod.cpp b/src/core/src/op/reduce_prod.cpp index 9d345ae63cf301..9d2c4dee4a8c51 100644 --- a/src/core/src/op/reduce_prod.cpp +++ b/src/core/src/op/reduce_prod.cpp @@ -7,6 +7,7 @@ #include "bound_evaluate.hpp" #include "element_visitor.hpp" #include "itt.hpp" +#include "ngraph/validation_util.hpp" #include "openvino/core/shape_util.hpp" #include "openvino/op/util/axes_util.hpp" #include "openvino/reference/reduce_prod.hpp" @@ -15,11 +16,11 @@ namespace ov { namespace op { namespace reduce_prod { namespace { -bool has_positive_bounds_on_data(const Node* const op) { +bool has_non_negative_bounds_on_data(const Node* const op) { const auto& lb = op->get_input_tensor(0).get_lower_value(); const auto& ub = op->get_input_tensor(0).get_upper_value(); - return lb && ub && tensor_is_positive(lb) && tensor_is_positive(ub); + return lb && ub && tensor_is_non_negative(lb) && tensor_is_non_negative(ub); } } // namespace @@ -78,14 +79,34 @@ bool ReduceProd::has_evaluate() const { } bool ReduceProd::evaluate_lower(ov::TensorVector& output_values) const { - return reduce_prod::has_positive_bounds_on_data(this) && get_input_tensor(1).has_and_set_bound() && + return reduce_prod::has_non_negative_bounds_on_data(this) && get_input_tensor(1).has_and_set_bound() && default_lower_bound_evaluator(this, output_values); } bool ReduceProd::evaluate_upper(ov::TensorVector& output_values) const { - return reduce_prod::has_positive_bounds_on_data(this) && get_input_tensor(1).has_and_set_bound() && - default_upper_bound_evaluator(this, output_values); + if (!reduce_prod::has_non_negative_bounds_on_data(this) || !get_input_tensor(1).has_and_set_bound()) + return false; + // We need to cover a case: if an Upper Bound comes from ShapeOf and contains + // dynamic dimension (-1) - it has a value max_of_type, which points on + // a maximum possible value. For example, Upper Bound of shape [-1, 12] is + // [max_of_type, 12]. + // In such case we shouldn't evaluate a real ReduceProd because it'll cause an + // overflow and returns wrong value. We should return an Upper Bound as for [-1], + // which will be evaluated as [max_of_type] + // In case dimensions has a zero dimension - it should return 0 in any case + if (tensor_has_max_value(get_input_tensor(0).get_upper_value()) && + !tensor_has_zero_value(get_input_tensor(0).get_upper_value())) { + OPENVINO_SUPPRESS_DEPRECATED_START + auto max_constant = ngraph::get_constant_max_of_type(get_output_element_type(0)); + OPENVINO_SUPPRESS_DEPRECATED_END + OPENVINO_ASSERT(max_constant->get_byte_size() <= output_values[0].get_byte_size()); + memcpy(output_values[0].data(), max_constant->get_data_ptr(), max_constant->get_byte_size()); + return true; + } + + return default_upper_bound_evaluator(this, output_values); } + } // namespace v1 } // namespace op } // namespace ov diff --git a/src/core/src/op/reshape.cpp b/src/core/src/op/reshape.cpp index a20a4b5d3a06fe..279a06350ee7ea 100644 --- a/src/core/src/op/reshape.cpp +++ b/src/core/src/op/reshape.cpp @@ -10,7 +10,6 @@ #include "bound_evaluate.hpp" #include "compare.hpp" #include "itt.hpp" -#include "ngraph/runtime/opt_kernel/reshape.hpp" #include "ngraph/util.hpp" #include "openvino/core/dimension_tracker.hpp" #include "openvino/core/validation_util.hpp" @@ -177,15 +176,10 @@ bool op::v1::Reshape::evaluate_reshape(ov::TensorVector& outputs, const ov::Tens OPENVINO_ASSERT(ov::PartialShape(output_shape).is_static()); outputs[0].set_shape(ov::PartialShape(output_shape).to_shape()); - OPENVINO_SUPPRESS_DEPRECATED_START - const AxisVector order = ngraph::get_default_order(inputs[0].get_shape()); - OPENVINO_SUPPRESS_DEPRECATED_END - ngraph::runtime::opt_kernel::reshape(static_cast(inputs[0].data()), - static_cast(outputs[0].data()), - inputs[0].get_shape(), - order, - outputs[0].get_shape(), - inputs[0].get_element_type().size()); + ov::reference::reshape(static_cast(inputs[0].data()), + static_cast(outputs[0].data()), + inputs[0].get_shape(), + inputs[0].get_element_type().size()); return true; } diff --git a/src/core/src/op/shuffle_channels.cpp b/src/core/src/op/shuffle_channels.cpp index 30de73691bb470..50ffa228d33dc7 100644 --- a/src/core/src/op/shuffle_channels.cpp +++ b/src/core/src/op/shuffle_channels.cpp @@ -11,7 +11,6 @@ #include "ngraph/attribute_visitor.hpp" #include "ngraph/builder/reshape.hpp" #include "ngraph/runtime/host_tensor.hpp" -#include "ngraph/runtime/opt_kernel/reshape.hpp" #include "ngraph/type/element_type.hpp" #include "ngraph/type/element_type_traits.hpp" #include "openvino/core/validation_util.hpp" diff --git a/src/core/src/op/space_to_batch.cpp b/src/core/src/op/space_to_batch.cpp index 634a0163f088d4..1747b6b615648a 100644 --- a/src/core/src/op/space_to_batch.cpp +++ b/src/core/src/op/space_to_batch.cpp @@ -15,10 +15,10 @@ #include "ngraph/builder/make_constant.hpp" #include "ngraph/node.hpp" #include "ngraph/ops.hpp" -#include "ngraph/runtime/opt_kernel/reshape.hpp" #include "ngraph/shape.hpp" #include "openvino/op/util/precision_sensitive_attribute.hpp" #include "openvino/reference/pad.hpp" +#include "openvino/reference/reshape.hpp" using namespace std; using namespace ngraph; @@ -169,32 +169,32 @@ bool ngraph::op::v1::SpaceToBatch::evaluate_space_to_batch(const HostTensorVecto } } - ngraph::runtime::opt_kernel::reshape(flat_data.data(), - dispersed_data.data(), - data_shape, - plain_axes_order, - dispersed_shape, - elem_size); + ov::reference::reshape(flat_data.data(), + dispersed_data.data(), + data_shape, + plain_axes_order, + dispersed_shape, + elem_size); ov::Shape post_transpose_shape(axes_order.size()); for (size_t i = 0; i < axes_order.size(); ++i) { post_transpose_shape[i] = dispersed_shape[axes_order[i]]; } - ngraph::runtime::opt_kernel::reshape(dispersed_data.data(), - post_transpose_data.data(), - dispersed_shape, - axes_order, - post_transpose_shape, - elem_size); + ov::reference::reshape(dispersed_data.data(), + post_transpose_data.data(), + dispersed_shape, + axes_order, + post_transpose_shape, + elem_size); squeezed_shape[0] *= block_values[block_idx]; squeezed_shape[block_idx] /= block_values[block_idx]; - ngraph::runtime::opt_kernel::reshape(post_transpose_data.data(), - flat_data.data(), - post_transpose_shape, - plain_axes_order, - squeezed_shape, - elem_size); + ov::reference::reshape(post_transpose_data.data(), + flat_data.data(), + post_transpose_shape, + plain_axes_order, + squeezed_shape, + elem_size); data_shape = squeezed_shape; } diff --git a/src/core/src/op/split.cpp b/src/core/src/op/split.cpp index dc2ac72b509db7..4c5563e892321c 100644 --- a/src/core/src/op/split.cpp +++ b/src/core/src/op/split.cpp @@ -2,42 +2,46 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "openvino/reference/split.hpp" +#include "openvino/op/split.hpp" #include -#include #include "bound_evaluate.hpp" #include "itt.hpp" -#include "ngraph/attribute_visitor.hpp" -#include "ngraph/builder/split.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/op/split.hpp" -#include "ngraph/op/util/op_types.hpp" -#include "ngraph/runtime/host_tensor.hpp" -#include "ngraph/validation_util.hpp" - -using namespace std; -using namespace ngraph; - -op::v1::Split::Split(const Output& data, const Output& axis, const size_t num_splits) +#include "openvino/core/validation_util.hpp" +#include "openvino/reference/split.hpp" +#include "split_shape_inference.hpp" + +namespace ov { +namespace op { + +namespace v1 { +namespace validate { +namespace { +bool axis_type(const element::Type& et) { + return et.is_integral_number(); +} +} // namespace +} // namespace validate + +Split::Split(const Output& data, const Output& axis, const size_t num_splits) : Op({data, axis}), m_num_splits{num_splits} { constructor_validate_and_infer_types(); } -bool ngraph::op::v1::Split::visit_attributes(AttributeVisitor& visitor) { +bool Split::visit_attributes(AttributeVisitor& visitor) { OV_OP_SCOPE(v1_Split_visit_attributes); visitor.on_attribute("num_splits", m_num_splits); return true; } -void op::v1::Split::validate_and_infer_types() { +void Split::validate_and_infer_types() { OV_OP_SCOPE(v1_Split_validate_and_infer_types); const auto& axis_et = get_input_element_type(1); NODE_VALIDATION_CHECK(this, - axis_et.is_integral_number(), + validate::axis_type(axis_et), "Element type of 'axis' input must be integer. Got: ", axis_et); @@ -58,72 +62,70 @@ void op::v1::Split::validate_and_infer_types() { set_input_is_relevant_to_shape(0); } -shared_ptr op::v1::Split::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr Split::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_Split_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_num_splits); + return std::make_shared(new_args.at(0), new_args.at(1), m_num_splits); } -OPENVINO_SUPPRESS_DEPRECATED_START -bool op::v1::Split::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { +bool Split::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v1_Split_evaluate); - OPENVINO_SUPPRESS_DEPRECATED_START - OPENVINO_ASSERT(validate_host_tensor_vector(outputs, m_num_splits) && validate_host_tensor_vector(inputs, 2)); - OPENVINO_SUPPRESS_DEPRECATED_END + OPENVINO_ASSERT(outputs.size() == m_num_splits); - if (has_evaluate()) { + const auto output_shapes = + shape_infer(this, ov::util::get_tensors_partial_shapes(inputs), make_tensor_accessor(inputs)); + const auto& axis_tensor = inputs[1]; + const auto result = validate::axis_type(axis_tensor.get_element_type()); + if (result) { const auto& data_tensor = inputs[0]; - const auto& axis_tensor = inputs[1]; - - const auto input_shapes = - std::vector{data_tensor->get_partial_shape(), axis_tensor->get_partial_shape()}; - - auto output_shapes = shape_infer(this, input_shapes, make_tensor_accessor(inputs)); auto outputs_data = std::vector(m_num_splits); - for (size_t i = 0; i < m_num_splits; ++i) { - outputs[i]->set_shape(output_shapes[i].get_shape()); - outputs_data[i] = outputs[i]->get_data_ptr(); + { + auto outputs_it = outputs.begin(); + auto outputs_data_it = outputs_data.begin(); + for (const auto& p_shape : output_shapes) { + outputs_it->set_shape(p_shape.get_shape()); + *outputs_data_it = static_cast(outputs_it->data()); + ++outputs_it, ++outputs_data_it; + } } - OPENVINO_SUPPRESS_DEPRECATED_START - auto axis = host_tensor_2_vector(axis_tensor)[0]; - axis = normalize_axis(this, axis, data_tensor->get_partial_shape().rank()); - OPENVINO_SUPPRESS_DEPRECATED_END + auto axis = get_tensor_data_as(axis_tensor).front(); + axis = ov::util::normalize(axis, data_tensor.get_shape().size()); - ov::reference::split(data_tensor->get_data_ptr(), - data_tensor->get_shape(), - data_tensor->get_element_type().size(), + ov::reference::split(static_cast(data_tensor.data()), + data_tensor.get_shape(), + data_tensor.get_element_type().size(), axis, m_num_splits, outputs_data.data()); - return true; } - return false; + + return result; } -OPENVINO_SUPPRESS_DEPRECATED_END -bool op::v1::Split::has_evaluate() const { +bool Split::has_evaluate() const { OV_OP_SCOPE(v1_Split_has_evaluate); - return get_input_element_type(1).is_integral_number(); + return validate::axis_type(get_input_element_type(1)); } -bool op::v1::Split::evaluate_lower(ov::TensorVector& output_values) const { +bool Split::evaluate_lower(ov::TensorVector& output_values) const { OV_OP_SCOPE(v1_Split_evaluate_lower); - - return input(1).get_tensor().has_and_set_bound() && default_lower_bound_evaluator(this, output_values); + return get_input_tensor(1).has_and_set_bound() && default_lower_bound_evaluator(this, output_values); } -bool op::v1::Split::evaluate_upper(ov::TensorVector& output_values) const { +bool Split::evaluate_upper(ov::TensorVector& output_values) const { OV_OP_SCOPE(v1_Split_evaluate_upper); - - return input(1).get_tensor().has_and_set_bound() && default_upper_bound_evaluator(this, output_values); + return get_input_tensor(1).has_and_set_bound() && default_upper_bound_evaluator(this, output_values); } -bool op::v1::Split::evaluate_label(TensorLabelVector& output_labels) const { +bool Split::evaluate_label(TensorLabelVector& output_labels) const { OPENVINO_ASSERT(output_labels.size() == get_num_splits()); OPENVINO_SUPPRESS_DEPRECATED_START - return input(1).get_tensor().has_and_set_bound() && default_label_evaluator(this, output_labels); + return get_input_tensor(1).has_and_set_bound() && default_label_evaluator(this, output_labels); OPENVINO_SUPPRESS_DEPRECATED_END } +} // namespace v1 +} // namespace op +} // namespace ov diff --git a/src/core/src/op/squeeze.cpp b/src/core/src/op/squeeze.cpp index 50bf9af02d00a5..5e47edae2c1cc9 100644 --- a/src/core/src/op/squeeze.cpp +++ b/src/core/src/op/squeeze.cpp @@ -2,34 +2,39 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/squeeze.hpp" +#include "openvino/op/squeeze.hpp" -#include -#include -#include -#include +#include #include "bound_evaluate.hpp" #include "itt.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/validation_util.hpp" -#include "openvino/reference/copy.hpp" +#include "openvino/core/validation_util.hpp" +#include "openvino/op/constant.hpp" #include "squeeze_shape_inference.hpp" -using namespace std; -using namespace ngraph; +namespace ov { +namespace op { +namespace v0 { +namespace validate { +namespace { -op::Squeeze::Squeeze() : Op() {} +bool axes_has_and_set_bound(const Node& op) { + return (op.get_input_size() < 2) || op.get_input_tensor(1).has_and_set_bound(); +} +} // namespace +} // namespace validate + +Squeeze::Squeeze() : Op() {} -op::Squeeze::Squeeze(const Output& data, const Output& axes) : Op({data, axes}) { +Squeeze::Squeeze(const Output& data, const Output& axes) : Op({data, axes}) { constructor_validate_and_infer_types(); } -op::Squeeze::Squeeze(const Output& data) : Op({data}) { +Squeeze::Squeeze(const Output& data) : Op({data}) { constructor_validate_and_infer_types(); } -void op::Squeeze::validate_and_infer_types() { +void Squeeze::validate_and_infer_types() { OV_OP_SCOPE(v0_Squeeze_validate_and_infer_types); OPENVINO_SUPPRESS_DEPRECATED_START @@ -40,115 +45,86 @@ void op::Squeeze::validate_and_infer_types() { set_output_type(0, get_input_element_type(0), output_shapes[0]); } -bool ngraph::op::v0::Squeeze::visit_attributes(AttributeVisitor& visitor) { - OV_OP_SCOPE(v0_Squeeze_visit_attributes); - return true; -} - -shared_ptr op::Squeeze::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr Squeeze::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_Squeeze_clone_with_new_inputs); check_new_args_count(this, new_args); - if (new_args.size() == 1) { - return make_shared(new_args.at(0)); - } else if (new_args.size() == 2) { - return make_shared(new_args.at(0), new_args.at(1)); - } else { + + switch (new_args.size()) { + case 1: + return std::make_shared(new_args[0]); + case 2: + return std::make_shared(new_args[0], new_args[1]); + default: OPENVINO_THROW("Incorrect number of new arguments"); } } -OPENVINO_SUPPRESS_DEPRECATED_START -bool op::v0::Squeeze::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { +bool Squeeze::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v0_Squeeze_evaluate); - OPENVINO_SUPPRESS_DEPRECATED_START - OPENVINO_ASSERT(validate_host_tensor_vector(inputs, inputs.size())); - OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); - OPENVINO_SUPPRESS_DEPRECATED_END - - if (has_evaluate()) { - auto input_shapes = std::vector{inputs[0]->get_partial_shape()}; - - if (inputs.size() == 2) { - input_shapes.push_back(inputs[1]->get_partial_shape()); - } + OPENVINO_ASSERT(outputs.size() == 1); - auto output_shapes = shape_infer(this, input_shapes, make_tensor_accessor(inputs)); + const auto output_shapes = + shape_infer(this, ov::util::get_tensors_partial_shapes(inputs), make_tensor_accessor(inputs)); + outputs[0].set_shape(output_shapes.front().get_shape()); - auto out_shape = output_shapes[0].get_shape(); - outputs[0]->set_shape(out_shape); - - ov::reference::copy(inputs[0]->get_data_ptr(), - outputs[0]->get_data_ptr(), - shape_size(out_shape) * outputs[0]->get_element_type().size()); - - return true; - } - return false; + std::memcpy(outputs[0].data(), inputs[0].data(), outputs[0].get_byte_size()); + return true; } -OPENVINO_SUPPRESS_DEPRECATED_END -bool op::v0::Squeeze::has_evaluate() const { +bool Squeeze::has_evaluate() const { OV_OP_SCOPE(v0_Squeeze_has_evaluate); - - if (get_input_size() == 2) { - switch (get_input_element_type(1)) { - case ngraph::element::i8: - case ngraph::element::i16: - case ngraph::element::i32: - case ngraph::element::i64: - case ngraph::element::u8: - case ngraph::element::u16: - case ngraph::element::u32: - case ngraph::element::u64: + const auto validate_axes_type = [](const element::Type& et) -> bool { + switch (et) { + case element::i8: + case element::i16: + case element::i32: + case element::i64: + case element::u8: + case element::u16: + case element::u32: + case element::u64: return true; default: - break; + return false; } - return false; - } else if (get_input_size() == 1) { - return true; - } else { - return false; - } + }; + + return (get_input_size() < 2) || validate_axes_type(get_input_element_type(1)); } -bool op::v0::Squeeze::evaluate_lower(ov::TensorVector& output_values) const { +bool Squeeze::evaluate_lower(TensorVector& output_values) const { OV_OP_SCOPE(v0_Squeeze_evaluate_lower); - if (inputs().size() > 1 && !input_value(1).get_tensor().has_and_set_bound()) - return false; - return default_lower_bound_evaluator(this, output_values); + return validate::axes_has_and_set_bound(*this) && default_lower_bound_evaluator(this, output_values); } -bool op::v0::Squeeze::evaluate_upper(ov::TensorVector& output_values) const { +bool Squeeze::evaluate_upper(TensorVector& output_values) const { OV_OP_SCOPE(v0_Squeeze_evaluate_upper); - if (inputs().size() > 1 && !input_value(1).get_tensor().has_and_set_bound()) - return false; - return default_upper_bound_evaluator(this, output_values); + return validate::axes_has_and_set_bound(*this) && default_upper_bound_evaluator(this, output_values); } -bool op::v0::Squeeze::evaluate_label(TensorLabelVector& output_labels) const { - if (get_input_size() > 1 && !get_input_tensor(1).has_and_set_bound()) - return false; +bool Squeeze::evaluate_label(TensorLabelVector& output_labels) const { OPENVINO_SUPPRESS_DEPRECATED_START - return default_label_evaluator(this, output_labels); + return validate::axes_has_and_set_bound(*this) && default_label_evaluator(this, output_labels); OPENVINO_SUPPRESS_DEPRECATED_END } -bool op::v0::Squeeze::constant_fold(OutputVector& output_values, const OutputVector& inputs_values) { +bool Squeeze::constant_fold(OutputVector& output_values, const OutputVector& inputs_values) { OV_OP_SCOPE(v0_Squeeze_constant_fold); if (get_output_partial_shape(0).is_dynamic() || is_const_fold_disabled()) { return false; } - const auto& shape = get_output_shape(0); - - if (auto data_const = std::dynamic_pointer_cast(inputs_values[0].get_node_shared_ptr())) { - output_values[0] = std::make_shared(*data_const, shape); + if (auto data_const = std::dynamic_pointer_cast(inputs_values[0].get_node_shared_ptr())) { + const auto& shape = get_output_shape(0); + output_values[0] = std::make_shared(*data_const, shape); return true; } return false; } -bool op::v0::Squeeze::is_dynamic() const { +bool Squeeze::is_dynamic() const { return get_output_partial_shape(0).is_dynamic(); } +} // namespace v0 +} // namespace op +} // namespace ov diff --git a/src/core/src/op/tile.cpp b/src/core/src/op/tile.cpp index 6696ec8676a5f1..f6274a60136ac9 100644 --- a/src/core/src/op/tile.cpp +++ b/src/core/src/op/tile.cpp @@ -4,24 +4,22 @@ #include "openvino/op/tile.hpp" -#include - #include "bound_evaluate.hpp" #include "itt.hpp" #include "openvino/op/util/precision_sensitive_attribute.hpp" #include "openvino/reference/tile.hpp" +#include "tile_shape_inference.hpp" + +namespace ov { +namespace op { +namespace v0 { -ov::op::v0::Tile::Tile(const Output& data, const Output& repeats) : Op({data, repeats}) { +Tile::Tile(const Output& data, const Output& repeats) : Op({data, repeats}) { ov::mark_as_precision_sensitive(input(1)); constructor_validate_and_infer_types(); } -bool ov::op::v0::Tile::visit_attributes(ov::AttributeVisitor& visitor) { - OV_OP_SCOPE(v0_Tile_visit_attributes); - return true; -} - -void ov::op::v0::Tile::validate_and_infer_types() { +void Tile::validate_and_infer_types() { OV_OP_SCOPE(v0_Tile_validate_and_infer_types); // Repeats should have integer data type. For now we only allow i64 @@ -30,7 +28,6 @@ void ov::op::v0::Tile::validate_and_infer_types() { repeats_et.is_integral(), "Tile repeats must have any integer element type, but has ", repeats_et); - OPENVINO_SUPPRESS_DEPRECATED_START auto output_shapes = shape_infer(this, get_node_input_partial_shapes(*this)); OPENVINO_SUPPRESS_DEPRECATED_END @@ -40,53 +37,53 @@ void ov::op::v0::Tile::validate_and_infer_types() { set_input_is_relevant_to_shape(1); } -std::shared_ptr ov::op::v0::Tile::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr Tile::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_Tile_clone_with_new_inputs); check_new_args_count(this, new_args); return std::make_shared(new_args.at(0), new_args.at(1)); } -bool ov::op::v0::Tile::evaluate(ov::TensorVector& output_values, const ov::TensorVector& input_values) const { +bool Tile::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v0_Tile_evaluate); - const auto& data = input_values[0]; - const auto& axis = input_values[1]; - auto& output = output_values[0]; - auto repeats_val = get_tensor_data_as(axis, ov::util::Cast()); - const auto repeats_rank = repeats_val.size(); - - std::vector input_shapes = {data.get_shape(), axis.get_shape()}; - - const auto& output_shape = shape_infer(this, input_shapes, make_tensor_accessor(input_values)).front().to_shape(); - output.set_shape(output_shape); - repeats_val.insert(repeats_val.begin(), output_shape.size() - repeats_rank, 1); - ov::reference::tile(static_cast(data.data()), - static_cast(output.data()), - data.get_shape(), - output_shape, - data.get_element_type().size(), - repeats_val); + OPENVINO_ASSERT(outputs.size() == 1); + OPENVINO_ASSERT(inputs.size() == 2); + + const auto& d = inputs[0]; + const auto& r = inputs[1]; + auto repeats = get_tensor_data_as(r); + + const std::vector input_shapes{d.get_shape(), r.get_shape()}; + const auto output_shape = shape_infer(this, input_shapes, make_tensor_accessor(inputs)).front().to_shape(); + outputs[0].set_shape(output_shape); + repeats.insert(repeats.begin(), output_shape.size() - repeats.size(), 1); + reference::tile(static_cast(d.data()), + static_cast(outputs[0].data()), + d.get_shape(), + output_shape, + d.get_element_type().size(), + repeats); return true; } -bool ov::op::v0::Tile::has_evaluate() const { +bool Tile::has_evaluate() const { OV_OP_SCOPE(v0_Tile_has_evaluate); return true; } -bool ov::op::v0::Tile::evaluate_lower(ov::TensorVector& output_values) const { +bool Tile::evaluate_lower(TensorVector& output_values) const { OV_OP_SCOPE(v0_Tile_evaluate_lower); return get_input_tensor(1).has_and_set_bound() && default_lower_bound_evaluator(this, output_values); } -bool ov::op::v0::Tile::evaluate_upper(ov::TensorVector& output_values) const { +bool Tile::evaluate_upper(TensorVector& output_values) const { OV_OP_SCOPE(v0_Tile_evaluate_upper); return get_input_tensor(1).has_and_set_bound() && default_upper_bound_evaluator(this, output_values); } -bool ov::op::v0::Tile::evaluate_label(TensorLabelVector& output_labels) const { +bool Tile::evaluate_label(TensorLabelVector& output_labels) const { OV_OP_SCOPE(v0_Tile_evaluate_label); OPENVINO_ASSERT(output_labels.size() == 1); @@ -94,3 +91,6 @@ bool ov::op::v0::Tile::evaluate_label(TensorLabelVector& output_labels) const { return get_input_tensor(1).has_and_set_bound() && default_label_evaluator(this, output_labels); OPENVINO_SUPPRESS_DEPRECATED_END } +} // namespace v0 +} // namespace op +} // namespace ov diff --git a/src/core/src/op/topk.cpp b/src/core/src/op/topk.cpp index da56c6bb7494c7..a84d0490d9bebd 100644 --- a/src/core/src/op/topk.cpp +++ b/src/core/src/op/topk.cpp @@ -4,163 +4,153 @@ #include "openvino/op/topk.hpp" -#include -#include - +#include "element_visitor.hpp" #include "itt.hpp" -#include "openvino/core/attribute_visitor.hpp" -#include "openvino/core/axis_vector.hpp" -#include "openvino/core/dimension_tracker.hpp" -#include "openvino/core/shape.hpp" #include "openvino/core/validation_util.hpp" -#include "openvino/op/constant.hpp" -#include "openvino/op/util/op_types.hpp" #include "openvino/reference/topk.hpp" - -using namespace std; +#include "topk_shape_inference.hpp" namespace ov { -OPENVINO_SUPPRESS_DEPRECATED_START +namespace op { namespace topk { +namespace validate { namespace { -template -inline bool evaluate_execute(const ngraph::HostTensorPtr& arg0, - const ngraph::HostTensorPtr& out_indices, - const ngraph::HostTensorPtr& out_values, - const ov::Shape out_shape, - const size_t axis, - const size_t k, - const bool compute_max, - const op::v1::TopK::SortType sort) { - using T = typename element_type_traits::value_type; - using U = typename element_type_traits::value_type; - const ov::Shape in_shape = arg0->get_shape(); - out_indices->set_shape(out_shape); - out_indices->set_element_type(INDEX_ET); - - out_values->set_shape(out_shape); - out_values->set_element_type(arg0->get_element_type()); - - ov::reference::topk(arg0->get_data_ptr(), - out_indices->get_data_ptr(), - out_values->get_data_ptr(), - in_shape, - out_shape, - axis, - k, - compute_max, - sort); - return true; -} - -#define EXECUTE_EVALUATE_TOPK(a, ...) \ - case element::Type_t::a: { \ - OV_OP_SCOPE(OV_PP_CAT3(exec_topk_eval, _, a)); \ - rc = evaluate_execute(__VA_ARGS__); \ - } break - -template -bool evaluate(const ngraph::HostTensorPtr& arg, - const ngraph::HostTensorPtr& out_indices, - const ngraph::HostTensorPtr& out_values, - const ov::Shape out_shape, - const size_t axis, - const size_t k, - const bool max, - const op::v1::TopK::SortType sort, - const element::Type index_et) { - bool rc = true; - switch (index_et) { - EXECUTE_EVALUATE_TOPK(i32, arg, out_indices, out_values, out_shape, axis, k, max, sort); - EXECUTE_EVALUATE_TOPK(i64, arg, out_indices, out_values, out_shape, axis, k, max, sort); +bool data_type(const element::Type& et) { + switch (et) { + case element::f16: + case element::f32: + case element::i32: + case element::i64: + case element::u32: + case element::u64: + return true; default: - rc = false; - break; + return false; } - return rc; } -bool evaluate_topk(const ngraph::HostTensorPtr& arg, - const ngraph::HostTensorPtr& out_indices, - const ngraph::HostTensorPtr& out_values, - const ov::Shape out_shape, - const size_t axis, - const size_t k, - const bool max, - const op::v1::TopK::SortType sort, - const element::Type index_et) { - bool rc = true; - switch (arg->get_element_type()) { - OPENVINO_TYPE_CASE(evaluate_topk, i32, arg, out_indices, out_values, out_shape, axis, k, max, sort, index_et); - OPENVINO_TYPE_CASE(evaluate_topk, i64, arg, out_indices, out_values, out_shape, axis, k, max, sort, index_et); - OPENVINO_TYPE_CASE(evaluate_topk, u32, arg, out_indices, out_values, out_shape, axis, k, max, sort, index_et); - OPENVINO_TYPE_CASE(evaluate_topk, u64, arg, out_indices, out_values, out_shape, axis, k, max, sort, index_et); - OPENVINO_TYPE_CASE(evaluate_topk, f16, arg, out_indices, out_values, out_shape, axis, k, max, sort, index_et); - OPENVINO_TYPE_CASE(evaluate_topk, f32, arg, out_indices, out_values, out_shape, axis, k, max, sort, index_et); +bool k_type(const element::Type& et) { + switch (et) { + case element::i8: + case element::i16: + case element::i32: + case element::i64: + case element::u8: + case element::u16: + case element::u32: + case element::u64: + return true; default: - rc = false; - break; + return false; } - return rc; } -bool TopK_evaluate(const ov::op::util::TopKBase* const node, - const HostTensorVector& outputs, - const HostTensorVector& inputs) { - const auto& arg_shape = inputs[0]->get_shape(); - OPENVINO_SUPPRESS_DEPRECATED_START - const auto axis = normalize_axis(node, node->get_provided_axis(), arg_shape.size()); - OPENVINO_SUPPRESS_DEPRECATED_END - const auto compute_max = node->get_mode() == ov::op::TopKMode::MAX; - const auto sort_type = node->get_sort_type(); - - const auto input_shapes = vector{inputs[0]->get_partial_shape(), inputs[1]->get_partial_shape()}; - auto output_shape = shape_infer(node, input_shapes, ov::make_tensor_accessor(inputs)).front().to_shape(); +} // namespace +} // namespace validate + +struct Evaluate : public element::NoAction { + using element::NoAction::visit; + + template > + static result_type visit(const Tensor& in, + Tensor& out_values, + Tensor& out_indices, + const Shape& out_shape, + const size_t axis, + const bool compute_max, + const TopKSortType sort) { + using namespace ov::element; + return IfTypeOf::apply(out_indices.get_element_type(), + in.data(), + out_values.data(), + out_indices, + in.get_shape(), + out_shape, + axis, + out_shape[axis], + compute_max, + sort); + } + +private: + struct EvalByIdxType : public element::NoAction { + using element::NoAction::visit; + + template > + static result_type visit(const T* in_first, + T* out_first, + Tensor& out_indices, + const Shape& in_shape, + const Shape& out_shape, + const size_t axis, + const size_t k, + const bool compute_max, + const TopKSortType sort) { + reference::topk(in_first, + out_indices.data(), + out_first, + in_shape, + out_shape, + axis, + k, + compute_max, + sort); + return true; + } + }; +}; + +namespace { +bool evaluate(const util::TopKBase* const node, TensorVector& outputs, const TensorVector& inputs) { + auto output_shapes = shape_infer(node, ov::util::get_tensors_partial_shapes(inputs), make_tensor_accessor(inputs)); + OPENVINO_ASSERT(outputs.size() == output_shapes.size()); + auto output_shape = output_shapes.front().get_shape(); + const auto axis = ov::util::normalize(node->get_provided_axis(), output_shape.size()); if (output_shape[axis] == 0) { // the kernel can't handle K (output_shape[axis]) equal 0, use arg_shape[axis] instead. - output_shape[axis] = arg_shape[axis]; + output_shape[axis] = inputs[0].get_shape()[axis]; } - const size_t k = output_shape[axis]; - OPENVINO_ASSERT(k <= arg_shape[axis], "'K' exceeds the dimension of top_k_axis"); - - // TopK reference implementation provides stable indices output so this parameter is not passed on - return evaluate_topk(inputs[0], - outputs[1], - outputs[0], - output_shape, - axis, - k, - compute_max, - sort_type, - node->get_index_element_type()); + for (auto& t : outputs) { + t.set_shape(output_shape); + } + + using namespace ov::element; + return IfTypeOf::apply(inputs[0].get_element_type(), + inputs[0], + outputs[0], + outputs[1], + output_shape, + axis, + (node->get_mode() == ov::op::TopKMode::MAX), + node->get_sort_type()); } } // namespace } // namespace topk // v1 version starts - -op::v1::TopK::TopK(const Output& data, - const Output& k, - const int64_t axis, - const std::string& mode, - const std::string& sort, - const element::Type& index_element_type) +namespace v1 { +TopK::TopK(const Output& data, + const Output& k, + const int64_t axis, + const std::string& mode, + const std::string& sort, + const element::Type& index_element_type) : util::TopKBase(data, k, axis, mode, sort, index_element_type) { constructor_validate_and_infer_types(); } -op::v1::TopK::TopK(const Output& data, - const Output& k, - const int64_t axis, - const Mode mode, - const SortType sort, - const element::Type& index_element_type) +TopK::TopK(const Output& data, + const Output& k, + const int64_t axis, + const Mode mode, + const SortType sort, + const element::Type& index_element_type) : util::TopKBase(data, k, axis, mode, sort, index_element_type) { constructor_validate_and_infer_types(); } -void op::v1::TopK::k_type_check(const element::Type& k_element_type) const { +void TopK::k_type_check(const element::Type& k_element_type) const { NODE_VALIDATION_CHECK( this, k_element_type == element::i8 || k_element_type == element::i32 || k_element_type == element::i64, @@ -169,156 +159,84 @@ void op::v1::TopK::k_type_check(const element::Type& k_element_type) const { ")."); } -shared_ptr op::v1::TopK::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr TopK::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_TopK_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_axis, m_mode, m_sort, m_index_element_type); + return std::make_shared(new_args.at(0), new_args.at(1), m_axis, m_mode, m_sort, m_index_element_type); } -bool op::v1::TopK::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { +bool TopK::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v1_TopK_evaluate); - return topk::TopK_evaluate(this, outputs, inputs); + return topk::evaluate(this, outputs, inputs); } -bool op::v1::TopK::has_evaluate() const { +bool TopK::has_evaluate() const { OV_OP_SCOPE(v1_TopK_has_evaluate); - - switch (get_input_element_type(0)) { - case element::i32: - case element::i64: - case element::u32: - case element::u64: - case element::f16: - case element::f32: - break; - default: - return false; - } - - if (op::util::is_constant(input_value(1).get_node())) { - switch (get_input_element_type(1)) { - case element::i8: - case element::i32: - case element::i64: - break; - default: - return false; - } - } else { - switch (get_input_element_type(1)) { - case element::i8: - case element::i16: - case element::i32: - case element::i64: - case element::u8: - case element::u16: - case element::u32: - case element::u64: - break; - default: - return false; - } - } - - return true; + return topk::validate::data_type(get_input_element_type(0)) && topk::validate::k_type(get_input_element_type(1)); } +} // namespace v1 // v3 version starts -op::v3::TopK::TopK(const Output& data, - const Output& k, - const int64_t axis, - const std::string& mode, - const std::string& sort, - const element::Type& index_element_type) +namespace v3 { +TopK::TopK(const Output& data, + const Output& k, + const int64_t axis, + const std::string& mode, + const std::string& sort, + const element::Type& index_element_type) : TopK(data, k, axis, as_enum(mode), as_enum(sort), index_element_type) {} -op::v3::TopK::TopK(const Output& data, - const Output& k, - const int64_t axis, - const Mode mode, - const SortType sort, - const element::Type& index_element_type) +TopK::TopK(const Output& data, + const Output& k, + const int64_t axis, + const Mode mode, + const SortType sort, + const element::Type& index_element_type) : util::TopKBase{data, k, axis, mode, sort, index_element_type} { constructor_validate_and_infer_types(); } -shared_ptr op::v3::TopK::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr TopK::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v3_TopK_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_axis, m_mode, m_sort, m_index_element_type); + return std::make_shared(new_args.at(0), new_args.at(1), m_axis, m_mode, m_sort, m_index_element_type); } -bool op::v3::TopK::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { +bool TopK::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v3_TopK_evaluate); - return topk::TopK_evaluate(this, outputs, inputs); + return topk::evaluate(this, outputs, inputs); } -bool op::v3::TopK::has_evaluate() const { +bool TopK::has_evaluate() const { OV_OP_SCOPE(v3_TopK_has_evaluate); - - switch (get_input_element_type(0)) { - case element::i32: - case element::i64: - case element::u32: - case element::u64: - case element::f16: - case element::f32: - break; - default: - return false; - } - - if (op::util::is_constant(input_value(1).get_node())) { - switch (get_input_element_type(1)) { - case element::i8: - case element::i32: - case element::i64: - break; - default: - return false; - } - } else { - switch (get_input_element_type(1)) { - case element::i8: - case element::i16: - case element::i32: - case element::i64: - case element::u8: - case element::u16: - case element::u32: - case element::u64: - break; - default: - return false; - } - } - - return true; + return topk::validate::data_type(get_input_element_type(0)) && topk::validate::k_type(get_input_element_type(1)); } +} // namespace v3 // =============== V11 =============== -ov::op::v11::TopK::TopK(const Output& data, - const Output& k, - const int64_t axis, - const std::string& mode, - const std::string& sort, - const element::Type& index_element_type, - const bool stable) +namespace v11 { +TopK::TopK(const Output& data, + const Output& k, + const int64_t axis, + const std::string& mode, + const std::string& sort, + const element::Type& index_element_type, + const bool stable) : TopK(data, k, axis, as_enum(mode), as_enum(sort), index_element_type, stable) {} -ov::op::v11::TopK::TopK(const Output& data, - const Output& k, - const int64_t axis, - const TopKMode mode, - const TopKSortType sort, - const element::Type& index_element_type, - const bool stable) +TopK::TopK(const Output& data, + const Output& k, + const int64_t axis, + const TopKMode mode, + const TopKSortType sort, + const element::Type& index_element_type, + const bool stable) : util::TopKBase{data, k, axis, mode, sort, index_element_type}, m_stable{stable} { constructor_validate_and_infer_types(); } -void ov::op::v11::TopK::validate_and_infer_types() { +void TopK::validate_and_infer_types() { OV_OP_SCOPE(v11_TopK_validate_and_infer_types); if (m_stable) { @@ -331,44 +249,34 @@ void ov::op::v11::TopK::validate_and_infer_types() { util::TopKBase::validate_and_infer_types(); } -bool ov::op::v11::TopK::visit_attributes(AttributeVisitor& visitor) { +bool TopK::visit_attributes(AttributeVisitor& visitor) { OV_OP_SCOPE(v11_TopK_visit_attributes); util::TopKBase::visit_attributes(visitor); visitor.on_attribute("stable", m_stable); return true; } -std::shared_ptr ov::op::v11::TopK::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr TopK::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v11_TopK_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - m_axis, - m_mode, - m_sort, - m_index_element_type, - m_stable); + return std::make_shared(new_args.at(0), + new_args.at(1), + m_axis, + m_mode, + m_sort, + m_index_element_type, + m_stable); } -bool ov::op::v11::TopK::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { +bool TopK::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v11_TopK_evaluate); - return topk::TopK_evaluate(this, outputs, inputs); + return topk::evaluate(this, outputs, inputs); } -bool ov::op::v11::TopK::has_evaluate() const { +bool TopK::has_evaluate() const { OV_OP_SCOPE(v11_TopK_has_evaluate); - - switch (get_input_element_type(0)) { - case element::i32: - case element::i64: - case element::u32: - case element::u64: - case element::f16: - case element::f32: - break; - default: - return false; - } - return true; + return topk::validate::data_type(get_input_element_type(0)); } +} // namespace v11 +} // namespace op } // namespace ov diff --git a/src/core/src/op/variadic_split.cpp b/src/core/src/op/variadic_split.cpp index ab94af3fd8345f..38b309325fe16a 100644 --- a/src/core/src/op/variadic_split.cpp +++ b/src/core/src/op/variadic_split.cpp @@ -2,33 +2,69 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/variadic_split.hpp" +#include "openvino/op/variadic_split.hpp" #include #include "bound_evaluate.hpp" #include "compare.hpp" #include "itt.hpp" -#include "ngraph/validation_util.hpp" +#include "openvino/core/validation_util.hpp" #include "openvino/reference/slice.hpp" #include "variadic_split_shape_inference.hpp" -using namespace std; -using namespace ngraph; +namespace ov { +namespace op { +namespace variadic_split { +namespace { -op::v1::VariadicSplit::VariadicSplit(const Output& data, - const Output& axis, - const Output& split_lengths) - : Op({data, axis, split_lengths}) { - constructor_validate_and_infer_types(); +bool has_axis_and_splits_bound_set(const Node* const node) { + return have_node_inputs_bounds_set(node, 1, 2); } -bool ngraph::op::v1::VariadicSplit::visit_attributes(AttributeVisitor& visitor) { - OV_OP_SCOPE(v1_VariadicSplit_visit_attributes); +bool evaluate(TensorVector& outputs, const TensorVector& inputs) { + const auto& data_tensor = inputs[0]; + const auto& axis_tensor = inputs[1]; + const auto axis = + ov::util::normalize(get_tensor_data_as(axis_tensor).front(), data_tensor.get_shape().size()); + + ov::Coordinate upper_bounds(data_tensor.get_shape()); + ov::Coordinate lower_bounds(upper_bounds.size()); + upper_bounds[axis] = 0; + + const Strides default_strides(upper_bounds.size(), 1); + constexpr auto is_zero_dim = ov::cmp::Equal(0); + + for (auto& output : outputs) { + const auto& out_shape = output.get_shape(); + upper_bounds[axis] += out_shape[axis]; + + if (std::none_of(out_shape.cbegin(), out_shape.cend(), is_zero_dim)) { + reference::slice(static_cast(data_tensor.data()), + static_cast(output.data()), + data_tensor.get_shape(), + lower_bounds, + upper_bounds, + default_strides, + out_shape, + data_tensor.get_element_type().size()); + } + + lower_bounds[axis] = upper_bounds[axis]; + } + return true; } +} // namespace +} // namespace variadic_split -void ngraph::op::v1::VariadicSplit::validate_and_infer_types() { +namespace v1 { +VariadicSplit::VariadicSplit(const Output& data, const Output& axis, const Output& split_lengths) + : Op({data, axis, split_lengths}) { + constructor_validate_and_infer_types(); +} + +void VariadicSplit::validate_and_infer_types() { OV_OP_SCOPE(v1_VariadicSplit_validate_and_infer_types); for (size_t i = 0; i < get_input_size(); ++i) { set_input_is_relevant_to_value(i); @@ -45,107 +81,52 @@ void ngraph::op::v1::VariadicSplit::validate_and_infer_types() { } } -shared_ptr op::v1::VariadicSplit::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr VariadicSplit::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_VariadicSplit_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2)); + return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2)); } -OPENVINO_SUPPRESS_DEPRECATED_START -namespace variadic_split { -namespace { -inline bool evaluate(const HostTensorPtr& in, - const HostTensorPtr& out, - const Coordinate& lower_bounds, - const Coordinate& upper_bounds) { - const auto& output_shape = out->get_shape(); - const auto has_nonzero_dims = std::none_of(output_shape.begin(), output_shape.end(), ov::cmp::Equal(0)); - - if (has_nonzero_dims) { - ov::reference::slice(in->get_data_ptr(), - out->get_data_ptr(), - in->get_shape(), - lower_bounds, - upper_bounds, - Strides(lower_bounds.size(), 1), - out->get_shape(), - in->get_element_type().size()); - return true; - } - return false; -} -} // namespace -} // namespace variadic_split - -bool op::v1::VariadicSplit::evaluate_variadic_split(const HostTensorVector& inputs, - const HostTensorVector& outputs) const { - const auto& data_tensor = inputs[0]; - const auto& axis_tensor = inputs[1]; - const auto& split_lengths_tensor = inputs[2]; - OPENVINO_ASSERT(axis_tensor->get_element_type().is_integral_number(), - "axis element type is not integral data type"); - OPENVINO_ASSERT(split_lengths_tensor->get_element_type().is_integral_number(), - "split_lengths element type is not integral data type"); - - OPENVINO_SUPPRESS_DEPRECATED_START - int64_t axis = host_tensor_2_vector(axis_tensor)[0]; - axis = ngraph::normalize_axis(this, axis, data_tensor->get_partial_shape().rank()); - OPENVINO_SUPPRESS_DEPRECATED_END +bool VariadicSplit::evaluate(TensorVector& outputs, const TensorVector& inputs) const { + OV_OP_SCOPE(v1_VariadicSplit_evaluate); - std::vector input_shapes = {data_tensor->get_partial_shape(), - axis_tensor->get_partial_shape(), - split_lengths_tensor->get_partial_shape()}; - auto output_shapes = shape_infer(this, input_shapes, make_tensor_accessor(inputs)); + if (inputs[1].get_element_type().is_integral_number() && inputs[2].get_element_type().is_integral_number()) { + const auto output_shapes = + shape_infer(this, ov::util::get_tensors_partial_shapes(inputs), make_tensor_accessor(inputs)); + OPENVINO_ASSERT(outputs.size() == output_shapes.size()); - const auto data_shape = data_tensor->get_shape(); - std::vector lower_bounds(data_shape.size(), 0); - std::vector upper_bounds = data_shape; - upper_bounds[axis] = 0; + auto out_partial_shape = output_shapes.cbegin(); + for (auto& output : outputs) { + output.set_shape(out_partial_shape->to_shape()); + ++out_partial_shape; + } - size_t split_pos = 0; - for (const auto& output : outputs) { - ov::Shape output_shape = output_shapes[split_pos++].get_shape(); - upper_bounds[axis] += output_shape[axis]; - output->set_shape(output_shape); - variadic_split::evaluate(data_tensor, output, lower_bounds, upper_bounds); - lower_bounds.at(axis) = upper_bounds.at(axis); + return variadic_split::evaluate(outputs, inputs); + } else { + return false; } - - return true; -} -bool op::v1::VariadicSplit::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { - OV_OP_SCOPE(v1_VariadicSplit_evaluate); - return evaluate_variadic_split(inputs, outputs); } -bool op::v1::VariadicSplit::has_evaluate() const { +bool VariadicSplit::has_evaluate() const { OV_OP_SCOPE(v1_VariadicSplit_has_evaluate); return get_input_element_type(1).is_integral_number() && get_input_element_type(2).is_integral_number(); } -bool op::v1::VariadicSplit::has_axis_and_splits_bound_set() const { - for (size_t i = 1; i < get_input_size(); ++i) { - if (!get_input_tensor(i).has_and_set_bound()) { - return false; - } - } - return true; -} - -bool op::v1::VariadicSplit::evaluate_lower(ov::TensorVector& output_values) const { +bool VariadicSplit::evaluate_lower(TensorVector& output_values) const { OV_OP_SCOPE(v1_Split_evaluate_lower); - - return has_axis_and_splits_bound_set() && default_lower_bound_evaluator(this, output_values); + return variadic_split::has_axis_and_splits_bound_set(this) && default_lower_bound_evaluator(this, output_values); } -bool op::v1::VariadicSplit::evaluate_upper(ov::TensorVector& output_values) const { +bool VariadicSplit::evaluate_upper(TensorVector& output_values) const { OV_OP_SCOPE(v1_Split_evaluate_upper); - - return has_axis_and_splits_bound_set() && default_upper_bound_evaluator(this, output_values); + return variadic_split::has_axis_and_splits_bound_set(this) && default_upper_bound_evaluator(this, output_values); } -bool op::v1::VariadicSplit::evaluate_label(TensorLabelVector& output_labels) const { +bool VariadicSplit::evaluate_label(TensorLabelVector& output_labels) const { OPENVINO_SUPPRESS_DEPRECATED_START - return has_axis_and_splits_bound_set() && default_label_evaluator(this, output_labels); + return variadic_split::has_axis_and_splits_bound_set(this) && default_label_evaluator(this, output_labels); OPENVINO_SUPPRESS_DEPRECATED_END } +} // namespace v1 +} // namespace op +} // namespace ov diff --git a/src/core/src/opsets/opset.cpp b/src/core/src/opsets/opset.cpp index 1a61c91e7a1133..9adcd22a43cc35 100644 --- a/src/core/src/opsets/opset.cpp +++ b/src/core/src/opsets/opset.cpp @@ -5,17 +5,11 @@ #include "ngraph/opsets/opset.hpp" #include "itt.hpp" -#include "ngraph/deprecated.hpp" #include "ngraph/log.hpp" #include "openvino/op/ops.hpp" #include "openvino/opsets/opset.hpp" #include "openvino/util/log.hpp" -OPENVINO_SUPPRESS_DEPRECATED_START -ngraph::OpSet::OpSet(const ov::OpSet& opset) : ov::OpSet(opset) {} - -ngraph::OpSet::OpSet(const ngraph::OpSet& opset) : ov::OpSet(opset) {} - ov::OpSet::OpSet(const std::string& name) : m_name(name) {} ov::OpSet::OpSet(const ov::OpSet& opset) { @@ -51,24 +45,6 @@ ov::Node* ov::OpSet::create_insensitive(const std::string& name) const { return m_factory_registry.create(type_info_it->second); } -const std::map>& ngraph::get_available_opsets() { -#define _NGRAPH_REG_OPSET(OPSET) \ - { #OPSET, ngraph::get_##OPSET } - const static std::map> opset_map = {_NGRAPH_REG_OPSET(opset1), - _NGRAPH_REG_OPSET(opset2), - _NGRAPH_REG_OPSET(opset3), - _NGRAPH_REG_OPSET(opset4), - _NGRAPH_REG_OPSET(opset5), - _NGRAPH_REG_OPSET(opset6), - _NGRAPH_REG_OPSET(opset7), - _NGRAPH_REG_OPSET(opset8), - _NGRAPH_REG_OPSET(opset9), - _NGRAPH_REG_OPSET(opset10), - _NGRAPH_REG_OPSET(opset11)}; -#undef _NGRAPH_REG_OPSET - return opset_map; -} - const std::map>& ov::get_available_opsets() { #define _OPENVINO_REG_OPSET(OPSET) \ { #OPSET, ov::get_##OPSET } @@ -232,57 +208,96 @@ const ov::OpSet& ov::get_opset13() { return opset; } -const ngraph::OpSet& ngraph::get_opset1() { +OPENVINO_SUPPRESS_DEPRECATED_START +namespace ngraph { + +OpSet::OpSet(const ov::OpSet& opset) : ov::OpSet(opset) {} + +OpSet::OpSet(const OpSet& opset) : ov::OpSet(opset) {} + +const std::map>& get_available_opsets() { +#define _REG_OPSET(OPSET) \ + { #OPSET, get_##OPSET } + const static std::map> opset_map = {_REG_OPSET(opset1), + _REG_OPSET(opset2), + _REG_OPSET(opset3), + _REG_OPSET(opset4), + _REG_OPSET(opset5), + _REG_OPSET(opset6), + _REG_OPSET(opset7), + _REG_OPSET(opset8), + _REG_OPSET(opset9), + _REG_OPSET(opset10), + _REG_OPSET(opset11), + _REG_OPSET(opset12), + _REG_OPSET(opset13)}; +#undef _REG_OPSET + return opset_map; +} + +const OpSet& get_opset1() { static OpSet opset(ov::get_opset1()); return opset; } -const ngraph::OpSet& ngraph::get_opset2() { +const OpSet& get_opset2() { static OpSet opset(ov::get_opset2()); return opset; } -const ngraph::OpSet& ngraph::get_opset3() { +const OpSet& get_opset3() { static OpSet opset(ov::get_opset3()); return opset; } -const ngraph::OpSet& ngraph::get_opset4() { +const OpSet& get_opset4() { static OpSet opset(ov::get_opset4()); return opset; } -const ngraph::OpSet& ngraph::get_opset5() { +const OpSet& get_opset5() { static OpSet opset(ov::get_opset5()); return opset; } -const ngraph::OpSet& ngraph::get_opset6() { +const OpSet& get_opset6() { static OpSet opset(ov::get_opset6()); return opset; } -const ngraph::OpSet& ngraph::get_opset7() { +const OpSet& get_opset7() { static OpSet opset(ov::get_opset7()); return opset; } -const ngraph::OpSet& ngraph::get_opset8() { +const OpSet& get_opset8() { static OpSet opset(ov::get_opset8()); return opset; } -const ngraph::OpSet& ngraph::get_opset9() { +const OpSet& get_opset9() { static OpSet opset(ov::get_opset9()); return opset; } -const ngraph::OpSet& ngraph::get_opset10() { +const OpSet& get_opset10() { static OpSet opset(ov::get_opset10()); return opset; } -const ngraph::OpSet& ngraph::get_opset11() { +const OpSet& get_opset11() { static OpSet opset(ov::get_opset11()); return opset; } + +const OpSet& get_opset12() { + static OpSet opset(ov::get_opset12()); + return opset; +} + +const OpSet& get_opset13() { + static OpSet opset(ov::get_opset13()); + return opset; +} + +} // namespace ngraph diff --git a/src/core/src/pass/serialize.cpp b/src/core/src/pass/serialize.cpp index dc1263d7991deb..c879e8780f1370 100644 --- a/src/core/src/pass/serialize.cpp +++ b/src/core/src/pass/serialize.cpp @@ -21,6 +21,7 @@ #include "openvino/opsets/opset1.hpp" #include "openvino/pass/constant_folding.hpp" #include "openvino/reference/convert.hpp" +#include "openvino/runtime/aligned_buffer.hpp" #include "openvino/util/file_util.hpp" #include "pugixml.hpp" #include "transformations/hash.hpp" @@ -532,6 +533,19 @@ class XmlSerializer : public ov::AttributeVisitor { m_xml_node.append_attribute("offset").set_value(static_cast(offset)); m_xml_node.append_attribute("size").set_value(static_cast(new_size)); } + } else if (const auto& a = ov::as_type>>(&adapter)) { + if (name == "value" && translate_type_name(m_node_type_name) == "Const") { + const int64_t size = a->get()->size(); + size_t new_size; + int64_t offset = m_constant_write_handler.write(static_cast(a->get()->get_ptr()), + size, + &new_size, + m_compress_to_fp16, + m_output_element_type); + + m_xml_node.append_attribute("offset").set_value(static_cast(offset)); + m_xml_node.append_attribute("size").set_value(static_cast(new_size)); + } } else if (const auto& a = ov::as_type>(&adapter)) { const auto& attrs = a->get(); diff --git a/src/core/src/runtime/aligned_buffer.cpp b/src/core/src/runtime/aligned_buffer.cpp index 95ab3f44306eb8..4207eefe5db9b7 100644 --- a/src/core/src/runtime/aligned_buffer.cpp +++ b/src/core/src/runtime/aligned_buffer.cpp @@ -8,17 +8,19 @@ #include #include "ngraph/util.hpp" +#include "openvino/runtime/aligned_buffer.hpp" +#include "openvino/util/log.hpp" -using namespace ngraph; -using namespace std; NGRAPH_SUPPRESS_DEPRECATED_START +namespace ngraph { + runtime::AlignedBuffer::AlignedBuffer() : m_allocated_buffer(nullptr), m_aligned_buffer(nullptr), m_byte_size(0) {} runtime::AlignedBuffer::AlignedBuffer(size_t byte_size, size_t alignment) : m_byte_size(byte_size) { m_byte_size = std::max(1, byte_size); size_t allocation_size = m_byte_size + alignment; - m_allocated_buffer = static_cast(ngraph_malloc(allocation_size)); + m_allocated_buffer = new char[allocation_size]; m_aligned_buffer = m_allocated_buffer; size_t mod = (alignment != 0) ? size_t(m_aligned_buffer) % alignment : 0; @@ -38,14 +40,14 @@ runtime::AlignedBuffer::AlignedBuffer(AlignedBuffer&& other) runtime::AlignedBuffer::~AlignedBuffer() { if (m_allocated_buffer != nullptr) { - free(m_allocated_buffer); + delete[] m_allocated_buffer; } } runtime::AlignedBuffer& runtime::AlignedBuffer::operator=(AlignedBuffer&& other) { if (this != &other) { if (m_allocated_buffer != nullptr) { - free(m_allocated_buffer); + delete[] m_allocated_buffer; } m_allocated_buffer = other.m_allocated_buffer; m_aligned_buffer = other.m_aligned_buffer; @@ -56,9 +58,60 @@ runtime::AlignedBuffer& runtime::AlignedBuffer::operator=(AlignedBuffer&& other) } return *this; } +} // namespace ngraph namespace ov { -AttributeAdapter>::AttributeAdapter( - shared_ptr& value) - : DirectValueAccessor>(value) {} +AttributeAdapter>::AttributeAdapter( + std::shared_ptr& value) + : DirectValueAccessor>(value) {} +} // namespace ov +NGRAPH_SUPPRESS_DEPRECATED_END + +namespace ov { +AlignedBuffer::AlignedBuffer() : m_allocated_buffer(nullptr), m_aligned_buffer(nullptr), m_byte_size(0) {} + +AlignedBuffer::AlignedBuffer(size_t byte_size, size_t alignment) : m_byte_size(byte_size) { + m_byte_size = std::max(1, byte_size); + size_t allocation_size = m_byte_size + alignment; + m_allocated_buffer = new char[allocation_size]; + m_aligned_buffer = m_allocated_buffer; + size_t mod = (alignment != 0) ? reinterpret_cast(m_aligned_buffer) % alignment : 0; + + if (mod != 0) { + m_aligned_buffer += (alignment - mod); + } +} + +AlignedBuffer::AlignedBuffer(AlignedBuffer&& other) + : m_allocated_buffer(other.m_allocated_buffer), + m_aligned_buffer(other.m_aligned_buffer), + m_byte_size(other.m_byte_size) { + other.m_allocated_buffer = nullptr; + other.m_aligned_buffer = nullptr; + other.m_byte_size = 0; +} + +AlignedBuffer::~AlignedBuffer() { + if (m_allocated_buffer != nullptr) { + delete[] m_allocated_buffer; + } +} + +AlignedBuffer& AlignedBuffer::operator=(AlignedBuffer&& other) { + if (this != &other) { + if (m_allocated_buffer != nullptr) { + delete[] m_allocated_buffer; + } + m_allocated_buffer = other.m_allocated_buffer; + m_aligned_buffer = other.m_aligned_buffer; + m_byte_size = other.m_byte_size; + other.m_allocated_buffer = nullptr; + other.m_aligned_buffer = nullptr; + other.m_byte_size = 0; + } + return *this; +} + +AttributeAdapter>::AttributeAdapter(std::shared_ptr& value) + : DirectValueAccessor>(value) {} } // namespace ov diff --git a/src/core/src/runtime/tensor.cpp b/src/core/src/runtime/tensor.cpp index 7f0c51fa45fea0..f7f587d1a95e9d 100644 --- a/src/core/src/runtime/tensor.cpp +++ b/src/core/src/runtime/tensor.cpp @@ -4,10 +4,6 @@ #include "ngraph/runtime/tensor.hpp" -#include "ngraph/log.hpp" -#include "ngraph/runtime/aligned_buffer.hpp" -#include "ngraph/type/element_type.hpp" - using namespace ngraph; using namespace std; diff --git a/src/core/src/shape_util.cpp b/src/core/src/shape_util.cpp index 9ce8512d7a7797..72c72c39b68d4f 100644 --- a/src/core/src/shape_util.cpp +++ b/src/core/src/shape_util.cpp @@ -9,10 +9,9 @@ #include "openvino/core/partial_shape.hpp" #include "openvino/core/shape_util.hpp" -using namespace ngraph; - +namespace ngraph { template <> -PartialShape ngraph::project(const PartialShape& shape, const AxisSet& axes) { +PartialShape project(const PartialShape& shape, const AxisSet& axes) { if (shape.rank().is_dynamic()) { return shape; } else { @@ -29,7 +28,7 @@ PartialShape ngraph::project(const PartialShape& shape, const AxisSet& axes) { } template <> -PartialShape ngraph::reduce(const PartialShape& shape, const AxisSet& deleted_axes, bool keep_dims) { +PartialShape reduce(const PartialShape& shape, const AxisSet& deleted_axes, bool keep_dims) { if (shape.rank().is_dynamic()) { return shape; } else { @@ -49,8 +48,8 @@ PartialShape ngraph::reduce(const PartialShape& shape, const AxisSet& deleted_ax } template <> -PartialShape ngraph::inject_pairs(const PartialShape& shape, - std::vector> new_axis_pos_value_pairs) { +PartialShape inject_pairs(const PartialShape& shape, + std::vector> new_axis_pos_value_pairs) { if (shape.rank().is_dynamic()) { return shape; } else { @@ -76,6 +75,7 @@ PartialShape ngraph::inject_pairs(const PartialShape& shape, return PartialShape{result_dims}; } } +} // namespace ngraph namespace ov { template diff --git a/src/core/src/util.cpp b/src/core/src/util.cpp index 3c12bd5cb10881..49ae1575101e7b 100644 --- a/src/core/src/util.cpp +++ b/src/core/src/util.cpp @@ -13,21 +13,13 @@ #include #include -#include "ngraph/coordinate_diff.hpp" -#include "ngraph/function.hpp" -#include "ngraph/graph_util.hpp" -#include "ngraph/log.hpp" -#include "ngraph/node.hpp" -#include "ngraph/op/result.hpp" -#include "ngraph/partial_shape.hpp" -#include "ngraph/shape.hpp" #include "openvino/util/common_util.hpp" #include "openvino/util/log.hpp" -NGRAPH_SUPPRESS_DEPRECATED_START -using namespace std; +OPENVINO_SUPPRESS_DEPRECATED_START -void ngraph::dump(ostream& out, const void* _data, size_t _size) { +namespace ngraph { +void dump(std::ostream& out, const void* _data, size_t _size) { auto flags = out.flags(); const uint8_t* data = reinterpret_cast(_data); size_t len = _size; @@ -61,27 +53,27 @@ void ngraph::dump(ostream& out, const void* _data, size_t _size) { out.flags(flags); } -std::string ngraph::to_lower(const std::string& s) { +std::string to_lower(const std::string& s) { return ov::util::to_lower(s); } -std::string ngraph::to_upper(const std::string& s) { +std::string to_upper(const std::string& s) { return ov::util::to_upper(s); } -string ngraph::trim(const string& s) { +std::string trim(const std::string& s) { return ov::util::trim(s); } -vector ngraph::split(const string& src, char delimiter, bool do_trim) { +std::vector split(const std::string& src, char delimiter, bool do_trim) { return ov::util::split(src, delimiter, do_trim); } -size_t ngraph::hash_combine(const std::vector& list) { +size_t hash_combine(const std::vector& list) { return ov::util::hash_combine(list); } -void* ngraph::ngraph_malloc(size_t size) { +void* ngraph_malloc(size_t size) { auto ptr = malloc(size); if (size != 0 && !ptr) { OPENVINO_ERR << "malloc failed to allocate memory of size " << size; @@ -90,13 +82,13 @@ void* ngraph::ngraph_malloc(size_t size) { return ptr; } -void ngraph::ngraph_free(void* ptr) { +void ngraph_free(void* ptr) { if (ptr) { free(ptr); } } -size_t ngraph::round_up(size_t size, size_t alignment) { +size_t round_up(size_t size, size_t alignment) { if (alignment == 0) { return size; } @@ -109,27 +101,27 @@ size_t ngraph::round_up(size_t size, size_t alignment) { return size + alignment - remainder; } -size_t ngraph::stopwatch::get_call_count() const { +size_t stopwatch::get_call_count() const { return m_total_count; } -size_t ngraph::stopwatch::get_seconds() const { - return chrono::duration_cast(get_timer_value()).count(); +size_t stopwatch::get_seconds() const { + return std::chrono::duration_cast(get_timer_value()).count(); } -size_t ngraph::stopwatch::get_milliseconds() const { - return chrono::duration_cast(get_timer_value()).count(); +size_t stopwatch::get_milliseconds() const { + return std::chrono::duration_cast(get_timer_value()).count(); } -size_t ngraph::stopwatch::get_microseconds() const { - return chrono::duration_cast(get_timer_value()).count(); +size_t stopwatch::get_microseconds() const { + return std::chrono::duration_cast(get_timer_value()).count(); } -size_t ngraph::stopwatch::get_nanoseconds() const { +size_t stopwatch::get_nanoseconds() const { return get_timer_value().count(); } -chrono::nanoseconds ngraph::stopwatch::get_timer_value() const { +std::chrono::nanoseconds stopwatch::get_timer_value() const { if (m_active) { return (m_clock.now() - m_start_time); } else { @@ -137,23 +129,22 @@ chrono::nanoseconds ngraph::stopwatch::get_timer_value() const { } } -size_t ngraph::stopwatch::get_total_seconds() const { - return chrono::duration_cast(m_total_time).count(); +size_t stopwatch::get_total_seconds() const { + return std::chrono::duration_cast(m_total_time).count(); } -size_t ngraph::stopwatch::get_total_milliseconds() const { - return chrono::duration_cast(m_total_time).count(); +size_t stopwatch::get_total_milliseconds() const { + return std::chrono::duration_cast(m_total_time).count(); } -size_t ngraph::stopwatch::get_total_microseconds() const { - return chrono::duration_cast(m_total_time).count(); +size_t stopwatch::get_total_microseconds() const { + return std::chrono::duration_cast(m_total_time).count(); } -size_t ngraph::stopwatch::get_total_nanoseconds() const { +size_t stopwatch::get_total_nanoseconds() const { return m_total_time.count(); } -namespace ngraph { template <> float parse_string(const std::string& s) { const char* tmp = s.c_str(); @@ -201,40 +192,30 @@ uint8_t parse_string(const std::string& s) { return result; } -} // namespace ngraph -std::ostream& operator<<(std::ostream& os, const ngraph::NodeVector& nv) { - std::vector names; - for (auto n : nv) { - names.push_back(n->get_name()); - } - os << ngraph::vector_to_string(names); - return os; -} - -ngraph::AxisVector ngraph::get_default_order(const Shape& shape) { +AxisVector get_default_order(const Shape& shape) { return get_default_order(shape.size()); } -ngraph::AxisVector ngraph::get_default_order(const PartialShape& shape) { +AxisVector get_default_order(const PartialShape& shape) { return get_default_order(shape.rank()); } -ngraph::AxisVector ngraph::get_default_order(size_t rank) { +AxisVector get_default_order(size_t rank) { AxisVector default_order(rank); std::iota(begin(default_order), end(default_order), 0); return default_order; } -ngraph::AxisVector ngraph::get_default_order(const Rank& rank) { - NGRAPH_CHECK(rank.is_static(), "Can not calculate default order for dynamic rank"); +AxisVector get_default_order(const Rank& rank) { + OPENVINO_ASSERT(rank.is_static(), "Can not calculate default order for dynamic rank"); AxisVector default_order(rank.get_length()); std::iota(begin(default_order), end(default_order), 0); return default_order; } -void ngraph::parse_version_string(std::string version, size_t& major, size_t& minor, size_t& patch, string& extra) { +void parse_version_string(std::string version, size_t& major, size_t& minor, size_t& patch, std::string& extra) { // Since regex is broken in gcc 4.8 I will just manually parse the version string // Version strings look like `0.25.0-rc.0+7c32240` or `v0.25.0-rc.0+7c32240` size_t start; @@ -242,18 +223,18 @@ void ngraph::parse_version_string(std::string version, size_t& major, size_t& mi extra = ""; start = (version[0] == 'v' ? 1 : 0); end = version.find_first_of('.', start); - string major_str = version.substr(start, end - start); + std::string major_str = version.substr(start, end - start); start = end + 1; end = version.find_first_of('.', start); - string minor_str = version.substr(start, end - start); + std::string minor_str = version.substr(start, end - start); start = end + 1; end = version.find_first_of("-+", start); - string patch_str = version.substr(start, end - start); + std::string patch_str = version.substr(start, end - start); start = end; - if (start != string::npos) { + if (start != std::string::npos) { extra = version.substr(start); } @@ -279,73 +260,74 @@ void ngraph::parse_version_string(std::string version, size_t& major, size_t& mi OPENVINO_THROW("Error parsing version string '", version, "'"); } } +} // namespace ngraph -vector read_float_vector(shared_ptr tv) { - vector float_vec; - ngraph::element::Type element_type = tv->get_element_type(); +std::vector read_float_vector(std::shared_ptr tv) { + std::vector float_vec; + ov::element::Type element_type = tv->get_element_type(); - if (element_type == ngraph::element::boolean) { - vector vec = read_vector(tv); + if (element_type == ov::element::boolean) { + std::vector vec = read_vector(tv); // Changed from vector ctor to explicit for loop to add static_cast // This silences MSVC warnings for (char value : vec) { float_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::bf16) { - vector vec = read_vector(tv); - float_vec = ngraph::bfloat16::to_float_vector(vec); - } else if (element_type == ngraph::element::f16) { - vector vec = read_vector(tv); - for (ngraph::float16 value : vec) { + } else if (element_type == ov::element::bf16) { + std::vector vec = read_vector(tv); + float_vec = ov::bfloat16::to_float_vector(vec); + } else if (element_type == ov::element::f16) { + std::vector vec = read_vector(tv); + for (ov::float16 value : vec) { float_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::f32) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::f32) { + std::vector vec = read_vector(tv); for (float value : vec) { float_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::f64) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::f64) { + std::vector vec = read_vector(tv); for (double value : vec) { float_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::i8) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::i8) { + std::vector vec = read_vector(tv); for (int8_t value : vec) { float_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::i16) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::i16) { + std::vector vec = read_vector(tv); for (int16_t value : vec) { float_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::i32) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::i32) { + std::vector vec = read_vector(tv); for (int32_t value : vec) { float_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::i64) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::i64) { + std::vector vec = read_vector(tv); for (int64_t value : vec) { float_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::u8) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::u8) { + std::vector vec = read_vector(tv); for (uint8_t value : vec) { float_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::u16) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::u16) { + std::vector vec = read_vector(tv); for (uint16_t value : vec) { float_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::u32) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::u32) { + std::vector vec = read_vector(tv); for (uint32_t value : vec) { float_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::u64) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::u64) { + std::vector vec = read_vector(tv); for (uint64_t value : vec) { float_vec.push_back(static_cast(value)); } @@ -356,72 +338,72 @@ vector read_float_vector(shared_ptr tv) { return float_vec; } -vector read_index_vector(shared_ptr tv) { - vector index_vec; - ngraph::element::Type element_type = tv->get_element_type(); +std::vector read_index_vector(std::shared_ptr tv) { + std::vector index_vec; + ov::element::Type element_type = tv->get_element_type(); - if (element_type == ngraph::element::boolean) { - vector vec = read_vector(tv); + if (element_type == ov::element::boolean) { + std::vector vec = read_vector(tv); // Changed from vector ctor to explicit for loop to add static_cast // This silences MSVC warnings for (char value : vec) { index_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::bf16) { - vector vec = read_vector(tv); - vector float_vec = ngraph::bfloat16::to_float_vector(vec); + } else if (element_type == ov::element::bf16) { + std::vector vec = read_vector(tv); + std::vector float_vec = ov::bfloat16::to_float_vector(vec); for (float value : float_vec) { index_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::f16) { - vector vec = read_vector(tv); - for (ngraph::float16 value : vec) { + } else if (element_type == ov::element::f16) { + std::vector vec = read_vector(tv); + for (ov::float16 value : vec) { index_vec.push_back(static_cast(static_cast(value))); } - } else if (element_type == ngraph::element::f32) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::f32) { + std::vector vec = read_vector(tv); for (float value : vec) { index_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::f64) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::f64) { + std::vector vec = read_vector(tv); for (double value : vec) { index_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::i8) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::i8) { + std::vector vec = read_vector(tv); for (int8_t value : vec) { index_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::i16) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::i16) { + std::vector vec = read_vector(tv); for (int16_t value : vec) { index_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::i32) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::i32) { + std::vector vec = read_vector(tv); for (int32_t value : vec) { index_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::i64) { + } else if (element_type == ov::element::i64) { index_vec = read_vector(tv); - } else if (element_type == ngraph::element::u8) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::u8) { + std::vector vec = read_vector(tv); for (uint8_t value : vec) { index_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::u16) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::u16) { + std::vector vec = read_vector(tv); for (uint16_t value : vec) { index_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::u32) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::u32) { + std::vector vec = read_vector(tv); for (uint32_t value : vec) { index_vec.push_back(static_cast(value)); } - } else if (element_type == ngraph::element::u64) { - vector vec = read_vector(tv); + } else if (element_type == ov::element::u64) { + std::vector vec = read_vector(tv); for (uint64_t value : vec) { index_vec.push_back(static_cast(value)); } diff --git a/src/core/src/validation_util.cpp b/src/core/src/validation_util.cpp index 3d2f72b8533825..803364b289008d 100644 --- a/src/core/src/validation_util.cpp +++ b/src/core/src/validation_util.cpp @@ -5,36 +5,25 @@ #include "ngraph/validation_util.hpp" #include -#include -#include #include #include "bound_evaluate.hpp" #include "compare.hpp" #include "ngraph/evaluator.hpp" -#include "ngraph/op/concat.hpp" -#include "ngraph/op/convert.hpp" -#include "ngraph/op/gather.hpp" -#include "ngraph/op/min.hpp" -#include "ngraph/op/minimum.hpp" -#include "ngraph/op/reshape.hpp" -#include "ngraph/op/shape_of.hpp" -#include "ngraph/op/squeeze.hpp" -#include "ngraph/op/unsqueeze.hpp" -#include "ngraph/shape.hpp" -#include "ngraph/type/element_type_traits.hpp" -#include "ngraph/util.hpp" #include "openvino/core/dimension_tracker.hpp" +#include "openvino/op/concat.hpp" +#include "openvino/op/gather.hpp" #include "openvino/op/ops.hpp" #include "sequnce_generator.hpp" #include "validation_util.hpp" -NGRAPH_SUPPRESS_DEPRECATED_START -using namespace std; +OPENVINO_SUPPRESS_DEPRECATED_START -ngraph::Strides ngraph::conv_default_strides(const Node* /* node */, - const PartialShape& data_batch_shape, - const PartialShape& filters_shape) { +namespace ngraph { + +Strides conv_default_strides(const Node* /* node */, + const PartialShape& data_batch_shape, + const PartialShape& filters_shape) { size_t rank; if (data_batch_shape.rank().is_static() && data_batch_shape.rank().get_length() >= 2) { @@ -48,9 +37,9 @@ ngraph::Strides ngraph::conv_default_strides(const Node* /* node */, return Strides(rank, 1); } -ngraph::CoordinateDiff ngraph::conv_default_padding(const Node* /* node */, - const PartialShape& data_batch_shape, - const PartialShape& filters_shape) { +CoordinateDiff conv_default_padding(const Node* /* node */, + const PartialShape& data_batch_shape, + const PartialShape& filters_shape) { size_t rank; if (data_batch_shape.rank().is_static() && data_batch_shape.rank().get_length() >= 2) { @@ -71,16 +60,16 @@ ngraph::CoordinateDiff ngraph::conv_default_padding(const Node* /* node */, // TODO(amprocte): The messages here would be a bit friendlier if we didn't say "after // padding/after dilation" for cases where there is actually no padding/dilation. // -ngraph::PartialShape ngraph::infer_windowed_reduction_output_shape(const Node* node, - const PartialShape& data_shape, - const Strides& data_dilation, - const CoordinateDiff& data_padding_below, - const CoordinateDiff& data_padding_above, - const PartialShape& window_shape, - const Strides& window_strides, - const Strides& window_dilation, - bool is_window_all_in_padding_allowed, - bool ceil_mode) { +PartialShape infer_windowed_reduction_output_shape(const Node* node, + const PartialShape& data_shape, + const Strides& data_dilation, + const CoordinateDiff& data_padding_below, + const CoordinateDiff& data_padding_above, + const PartialShape& window_shape, + const Strides& window_strides, + const Strides& window_dilation, + bool is_window_all_in_padding_allowed, + bool ceil_mode) { PartialShape data_shape_merged{PartialShape::dynamic()}; NODE_VALIDATION_CHECK( @@ -203,13 +192,13 @@ ngraph::PartialShape ngraph::infer_windowed_reduction_output_shape(const Node* n return output_shape; } -void ngraph::validate_conv_params_spatial_dimensions(const Node* node, - const size_t num_spatial_dims, - const op::PadType auto_pad, - Strides& strides, - Strides& dilations, - CoordinateDiff& pads_begin, - CoordinateDiff& pads_end) { +void validate_conv_params_spatial_dimensions(const Node* node, + const size_t num_spatial_dims, + const op::PadType auto_pad, + Strides& strides, + Strides& dilations, + CoordinateDiff& pads_begin, + CoordinateDiff& pads_end) { if (strides.size() == 0) { strides = Strides(num_spatial_dims, 1); } @@ -233,15 +222,15 @@ void ngraph::validate_conv_params_spatial_dimensions(const Node* node, "Pads should be defined for all and only spatial features."); } -ngraph::PartialShape ngraph::validate_and_infer_convolution_forward_output_shape(const Node* node, - const Rank& result_ps_rank, - const PartialShape& data_batch_pshape, - const PartialShape& filters_pshape, - const op::PadType auto_pad, - Strides& strides, - Strides& dilations, - CoordinateDiff& pads_begin, - CoordinateDiff& pads_end) { +PartialShape validate_and_infer_convolution_forward_output_shape(const Node* node, + const Rank& result_ps_rank, + const PartialShape& data_batch_pshape, + const PartialShape& filters_pshape, + const op::PadType auto_pad, + Strides& strides, + Strides& dilations, + CoordinateDiff& pads_begin, + CoordinateDiff& pads_end) { PartialShape result_shape = PartialShape::dynamic(); if (result_ps_rank.is_static()) { const auto num_spatial_dims = result_ps_rank.get_length() - 2; @@ -267,7 +256,7 @@ ngraph::PartialShape ngraph::validate_and_infer_convolution_forward_output_shape pads_end.clear(); const PartialShape filter_spatial_shape = [filters_pshape]() { - vector filter_dims{filters_pshape}; + std::vector filter_dims{filters_pshape}; filter_dims.erase(filter_dims.begin(), filter_dims.begin() + 2); // Remove {C_OUT, C_IN} return PartialShape{filter_dims}; @@ -299,142 +288,18 @@ ngraph::PartialShape ngraph::validate_and_infer_convolution_forward_output_shape return result_shape; } -// -// Infers the output batch shape and element type for convolution fprop. -// -ngraph::PartialShape ov::infer_convolution_forward(const Node* node, - const PartialShape& data_batch_shape, - const Strides& data_dilation, - const CoordinateDiff& data_padding_below, - const CoordinateDiff& data_padding_above, - const PartialShape& filters_shape, - const Strides& filter_strides, - const Strides& filter_dilation) { - Rank data_batch_filters_rank{Rank::dynamic()}; - - NODE_VALIDATION_CHECK(node, - Rank::merge(data_batch_filters_rank, data_batch_shape.rank(), filters_shape.rank()), - "Data batch and filters rank do not match (data batch shape: ", - data_batch_shape, - ", filters shape: ", - filters_shape, - ")."); - - NODE_VALIDATION_CHECK(node, - data_batch_filters_rank.is_dynamic() || data_batch_filters_rank.get_length() >= 3, - "Data batch and filters must have rank of at least 3 (one batch axis, ", - "one input-channel axis, and at least one spatial dimension) ", - "(data batch shape: ", - data_batch_shape, - ", filters shape: ", - filters_shape, - ")."); - - Rank spatial_rank{Rank::dynamic()}; - NODE_VALIDATION_CHECK(node, - Rank::merge(spatial_rank, spatial_rank, data_batch_filters_rank - 2) && - Rank::merge(spatial_rank, spatial_rank, data_dilation.size()) && - Rank::merge(spatial_rank, spatial_rank, data_padding_below.size()) && - Rank::merge(spatial_rank, spatial_rank, data_padding_above.size()) && - Rank::merge(spatial_rank, spatial_rank, filter_strides.size()) && - Rank::merge(spatial_rank, spatial_rank, filter_dilation.size()), - "Ranks for data item shape/filters shape (data batch has shape ", - data_batch_shape, - ", so data item rank is ", - (data_batch_shape.rank() - 2), - " and filters have shape ", - filters_shape, - ", so filters spatial rank is ", - (filters_shape.rank() - 2), - "), data dilation (", - data_dilation, - "), padding below (", - data_padding_below, - "), padding above (", - data_padding_above, - "), filter strides (", - filter_strides, - "), and filter dilation (", - filter_dilation, - ") do not match."); - - Dimension batch_size = (data_batch_shape.rank().is_static() ? data_batch_shape[0] : Dimension::dynamic()); - Dimension data_channel_count = (data_batch_shape.rank().is_static() ? data_batch_shape[1] : Dimension::dynamic()); - PartialShape data_spatial_shape(PartialShape::dynamic(spatial_rank)); - - Dimension filter_output_channel_count = - (filters_shape.rank().is_static() ? filters_shape[0] : Dimension::dynamic()); - Dimension filter_input_channel_count = (filters_shape.rank().is_static() ? filters_shape[1] : Dimension::dynamic()); - PartialShape filter_spatial_shape(PartialShape::dynamic(spatial_rank)); - - // - // Note: spatial_rank is definitely static at this point. - // - - for (int64_t i = 0; i < spatial_rank.get_length(); i++) { - if (data_batch_shape.rank().is_static()) { - data_spatial_shape[i] = data_batch_shape[i + 2]; - } - - if (filters_shape.rank().is_static()) { - filter_spatial_shape[i] = filters_shape[i + 2]; - } - } - - NODE_VALIDATION_CHECK(node, batch_size.is_dynamic() || batch_size.get_length() > 0, "Batch size is zero."); - - Dimension merged_channel_count; - - NODE_VALIDATION_CHECK(node, - Dimension::merge(merged_channel_count, data_channel_count, filter_input_channel_count), - "Data batch channel count (", - data_channel_count, - ") does not match filter input ", - "channel count (", - filter_input_channel_count, - ")."); - - NODE_VALIDATION_CHECK(node, - merged_channel_count.is_dynamic() || merged_channel_count.get_length() > 0, - "Data batch channel count and/or filter input channel count is zero."); - - NODE_VALIDATION_CHECK(node, - filter_output_channel_count.is_dynamic() || filter_output_channel_count.get_length() > 0, - "Filter output channel count is zero."); - - PartialShape data_output_shape = ngraph::infer_windowed_reduction_output_shape(node, - data_spatial_shape, - data_dilation, - data_padding_below, - data_padding_above, - filter_spatial_shape, - filter_strides, - filter_dilation, - true); - - PartialShape batch_output_shape(PartialShape::dynamic(spatial_rank + 2)); - batch_output_shape[0] = batch_size; - batch_output_shape[1] = filter_output_channel_count; - - for (int64_t i = 0; i < spatial_rank.get_length(); i++) { - batch_output_shape[i + 2] = data_output_shape[i]; - } - - return batch_output_shape; -} - // // Infers the output batch shape and element type for batched pooling fprop. // -ngraph::PartialShape ngraph::infer_batched_pooling_forward(const Node* node, - const PartialShape& data_batch_shape, - const CoordinateDiff& data_padding_below, - const CoordinateDiff& data_padding_above, - const PartialShape& window_shape, - const Strides& window_strides, - bool is_window_all_in_padding_allowed, - bool ceil_mode, - const Strides& window_dilation) { +PartialShape infer_batched_pooling_forward(const Node* node, + const PartialShape& data_batch_shape, + const CoordinateDiff& data_padding_below, + const CoordinateDiff& data_padding_above, + const PartialShape& window_shape, + const Strides& window_strides, + bool is_window_all_in_padding_allowed, + bool ceil_mode, + const 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), @@ -517,15 +382,15 @@ ngraph::PartialShape ngraph::infer_batched_pooling_forward(const Node* node, } struct ChannelShapedInputSpec { - ngraph::element::Type m_element_type; - ngraph::PartialShape m_shape; + element::Type m_element_type; + PartialShape m_shape; std::string m_input_name; }; -static std::tuple infer_batch_norm_forward_helper( - const ngraph::Node* node, - ngraph::element::Type input_element_type, - const ngraph::PartialShape& input_shape, +static std::tuple infer_batch_norm_forward_helper( + const Node* node, + element::Type input_element_type, + const PartialShape& input_shape, const std::vector& channel_shaped_inputs) { // Built up a slash-separated string naming all the channel-shaped inputs, for use in error // messages. @@ -541,11 +406,11 @@ static std::tuple= 2, @@ -570,11 +435,11 @@ static std::tuple ngraph::infer_batch_norm_forward( - const Node* node, - element::Type input_element_type, - element::Type gamma_element_type, - element::Type beta_element_type, - element::Type mean_element_type, - element::Type variance_element_type, - const PartialShape& input_shape, - const PartialShape& gamma_shape, - const PartialShape& beta_shape, - const PartialShape& mean_shape, - const PartialShape& variance_shape) { +std::tuple infer_batch_norm_forward(const Node* node, + element::Type input_element_type, + element::Type gamma_element_type, + element::Type beta_element_type, + element::Type mean_element_type, + element::Type variance_element_type, + const PartialShape& input_shape, + const PartialShape& gamma_shape, + const PartialShape& beta_shape, + const PartialShape& mean_shape, + const PartialShape& variance_shape) { return infer_batch_norm_forward_helper(node, input_element_type, input_shape, @@ -634,14 +498,13 @@ std::tuple ng {variance_element_type, variance_shape, "variance"}}); } -std::tuple ngraph::infer_batch_norm_forward( - const Node* node, - element::Type input_element_type, - element::Type gamma_element_type, - element::Type beta_element_type, - const PartialShape& input_shape, - const PartialShape& gamma_shape, - const PartialShape& beta_shape) { +std::tuple infer_batch_norm_forward(const Node* node, + element::Type input_element_type, + element::Type gamma_element_type, + element::Type beta_element_type, + const PartialShape& input_shape, + const PartialShape& gamma_shape, + const PartialShape& beta_shape) { return infer_batch_norm_forward_helper( node, input_element_type, @@ -649,64 +512,13 @@ std::tuple ng {{gamma_element_type, gamma_shape, "gamma"}, {beta_element_type, beta_shape, "beta"}}); } -void ov::infer_auto_padding(const Shape& image_shape, +bool try_apply_auto_padding(const PartialShape& image_shape, const Shape& filter_shape, const Strides& filter_strides, const Strides& filter_dilations, const op::PadType pad_type, CoordinateDiff& padding_above, CoordinateDiff& padding_below) { - const auto image_dims = std::vector(std::begin(image_shape), std::end(image_shape)); - // because image_shape is fully known result of try_apply_infer_auto_padding is ignored - ov::util::try_apply_auto_padding(image_dims, - filter_shape, - filter_strides, - filter_dilations, - pad_type, - padding_above, - padding_below); -} - -bool ov::util::try_apply_auto_padding(const PartialShape& image_shape, - const Shape& filter_shape, - const Strides& filter_strides, - const Strides& filter_dilations, - const op::PadType pad_type, - CoordinateDiff& padding_above, - CoordinateDiff& padding_below) { - OPENVINO_ASSERT(pad_type == op::PadType::SAME_UPPER || pad_type == op::PadType::SAME_LOWER); - - if (image_shape.rank().is_dynamic()) { - return false; - } - const auto image_dims = static_cast>(image_shape); - for (size_t i = 0; i < static_cast(filter_shape.size()); i++) { - if (image_dims[i + 2].is_static()) { - auto image_size = static_cast(image_dims[i + 2].get_length()); - int64_t filter_size = (static_cast(filter_shape[i]) - 1) * filter_dilations[i] + 1; - auto filter_stride = static_cast(filter_strides[i]); - auto output_size = (image_size + filter_stride - 1) / filter_stride; - - auto padding_needed = std::max(int64_t(0), (output_size - 1) * filter_stride + filter_size - image_size); - auto padding_lhs = padding_needed / 2; - auto padding_rhs = padding_needed - padding_lhs; - padding_below.push_back(pad_type == op::PadType::SAME_UPPER ? padding_lhs : padding_rhs); - padding_above.push_back(pad_type == op::PadType::SAME_UPPER ? padding_rhs : padding_lhs); - } else { - padding_below.push_back(0); - padding_above.push_back(0); - } - } - return true; -} - -bool ngraph::try_apply_auto_padding(const PartialShape& image_shape, - const Shape& filter_shape, - const Strides& filter_strides, - const Strides& filter_dilations, - const op::PadType pad_type, - CoordinateDiff& padding_above, - CoordinateDiff& padding_below) { return ov::util::try_apply_auto_padding(image_shape, filter_shape, filter_strides, @@ -716,16 +528,16 @@ bool ngraph::try_apply_auto_padding(const PartialShape& image_shape, padding_below); } -ngraph::PartialShape ngraph::infer_slice_shape(const Node* node, - const PartialShape& input_shape, - const std::vector& begin, - const std::vector& end, - const std::vector& strides, - const AxisSet& begin_mask, - const AxisSet& end_mask, - const AxisSet& new_axis_mask, - const AxisSet& shrink_axis_mask, - const AxisSet& ellipsis_mask) { +PartialShape infer_slice_shape(const Node* node, + const PartialShape& input_shape, + const std::vector& begin, + const std::vector& end, + const std::vector& strides, + const AxisSet& begin_mask, + const AxisSet& end_mask, + const AxisSet& new_axis_mask, + const AxisSet& shrink_axis_mask, + const AxisSet& ellipsis_mask) { if (begin.size() && end.size()) { NODE_VALIDATION_CHECK(node, begin.size() == end.size(), @@ -869,146 +681,58 @@ ngraph::PartialShape ngraph::infer_slice_shape(const Node* node, return dim; } -namespace { -const auto normalize_axis_to = [](const int64_t& tensor_rank) { - return [&tensor_rank](int64_t& axis) { - if (axis < 0) { - axis += tensor_rank; - } - }; -}; - -std::string normalize_axis_error_msg(const int64_t& axis, const int64_t& lower, const int64_t& upper) { - return std::string(" Parameter axis ") - .append(to_string(axis)) - .append(" out of the tensor rank range [") - .append(to_string(lower)) - .append(", ") - .append(to_string(upper)) - .append("]."); -} -} // namespace +void opset1::infer_conv_backprop_auto_padding(const Shape& input_data_shape, + const Shape& filters_shape, + const Shape& output_shape, + const Strides& strides, + const Strides& dilations, + const op::PadType auto_pad_type, + const CoordinateDiff& output_padding, + CoordinateDiff& pads_begin, + CoordinateDiff& pads_end) { + OPENVINO_ASSERT(auto_pad_type == op::PadType::SAME_UPPER || auto_pad_type == op::PadType::SAME_LOWER); -int64_t ov::util::normalize(const int64_t& value, const int64_t& max) { - return (value < 0) ? value + max : value; -}; + size_t num_spatial_dims = input_data_shape.size(); + OPENVINO_ASSERT(filters_shape.size() == num_spatial_dims && strides.size() == num_spatial_dims && + dilations.size() == num_spatial_dims && pads_begin.size() == num_spatial_dims && + pads_end.size() == num_spatial_dims && output_padding.size() == num_spatial_dims); -void ov::normalize_axes(const Node* node, const int64_t& tensor_rank, std::vector& axes) { - const auto axis_checker = cmp::Between(-tensor_rank, tensor_rank ? (tensor_rank - 1) : 0); - const auto invalid_axis = std::find_if_not(axes.cbegin(), axes.cend(), axis_checker); - NODE_VALIDATION_CHECK(node, - invalid_axis == axes.cend(), - normalize_axis_error_msg(*invalid_axis, axis_checker.lower(), axis_checker.upper())); - std::for_each(axes.begin(), axes.end(), normalize_axis_to(tensor_rank)); -} + pads_begin = CoordinateDiff(num_spatial_dims); + pads_end = CoordinateDiff(num_spatial_dims); -std::vector ov::normalize_axes(const std::string& node_description, - const std::vector& axes, - const Rank& tensor_rank) { - std::vector new_axes; - new_axes.reserve(axes.size()); - for (const auto& axis : axes) { - new_axes.push_back(normalize_axis(node_description, axis, tensor_rank)); + for (uint64_t i = 0; i < num_spatial_dims; ++i) { + int total_padding = std::max( + static_cast(strides[i] * (input_data_shape[i] - 1) + dilations[i] * (filters_shape[i] - 1) + 1 - + output_shape[i] + output_padding[i]), + 0); + if (auto_pad_type != op::PadType::SAME_UPPER) { + pads_begin[i] = total_padding / 2; + pads_end[i] = total_padding - pads_begin[i]; + } else { + pads_end[i] = total_padding / 2; + pads_begin[i] = total_padding - pads_end[i]; + } } - return new_axes; -} - -int64_t ov::normalize_axis(const Node* node, std::int64_t axis, const Rank& tensor_rank) { - return normalize_axis(node->description(), axis, tensor_rank); } -int64_t ov::normalize_axis(const std::string& node_description, std::int64_t axis, const Rank& tensor_rank) { - if (axis < 0) { - // Handling negative axis requires static tensor rank - NGRAPH_CHECK(tensor_rank.is_static(), - node_description, - " Rank must be static in order to normalize negative axis=", - axis); - } - if (tensor_rank.is_dynamic()) { - return axis; +namespace { +/// \brief Scalar variant describes value of an Output, for use in max shape determination +/// +/// For tensor values, we use the maximum value in the tensor +struct MaxValue { + /// \brief No information known about the output + MaxValue() = default; + /// \brief uint64_t assoiated with the output + MaxValue(uint64_t value) : m_value(value) {} + MaxValue(const std::vector& slices, int64_t slice_axis) : m_slices(slices), m_slice_axis(slice_axis) { + m_value = *max_element(m_slices.begin(), m_slices.end()); } + uint64_t m_value{std::numeric_limits::max()}; + std::vector m_slices; + int64_t m_slice_axis{-1}; +}; - const auto tensor_rank_value = tensor_rank.get_length(); - return normalize_axis(node_description, - axis, - tensor_rank_value, - -tensor_rank_value, - tensor_rank_value ? (tensor_rank_value - 1) : 0); -} - -int64_t ov::normalize_axis(const Node* node, - std::int64_t axis, - std::uint64_t tensor_rank, - std::int64_t axis_range_min, - std::int64_t axis_range_max) { - return normalize_axis(node->description(), axis, tensor_rank, axis_range_min, axis_range_max); -} - -int64_t ov::normalize_axis(const std::string& node_description, - std::int64_t axis, - std::uint64_t tensor_rank, - std::int64_t axis_range_min, - std::int64_t axis_range_max) { - // Accepted range of value for axis is [axis_range_min, axis_range_max]. - OPENVINO_ASSERT((axis_range_min <= axis) && (axis <= axis_range_max), - node_description, - normalize_axis_error_msg(axis, axis_range_min, axis_range_max)); - return util::normalize(axis, tensor_rank); -} - -void ngraph::opset1::infer_conv_backprop_auto_padding(const Shape& input_data_shape, - const Shape& filters_shape, - const Shape& output_shape, - const Strides& strides, - const Strides& dilations, - const op::PadType auto_pad_type, - const CoordinateDiff& output_padding, - CoordinateDiff& pads_begin, - CoordinateDiff& pads_end) { - NGRAPH_CHECK(auto_pad_type == op::PadType::SAME_UPPER || auto_pad_type == op::PadType::SAME_LOWER); - - size_t num_spatial_dims = input_data_shape.size(); - NGRAPH_CHECK(filters_shape.size() == num_spatial_dims && strides.size() == num_spatial_dims && - dilations.size() == num_spatial_dims && pads_begin.size() == num_spatial_dims && - pads_end.size() == num_spatial_dims && output_padding.size() == num_spatial_dims); - - pads_begin = CoordinateDiff(num_spatial_dims); - pads_end = CoordinateDiff(num_spatial_dims); - - for (uint64_t i = 0; i < num_spatial_dims; ++i) { - int total_padding = std::max( - static_cast(strides[i] * (input_data_shape[i] - 1) + dilations[i] * (filters_shape[i] - 1) + 1 - - output_shape[i] + output_padding[i]), - 0); - if (auto_pad_type != op::PadType::SAME_UPPER) { - pads_begin[i] = total_padding / 2; - pads_end[i] = total_padding - pads_begin[i]; - } else { - pads_end[i] = total_padding / 2; - pads_begin[i] = total_padding - pads_end[i]; - } - } -} - -namespace { -/// \brief Scalar variant describes value of an Output, for use in max shape determination -/// -/// For tensor values, we use the maximum value in the tensor -struct MaxValue { - /// \brief No information known about the output - MaxValue() = default; - /// \brief uint64_t assoiated with the output - MaxValue(uint64_t value) : m_value(value) {} - MaxValue(const vector& slices, int64_t slice_axis) : m_slices(slices), m_slice_axis(slice_axis) { - m_value = *max_element(m_slices.begin(), m_slices.end()); - } - uint64_t m_value{numeric_limits::max()}; - vector m_slices; - int64_t m_slice_axis{-1}; -}; - -vector exec_constant(ngraph::Node* node, vector& inputs) { +std::vector exec_constant(Node* node, std::vector& inputs) { auto result = MaxValue(); auto op = ov::as_type(node); auto element_type = op->get_output_element_type(0); @@ -1032,44 +756,44 @@ vector exec_constant(ngraph::Node* node, vector& inputs) { return {result}; } -vector exec_minimum(ngraph::Node* node, vector& inputs) { - uint64_t min_value = numeric_limits::max(); +std::vector exec_minimum(Node* node, std::vector& inputs) { + uint64_t min_value = std::numeric_limits::max(); switch (node->get_output_element_type(0)) { - case ngraph::element::Type_t::i8: - min_value = numeric_limits::max(); + case element::Type_t::i8: + min_value = std::numeric_limits::max(); break; - case ngraph::element::Type_t::i16: - min_value = numeric_limits::max(); + case element::Type_t::i16: + min_value = std::numeric_limits::max(); break; - case ngraph::element::Type_t::i32: - min_value = numeric_limits::max(); + case element::Type_t::i32: + min_value = std::numeric_limits::max(); break; - case ngraph::element::Type_t::i64: - min_value = numeric_limits::max(); + case element::Type_t::i64: + min_value = std::numeric_limits::max(); break; - case ngraph::element::Type_t::u8: - min_value = numeric_limits::max(); + case element::Type_t::u8: + min_value = std::numeric_limits::max(); break; - case ngraph::element::Type_t::u16: - min_value = numeric_limits::max(); + case element::Type_t::u16: + min_value = std::numeric_limits::max(); break; - case ngraph::element::Type_t::u32: - min_value = numeric_limits::max(); + case element::Type_t::u32: + min_value = std::numeric_limits::max(); break; - case ngraph::element::Type_t::u64: - min_value = numeric_limits::max(); + case element::Type_t::u64: + min_value = std::numeric_limits::max(); break; default: break; } - min_value = min(min_value, inputs.at(0).m_value); - min_value = min(min_value, inputs.at(1).m_value); + min_value = std::min(min_value, inputs.at(0).m_value); + min_value = std::min(min_value, inputs.at(1).m_value); return {MaxValue(min_value)}; } -vector exec_concat(ngraph::Node* node, vector& inputs) { - auto op = ov::as_type(node); - vector slice_maxen; +std::vector exec_concat(Node* node, std::vector& inputs) { + auto op = ov::as_type(node); + std::vector slice_maxen; for (const auto& input : inputs) { slice_maxen.push_back(input.m_value); } @@ -1077,13 +801,13 @@ vector exec_concat(ngraph::Node* node, vector& inputs) { return {MaxValue(slice_maxen, axis)}; } -vector exec_reduce_min(ngraph::Node* node, vector& inputs) { +std::vector exec_reduce_min(Node* node, std::vector& inputs) { auto data = inputs.at(0); if (data.m_slice_axis >= 0 && data.m_slices.size() > 1) { - if (auto indices_const = ov::as_type(node->get_input_node_ptr(1))) { + if (auto indices_const = ov::as_type(node->get_input_node_ptr(1))) { if (indices_const->get_output_element_type(0).is_integral()) { const auto& indices_shape = indices_const->get_output_shape(0); - if (indices_shape == ngraph::Shape{1}) { + if (indices_shape == Shape{1}) { auto indices = indices_const->cast_vector(); auto axis = indices.at(0); if (axis == data.m_slice_axis) { @@ -1097,7 +821,7 @@ vector exec_reduce_min(ngraph::Node* node, vector& inputs) { return {MaxValue(data.m_value)}; } -vector exec_shape_of(ngraph::Node* node, vector& inputs) { +std::vector exec_shape_of(Node* node, std::vector& inputs) { const auto& inputPS = node->get_input_partial_shape(0); std::vector shapeDims; for (int64_t i = 0; i < inputPS.rank().get_length(); i++) { @@ -1111,11 +835,11 @@ vector exec_shape_of(ngraph::Node* node, vector& inputs) { return {MaxValue(shapeDims, 0)}; } -vector exec_gather(ngraph::Node* node, vector& inputs) { - auto gather = ov::as_type(node); +std::vector exec_gather(Node* node, std::vector& inputs) { + auto gather = ov::as_type(node); - const auto& indices = ov::as_type_ptr(node->input_value(1).get_node_shared_ptr()); - const auto& axis = ov::as_type_ptr(node->input_value(2).get_node_shared_ptr()); + const auto& indices = ov::as_type_ptr(node->input_value(1).get_node_shared_ptr()); + const auto& axis = ov::as_type_ptr(node->input_value(2).get_node_shared_ptr()); if (!indices || !axis) { return {MaxValue()}; @@ -1133,32 +857,33 @@ vector exec_gather(ngraph::Node* node, vector& inputs) { return {MaxValue(inputs[0].m_slices[indicesVec[0]])}; } -vector exec_nop(ngraph::Node* node, vector& inputs) { +std::vector exec_nop(Node* node, std::vector& inputs) { return {inputs.at(0)}; } } // namespace -pair ngraph::maximum_value(const Output& value) { - static Evaluator::op_handler_map handlers = {{op::v0::Concat::get_type_info_static(), exec_concat}, - {op::v0::Constant::get_type_info_static(), exec_constant}, - {op::v0::Convert::get_type_info_static(), exec_nop}, - {op::v1::Gather::get_type_info_static(), exec_gather}, - {op::v1::Minimum::get_type_info_static(), exec_minimum}, - {op::v1::ReduceMin::get_type_info_static(), exec_reduce_min}, - {op::v1::Reshape::get_type_info_static(), exec_nop}, - {op::v3::ShapeOf::get_type_info_static(), exec_shape_of}, - {op::v0::Squeeze::get_type_info_static(), exec_nop}, - {op::v0::Unsqueeze::get_type_info_static(), exec_nop}}; +std::pair maximum_value(const Output& value) { + static ngraph::Evaluator::op_handler_map handlers = { + {ov::op::v0::Concat::get_type_info_static(), exec_concat}, + {ov::op::v0::Constant::get_type_info_static(), exec_constant}, + {ov::op::v0::Convert::get_type_info_static(), exec_nop}, + {ov::op::v1::Gather::get_type_info_static(), exec_gather}, + {ov::op::v1::Minimum::get_type_info_static(), exec_minimum}, + {ov::op::v1::ReduceMin::get_type_info_static(), exec_reduce_min}, + {ov::op::v1::Reshape::get_type_info_static(), exec_nop}, + {ov::op::v3::ShapeOf::get_type_info_static(), exec_shape_of}, + {ov::op::v0::Squeeze::get_type_info_static(), exec_nop}, + {ov::op::v0::Unsqueeze::get_type_info_static(), exec_nop}}; Evaluator::value_map value_map; Evaluator evaluator(handlers, value_map); auto val = evaluator.evaluate(value); - return pair(val.m_value < numeric_limits::max(), val.m_value); + return std::pair(val.m_value < std::numeric_limits::max(), val.m_value); } -void ngraph::evaluate_nodes(std::map& value_map, - std::map& output_tensor_map, - const OutputVector& outputs, - const EvaluationContext& evaluation_context) { +void evaluate_nodes(std::map& value_map, + std::map& output_tensor_map, + const OutputVector& outputs, + const EvaluationContext& evaluation_context) { Evaluator evaluator({}, value_map); evaluator.set_universal_handler( [&output_tensor_map, &evaluation_context](Node* node, @@ -1167,7 +892,7 @@ void ngraph::evaluate_nodes(std::map& value_map, for (const auto& v : node->outputs()) { auto it = output_tensor_map.find(v); if (it == output_tensor_map.end()) { - auto c = make_shared(v); + auto c = std::make_shared(v); output_tensors.push_back(c); } else { output_tensors.push_back(it->second); @@ -1176,7 +901,7 @@ void ngraph::evaluate_nodes(std::map& value_map, if (node->evaluate(output_tensors, input_tensors, evaluation_context)) { return output_tensors; } else { - NGRAPH_CHECK(false, "Evaluation failed on ", node); + OPENVINO_THROW("Evaluation failed on ", node); } }); for (const auto& value : outputs) { @@ -1184,45 +909,8 @@ void ngraph::evaluate_nodes(std::map& value_map, } } -bool ov::evaluate_as_partial_shape(const Output& output, PartialShape& pshape) { - Tensor lb, ub; - std::tie(lb, ub) = ov::evaluate_both_bounds(output); - bool shape_defined = false; - if (lb && ub) { - auto lower_bound = std::make_shared(lb.get_element_type(), lb.get_shape(), lb.data()) - ->cast_vector(); - auto upper_bound = std::make_shared(ub.get_element_type(), ub.get_shape(), ub.data()) - ->cast_vector(); - NGRAPH_CHECK(lower_bound.size() == upper_bound.size()); - const TensorLabel& labels = output.get_tensor().get_value_label(); - NGRAPH_CHECK(labels.empty() || lower_bound.size() == labels.size()); - - vector resulting_pshape(lower_bound.size()); - for (size_t i = 0; i < lower_bound.size(); ++i) { - auto low = lower_bound[i], up = upper_bound[i]; - NGRAPH_CHECK(low >= 0 && up >= 0, "Value for partial shape evaluation can't be lower than zero."); - if (output.get_element_type() == element::i32 && low != up) { - if (up == std::numeric_limits::max()) - up = std::numeric_limits::max(); - if (low == std::numeric_limits::max()) - low = std::numeric_limits::max(); - } - resulting_pshape[i] = {low, up}; - if (!labels.empty() && labels[i]) - ov::DimensionTracker::set_label(resulting_pshape[i], labels[i]); - } - pshape = PartialShape(resulting_pshape); - shape_defined = true; - } - return shape_defined; -} - -bool ov::default_label_evaluator(const Node* node, TensorLabelVector& output_labels) { - return default_label_evaluator(node, {0}, output_labels); -} - -shared_ptr ngraph::get_constant_max_of_type(element::Type_t t) { -#define NGRAPH_TYPE_TO_MAX_CONST(t) \ +std::shared_ptr get_constant_max_of_type(element::Type_t t) { +#define OPENVINO_TYPE_TO_MAX_CONST(t) \ case t: \ return ov::op::v0::Constant::create( \ t, \ @@ -1231,27 +919,27 @@ shared_ptr ngraph::get_constant_max_of_type(element::T break switch (t) { - NGRAPH_TYPE_TO_MAX_CONST(element::boolean); - NGRAPH_TYPE_TO_MAX_CONST(element::bf16); - NGRAPH_TYPE_TO_MAX_CONST(element::f16); - NGRAPH_TYPE_TO_MAX_CONST(element::f32); - NGRAPH_TYPE_TO_MAX_CONST(element::f64); - NGRAPH_TYPE_TO_MAX_CONST(element::i8); - NGRAPH_TYPE_TO_MAX_CONST(element::i16); - NGRAPH_TYPE_TO_MAX_CONST(element::i32); - NGRAPH_TYPE_TO_MAX_CONST(element::i64); - NGRAPH_TYPE_TO_MAX_CONST(element::u1); - NGRAPH_TYPE_TO_MAX_CONST(element::u8); - NGRAPH_TYPE_TO_MAX_CONST(element::u16); - NGRAPH_TYPE_TO_MAX_CONST(element::u32); - NGRAPH_TYPE_TO_MAX_CONST(element::u64); + OPENVINO_TYPE_TO_MAX_CONST(element::boolean); + OPENVINO_TYPE_TO_MAX_CONST(element::bf16); + OPENVINO_TYPE_TO_MAX_CONST(element::f16); + OPENVINO_TYPE_TO_MAX_CONST(element::f32); + OPENVINO_TYPE_TO_MAX_CONST(element::f64); + OPENVINO_TYPE_TO_MAX_CONST(element::i8); + OPENVINO_TYPE_TO_MAX_CONST(element::i16); + OPENVINO_TYPE_TO_MAX_CONST(element::i32); + OPENVINO_TYPE_TO_MAX_CONST(element::i64); + OPENVINO_TYPE_TO_MAX_CONST(element::u1); + OPENVINO_TYPE_TO_MAX_CONST(element::u8); + OPENVINO_TYPE_TO_MAX_CONST(element::u16); + OPENVINO_TYPE_TO_MAX_CONST(element::u32); + OPENVINO_TYPE_TO_MAX_CONST(element::u64); default: return nullptr; } } -shared_ptr ngraph::get_constant_min_of_type(element::Type_t t) { -#define NGRAPH_TYPE_TO_MIN_CONST(t) \ +std::shared_ptr get_constant_min_of_type(element::Type_t t) { +#define OPENVINO_TYPE_TO_MIN_CONST(t) \ case t: \ return ov::op::v0::Constant::create( \ t, \ @@ -1260,27 +948,27 @@ shared_ptr ngraph::get_constant_min_of_type(element::T break switch (t) { - NGRAPH_TYPE_TO_MIN_CONST(element::boolean); - NGRAPH_TYPE_TO_MIN_CONST(element::bf16); - NGRAPH_TYPE_TO_MIN_CONST(element::f16); - NGRAPH_TYPE_TO_MIN_CONST(element::f32); - NGRAPH_TYPE_TO_MIN_CONST(element::f64); - NGRAPH_TYPE_TO_MIN_CONST(element::i8); - NGRAPH_TYPE_TO_MIN_CONST(element::i16); - NGRAPH_TYPE_TO_MIN_CONST(element::i32); - NGRAPH_TYPE_TO_MIN_CONST(element::i64); - NGRAPH_TYPE_TO_MIN_CONST(element::u1); - NGRAPH_TYPE_TO_MIN_CONST(element::u8); - NGRAPH_TYPE_TO_MIN_CONST(element::u16); - NGRAPH_TYPE_TO_MIN_CONST(element::u32); - NGRAPH_TYPE_TO_MIN_CONST(element::u64); + OPENVINO_TYPE_TO_MIN_CONST(element::boolean); + OPENVINO_TYPE_TO_MIN_CONST(element::bf16); + OPENVINO_TYPE_TO_MIN_CONST(element::f16); + OPENVINO_TYPE_TO_MIN_CONST(element::f32); + OPENVINO_TYPE_TO_MIN_CONST(element::f64); + OPENVINO_TYPE_TO_MIN_CONST(element::i8); + OPENVINO_TYPE_TO_MIN_CONST(element::i16); + OPENVINO_TYPE_TO_MIN_CONST(element::i32); + OPENVINO_TYPE_TO_MIN_CONST(element::i64); + OPENVINO_TYPE_TO_MIN_CONST(element::u1); + OPENVINO_TYPE_TO_MIN_CONST(element::u8); + OPENVINO_TYPE_TO_MIN_CONST(element::u16); + OPENVINO_TYPE_TO_MIN_CONST(element::u32); + OPENVINO_TYPE_TO_MIN_CONST(element::u64); default: return nullptr; } } -std::shared_ptr ngraph::get_constant_lowest_of_type(element::Type_t t) { -#define NGRAPH_TYPE_TO_LOWEST_CONST(t) \ +std::shared_ptr get_constant_lowest_of_type(element::Type_t t) { +#define OPENVINO_TYPE_TO_LOWEST_CONST(t) \ case t: \ return op::v0::Constant::create(t, \ {}, \ @@ -1288,20 +976,20 @@ std::shared_ptr ngraph::get_constant_lowest_of_type(el break switch (t) { - NGRAPH_TYPE_TO_LOWEST_CONST(element::boolean); - NGRAPH_TYPE_TO_LOWEST_CONST(element::bf16); - NGRAPH_TYPE_TO_LOWEST_CONST(element::f16); - NGRAPH_TYPE_TO_LOWEST_CONST(element::f32); - NGRAPH_TYPE_TO_LOWEST_CONST(element::f64); - NGRAPH_TYPE_TO_LOWEST_CONST(element::i8); - NGRAPH_TYPE_TO_LOWEST_CONST(element::i16); - NGRAPH_TYPE_TO_LOWEST_CONST(element::i32); - NGRAPH_TYPE_TO_LOWEST_CONST(element::i64); - NGRAPH_TYPE_TO_LOWEST_CONST(element::u1); - NGRAPH_TYPE_TO_LOWEST_CONST(element::u8); - NGRAPH_TYPE_TO_LOWEST_CONST(element::u16); - NGRAPH_TYPE_TO_LOWEST_CONST(element::u32); - NGRAPH_TYPE_TO_LOWEST_CONST(element::u64); + OPENVINO_TYPE_TO_LOWEST_CONST(element::boolean); + OPENVINO_TYPE_TO_LOWEST_CONST(element::bf16); + OPENVINO_TYPE_TO_LOWEST_CONST(element::f16); + OPENVINO_TYPE_TO_LOWEST_CONST(element::f32); + OPENVINO_TYPE_TO_LOWEST_CONST(element::f64); + OPENVINO_TYPE_TO_LOWEST_CONST(element::i8); + OPENVINO_TYPE_TO_LOWEST_CONST(element::i16); + OPENVINO_TYPE_TO_LOWEST_CONST(element::i32); + OPENVINO_TYPE_TO_LOWEST_CONST(element::i64); + OPENVINO_TYPE_TO_LOWEST_CONST(element::u1); + OPENVINO_TYPE_TO_LOWEST_CONST(element::u8); + OPENVINO_TYPE_TO_LOWEST_CONST(element::u16); + OPENVINO_TYPE_TO_LOWEST_CONST(element::u32); + OPENVINO_TYPE_TO_LOWEST_CONST(element::u64); case element::undefined: case element::dynamic: @@ -1310,15 +998,193 @@ std::shared_ptr ngraph::get_constant_lowest_of_type(el } } -shared_ptr ov::get_constant_from_source(const Output& source) { - return ov::util::get_constant_from_source(source); -} - -bool ngraph::validate_host_tensor_vector(const HostTensorVector& tensor_vector, const size_t& size) { +bool validate_host_tensor_vector(const HostTensorVector& tensor_vector, const size_t& size) { return (tensor_vector.size() == size) && std::none_of(tensor_vector.cbegin(), tensor_vector.cend(), ov::cmp::Equal(nullptr)); } +} // namespace ngraph + +void ov::infer_auto_padding(const Shape& image_shape, + const Shape& filter_shape, + const Strides& filter_strides, + const Strides& filter_dilations, + const op::PadType pad_type, + CoordinateDiff& padding_above, + CoordinateDiff& padding_below) { + const auto image_dims = std::vector(std::begin(image_shape), std::end(image_shape)); + // because image_shape is fully known result of try_apply_infer_auto_padding is ignored + ov::util::try_apply_auto_padding(image_dims, + filter_shape, + filter_strides, + filter_dilations, + pad_type, + padding_above, + padding_below); +} + +bool ov::util::try_apply_auto_padding(const PartialShape& image_shape, + const Shape& filter_shape, + const Strides& filter_strides, + const Strides& filter_dilations, + const op::PadType pad_type, + CoordinateDiff& padding_above, + CoordinateDiff& padding_below) { + OPENVINO_ASSERT(pad_type == op::PadType::SAME_UPPER || pad_type == op::PadType::SAME_LOWER); + + if (image_shape.rank().is_dynamic()) { + return false; + } + const auto image_dims = static_cast>(image_shape); + for (size_t i = 0; i < static_cast(filter_shape.size()); i++) { + if (image_dims[i + 2].is_static()) { + auto image_size = static_cast(image_dims[i + 2].get_length()); + int64_t filter_size = (static_cast(filter_shape[i]) - 1) * filter_dilations[i] + 1; + auto filter_stride = static_cast(filter_strides[i]); + auto output_size = (image_size + filter_stride - 1) / filter_stride; + + auto padding_needed = std::max(int64_t(0), (output_size - 1) * filter_stride + filter_size - image_size); + auto padding_lhs = padding_needed / 2; + auto padding_rhs = padding_needed - padding_lhs; + padding_below.push_back(pad_type == op::PadType::SAME_UPPER ? padding_lhs : padding_rhs); + padding_above.push_back(pad_type == op::PadType::SAME_UPPER ? padding_rhs : padding_lhs); + } else { + padding_below.push_back(0); + padding_above.push_back(0); + } + } + return true; +} + +namespace { +const auto normalize_axis_to = [](const int64_t& tensor_rank) { + return [&tensor_rank](int64_t& axis) { + if (axis < 0) { + axis += tensor_rank; + } + }; +}; + +std::string normalize_axis_error_msg(const int64_t& axis, const int64_t& lower, const int64_t& upper) { + return std::string(" Parameter axis ") + .append(std::to_string(axis)) + .append(" out of the tensor rank range [") + .append(std::to_string(lower)) + .append(", ") + .append(std::to_string(upper)) + .append("]."); +} +} // namespace + +int64_t ov::util::normalize(const int64_t& value, const int64_t& max) { + return (value < 0) ? value + max : value; +}; + +void ov::normalize_axes(const Node* node, const int64_t& tensor_rank, std::vector& axes) { + const auto axis_checker = cmp::Between(-tensor_rank, tensor_rank ? (tensor_rank - 1) : 0); + const auto invalid_axis = std::find_if_not(axes.cbegin(), axes.cend(), axis_checker); + NODE_VALIDATION_CHECK(node, + invalid_axis == axes.cend(), + normalize_axis_error_msg(*invalid_axis, axis_checker.lower(), axis_checker.upper())); + std::for_each(axes.begin(), axes.end(), normalize_axis_to(tensor_rank)); +} + +std::vector ov::normalize_axes(const std::string& node_description, + const std::vector& axes, + const Rank& tensor_rank) { + std::vector new_axes; + new_axes.reserve(axes.size()); + for (const auto& axis : axes) { + new_axes.push_back(normalize_axis(node_description, axis, tensor_rank)); + } + return new_axes; +} + +int64_t ov::normalize_axis(const Node* node, std::int64_t axis, const Rank& tensor_rank) { + return normalize_axis(node->description(), axis, tensor_rank); +} + +int64_t ov::normalize_axis(const std::string& node_description, std::int64_t axis, const Rank& tensor_rank) { + if (axis < 0) { + // Handling negative axis requires static tensor rank + OPENVINO_ASSERT(tensor_rank.is_static(), + node_description, + " Rank must be static in order to normalize negative axis=", + axis); + } + if (tensor_rank.is_dynamic()) { + return axis; + } + + const auto tensor_rank_value = tensor_rank.get_length(); + return normalize_axis(node_description, + axis, + tensor_rank_value, + -tensor_rank_value, + tensor_rank_value ? (tensor_rank_value - 1) : 0); +} + +int64_t ov::normalize_axis(const Node* node, + std::int64_t axis, + std::uint64_t tensor_rank, + std::int64_t axis_range_min, + std::int64_t axis_range_max) { + return normalize_axis(node->description(), axis, tensor_rank, axis_range_min, axis_range_max); +} + +int64_t ov::normalize_axis(const std::string& node_description, + std::int64_t axis, + std::uint64_t tensor_rank, + std::int64_t axis_range_min, + std::int64_t axis_range_max) { + // Accepted range of value for axis is [axis_range_min, axis_range_max]. + OPENVINO_ASSERT((axis_range_min <= axis) && (axis <= axis_range_max), + node_description, + normalize_axis_error_msg(axis, axis_range_min, axis_range_max)); + return util::normalize(axis, tensor_rank); +} + +bool ov::evaluate_as_partial_shape(const Output& output, PartialShape& pshape) { + Tensor lb, ub; + std::tie(lb, ub) = ov::evaluate_both_bounds(output); + bool shape_defined = false; + if (lb && ub) { + auto lower_bound = std::make_shared(lb.get_element_type(), lb.get_shape(), lb.data()) + ->cast_vector(); + auto upper_bound = std::make_shared(ub.get_element_type(), ub.get_shape(), ub.data()) + ->cast_vector(); + OPENVINO_ASSERT(lower_bound.size() == upper_bound.size()); + const TensorLabel& labels = output.get_tensor().get_value_label(); + OPENVINO_ASSERT(labels.empty() || lower_bound.size() == labels.size()); + + std::vector resulting_pshape(lower_bound.size()); + for (size_t i = 0; i < lower_bound.size(); ++i) { + auto low = lower_bound[i], up = upper_bound[i]; + OPENVINO_ASSERT(low >= 0 && up >= 0, "Value for partial shape evaluation can't be lower than zero."); + if (output.get_element_type() == element::i32 && low != up) { + if (up == std::numeric_limits::max()) + up = std::numeric_limits::max(); + if (low == std::numeric_limits::max()) + low = std::numeric_limits::max(); + } + resulting_pshape[i] = {low, up}; + if (!labels.empty() && labels[i]) + ov::DimensionTracker::set_label(resulting_pshape[i], labels[i]); + } + pshape = PartialShape(resulting_pshape); + shape_defined = true; + } + return shape_defined; +} + +bool ov::default_label_evaluator(const Node* node, TensorLabelVector& output_labels) { + return default_label_evaluator(node, {0}, output_labels); +} + +std::shared_ptr ov::get_constant_from_source(const Output& source) { + return ov::util::get_constant_from_source(source); +} + bool ov::has_no_labels(const ov::TensorLabel& labels) { return std::all_of(labels.cbegin(), labels.cend(), cmp::Equal(no_label)); } @@ -1381,6 +1247,130 @@ std::shared_ptr ov::util::constantfold_subgraph(const Outp return ov::as_type_ptr(outputs[subgraph_sink.get_index()].get_node_shared_ptr()); } +// +// Infers the output batch shape and element type for convolution fprop. +// +ov::PartialShape ov::infer_convolution_forward(const Node* node, + const PartialShape& data_batch_shape, + const Strides& data_dilation, + const CoordinateDiff& data_padding_below, + const CoordinateDiff& data_padding_above, + const PartialShape& filters_shape, + const Strides& filter_strides, + const Strides& filter_dilation) { + Rank data_batch_filters_rank{Rank::dynamic()}; + + NODE_VALIDATION_CHECK(node, + Rank::merge(data_batch_filters_rank, data_batch_shape.rank(), filters_shape.rank()), + "Data batch and filters rank do not match (data batch shape: ", + data_batch_shape, + ", filters shape: ", + filters_shape, + ")."); + + NODE_VALIDATION_CHECK(node, + data_batch_filters_rank.is_dynamic() || data_batch_filters_rank.get_length() >= 3, + "Data batch and filters must have rank of at least 3 (one batch axis, ", + "one input-channel axis, and at least one spatial dimension) ", + "(data batch shape: ", + data_batch_shape, + ", filters shape: ", + filters_shape, + ")."); + + Rank spatial_rank{Rank::dynamic()}; + NODE_VALIDATION_CHECK(node, + Rank::merge(spatial_rank, spatial_rank, data_batch_filters_rank - 2) && + Rank::merge(spatial_rank, spatial_rank, data_dilation.size()) && + Rank::merge(spatial_rank, spatial_rank, data_padding_below.size()) && + Rank::merge(spatial_rank, spatial_rank, data_padding_above.size()) && + Rank::merge(spatial_rank, spatial_rank, filter_strides.size()) && + Rank::merge(spatial_rank, spatial_rank, filter_dilation.size()), + "Ranks for data item shape/filters shape (data batch has shape ", + data_batch_shape, + ", so data item rank is ", + (data_batch_shape.rank() - 2), + " and filters have shape ", + filters_shape, + ", so filters spatial rank is ", + (filters_shape.rank() - 2), + "), data dilation (", + data_dilation, + "), padding below (", + data_padding_below, + "), padding above (", + data_padding_above, + "), filter strides (", + filter_strides, + "), and filter dilation (", + filter_dilation, + ") do not match."); + + Dimension batch_size = (data_batch_shape.rank().is_static() ? data_batch_shape[0] : Dimension::dynamic()); + Dimension data_channel_count = (data_batch_shape.rank().is_static() ? data_batch_shape[1] : Dimension::dynamic()); + PartialShape data_spatial_shape(PartialShape::dynamic(spatial_rank)); + + Dimension filter_output_channel_count = + (filters_shape.rank().is_static() ? filters_shape[0] : Dimension::dynamic()); + Dimension filter_input_channel_count = (filters_shape.rank().is_static() ? filters_shape[1] : Dimension::dynamic()); + PartialShape filter_spatial_shape(PartialShape::dynamic(spatial_rank)); + + // + // Note: spatial_rank is definitely static at this point. + // + + for (int64_t i = 0; i < spatial_rank.get_length(); i++) { + if (data_batch_shape.rank().is_static()) { + data_spatial_shape[i] = data_batch_shape[i + 2]; + } + + if (filters_shape.rank().is_static()) { + filter_spatial_shape[i] = filters_shape[i + 2]; + } + } + + NODE_VALIDATION_CHECK(node, batch_size.is_dynamic() || batch_size.get_length() > 0, "Batch size is zero."); + + Dimension merged_channel_count; + + NODE_VALIDATION_CHECK(node, + Dimension::merge(merged_channel_count, data_channel_count, filter_input_channel_count), + "Data batch channel count (", + data_channel_count, + ") does not match filter input ", + "channel count (", + filter_input_channel_count, + ")."); + + NODE_VALIDATION_CHECK(node, + merged_channel_count.is_dynamic() || merged_channel_count.get_length() > 0, + "Data batch channel count and/or filter input channel count is zero."); + + NODE_VALIDATION_CHECK(node, + filter_output_channel_count.is_dynamic() || filter_output_channel_count.get_length() > 0, + "Filter output channel count is zero."); + + PartialShape data_output_shape = ngraph::infer_windowed_reduction_output_shape(node, + data_spatial_shape, + data_dilation, + data_padding_below, + data_padding_above, + filter_spatial_shape, + filter_strides, + filter_dilation, + true); + + PartialShape batch_output_shape(PartialShape::dynamic(spatial_rank + 2)); + batch_output_shape[0] = batch_size; + batch_output_shape[1] = filter_output_channel_count; + + for (int64_t i = 0; i < spatial_rank.get_length(); i++) { + batch_output_shape[i + 2] = data_output_shape[i]; + } + + return batch_output_shape; +} + namespace ov { namespace util { using ov::op::v0::Constant; @@ -1394,5 +1384,14 @@ std::shared_ptr get_constant_from_source(const Output& source) { return {}; } } + +std::vector get_tensors_partial_shapes(const TensorVector& tensors) { + std::vector shapes; + shapes.reserve(tensors.size()); + for (const auto& t : tensors) { + shapes.emplace_back(t.get_shape()); + } + return shapes; +} } // namespace util } // namespace ov diff --git a/src/core/tests/CMakeLists.txt b/src/core/tests/CMakeLists.txt index 433395d8a4bc0f..45751efe2012b2 100644 --- a/src/core/tests/CMakeLists.txt +++ b/src/core/tests/CMakeLists.txt @@ -57,10 +57,10 @@ target_include_directories(${TARGET_NAME} PRIVATE ${OV_CORE_SRC_DIR}/src target_compile_definitions(${TARGET_NAME} PRIVATE SHARED_LIB_PREFIX="${CMAKE_SHARED_LIBRARY_PREFIX}" - SHARED_LIB_SUFFIX="${IE_BUILD_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}" + SHARED_LIB_SUFFIX="${OV_BUILD_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}" FRONTEND_LIB_PREFIX="${CMAKE_SHARED_LIBRARY_PREFIX}${FRONTEND_NAME_PREFIX}" # Assume .so is an existed symlink to .so (or .so - FRONTEND_LIB_SUFFIX="${FRONTEND_NAME_SUFFIX}${IE_BUILD_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}" + FRONTEND_LIB_SUFFIX="${FRONTEND_NAME_SUFFIX}${OV_BUILD_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}" ) if(RISCV64) diff --git a/src/core/tests/aligned_buffer.cpp b/src/core/tests/aligned_buffer.cpp index fae5929ba3db2a..604d153eeb5c36 100644 --- a/src/core/tests/aligned_buffer.cpp +++ b/src/core/tests/aligned_buffer.cpp @@ -2,31 +2,30 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/runtime/aligned_buffer.hpp" +#include "openvino/runtime/aligned_buffer.hpp" #include "gtest/gtest.h" -using namespace ngraph; +using namespace ov; -OPENVINO_SUPPRESS_DEPRECATED_START TEST(aligned_buffer, alignment) { - runtime::AlignedBuffer buffer(100, 64); + AlignedBuffer buffer(100, 64); size_t addr = reinterpret_cast(buffer.get_ptr()) % 64; EXPECT_EQ(addr, 0); } TEST(aligned_buffer, move) { { - runtime::AlignedBuffer buffer1(100, 64); - runtime::AlignedBuffer buffer2(std::move(buffer1)); + AlignedBuffer buffer1(100, 64); + AlignedBuffer buffer2(std::move(buffer1)); EXPECT_EQ(buffer1.size(), 0); EXPECT_EQ(buffer1.get_ptr(), nullptr); EXPECT_EQ(buffer2.size(), 100); EXPECT_NE(buffer2.get_ptr(), nullptr); } { - runtime::AlignedBuffer buffer1(100, 64); - runtime::AlignedBuffer buffer2; + AlignedBuffer buffer1(100, 64); + AlignedBuffer buffer2; buffer2 = std::move(buffer1); EXPECT_EQ(buffer1.size(), 0); EXPECT_EQ(buffer1.get_ptr(), nullptr); diff --git a/src/core/tests/bfloat16.cpp b/src/core/tests/bfloat16.cpp index bb3a35dc9953a3..f031d01226cf41 100644 --- a/src/core/tests/bfloat16.cpp +++ b/src/core/tests/bfloat16.cpp @@ -10,7 +10,7 @@ #include #include "common_test_utils/float_util.hpp" -#include "ngraph/runtime/aligned_buffer.hpp" +#include "openvino/runtime/aligned_buffer.hpp" #include "openvino/util/log.hpp" using namespace std; @@ -140,9 +140,8 @@ TEST(bfloat16, numeric_limits) { } TEST(benchmark, bfloat16) { - OPENVINO_SUPPRESS_DEPRECATED_START size_t buffer_size = 128 * 3 * 224 * 224; - ngraph::runtime::AlignedBuffer data(buffer_size * sizeof(float), 4096); + ov::AlignedBuffer data(buffer_size * sizeof(float), 4096); float* f = static_cast(data.get_ptr()); // vector data(buffer_size); std::mt19937 rng(2112); @@ -153,53 +152,36 @@ TEST(benchmark, bfloat16) { OPENVINO_INFO << "buffer size " << buffer_size << " floats or " << data.size() << " bytes"; { - ngraph::runtime::AlignedBuffer bf_data(buffer_size * sizeof(bfloat16), 4096); + ov::AlignedBuffer bf_data(buffer_size * sizeof(bfloat16), 4096); bfloat16* p = static_cast(bf_data.get_ptr()); - ngraph::stopwatch timer; - timer.start(); for (size_t i = 0; i < buffer_size; ++i) { p[i] = bfloat16(f[i]); } - timer.stop(); - OPENVINO_INFO << "float to bfloat16 ctor " << timer.get_milliseconds() << "ms"; } { - ngraph::runtime::AlignedBuffer bf_data(buffer_size * sizeof(bfloat16), 4096); + ov::AlignedBuffer bf_data(buffer_size * sizeof(bfloat16), 4096); bfloat16* p = static_cast(bf_data.get_ptr()); - ngraph::stopwatch timer; - timer.start(); for (size_t i = 0; i < buffer_size; ++i) { p[i] = bfloat16::truncate(f[i]); } - timer.stop(); - OPENVINO_INFO << "float to bfloat16 truncate " << timer.get_milliseconds() << "ms"; } { - ngraph::runtime::AlignedBuffer bf_data(buffer_size * sizeof(bfloat16), 4096); + ov::AlignedBuffer bf_data(buffer_size * sizeof(bfloat16), 4096); bfloat16* p = static_cast(bf_data.get_ptr()); - ngraph::stopwatch timer; - timer.start(); for (size_t i = 0; i < buffer_size; ++i) { p[i] = bfloat16::round_to_nearest(f[i]); } - timer.stop(); - OPENVINO_INFO << "float to bfloat16 round to nearest " << timer.get_milliseconds() << "ms"; } { - ngraph::runtime::AlignedBuffer bf_data(buffer_size * sizeof(bfloat16), 4096); + ov::AlignedBuffer bf_data(buffer_size * sizeof(bfloat16), 4096); bfloat16* p = static_cast(bf_data.get_ptr()); - ngraph::stopwatch timer; - timer.start(); for (size_t i = 0; i < buffer_size; ++i) { p[i] = bfloat16::round_to_nearest_even(f[i]); } - timer.stop(); - OPENVINO_INFO << "float to bfloat16 round to nearest even " << timer.get_milliseconds() << "ms"; } - OPENVINO_SUPPRESS_DEPRECATED_END } TEST(bfloat16, assigns) { diff --git a/src/core/tests/constant.cpp b/src/core/tests/constant.cpp index 45ad60d153627a..010bb83b3e75d9 100644 --- a/src/core/tests/constant.cpp +++ b/src/core/tests/constant.cpp @@ -10,6 +10,8 @@ #include "common_test_utils/type_prop.hpp" #include "openvino/core/except.hpp" +#include "openvino/runtime/aligned_buffer.hpp" +#include "openvino/runtime/shared_buffer.hpp" using namespace ov; using namespace std; @@ -266,8 +268,8 @@ TEST(constant, int4_string) { EXPECT_EQ(v[2], -1); const auto p = c.get_data_ptr(); - EXPECT_EQ(0x10, p[0]); - EXPECT_EQ(0xF0, p[1] & 0xF0); + EXPECT_EQ(0x01, p[0]); + EXPECT_EQ(0x0F, p[1] & 0x0F); EXPECT_EQ(input, c.get_value_strings()); @@ -318,8 +320,8 @@ TEST(constant, int4_vector_negative_number) { EXPECT_EQ(v[2], int8_t(-1)); const auto p = c.get_data_ptr(); - EXPECT_EQ(0xFE, p[0]); - EXPECT_EQ(0xF0, p[1] & 0xF0); + EXPECT_EQ(0xEF, p[0]); + EXPECT_EQ(0x0F, p[1] & 0x0F); } TEST(constant, int4_vector_positive_number) { @@ -332,8 +334,8 @@ TEST(constant, int4_vector_positive_number) { EXPECT_EQ(v[2], int8_t(5)); const auto p = c.get_data_ptr(); - EXPECT_EQ(0x12, p[0]); - EXPECT_EQ(0x50, p[1] & 0xF0); + EXPECT_EQ(0x21, p[0]); + EXPECT_EQ(0x05, p[1] & 0x0F); } TEST(constant, int4_vector_broadcast_negative_number) { @@ -795,8 +797,8 @@ TEST(constant, uint4_string) { EXPECT_EQ(v[3], 0); const auto p = c.get_data_ptr(); - EXPECT_EQ(p[0], 0x10); - EXPECT_EQ(p[1], 0x10); + EXPECT_EQ(p[0], 0x01); + EXPECT_EQ(p[1], 0x01); EXPECT_EQ(input, c.get_value_strings()); @@ -831,8 +833,8 @@ TEST(constant, uint4_vector) { EXPECT_EQ(v[3], 0); const auto p = c.get_data_ptr(); - EXPECT_EQ(p[0], 0x10); - EXPECT_EQ(p[1], 0x10); + EXPECT_EQ(p[0], 0x01); + EXPECT_EQ(p[1], 0x01); } TEST(constant, uint4_vector_broadcast) { @@ -1726,14 +1728,12 @@ TEST(constant, lazy_bitwise_identical) { auto shape = Shape{10, 1000, 1000}; auto type = element::i32; auto byte_size = shape_size(shape) * sizeof(int32_t); - OPENVINO_SUPPRESS_DEPRECATED_START - auto aligned_weights_buffer = std::make_shared(byte_size); + auto aligned_weights_buffer = std::make_shared(byte_size); std::memset(aligned_weights_buffer->get_ptr(), 1, byte_size); - auto weights = std::make_shared>>( - aligned_weights_buffer->get_ptr(), - aligned_weights_buffer->size(), - aligned_weights_buffer); - OPENVINO_SUPPRESS_DEPRECATED_END + auto weights = + std::make_shared>>(aligned_weights_buffer->get_ptr(), + aligned_weights_buffer->size(), + aligned_weights_buffer); using namespace std::chrono; auto create_constant = [&]() { diff --git a/src/core/tests/copy.cpp b/src/core/tests/copy.cpp index d7b2b4256f4aa3..f902d7485a1932 100644 --- a/src/core/tests/copy.cpp +++ b/src/core/tests/copy.cpp @@ -447,12 +447,12 @@ TEST(copy, random_uniform) { const auto min_val_param = make_shared(element::f32, Shape{1}); const auto max_val_param = make_shared(element::f32, Shape{1}); - auto out_shape = make_shared(element::i64, Shape{3}, std::vector{1, 2, 3}); + auto out_shape = make_shared(element::i64, Shape{3}, shape); auto ru = std::make_shared(out_shape, min_val_param, max_val_param, element::f32, 150, 10); // Call `evaluate` to update m_state - auto outputs = ov::TensorVector{{element::i64, out_shape->get_shape(), shape.data()}}; + auto outputs = ov::TensorVector{{element::i64, {1lu, 2lu, 3lu}}}; ru->evaluate(outputs, ov::TensorVector{{element::i64, out_shape->get_shape(), shape.data()}, {element::f32, min_val_param->get_shape(), &min}, diff --git a/src/core/tests/eval.cpp b/src/core/tests/eval.cpp index 86b3cc2ecf82ce..fabf47f0f2f248 100644 --- a/src/core/tests/eval.cpp +++ b/src/core/tests/eval.cpp @@ -178,6 +178,27 @@ TEST(eval, evaluate_dynamic_range_sum) { ASSERT_EQ(cval, seq); } +TEST(eval, evaluate_dynamic_range_fp16_out) { + auto p_start = make_shared(element::i32, PartialShape{}); + auto p_stop = make_shared(element::i32, PartialShape{}); + auto p_step = make_shared(element::i32, PartialShape{}); + auto range = make_shared(p_start, p_stop, p_step, ov::element::f16); + auto model = make_shared(OutputVector{range}, ParameterVector{p_start, p_stop, p_step}); + auto result_tensor = ov::Tensor(); + auto out_vector = ov::TensorVector{result_tensor}; + auto in_vector = ov::TensorVector{make_tensor({}, {0}), + make_tensor({}, {3087}), + make_tensor({}, {1})}; + ASSERT_TRUE(model->evaluate(out_vector, in_vector)); + result_tensor = out_vector.at(0); + EXPECT_EQ(result_tensor.get_element_type(), element::f16); + EXPECT_EQ(result_tensor.get_shape(), (Shape{3087})); + auto cval = read_vector(result_tensor); + for (size_t i = 0; i < 3087; i++) { + ASSERT_EQ(cval[i], ov::float16(i)); + } +} + TEST(eval, evaluate_broadcast_v3_bidirectional) { Shape shape_a{4, 1}; auto A = make_shared(element::f32, shape_a); diff --git a/src/core/tests/extension.cpp b/src/core/tests/extension.cpp index e62ed76fd72b58..5dd442c65e0449 100644 --- a/src/core/tests/extension.cpp +++ b/src/core/tests/extension.cpp @@ -15,7 +15,7 @@ inline std::string get_extension_path() { return ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("openvino_template_extension") + IE_BUILD_POSTFIX); + std::string("openvino_template_extension") + OV_BUILD_POSTFIX); } TEST(extension, load_extension) { diff --git a/src/core/tests/int4.cpp b/src/core/tests/int4.cpp index 2edb82dda0183c..d9a20fbf3649b2 100644 --- a/src/core/tests/int4.cpp +++ b/src/core/tests/int4.cpp @@ -15,9 +15,9 @@ TEST(int4, convert_i4_to_string) { vector values{171, 16}; auto constant = make_shared(element::i4, Shape{3}, &values[0]); - vector ref{"-6", "-5", "1"}; + vector ref{"-5", "-6", "0"}; for (size_t i = 0; i < 3; ++i) { - ASSERT_EQ(constant->convert_value_to_string(i), ref[i]); + EXPECT_EQ(constant->convert_value_to_string(i), ref[i]); } } diff --git a/src/core/tests/reshape_opt_kernel.cpp b/src/core/tests/reshape_opt_kernel.cpp index d23b25308a39f7..823f75cc39e123 100644 --- a/src/core/tests/reshape_opt_kernel.cpp +++ b/src/core/tests/reshape_opt_kernel.cpp @@ -8,8 +8,8 @@ #include #include "common_test_utils/ndarray.hpp" -#include "ngraph/runtime/opt_kernel/reshape.hpp" #include "openvino/core/axis_vector.hpp" +#include "openvino/reference/reshape.hpp" using namespace ov; @@ -50,12 +50,12 @@ TEST_P(ReshapeOptKernel, reshape_opt_kernel) { for (size_t i = 0; i < out_shape.size(); i++) out_shape[i] = in_shape[axis_order[i]]; - ngraph::runtime::opt_kernel::reshape((const char*)p.input.data(), - (char*)output_buff.data(), - in_shape, - axis_order, - out_shape, - sizeof(ElementValue)); + ov::reference::reshape(static_cast(p.input.data()), + reinterpret_cast(output_buff.data()), + in_shape, + axis_order, + out_shape, + sizeof(ElementValue)); EXPECT_EQ(p.output.get_vector(), output_buff); } diff --git a/src/core/tests/type_prop/reduce_prod.cpp b/src/core/tests/type_prop/reduce_prod.cpp index 20cc6699a6b61b..4def461f847a69 100644 --- a/src/core/tests/type_prop/reduce_prod.cpp +++ b/src/core/tests/type_prop/reduce_prod.cpp @@ -11,6 +11,9 @@ using Type = ::testing::Types; INSTANTIATE_TYPED_TEST_SUITE_P(type_prop_reduce_prod, ReduceTest, Type); INSTANTIATE_TYPED_TEST_SUITE_P(type_prop_reduce_prod_et, ReduceArithmeticTest, Type); +INSTANTIATE_TYPED_TEST_SUITE_P(type_prop_reduce_prod_dynamic, ReduceTest, Type); +INSTANTIATE_TYPED_TEST_SUITE_P(type_prop_reduce_prod_dynamic_zero, ReduceTest, Type); +INSTANTIATE_TYPED_TEST_SUITE_P(type_prop_reduce_prod_scalar, ReduceTest, Type); TEST(type_prop, reduce_prod_value_propagation) { const auto param = std::make_shared(element::f32, PartialShape{{1, 8}, {2, 3}, 6}); @@ -22,3 +25,36 @@ TEST(type_prop, reduce_prod_value_propagation) { EXPECT_EQ(reshape->get_element_type(), ov::element::f32); EXPECT_EQ(reshape->get_output_partial_shape(0), (PartialShape{{12, 144}})); } + +TEST(type_prop, reduce_prod_value_propagation_dynamic) { + const auto param = std::make_shared(element::f32, PartialShape{-1, 12, 32, 32}); + const auto shape_of = std::make_shared(param); + const auto reduce_prod = + std::make_shared(shape_of, ov::op::v0::Constant::create(element::i64, {1}, {0}), true); + const auto reshape = std::make_shared(param, reduce_prod, false); + + EXPECT_EQ(reshape->get_element_type(), ov::element::f32); + EXPECT_EQ(reshape->get_output_partial_shape(0), (PartialShape{-1})); +} + +TEST(type_prop, reduce_prod_value_propagation_dynamic_zero) { + const auto param = std::make_shared(element::f32, PartialShape{-1, 12, 0, -1}); + const auto shape_of = std::make_shared(param); + const auto reduce_prod = + std::make_shared(shape_of, ov::op::v0::Constant::create(element::i64, {1}, {0}), true); + const auto reshape = std::make_shared(param, reduce_prod, false); + + EXPECT_EQ(reshape->get_element_type(), ov::element::f32); + EXPECT_EQ(reshape->get_output_partial_shape(0), (PartialShape{0})); +} + +TEST(type_prop, reduce_prod_value_propagation_scalar) { + const auto param = std::make_shared(element::f32, PartialShape{0}); + const auto shape_of = std::make_shared(param); + const auto reduce_prod = + std::make_shared(shape_of, ov::op::v0::Constant::create(element::i64, {1}, {0}), true); + const auto reshape = std::make_shared(param, reduce_prod, false); + + EXPECT_EQ(reshape->get_element_type(), ov::element::f32); + EXPECT_EQ(reshape->get_output_partial_shape(0), (PartialShape{0})); +} diff --git a/src/core/tests/uint4.cpp b/src/core/tests/uint4.cpp index 5c3b0a5e06af20..8285fdb3cd5e1c 100644 --- a/src/core/tests/uint4.cpp +++ b/src/core/tests/uint4.cpp @@ -13,9 +13,9 @@ TEST(uint4, convert_u4_to_string) { vector values{171, 16}; auto constant = make_shared(element::u4, Shape{3}, &values[0]); - vector ref{"10", "11", "1"}; + vector ref{"11", "10", "0"}; for (size_t i = 0; i < 3; ++i) { - ASSERT_EQ(constant->convert_value_to_string(i), ref[i]); + EXPECT_EQ(constant->convert_value_to_string(i), ref[i]); } } diff --git a/src/core/tests/visitors/visitors.hpp b/src/core/tests/visitors/visitors.hpp index 838eade854181b..893d982a59b3eb 100644 --- a/src/core/tests/visitors/visitors.hpp +++ b/src/core/tests/visitors/visitors.hpp @@ -10,12 +10,13 @@ #include #include "ngraph/factory.hpp" -#include "ngraph/runtime/aligned_buffer.hpp" #include "openvino/core/attribute_visitor.hpp" #include "openvino/core/deprecated.hpp" #include "openvino/op/util/framework_node.hpp" #include "openvino/op/util/sub_graph_base.hpp" #include "openvino/op/util/variable.hpp" +#include "openvino/runtime/aligned_buffer.hpp" +#include "openvino/runtime/tensor.hpp" namespace ov { namespace test { @@ -217,10 +218,9 @@ class DeserializeAttributeVisitor : public AttributeVisitor { } void on_adapter(const std::string& name, ValueAccessor& adapter) override { - OPENVINO_SUPPRESS_DEPRECATED_START - if (auto a = ::ov::as_type<::ov::AttributeAdapter>>(&adapter)) { - auto& data = m_values.get(name); - data->read(a->get()->get_ptr(), a->get()->size()); + if (auto a = ::ov::as_type<::ov::AttributeAdapter>>(&adapter)) { + auto& data = m_values.get(name); + std::memcpy(a->get()->get_ptr(), data.data(), a->get()->size()); } else if (auto a = ov::as_type< ov::AttributeAdapter>>>( &adapter)) { @@ -240,7 +240,6 @@ class DeserializeAttributeVisitor : public AttributeVisitor { } else { OPENVINO_THROW("Attribute \"", name, "\" cannot be unmarshalled"); } - OPENVINO_SUPPRESS_DEPRECATED_END } // The remaining adapter methods fall back on the void adapter if not implemented void on_adapter(const std::string& name, ValueAccessor& adapter) override { @@ -309,10 +308,9 @@ class SerializeAttributeVisitor : public AttributeVisitor { } void on_adapter(const std::string& name, ValueAccessor& adapter) override { - OPENVINO_SUPPRESS_DEPRECATED_START - if (auto a = ::ov::as_type<::ov::AttributeAdapter>>(&adapter)) { - ngraph::HostTensorPtr data = std::make_shared(element::u8, Shape{a->get()->size()}); - data->write(a->get()->get_ptr(), a->get()->size()); + if (auto a = ::ov::as_type<::ov::AttributeAdapter>>(&adapter)) { + ov::Tensor data(element::u8, Shape{a->get()->size()}); + std::memcpy(data.data(), a->get()->get_ptr(), a->get()->size()); m_values.insert(name, data); } else if (auto a = ov::as_type< ov::AttributeAdapter>>>( @@ -333,7 +331,6 @@ class SerializeAttributeVisitor : public AttributeVisitor { } else { OPENVINO_THROW("Attribute \"", name, "\" cannot be marshalled"); } - OPENVINO_SUPPRESS_DEPRECATED_END } // The remaining adapter methods fall back on the void adapter if not implemented void on_adapter(const std::string& name, ValueAccessor& adapter) override { diff --git a/src/frontends/common/CMakeLists.txt b/src/frontends/common/CMakeLists.txt index 1cb869079213d2..4fd41e6f4d3601 100644 --- a/src/frontends/common/CMakeLists.txt +++ b/src/frontends/common/CMakeLists.txt @@ -39,7 +39,7 @@ target_link_libraries(${TARGET_NAME}_obj PRIVATE openvino::util openvino::core:: set_target_properties(${TARGET_NAME}_obj PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF) -set(FRONTEND_LIB_SUFFIX "${FRONTEND_NAME_SUFFIX}${IE_BUILD_POSTFIX}") +set(FRONTEND_LIB_SUFFIX "${FRONTEND_NAME_SUFFIX}${OV_BUILD_POSTFIX}") if(APPLE) set(FRONTEND_LIB_SUFFIX "${FRONTEND_LIB_SUFFIX}${OpenVINO_VERSION_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}") else() diff --git a/src/frontends/common/src/manager.cpp b/src/frontends/common/src/manager.cpp index 35df484c2cab26..6194fca7583937 100644 --- a/src/frontends/common/src/manager.cpp +++ b/src/frontends/common/src/manager.cpp @@ -20,21 +20,6 @@ class FrontEndManager::Impl { std::mutex m_loading_mutex; std::vector m_plugins; - // Note, static methods below are required to create an order of initialization of static variables - // e.g. if users (not encouraged) created ov::Model globally, we need to ensure proper order of initialization - - /// \return map of shared object per frontend - static std::unordered_map>& get_shared_objects_map() { - static std::unordered_map> shared_objects_map; - return shared_objects_map; - } - - /// \return Mutex to guard access the shared object map - static std::mutex& get_shared_objects_mutex() { - static std::mutex shared_objects_map_mutex; - return shared_objects_map_mutex; - } - public: Impl() { search_all_plugins(); @@ -46,10 +31,6 @@ class FrontEndManager::Impl { auto fe_obj = std::make_shared(); fe_obj->m_shared_object = std::make_shared(plugin.get_so_pointer()); fe_obj->m_actual = plugin.get_creator().m_creator(); - - std::lock_guard guard(get_shared_objects_mutex()); - get_shared_objects_map().emplace(plugin.get_creator().m_name, fe_obj->m_shared_object); - return fe_obj; } @@ -164,6 +145,7 @@ class FrontEndManager::Impl { {".xml", {"ir", "ir"}}, {".onnx", {"onnx", "onnx"}}, {".pb", {"tf", "tensorflow"}}, + {".pbtxt", {"tf", "tensorflow"}}, {".tflite", {"tflite", "tensorflow_lite"}}, {".pdmodel", {"paddle", "paddle"}}, // {".ts", {"pytorch", "pytorch"}}, diff --git a/src/frontends/common/src/plugin_loader.cpp b/src/frontends/common/src/plugin_loader.cpp index a044152d8d590d..a98eff766bbc0d 100644 --- a/src/frontends/common/src/plugin_loader.cpp +++ b/src/frontends/common/src/plugin_loader.cpp @@ -16,17 +16,32 @@ #include -#include #include #include #include "openvino/util/file_util.hpp" +#include "openvino/util/log.hpp" #include "openvino/util/shared_object.hpp" #include "plugin_loader.hpp" using namespace ov; using namespace ov::frontend; +// Note, static methods below are required to create an order of initialization of static variables +// e.g. if users (not encouraged) created ov::Model globally, we need to ensure proper order of initialization + +/// \return map of shared object per frontend +std::unordered_map>& ov::frontend::get_shared_objects_map() { + static std::unordered_map> shared_objects_map; + return shared_objects_map; +} + +/// \return Mutex to guard access the shared object map +std::mutex& ov::frontend::get_shared_objects_mutex() { + static std::mutex shared_objects_map_mutex; + return shared_objects_map_mutex; +} + #ifdef OPENVINO_STATIC_LIBRARY # include "ov_frontends.hpp" @@ -131,6 +146,10 @@ bool PluginInfo::load() { m_load_failed = true; return false; } + + std::lock_guard guard(get_shared_objects_mutex()); + get_shared_objects_map().emplace(get_creator().m_name, get_so_pointer()); + return true; } diff --git a/src/frontends/common/src/plugin_loader.hpp b/src/frontends/common/src/plugin_loader.hpp index 93e6a5cc2eb5a3..dccf8ddf7a39f3 100644 --- a/src/frontends/common/src/plugin_loader.hpp +++ b/src/frontends/common/src/plugin_loader.hpp @@ -4,7 +4,12 @@ #pragma once -#include +#include +#include +#include +#include + +#include "openvino/frontend/manager.hpp" #ifdef _WIN32 static const char PathSeparator[] = ";"; @@ -15,6 +20,9 @@ static const char PathSeparator[] = ":"; namespace ov { namespace frontend { +std::unordered_map>& get_shared_objects_map(); +std::mutex& get_shared_objects_mutex(); + /// \brief Internal data structure holding by each frontend. Includes library handle and extensions. class FrontEndSharedData { friend inline void add_extension_to_shared_data(std::shared_ptr& obj, diff --git a/src/frontends/ir/src/frontend.cpp b/src/frontends/ir/src/frontend.cpp index 8b8dca4d995ffb..ba515b5560641f 100644 --- a/src/frontends/ir/src/frontend.cpp +++ b/src/frontends/ir/src/frontend.cpp @@ -9,10 +9,10 @@ #include #include "input_model.hpp" -#include "ngraph/runtime/aligned_buffer.hpp" -#include "ngraph/runtime/shared_buffer.hpp" #include "openvino/core/any.hpp" #include "openvino/core/so_extension.hpp" +#include "openvino/runtime/aligned_buffer.hpp" +#include "openvino/runtime/shared_buffer.hpp" #include "openvino/util/file_util.hpp" #include "openvino/util/mmap_object.hpp" #include "transformations/resolve_names_collisions.hpp" @@ -116,8 +116,7 @@ void FrontEnd::add_extension(const ov::Extension::Ptr& ext) { InputModel::Ptr FrontEnd::load_impl(const std::vector& variants) const { std::ifstream local_model_stream; std::istream* provided_model_stream = nullptr; - OPENVINO_SUPPRESS_DEPRECATED_START - std::shared_ptr weights; + std::shared_ptr weights; auto create_extensions_map = [&]() -> std::unordered_map { std::unordered_map exts; @@ -180,8 +179,8 @@ InputModel::Ptr FrontEnd::load_impl(const std::vector& variants) const } else if (variant.is()) { weights_path = variant.as(); #endif - } else if (variant.is>()) { - weights = variant.as>(); + } else if (variant.is>()) { + weights = variant.as>(); } } bool enable_mmap = variants[variants.size() - 1].is() ? variants[variants.size() - 1].as() : false; @@ -204,10 +203,9 @@ InputModel::Ptr FrontEnd::load_impl(const std::vector& variants) const if (!weights_path.empty()) { if (enable_mmap) { auto mapped_memory = ov::load_mmap_object(weights_path); - weights = - std::make_shared>>(mapped_memory->data(), - mapped_memory->size(), - mapped_memory); + weights = std::make_shared>>(mapped_memory->data(), + mapped_memory->size(), + mapped_memory); } else { std::ifstream bin_stream; bin_stream.open(weights_path.c_str(), std::ios::binary); @@ -222,17 +220,16 @@ InputModel::Ptr FrontEnd::load_impl(const std::vector& variants) const size_t file_size = bin_stream.tellg(); bin_stream.seekg(0, std::ios::beg); - auto aligned_weights_buffer = std::make_shared(file_size); + auto aligned_weights_buffer = std::make_shared(file_size); bin_stream.read(aligned_weights_buffer->get_ptr(), aligned_weights_buffer->size()); bin_stream.close(); - weights = std::make_shared>>( + weights = std::make_shared>>( aligned_weights_buffer->get_ptr(), aligned_weights_buffer->size(), aligned_weights_buffer); } } - OPENVINO_SUPPRESS_DEPRECATED_END return create_input_model(); } diff --git a/src/frontends/ir/src/input_model.cpp b/src/frontends/ir/src/input_model.cpp index 2f58a68c94f89b..6a32b22f786b52 100644 --- a/src/frontends/ir/src/input_model.cpp +++ b/src/frontends/ir/src/input_model.cpp @@ -18,10 +18,9 @@ #include "openvino/util/common_util.hpp" #include "utils.hpp" -OPENVINO_SUPPRESS_DEPRECATED_START namespace { void parse_pre_process(pugi::xml_node& root, - std::shared_ptr weights, + std::shared_ptr weights, std::shared_ptr model) { /* Preprocessing block can have two preprocessing types: * @@ -183,7 +182,9 @@ void parse_pre_process(pugi::xml_node& root, const char* data = weights->get_ptr() + offset; per_channel_values[item.first] = ov::op::v0::Constant::create(input_type, mean_shape, data); } + OPENVINO_SUPPRESS_DEPRECATED_START auto const_node = get_constant_from_source(std::make_shared(per_channel_values, 0)); + OPENVINO_SUPPRESS_DEPRECATED_END OPENVINO_ASSERT(const_node); const auto& consumers = input_node->output(0).get_target_inputs(); auto add = std::make_shared(input_node, const_node); @@ -193,15 +194,13 @@ void parse_pre_process(pugi::xml_node& root, } } } // namespace -OPENVINO_SUPPRESS_DEPRECATED_END namespace ov { namespace frontend { namespace ir { -OPENVINO_SUPPRESS_DEPRECATED_START class InputModel::InputModelIRImpl { - std::shared_ptr m_weights; + std::shared_ptr m_weights; std::unordered_map m_extensions; std::unordered_map m_opsets; pugi::xml_node m_root; @@ -209,7 +208,7 @@ class InputModel::InputModelIRImpl { public: InputModelIRImpl(std::istream& stream, - const std::shared_ptr& weights, + const std::shared_ptr& weights, const std::unordered_map& extensions) : m_weights(weights), m_extensions(extensions) { @@ -227,11 +226,10 @@ class InputModel::InputModelIRImpl { }; InputModel::InputModel(std::istream& stream, - const std::shared_ptr& weights, + const std::shared_ptr& weights, const std::unordered_map& extensions) { _impl = std::make_shared(stream, weights, extensions); } -OPENVINO_SUPPRESS_DEPRECATED_END std::shared_ptr InputModel::convert() { return _impl->convert(); diff --git a/src/frontends/ir/src/input_model.hpp b/src/frontends/ir/src/input_model.hpp index 1b4da95f098b64..d5a9b64abaf0f8 100644 --- a/src/frontends/ir/src/input_model.hpp +++ b/src/frontends/ir/src/input_model.hpp @@ -7,9 +7,9 @@ #include #include -#include "ngraph/runtime/aligned_buffer.hpp" #include "openvino/frontend/manager.hpp" #include "openvino/frontend/visibility.hpp" +#include "openvino/runtime/aligned_buffer.hpp" namespace ov { namespace frontend { @@ -20,11 +20,9 @@ class InputModel : public ov::frontend::InputModel { std::shared_ptr _impl; public: - OPENVINO_SUPPRESS_DEPRECATED_START InputModel(std::istream& stream, - const std::shared_ptr& weights, + const std::shared_ptr& weights, const std::unordered_map& extensions); - OPENVINO_SUPPRESS_DEPRECATED_END std::shared_ptr convert(); }; diff --git a/src/frontends/ir/src/ir_deserializer.cpp b/src/frontends/ir/src/ir_deserializer.cpp index 42be66281d5d24..d245301633e4e3 100644 --- a/src/frontends/ir/src/ir_deserializer.cpp +++ b/src/frontends/ir/src/ir_deserializer.cpp @@ -20,6 +20,8 @@ #include "openvino/op/util/read_value_base.hpp" #include "openvino/op/util/sub_graph_base.hpp" #include "openvino/op/util/variable.hpp" +#include "openvino/runtime/aligned_buffer.hpp" +#include "openvino/runtime/shared_buffer.hpp" #include "rt_info_deserializer.hpp" #include "transformations/rt_info/attributes.hpp" #include "utils.hpp" @@ -258,7 +260,6 @@ void ov::XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor< if (skip_names.count(name) && !getStrAttribute(m_node.child("data"), name, val)) return; - OPENVINO_SUPPRESS_DEPRECATED_START if (auto a = ov::as_type>(&adapter)) { static_cast(*a) = ov::element::Type(val); } else if (auto a = ov::as_type>(&adapter)) { @@ -322,7 +323,7 @@ void ov::XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor< ov::op::util::VariableInfo{ov::PartialShape::dynamic(), ov::element::dynamic, variable_id}); } a->set(m_variables[variable_id]); - } else if (auto a = ov::as_type>>(&adapter)) { + } else if (auto a = ov::as_type>>(&adapter)) { std::string value; pugi::xml_node dn = m_node.child("data"); auto type = pugixml::utils::get_str_attr(m_node, "type"); @@ -331,7 +332,7 @@ void ov::XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor< OPENVINO_THROW("No attrtibutes defined for ", type, " op!"); if (getStrAttribute(dn, name, value)) { - auto buffer = std::make_shared(value.size()); + auto buffer = std::make_shared(value.size()); auto data = static_cast(buffer->get_ptr()); value.copy(data, value.size()); a->set(buffer); @@ -356,11 +357,7 @@ void ov::XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor< OPENVINO_THROW("Attribute and shape size are inconsistent for ", type, " op!"); char* data = m_weights->get_ptr() + offset; - auto buffer = - std::make_shared>>( - data, - size, - m_weights); + auto buffer = std::make_shared>>(data, size, m_weights); a->set(buffer); } } else if (auto a = ov::as_type>(&adapter)) { @@ -388,7 +385,6 @@ void ov::XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor< } else { OPENVINO_THROW("Error IR reading. Attribute adapter can not be found for ", name, " parameter"); } - OPENVINO_SUPPRESS_DEPRECATED_END } void ov::XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor>& adapter) { @@ -409,10 +405,8 @@ void ov::XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor< adapter.set(model); } -OPENVINO_SUPPRESS_DEPRECATED_START -std::shared_ptr ov::XmlDeserializer::parse_function( - const pugi::xml_node& root, - const std::shared_ptr& weights) { +std::shared_ptr ov::XmlDeserializer::parse_function(const pugi::xml_node& root, + const std::shared_ptr& weights) { // OV_ITT_SCOPE_CHAIN(FIRST_INFERENCE, taskChain, itt::domains::V10Reader_RT, "V10Parser", "Parse"); struct FunctionNodes { @@ -553,7 +547,6 @@ std::shared_ptr ov::XmlDeserializer::parse_function( return function; } -OPENVINO_SUPPRESS_DEPRECATED_END class MetaDataParser : public ov::Meta { public: @@ -751,12 +744,10 @@ static const std::string& translate_type_name(const std::string& name) { return name; } -OPENVINO_SUPPRESS_DEPRECATED_START -std::shared_ptr ov::XmlDeserializer::create_node( - const std::vector>& inputs, - const pugi::xml_node& node, - const std::shared_ptr& weights, - const GenericLayerParams& params) { +std::shared_ptr ov::XmlDeserializer::create_node(const std::vector>& inputs, + const pugi::xml_node& node, + const std::shared_ptr& weights, + const GenericLayerParams& params) { // Check that inputs are correctly defined for (size_t i = 0; i < inputs.size(); i++) { if (!inputs[i].get_node()) @@ -959,4 +950,3 @@ std::shared_ptr ov::XmlDeserializer::create_node( return ovNode; } -OPENVINO_SUPPRESS_DEPRECATED_END diff --git a/src/frontends/ir/src/ir_deserializer.hpp b/src/frontends/ir/src/ir_deserializer.hpp index f2062393f2986a..0b0d606ea4170b 100644 --- a/src/frontends/ir/src/ir_deserializer.hpp +++ b/src/frontends/ir/src/ir_deserializer.hpp @@ -10,11 +10,11 @@ #include #include "input_model.hpp" -#include "ngraph/runtime/aligned_buffer.hpp" #include "openvino/core/attribute_visitor.hpp" #include "openvino/core/op_extension.hpp" #include "openvino/op/loop.hpp" #include "openvino/op/util/sub_graph_base.hpp" +#include "openvino/runtime/aligned_buffer.hpp" #include "utils.hpp" namespace ov { @@ -58,9 +58,8 @@ struct GenericLayerParams { class XmlDeserializer : public ov::AttributeVisitor { public: - OPENVINO_SUPPRESS_DEPRECATED_START explicit XmlDeserializer(const pugi::xml_node& node, - const std::shared_ptr& weights, + const std::shared_ptr& weights, const std::unordered_map& opsets, const std::unordered_map& extensions, std::unordered_map>& variables, @@ -71,7 +70,6 @@ class XmlDeserializer : public ov::AttributeVisitor { m_extensions(extensions), m_variables(variables), m_version(version) {} - OPENVINO_SUPPRESS_DEPRECATED_END void on_adapter(const std::string& name, ov::ValueAccessor& value) override { std::string val; @@ -164,14 +162,12 @@ class XmlDeserializer : public ov::AttributeVisitor { // TODO consider to call only once per layer/TI-Loop node IoMap updated_io_map(const pugi::xml_node& node, const pugi::xml_node& body_node); - OPENVINO_SUPPRESS_DEPRECATED_START /// \brief Traverses xml node representation in order to create ov function for it. /// \param node xml node representation /// \param weights weights attached to current node /// \return shared pointer to function representing input node std::shared_ptr parse_function(const pugi::xml_node& root, - const std::shared_ptr& weights); - OPENVINO_SUPPRESS_DEPRECATED_END + const std::shared_ptr& weights); /// \brief Traverses xml node representation in order to get the purpose attribute of /// inputs/outputs in the body of Loop op. \param node xml node representation \return struct /// with value of purpuse attribute @@ -179,12 +175,10 @@ class XmlDeserializer : public ov::AttributeVisitor { GenericLayerParams parse_generic_params(const pugi::xml_node& node); - OPENVINO_SUPPRESS_DEPRECATED_START std::shared_ptr create_node(const ov::OutputVector& inputs, const pugi::xml_node& node, - const std::shared_ptr& weights, + const std::shared_ptr& weights, const GenericLayerParams& params); - OPENVINO_SUPPRESS_DEPRECATED_END void read_meta_data(const std::shared_ptr& model, const pugi::xml_node& meta_section); @@ -194,9 +188,7 @@ class XmlDeserializer : public ov::AttributeVisitor { // -- DATA -- const pugi::xml_node m_node; - OPENVINO_SUPPRESS_DEPRECATED_START - const std::shared_ptr& m_weights; - OPENVINO_SUPPRESS_DEPRECATED_END + const std::shared_ptr& m_weights; const std::unordered_map& m_opsets; const std::unordered_map& m_extensions; std::unordered_map>& m_variables; diff --git a/src/frontends/onnx/frontend/src/core/tensor.hpp b/src/frontends/onnx/frontend/src/core/tensor.hpp index cb54edf8e95e22..76a97b057f2a61 100644 --- a/src/frontends/onnx/frontend/src/core/tensor.hpp +++ b/src/frontends/onnx/frontend/src/core/tensor.hpp @@ -15,6 +15,7 @@ #include "ngraph/shape.hpp" #include "ngraph/type/element_type.hpp" #include "onnx_common/utils.hpp" +#include "openvino/runtime/aligned_buffer.hpp" #include "utils/common.hpp" #include "utils/tensor_external_data.hpp" @@ -302,15 +303,13 @@ class Tensor { template std::vector get_external_data() const { const auto ext_data = detail::TensorExternalData(*m_tensor_proto); - OPENVINO_SUPPRESS_DEPRECATED_START - std::shared_ptr buffer = nullptr; + std::shared_ptr buffer = nullptr; if (m_mmap_cache) { buffer = ext_data.load_external_mmap_data(m_model_dir, m_mmap_cache); } else { buffer = ext_data.load_external_data(m_model_dir); } return std::vector(buffer->get_ptr(), buffer->get_ptr() + buffer->size()); - OPENVINO_SUPPRESS_DEPRECATED_END } const void* get_data_ptr() const { diff --git a/src/frontends/onnx/frontend/src/op/random_uniform.cpp b/src/frontends/onnx/frontend/src/op/random_uniform.cpp index 6215dcc491c07d..a26ed672a0cc15 100644 --- a/src/frontends/onnx/frontend/src/op/random_uniform.cpp +++ b/src/frontends/onnx/frontend/src/op/random_uniform.cpp @@ -29,6 +29,7 @@ OutputVector random_uniform(const Node& node) { const auto target_type = common::get_ngraph_element_type(dtype); const uint64_t global_seed = 0; + // TODO: This multiplication leads to a mismatch in accuracy. Issue: 123003 const auto seed_uint64 = static_cast(seed * 1000); return {std::make_shared(target_shape_const, diff --git a/src/frontends/onnx/frontend/src/utils/tensor_external_data.cpp b/src/frontends/onnx/frontend/src/utils/tensor_external_data.cpp index 53e83e5d714101..9a40d1fc6d7595 100644 --- a/src/frontends/onnx/frontend/src/utils/tensor_external_data.cpp +++ b/src/frontends/onnx/frontend/src/utils/tensor_external_data.cpp @@ -12,7 +12,6 @@ #include "openvino/util/file_util.hpp" #include "openvino/util/log.hpp" -OPENVINO_SUPPRESS_DEPRECATED_START namespace ngraph { namespace onnx_import { namespace detail { @@ -51,13 +50,13 @@ Buffer TensorExternalData::load_external_mmap_data(const std:: if (m_data_length > mapped_memory->size() || mapped_memory->size() == 0) { throw error::invalid_external_data{*this}; } - return std::make_shared>>( + return std::make_shared>>( mapped_memory->data() + m_offset, m_data_length > 0 ? m_data_length : static_cast(file_size) - m_offset, mapped_memory); } -Buffer TensorExternalData::load_external_data(const std::string& model_dir) const { +Buffer TensorExternalData::load_external_data(const std::string& model_dir) const { auto full_path = ov::util::path_join({model_dir, m_data_location}); #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) NGRAPH_SUPPRESS_DEPRECATED_START @@ -82,14 +81,13 @@ Buffer TensorExternalData::load_external_data(co // default value of m_offset is 0 external_data_stream.seekg(m_offset, std::ios::beg); - auto read_data = std::make_shared(read_data_length); + auto read_data = std::make_shared(read_data_length); external_data_stream.read(read_data->get_ptr(), read_data_length); external_data_stream.close(); - auto buffer = std::make_shared>>( - read_data->get_ptr(), - read_data->size(), - read_data); + auto buffer = std::make_shared>>(read_data->get_ptr(), + read_data->size(), + read_data); return buffer; } diff --git a/src/frontends/onnx/frontend/src/utils/tensor_external_data.hpp b/src/frontends/onnx/frontend/src/utils/tensor_external_data.hpp index a13ccd457f485c..eb04e001e7ed4c 100644 --- a/src/frontends/onnx/frontend/src/utils/tensor_external_data.hpp +++ b/src/frontends/onnx/frontend/src/utils/tensor_external_data.hpp @@ -6,15 +6,15 @@ #include -#include "ngraph/runtime/shared_buffer.hpp" +#include "openvino/runtime/aligned_buffer.hpp" +#include "openvino/runtime/shared_buffer.hpp" #include "openvino/util/mmap_object.hpp" namespace ngraph { namespace onnx_import { namespace detail { -OPENVINO_SUPPRESS_DEPRECATED_START template -using Buffer = std::shared_ptr>>; +using Buffer = std::shared_ptr>>; using MappedMemoryHandles = std::shared_ptr>>; /// \brief Helper class used to load tensor data from external files class TensorExternalData { @@ -28,7 +28,7 @@ class TensorExternalData { /// the invalid_external_data exception is thrown. /// /// \return External binary data loaded into the SharedBuffer - Buffer load_external_data(const std::string& model_dir) const; + Buffer load_external_data(const std::string& model_dir) const; /// \brief Map (mmap for lin, MapViewOfFile for win) external data from tensor passed to constructor /// @@ -50,7 +50,6 @@ class TensorExternalData { uint64_t m_data_length = 0; std::string m_sha1_digest{}; }; -OPENVINO_SUPPRESS_DEPRECATED_END } // namespace detail } // namespace onnx_import } // namespace ngraph diff --git a/src/frontends/onnx/tests/CMakeLists.txt b/src/frontends/onnx/tests/CMakeLists.txt index 22bd85d5b92ee3..f0f8891b4a4945 100644 --- a/src/frontends/onnx/tests/CMakeLists.txt +++ b/src/frontends/onnx/tests/CMakeLists.txt @@ -133,7 +133,7 @@ target_include_directories(ov_onnx_frontend_tests PRIVATE "${CMAKE_CURRENT_SOURC target_compile_definitions(ov_onnx_frontend_tests PRIVATE SHARED_LIB_PREFIX="${CMAKE_SHARED_LIBRARY_PREFIX}" - SHARED_LIB_SUFFIX="${IE_BUILD_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}") + SHARED_LIB_SUFFIX="${OV_BUILD_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}") set(ONNX_OPSET_VERSION 17 CACHE INTERNAL "Supported version of ONNX operator set") target_compile_definitions(ov_onnx_frontend_tests PRIVATE ONNX_OPSET_VERSION=${ONNX_OPSET_VERSION}) diff --git a/src/frontends/onnx/tests/__init__.py b/src/frontends/onnx/tests/__init__.py index 857c3853cf8fd2..87220792d2d349 100644 --- a/src/frontends/onnx/tests/__init__.py +++ b/src/frontends/onnx/tests/__init__.py @@ -127,6 +127,7 @@ def xfail_test(reason="Mark the test as expected to fail", strict=True): "Not equal to tolerance") xfail_issue_58033 = xfail_test(reason="Einsum operation misses support for complex ellipsis equations") xfail_issue_58676 = xfail_test(reason="AssertionError: Not equal to tolerance rtol=0.001, atol=1e-07") +skip_issue_58676 = pytest.mark.skip(reason="AssertionError: Not equal to tolerance rtol=0.001, atol=1e-07") xfail_issue_onnx_models_140 = xfail_test(reason="https://github.com/onnx/models/issues/140") xfail_issue_63033 = xfail_test(reason="BatchNormalization: Training mode is not supported") diff --git a/src/frontends/onnx/tests/skip_tests_config.cpp b/src/frontends/onnx/tests/skip_tests_config.cpp index 234cb99dfe9257..99d6bc297a1110 100644 --- a/src/frontends/onnx/tests/skip_tests_config.cpp +++ b/src/frontends/onnx/tests/skip_tests_config.cpp @@ -9,9 +9,11 @@ std::vector disabledTestPatterns() { return { -#ifndef BUILD_SHARED_LIBS +#ifdef OPENVINO_STATIC_LIBRARY // Disable tests for static libraries - ".*FrontendLibCloseTest.*" + ".*FrontendLibCloseTest.*", #endif + // CVS-123201 + ".*testUnloadLibBeforeDeletingDependentObject.*", }; } diff --git a/src/frontends/onnx/tests/tests_python/test_backend.py b/src/frontends/onnx/tests/tests_python/test_backend.py index d1ef686bdd4124..14034898b7c693 100644 --- a/src/frontends/onnx/tests/tests_python/test_backend.py +++ b/src/frontends/onnx/tests/tests_python/test_backend.py @@ -2,6 +2,7 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform import logging import onnx.backend.test @@ -24,6 +25,7 @@ xfail_issue_38735, skip_issue_39658, skip_issue_39658, + skip_issue_58676, xfail_issue_44858, xfail_issue_44965, xfail_issue_45180, @@ -683,6 +685,22 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None ), ] +if platform.system() == 'Darwin': + tests_expected_to_fail.extend([ + ( + skip_issue_58676, + "OnnxBackendNodeModelTest.test_mish_expanded_cpu" + ), + ( + skip_issue_58676, + "OnnxBackendNodeModelTest.test_resize_downsample_scales_linear_cpu" + ), + ( + skip_issue_58676, + "OnnxBackendNodeModelTest.test_div_uint8_cpu" + )] + ) + for test_group in tests_expected_to_fail: for test_case in test_group[1:]: expect_fail(f"{test_case}", test_group[0]) diff --git a/src/frontends/paddle/src/op/slice_ops.hpp b/src/frontends/paddle/src/op/slice_ops.hpp index dc2a609ba18513..1f8798bc00e91f 100644 --- a/src/frontends/paddle/src/op/slice_ops.hpp +++ b/src/frontends/paddle/src/op/slice_ops.hpp @@ -33,63 +33,16 @@ NamedOutputs slice_op(const NodeContext& node, const bool& stride_input) { Output start_idx_node = idx_node("StartsTensor", "StartsTensorList", "starts", node); Output end_idx_node = idx_node("EndsTensor", "EndsTensorList", "ends", node); Output strides_idx_node; - if (stride_input) - strides_idx_node = idx_node("StridesTensor", "StridesTensorList", "strides", node); - - // The following process is: - // Given: - // data = [ [1, 2, 3, 4], [5, 6, 7, 8], ] // shape is: [2, 4] - // axes = [0] - // starts = [1] - // ends = [2] - // Our process is: - // 1. Get 'axes': [0, 1], 'starts', 'ends' - // 2. Get data shape: [2,4] and dims: 2 - // 3. Create two tensor t1 and t2, shape is the dims from step2: 2. t1: [0, 0], t2: [INT_MAX, INT_MAX] - // 4. Use 'ScatterNDUpdate' to update some elements in t1, the updated indexes are coming from 'axes', the contents - // are coming from 'starts', t1: [1, 0]; apply the similar process to t2 - // 5. Call 'StrideSlice' with t1 and t2 - // Why using ScatterNDUpdate is that 'axes' may be discontinuous. - - // the shape of input, such as [2, 4] - const auto shape_node = std::make_shared(data, element::Type_t::i32); - // the input dim, such as [2] - const auto rank_node = std::make_shared(shape_node, element::i32); - const auto const_0_node = default_opset::Constant::create(element::i32, {}, {0}); - const auto const_max_node = default_opset::Constant::create(element::i32, {}, {INT_MAX}); - const auto const_1_node = default_opset::Constant::create(element::i32, {}, {1}); - // t1: [0, 0] - const auto start_node = std::make_shared(const_0_node, rank_node); - // t2: [INT_MAX, INT_MAX] - const auto end_node = std::make_shared(const_max_node, rank_node); - const auto strides_node = std::make_shared(const_1_node, rank_node); - const auto axes_node = default_opset::Constant::create(element::i32, {axes.size(), 1}, axes); - // update t1 - const auto fixed_start_node = - std::make_shared(start_node, axes_node, start_idx_node); - // update t2 - const auto fixed_end_node = std::make_shared(end_node, axes_node, end_idx_node); - std::shared_ptr stride_slice_node; if (stride_input) { - const auto fixed_strides_node = - std::make_shared(strides_node, axes_node, strides_idx_node); - - stride_slice_node = std::make_shared(data, - fixed_start_node, - fixed_end_node, - fixed_strides_node, - std::vector{0}, - std::vector{0}); + strides_idx_node = idx_node("StridesTensor", "StridesTensorList", "strides", node); } else { - stride_slice_node = std::make_shared(data, - fixed_start_node, - fixed_end_node, - std::vector{0}, - std::vector{0}); + strides_idx_node = + default_opset::Constant::create(element::i32, start_idx_node.get_shape(), std::vector{1}); } - + const auto axes_node = default_opset::Constant::create(element::i32, {axes.size()}, axes); + const auto slice_node = + std::make_shared(data, start_idx_node, end_idx_node, strides_idx_node, axes_node); const auto decrease_axis = node.get_attribute>("decrease_axis"); - if (decrease_axis.size() > 0) { PartialShape input_shape = data.get_partial_shape(); PADDLE_OP_CHECK(node, @@ -99,18 +52,19 @@ NamedOutputs slice_op(const NodeContext& node, const bool& stride_input) { // according to paddle slice_op, when all axes are decreased, output shape is [1], instead of scalar. // Ref: paddle/fluid/operators/slice_op.h auto decreased_node = std::make_shared( - stride_slice_node, + slice_node, std::make_shared(element::i64, Shape{1}, 1), false); return node.default_single_output_mapping({decreased_node}, {"Out"}); } + const auto squeeze_index_node = default_opset::Constant::create(element::i32, {decrease_axis.size()}, decrease_axis); - const auto decreased_node = std::make_shared(stride_slice_node, squeeze_index_node); + const auto decreased_node = std::make_shared(slice_node, squeeze_index_node); return node.default_single_output_mapping({decreased_node}, {"Out"}); + } else { + return node.default_single_output_mapping({slice_node}, {"Out"}); } - - return node.default_single_output_mapping({stride_slice_node}, {"Out"}); } } // namespace } // namespace op diff --git a/src/frontends/paddle/tests/CMakeLists.txt b/src/frontends/paddle/tests/CMakeLists.txt index 82a68ce62bc206..6d373e67c0a663 100644 --- a/src/frontends/paddle/tests/CMakeLists.txt +++ b/src/frontends/paddle/tests/CMakeLists.txt @@ -4,25 +4,6 @@ set(TARGET_NAME "paddle_tests") -ov_add_test_target( - NAME ${TARGET_NAME} - ROOT ${CMAKE_CURRENT_SOURCE_DIR} - DEPENDENCIES - paddle_test_models - openvino_paddle_frontend - paddle_fe_standalone_build_test - LINK_LIBRARIES - cnpy - frontend_shared_test_classes - openvino_paddle_frontend - openvino::runtime - gtest_main_manifest - func_test_utils - ADD_CLANG_FORMAT - # LABELS - # OV UNIT PADDLE_FE -) - # Test model generating set(PADDLE_REQ "${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt") if(Python3_Interpreter_FOUND) @@ -43,6 +24,29 @@ endif() # PDPD 2.5.1 is not compatible with tests models we use set(paddlepaddle_FOUND OFF) +if(paddlepaddle_FOUND) + set(ctest_labels OV UNIT) +endif() + +ov_add_test_target( + NAME ${TARGET_NAME} + ROOT ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDENCIES + paddle_test_models + openvino_paddle_frontend + paddle_fe_standalone_build_test + LINK_LIBRARIES + cnpy + frontend_shared_test_classes + openvino_paddle_frontend + openvino::runtime + gtest_main_manifest + func_test_utils + ADD_CLANG_FORMAT + LABELS + ${ctest_labels} PADDLE_FE +) + set(TEST_PADDLE_MODELS_DIRNAME ${TEST_MODEL_ZOO}/paddle_test_models) target_compile_definitions(${TARGET_NAME} PRIVATE -D TEST_PADDLE_MODELS_DIRNAME=\"${TEST_PADDLE_MODELS_DIRNAME}/\") diff --git a/src/frontends/paddle/tests/skip_tests_config.cpp b/src/frontends/paddle/tests/skip_tests_config.cpp index 234cb99dfe9257..144e9d001ae276 100644 --- a/src/frontends/paddle/tests/skip_tests_config.cpp +++ b/src/frontends/paddle/tests/skip_tests_config.cpp @@ -9,7 +9,7 @@ std::vector disabledTestPatterns() { return { -#ifndef BUILD_SHARED_LIBS +#ifdef OPENVINO_STATIC_LIBRARY // Disable tests for static libraries ".*FrontendLibCloseTest.*" #endif diff --git a/src/frontends/paddle/tests/test_models/gen_scripts/generate_slice.py b/src/frontends/paddle/tests/test_models/gen_scripts/generate_slice.py index f89e18d7500c65..f2a6d1a8769295 100644 --- a/src/frontends/paddle/tests/test_models/gen_scripts/generate_slice.py +++ b/src/frontends/paddle/tests/test_models/gen_scripts/generate_slice.py @@ -20,7 +20,7 @@ def slice(name : str, x, axes : list, start : list, end : list): with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): node_x = paddle.static.data(name='x', shape=x.shape, dtype = data_type) - out = paddle.fluid.layers.slice(node_x, axes = axes, starts = start, ends = end) + out = paddle.slice(node_x, axes = axes, starts = start, ends = end) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) diff --git a/src/frontends/pytorch/README.md b/src/frontends/pytorch/README.md new file mode 100644 index 00000000000000..92a38d693d9b21 --- /dev/null +++ b/src/frontends/pytorch/README.md @@ -0,0 +1,141 @@ +# OpenVINO PyTorch Frontend + +The PyTorch Frontend (PT FE) is a C++ based OpenVINO Frontend component that is +responsible for reading and converting a PyTorch model to an `ov::Model` object +that can be further serialized into the Intermediate Representation (IR) format. + +## Key Contacts + +People from the [openvino-pytorch-frontend-maintainers](https://github.com/orgs/openvinotoolkit/teams/openvino-pytorch-frontend-maintainers) +have the rights to approve and merge PRs to the PyTorch Frontend component. +They can assist with any questions about the component. + +## Components + +The structure of OpenVINO PyTorch Frontend sources includes the following +directories: + +* [include](./include) is a public frontend API. +* [src](./src/) folder contains the sources of the component. + +## Architecture + +OpenVINO PyTorch Frontend is a C++ component that uses [TorchScriptPythonDecoder](../../bindings/python/src/openvino/frontend/pytorch/ts_decoder.py) +in Python code to parse a PyTorch model from a Python object. Usually, the frontend is +used inside [openvino.convert_model](../../../tools/ovc) in Python code or inside +openvino backend in `torch.compile_model`, in which case `TorchFXPythonDecoder` +is used to decode `torch.fx.graph`. The entire model conversion workflow can be +represented by the following diagram. + +```mermaid +flowchart TD + A[(torch.nn.Module)] --> torch.compile + subgraph torch.compile + subgraph TorchFXPythonDecoder + torch.fx.graph_module.GraphModule + end + TorchFXPythonDecoder --> E("pytorch::FrontEnd::load()") + E -->|ov::InputModel| F("pytorch::FrontEnd::convert()") + F --> G[(ov::Model)] + end + A[(torch.nn.Module)] --> openvino.convert_model + subgraph openvino.convert_model + subgraph TorchScriptPythonDecoder + torch.jit.trace ~~~ torch.jit.script + end + TorchScriptPythonDecoder --> B("pytorch::FrontEnd::load()") + B -->|ov::InputModel| C("pytorch::FrontEnd::convert()") + end + openvino.convert_model --> D[(ov::Model)] +``` + +OpenVINO PyTorch Frontend supports extensions. To add an extension, use +`ov::frontend::pytorch::Frontend::add_extension()` API. +The following extension types are supported: + +* `ov::frontend::tensorflow::ConversionExtension` or `ov::frontend::ConversionExtension` - add a new Loader into the conversion pipeline. +* `ov::TelemetryExtension` - enable telemetry for the frontend. +* `ov::BaseOpExtension` - enable support for a custom operation. +* `ov::detail::SOExtension` - allow support for `ov::BaseOpExtension` extensions loaded from an external library. + +## How to Implement Support for a New PyTorch Operation + +PyTorch conversion into the OpenVINO opset operations consists of two stages: +1. Conversion of PyTorch operations to OpenVINO opset using [translators](./src/op/), + which directly transforms a PyTorch operation into a sub-graph of the OpenVINO + opset. This is a 1->N conversion. +2. [Internal Transformations](./src/transforms) that transform a sub-graph of + operations into a sub-graph of the OpenVINO opset. This is an N->N conversion. + +### Operation Translation + +Most PyTorch operations can be converted by a single `translator`. The +dictionary of `translators` is placed in the [op_table.cpp](./src/op_table.cpp) +file and each translator is located in the [op](../tensorflow_common/src/op/) +directory: + +https://github.com/openvinotoolkit/openvino/blob/491454103ea2f29b242587c6084c19868a879a82/src/frontends/pytorch/src/op_table.cpp#L222-L227 + +The main rules for translator implementation: +1. Support dynamic shapes and ranks, undefined types, including future support of new types, such as strings and complex numbers. +2. Try to maintain the same algorithmic complexity of the decomposition. Fewer operations are usually better. +3. Use the latest OpenVINO opset version for the translation. +4. Use helper routines for operation checks and graph construction from `utils.hpp`. +5. Call `NodeContext::mark_mode()` for each created node. + +#### Inplace and Mutable Operations + +Some PyTorch operations modify the input tensor rather than the output. For example, +`aten::add` writes the result of addition to the output, but `aten::add_` writes the result +to its first input. To correctly convert such an operation: +* Ensure that the output tensor produced by the translation has the same type and shape as the initial input. +* Call `NodeContext::mutate_input()` to change the input tensor with the new value. + +#### PtFrameworkNode Primitive + +`PtFrameworkNode` is used to represent unconverted operation from the original +model. You can use `FrontEnd::convert_partially()` instead of `Frontend::convert()` +to get an `ov::Model` containing unconverted operations. + +#### Operations Accepting Strings + +At the moment, OpenVINO core does not support strings. However, since strings in models are usually constants, you can extract them as `std::string` directly from Python using `NodeContext::const_input()`. + +#### Operations with lists, tuples, dicts + +These types are also not supported by OpenVINO core and generally require +implementing transformation for N->N conversion. However, in some simple cases, lists +and tuples can be processed. Helpers for working with lists can be found in `utils.hpp`. +For example, `get_list_as_outputs` enables you to get list elements to work with them +in the translator or transformation. + +### Internal Transformations + +In rare cases, converting PyTorch operations requires transformation. The main +difference between transformation and translation is that transformation works on the graph rather +than on the `NodeContext` of a single operation. This means that some functionality +provided by `NodeContext` is not accessible in transformation and usually +requires working with `PtFramworkNode` directly. [General rules](https://docs.openvino.ai/2023.1/openvino_docs_transformations.html) +for writing transformations also apply to PT FE transformations. + +### PyTorch Frontend Layer Tests + +The layer tests are Python-based tests that check if a PyTorch operation is +supported by PT FE. The testing pipeline of the layer tests consists of four +steps: +1. Create a simple model containing the PyTorch operation to be tested. +2. Convert this model into an OpenVINO Model. +3. Infer the original model using PyTorch and infer the OpenVINO Model. +4. Compare the inference results between both frameworks. + +To set up the environment for running the layer tests, follow these [instructions](../../../tests/layer_tests/README.md). + +To test the entire suite of the PyTorch operation set support, run the following command: +```bash +python -m pytest layer_tests/pytorch_tests +``` + +## See Also + * [OpenVINO README](../../../README.md) + * [OpenVINO Core Components](../../README.md) + * [Developer documentation](../../../docs/dev/index.md) diff --git a/src/frontends/pytorch/include/openvino/frontend/pytorch/decoder.hpp b/src/frontends/pytorch/include/openvino/frontend/pytorch/decoder.hpp index 066c203e3a1938..d5878783c314af 100644 --- a/src/frontends/pytorch/include/openvino/frontend/pytorch/decoder.hpp +++ b/src/frontends/pytorch/include/openvino/frontend/pytorch/decoder.hpp @@ -40,6 +40,9 @@ class TorchDecoder : public IDecoder { // Return shape if inputs has torch::Tensor type in the original model, otherwise returns the shape [] of a scalar virtual PartialShape get_input_shape(size_t index) const = 0; + // Return strides if inputs has torch::Tensor type in original model, otherwise return []. + virtual const std::vector& get_input_strides(size_t index) const = 0; + // Return element::Type when it the original type can be represented, otherwise returns PT-specific data type object // (see custom_type.hpp) virtual Any get_input_type(size_t index) const = 0; diff --git a/src/frontends/pytorch/src/frontend.cpp b/src/frontends/pytorch/src/frontend.cpp index 0910aa3e057e72..36d4027dcc426f 100644 --- a/src/frontends/pytorch/src/frontend.cpp +++ b/src/frontends/pytorch/src/frontend.cpp @@ -20,6 +20,7 @@ #include "transformations/op_conversions/convert_convertlike.hpp" #include "transformations/resolve_names_collisions.hpp" #include "transforms.hpp" +#include "transforms/align_types_removal.hpp" #include "transforms/append_list_unpack_replacer.hpp" #include "transforms/aten_cat_replacer.hpp" #include "transforms/aten_getitem_replacer.hpp" @@ -41,6 +42,7 @@ #include "transforms/softmax_reshape_elimination.hpp" #include "transforms/string_equality_replacer.hpp" #include "transforms/tuple_unpack_replacer.hpp" +#include "transforms/u4_block_repack.hpp" #include "translate_session.hpp" namespace ov { @@ -176,6 +178,7 @@ void FrontEnd::normalize(const std::shared_ptr& model) const { manager.register_pass( element::TypeVector{element::u8, element::i8, element::u4, element::i4}); manager.register_pass(); + manager.register_pass(); manager.register_pass(); manager.register_pass(); manager.register_pass(); @@ -200,8 +203,11 @@ void FrontEnd::normalize(const std::shared_ptr& model) const { manager.register_pass(); manager.register_pass(); manager.register_pass(); + manager.register_pass(); manager.register_pass(); manager.register_pass(); + // Second pass of AlignTypesRemoval after all converting transformations + manager.register_pass(); manager.register_pass(); manager.run_passes(model); diff --git a/src/frontends/pytorch/src/helper_ops/align_types.hpp b/src/frontends/pytorch/src/helper_ops/align_types.hpp new file mode 100644 index 00000000000000..cd69af250fa30d --- /dev/null +++ b/src/frontends/pytorch/src/helper_ops/align_types.hpp @@ -0,0 +1,43 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "internal_op.hpp" +#include "openvino/frontend/decoder.hpp" +#include "utils.hpp" + +namespace ov { +namespace frontend { +namespace pytorch { + +class AlignTypes : public InternalOperation { +public: + AlignTypes(const Output& lhs, const Output& rhs, bool align_scalars) + : InternalOperation("ov::align_types", + {lhs, rhs}, + 2, + "This is internal operation for type alignment and should be removed " + "at normalization step. It can't be removed if types can't be resolved."), + m_align_scalars(align_scalars) { + validate_and_infer_types(); + } + + void validate_and_infer_types() override { + auto lhs = input_value(0); + auto rhs = input_value(1); + auto out_type = infer_types(lhs, rhs, m_align_scalars); + set_output_type(0, out_type, get_input_partial_shape(0)); + set_output_type(1, out_type, get_input_partial_shape(1)); + } + +private: + const bool m_align_scalars; +}; +} // namespace pytorch +} // namespace frontend +} // namespace ov diff --git a/src/frontends/pytorch/src/helper_ops/internal_op.hpp b/src/frontends/pytorch/src/helper_ops/internal_op.hpp new file mode 100644 index 00000000000000..510654dce8620a --- /dev/null +++ b/src/frontends/pytorch/src/helper_ops/internal_op.hpp @@ -0,0 +1,56 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "openvino/frontend/decoder.hpp" +#include "pt_framework_node.hpp" +#include "utils.hpp" + +namespace ov { +namespace frontend { +namespace pytorch { + +class InternalOpDecoder : public DummyDecoder { +public: + explicit InternalOpDecoder(const std::string& op_type, const size_t num_outputs) + : m_op_type(op_type), + m_num_outputs(num_outputs) {} + const std::string& get_op_type() const override { + return m_op_type; + } + size_t num_of_outputs() const override { + return m_num_outputs; + } + size_t get_subgraph_size() const override { + return 0; + } + const std::string& decoder_type_name() const override { + return m_decoder_type; + } + +private: + const std::string m_op_type; + const std::string m_decoder_type = "internal_op"; + const size_t m_num_outputs; +}; + +class InternalOperation : public PtFrameworkNode { +protected: + InternalOperation(const std::string& op_type, + const OutputVector& inputs, + size_t num_outputs, + const std::string& no_conversion_reason) + : PtFrameworkNode(std::make_shared(op_type, num_outputs), inputs) { + auto attrs = get_attrs(); + attrs[PtFrameworkNode::failed_conversion_key] = no_conversion_reason; + set_attrs(attrs); + } +}; +} // namespace pytorch +} // namespace frontend +} // namespace ov diff --git a/src/frontends/pytorch/src/op/adaptive_avg_pool3d.cpp b/src/frontends/pytorch/src/op/adaptive_avg_pool3d.cpp deleted file mode 100644 index 42aa3da1d8586b..00000000000000 --- a/src/frontends/pytorch/src/op/adaptive_avg_pool3d.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "openvino/frontend/pytorch/node_context.hpp" -#include "openvino/op/adaptive_avg_pool.hpp" -#include "openvino/op/concat.hpp" -#include "openvino/op/constant.hpp" -#include "openvino/op/reshape.hpp" -#include "openvino/op/shape_of.hpp" -#include "openvino/op/slice.hpp" -#include "openvino/op/tile.hpp" -#include "utils.hpp" - -namespace ov { -namespace frontend { -namespace pytorch { -namespace op { - -using namespace ov::op; - -OutputVector translate_adaptive_avg_pool3d(const NodeContext& context) { - num_inputs_check(context, 2, 2); - auto const_tile_params = context.mark_node(v0::Constant::create(element::i32, Shape{5}, {1, 1, 1, 1, 1})); - auto const_0 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {0})); - auto const_1 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {1})); - auto const_neg_3 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {-3})); - - auto input_tensor = context.get_input(0); - auto given_shape = context.get_input(1); - - auto input_shape = context.mark_node(std::make_shared(input_tensor, element::i32)); - auto shape_begin = - context.mark_node(std::make_shared(input_shape, const_0, const_neg_3, const_1, const_0)); - auto output_shape = context.mark_node(std::make_shared(OutputVector{shape_begin, given_shape}, 0)); - - auto tile = context.mark_node(std::make_shared(input_tensor, const_tile_params)); - auto adaptive_avg_pool = context.mark_node(std::make_shared(tile, given_shape)); - auto reshape = context.mark_node(std::make_shared(adaptive_avg_pool, output_shape, false)); - - return {reshape}; -}; - -} // namespace op -} // namespace pytorch -} // namespace frontend -} // namespace ov \ No newline at end of file diff --git a/src/frontends/pytorch/src/op/adaptive_max_pool2d.cpp b/src/frontends/pytorch/src/op/adaptive_max_pool2d.cpp deleted file mode 100644 index 5705fd22e70f47..00000000000000 --- a/src/frontends/pytorch/src/op/adaptive_max_pool2d.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "openvino/frontend/pytorch/node_context.hpp" -#include "openvino/op/adaptive_max_pool.hpp" -#include "utils.hpp" - -namespace ov { -namespace frontend { -namespace pytorch { -namespace op { - -OutputVector translate_adaptive_max_pool2d(const NodeContext& context) { - num_inputs_check(context, 2, 2); - auto x = context.get_input(0); - auto y = context.get_input(1); - auto adaptive_max_pool = context.mark_node(std::make_shared(x, y, ov::element::i32)); - return {adaptive_max_pool->output(0), adaptive_max_pool->output(1)}; -}; - -} // namespace op -} // namespace pytorch -} // namespace frontend -} // namespace ov \ No newline at end of file diff --git a/src/frontends/pytorch/src/op/adaptive_poolnd.cpp b/src/frontends/pytorch/src/op/adaptive_poolnd.cpp new file mode 100644 index 00000000000000..9c349e50c8ed86 --- /dev/null +++ b/src/frontends/pytorch/src/op/adaptive_poolnd.cpp @@ -0,0 +1,123 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/frontend/pytorch/node_context.hpp" +#include "openvino/op/adaptive_avg_pool.hpp" +#include "openvino/op/adaptive_max_pool.hpp" +#include "openvino/op/concat.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/convert.hpp" +#include "openvino/op/reshape.hpp" +#include "openvino/op/shape_of.hpp" +#include "openvino/op/slice.hpp" +#include "openvino/op/tile.hpp" +#include "utils.hpp" + +namespace ov { +namespace frontend { +namespace pytorch { +namespace op { + +using namespace ov::op; + +namespace { + +std::tuple, Output> get_tile_input_and_output_shape(const NodeContext& context, + const Output& input_tensor, + const Output& given_shape, + const Output& tile_shape, + const Output& slice_end) { + auto const_0 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {0})); + auto const_1 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {1})); + auto input_shape = context.mark_node(std::make_shared(input_tensor, element::i32)); + auto shape_begin = + context.mark_node(std::make_shared(input_shape, const_0, slice_end, const_1, const_0)); + Output output_shape = + context.mark_node(std::make_shared(OutputVector{shape_begin, given_shape}, 0)); + Output tile = context.mark_node(std::make_shared(input_tensor, tile_shape)); + return std::make_tuple(tile, output_shape); +}; + +OutputVector translate_adaptive_avg_pool_base(const NodeContext& context, + const Output& tile_shape, + const Output& slice_end) { + num_inputs_check(context, 2, 2); + + auto input_tensor = context.get_input(0); + auto given_shape = context.get_input(1); + Output tile_input; + Output output_shape; + std::tie(tile_input, output_shape) = + get_tile_input_and_output_shape(context, input_tensor, given_shape, tile_shape, slice_end); + auto adaptive_avg_pool = context.mark_node(std::make_shared(tile_input, given_shape)); + auto reshape = context.mark_node(std::make_shared(adaptive_avg_pool, output_shape, false)); + return {reshape}; +}; + +OutputVector translate_adaptive_max_pool_base(const NodeContext& context, + const Output& tile_shape, + const Output& slice_end) { + num_inputs_check(context, 2, 2); + + auto input_tensor = context.get_input(0); + auto given_shape = context.get_input(1); + Output tile_input; + Output output_shape; + std::tie(tile_input, output_shape) = + get_tile_input_and_output_shape(context, input_tensor, given_shape, tile_shape, slice_end); + + auto adaptive_max_pool = + context.mark_node(std::make_shared(tile_input, given_shape, element::i32)); + auto pooled_tensor = adaptive_max_pool->output(0); + auto pooled_indices = adaptive_max_pool->output(1); + // adaptive max pool in torch return indices in i64, indices_element_type i64 is not implented on ov runtime side + pooled_indices = context.mark_node(std::make_shared(pooled_indices, element::i64)); + pooled_tensor = context.mark_node(std::make_shared(pooled_tensor, output_shape, false)); + pooled_indices = context.mark_node(std::make_shared(pooled_indices, output_shape, false)); + // aten::adaptive_max_pool{n}d always returns tuple with 2 tensors: pooled tensor and indicies + // output selecting only first or preserve both made outside of operation by return_indices flag + return {pooled_tensor, pooled_indices}; +}; +} // namespace + +OutputVector translate_adaptive_avg_pool3d(const NodeContext& context) { + auto const_tile_params = context.mark_node(v0::Constant::create(element::i32, Shape{5}, {1, 1, 1, 1, 1})); + auto const_neg_3 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {-3})); + return translate_adaptive_avg_pool_base(context, const_tile_params, const_neg_3); +}; + +OutputVector translate_adaptive_avg_pool2d(const NodeContext& context) { + auto const_tile_params = context.mark_node(v0::Constant::create(element::i32, Shape{4}, {1, 1, 1, 1})); + auto const_neg_2 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {-2})); + return translate_adaptive_avg_pool_base(context, const_tile_params, const_neg_2); +}; + +OutputVector translate_adaptive_avg_pool1d(const NodeContext& context) { + auto const_tile_params = context.mark_node(v0::Constant::create(element::i32, Shape{3}, {1, 1, 1})); + auto const_neg_1 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {-1})); + return translate_adaptive_avg_pool_base(context, const_tile_params, const_neg_1); +}; + +OutputVector translate_adaptive_max_pool3d(const NodeContext& context) { + auto const_tile_params = context.mark_node(v0::Constant::create(element::i32, Shape{5}, {1, 1, 1, 1, 1})); + auto const_neg_3 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {-3})); + return translate_adaptive_max_pool_base(context, const_tile_params, const_neg_3); +}; + +OutputVector translate_adaptive_max_pool2d(const NodeContext& context) { + auto const_tile_params = context.mark_node(v0::Constant::create(element::i32, Shape{4}, {1, 1, 1, 1})); + auto const_neg_2 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {-2})); + return translate_adaptive_max_pool_base(context, const_tile_params, const_neg_2); +}; + +OutputVector translate_adaptive_max_pool1d(const NodeContext& context) { + auto const_tile_params = context.mark_node(v0::Constant::create(element::i32, Shape{3}, {1, 1, 1})); + auto const_neg_1 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {-1})); + return translate_adaptive_max_pool_base(context, const_tile_params, const_neg_1); +}; + +} // namespace op +} // namespace pytorch +} // namespace frontend +} // namespace ov \ No newline at end of file diff --git a/src/frontends/pytorch/src/op/add.cpp b/src/frontends/pytorch/src/op/add.cpp index f0a997b6f8fa3a..33699ad90fa39c 100644 --- a/src/frontends/pytorch/src/op/add.cpp +++ b/src/frontends/pytorch/src/op/add.cpp @@ -15,7 +15,9 @@ namespace frontend { namespace pytorch { namespace op { -OutputVector translate_add(const NodeContext& context) { +using namespace ov::op; + +OutputVector translate_add_common(const NodeContext& context, bool inplace) { num_inputs_check(context, 2, 3); auto lhs = context.get_input(0); auto rhs = context.get_input(1); @@ -26,12 +28,28 @@ OutputVector translate_add(const NodeContext& context) { // Case when two lists gets concatenated FRONT_END_OP_CONVERSION_CHECK(false, "aten::add is used for concatenation of lists, not possible to convert"); } - align_eltwise_input_types(context, lhs, rhs, true); + if (inplace) { + if (lhs.get_element_type().is_dynamic() || lhs.get_element_type() != rhs.get_element_type()) + rhs = context.mark_node(std::make_shared(rhs, lhs)); + } else { + align_eltwise_input_types(context, lhs, rhs, true); + } if (!context.input_is_none(2)) { - auto converted_alpha = context.mark_node(std::make_shared(context.get_input(2), rhs)); - rhs = context.mark_node(std::make_shared(converted_alpha, rhs)); + auto converted_alpha = context.mark_node(std::make_shared(context.get_input(2), rhs)); + rhs = context.mark_node(std::make_shared(converted_alpha, rhs)); } - return {context.mark_node(std::make_shared(lhs, rhs))}; + auto add = context.mark_node(std::make_shared(lhs, rhs)); + if (inplace) + context.mutate_input(0, add); + return {add}; +}; + +OutputVector translate_add(const NodeContext& context) { + return translate_add_common(context, false); +}; + +OutputVector translate_add_(const NodeContext& context) { + return translate_add_common(context, true); }; } // namespace op diff --git a/src/frontends/pytorch/src/op/as_strided.cpp b/src/frontends/pytorch/src/op/as_strided.cpp new file mode 100644 index 00000000000000..5d1dfe38bdaa17 --- /dev/null +++ b/src/frontends/pytorch/src/op/as_strided.cpp @@ -0,0 +1,106 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/frontend/pytorch/node_context.hpp" +#include "openvino/op/add.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/gather.hpp" +#include "openvino/op/multiply.hpp" +#include "openvino/op/range.hpp" +#include "openvino/op/reshape.hpp" +#include "openvino/op/scatter_update.hpp" +#include "openvino/op/tile.hpp" +#include "openvino/op/transpose.hpp" +#include "utils.hpp" + +namespace ov { +namespace frontend { +namespace pytorch { +namespace op { + +using namespace ov::op; +bool compare_strides(const std::tuple& a, const std::tuple& b) { + return std::get<0>(a) > std::get<0>(b); +} +OutputVector translate_as_strided(const NodeContext& context) { + // "aten::as_strided(Tensor(a) self, SymInt[] size, SymInt[] stride, SymInt? storage_offset=None) -> Tensor(a)" + num_inputs_check(context, 3, 4); + auto decoder = context.get_decoder(); + auto input = context.get_input(0); + auto const_1 = context.mark_node(v0::Constant::create(element::i32, Shape{}, {1})); + auto const_0 = context.mark_node(v0::Constant::create(element::i32, Shape{}, {0})); + auto const_neg_1 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {-1})); + auto input_strides = decoder->get_input_strides(0); + FRONT_END_OP_CONVERSION_CHECK(input_strides.size() != 0, + "aten::as_strided: Couldn't retrive input stride information from torchscript."); + + std::vector idxs(input_strides.size()); + iota(idxs.begin(), idxs.end(), 0); + std::vector> stride_idxs(idxs.size()); + std::for_each(idxs.rbegin(), idxs.rend(), [&](size_t& idx) { + stride_idxs[idx] = {input_strides[idx], idx}; + }); + + std::sort(stride_idxs.begin(), stride_idxs.end(), compare_strides); + std::vector transpose_idx(idxs.size()); + int transpose_counter = 0; + std::for_each(stride_idxs.begin(), stride_idxs.end(), [&](std::tuple& pair) { + transpose_idx[transpose_counter] = uint64_t(std::get<1>(pair)); + transpose_counter++; + }); + auto transpose_idx_const = + context.mark_node(v0::Constant::create(element::i32, Shape{transpose_idx.size()}, transpose_idx)); + auto transposed_input = context.mark_node(std::make_shared(input, transpose_idx_const)); + auto flat_input = context.mark_node(std::make_shared(transposed_input, const_neg_1, false)); + std::deque> sizes; + std::deque> strides; + if (std::dynamic_pointer_cast(context.get_input_from_visible_context(1).get_node_shared_ptr())) { + auto input_vector = context.const_input>(1); + std::for_each(input_vector.rbegin(), input_vector.rend(), [&](int64_t input_val) { + auto const_input = context.mark_node(v0::Constant::create(element::i32, Shape{}, {input_val})); + sizes.push_front(const_input); + }); + } else { + sizes = get_list_as_outputs(context.get_input(1)); + } + if (std::dynamic_pointer_cast(context.get_input_from_visible_context(2).get_node_shared_ptr())) { + auto input_vector = context.const_input>(2); + std::for_each(input_vector.rbegin(), input_vector.rend(), [&](int64_t input_val) { + auto const_input = context.mark_node(v0::Constant::create(element::i32, Shape{}, {input_val})); + strides.push_front(const_input); + }); + } else { + strides = get_list_as_outputs(context.get_input(2)); + } + auto offset = const_0->output(0); + if (!context.input_is_none(3)) { + offset = context.get_input(3); + } + FRONT_END_OP_CONVERSION_CHECK(sizes.size() == strides.size(), + "aten::as_strided: Vector for strides and sizes need to have equal length."); + auto strides_size = strides.size() - 1; + auto i = 0; + auto strides_length_const = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {strides.size()})); + auto ones_strides_len = context.mark_node(std::make_shared(const_1, strides_length_const)); + auto indices = const_0; + std::for_each(strides.rbegin(), strides.rend(), [&](Output& stride) { + auto const_num_iter = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {strides_size - i})); + stride = context.mark_node(std::make_shared(stride, element::i32)); + auto size = sizes.at(strides_size - i); + auto range = context.mark_node(std::make_shared(const_0, size, const_1, element::i32)); + range = context.mark_node(std::make_shared(range, stride)); + auto iteration_shape = context.mark_node( + std::make_shared(ones_strides_len, const_num_iter, const_neg_1, const_0)); + range = context.mark_node(std::make_shared(range, iteration_shape, false)); + indices = context.mark_node(std::make_shared(indices, range)); + i++; + }); + indices = context.mark_node(std::make_shared(indices, offset)); + auto gather = context.mark_node(std::make_shared(flat_input, indices, const_0)); + return {gather}; +}; +} // namespace op +} // namespace pytorch +} // namespace frontend +} // namespace ov diff --git a/src/frontends/pytorch/src/op/bitwise.cpp b/src/frontends/pytorch/src/op/bitwise.cpp index 6e3b1fe5f49ee4..8cbae192ca6bef 100644 --- a/src/frontends/pytorch/src/op/bitwise.cpp +++ b/src/frontends/pytorch/src/op/bitwise.cpp @@ -17,7 +17,7 @@ OutputVector translate_bitwise_not(const NodeContext& context) { num_inputs_check(context, 1, 2); auto x = context.get_input(0); FRONT_END_OP_CONVERSION_CHECK(x.get_element_type().compatible(element::boolean), - "aten::bitwise_not suppored only for boolean input"); + "aten::bitwise_not supported only for boolean input"); auto not_x = context.mark_node(std::make_shared(x)); if (!context.input_is_none(1)) { context.mutate_input(1, not_x); @@ -30,7 +30,7 @@ OutputVector translate_bitwise_and(const NodeContext& context) { auto x = context.get_input(0); auto y = context.get_input(1); FRONT_END_OP_CONVERSION_CHECK(x.get_element_type().compatible(element::boolean), - "aten::bitwise_not suppored only for boolean input"); + "aten::bitwise_not supported only for boolean input"); auto and_x = context.mark_node(std::make_shared(x, y)); return {and_x}; }; @@ -40,7 +40,7 @@ OutputVector translate_bitwise_or(const NodeContext& context) { auto x = context.get_input(0); auto y = context.get_input(1); FRONT_END_OP_CONVERSION_CHECK(x.get_element_type().compatible(element::boolean), - "aten::bitwise_not suppored only for boolean input"); + "aten::bitwise_not supported only for boolean input"); auto or_x = context.mark_node(std::make_shared(x, y)); return {or_x}; }; diff --git a/src/frontends/pytorch/src/op/div.cpp b/src/frontends/pytorch/src/op/div.cpp index 7fb12ec253413a..dbbb6c89af7e6c 100644 --- a/src/frontends/pytorch/src/op/div.cpp +++ b/src/frontends/pytorch/src/op/div.cpp @@ -17,7 +17,7 @@ namespace frontend { namespace pytorch { namespace op { -OutputVector translate_div(const NodeContext& context) { +OutputVector translate_div_common(const NodeContext& context, bool inplace) { num_inputs_check(context, 2, 3); auto x = context.get_input(0); auto y = context.get_input(1); @@ -34,7 +34,12 @@ OutputVector translate_div(const NodeContext& context) { y = context.mark_node(std::make_shared(y, element::f32)); } } - align_eltwise_input_types(context, x, y, true); + if (inplace) { + if (x.get_element_type().is_dynamic() || x.get_element_type() != y.get_element_type()) + y = context.mark_node(std::make_shared(x, y)); + } else { + align_eltwise_input_types(context, x, y, true); + } auto res = context.mark_node(std::make_shared(x, y, true)); // TODO: ticket 103296; Temporarily disable ConvertDivide transformation disable_divide_conversion(res); @@ -44,9 +49,19 @@ OutputVector translate_div(const NodeContext& context) { const auto convert = context.mark_node(std::make_shared(res, element::i32)); res = context.mark_node(std::make_shared(convert, x)); } + if (inplace) + context.mutate_input(0, res); return {res}; }; +OutputVector translate_div(const NodeContext& context) { + return translate_div_common(context, false); +}; + +OutputVector translate_div_(const NodeContext& context) { + return translate_div_common(context, true); +}; + } // namespace op } // namespace pytorch } // namespace frontend diff --git a/src/frontends/pytorch/src/op/erf.cpp b/src/frontends/pytorch/src/op/erf.cpp new file mode 100644 index 00000000000000..0525035bd43e24 --- /dev/null +++ b/src/frontends/pytorch/src/op/erf.cpp @@ -0,0 +1,37 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/op/erf.hpp" + +#include "openvino/frontend/pytorch/node_context.hpp" +#include "openvino/op/convert.hpp" +#include "utils.hpp" + +namespace ov { +namespace frontend { +namespace pytorch { +namespace op { + +OutputVector translate_erf(const NodeContext& context) { + // aten::erf(Tensor self) -> Tensor + // aten::erf.out(Tensor self, Tensor(!a) out) -> Tensor(!a) + num_inputs_check(context, 1, 2); + auto x = context.get_input(0); + auto xdtype = x.get_element_type(); + // in torch, erf return always float dtype, while ov cast to input dtype + if (xdtype.is_dynamic() || !xdtype.is_real()) { + x = context.mark_node(std::make_shared(x, element::f32)); + } + + auto y = context.mark_node(std::make_shared(x)); + if (!context.input_is_none(1)) { + context.mutate_input(1, y); + } + return {y}; +}; + +} // namespace op +} // namespace pytorch +} // namespace frontend +} // namespace ov \ No newline at end of file diff --git a/src/frontends/pytorch/src/op/full.cpp b/src/frontends/pytorch/src/op/full.cpp index cf60d096555007..e8bfa1c7ce99d7 100644 --- a/src/frontends/pytorch/src/op/full.cpp +++ b/src/frontends/pytorch/src/op/full.cpp @@ -3,10 +3,19 @@ // #include "openvino/frontend/pytorch/node_context.hpp" +#include "openvino/op/add.hpp" #include "openvino/op/broadcast.hpp" #include "openvino/op/constant.hpp" #include "openvino/op/convert_like.hpp" +#include "openvino/op/divide.hpp" +#include "openvino/op/gather.hpp" +#include "openvino/op/multiply.hpp" +#include "openvino/op/power.hpp" +#include "openvino/op/range.hpp" +#include "openvino/op/reshape.hpp" +#include "openvino/op/scatter_elements_update.hpp" #include "openvino/op/shape_of.hpp" +#include "openvino/op/squeeze.hpp" #include "utils.hpp" namespace ov { @@ -71,12 +80,17 @@ OutputVector translate_full_like(const NodeContext& context) { return {base_translate_full_with_convertlike(context, sizes, value, out)}; }; -OutputVector translate_fill_(const NodeContext& context) { - num_inputs_check(context, 2, 2); +OutputVector translate_fill(const NodeContext& context) { + num_inputs_check(context, 2, 3); auto input = context.get_input(0); auto value = context.get_input(1); auto sizes = context.mark_node(std::make_shared(input, element::i32)); - return {base_translate_full_with_convertlike(context, sizes, value, input)}; + auto out = context.input_is_none(2) ? input : context.get_input(2); + auto result = base_translate_full_with_convertlike(context, sizes, value, out); + if (!context.input_is_none(2)) { + context.mutate_input(2, result); + } + return {result}; }; OutputVector translate_new_full(const NodeContext& context) { @@ -187,6 +201,67 @@ OutputVector translate_empty(const NodeContext& context) { } return {empty}; }; + +OutputVector translate_fill_diagonal(const NodeContext& context) { + // aten::fill_diagonal_(Tensor(a!) self, Scalar fill_value, bool wrap=False) -> Tensor(a!) + // realization inspired by numpy: + // https://github.com/numpy/numpy/blob/c236e694d222ae6b812cb8dab54471bc4c912f0f/numpy/lib/_index_tricks_impl.py#L787-L918 + num_inputs_check(context, 3, 3); + auto input_tensor = context.get_input(0); + auto fill_value = context.get_input(1); + auto input_shape = context.mark_node(std::make_shared(input_tensor, element::i32)); + auto input_rank = input_tensor.get_partial_shape().rank(); + auto const_one = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {1})); + auto const_zero = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {0})); + auto const_one_s = context.mark_node(v0::Constant::create(element::i32, Shape{}, {1})); + auto const_zero_s = context.mark_node(v0::Constant::create(element::i32, Shape{}, {0})); + auto const_neg_one = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {-1})); + if (input_rank.is_dynamic() || input_rank.get_length() < 2) { + FRONT_END_OP_CONVERSION_CHECK(false, "aten::fill_diagonal_ required tensor with static rank >= 2 "); + } + auto flatten_input = context.mark_node(std::make_shared(input_tensor, const_neg_one, false)); + auto wrap = context.const_input(2); + Output step; + // default value for end - number of elements in input tensor + Output end; + auto flatten_shape = context.mark_node(std::make_shared(flatten_input, element::i32)); + end = context.mark_node(std::make_shared(flatten_shape, const_neg_one, const_zero)); + auto last_dim = context.mark_node(std::make_shared(input_shape, const_neg_one, const_zero)); + if (input_rank.get_length() == 2) { + // step = a.shape[1] + 1 + step = context.mark_node(std::make_shared(last_dim, const_one_s)); + if (!wrap) { + // if not wrap. and non squared matrix, do not fill tail by cutting end to square + end = context.mark_node(std::make_shared(last_dim, last_dim)); + } + } else { + // step = 1 + (cumprod(a.shape[:-1])).sum() + // cumprod operation is not supported by ov, but with condition that >2D tensors supported only if all dims + // equals cumprod can be represented as finite geometric serial and its sum can be found by formula + // b0 * (bn * q - 1) / (q - 1), where in this particual case q = b0, bn = b0 ^ n + auto rank_minus_one = + context.mark_node(v0::Constant::create(element::i32, Shape{}, {input_rank.get_length() - 1})); + auto dim_power = context.mark_node(std::make_shared(last_dim, rank_minus_one)); + auto dim_power_minus_one = context.mark_node(std::make_shared(dim_power, const_neg_one)); + auto dim_minus_one = context.mark_node(std::make_shared(last_dim, const_neg_one)); + auto q = context.mark_node(std::make_shared(dim_power_minus_one, dim_minus_one, true)); + auto cumprod_sum = context.mark_node(std::make_shared(last_dim, q)); + step = context.mark_node(std::make_shared(const_one_s, cumprod_sum)); + // wrap parameter is not applicable in this case as supported only equal dims on pytorch side + } + step = context.mark_node(std::make_shared(step, const_zero)); + end = context.mark_node(std::make_shared(end, const_zero)); + auto indices = context.mark_node(std::make_shared(const_zero_s, end, step, element::i32)); + auto indices_shape = context.mark_node(std::make_shared(indices, element::i32)); + fill_value = context.mark_node(std::make_shared(fill_value, input_tensor)); + fill_value = context.mark_node(std::make_shared(fill_value, indices_shape)); + // fill values + auto filled_tensor = + context.mark_node(std::make_shared(flatten_input, indices, fill_value, const_zero)); + // reshape back to original shape + filled_tensor = context.mark_node(std::make_shared(filled_tensor, input_shape, false)); + return {filled_tensor}; +} } // namespace op } // namespace pytorch } // namespace frontend diff --git a/src/frontends/pytorch/src/op/max_poolnd.cpp b/src/frontends/pytorch/src/op/max_poolnd.cpp index 0d685f03e16019..30bf1546ec87e8 100644 --- a/src/frontends/pytorch/src/op/max_poolnd.cpp +++ b/src/frontends/pytorch/src/op/max_poolnd.cpp @@ -100,8 +100,23 @@ OutputVector translate_max_poolnd(const NodeContext& context) { std::fill_n(pads.begin(), pads.size(), 0); } - return { - context.mark_node(std::make_shared(input, strides, dilations, pads, pads, kernel, rounding_type))}; + auto res = context.mark_node(std::make_shared(input, + strides, + dilations, + pads, + pads, + kernel, + rounding_type, + PadType::EXPLICIT, + element::i64, + 2)); + if (context.get_output_size() == 2) { + auto out1 = res->output(0); + auto out2 = res->output(1); + return {out1, out2}; + } else { + return {res}; + } }; OutputVector translate_max_poolnd_fx(const NodeContext& context) { diff --git a/src/frontends/pytorch/src/op/min_max.cpp b/src/frontends/pytorch/src/op/min_max.cpp index 670b4eca4d4e93..45b4f5f0155354 100644 --- a/src/frontends/pytorch/src/op/min_max.cpp +++ b/src/frontends/pytorch/src/op/min_max.cpp @@ -112,6 +112,36 @@ OutputVector translate_minimum(const NodeContext& context) { return {res}; } +OutputVector translate_amin(const NodeContext& context) { + // aten::amin(Tensor self, int[1] dim=[], bool keepdim=False) -> Tensor + + // aten::amin.out(Tensor self, int[1] dim=[], bool keepdim=False, *, Tensor(a!) out) -> Tensor(a!) + num_inputs_check(context, 3, 4); + auto x = context.get_input(0); + auto dims = context.get_input(1); + auto keep_dims = context.const_input(2); + auto res = context.mark_node(std::make_shared(x, dims, keep_dims)); + if (!context.input_is_none(3)) { + context.mutate_input(3, res); + } + return {res}; +} + +OutputVector translate_amax(const NodeContext& context) { + // aten::amax(Tensor self, int[1] dim=[], bool keepdim=False) -> Tensor + + // aten::amax.out(Tensor self, int[1] dim=[], bool keepdim=False, *, Tensor(a!) out) -> Tensor(a!) + num_inputs_check(context, 3, 4); + auto x = context.get_input(0); + auto dims = context.get_input(1); + auto keep_dims = context.const_input(2); + auto res = context.mark_node(std::make_shared(x, dims, keep_dims)); + if (!context.input_is_none(3)) { + context.mutate_input(3, res); + } + return {res}; +} + } // namespace op } // namespace pytorch } // namespace frontend diff --git a/src/frontends/pytorch/src/op/pixel_shuffle.cpp b/src/frontends/pytorch/src/op/pixel_shuffle.cpp index e2d3e8c6390c55..fc35b44d9a304a 100644 --- a/src/frontends/pytorch/src/op/pixel_shuffle.cpp +++ b/src/frontends/pytorch/src/op/pixel_shuffle.cpp @@ -6,6 +6,7 @@ #include "openvino/op/add.hpp" #include "openvino/op/concat.hpp" #include "openvino/op/constant.hpp" +#include "openvino/op/divide.hpp" #include "openvino/op/gather.hpp" #include "openvino/op/multiply.hpp" #include "openvino/op/range.hpp" @@ -15,6 +16,7 @@ #include "openvino/op/split.hpp" #include "openvino/op/squeeze.hpp" #include "openvino/op/transpose.hpp" +#include "openvino/op/unsqueeze.hpp" #include "utils.hpp" namespace ov { @@ -67,6 +69,74 @@ OutputVector translate_pixel_shuffle(const NodeContext& context) { return {context.mark_node(std::make_shared(transpose, shape_after, false))}; }; +OutputVector translate_pixel_unshuffle(const NodeContext& context) { + // aten::pixel_unshuffle(Tensor self, int upscale_factor) -> Tensor + num_inputs_check(context, 2, 2); + auto x = context.get_input(0); + auto upscale_factor = context.get_input(1); + auto neg_1 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {-1})); + auto neg_3 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {-3})); + auto zero = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {0})); + auto zero_s = context.mark_node(v0::Constant::create(element::i32, Shape{}, {0})); + auto one = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {1})); + auto one_s = context.mark_node(v0::Constant::create(element::i32, Shape{}, {1})); + Output shape; + Output rank; + std::tie(shape, rank) = get_shape_rank(context, x, true); + // 1. Reshape input to [-1, C, H / r, r, W / r, r], where r is upscale factor + auto indices = context.mark_node(v0::Constant::create(element::i32, Shape{3}, {-3, -2, -1})); + auto dims = context.mark_node(std::make_shared(shape, indices, zero_s)); + auto dims_splitted = context.mark_node(std::make_shared(dims, zero_s, 3)); + auto c = dims_splitted->output(0); + auto h = dims_splitted->output(1); + auto w = dims_splitted->output(2); + auto dims_before = context.mark_node(std::make_shared(shape, zero, neg_3, one)); + auto r = context.mark_node(std::make_shared(upscale_factor, zero)); + auto new_h = context.mark_node(std::make_shared(h, upscale_factor, true)); + auto new_w = context.mark_node(std::make_shared(w, upscale_factor, true)); + auto intermediate_shape = + context.mark_node(std::make_shared(OutputVector{neg_1, c, new_h, r, new_w, r}, 0)); + auto x_reshaped = context.mark_node(std::make_shared(x, intermediate_shape, false)); + // 2. Transpose to [-1, C, r, r, H / r, W / r] + auto transpose_order = context.mark_node(v0::Constant::create(element::i32, Shape{6}, {0, 1, 3, 5, 2, 4})); + auto x_transposed = context.mark_node(std::make_shared(x_reshaped, transpose_order)); + // 3. Reshape to [*, C*r*r, H / r, W / r] + auto r_sqr = context.mark_node(std::make_shared(r, r)); + auto new_c = context.mark_node(std::make_shared(c, r_sqr)); + auto final_shape = + context.mark_node(std::make_shared(OutputVector{dims_before, new_c, new_h, new_w}, 0)); + return {context.mark_node(std::make_shared(x_transposed, final_shape, false))}; +}; + +OutputVector translate_channel_shuffle(const NodeContext& context) { + // aten::channel_shuffle(Tensor self, int groups) -> Tensor + num_inputs_check(context, 2, 2); + auto x = context.get_input(0); + auto groups = context.get_input(1); + auto neg_1 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {-1})); + auto zero = context.mark_node(v0::Constant::create(element::i32, Shape{}, {0})); + auto one = context.mark_node(v0::Constant::create(element::i32, Shape{}, {1})); + auto shape = context.mark_node(std::make_shared(x, element::i32)); + // PyTorch realization uses assumption that channels dim is always 1 + auto indices = context.mark_node(v0::Constant::create(element::i32, Shape{2}, {0, 1})); + auto dims = context.mark_node(std::make_shared(shape, indices, zero)); + auto dims_splitted = context.mark_node(std::make_shared(dims, zero, 2)); + auto c = dims_splitted->output(1); + auto n = dims_splitted->output(0); + groups = context.mark_node(std::make_shared(groups, element::i32)); + auto k = context.mark_node(std::make_shared(c, groups, true)); + auto g = context.mark_node(std::make_shared(groups, zero)); + // 1. Reshape input [N, G, K=C/G, -1] + auto reshape_indices = context.mark_node(std::make_shared(OutputVector{n, g, k, neg_1}, 0)); + x = context.mark_node(std::make_shared(x, reshape_indices, false)); + // 2. Transpose to [N, K, G, -1] + auto permute_indices = context.mark_node(v0::Constant::create(element::i32, Shape{4}, {0, 2, 1, 3})); + auto y = context.mark_node(std::make_shared(x, permute_indices)); + // 3. Reshape back to original shape + auto result = context.mark_node(std::make_shared(y, shape, false)); + return {result}; +}; + } // namespace op } // namespace pytorch } // namespace frontend diff --git a/src/frontends/pytorch/src/op/scaled_dot_product_attention.cpp b/src/frontends/pytorch/src/op/scaled_dot_product_attention.cpp index 735324405d1f11..82231472e401be 100644 --- a/src/frontends/pytorch/src/op/scaled_dot_product_attention.cpp +++ b/src/frontends/pytorch/src/op/scaled_dot_product_attention.cpp @@ -15,6 +15,7 @@ #include "openvino/op/matmul.hpp" #include "openvino/op/multiply.hpp" #include "openvino/op/range.hpp" +#include "openvino/op/reshape.hpp" #include "openvino/op/select.hpp" #include "openvino/op/shape_of.hpp" #include "openvino/op/softmax.hpp" @@ -22,6 +23,7 @@ #include "openvino/op/squeeze.hpp" #include "openvino/op/transpose.hpp" #include "openvino/op/unsqueeze.hpp" +#include "openvino/op/util/framework_node.hpp" #include "utils.hpp" namespace ov { @@ -31,10 +33,7 @@ namespace op { using namespace ov::op; -OutputVector translate_scaled_dot_product_attention(const NodeContext& context) { - // aten::scaled_dot_product_attention(Tensor query, Tensor key, Tensor value, Tensor? attn_mask=None, float - // dropout_p=0., bool is_causal=False) - num_inputs_check(context, 6, 6); +std::shared_ptr translate_scaled_dot_product_attention_common(const NodeContext& context) { auto query = context.get_input(0); auto key = context.get_input(1); auto value = context.get_input(2); @@ -68,7 +67,10 @@ OutputVector translate_scaled_dot_product_attention(const NodeContext& context) minus_inf = context.mark_node(std::make_shared(minus_inf, scaled_atten)); // two types of masks are supported. A boolean mask where a value of True indicates that the element should take // part in attention. A float mask of the same type as query, key, value that is added to the attention score. - auto is_causal = context.const_input(5); + auto is_causal = false; + if (!context.input_is_none(5)) { + is_causal = context.const_input(5); + } if (is_causal || !context.input_is_none(3)) { Output mask; Output atten_mask; @@ -100,10 +102,30 @@ OutputVector translate_scaled_dot_product_attention(const NodeContext& context) scaled_atten = context.mark_node(std::make_shared(scaled_atten, atten_mask)); } scaled_atten = context.mark_node(std::make_shared(scaled_atten, -1)); - return {context.mark_node(std::make_shared(scaled_atten, value))}; + return context.mark_node(std::make_shared(scaled_atten, value)); +}; + +OutputVector translate_scaled_dot_product_attention(const NodeContext& context) { + // aten::scaled_dot_product_attention(Tensor query, Tensor key, Tensor value, Tensor? attn_mask=None, float + // dropout_p=0., bool is_causal=False) + num_inputs_check(context, 6, 6); + return {translate_scaled_dot_product_attention_common(context)}; +}; + +OutputVector translate_scaled_dot_product_attention_fx(const NodeContext& context) { + // aten::scaled_dot_product_attention(Tensor query, Tensor key, Tensor value, Tensor? attn_mask=None, float + // dropout_p=0., bool is_causal=False) + num_inputs_check(context, 3, 6); + auto output = translate_scaled_dot_product_attention_common(context); + // TODO: scaled_dot_product_flash_attention has 9 outputs but for most cases only + // the first input is used. Rest of the outputs should be returned properly as + // needed. + ov::OutputVector out_vec; + out_vec.push_back(output); + return {context.mark_node(make_list_construct(out_vec))}; }; } // namespace op } // namespace pytorch } // namespace frontend -} // namespace ov \ No newline at end of file +} // namespace ov diff --git a/src/frontends/pytorch/src/op/sub.cpp b/src/frontends/pytorch/src/op/sub.cpp index 94963ed9bdb61f..62534aee53864b 100644 --- a/src/frontends/pytorch/src/op/sub.cpp +++ b/src/frontends/pytorch/src/op/sub.cpp @@ -15,18 +15,34 @@ namespace op { using namespace ov::op; -OutputVector translate_sub(const NodeContext& context) { +OutputVector translate_sub_common(const NodeContext& context, bool inplace) { num_inputs_check(context, 2, 3); auto x = context.get_input(0); auto y = context.get_input(1); - align_eltwise_input_types(context, x, y); + if (inplace) { + if (x.get_element_type().is_dynamic() || x.get_element_type() != y.get_element_type()) + y = context.mark_node(std::make_shared(x, y)); + } else { + align_eltwise_input_types(context, x, y); + } // default alpha is 1 so no need to multiply if alpha is not provided if (!context.input_is_none(2)) { auto alpha = context.get_input(2); auto casted_alpha = context.mark_node(std::make_shared(alpha, y)); y = context.mark_node(std::make_shared(casted_alpha, y)); } - return {context.mark_node(std::make_shared(x, y))}; + auto sub = context.mark_node(std::make_shared(x, y)); + if (inplace) + context.mutate_input(0, sub); + return {sub}; +}; + +OutputVector translate_sub(const NodeContext& context) { + return translate_sub_common(context, false); +}; + +OutputVector translate_sub_(const NodeContext& context) { + return translate_sub_common(context, true); }; } // namespace op diff --git a/src/frontends/pytorch/src/op_table.cpp b/src/frontends/pytorch/src/op_table.cpp index 41a790d1ef2079..c307be6fc22e2c 100644 --- a/src/frontends/pytorch/src/op_table.cpp +++ b/src/frontends/pytorch/src/op_table.cpp @@ -17,17 +17,25 @@ namespace op { // TorchScript translations OP_CONVERTER(translate_adaptive_avg_pool3d); +OP_CONVERTER(translate_adaptive_avg_pool2d); +OP_CONVERTER(translate_adaptive_avg_pool1d); +OP_CONVERTER(translate_adaptive_max_pool3d); OP_CONVERTER(translate_adaptive_max_pool2d); +OP_CONVERTER(translate_adaptive_max_pool1d); OP_CONVERTER(translate_add); +OP_CONVERTER(translate_add_); OP_CONVERTER(translate_addcmul); OP_CONVERTER(translate_addmm); OP_CONVERTER(translate_all); +OP_CONVERTER(translate_amax); +OP_CONVERTER(translate_amin); OP_CONVERTER(translate_and); OP_CONVERTER(translate_arange); OP_CONVERTER(translate_argmax); OP_CONVERTER(translate_argsort); OP_CONVERTER(translate_argmax); OP_CONVERTER(translate_argmin); +OP_CONVERTER(translate_as_strided); OP_CONVERTER(translate_as_tensor); OP_CONVERTER(translate_avg_poolnd); OP_CONVERTER(translate_bool); @@ -37,6 +45,7 @@ OP_CONVERTER(translate_bitwise_not); OP_CONVERTER(translate_bitwise_or); OP_CONVERTER(translate_cat); OP_CONVERTER(translate_cdist); +OP_CONVERTER(translate_channel_shuffle); OP_CONVERTER(translate_clamp); OP_CONVERTER(translate_constant); OP_CONVERTER(translate_conv_transposend); @@ -49,16 +58,19 @@ OP_CONVERTER(translate_deform_conv); OP_CONVERTER(translate_derive_index); OP_CONVERTER(translate_dim); OP_CONVERTER(translate_div); +OP_CONVERTER(translate_div_); OP_CONVERTER(translate_elu); OP_CONVERTER(translate_embedding); OP_CONVERTER(translate_embedding_bag); OP_CONVERTER(translate_empty); +OP_CONVERTER(translate_erf); OP_CONVERTER(translate_expand); OP_CONVERTER(translate_expand_as); OP_CONVERTER(translate_eye); OP_CONVERTER(translate_fake_quantize_per_channel_affine); OP_CONVERTER(translate_fake_quantize_per_tensor_affine); -OP_CONVERTER(translate_fill_); +OP_CONVERTER(translate_fill); +OP_CONVERTER(translate_fill_diagonal); OP_CONVERTER(translate_flatten); OP_CONVERTER(translate_flip); OP_CONVERTER(translate_floor_divide); @@ -122,6 +134,7 @@ OP_CONVERTER(translate_outer); OP_CONVERTER(translate_pad); OP_CONVERTER(translate_pairwise_distance); OP_CONVERTER(translate_pixel_shuffle); +OP_CONVERTER(translate_pixel_unshuffle); OP_CONVERTER(translate_pow); OP_CONVERTER(translate_pythonop); OP_CONVERTER(translate_quantize_per_channel); @@ -164,6 +177,7 @@ OP_CONVERTER(translate_squeeze); OP_CONVERTER(translate_std); OP_CONVERTER(translate_std_mean); OP_CONVERTER(translate_sub); +OP_CONVERTER(translate_sub_); OP_CONVERTER(translate_sum); OP_CONVERTER(translate_t); OP_CONVERTER(translate_to); @@ -203,6 +217,7 @@ OP_CONVERTER(translate_group_norm_fx); OP_CONVERTER(translate_index_fx); OP_CONVERTER(translate_layer_norm_fx); OP_CONVERTER(translate_max_poolnd_fx); +OP_CONVERTER(translate_scaled_dot_product_attention_fx); OP_CONVERTER(translate_slice_fx); OP_CONVERTER(translate_softmax_fx); OP_CONVERTER(translate_transpose_fx); @@ -228,18 +243,24 @@ const std::map get_supported_ops_ts() { {"aten::acos_", op::inplace_op>}, {"aten::acosh", op::translate_1to1_match_1_inputs_with_fp32_type_alignment}, {"aten::acosh_", op::inplace_op>}, - {"aten::adaptive_avg_pool2d", op::quantizable_op>}, + {"aten::adaptive_avg_pool1d", op::quantizable_op}, + {"aten::adaptive_avg_pool2d", op::quantizable_op}, {"aten::adaptive_avg_pool3d", op::quantizable_op}, + {"aten::adaptive_max_pool1d", op::quantizable_op}, {"aten::adaptive_max_pool2d", op::quantizable_op}, + {"aten::adaptive_max_pool3d", op::quantizable_op}, {"aten::add", op::translate_add}, - {"aten::add_", op::inplace_op}, + {"aten::add_", op::translate_add_}, {"aten::addcmul", op::translate_addcmul}, {"aten::addmm", op::translate_addmm}, {"aten::all", op::translate_all}, + {"aten::amax", op::translate_amax}, + {"aten::amin", op::translate_amin}, {"aten::arange", op::translate_arange}, {"aten::argmax", op::translate_argmax}, {"aten::argmin", op::translate_argmin}, {"aten::argsort", op::translate_argsort}, + {"aten::as_strided", op::translate_as_strided}, {"aten::as_tensor", op::translate_as_tensor}, {"aten::asin", op::translate_1to1_match_1_inputs_with_fp32_type_alignment}, {"aten::asin_", op::inplace_op>}, @@ -263,9 +284,13 @@ const std::map get_supported_ops_ts() { {"aten::cdist", op::translate_cdist}, {"aten::ceil", op::translate_1to1_match_1_inputs}, {"aten::ceil_", op::inplace_op>}, + {"aten::channel_shuffle", op::translate_channel_shuffle}, {"aten::clamp", op::translate_clamp}, + {"aten::clamp_", op::inplace_op}, {"aten::clamp_max", op::translate_1to1_match_2_inputs}, {"aten::clamp_min", op::translate_1to1_match_2_inputs}, + {"aten::clip", op::translate_clamp}, + {"aten::clip_", op::inplace_op}, {"aten::clone", op::skip_node}, // ignore clone operators that are inserted by PyTorch autograd {"aten::contiguous", op::skip_node}, // In openvino how tensors are stored in memory is internal plugin detail, // we assume all tensors are contiguous @@ -287,7 +312,7 @@ const std::map get_supported_ops_ts() { {"aten::dequantize", op::skip_node}, // we convert model to fp32 using FQ, so dequantization is not needed {"aten::dim", op::translate_dim}, {"aten::div", op::translate_div}, - {"aten::div_", op::inplace_op}, + {"aten::div_", op::translate_div_}, {"aten::dropout", op::skip_node}, {"aten::dropout_", op::skip_node}, {"aten::elu", op::translate_elu}, @@ -295,6 +320,8 @@ const std::map get_supported_ops_ts() { {"aten::embedding_bag", op::translate_embedding_bag}, {"aten::empty", op::translate_empty}, {"aten::eq", op::translate_1to1_match_2_inputs_align_types}, + {"aten::erf", op::translate_erf}, + {"aten::erf_", op::inplace_op}, {"aten::exp", op::translate_1to1_match_1_inputs_with_fp32_type_alignment}, {"aten::exp_", op::inplace_op>}, {"aten::expand", op::translate_expand}, @@ -303,7 +330,9 @@ const std::map get_supported_ops_ts() { {"aten::fake_quantize_per_channel_affine", op::translate_fake_quantize_per_channel_affine}, {"aten::fake_quantize_per_tensor_affine", op::translate_fake_quantize_per_tensor_affine}, {"aten::feature_dropout", op::skip_node}, - {"aten::fill_", op::inplace_op}, + {"aten::fill", op::translate_fill}, + {"aten::fill_", op::inplace_op}, + {"aten::fill_diagonal_", op::inplace_op}, {"aten::flatten", op::quantizable_op}, {"aten::flip", op::translate_flip}, {"aten::floor", op::translate_1to1_match_1_inputs}, @@ -367,17 +396,20 @@ const std::map get_supported_ops_ts() { {"aten::max", op::translate_max}, {"aten::maximum", op::translate_maximum}, {"aten::max_pool1d", op::quantizable_op}, + {"aten::max_pool1d_with_indices", op::quantizable_op}, {"aten::max_pool2d", op::quantizable_op}, + {"aten::max_pool2d_with_indices", op::quantizable_op}, {"aten::max_pool3d", op::quantizable_op}, + {"aten::max_pool3d_with_indices", op::quantizable_op}, {"aten::mean", op::quantizable_op}, {"aten::meshgrid", op::translate_meshgrid}, {"aten::min", op::translate_min}, {"aten::minimum", op::translate_minimum}, {"aten::mm", op::translate_1to1_match_2_inputs}, {"aten::mul", op::translate_1to1_match_2_inputs_align_types}, - {"aten::mul_", op::inplace_op>}, + {"aten::mul_", op::inplace_translate_1to1_match_2_inputs_align_types}, {"aten::multiply", op::translate_1to1_match_2_inputs_align_types}, - {"aten::multiply_", op::inplace_op>}, + {"aten::multiply_", op::inplace_translate_1to1_match_2_inputs_align_types}, {"aten::narrow", op::translate_narrow}, {"aten::ne", op::translate_1to1_match_2_inputs_align_types}, {"aten::neg", op::translate_neg}, @@ -397,6 +429,7 @@ const std::map get_supported_ops_ts() { {"aten::pairwise_distance", op::translate_pairwise_distance}, {"aten::permute", op::translate_1to1_match_2_inputs}, {"aten::pixel_shuffle", op::translate_pixel_shuffle}, + {"aten::pixel_unshuffle", op::translate_pixel_unshuffle}, {"aten::prelu", op::translate_1to1_match_2_inputs}, {"aten::pow", op::translate_pow}, {"aten::quantize_per_channel", op::translate_quantize_per_channel}, @@ -447,7 +480,7 @@ const std::map get_supported_ops_ts() { {"aten::std", op::translate_std}, {"aten::std_mean", op::translate_std_mean}, {"aten::sub", op::translate_sub}, - {"aten::sub_", op::inplace_op}, + {"aten::sub_", op::translate_sub_}, {"aten::sum", op::translate_sum}, {"aten::swapaxes", op::quantizable_op}, {"aten::t", op::translate_t}, @@ -528,6 +561,7 @@ const std::map get_supported_ops_fx() { {"aten.arange.default", op::translate_arange_fx}, {"aten.argmax.default", op::translate_argmax}, {"aten.avg_pool2d.default", op::translate_avg_poolnd}, + {"aten.baddbmm.default", op::translate_addmm}, {"aten.bitwise_and.Tensor", op::translate_bitwise_and}, {"aten.bmm.default", op::translate_1to1_match_2_inputs_align_types}, {"aten.cat.default", op::translate_cat_fx}, @@ -554,6 +588,7 @@ const std::map get_supported_ops_fx() { {"aten.hardswish_.default", op::inplace_op>}, {"aten.hardtanh_.default", op::inplace_op}, {"aten.index.Tensor", op::translate_index_fx}, + {"aten.leaky_relu_.default", op::inplace_op>}, {"aten.lift_fresh_copy.default", op::skip_node}, {"aten.linalg_vector_norm.default", op::translate_linalg_vector_norm}, {"aten.log.default", op::translate_log}, @@ -576,6 +611,7 @@ const std::map get_supported_ops_fx() { {"aten.relu.default", op::translate_1to1_match_1_inputs}, {"aten.relu_.default", op::inplace_op>}, {"aten.rsub.Scalar", op::translate_rsub}, + {"aten._scaled_dot_product_flash_attention.default", op::translate_scaled_dot_product_attention_fx}, {"aten.select.int", op::translate_select}, {"aten.sigmoid.default", op::translate_1to1_match_1_inputs}, {"aten.silu.default", op::translate_1to1_match_1_inputs}, diff --git a/src/frontends/pytorch/src/pt_framework_node.hpp b/src/frontends/pytorch/src/pt_framework_node.hpp index 04b71d1169ae81..00d967200405cb 100644 --- a/src/frontends/pytorch/src/pt_framework_node.hpp +++ b/src/frontends/pytorch/src/pt_framework_node.hpp @@ -20,14 +20,17 @@ class PtFrameworkNode : public ov::op::util::FrameworkNode { PtFrameworkNode(const std::shared_ptr& decoder, const OutputVector& inputs, size_t output_size, - bool is_backprop = false) + bool is_reverseprop = false) : ov::op::util::FrameworkNode(inputs, output_size, decoder->get_subgraph_size()), m_decoder(decoder) { ov::op::util::FrameworkNodeAttrs attrs; attrs.set_type_name("PTFrameworkNode"); - if (is_backprop) { - attrs[op_type_key] = m_decoder->get_op_type() + "_backprop"; + if (is_reverseprop) { + attrs[op_type_key] = m_decoder->get_op_type() + "_reverseprop"; attrs[schema_key] = "None"; + attrs[failed_conversion_key] = + "This is an internal openvino operation representing reverse data propagation. It should not appear in " + "graph in normal conversion flow and might be result of other failures."; } else { attrs[op_type_key] = m_decoder->get_op_type(); attrs[schema_key] = m_decoder->get_schema(); diff --git a/src/frontends/pytorch/src/transforms/align_types_removal.cpp b/src/frontends/pytorch/src/transforms/align_types_removal.cpp new file mode 100644 index 00000000000000..c5e43d8af13004 --- /dev/null +++ b/src/frontends/pytorch/src/transforms/align_types_removal.cpp @@ -0,0 +1,60 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "align_types_removal.hpp" + +#include +#include + +#include "helper_ops/align_types.hpp" +#include "openvino/core/rt_info.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/split.hpp" +#include "openvino/op/squeeze.hpp" +#include "openvino/op/util/framework_node.hpp" +#include "openvino/pass/pattern/matcher.hpp" +#include "openvino/pass/pattern/op/wrap_type.hpp" +#include "utils.hpp" + +namespace ov { +namespace frontend { +namespace pytorch { +namespace pass { + +using namespace ov::op; + +AlignTypesRemoval::AlignTypesRemoval() { + auto align_types_pattern = ov::pass::pattern::wrap_type(); + + ov::matcher_pass_callback callback = [](ov::pass::pattern::Matcher& m) { + auto align_types = std::dynamic_pointer_cast(m.get_match_root()); + if (!align_types) + return false; + auto lhs_itype = align_types->get_input_element_type(0); + auto rhs_itype = align_types->get_input_element_type(1); + auto lhs_otype = align_types->get_output_element_type(0); + auto rhs_otype = align_types->get_output_element_type(1); + if (lhs_otype.is_static() && rhs_otype.is_static()) { + auto out1 = align_types->input_value(0); + auto out2 = align_types->input_value(1); + if (lhs_itype != lhs_otype) + out1 = std::make_shared(align_types->input_value(0), lhs_otype); + if (rhs_itype != rhs_otype) + out2 = std::make_shared(align_types->input_value(1), rhs_otype); + align_types->output(0).replace(out1); + align_types->output(1).replace(out2); + return true; + } + return false; + }; + + auto m = std::make_shared(align_types_pattern, + "ov::frontend::pytorch::pass::AlignTypesRemoval"); + this->register_matcher(m, callback); +}; + +} // namespace pass +} // namespace pytorch +} // namespace frontend +} // namespace ov diff --git a/src/frontends/pytorch/src/transforms/align_types_removal.hpp b/src/frontends/pytorch/src/transforms/align_types_removal.hpp new file mode 100644 index 00000000000000..bba81df9e0e086 --- /dev/null +++ b/src/frontends/pytorch/src/transforms/align_types_removal.hpp @@ -0,0 +1,24 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/pass/graph_rewrite.hpp" +#include "openvino/pass/pass.hpp" + +namespace ov { +namespace frontend { +namespace pytorch { +namespace pass { + +class AlignTypesRemoval : public ov::pass::MatcherPass { +public: + OPENVINO_RTTI("ov::frontend::pytorch::pass::AlignTypesRemoval"); + AlignTypesRemoval(); +}; + +} // namespace pass +} // namespace pytorch +} // namespace frontend +} // namespace ov diff --git a/src/frontends/pytorch/src/transforms/aten_stack_list_construct_replacer.cpp b/src/frontends/pytorch/src/transforms/aten_stack_list_construct_replacer.cpp index f8de5275b69ae8..67ea5f4f9e1ff9 100644 --- a/src/frontends/pytorch/src/transforms/aten_stack_list_construct_replacer.cpp +++ b/src/frontends/pytorch/src/transforms/aten_stack_list_construct_replacer.cpp @@ -12,6 +12,7 @@ #include "openvino/pass/pattern/matcher.hpp" #include "openvino/pass/pattern/op/wrap_type.hpp" #include "utils.hpp" +#include "utils_quantize.hpp" namespace ov { namespace frontend { @@ -38,22 +39,31 @@ AtenStackListConstructReplacer::AtenStackListConstructReplacer() { auto axis_node = pattern_map.at(axis).get_node_shared_ptr(); auto axis_const = std::dynamic_pointer_cast(axis_node); auto axis = axis_const->cast_vector(); + if (axis.size() != 1) { + add_exception_to_fw_node(stack, "aten::stack has multiple axes, only one is supported."); + return false; + } // Check if ListConstruct is an input if (auto list_construct_node = cast_fw_node(input_node, "prim::ListConstruct")) { const auto& list_inputs = list_construct_node->input_values(); - OutputVector node_vector; - auto zero = v0::Constant::create(element::i32, Shape{}, {0}); - // Iterate over values in ListConstruct - for (const auto& list_input : list_inputs) { - auto node = concat_list_construct(list_input); - auto unsqueezed_node = std::make_shared(node, axis_const); - node_vector.push_back(unsqueezed_node); + std::shared_ptr node; + if (auto compression = u4_compression_stack(list_inputs, axis[0])) { + node = compression; + } else { + OutputVector node_vector; + auto zero = v0::Constant::create(element::i32, Shape{}, {0}); + // Iterate over values in ListConstruct + for (const auto& list_input : list_inputs) { + auto node = concat_list_construct(list_input); + auto unsqueezed_node = std::make_shared(node, axis_const); + node_vector.push_back(unsqueezed_node); + } + // Concat vectors on provided axis + node = std::make_shared(node_vector, axis[0]); } - // Concat vectors on provided axis - auto concat = std::make_shared(node_vector, axis[0]); - copy_runtime_info_and_name(stack, {concat}, {input_node}); - replace_node(stack, concat); + copy_runtime_info_and_name(stack, {node}, {input_node}); + replace_node(stack, node); return true; } add_exception_to_fw_node(stack, "Unsupported case of aten::stack."); diff --git a/src/frontends/pytorch/src/transforms/prim_list_construct_pad.cpp b/src/frontends/pytorch/src/transforms/prim_list_construct_pad.cpp index 2147ddc17d9c84..74b4e8cc03bb4e 100644 --- a/src/frontends/pytorch/src/transforms/prim_list_construct_pad.cpp +++ b/src/frontends/pytorch/src/transforms/prim_list_construct_pad.cpp @@ -71,13 +71,19 @@ PrimListConstructPadReplacer::PrimListConstructPadReplacer() { input_node = pad_op->input_value(0); padding = pad_op->input_value(1); auto mode_node = pad_op->input_value(2).get_node_shared_ptr(); - pad_value = pad_op->input_value(3); if (const auto& fw_node_mode = cast_fw_node(mode_node, "prim::Constant")) { const auto& attrs = fw_node_mode->get_attrs(); if (attrs.find("string_value") != attrs.end()) { mode = attrs.at("string_value"); } } + pad_value = pad_op->input_value(3); + if (const auto& fw_node_mode = cast_fw_node(pad_value.get_node_shared_ptr(), "prim::Constant")) { + const auto& attrs = fw_node_mode->get_attrs(); + if (attrs.find("none_value") != attrs.end()) { + pad_value = v0::Constant::create(element::f32, Shape{}, {0}); + } + } } else if ((pad_op = cast_fw_node(m.get_match_root(), "aten::reflection_pad2d"))) { mode = "reflect"; input_node = pad_op->input_value(0); diff --git a/src/frontends/pytorch/src/transforms/string_equality_replacer.cpp b/src/frontends/pytorch/src/transforms/string_equality_replacer.cpp index 0219600799a3c0..f7e5e80b604a76 100644 --- a/src/frontends/pytorch/src/transforms/string_equality_replacer.cpp +++ b/src/frontends/pytorch/src/transforms/string_equality_replacer.cpp @@ -26,16 +26,8 @@ using namespace ov::op; StringEqualityReplacer::StringEqualityReplacer() { auto framework_node_lhs = pattern::wrap_type(); auto framework_node_rhs = pattern::wrap_type(); - auto convert_lhs = pattern::wrap_type({framework_node_lhs}); - auto convert_like_lhs = pattern::wrap_type({framework_node_lhs, framework_node_rhs}); - auto convert_rhs = pattern::wrap_type({framework_node_rhs}); - auto convert_like_rhs = pattern::wrap_type({framework_node_rhs, framework_node_lhs}); - auto lhs_pattern = - std::make_shared(OutputVector{framework_node_lhs, convert_lhs, convert_like_lhs}); - auto rhs_pattern = - std::make_shared(OutputVector{framework_node_rhs, convert_rhs, convert_like_rhs}); - auto equal_op = pattern::wrap_type({lhs_pattern, rhs_pattern}); - auto not_equal_op = pattern::wrap_type({lhs_pattern, rhs_pattern}); + auto equal_op = pattern::wrap_type({framework_node_lhs, framework_node_rhs}); + auto not_equal_op = pattern::wrap_type({framework_node_lhs, framework_node_rhs}); auto string_equality_pattern = std::make_shared(OutputVector{equal_op, not_equal_op}); diff --git a/src/frontends/pytorch/src/transforms/u4_block_repack.cpp b/src/frontends/pytorch/src/transforms/u4_block_repack.cpp new file mode 100644 index 00000000000000..e08ebd728b050e --- /dev/null +++ b/src/frontends/pytorch/src/transforms/u4_block_repack.cpp @@ -0,0 +1,98 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "u4_block_repack.hpp" + +#include "openvino/core/rt_info.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/reshape.hpp" +#include "openvino/op/transpose.hpp" +#include "openvino/pass/pattern/matcher.hpp" +#include "openvino/pass/pattern/op/wrap_type.hpp" +#include "utils.hpp" +#include "utils_quantize.hpp" + +namespace ov { +namespace frontend { +namespace pytorch { +namespace pass { + +using namespace ov::op; +using namespace ov::pass::pattern; + +U4BlockRepack::U4BlockRepack() { + const auto m_constant = ov::pass::pattern::wrap_type(); + const auto m_reshape1 = ov::pass::pattern::wrap_type({m_constant, any_input()}); + const auto m_transpose = ov::pass::pattern::wrap_type({m_reshape1, any_input()}); + const auto m_reshape2 = ov::pass::pattern::wrap_type({m_transpose, any_input()}); + + auto pack_byte = [](uint8_t lo, uint8_t hi) { + return (hi << 4) | (lo & 0x0F); + }; // swap halfs because Convert op assumes this layout + + auto get_u4 = [](const uint8_t* src, size_t idx) { + const size_t byte_idx = idx / 2; + const uint8_t bit_shift = 4 * (idx % 2); + return (src[byte_idx] >> bit_shift) & 0xF; + }; + + register_matcher( + std::make_shared(m_reshape2, "ov::frontend::pytorch::pass::U4BlockRepack"), + [=](ov::pass::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); + auto constant = + std::dynamic_pointer_cast(pattern_to_output[m_constant].get_node_shared_ptr()); + if (!constant) + return false; + auto reshape1 = pattern_to_output[m_reshape1].get_node_shared_ptr(); + auto transpose = pattern_to_output[m_transpose].get_node_shared_ptr(); + auto reshape2 = pattern_to_output[m_reshape2].get_node_shared_ptr(); + + if (constant->get_element_type() != element::u4) + return false; + + // FIXME: Check reshape/transpose/reshape target shapes and axes permutation; now they are supposed to be + // always in expected form + + auto source_shape = reshape1->get_output_shape(0); + + if (source_shape.size() != 3) + return false; + + auto destination_shape = reshape2->get_output_shape(0); + + size_t n_blocks = source_shape[0]; + size_t block_height = source_shape[1]; + size_t lane_size = source_shape[2]; // size in u4 units + size_t block_size = block_height * lane_size / 2; // size in bytes + + auto src = constant->get_data_ptr(); + + auto new_const = std::make_shared(element::u4, destination_shape); + auto dst = const_cast( // const_cast? + reinterpret_cast(new_const->get_data_ptr())); // TODO: How to better accees u4 data? + + for (size_t iblock = 0; iblock < n_blocks; ++iblock) { + auto src_block = src + iblock * block_size; + auto dst_block = dst + iblock * block_size; + for (size_t i = 0; i < lane_size; ++i) { + for (size_t j = 0; j < block_height / 2; ++j) { // /2 because we handle two bytes at once + uint8_t lo = get_u4(src_block, 2 * j * lane_size + i); + uint8_t hi = get_u4(src_block, (2 * j + 1) * lane_size + i); + dst_block[i * block_height / 2 + j] = pack_byte(lo, hi); + } + } + } + + copy_runtime_info(NodeVector{constant, reshape1, transpose, reshape2}, new_const); + replace_node(reshape2, new_const); + + return true; + }); +}; + +} // namespace pass +} // namespace pytorch +} // namespace frontend +} // namespace ov diff --git a/src/frontends/pytorch/src/transforms/u4_block_repack.hpp b/src/frontends/pytorch/src/transforms/u4_block_repack.hpp new file mode 100644 index 00000000000000..aa6e00f70e564c --- /dev/null +++ b/src/frontends/pytorch/src/transforms/u4_block_repack.hpp @@ -0,0 +1,24 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/pass/graph_rewrite.hpp" +#include "openvino/pass/pass.hpp" + +namespace ov { +namespace frontend { +namespace pytorch { +namespace pass { + +class U4BlockRepack : public ov::pass::MatcherPass { +public: + OPENVINO_RTTI("ov::frontend::pytorch::pass::U4BlockRepack"); + U4BlockRepack(); +}; + +} // namespace pass +} // namespace pytorch +} // namespace frontend +} // namespace ov diff --git a/src/frontends/pytorch/src/utils.cpp b/src/frontends/pytorch/src/utils.cpp index afd9b5ebf85216..7decae35b30bbb 100644 --- a/src/frontends/pytorch/src/utils.cpp +++ b/src/frontends/pytorch/src/utils.cpp @@ -4,6 +4,7 @@ #include "utils.hpp" +#include "helper_ops/align_types.hpp" #include "op_table.hpp" #include "openvino/core/rt_info.hpp" #include "openvino/frontend/pytorch/decoder.hpp" @@ -381,33 +382,17 @@ std::unordered_map bit_to_int{ }; } // namespace -void align_eltwise_input_types(const NodeContext& context, Output& lhs, Output& rhs, bool align_scalars) { +element::Type infer_types(const Output& lhs, const Output& rhs, bool align_scalars) { const auto& lhs_type = lhs.get_element_type(); const auto& rhs_type = rhs.get_element_type(); - auto out_type = context.get_output_type(0); - if (out_type.is()) { - auto otype = out_type.as(); - if (otype.is_real()) { - if (otype != lhs_type) { - lhs = context.mark_node(std::make_shared(lhs, otype)); - } - if (otype != rhs_type) { - rhs = context.mark_node(std::make_shared(rhs, otype)); - } - return; - } - } if (lhs_type.is_dynamic() || rhs_type.is_dynamic()) { - // if any of types is not known, align to lhs type. - // TODO: can be fixed with special operation? - rhs = context.mark_node(std::make_shared(rhs, lhs)); - return; + return element::dynamic; } // Both types are static, align types. If float and int types are used convert int type to f32, after that align // to the largest bitness, if both float or both int, just align bitness if (lhs_type == rhs_type) - return; + return lhs_type; // if one of operands is scalar, the resulting type is taken from the other operand except when scalar is float // type and other operand is int, in that case BOTH operands get fp32 type @@ -429,11 +414,9 @@ void align_eltwise_input_types(const NodeContext& context, Output& lhs, Ou if (!align_scalars) rhs_dst_type = element::f32; } else if (is_lhs_scalar && rhs_type != element::boolean) { - lhs = context.mark_node(std::make_shared(lhs, rhs)); - return; + return rhs_type; } else if (is_rhs_scalar && lhs_type != element::boolean) { - rhs = context.mark_node(std::make_shared(rhs, lhs)); - return; + return lhs_type; } if (!lhs_dst_type.is_real() && rhs_dst_type.is_real()) { @@ -470,13 +453,39 @@ void align_eltwise_input_types(const NodeContext& context, Output& lhs, Ou } } } + return lhs_dst_type; +} - // Cast to destination types - if (lhs_dst_type != lhs_type) { - lhs = context.mark_node(std::make_shared(lhs, lhs_dst_type)); +void align_eltwise_input_types(const NodeContext& context, Output& lhs, Output& rhs, bool align_scalars) { + const auto& lhs_type = lhs.get_element_type(); + const auto& rhs_type = rhs.get_element_type(); + auto out_type = context.get_output_type(0); + if (out_type.is()) { + auto otype = out_type.as(); + if (otype.is_real()) { + if (otype != lhs_type) { + lhs = context.mark_node(std::make_shared(lhs, otype)); + } + if (otype != rhs_type) { + rhs = context.mark_node(std::make_shared(rhs, otype)); + } + return; + } + } + auto dst_type = infer_types(lhs, rhs, align_scalars); + if (dst_type.is_dynamic()) { + // We can't decide the type at this point, create a special operation + auto at = std::make_shared(lhs, rhs, align_scalars); + lhs = at->output(0); + rhs = at->output(1); + return; + } + // Cast to destination type + if (dst_type != lhs_type) { + lhs = context.mark_node(std::make_shared(lhs, dst_type)); } - if (rhs_dst_type != rhs_type) { - rhs = context.mark_node(std::make_shared(rhs, rhs_dst_type)); + if (dst_type != rhs_type) { + rhs = context.mark_node(std::make_shared(rhs, dst_type)); } } diff --git a/src/frontends/pytorch/src/utils.hpp b/src/frontends/pytorch/src/utils.hpp index 1635296e612dff..20bae6fa62f5c3 100644 --- a/src/frontends/pytorch/src/utils.hpp +++ b/src/frontends/pytorch/src/utils.hpp @@ -7,6 +7,7 @@ #include "openvino/frontend/pytorch/node_context.hpp" #include "openvino/op/constant.hpp" #include "openvino/op/convert.hpp" +#include "openvino/op/convert_like.hpp" namespace ov { @@ -65,11 +66,11 @@ Any simplified_type_interpret(Any type); void add_exception_to_fw_node(std::shared_ptr node, const std::string& msg); +element::Type infer_types(const Output& lhs, const Output& rhs, bool align_scalars); void align_eltwise_input_types(const NodeContext& context, Output& lhs, Output& rhs, bool align_scalars = false); - void align_output_types(const NodeContext& context, OutputVector& outputs); std::deque> get_list_as_outputs(const Output& start); @@ -125,12 +126,31 @@ OutputVector translate_1to1_match_2_inputs_align_types(const NodeContext& contex FRONT_END_OP_CONVERSION_CHECK(!context.input_is_none(0) && !context.input_is_none(1), "Inputs should not be None."); auto lhs = context.get_input(0); auto rhs = context.get_input(1); - align_eltwise_input_types(context, lhs, rhs, true); + auto lhs_type = context.get_input_type(0); + auto rhs_type = context.get_input_type(1); + // If type is string or None, we shouldn't align + if (!lhs_type.is() && !rhs_type.is() && !lhs_type.is() && + !rhs_type.is()) + align_eltwise_input_types(context, lhs, rhs, true); OutputVector res = {context.mark_node(std::make_shared(lhs, rhs))}; align_output_types(context, res); return res; } +template +OutputVector inplace_translate_1to1_match_2_inputs_align_types(const NodeContext& context) { + num_inputs_check(context, 2, 2); + FRONT_END_OP_CONVERSION_CHECK(!context.input_is_none(0) && !context.input_is_none(1), "Inputs should not be None."); + auto lhs = context.get_input(0); + auto rhs = context.get_input(1); + // For inplace op we know direction of type alignment + if (lhs.get_element_type().is_dynamic() || lhs.get_element_type() != rhs.get_element_type()) + rhs = context.mark_node(std::make_shared(rhs, lhs)); + OutputVector res = {context.mark_node(std::make_shared(lhs, rhs))}; + context.mutate_input(idx, res[0]); + return res; +} + inline OutputVector return_false_scalar(const NodeContext& context) { return {context.mark_node(ov::op::v0::Constant::create(element::boolean, Shape{}, {false}))}; } @@ -158,6 +178,9 @@ class DummyDecoder : public TorchDecoder { virtual PartialShape get_input_shape(size_t index) const override { FRONT_END_NOT_IMPLEMENTED(get_input_shape); } + virtual const std::vector& get_input_strides(size_t index) const override { + FRONT_END_NOT_IMPLEMENTED(get_input_strides); + } virtual Any get_input_type(size_t index) const override { FRONT_END_NOT_IMPLEMENTED(get_input_type); } @@ -165,7 +188,7 @@ class DummyDecoder : public TorchDecoder { FRONT_END_NOT_IMPLEMENTED(get_output_debug_name); } virtual PartialShape get_output_shape(size_t index) const override { - FRONT_END_NOT_IMPLEMENTED(get_output_shape); + return PartialShape::dynamic(); } virtual Any get_output_type(size_t index) const override { FRONT_END_NOT_IMPLEMENTED(get_output_type); @@ -186,7 +209,7 @@ class DummyDecoder : public TorchDecoder { FRONT_END_NOT_IMPLEMENTED(get_op_type); } virtual const std::string& get_schema() const override { - FRONT_END_NOT_IMPLEMENTED(get_schema); + return m_schema; } virtual size_t num_of_outputs() const override { FRONT_END_NOT_IMPLEMENTED(num_of_outputs); @@ -215,6 +238,9 @@ class DummyDecoder : public TorchDecoder { virtual OutputVector inlined_inputs(size_t start_index) const override { FRONT_END_NOT_IMPLEMENTED(inlined_inputs); } + +private: + const std::string m_schema = "NONE"; }; } // namespace pytorch diff --git a/src/frontends/pytorch/src/utils_quantize.cpp b/src/frontends/pytorch/src/utils_quantize.cpp index 5af546f3d5be5d..1346fd76971fcc 100644 --- a/src/frontends/pytorch/src/utils_quantize.cpp +++ b/src/frontends/pytorch/src/utils_quantize.cpp @@ -6,6 +6,7 @@ #include "openvino/frontend/pytorch/node_context.hpp" #include "openvino/op/broadcast.hpp" +#include "openvino/op/constant.hpp" #include "openvino/op/convert.hpp" #include "openvino/op/convert_like.hpp" #include "openvino/op/fake_quantize.hpp" @@ -13,6 +14,7 @@ #include "openvino/op/reshape.hpp" #include "openvino/op/scatter_elements_update.hpp" #include "openvino/op/subtract.hpp" +#include "transformations/utils/utils.hpp" namespace ov { namespace frontend { @@ -168,6 +170,53 @@ std::shared_ptr cast_quantized_fw_node(std::shared_ptr no return quant_node; } +std::shared_ptr u4_compression_stack(const OutputVector& list_elems, int64_t axis) { + // Part 1: Detect pattern + + if (list_elems.size() != 2) + return nullptr; + auto bitwise_and = cast_fw_node(list_elems[0].get_node_shared_ptr(), "aten::bitwise_and"); + if (!bitwise_and) + return nullptr; + auto bitwise_shift = cast_fw_node(list_elems[1].get_node_shared_ptr(), "aten::bitwise_right_shift"); + if (!bitwise_shift) + return nullptr; + + auto weights_u8 = std::dynamic_pointer_cast(bitwise_and->get_input_node_shared_ptr(0)); + if (weights_u8 != std::dynamic_pointer_cast(bitwise_shift->get_input_node_shared_ptr(0))) + return nullptr; + + if (weights_u8->get_output_element_type(0) != element::u8) + return nullptr; + + if (axis != -1 && static_cast(axis) != weights_u8->get_shape().size() - 1) + return nullptr; + + if (!ov::op::util::has_constant_value(bitwise_and->get_input_node_shared_ptr(1), 0x0F)) + return nullptr; + + if (!ov::op::util::has_constant_value(bitwise_shift->get_input_node_shared_ptr(1), 4)) + return nullptr; + + // Pattern detected, weights_u8 is target u8 packed constant with weights + + // Part 2: Form u4 constant by repacking of the original weights_u8 + // Repacking transformes half of lanes to interleaved representation. + + auto u8_shape = weights_u8->get_shape(); + size_t full_size = shape_size(u8_shape); + auto src = weights_u8->get_data_ptr(); + + auto u4_shape = u8_shape; + u4_shape.push_back(2); + auto new_const = std::make_shared(element::u4, u4_shape); + auto dst = const_cast(reinterpret_cast(new_const->get_data_ptr())); + + std::copy(src, src + full_size, dst); // TODO: Avoid copying, reuse the same constant + copy_runtime_info_and_name(weights_u8, {new_const}, {weights_u8, bitwise_and, bitwise_shift}); + return new_const; +} + } // namespace pytorch } // namespace frontend } // namespace ov diff --git a/src/frontends/pytorch/src/utils_quantize.hpp b/src/frontends/pytorch/src/utils_quantize.hpp index 69917e7b8bce3e..e02bce880d2480 100644 --- a/src/frontends/pytorch/src/utils_quantize.hpp +++ b/src/frontends/pytorch/src/utils_quantize.hpp @@ -166,6 +166,12 @@ OutputVector quantizable_op(const NodeContext& context) { } } // namespace op +/** + * Captures aten::stack([aten::bitwise_and(Constant(u8)), aten::bitwise_right_shift(Constant(u8))], dim=-1). + * This pattern is transformed to a single Constant with element_type=u4. + */ +std::shared_ptr u4_compression_stack(const OutputVector& list_elems, int64_t axis); + } // namespace pytorch } // namespace frontend } // namespace ov diff --git a/src/frontends/tensorflow/README.md b/src/frontends/tensorflow/README.md index 7fc421cd92c7f4..4a48203a2b41dc 100644 --- a/src/frontends/tensorflow/README.md +++ b/src/frontends/tensorflow/README.md @@ -205,6 +205,7 @@ py.test tensorflow_tests/test_tf_Unique.py --use_new_frontend ``` ## See also + * [Supported Operations](./docs/supported_ops.md) * [OpenVINO README](../../../README.md) * [OpenVINO Core Components](../../README.md) * [Developer documentation](../../../docs/dev/index.md) diff --git a/src/frontends/tensorflow/docs/supported_ops.md b/src/frontends/tensorflow/docs/supported_ops.md new file mode 100644 index 00000000000000..5794e3f16653fd --- /dev/null +++ b/src/frontends/tensorflow/docs/supported_ops.md @@ -0,0 +1,1406 @@ +# TensorFlow Operations Supported by OpenVINO TensorFlow Frontend + +Here is a table of operations supported by the TensorFlow Frontend from [tf.raw_ops](https://www.tensorflow.org/api_docs/python/tf/raw_ops). +A "supported operation" is one that TensorFlow Frontend can convert to the OpenVINO representation. + +| Operation Name | Supported | Limitation | +|---------------------------------------------------------|-------------------------------|-------------------------------| +| Abort | NO | | +| Abs | YES | | +| AccumulateNV2 | NO | | +| AccumulatorApplyGradient | NO | | +| AccumulatorNumAccumulated | NO | | +| AccumulatorSetGlobalStep | NO | | +| AccumulatorTakeGradient | NO | | +| Acos | YES | | +| Acosh | YES | | +| Add | YES | | +| AddManySparseToTensorsMap | NO | | +| AddN | YES | | +| AddSparseToTensorsMap | NO | | +| AddV2 | YES | | +| AdjustContrast | NO | | +| AdjustContrastv2 | YES | | +| AdjustHue | NO | | +| AdjustSaturation | NO | | +| All | YES | | +| AllCandidateSampler | NO | | +| AllToAll | NO | | +| Angle | NO | | +| AnonymousHashTable | NO | | +| AnonymousIterator | NO | | +| AnonymousIteratorV2 | NO | | +| AnonymousIteratorV3 | NO | | +| AnonymousMemoryCache | NO | | +| AnonymousMultiDeviceIterator | NO | | +| AnonymousMultiDeviceIteratorV3 | NO | | +| AnonymousMutableDenseHashTable | NO | | +| AnonymousMutableHashTable | NO | | +| AnonymousMutableHashTableOfTensors | NO | | +| AnonymousRandomSeedGenerator | NO | | +| AnonymousSeedGenerator | NO | | +| Any | YES | | +| ApplyAdaMax | NO | | +| ApplyAdadelta | NO | | +| ApplyAdagrad | NO | | +| ApplyAdagradDA | NO | | +| ApplyAdagradV2 | NO | | +| ApplyAdam | NO | | +| ApplyAddSign | NO | | +| ApplyCenteredRMSProp | NO | | +| ApplyFtrl | NO | | +| ApplyFtrlV2 | NO | | +| ApplyGradientDescent | NO | | +| ApplyMomentum | NO | | +| ApplyPowerSign | NO | | +| ApplyProximalAdagrad | NO | | +| ApplyProximalGradientDescent | NO | | +| ApplyRMSProp | NO | | +| ApproxTopK | NO | | +| ApproximateEqual | NO | | +| ArgMax | YES | | +| ArgMin | YES | | +| AsString | NO | | +| Asin | YES | | +| Asinh | YES | | +| Assert | YES | | +| AssertCardinalityDataset | NO | | +| AssertNextDataset | NO | | +| AssertPrevDataset | NO | | +| Assign | YES | | +| AssignAdd | NO | | +| AssignAddVariableOp | NO | | +| AssignSub | NO | | +| AssignSubVariableOp | NO | | +| AssignVariableOp | YES | | +| AssignVariableXlaConcatND | NO | | +| Atan | YES | | +| Atan2 | NO | | +| Atanh | YES | | +| AudioSpectrogram | NO | | +| AudioSummary | NO | | +| AudioSummaryV2 | NO | | +| AutoShardDataset | NO | | +| AvgPool | YES | | +| AvgPool3D | YES | | +| AvgPool3DGrad | NO | | +| AvgPoolGrad | NO | | +| BandedTriangularSolve | NO | | +| Barrier | NO | | +| BarrierClose | NO | | +| BarrierIncompleteSize | NO | | +| BarrierInsertMany | NO | | +| BarrierReadySize | NO | | +| BarrierTakeMany | NO | | +| Batch | NO | | +| BatchCholesky | NO | | +| BatchCholeskyGrad | NO | | +| BatchDataset | NO | | +| BatchDatasetV2 | NO | | +| BatchFFT | NO | | +| BatchFFT2D | NO | | +| BatchFFT3D | NO | | +| BatchFunction | NO | | +| BatchIFFT | NO | | +| BatchIFFT2D | NO | | +| BatchIFFT3D | NO | | +| BatchMatMul | YES | | +| BatchMatMulV2 | YES | | +| BatchMatMulV3 | YES | | +| BatchMatrixBandPart | NO | | +| BatchMatrixDeterminant | NO | | +| BatchMatrixDiag | NO | | +| BatchMatrixDiagPart | NO | | +| BatchMatrixInverse | NO | | +| BatchMatrixSetDiag | NO | | +| BatchMatrixSolve | NO | | +| BatchMatrixSolveLs | NO | | +| BatchMatrixTriangularSolve | NO | | +| BatchNormWithGlobalNormalization | NO | | +| BatchNormWithGlobalNormalizationGrad | NO | | +| BatchSelfAdjointEig | NO | | +| BatchSelfAdjointEigV2 | NO | | +| BatchSvd | NO | | +| BatchToSpace | NO | | +| BatchToSpaceND | YES | | +| BesselI0 | NO | | +| BesselI0e | NO | | +| BesselI1 | NO | | +| BesselI1e | NO | | +| BesselJ0 | NO | | +| BesselJ1 | NO | | +| BesselK0 | NO | | +| BesselK0e | NO | | +| BesselK1 | NO | | +| BesselK1e | NO | | +| BesselY0 | NO | | +| BesselY1 | NO | | +| Betainc | NO | | +| BiasAdd | YES | | +| BiasAddGrad | NO | | +| BiasAddV1 | NO | | +| Bincount | NO | | +| Bitcast | NO | | +| BitwiseAnd | NO | | +| BitwiseOr | NO | | +| BitwiseXor | NO | | +| BlockLSTM | YES | | +| BlockLSTMGrad | NO | | +| BlockLSTMGradV2 | NO | | +| BlockLSTMV2 | NO | | +| BoostedTreesAggregateStats | NO | | +| BoostedTreesBucketize | NO | | +| BoostedTreesCalculateBestFeatureSplit | NO | | +| BoostedTreesCalculateBestFeatureSplitV2 | NO | | +| BoostedTreesCalculateBestGainsPerFeature | NO | | +| BoostedTreesCenterBias | NO | | +| BoostedTreesCreateEnsemble | NO | | +| BoostedTreesCreateQuantileStreamResource | NO | | +| BoostedTreesDeserializeEnsemble | NO | | +| BoostedTreesEnsembleResourceHandleOp | NO | | +| BoostedTreesExampleDebugOutputs | NO | | +| BoostedTreesFlushQuantileSummaries | NO | | +| BoostedTreesGetEnsembleStates | NO | | +| BoostedTreesMakeQuantileSummaries | NO | | +| BoostedTreesMakeStatsSummary | NO | | +| BoostedTreesPredict | NO | | +| BoostedTreesQuantileStreamResourceAddSummaries | NO | | +| BoostedTreesQuantileStreamResourceDeserialize | NO | | +| BoostedTreesQuantileStreamResourceFlush | NO | | +| BoostedTreesQuantileStreamResourceGetBucketBoundaries | NO | | +| BoostedTreesQuantileStreamResourceHandleOp | NO | | +| BoostedTreesSerializeEnsemble | NO | | +| BoostedTreesSparseAggregateStats | NO | | +| BoostedTreesSparseCalculateBestFeatureSplit | NO | | +| BoostedTreesTrainingPredict | NO | | +| BoostedTreesUpdateEnsemble | NO | | +| BoostedTreesUpdateEnsembleV2 | NO | | +| BroadcastArgs | YES | | +| BroadcastGradientArgs | NO | | +| BroadcastTo | YES | | +| Bucketize | YES | | +| BytesProducedStatsDataset | NO | | +| CSRSparseMatrixComponents | NO | | +| CSRSparseMatrixToDense | NO | | +| CSRSparseMatrixToSparseTensor | NO | | +| CSVDataset | NO | | +| CSVDatasetV2 | NO | | +| CTCBeamSearchDecoder | NO | | +| CTCGreedyDecoder | YES | | +| CTCLoss | YES | | +| CTCLossV2 | NO | | +| CacheDataset | NO | | +| CacheDatasetV2 | NO | | +| Case | NO | | +| Cast | YES | | +| Ceil | YES | | +| CheckNumerics | YES | | +| CheckNumericsV2 | YES | | +| Cholesky | NO | | +| CholeskyGrad | NO | | +| ChooseFastestBranchDataset | NO | | +| ChooseFastestDataset | NO | | +| ClipByValue | YES | | +| CloseSummaryWriter | NO | | +| CollectiveAllToAllV2 | NO | | +| CollectiveAllToAllV3 | NO | | +| CollectiveAssignGroupV2 | NO | | +| CollectiveBcastRecv | NO | | +| CollectiveBcastRecvV2 | NO | | +| CollectiveBcastSend | NO | | +| CollectiveBcastSendV2 | NO | | +| CollectiveGather | NO | | +| CollectiveGatherV2 | NO | | +| CollectiveInitializeCommunicator | NO | | +| CollectivePermute | NO | | +| CollectiveReduce | NO | | +| CollectiveReduceScatterV2 | NO | | +| CollectiveReduceV2 | NO | | +| CollectiveReduceV3 | NO | | +| CombinedNonMaxSuppression | NO | | +| Complex | NO | | +| ComplexAbs | NO | | +| CompositeTensorVariantFromComponents | NO | | +| CompositeTensorVariantToComponents | NO | | +| CompressElement | NO | | +| ComputeAccidentalHits | NO | | +| ComputeBatchSize | NO | | +| Concat | YES | | +| ConcatOffset | NO | | +| ConcatV2 | YES | | +| ConcatenateDataset | NO | | +| ConditionalAccumulator | NO | | +| ConfigureDistributedTPU | NO | | +| ConfigureTPUEmbedding | NO | | +| Conj | NO | | +| ConjugateTranspose | NO | | +| Const | YES | | +| ConsumeMutexLock | NO | | +| ControlTrigger | NO | | +| Conv | NO | | +| Conv2D | YES | | +| Conv2DBackpropFilter | NO | | +| Conv2DBackpropFilterV2 | NO | | +| Conv2DBackpropInput | YES | | +| Conv2DBackpropInputV2 | NO | | +| Conv3D | YES | | +| Conv3DBackpropFilter | NO | | +| Conv3DBackpropFilterV2 | NO | | +| Conv3DBackpropInput | NO | | +| Conv3DBackpropInputV2 | YES | | +| Copy | NO | | +| CopyHost | NO | | +| Cos | YES | | +| Cosh | YES | | +| CountUpTo | NO | | +| CreateSummaryDbWriter | NO | | +| CreateSummaryFileWriter | NO | | +| CropAndResize | YES | | +| CropAndResizeGradBoxes | NO | | +| CropAndResizeGradImage | NO | | +| Cross | NO | | +| CrossReplicaSum | NO | | +| CudnnRNN | NO | | +| CudnnRNNBackprop | NO | | +| CudnnRNNBackpropV2 | NO | | +| CudnnRNNBackpropV3 | NO | | +| CudnnRNNCanonicalToParams | NO | | +| CudnnRNNCanonicalToParamsV2 | NO | | +| CudnnRNNParamsSize | NO | | +| CudnnRNNParamsToCanonical | NO | | +| CudnnRNNParamsToCanonicalV2 | NO | | +| CudnnRNNV2 | NO | | +| CudnnRNNV3 | NO | | +| Cumprod | NO | | +| Cumsum | YES | | +| CumulativeLogsumexp | NO | | +| DataFormatDimMap | NO | | +| DataFormatVecPermute | NO | | +| DataServiceDataset | NO | | +| DataServiceDatasetV2 | NO | | +| DataServiceDatasetV3 | NO | | +| DataServiceDatasetV4 | NO | | +| DatasetCardinality | NO | | +| DatasetFromGraph | NO | | +| DatasetToGraph | NO | | +| DatasetToGraphV2 | NO | | +| DatasetToSingleElement | NO | | +| DatasetToTFRecord | NO | | +| Dawsn | NO | | +| DebugGradientIdentity | NO | | +| DebugGradientRefIdentity | NO | | +| DebugIdentity | NO | | +| DebugIdentityV2 | NO | | +| DebugIdentityV3 | NO | | +| DebugNanCount | NO | | +| DebugNumericSummary | NO | | +| DebugNumericSummaryV2 | NO | | +| DecodeAndCropJpeg | NO | | +| DecodeBase64 | NO | | +| DecodeBmp | NO | | +| DecodeCSV | NO | | +| DecodeCompressed | NO | | +| DecodeGif | NO | | +| DecodeImage | NO | | +| DecodeJSONExample | NO | | +| DecodeJpeg | NO | | +| DecodePaddedRaw | NO | | +| DecodePng | NO | | +| DecodeProtoV2 | NO | | +| DecodeRaw | NO | | +| DecodeWav | NO | | +| DeepCopy | NO | | +| DeleteIterator | NO | | +| DeleteMemoryCache | NO | | +| DeleteMultiDeviceIterator | NO | | +| DeleteRandomSeedGenerator | NO | | +| DeleteSeedGenerator | NO | | +| DeleteSessionTensor | NO | | +| DenseBincount | NO | | +| DenseCountSparseOutput | NO | | +| DenseToCSRSparseMatrix | NO | | +| DenseToDenseSetOperation | NO | | +| DenseToSparseBatchDataset | NO | | +| DenseToSparseSetOperation | NO | | +| DepthToSpace | YES | | +| DepthwiseConv2dNative | YES | | +| DepthwiseConv2dNativeBackpropFilter | NO | | +| DepthwiseConv2dNativeBackpropInput | NO | | +| Dequantize | NO | | +| DeserializeIterator | NO | | +| DeserializeManySparse | NO | | +| DeserializeSparse | NO | | +| DestroyResourceOp | NO | | +| DestroyTemporaryVariable | NO | | +| DeviceIndex | NO | | +| Diag | NO | | +| DiagPart | NO | | +| Digamma | NO | | +| Dilation2D | NO | | +| Dilation2DBackpropFilter | NO | | +| Dilation2DBackpropInput | NO | | +| DirectedInterleaveDataset | NO | | +| DisableCopyOnRead | NO | | +| DistributedSave | NO | | +| Div | NO | | +| DivNoNan | YES | | +| DrawBoundingBoxes | NO | | +| DrawBoundingBoxesV2 | NO | | +| DummyIterationCounter | NO | | +| DummyMemoryCache | NO | | +| DummySeedGenerator | NO | | +| DynamicEnqueueTPUEmbeddingArbitraryTensorBatch | NO | | +| DynamicPartition | YES | | +| DynamicStitch | YES | | +| EagerPyFunc | NO | | +| EditDistance | NO | | +| Eig | NO | | +| Einsum | YES | | +| Elu | YES | | +| EluGrad | NO | | +| Empty | NO | | +| EmptyTensorList | YES | | +| EncodeBase64 | NO | | +| EncodeJpeg | NO | | +| EncodeJpegVariableQuality | NO | | +| EncodePng | NO | | +| EncodeProto | NO | | +| EncodeWav | NO | | +| EnqueueTPUEmbeddingArbitraryTensorBatch | NO | | +| EnqueueTPUEmbeddingIntegerBatch | NO | | +| EnqueueTPUEmbeddingRaggedTensorBatch | NO | | +| EnqueueTPUEmbeddingSparseBatch | NO | | +| EnqueueTPUEmbeddingSparseTensorBatch | NO | | +| EnsureShape | YES | | +| Enter | YES | | +| Equal | YES | | +| Erf | YES | | +| Erfc | NO | | +| Erfinv | NO | | +| EuclideanNorm | YES | | +| Exit | YES | | +| Exp | YES | | +| ExpandDims | YES | | +| ExperimentalAssertNextDataset | NO | | +| ExperimentalAutoShardDataset | NO | | +| ExperimentalBytesProducedStatsDataset | NO | | +| ExperimentalCSVDataset | NO | | +| ExperimentalChooseFastestDataset | NO | | +| ExperimentalDatasetCardinality | NO | | +| ExperimentalDatasetToTFRecord | NO | | +| ExperimentalDenseToSparseBatchDataset | NO | | +| ExperimentalDirectedInterleaveDataset | NO | | +| ExperimentalGroupByReducerDataset | NO | | +| ExperimentalGroupByWindowDataset | NO | | +| ExperimentalIgnoreErrorsDataset | NO | | +| ExperimentalIteratorGetDevice | NO | | +| ExperimentalLMDBDataset | NO | | +| ExperimentalLatencyStatsDataset | NO | | +| ExperimentalMapAndBatchDataset | NO | | +| ExperimentalMapDataset | NO | | +| ExperimentalMatchingFilesDataset | NO | | +| ExperimentalMaxIntraOpParallelismDataset | NO | | +| ExperimentalNonSerializableDataset | NO | | +| ExperimentalParallelInterleaveDataset | NO | | +| ExperimentalParseExampleDataset | NO | | +| ExperimentalPrivateThreadPoolDataset | NO | | +| ExperimentalRandomDataset | NO | | +| ExperimentalRebatchDataset | NO | | +| ExperimentalScanDataset | NO | | +| ExperimentalSetStatsAggregatorDataset | NO | | +| ExperimentalSleepDataset | NO | | +| ExperimentalSlidingWindowDataset | NO | | +| ExperimentalSqlDataset | NO | | +| ExperimentalStatsAggregatorHandle | NO | | +| ExperimentalStatsAggregatorSummary | NO | | +| ExperimentalTakeWhileDataset | NO | | +| ExperimentalThreadPoolDataset | NO | | +| ExperimentalThreadPoolHandle | NO | | +| ExperimentalUnbatchDataset | NO | | +| ExperimentalUniqueDataset | NO | | +| Expint | NO | | +| Expm1 | NO | | +| ExtractGlimpse | NO | | +| ExtractGlimpseV2 | NO | | +| ExtractImagePatches | YES | | +| ExtractJpegShape | NO | | +| ExtractVolumePatches | NO | | +| FFT | NO | | +| FFT2D | NO | | +| FFT3D | NO | | +| FIFOQueue | YES | | +| FIFOQueueV2 | YES | | +| Fact | NO | | +| FakeParam | NO | | +| FakeQuantWithMinMaxArgs | YES | | +| FakeQuantWithMinMaxArgsGradient | NO | | +| FakeQuantWithMinMaxVars | YES | | +| FakeQuantWithMinMaxVarsGradient | NO | | +| FakeQuantWithMinMaxVarsPerChannel | YES | | +| FakeQuantWithMinMaxVarsPerChannelGradient | NO | | +| FakeQueue | NO | | +| Fill | YES | | +| FilterByLastComponentDataset | NO | | +| FilterDataset | NO | | +| FinalizeDataset | NO | | +| Fingerprint | NO | | +| FixedLengthRecordDataset | NO | | +| FixedLengthRecordDatasetV2 | NO | | +| FixedLengthRecordReader | NO | | +| FixedLengthRecordReaderV2 | NO | | +| FixedUnigramCandidateSampler | NO | | +| FlatMapDataset | NO | | +| Floor | YES | | +| FloorDiv | YES | | +| FloorMod | YES | | +| FlushSummaryWriter | NO | | +| For | NO | | +| FractionalAvgPool | NO | | +| FractionalAvgPoolGrad | NO | | +| FractionalMaxPool | NO | | +| FractionalMaxPoolGrad | NO | | +| FresnelCos | NO | | +| FresnelSin | NO | | +| FusedBatchNorm | YES | | +| FusedBatchNormGrad | NO | | +| FusedBatchNormGradV2 | NO | | +| FusedBatchNormGradV3 | NO | | +| FusedBatchNormV2 | YES | | +| FusedBatchNormV3 | YES | | +| FusedPadConv2D | NO | | +| FusedResizeAndPadConv2D | NO | | +| GRUBlockCell | YES | | +| GRUBlockCellGrad | NO | | +| Gather | YES | | +| GatherNd | YES | | +| GatherV2 | YES | | +| GenerateBoundingBoxProposals | NO | | +| GenerateVocabRemapping | NO | | +| GeneratorDataset | NO | | +| GetElementAtIndex | NO | | +| GetOptions | NO | | +| GetSessionHandle | NO | | +| GetSessionHandleV2 | NO | | +| GetSessionTensor | NO | | +| Greater | YES | | +| GreaterEqual | YES | | +| GroupByReducerDataset | NO | | +| GroupByWindowDataset | NO | | +| GuaranteeConst | NO | | +| HSVToRGB | NO | | +| HashTable | YES | | +| HashTableV2 | YES | | +| HistogramFixedWidth | NO | | +| HistogramSummary | NO | | +| IFFT | NO | | +| IFFT2D | NO | | +| IFFT3D | NO | | +| IRFFT | NO | | +| IRFFT2D | NO | | +| IRFFT3D | NO | | +| Identity | YES | | +| IdentityN | YES | | +| IdentityReader | NO | | +| IdentityReaderV2 | NO | | +| If | YES | | +| Igamma | NO | | +| IgammaGradA | NO | | +| Igammac | NO | | +| IgnoreErrorsDataset | NO | | +| Imag | NO | | +| ImageProjectiveTransformV2 | NO | | +| ImageProjectiveTransformV3 | NO | | +| ImageSummary | NO | | +| ImmutableConst | NO | | +| ImportEvent | NO | | +| InTopK | NO | | +| InTopKV2 | NO | | +| InfeedDequeue | NO | | +| InfeedDequeueTuple | NO | | +| InfeedEnqueue | NO | | +| InfeedEnqueuePrelinearizedBuffer | NO | | +| InfeedEnqueueTuple | NO | | +| InitializeTable | NO | | +| InitializeTableFromDataset | NO | | +| InitializeTableFromTextFile | NO | | +| InitializeTableFromTextFileV2 | NO | | +| InitializeTableV2 | NO | | +| InplaceAdd | NO | | +| InplaceSub | NO | | +| InplaceUpdate | NO | | +| InterleaveDataset | NO | | +| Inv | NO | | +| InvGrad | NO | | +| Invert | NO | | +| InvertPermutation | YES | | +| IsBoostedTreesEnsembleInitialized | NO | | +| IsBoostedTreesQuantileStreamResourceInitialized | NO | | +| IsFinite | YES | | +| IsInf | YES | | +| IsNan | YES | | +| IsTPUEmbeddingInitialized | NO | | +| IsVariableInitialized | YES | | +| IsotonicRegression | NO | | +| Iterator | YES | | +| IteratorFromStringHandle | NO | | +| IteratorFromStringHandleV2 | NO | | +| IteratorGetDevice | NO | | +| IteratorGetNext | YES | | +| IteratorGetNextAsOptional | NO | | +| IteratorGetNextSync | NO | | +| IteratorToStringHandle | NO | | +| IteratorV2 | YES | | +| L2Loss | YES | | +| LMDBDataset | NO | | +| LMDBReader | NO | | +| LRN | YES | | +| LRNGrad | NO | | +| LSTMBlockCell | NO | | +| LSTMBlockCellGrad | NO | | +| LatencyStatsDataset | NO | | +| LeakyRelu | YES | | +| LeakyReluGrad | NO | | +| LearnedUnigramCandidateSampler | NO | | +| LeftShift | NO | | +| LegacyParallelInterleaveDatasetV2 | NO | | +| Less | YES | | +| LessEqual | YES | | +| Lgamma | NO | | +| LinSpace | YES | | +| ListDataset | NO | | +| ListDiff | YES | | +| LoadAndRemapMatrix | NO | | +| LoadDataset | NO | | +| LoadTPUEmbeddingADAMParameters | NO | | +| LoadTPUEmbeddingAdadeltaParameters | NO | | +| LoadTPUEmbeddingAdagradMomentumParameters | NO | | +| LoadTPUEmbeddingAdagradParameters | NO | | +| LoadTPUEmbeddingCenteredRMSPropParameters | NO | | +| LoadTPUEmbeddingFTRLParameters | NO | | +| LoadTPUEmbeddingFrequencyEstimatorParameters | NO | | +| LoadTPUEmbeddingMDLAdagradLightParameters | NO | | +| LoadTPUEmbeddingMomentumParameters | NO | | +| LoadTPUEmbeddingProximalAdagradParameters | NO | | +| LoadTPUEmbeddingProximalYogiParameters | NO | | +| LoadTPUEmbeddingRMSPropParameters | NO | | +| LoadTPUEmbeddingStochasticGradientDescentParameters | NO | | +| Log | YES | | +| Log1p | YES | | +| LogMatrixDeterminant | NO | | +| LogSoftmax | YES | | +| LogUniformCandidateSampler | NO | | +| LogicalAnd | YES | | +| LogicalNot | YES | | +| LogicalOr | YES | | +| LookupTableExport | NO | | +| LookupTableExportV2 | NO | | +| LookupTableFind | NO | | +| LookupTableFindV2 | NO | | +| LookupTableImport | NO | | +| LookupTableImportV2 | NO | | +| LookupTableInsert | YES | | +| LookupTableInsertV2 | YES | | +| LookupTableRemoveV2 | NO | | +| LookupTableSize | NO | | +| LookupTableSizeV2 | NO | | +| LoopCond | YES | | +| LowerBound | NO | | +| Lu | NO | | +| MakeIterator | NO | | +| MapAndBatchDataset | NO | | +| MapClear | NO | | +| MapDataset | NO | | +| MapDefun | NO | | +| MapIncompleteSize | NO | | +| MapPeek | NO | | +| MapSize | NO | | +| MapStage | NO | | +| MapUnstage | NO | | +| MapUnstageNoKey | NO | | +| MatMul | YES | | +| MatchingFiles | NO | | +| MatchingFilesDataset | NO | | +| MatrixBandPart | NO | | +| MatrixDeterminant | NO | | +| MatrixDiag | YES | | +| MatrixDiagPart | NO | | +| MatrixDiagPartV2 | NO | | +| MatrixDiagPartV3 | NO | | +| MatrixDiagV2 | NO | | +| MatrixDiagV3 | NO | | +| MatrixExponential | NO | | +| MatrixInverse | NO | | +| MatrixLogarithm | NO | | +| MatrixSetDiag | NO | | +| MatrixSetDiagV2 | NO | | +| MatrixSetDiagV3 | NO | | +| MatrixSolve | NO | | +| MatrixSolveLs | NO | | +| MatrixSquareRoot | NO | | +| MatrixTriangularSolve | NO | | +| Max | YES | | +| MaxIntraOpParallelismDataset | NO | | +| MaxPool | YES | | +| MaxPool3D | YES | | +| MaxPool3DGrad | NO | | +| MaxPool3DGradGrad | NO | | +| MaxPoolGrad | NO | | +| MaxPoolGradGrad | NO | | +| MaxPoolGradGradV2 | NO | | +| MaxPoolGradGradWithArgmax | NO | | +| MaxPoolGradV2 | NO | | +| MaxPoolGradWithArgmax | NO | | +| MaxPoolV2 | YES | | +| MaxPoolWithArgmax | YES | | +| Maximum | YES | | +| Mean | YES | | +| Merge | YES | | +| MergeSummary | NO | | +| MergeV2Checkpoints | YES | | +| Mfcc | NO | | +| Min | YES | | +| Minimum | YES | | +| MirrorPad | YES | | +| MirrorPadGrad | NO | | +| Mod | YES | | +| ModelDataset | NO | | +| Mul | YES | | +| MulNoNan | NO | | +| MultiDeviceIterator | NO | | +| MultiDeviceIteratorFromStringHandle | NO | | +| MultiDeviceIteratorGetNextFromShard | NO | | +| MultiDeviceIteratorInit | NO | | +| MultiDeviceIteratorToStringHandle | NO | | +| Multinomial | NO | | +| MutableDenseHashTable | NO | | +| MutableDenseHashTableV2 | NO | | +| MutableHashTable | YES | | +| MutableHashTableOfTensors | NO | | +| MutableHashTableOfTensorsV2 | NO | | +| MutableHashTableV2 | YES | | +| MutexLock | NO | | +| MutexV2 | NO | | +| NcclAllReduce | NO | | +| NcclBroadcast | NO | | +| NcclReduce | NO | | +| Ndtri | NO | | +| Neg | YES | | +| NextAfter | NO | | +| NextIteration | YES | | +| NoOp | YES | | +| NonDeterministicInts | NO | | +| NonMaxSuppression | YES | | +| NonMaxSuppressionV2 | YES | | +| NonMaxSuppressionV3 | YES | | +| NonMaxSuppressionV4 | YES | | +| NonMaxSuppressionV5 | YES | | +| NonMaxSuppressionWithOverlaps | NO | | +| NonSerializableDataset | NO | | +| NotEqual | YES | | +| NthElement | NO | | +| OneHot | YES | | +| OneShotIterator | YES | | +| OnesLike | YES | | +| OptimizeDataset | NO | | +| OptimizeDatasetV2 | NO | | +| OptionalFromValue | NO | | +| OptionalGetValue | NO | | +| OptionalHasValue | NO | | +| OptionalNone | NO | | +| OptionsDataset | NO | | +| OrderedMapClear | NO | | +| OrderedMapIncompleteSize | NO | | +| OrderedMapPeek | NO | | +| OrderedMapSize | NO | | +| OrderedMapStage | NO | | +| OrderedMapUnstage | NO | | +| OrderedMapUnstageNoKey | NO | | +| OutfeedDequeue | NO | | +| OutfeedDequeueTuple | NO | | +| OutfeedDequeueTupleV2 | NO | | +| OutfeedDequeueV2 | NO | | +| OutfeedEnqueue | NO | | +| OutfeedEnqueueTuple | NO | | +| Pack | YES | | +| Pad | YES | | +| PadV2 | YES | | +| PaddedBatchDataset | NO | | +| PaddedBatchDatasetV2 | NO | | +| PaddingFIFOQueue | NO | | +| PaddingFIFOQueueV2 | NO | | +| ParallelBatchDataset | NO | | +| ParallelConcat | NO | | +| ParallelDynamicStitch | YES | | +| ParallelFilterDataset | NO | | +| ParallelInterleaveDataset | NO | | +| ParallelInterleaveDatasetV2 | NO | | +| ParallelInterleaveDatasetV3 | NO | | +| ParallelInterleaveDatasetV4 | NO | | +| ParallelMapDataset | NO | | +| ParallelMapDatasetV2 | NO | | +| ParameterizedTruncatedNormal | NO | | +| ParseExample | NO | | +| ParseExampleDataset | NO | | +| ParseExampleDatasetV2 | NO | | +| ParseExampleV2 | NO | | +| ParseSequenceExample | NO | | +| ParseSequenceExampleV2 | NO | | +| ParseSingleExample | NO | | +| ParseSingleSequenceExample | NO | | +| ParseTensor | NO | | +| PartitionedCall | YES | | +| Placeholder | YES | | +| PlaceholderV2 | NO | | +| PlaceholderWithDefault | YES | | +| Polygamma | NO | | +| PopulationCount | NO | | +| Pow | YES | | +| PrefetchDataset | NO | | +| Prelinearize | NO | | +| PrelinearizeTuple | NO | | +| PreventGradient | YES | | +| Print | NO | | +| PrintV2 | NO | | +| PriorityQueue | NO | | +| PriorityQueueV2 | NO | | +| PrivateThreadPoolDataset | NO | | +| Prod | YES | | +| PyFunc | NO | | +| PyFuncStateless | NO | | +| Qr | NO | | +| QuantizeAndDequantize | NO | | +| QuantizeAndDequantizeV2 | NO | | +| QuantizeAndDequantizeV3 | NO | | +| QuantizeAndDequantizeV4 | NO | | +| QuantizeAndDequantizeV4Grad | NO | | +| QuantizeDownAndShrinkRange | NO | | +| QuantizeV2 | NO | | +| QuantizedAdd | NO | | +| QuantizedAvgPool | NO | | +| QuantizedBatchNormWithGlobalNormalization | NO | | +| QuantizedBiasAdd | NO | | +| QuantizedConcat | NO | | +| QuantizedConv2D | NO | | +| QuantizedConv2DAndRelu | NO | | +| QuantizedConv2DAndReluAndRequantize | NO | | +| QuantizedConv2DAndRequantize | NO | | +| QuantizedConv2DPerChannel | NO | | +| QuantizedConv2DWithBias | NO | | +| QuantizedConv2DWithBiasAndRelu | NO | | +| QuantizedConv2DWithBiasAndReluAndRequantize | NO | | +| QuantizedConv2DWithBiasAndRequantize | NO | | +| QuantizedConv2DWithBiasSignedSumAndReluAndRequantize | NO | | +| QuantizedConv2DWithBiasSumAndRelu | NO | | +| QuantizedConv2DWithBiasSumAndReluAndRequantize | NO | | +| QuantizedDepthwiseConv2D | NO | | +| QuantizedDepthwiseConv2DWithBias | NO | | +| QuantizedDepthwiseConv2DWithBiasAndRelu | NO | | +| QuantizedDepthwiseConv2DWithBiasAndReluAndRequantize | NO | | +| QuantizedInstanceNorm | NO | | +| QuantizedMatMul | NO | | +| QuantizedMatMulWithBias | NO | | +| QuantizedMatMulWithBiasAndDequantize | NO | | +| QuantizedMatMulWithBiasAndRelu | NO | | +| QuantizedMatMulWithBiasAndReluAndRequantize | NO | | +| QuantizedMatMulWithBiasAndRequantize | NO | | +| QuantizedMaxPool | NO | | +| QuantizedMul | NO | | +| QuantizedRelu | NO | | +| QuantizedRelu6 | NO | | +| QuantizedReluX | NO | | +| QuantizedReshape | NO | | +| QuantizedResizeBilinear | NO | | +| QueueClose | NO | | +| QueueCloseV2 | NO | | +| QueueDequeue | YES | | +| QueueDequeueMany | YES | | +| QueueDequeueManyV2 | NO | | +| QueueDequeueUpTo | YES | | +| QueueDequeueUpToV2 | YES | | +| QueueDequeueV2 | YES | | +| QueueEnqueue | NO | | +| QueueEnqueueMany | NO | | +| QueueEnqueueManyV2 | NO | | +| QueueEnqueueV2 | NO | | +| QueueIsClosed | NO | | +| QueueIsClosedV2 | NO | | +| QueueSize | NO | | +| QueueSizeV2 | NO | | +| RFFT | NO | | +| RFFT2D | NO | | +| RFFT3D | NO | | +| RGBToHSV | NO | | +| RaggedBincount | NO | | +| RaggedCountSparseOutput | NO | | +| RaggedCross | NO | | +| RaggedFillEmptyRows | NO | | +| RaggedFillEmptyRowsGrad | NO | | +| RaggedGather | NO | | +| RaggedRange | NO | | +| RaggedTensorFromVariant | NO | | +| RaggedTensorToSparse | NO | | +| RaggedTensorToTensor | NO | | +| RaggedTensorToVariant | NO | | +| RaggedTensorToVariantGradient | NO | | +| RandomCrop | NO | | +| RandomDataset | NO | | +| RandomDatasetV2 | NO | | +| RandomGamma | NO | | +| RandomGammaGrad | NO | | +| RandomIndexShuffle | NO | | +| RandomPoisson | NO | | +| RandomPoissonV2 | NO | | +| RandomShuffle | NO | | +| RandomShuffleQueue | NO | | +| RandomShuffleQueueV2 | NO | | +| RandomStandardNormal | NO | | +| RandomUniform | YES | | +| RandomUniformInt | YES | | +| Range | YES | | +| RangeDataset | NO | | +| Rank | YES | | +| ReadFile | NO | | +| ReadVariableOp | YES | | +| ReadVariableXlaSplitND | NO | | +| ReaderNumRecordsProduced | NO | | +| ReaderNumRecordsProducedV2 | NO | | +| ReaderNumWorkUnitsCompleted | NO | | +| ReaderNumWorkUnitsCompletedV2 | NO | | +| ReaderRead | NO | | +| ReaderReadUpTo | NO | | +| ReaderReadUpToV2 | NO | | +| ReaderReadV2 | NO | | +| ReaderReset | NO | | +| ReaderResetV2 | NO | | +| ReaderRestoreState | NO | | +| ReaderRestoreStateV2 | NO | | +| ReaderSerializeState | NO | | +| ReaderSerializeStateV2 | NO | | +| Real | NO | | +| RealDiv | YES | | +| RebatchDataset | NO | | +| RebatchDatasetV2 | NO | | +| Reciprocal | YES | | +| ReciprocalGrad | NO | | +| RecordInput | NO | | +| Recv | NO | | +| RecvTPUEmbeddingActivations | NO | | +| ReduceDataset | NO | | +| ReduceJoin | NO | | +| RefEnter | NO | | +| RefExit | NO | | +| RefIdentity | NO | | +| RefMerge | NO | | +| RefNextIteration | NO | | +| RefSelect | NO | | +| RefSwitch | NO | | +| RegexFullMatch | NO | | +| RegexReplace | NO | | +| RegisterDataset | NO | | +| RegisterDatasetV2 | NO | | +| Relu | YES | | +| Relu6 | YES | | +| Relu6Grad | NO | | +| ReluGrad | NO | | +| RemoteCall | NO | | +| RepeatDataset | NO | | +| RequantizationRange | NO | | +| RequantizationRangePerChannel | NO | | +| Requantize | NO | | +| RequantizePerChannel | NO | | +| Reshape | YES | | +| ResizeArea | NO | | +| ResizeBicubic | NO | | +| ResizeBicubicGrad | NO | | +| ResizeBilinear | YES | | +| ResizeBilinearGrad | NO | | +| ResizeNearestNeighbor | YES | | +| ResizeNearestNeighborGrad | NO | | +| ResourceAccumulatorApplyGradient | NO | | +| ResourceAccumulatorNumAccumulated | NO | | +| ResourceAccumulatorSetGlobalStep | NO | | +| ResourceAccumulatorTakeGradient | NO | | +| ResourceApplyAdaMax | NO | | +| ResourceApplyAdadelta | NO | | +| ResourceApplyAdagrad | NO | | +| ResourceApplyAdagradDA | NO | | +| ResourceApplyAdagradV2 | NO | | +| ResourceApplyAdam | NO | | +| ResourceApplyAdamWithAmsgrad | NO | | +| ResourceApplyAddSign | NO | | +| ResourceApplyCenteredRMSProp | NO | | +| ResourceApplyFtrl | NO | | +| ResourceApplyFtrlV2 | NO | | +| ResourceApplyGradientDescent | NO | | +| ResourceApplyKerasMomentum | NO | | +| ResourceApplyMomentum | NO | | +| ResourceApplyPowerSign | NO | | +| ResourceApplyProximalAdagrad | NO | | +| ResourceApplyProximalGradientDescent | NO | | +| ResourceApplyRMSProp | NO | | +| ResourceConditionalAccumulator | NO | | +| ResourceCountUpTo | NO | | +| ResourceGather | YES | | +| ResourceGatherNd | NO | | +| ResourceScatterAdd | NO | | +| ResourceScatterDiv | NO | | +| ResourceScatterMax | NO | | +| ResourceScatterMin | NO | | +| ResourceScatterMul | NO | | +| ResourceScatterNdAdd | NO | | +| ResourceScatterNdMax | NO | | +| ResourceScatterNdMin | NO | | +| ResourceScatterNdSub | NO | | +| ResourceScatterNdUpdate | NO | | +| ResourceScatterSub | NO | | +| ResourceScatterUpdate | NO | | +| ResourceSparseApplyAdadelta | NO | | +| ResourceSparseApplyAdagrad | NO | | +| ResourceSparseApplyAdagradDA | NO | | +| ResourceSparseApplyAdagradV2 | NO | | +| ResourceSparseApplyCenteredRMSProp | NO | | +| ResourceSparseApplyFtrl | NO | | +| ResourceSparseApplyFtrlV2 | NO | | +| ResourceSparseApplyKerasMomentum | NO | | +| ResourceSparseApplyMomentum | NO | | +| ResourceSparseApplyProximalAdagrad | NO | | +| ResourceSparseApplyProximalGradientDescent | NO | | +| ResourceSparseApplyRMSProp | NO | | +| ResourceStridedSliceAssign | NO | | +| Restore | NO | | +| RestoreSlice | NO | | +| RestoreV2 | YES | | +| RetrieveTPUEmbeddingADAMParameters | NO | | +| RetrieveTPUEmbeddingAdadeltaParameters | NO | | +| RetrieveTPUEmbeddingAdagradMomentumParameters | NO | | +| RetrieveTPUEmbeddingAdagradParameters | NO | | +| RetrieveTPUEmbeddingCenteredRMSPropParameters | NO | | +| RetrieveTPUEmbeddingFTRLParameters | NO | | +| RetrieveTPUEmbeddingFrequencyEstimatorParameters | NO | | +| RetrieveTPUEmbeddingMDLAdagradLightParameters | NO | | +| RetrieveTPUEmbeddingMomentumParameters | NO | | +| RetrieveTPUEmbeddingProximalAdagradParameters | NO | | +| RetrieveTPUEmbeddingProximalYogiParameters | NO | | +| RetrieveTPUEmbeddingRMSPropParameters | NO | | +| RetrieveTPUEmbeddingStochasticGradientDescentParameters | NO | | +| Reverse | YES | | +| ReverseSequence | YES | | +| ReverseV2 | YES | | +| RewriteDataset | NO | | +| RightShift | NO | | +| Rint | NO | | +| RngReadAndSkip | NO | | +| RngSkip | NO | | +| Roll | YES | | +| Round | YES | | +| Rsqrt | YES | | +| RsqrtGrad | NO | | +| SampleDistortedBoundingBox | NO | | +| SampleDistortedBoundingBoxV2 | NO | | +| SamplingDataset | NO | | +| Save | NO | | +| SaveDataset | NO | | +| SaveDatasetV2 | NO | | +| SaveSlices | NO | | +| SaveV2 | YES | | +| ScalarSummary | NO | | +| ScaleAndTranslate | NO | | +| ScaleAndTranslateGrad | NO | | +| ScanDataset | NO | | +| ScatterAdd | NO | | +| ScatterDiv | NO | | +| ScatterMax | NO | | +| ScatterMin | NO | | +| ScatterMul | NO | | +| ScatterNd | YES | | +| ScatterNdAdd | NO | | +| ScatterNdMax | NO | | +| ScatterNdMin | NO | | +| ScatterNdNonAliasingAdd | NO | | +| ScatterNdSub | NO | | +| ScatterNdUpdate | NO | | +| ScatterSub | NO | | +| ScatterUpdate | NO | | +| SdcaFprint | NO | | +| SdcaOptimizer | NO | | +| SdcaOptimizerV2 | NO | | +| SdcaShrinkL1 | NO | | +| SegmentMax | NO | | +| SegmentMaxV2 | NO | | +| SegmentMean | NO | | +| SegmentMin | NO | | +| SegmentMinV2 | NO | | +| SegmentProd | NO | | +| SegmentProdV2 | NO | | +| SegmentSum | YES | | +| SegmentSumV2 | NO | | +| Select | YES | | +| SelectV2 | YES | | +| SelfAdjointEig | NO | | +| SelfAdjointEigV2 | NO | | +| Selu | YES | | +| SeluGrad | NO | | +| Send | NO | | +| SendTPUEmbeddingGradients | NO | | +| SerializeIterator | NO | | +| SerializeManySparse | NO | | +| SerializeSparse | NO | | +| SerializeTensor | NO | | +| SetSize | NO | | +| SetStatsAggregatorDataset | NO | | +| Shape | YES | | +| ShapeN | YES | | +| ShardDataset | NO | | +| ShardedFilename | YES | | +| ShardedFilespec | NO | | +| ShuffleAndRepeatDataset | NO | | +| ShuffleAndRepeatDatasetV2 | NO | | +| ShuffleDataset | NO | | +| ShuffleDatasetV2 | NO | | +| ShuffleDatasetV3 | NO | | +| ShutdownDistributedTPU | NO | | +| Sigmoid | YES | | +| SigmoidGrad | NO | | +| Sign | YES | | +| Sin | YES | | +| Sinh | YES | | +| Size | YES | | +| SkipDataset | NO | | +| SleepDataset | NO | | +| Slice | YES | | +| SlidingWindowDataset | NO | | +| Snapshot | YES | | +| SnapshotChunkDataset | NO | | +| SnapshotDataset | NO | | +| SnapshotDatasetReader | NO | | +| SnapshotDatasetV2 | NO | | +| SnapshotNestedDatasetReader | NO | | +| SobolSample | NO | | +| Softmax | YES | | +| SoftmaxCrossEntropyWithLogits | NO | | +| Softplus | YES | | +| SoftplusGrad | NO | | +| Softsign | YES | | +| SoftsignGrad | NO | | +| SpaceToBatch | NO | | +| SpaceToBatchND | YES | | +| SpaceToDepth | YES | | +| SparseAccumulatorApplyGradient | NO | | +| SparseAccumulatorTakeGradient | NO | | +| SparseAdd | NO | | +| SparseAddGrad | NO | | +| SparseApplyAdadelta | NO | | +| SparseApplyAdagrad | NO | | +| SparseApplyAdagradDA | NO | | +| SparseApplyAdagradV2 | NO | | +| SparseApplyCenteredRMSProp | NO | | +| SparseApplyFtrl | NO | | +| SparseApplyFtrlV2 | NO | | +| SparseApplyMomentum | NO | | +| SparseApplyProximalAdagrad | NO | | +| SparseApplyProximalGradientDescent | NO | | +| SparseApplyRMSProp | NO | | +| SparseBincount | NO | | +| SparseConcat | NO | | +| SparseConditionalAccumulator | NO | | +| SparseCountSparseOutput | NO | | +| SparseCross | NO | | +| SparseCrossHashed | NO | | +| SparseCrossV2 | NO | | +| SparseDenseCwiseAdd | NO | | +| SparseDenseCwiseDiv | NO | | +| SparseDenseCwiseMul | NO | | +| SparseFillEmptyRows | YES | | +| SparseFillEmptyRowsGrad | NO | | +| SparseMatMul | NO | | +| SparseMatrixAdd | NO | | +| SparseMatrixMatMul | NO | | +| SparseMatrixMul | NO | | +| SparseMatrixNNZ | NO | | +| SparseMatrixOrderingAMD | NO | | +| SparseMatrixSoftmax | NO | | +| SparseMatrixSoftmaxGrad | NO | | +| SparseMatrixSparseCholesky | NO | | +| SparseMatrixSparseMatMul | NO | | +| SparseMatrixTranspose | NO | | +| SparseMatrixZeros | NO | | +| SparseReduceMax | NO | | +| SparseReduceMaxSparse | NO | | +| SparseReduceSum | NO | | +| SparseReduceSumSparse | NO | | +| SparseReorder | NO | | +| SparseReshape | YES | | +| SparseSegmentMean | NO | | +| SparseSegmentMeanGrad | NO | | +| SparseSegmentMeanGradV2 | NO | | +| SparseSegmentMeanWithNumSegments | NO | | +| SparseSegmentSqrtN | NO | | +| SparseSegmentSqrtNGrad | NO | | +| SparseSegmentSqrtNGradV2 | NO | | +| SparseSegmentSqrtNWithNumSegments | NO | | +| SparseSegmentSum | YES | | +| SparseSegmentSumGrad | NO | | +| SparseSegmentSumGradV2 | NO | | +| SparseSegmentSumWithNumSegments | NO | | +| SparseSlice | NO | | +| SparseSliceGrad | NO | | +| SparseSoftmax | NO | | +| SparseSoftmaxCrossEntropyWithLogits | NO | | +| SparseSparseMaximum | NO | | +| SparseSparseMinimum | NO | | +| SparseSplit | NO | | +| SparseTensorDenseAdd | NO | | +| SparseTensorDenseMatMul | NO | | +| SparseTensorSliceDataset | NO | | +| SparseTensorToCSRSparseMatrix | NO | | +| SparseToDense | YES | | +| SparseToSparseSetOperation | NO | | +| Spence | NO | | +| Split | YES | | +| SplitV | YES | | +| SqlDataset | NO | | +| Sqrt | YES | | +| SqrtGrad | NO | | +| Square | YES | | +| SquaredDifference | YES | | +| Squeeze | YES | | +| Stack | NO | | +| StackClose | NO | | +| StackCloseV2 | NO | | +| StackPop | NO | | +| StackPopV2 | NO | | +| StackPush | NO | | +| StackPushV2 | NO | | +| StackV2 | NO | | +| Stage | NO | | +| StageClear | NO | | +| StagePeek | NO | | +| StageSize | NO | | +| StatefulPartitionedCall | YES | | +| StatefulRandomBinomial | NO | | +| StatefulStandardNormal | NO | | +| StatefulStandardNormalV2 | NO | | +| StatefulTruncatedNormal | NO | | +| StatefulUniform | NO | | +| StatefulUniformFullInt | NO | | +| StatefulUniformInt | NO | | +| StatelessCase | NO | | +| StatelessIf | YES | | +| StatelessMultinomial | NO | | +| StatelessParameterizedTruncatedNormal | NO | | +| StatelessRandomBinomial | NO | | +| StatelessRandomGammaV2 | NO | | +| StatelessRandomGammaV3 | NO | | +| StatelessRandomGetAlg | NO | | +| StatelessRandomGetKeyCounter | NO | | +| StatelessRandomGetKeyCounterAlg | NO | | +| StatelessRandomNormal | NO | | +| StatelessRandomNormalV2 | NO | | +| StatelessRandomPoisson | NO | | +| StatelessRandomUniform | NO | | +| StatelessRandomUniformFullInt | NO | | +| StatelessRandomUniformFullIntV2 | NO | | +| StatelessRandomUniformInt | NO | | +| StatelessRandomUniformIntV2 | NO | | +| StatelessRandomUniformV2 | NO | | +| StatelessSampleDistortedBoundingBox | NO | | +| StatelessShuffle | NO | | +| StatelessTruncatedNormal | NO | | +| StatelessTruncatedNormalV2 | NO | | +| StatelessWhile | YES | | +| StaticRegexFullMatch | YES | | +| StaticRegexReplace | NO | | +| StatsAggregatorHandle | NO | | +| StatsAggregatorHandleV2 | NO | | +| StatsAggregatorSetSummaryWriter | NO | | +| StatsAggregatorSummary | NO | | +| StopGradient | YES | | +| StridedSlice | YES | | +| StridedSliceAssign | NO | | +| StridedSliceGrad | NO | | +| StringFormat | NO | | +| StringJoin | YES | | +| StringLength | NO | | +| StringLower | NO | | +| StringNGrams | NO | | +| StringSplit | NO | | +| StringSplitV2 | NO | | +| StringStrip | NO | | +| StringToHashBucket | NO | | +| StringToHashBucketFast | NO | | +| StringToHashBucketStrong | NO | | +| StringToNumber | NO | | +| StringUpper | NO | | +| Sub | YES | | +| Substr | NO | | +| Sum | YES | | +| SummaryWriter | NO | | +| Svd | NO | | +| Switch | YES | | +| SymbolicGradient | NO | | +| SyncDevice | NO | | +| TFRecordDataset | NO | | +| TFRecordDatasetV2 | NO | | +| TFRecordReader | NO | | +| TFRecordReaderV2 | NO | | +| TPUCompilationResult | NO | | +| TPUEmbeddingActivations | NO | | +| TPUOrdinalSelector | NO | | +| TPUPartitionedCall | NO | | +| TPUPartitionedInput | NO | | +| TPUPartitionedInputV2 | NO | | +| TPUPartitionedOutput | NO | | +| TPUPartitionedOutputV2 | NO | | +| TPUReplicateMetadata | NO | | +| TPUReplicatedInput | NO | | +| TPUReplicatedOutput | NO | | +| TakeDataset | NO | | +| TakeManySparseFromTensorsMap | NO | | +| TakeWhileDataset | NO | | +| Tan | YES | | +| Tanh | YES | | +| TanhGrad | NO | | +| TemporaryVariable | NO | | +| TensorArray | NO | | +| TensorArrayClose | NO | | +| TensorArrayCloseV2 | NO | | +| TensorArrayCloseV3 | YES | | +| TensorArrayConcat | NO | | +| TensorArrayConcatV2 | NO | | +| TensorArrayConcatV3 | YES | | +| TensorArrayGather | NO | | +| TensorArrayGatherV2 | NO | | +| TensorArrayGatherV3 | YES | | +| TensorArrayGrad | NO | | +| TensorArrayGradV2 | NO | | +| TensorArrayGradV3 | NO | | +| TensorArrayGradWithShape | NO | | +| TensorArrayPack | NO | | +| TensorArrayRead | NO | | +| TensorArrayReadV2 | NO | | +| TensorArrayReadV3 | YES | | +| TensorArrayScatter | NO | | +| TensorArrayScatterV2 | NO | | +| TensorArrayScatterV3 | YES | | +| TensorArraySize | NO | | +| TensorArraySizeV2 | NO | | +| TensorArraySizeV3 | YES | | +| TensorArraySplit | NO | | +| TensorArraySplitV2 | NO | | +| TensorArraySplitV3 | NO | | +| TensorArrayUnpack | NO | | +| TensorArrayV2 | NO | | +| TensorArrayV3 | YES | | +| TensorArrayWrite | NO | | +| TensorArrayWriteV2 | NO | | +| TensorArrayWriteV3 | YES | | +| TensorDataset | NO | | +| TensorListConcat | NO | | +| TensorListConcatLists | NO | | +| TensorListConcatV2 | NO | | +| TensorListElementShape | NO | | +| TensorListFromTensor | YES | | +| TensorListGather | NO | | +| TensorListGetItem | YES | | +| TensorListLength | YES | | +| TensorListPopBack | NO | | +| TensorListPushBack | YES | | +| TensorListPushBackBatch | NO | | +| TensorListReserve | YES | | +| TensorListResize | YES | | +| TensorListScatter | NO | | +| TensorListScatterIntoExistingList | NO | | +| TensorListScatterV2 | NO | | +| TensorListSetItem | YES | | +| TensorListSplit | NO | | +| TensorListStack | YES | | +| TensorScatterAdd | NO | | +| TensorScatterMax | NO | | +| TensorScatterMin | NO | | +| TensorScatterSub | NO | | +| TensorScatterUpdate | NO | | +| TensorSliceDataset | NO | | +| TensorStridedSliceUpdate | NO | | +| TensorSummary | NO | | +| TensorSummaryV2 | NO | | +| TextLineDataset | NO | | +| TextLineReader | NO | | +| TextLineReaderV2 | NO | | +| ThreadPoolDataset | NO | | +| ThreadPoolHandle | NO | | +| ThreadUnsafeUnigramCandidateSampler | NO | | +| Tile | YES | | +| TileGrad | NO | | +| Timestamp | NO | | +| ToBool | YES | | +| TopK | YES | | +| TopKV2 | YES | | +| Transpose | YES | | +| TridiagonalMatMul | NO | | +| TridiagonalSolve | NO | | +| TruncateDiv | YES | | +| TruncateMod | YES | | +| TruncatedNormal | NO | | +| Unbatch | NO | | +| UnbatchDataset | NO | | +| UnbatchGrad | NO | | +| UncompressElement | NO | | +| UnicodeDecode | NO | | +| UnicodeDecodeWithOffsets | NO | | +| UnicodeEncode | NO | | +| UnicodeScript | NO | | +| UnicodeTranscode | NO | | +| UniformCandidateSampler | NO | | +| UniformDequantize | NO | | +| UniformQuantize | NO | | +| UniformQuantizedAdd | NO | | +| UniformQuantizedClipByValue | NO | | +| UniformQuantizedConvolution | NO | | +| UniformQuantizedConvolutionHybrid | NO | | +| UniformQuantizedDot | NO | | +| UniformQuantizedDotHybrid | NO | | +| UniformRequantize | NO | | +| Unique | YES | | +| UniqueDataset | NO | | +| UniqueV2 | NO | | +| UniqueWithCounts | NO | | +| UniqueWithCountsV2 | NO | | +| Unpack | YES | | +| UnravelIndex | YES | | +| UnsortedSegmentJoin | NO | | +| UnsortedSegmentMax | NO | | +| UnsortedSegmentMin | NO | | +| UnsortedSegmentProd | NO | | +| UnsortedSegmentSum | YES | | +| Unstage | NO | | +| UnwrapDatasetVariant | NO | | +| UpperBound | NO | | +| VarHandleOp | YES | | +| VarIsInitializedOp | YES | | +| Variable | YES | | +| VariableShape | NO | | +| VariableV2 | YES | | +| Where | YES | | +| While | YES | | +| WholeFileReader | NO | | +| WholeFileReaderV2 | NO | | +| WindowDataset | NO | | +| WindowOp | NO | | +| WorkerHeartbeat | NO | | +| WrapDatasetVariant | NO | | +| WriteAudioSummary | NO | | +| WriteFile | NO | | +| WriteGraphSummary | NO | | +| WriteHistogramSummary | NO | | +| WriteImageSummary | NO | | +| WriteRawProtoSummary | NO | | +| WriteScalarSummary | NO | | +| WriteSummary | NO | | +| Xdivy | YES | | +| XlaConcatND | NO | | +| XlaSplitND | NO | | +| Xlog1py | YES | | +| Xlogy | YES | | +| ZerosLike | YES | | +| Zeta | NO | | +| ZipDataset | NO | | diff --git a/src/frontends/tensorflow/src/checkpoint_v1_reader.cpp b/src/frontends/tensorflow/src/checkpoint_v1_reader.cpp index 33833100ad6c6f..185b374e6bc42f 100644 --- a/src/frontends/tensorflow/src/checkpoint_v1_reader.cpp +++ b/src/frontends/tensorflow/src/checkpoint_v1_reader.cpp @@ -7,7 +7,7 @@ #include "checkpoint_utils.hpp" #include "openvino/frontend/exception.hpp" #include "openvino/util/file_util.hpp" -#include "saved_tensor_slice.pb.h" +#include "ov_tensorflow/saved_tensor_slice.pb.h" #include "tf_utils.hpp" #ifdef ENABLE_SNAPPY_COMPRESSION diff --git a/src/frontends/tensorflow/src/checkpoint_v1_reader.hpp b/src/frontends/tensorflow/src/checkpoint_v1_reader.hpp index bfae3b139a2aae..1171fd6a682cb1 100644 --- a/src/frontends/tensorflow/src/checkpoint_v1_reader.hpp +++ b/src/frontends/tensorflow/src/checkpoint_v1_reader.hpp @@ -12,9 +12,9 @@ #include "checkpoint_utils.hpp" #include "openvino/core/any.hpp" #include "openvino/frontend/exception.hpp" -#include "saved_tensor_slice.pb.h" -#include "tensor_shape.pb.h" -#include "types.pb.h" +#include "ov_tensorflow/saved_tensor_slice.pb.h" +#include "ov_tensorflow/tensor_shape.pb.h" +#include "ov_tensorflow/types.pb.h" namespace ov { namespace frontend { diff --git a/src/frontends/tensorflow/src/decoder_argdef.cpp b/src/frontends/tensorflow/src/decoder_argdef.cpp index 3430bcbe5e37aa..af7c1a1cfccd01 100644 --- a/src/frontends/tensorflow/src/decoder_argdef.cpp +++ b/src/frontends/tensorflow/src/decoder_argdef.cpp @@ -5,11 +5,11 @@ #include "decoder_argdef.hpp" #include "decoder_proto.hpp" -#include "op_def.pb.h" #include "openvino/frontend/tensorflow/node_context.hpp" #include "openvino/frontend/tensorflow/special_types.hpp" +#include "ov_tensorflow/op_def.pb.h" +#include "ov_tensorflow/types.pb.h" #include "tf_utils.hpp" -#include "types.pb.h" namespace ov { namespace frontend { diff --git a/src/frontends/tensorflow/src/decoder_proto.cpp b/src/frontends/tensorflow/src/decoder_proto.cpp index 2488973c1029e1..9e0a53efb6d09f 100644 --- a/src/frontends/tensorflow/src/decoder_proto.cpp +++ b/src/frontends/tensorflow/src/decoder_proto.cpp @@ -4,12 +4,12 @@ #include "decoder_proto.hpp" -#include "attr_value.pb.h" -#include "node_def.pb.h" #include "openvino/frontend/tensorflow/node_context.hpp" #include "openvino/frontend/tensorflow/special_types.hpp" +#include "ov_tensorflow/attr_value.pb.h" +#include "ov_tensorflow/node_def.pb.h" +#include "ov_tensorflow/types.pb.h" #include "tf_utils.hpp" -#include "types.pb.h" namespace ov { namespace frontend { diff --git a/src/frontends/tensorflow/src/decoder_proto.hpp b/src/frontends/tensorflow/src/decoder_proto.hpp index 338bfdeccea79d..9d22e273e1e146 100644 --- a/src/frontends/tensorflow/src/decoder_proto.hpp +++ b/src/frontends/tensorflow/src/decoder_proto.hpp @@ -9,7 +9,7 @@ #include "openvino/core/type/element_type.hpp" #include "openvino/frontend/tensorflow/decoder.hpp" -#include "types.pb.h" +#include "ov_tensorflow/types.pb.h" namespace tensorflow { class GraphDef; diff --git a/src/frontends/tensorflow/src/frontend.cpp b/src/frontends/tensorflow/src/frontend.cpp index 24b5824fe336d1..ad9b5b76bdfbda 100644 --- a/src/frontends/tensorflow/src/frontend.cpp +++ b/src/frontends/tensorflow/src/frontend.cpp @@ -14,6 +14,7 @@ #include "helper_transforms/embedding_segments_feature_fusing.hpp" #include "helper_transforms/gru_block_cell_replacer.hpp" #include "helper_transforms/saved_model_unused_remover.hpp" +#include "helper_transforms/tensor_array_v3_replacer.hpp" #include "input_model.hpp" #include "op_table.hpp" #include "openvino/core/so_extension.hpp" @@ -491,6 +492,7 @@ void FrontEnd::normalize(const std::shared_ptr& model) const { manager.register_pass(); manager.register_pass(); manager.register_pass(); + manager.register_pass(); manager.register_pass(); manager.register_pass(); manager.register_pass(); diff --git a/src/frontends/tensorflow/src/graph_iterator_meta.cpp b/src/frontends/tensorflow/src/graph_iterator_meta.cpp index 8bc41fbaefdd04..06f2d31f389a27 100644 --- a/src/frontends/tensorflow/src/graph_iterator_meta.cpp +++ b/src/frontends/tensorflow/src/graph_iterator_meta.cpp @@ -10,8 +10,8 @@ #include #include "openvino/core/type/element_type.hpp" -#include "tensor_bundle.pb.h" -#include "trackable_object_graph.pb.h" +#include "ov_tensorflow/tensor_bundle.pb.h" +#include "ov_tensorflow/trackable_object_graph.pb.h" namespace ov { namespace frontend { diff --git a/src/frontends/tensorflow/src/graph_iterator_proto.hpp b/src/frontends/tensorflow/src/graph_iterator_proto.hpp index 8b073b08373305..5ef6d0a5954b41 100644 --- a/src/frontends/tensorflow/src/graph_iterator_proto.hpp +++ b/src/frontends/tensorflow/src/graph_iterator_proto.hpp @@ -10,10 +10,10 @@ #include "checkpoint_v1_reader.hpp" #include "decoder_argdef.hpp" #include "decoder_proto.hpp" -#include "graph.pb.h" #include "openvino/frontend/exception.hpp" #include "openvino/frontend/graph_iterator.hpp" #include "openvino/frontend/tensorflow/decoder.hpp" +#include "ov_tensorflow/graph.pb.h" namespace ov { namespace frontend { diff --git a/src/frontends/tensorflow/src/graph_iterator_saved_model.cpp b/src/frontends/tensorflow/src/graph_iterator_saved_model.cpp index ece0148d19bb20..803e7d694bc69a 100644 --- a/src/frontends/tensorflow/src/graph_iterator_saved_model.cpp +++ b/src/frontends/tensorflow/src/graph_iterator_saved_model.cpp @@ -10,8 +10,8 @@ #include #include "openvino/core/type/element_type.hpp" -#include "tensor_bundle.pb.h" -#include "trackable_object_graph.pb.h" +#include "ov_tensorflow/tensor_bundle.pb.h" +#include "ov_tensorflow/trackable_object_graph.pb.h" namespace ov { namespace frontend { diff --git a/src/frontends/tensorflow/src/graph_iterator_saved_model.hpp b/src/frontends/tensorflow/src/graph_iterator_saved_model.hpp index 511f2a0a5bc307..4cb385e66f744d 100644 --- a/src/frontends/tensorflow/src/graph_iterator_saved_model.hpp +++ b/src/frontends/tensorflow/src/graph_iterator_saved_model.hpp @@ -8,7 +8,7 @@ #include "graph_iterator_proto.hpp" #include "openvino/util/file_util.hpp" -#include "saved_model.pb.h" +#include "ov_tensorflow/saved_model.pb.h" #include "variables_index.hpp" namespace ov { diff --git a/src/frontends/tensorflow/src/op/merge.cpp b/src/frontends/tensorflow/src/op/merge.cpp index 3594f93ed08278..708de72aa3434f 100644 --- a/src/frontends/tensorflow/src/op/merge.cpp +++ b/src/frontends/tensorflow/src/op/merge.cpp @@ -5,6 +5,8 @@ #include "helper_ops/merge.hpp" #include "common_op_table.hpp" +#include "helper_ops/enter.hpp" +#include "helper_ops/next_iteration.hpp" #include "openvino/frontend/tensorflow/node_context.hpp" #include "openvino/op/constant.hpp" #include "utils.hpp" @@ -24,20 +26,47 @@ OutputVector translate_merge_op(const NodeContext& node) { auto node_name = node.get_name(); default_op_checks(node, 1, {"Merge"}); int input_size = static_cast(node.get_input_size()); - OutputVector inputs; + OutputVector inputs(input_size); for (int input_ind = 0; input_ind < input_size; ++input_ind) { - inputs.push_back(node.get_input(input_ind)); + inputs[input_ind] = node.get_input(input_ind); } // if Merge node has just one input, there is nothing to merge // return the same input and value_index equal to 0 - if (inputs.size() == 1) { + if (input_size == 1) { auto value_index = make_shared(element::i32, Shape{}, 0); value_index->output(0).set_names({node_name + ":1"}); inputs[0].add_names({node_name + ":0"}); return OutputVector{inputs[0], value_index}; } + // check if it is a case of TF1 While: Enter, NextIteration are going to Merge node + // in this case it can refine output shape and type for NextIteration based on Enter + if (input_size == 2) { + auto enter = as_type_ptr(inputs[0].get_node_shared_ptr()); + if (!enter) { + enter = as_type_ptr(inputs[1].get_node_shared_ptr()); + } + auto next_iteration = as_type_ptr(inputs[0].get_node_shared_ptr()); + if (!next_iteration) { + next_iteration = as_type_ptr(inputs[1].get_node_shared_ptr()); + } + + if (enter && next_iteration) { + // set output type and shape for NextIteration + // borrow them from Enter output + auto enter_output_type = enter->output(0).get_element_type(); + auto enter_output_shape = enter->output(0).get_partial_shape(); + auto next_iteration_output_shape = PartialShape::dynamic(enter_output_shape.rank()); + next_iteration->set_output_shape_and_type(next_iteration_output_shape, enter_output_type); + + // reset inputs + // refines input shapes and types for Merge node + inputs[0] = enter->output(0); + inputs[1] = next_iteration->output(0); + } + } + auto merge_node = make_shared(inputs, node.get_decoder()); set_node_name(node.get_name(), merge_node); diff --git a/src/frontends/tensorflow/src/op/tensor_array_operations.cpp b/src/frontends/tensorflow/src/op/tensor_array_operations.cpp new file mode 100644 index 00000000000000..c1b3d6ac205dc3 --- /dev/null +++ b/src/frontends/tensorflow/src/op/tensor_array_operations.cpp @@ -0,0 +1,332 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_op_table.hpp" +#include "helper_ops/enter.hpp" +#include "helper_ops/tensor_array.hpp" +#include "openvino/frontend/tensorflow/node_context.hpp" +#include "openvino/op/add.hpp" +#include "openvino/op/broadcast.hpp" +#include "openvino/op/concat.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/convert.hpp" +#include "openvino/op/gather.hpp" +#include "openvino/op/maximum.hpp" +#include "openvino/op/multiply.hpp" +#include "openvino/op/reshape.hpp" +#include "openvino/op/scatter_nd_update.hpp" +#include "openvino/op/scatter_update.hpp" +#include "openvino/op/shape_of.hpp" +#include "openvino/op/slice.hpp" +#include "openvino/op/subtract.hpp" +#include "openvino/op/unsqueeze.hpp" +#include "utils.hpp" + +using namespace std; +using namespace ov; +using namespace ov::op; +using namespace ov::frontend::tensorflow; + +namespace ov { +namespace frontend { +namespace tensorflow { +namespace op { + +namespace { +// the function creates the constant imitating initial tensor array container +Output create_initial_tensor_array_constant(int64_t tensor_element_rank, + const element::Type& element_type, + Output size, + const string& node_name) { + // adjust size to have it of shape [1] for further concatenation with element shape + auto new_size_shape = make_shared(element::i32, Shape{1}, 1); + size = make_shared(size, new_size_shape, false); + + // create a vector of size element_shape.rank() with ones + // and compute a shape of initial tensor array [size, 1, ..., 1] + vector ones(tensor_element_rank, 1); + auto ones_const = make_shared(element::i32, Shape{ones.size()}, ones); + auto target_shape = make_shared(OutputVector{size, ones_const}, 0); + + // create initial tensor array + auto scalar_value = make_shared(element_type, Shape{}, vector{0}); + auto initial_tensor_array = make_shared(scalar_value, target_shape); + + return initial_tensor_array->output(0); +} +} // namespace + +OutputVector translate_tensor_array_v3_op(const NodeContext& node) { + // TensorArrayV3 has just one input: + // 0) size to initialize a size of tensor array + default_op_checks(node, 1, {"TensorArrayV3"}); + auto dtype = node.get_attribute("dtype"); + auto size = node.get_input(0); + auto element_shape = node.get_attribute("element_shape"); + + if (element_shape.rank().is_static()) { + auto node_name = node.get_name(); + auto new_output1 = + create_initial_tensor_array_constant(element_shape.rank().get_length(), dtype, size, node.get_name()); + new_output1.set_names({node_name + ":0"}); + auto new_output2 = + create_initial_tensor_array_constant(element_shape.rank().get_length(), dtype, size, node.get_name()); + new_output2.set_names({node_name + ":1"}); + return OutputVector{new_output1, new_output2}; + } + + // dynamic case when it is unable retrieve element rank from the attribute + auto tensor_array_v3 = make_shared(size, dtype, node.get_decoder()); + set_node_name(node.get_name(), tensor_array_v3); + + return tensor_array_v3->outputs(); +} + +OutputVector translate_tensor_array_scatter_v3_op(const NodeContext& node) { + // TensorArrayScatterV3 has four inputs: + // 0) handle, a Tensor of type resource. The handle to a TensorArray. + // 1) indices, a Tensor of type int32. The locations at which to write the tensor elements. + // 2) value, a Tensor. The concatenated tensor to write to the TensorArray + // 3) flow_in A Tensor of type float32. A float scalar that enforces proper chaining of operations. + // The operation has one output: + // 0) flow_out indicates that operation is complete and handle resource is updated + default_op_checks(node, 4, {"TensorArrayScatterV3"}); + auto indices = node.get_input(1); + auto value = node.get_input(2); + // flow_in is used for transferring input tensor array + auto tensor_array = node.get_input(3); + + // check if producer of tensor_array is TensorArrayV3, internal operation, still + // if yes, try to replace it with constant container + if (as_type_ptr(tensor_array.get_node_shared_ptr()) && + value.get_partial_shape().rank().is_static()) { + // set tensor element rank that gets known from TensorArrayScatterV3 operation + auto tensor_array_v3 = as_type_ptr(tensor_array.get_node_shared_ptr()); + TENSORFLOW_OP_VALIDATION( + node, + value.get_partial_shape().rank().get_length() > 0, + "[TensorFlow Frontend] internal error or inconsistent model: value to TensorArrayScatterV3 is a scalar"); + int64_t tensor_element_rank = value.get_partial_shape().rank().get_length() - 1; + tensor_array_v3->set_element_rank(tensor_element_rank); + } + + // compute element shape (shape of a tensor in the tensor array) using value + auto element_shape = make_shared(value, element::i32)->output(0); + auto one_const = make_shared(element::i32, Shape{1}, 1); + auto max_const = make_shared(element::i32, Shape{1}, numeric_limits::max()); + element_shape = make_shared(element_shape, one_const, max_const, one_const); + + // compute size of tensor array + auto tensor_array_size = make_shared(tensor_array, element::i32)->output(0); + auto zero_const = make_shared(element::i32, Shape{1}, 0); + tensor_array_size = make_shared(tensor_array_size, zero_const, zero_const); + + // compute the new shape for tensor array where new tensors will be inserted + auto new_shape = make_shared(OutputVector{tensor_array_size, element_shape}, 0); + tensor_array = make_shared(tensor_array, new_shape); + + // adjust indices for ScatterNDUpdate to have a shape [N, 1] where N is a number of indices + indices = make_shared(indices, one_const); + + // compute updated tensor array using ScatterNDUpdate + // value should be of a shape [N, ] + auto updated_tensor_array = make_shared(tensor_array, indices, value); + set_node_name(node.get_name(), updated_tensor_array); + + // TensorArrayScatterV3 has just one output flow_out + // that is used for transferring updated tensor array + return {updated_tensor_array}; +} + +OutputVector translate_tensor_array_read_v3_op(const NodeContext& node) { + // TensorArrayReadV3 read an element from the TensorArray into the output + // and it has three inputs: + // 0) handle, a Tensor of type resource. The handle to a TensorArray. + // 1) index, a Tensor of type int32. The location from which to read the value + // 2) flow_in A Tensor of type float32. A float scalar that enforces proper chaining of operations. + // The operation has one output + // 0) read value from tensor array + default_op_checks(node, 3, {"TensorArrayReadV3"}); + auto index = node.get_input(1); + // flow_in is used for transferring input tensor array + auto tensor_array = node.get_input(2); + auto dtype = node.get_attribute("dtype"); + + // adjust the index to a scalar for using Gather operation + auto new_shape = make_shared(element::i32, Shape{0}, vector{}); + index = make_shared(index, new_shape, false); + + // gather tensor element by the required position + auto gather_axis = make_shared(element::i32, Shape{1}, 0); + Output tensor_element = make_shared(tensor_array, index, gather_axis); + tensor_element = make_shared(tensor_element, dtype); + + set_node_name(node.get_name(), tensor_element.get_node_shared_ptr()); + return {tensor_element}; +} + +OutputVector translate_tensor_array_close_v3_op(const NodeContext& node) { + // TensorArrayCloseV3 deletes the TensorArray from its resource container + // it outputs nothing + default_op_checks(node, 1, {"TensorArrayCloseV3"}); + return {}; +} + +OutputVector translate_tensor_array_size_v3_op(const NodeContext& node) { + // TensorArraySizeV3 gets the current size of the TensorArray + // it outputs int32 scalar equal to a size of the tensor array + default_op_checks(node, 2, {"TensorArraySizeV3"}); + // skip the handle by the first input + auto tensor_array = node.get_input(1); + + auto size = make_shared(tensor_array, element::i32)->output(0); + auto zero_const = make_shared(element::i32, Shape{1}, 0); + size = make_shared(size, zero_const, zero_const); + + // size must be scalar + auto scalar_shape = make_shared(element::i32, Shape{0}, vector{}); + size = make_shared(size, scalar_shape, false); + + set_node_name(node.get_name(), size.get_node_shared_ptr()); + return {size}; +} + +OutputVector translate_tensor_array_gather_v3_op(const NodeContext& node) { + // TensorArrayGatherV3 gathers specific elements from the TensorArray into output + // and it has three inputs: + // 0) handle, a Tensor of type resource. The handle to a TensorArray. + // 1) indices, a Tensor of type int32. The location from which to read tensor elements + // 2) flow_in A Tensor of type float32. A float scalar that enforces proper chaining of operations. + // The operation has one output + // 0) value with read tensor elements + // it outputs int32 scalar equal to a size of the tensor array + default_op_checks(node, 3, {"TensorArrayGatherV3"}); + // skip the handle by the first input + auto indices = node.get_input(1); + // flow_in serves for transferring tensor array + // handle input is ignored + auto tensor_array = node.get_input(2); + auto dtype = node.get_attribute("dtype"); + auto element_shape = node.get_attribute("element_shape", PartialShape::dynamic()); + + // gather tensor element by the required position + auto gather_axis = make_shared(element::i32, Shape{1}, 0); + Output tensor_element = make_shared(tensor_array, indices, gather_axis); + tensor_element = make_shared(tensor_element, dtype); + + // concretize tensor_element shape if this is specified + if (tensor_element.get_partial_shape().rank().is_dynamic() && element_shape.is_static()) { + auto element_shape_value = element_shape.get_shape(); + auto element_shape_const = + make_shared(element::i32, Shape{element_shape_value.size()}, element_shape_value); + auto size = make_shared(tensor_array, element::i32)->output(0); + auto zero_const = make_shared(element::i32, Shape{1}, 0); + size = make_shared(size, zero_const, zero_const); + auto new_shape = make_shared(OutputVector{size, element_shape_const}, 0); + tensor_element = make_shared(tensor_element, new_shape, false); + } + + set_node_name(node.get_name(), tensor_element.get_node_shared_ptr()); + return {tensor_element}; +} + +OutputVector translate_tensor_array_concat_v3_op(const NodeContext& node) { + // TensorArrayConcatV3 Concat the elements from the TensorArray into value + // and it has two inputs: + // 0) handle, a Tensor of type resource. The handle to a TensorArray. + // 1) flow_in A Tensor of type float32. A float scalar that enforces proper chaining of operations. + // The operation has one output + // 0) concatenated value by the first dimension + default_op_checks(node, 2, {"TensorArrayConcatV3"}); + // flow_in serves for transferring tensor array + // handle input is ignored + auto tensor_array = node.get_input(1); + auto dtype = node.get_attribute("dtype"); + + // since tensor array saves tensor elements in the concatenated form by the first dimension + // and for this operation they should be concatenated by the first dimension of the tensor element + // it needs to combine the first two dimensions + // tensor array is of shape [k, n0, n1, ..., nd] + // 1. compute element shape excluding the first dimension + auto zero_const = make_shared(element::i32, Shape{1}, 0); + auto one_const = make_shared(element::i32, Shape{1}, 1); + auto two_const = make_shared(element::i32, Shape{1}, 2); + auto max_const = make_shared(element::i32, Shape{1}, numeric_limits::max()); + auto tensor_array_shape = make_shared(tensor_array, element::i64); + auto element_shape_no_two_dims = make_shared(tensor_array_shape, two_const, max_const, one_const); + // 2. compute the first and second dimensions k and n0 + auto k = make_shared(tensor_array_shape, zero_const, zero_const); + auto n0 = make_shared(tensor_array_shape, one_const, zero_const); + auto k_by_n0 = make_shared(k, n0); + // 3. compute the first output containing concatenated tensor elements + // it folds the first and second dimensions + auto new_shape = make_shared(OutputVector{k_by_n0, element_shape_no_two_dims}, 0); + auto concatenated_array = make_shared(tensor_array, new_shape, false)->output(0); + concatenated_array = make_shared(concatenated_array, dtype); + concatenated_array.set_names({node.get_name() + ":0"}); + // 4. compute the second output with length of each tensor element for the concatenation + auto lengths = make_shared(n0, k)->output(0); + lengths.set_names({node.get_name() + ":1"}); + + return {concatenated_array, lengths}; +} + +OutputVector translate_tensor_array_write_v3_op(const NodeContext& node) { + // TensorArrayWriteV3 pushes an element onto the tensor_array. + // and it has four inputs + // 0) handle, a Tensor of type resource. The handle to a TensorArray. + // 1) index, a Tensor of type int32. The location where to write tensor element + // 2) value, a Tensor. The tensor to write at the specified location + // 3) flow_in A Tensor of type float32. A float scalar that enforces proper chaining of operations. + // The operation has one output + // 0) read value from tensor array + default_op_checks(node, 4, {"TensorArrayWriteV3"}); + auto handle = node.get_input(0); + auto index = node.get_input(1); + auto value = node.get_input(2); + // flow_in is used for transferring input tensor array + // tensor array has a rank equal to 1 + rank(element of tensor array) + // if it just initialized, its shape is equal to [tensor_array_size, 1, ..., 1] + // otherwise, it is equal to [tensor_array_size, ] + auto tensor_array = node.get_input(3); + + // reshape index to have it of [1] shape + auto new_index_shape = make_shared(element::i32, Shape{1}, 1); + index = make_shared(index, new_index_shape, false); + + if (auto enter = as_type_ptr(handle.get_node_shared_ptr())) { + if (as_type_ptr(enter->input_value(0).get_node_shared_ptr()) && + value.get_partial_shape().rank().is_static()) { + // set tensor element rank that gets known from TensorArrayWriteV3 operation + auto tensor_array_v3 = as_type_ptr(enter->input_value(0).get_node_shared_ptr()); + int64_t tensor_element_rank = value.get_partial_shape().rank().get_length(); + tensor_array_v3->set_element_rank(tensor_element_rank); + } + } + + // compute element shape in the input tensor array + auto tensor_array_shape = make_shared(tensor_array, element::i32); + + // compute the current size of tensor array + auto zero_const = make_shared(element::i32, Shape{1}, 0); + auto tensor_array_size = make_shared(tensor_array_shape, zero_const, zero_const); + + // adjust tensor array to have the correct shape [size, ] before value insertion + auto element_shape = make_shared(value, element::i32); + auto new_tensor_array_shape = make_shared(OutputVector{tensor_array_size, element_shape}, 0); + tensor_array = make_shared(tensor_array, new_tensor_array_shape); + + // update the resulted tensor using ScatterUpdate + value = make_shared(value, zero_const); + auto scatter_update = make_shared(tensor_array, index, value, zero_const); + + set_node_name(node.get_name(), scatter_update); + // use flow_out for transferring updated tensor array + return {scatter_update}; +} + +} // namespace op +} // namespace tensorflow +} // namespace frontend +} // namespace ov diff --git a/src/frontends/tensorflow/src/op/var_handle.cpp b/src/frontends/tensorflow/src/op/var_handle.cpp index 50a5b73c449f8f..501df1c504309b 100644 --- a/src/frontends/tensorflow/src/op/var_handle.cpp +++ b/src/frontends/tensorflow/src/op/var_handle.cpp @@ -9,8 +9,9 @@ #include "input_model.hpp" #include "ngraph/runtime/shared_buffer.hpp" #include "openvino/opsets/opset8.hpp" +#include "openvino/runtime/shared_buffer.hpp" #include "openvino/util/mmap_object.hpp" -#include "tensor_bundle.pb.h" +#include "ov_tensorflow/tensor_bundle.pb.h" using namespace std; using namespace ov::opset8; @@ -44,15 +45,12 @@ static std::shared_ptr read_variable(std::shared_ptr v node, static_cast(mapped_memory->size()) >= entry.offset() + entry.size(), "[TensorFlow Frontend] Internal error: Variable entry size is out of bounds of mapped memory size."); - OPENVINO_SUPPRESS_DEPRECATED_START return std::make_shared( ov_type, shape, - std::make_shared>>( - mapped_memory->data() + entry.offset(), - entry.size(), - mapped_memory)); - OPENVINO_SUPPRESS_DEPRECATED_END + std::make_shared>>(mapped_memory->data() + entry.offset(), + entry.size(), + mapped_memory)); } else { std::vector var_data; var_data.resize(size); diff --git a/src/frontends/tensorflow/src/op/xla_conv_v2.cpp b/src/frontends/tensorflow/src/op/xla_conv_v2.cpp index dc2e319c9a03b1..2d6ecdfa7bfb73 100644 --- a/src/frontends/tensorflow/src/op/xla_conv_v2.cpp +++ b/src/frontends/tensorflow/src/op/xla_conv_v2.cpp @@ -14,8 +14,8 @@ #include "openvino/op/shape_of.hpp" #include "openvino/op/slice.hpp" #include "openvino/op/transpose.hpp" +#include "ov_tensorflow/xla_data.pb.h" #include "utils.hpp" -#include "xla_data.pb.h" using namespace std; using namespace ov; diff --git a/src/frontends/tensorflow/src/op/xla_dot.cpp b/src/frontends/tensorflow/src/op/xla_dot.cpp index e463494511f076..b4c38519ce210c 100644 --- a/src/frontends/tensorflow/src/op/xla_dot.cpp +++ b/src/frontends/tensorflow/src/op/xla_dot.cpp @@ -13,8 +13,8 @@ #include "openvino/op/shape_of.hpp" #include "openvino/op/transpose.hpp" #include "openvino/op/unsqueeze.hpp" +#include "ov_tensorflow/xla_data.pb.h" #include "utils.hpp" -#include "xla_data.pb.h" using namespace std; using namespace ov; diff --git a/src/frontends/tensorflow/src/op_table.cpp b/src/frontends/tensorflow/src/op_table.cpp index b1313ec07ba826..3a4c570c6576fb 100644 --- a/src/frontends/tensorflow/src/op_table.cpp +++ b/src/frontends/tensorflow/src/op_table.cpp @@ -46,6 +46,14 @@ TF_OP_CONVERTER(translate_sparse_segment_sum_op); TF_OP_CONVERTER(translate_staticregexfullmatch_op); TF_OP_CONVERTER(translate_stringjoin_op); TF_OP_CONVERTER(translate_switch_op); +TF_OP_CONVERTER(translate_tensor_array_close_v3_op); +TF_OP_CONVERTER(translate_tensor_array_concat_v3_op); +TF_OP_CONVERTER(translate_tensor_array_gather_v3_op); +TF_OP_CONVERTER(translate_tensor_array_read_v3_op); +TF_OP_CONVERTER(translate_tensor_array_scatter_v3_op); +TF_OP_CONVERTER(translate_tensor_array_size_v3_op); +TF_OP_CONVERTER(translate_tensor_array_v3_op); +TF_OP_CONVERTER(translate_tensor_array_write_v3_op); TF_OP_CONVERTER(translate_varhandle_op); TF_OP_CONVERTER(translate_variable_op); TF_OP_CONVERTER(translate_varisinitialized_op); @@ -130,6 +138,7 @@ const std::map get_supported_ops() { {"AvgPool3D", CreatorFunction(translate_avg_pool_op)}, {"BatchMatMul", CreatorFunction(translate_batch_mat_mul_op)}, {"BatchMatMulV2", CreatorFunction(translate_batch_mat_mul_op)}, + {"BatchMatMulV3", CreatorFunction(translate_batch_mat_mul_with_type_op)}, {"BatchToSpaceND", CreatorFunction(translate_batch_to_space_nd_op)}, {"BroadcastArgs", CreatorFunction(translate_broadcast_args_op)}, {"BroadcastTo", CreatorFunction(translate_broadcast_to_op)}, @@ -173,6 +182,8 @@ const std::map get_supported_ops() { {"Gather", CreatorFunction(translate_gather_op)}, {"GatherV2", CreatorFunction(translate_gather_v2_op)}, {"GatherNd", CreatorFunction(translate_gather_nd_op)}, + {"GatherTree", CreatorFunction(translate_gather_tree_op)}, + {"Addons>GatherTree", CreatorFunction(translate_gather_tree_op)}, {"HashTable", CreatorFunction(translate_hash_table_op)}, {"HashTableV2", CreatorFunction(translate_hash_table_op)}, {"Identity", CreatorFunction(translate_identity_op)}, @@ -211,6 +222,7 @@ const std::map get_supported_ops() { {"NoOp", CreatorFunction(translate_no_op)}, // do nothing {"OneHot", CreatorFunction(translate_one_hot_op)}, {"OneShotIterator", CreatorFunction(translate_iterator_op)}, + {"OnesLike", CreatorFunction(translate_ones_like_op)}, {"Pack", CreatorFunction(translate_pack_op)}, {"Pad", CreatorFunction(translate_pad_op)}, {"PadV2", CreatorFunction(translate_padv2_op)}, @@ -267,6 +279,14 @@ const std::map get_supported_ops() { {"StatelessWhile", CreatorFunction(translate_while_op)}, {"StridedSlice", CreatorFunction(translate_strided_slice_op)}, {"Switch", CreatorFunction(translate_switch_op)}, + {"TensorArrayCloseV3", CreatorFunction(translate_tensor_array_close_v3_op)}, + {"TensorArrayConcatV3", CreatorFunction(translate_tensor_array_concat_v3_op)}, + {"TensorArrayGatherV3", CreatorFunction(translate_tensor_array_gather_v3_op)}, + {"TensorArrayReadV3", CreatorFunction(translate_tensor_array_read_v3_op)}, + {"TensorArrayScatterV3", CreatorFunction(translate_tensor_array_scatter_v3_op)}, + {"TensorArraySizeV3", CreatorFunction(translate_tensor_array_size_v3_op)}, + {"TensorArrayV3", CreatorFunction(translate_tensor_array_v3_op)}, + {"TensorArrayWriteV3", CreatorFunction(translate_tensor_array_write_v3_op)}, {"TensorListFromTensor", CreatorFunction(translate_tensor_list_from_tensor_op)}, {"TensorListGetItem", CreatorFunction(translate_tensor_list_get_item_op)}, {"TensorListLength", CreatorFunction(translate_tensor_list_length_op)}, @@ -276,15 +296,20 @@ const std::map get_supported_ops() { {"TensorListReserve", CreatorFunction(translate_tensor_list_reserve_op)}, {"TensorListResize", CreatorFunction(translate_tensor_list_resize_op)}, {"Tile", CreatorFunction(translate_tile_op)}, + {"ToBool", CreatorFunction(translate_tobool_op)}, {"TopK", CreatorFunction(translate_top_k_op)}, {"TopKV2", CreatorFunction(translate_top_k_v2_op)}, {"Transpose", CreatorFunction(translate_transpose_op)}, + {"TruncateDiv", CreatorFunction(translate_truncate_div_op)}, + {"TruncateMod", CreatorFunction(translate_truncate_mod_op)}, {"Unpack", CreatorFunction(translate_unpack_op)}, {"UnravelIndex", CreatorFunction(translate_unravel_index_op)}, {"UnsortedSegmentSum", CreatorFunction(translate_unsorted_segment_sum_op)}, {"While", CreatorFunction(translate_while_op)}, {"Where", CreatorFunction(translate_where_op)}, {"Xdivy", CreatorFunction(translate_x_div_y_op)}, + {"Xlog1py", CreatorFunction(translate_xlog1py_op)}, + {"Xlogy", CreatorFunction(translate_xlogy_op)}, {"ZerosLike", CreatorFunction(translate_zeros_like_op)}, // Translators for SavedModel and MetaGraph diff --git a/src/frontends/tensorflow/src/proto/any.proto b/src/frontends/tensorflow/src/proto/google/protobuf/any.proto similarity index 100% rename from src/frontends/tensorflow/src/proto/any.proto rename to src/frontends/tensorflow/src/proto/google/protobuf/any.proto diff --git a/src/frontends/tensorflow/src/proto/wrappers.proto b/src/frontends/tensorflow/src/proto/google/protobuf/wrappers.proto similarity index 100% rename from src/frontends/tensorflow/src/proto/wrappers.proto rename to src/frontends/tensorflow/src/proto/google/protobuf/wrappers.proto diff --git a/src/frontends/tensorflow/src/proto/allocation_description.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/allocation_description.proto similarity index 100% rename from src/frontends/tensorflow/src/proto/allocation_description.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/allocation_description.proto diff --git a/src/frontends/tensorflow/src/proto/api_def.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/api_def.proto similarity index 99% rename from src/frontends/tensorflow/src/proto/api_def.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/api_def.proto index 810aabc5a2c2c3..cbb581973d32bb 100644 --- a/src/frontends/tensorflow/src/proto/api_def.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/api_def.proto @@ -21,7 +21,7 @@ option java_outer_classname = "ApiDefProtos"; option java_multiple_files = true; option java_package = "org.tensorflow.framework"; option go_package = "github.com/tensorflow/tensorflow/tensorflow/go/core/framework/api_def_go_proto"; -import "attr_value.proto"; +import "ov_tensorflow/attr_value.proto"; // Used to specify and override the default API & behavior in the // generated code for client languages, from what you would get from diff --git a/src/frontends/tensorflow/src/proto/attr_value.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/attr_value.proto similarity index 96% rename from src/frontends/tensorflow/src/proto/attr_value.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/attr_value.proto index 3028176c02bcd7..b903c30cf99276 100644 --- a/src/frontends/tensorflow/src/proto/attr_value.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/attr_value.proto @@ -14,9 +14,9 @@ syntax = "proto3"; package tensorflow; -import "tensor.proto"; -import "tensor_shape.proto"; -import "types.proto"; +import "ov_tensorflow/tensor.proto"; +import "ov_tensorflow/tensor_shape.proto"; +import "ov_tensorflow/types.proto"; option cc_enable_arenas = true; option java_outer_classname = "AttrValueProtos"; diff --git a/src/frontends/tensorflow/src/proto/cost_graph.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/cost_graph.proto similarity index 97% rename from src/frontends/tensorflow/src/proto/cost_graph.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/cost_graph.proto index dad93a029babae..8e4d9788f49595 100644 --- a/src/frontends/tensorflow/src/proto/cost_graph.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/cost_graph.proto @@ -14,8 +14,8 @@ syntax = "proto3"; package tensorflow; -import "tensor_shape.proto"; -import "types.proto"; +import "ov_tensorflow/tensor_shape.proto"; +import "ov_tensorflow/types.proto"; option cc_enable_arenas = true; option java_outer_classname = "CostGraphProtos"; diff --git a/src/frontends/tensorflow/src/proto/dataset_options.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/dataset_options.proto similarity index 100% rename from src/frontends/tensorflow/src/proto/dataset_options.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/dataset_options.proto diff --git a/src/frontends/tensorflow/src/proto/device_attributes.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/device_attributes.proto similarity index 100% rename from src/frontends/tensorflow/src/proto/device_attributes.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/device_attributes.proto diff --git a/src/frontends/tensorflow/src/proto/function.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/function.proto similarity index 98% rename from src/frontends/tensorflow/src/proto/function.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/function.proto index 65a2acb3b91979..9e84731c983bb1 100644 --- a/src/frontends/tensorflow/src/proto/function.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/function.proto @@ -14,9 +14,9 @@ syntax = "proto3"; package tensorflow; -import "attr_value.proto"; -import "node_def.proto"; -import "op_def.proto"; +import "ov_tensorflow/attr_value.proto"; +import "ov_tensorflow/node_def.proto"; +import "ov_tensorflow/op_def.proto"; option cc_enable_arenas = true; option java_outer_classname = "FunctionProtos"; diff --git a/src/frontends/tensorflow/src/proto/graph.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/graph.proto similarity index 95% rename from src/frontends/tensorflow/src/proto/graph.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/graph.proto index c52e84022f9fcd..e047abeafe18b1 100644 --- a/src/frontends/tensorflow/src/proto/graph.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/graph.proto @@ -14,9 +14,9 @@ syntax = "proto3"; package tensorflow; -import "function.proto"; -import "node_def.proto"; -import "versions.proto"; +import "ov_tensorflow/function.proto"; +import "ov_tensorflow/node_def.proto"; +import "ov_tensorflow/versions.proto"; option cc_enable_arenas = true; option java_outer_classname = "GraphProtos"; diff --git a/src/frontends/tensorflow/src/proto/graph_transfer_info.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/graph_transfer_info.proto similarity index 98% rename from src/frontends/tensorflow/src/proto/graph_transfer_info.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/graph_transfer_info.proto index e42c1353695313..9e7d598e34a5c1 100644 --- a/src/frontends/tensorflow/src/proto/graph_transfer_info.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/graph_transfer_info.proto @@ -14,7 +14,7 @@ syntax = "proto3"; package tensorflow; -import "types.proto"; +import "ov_tensorflow/types.proto"; option cc_enable_arenas = true; option java_outer_classname = "GraphTransferInfoProto"; diff --git a/src/frontends/tensorflow/src/proto/kernel_def.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/kernel_def.proto similarity index 98% rename from src/frontends/tensorflow/src/proto/kernel_def.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/kernel_def.proto index 5e6b839d31582e..88142d3de9584d 100644 --- a/src/frontends/tensorflow/src/proto/kernel_def.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/kernel_def.proto @@ -14,7 +14,7 @@ syntax = "proto3"; package tensorflow; -import "attr_value.proto"; +import "ov_tensorflow/attr_value.proto"; option cc_enable_arenas = true; option java_outer_classname = "KernelDefProtos"; diff --git a/src/frontends/tensorflow/src/proto/log_memory.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/log_memory.proto similarity index 98% rename from src/frontends/tensorflow/src/proto/log_memory.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/log_memory.proto index 96dac4c9ca370d..62489f0e0b8df4 100644 --- a/src/frontends/tensorflow/src/proto/log_memory.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/log_memory.proto @@ -14,7 +14,7 @@ syntax = "proto3"; package tensorflow; -import "tensor_description.proto"; +import "ov_tensorflow/tensor_description.proto"; option cc_enable_arenas = true; option java_outer_classname = "LogMemoryProtos"; diff --git a/src/frontends/tensorflow/src/proto/meta_graph.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/meta_graph.proto similarity index 97% rename from src/frontends/tensorflow/src/proto/meta_graph.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/meta_graph.proto index b6918fa853bf8c..255fb6efeb2f9e 100644 --- a/src/frontends/tensorflow/src/proto/meta_graph.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/meta_graph.proto @@ -14,14 +14,14 @@ syntax = "proto3"; package tensorflow; -import "any.proto"; -import "graph.proto"; -import "op_def.proto"; -import "tensor_shape.proto"; -import "types.proto"; -import "saved_object_graph.proto"; -import "saver.proto"; -import "struct.proto"; +import "google/protobuf/any.proto"; +import "ov_tensorflow/graph.proto"; +import "ov_tensorflow/op_def.proto"; +import "ov_tensorflow/tensor_shape.proto"; +import "ov_tensorflow/types.proto"; +import "ov_tensorflow/saved_object_graph.proto"; +import "ov_tensorflow/saver.proto"; +import "ov_tensorflow/struct.proto"; option cc_enable_arenas = true; option java_outer_classname = "MetaGraphProtos"; diff --git a/src/frontends/tensorflow/src/proto/model.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/model.proto similarity index 100% rename from src/frontends/tensorflow/src/proto/model.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/model.proto diff --git a/src/frontends/tensorflow/src/proto/node_def.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/node_def.proto similarity index 99% rename from src/frontends/tensorflow/src/proto/node_def.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/node_def.proto index 573d0f901dd732..b8f3a017a30fc5 100644 --- a/src/frontends/tensorflow/src/proto/node_def.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/node_def.proto @@ -14,7 +14,7 @@ syntax = "proto3"; package tensorflow; -import "attr_value.proto"; +import "ov_tensorflow/attr_value.proto"; option cc_enable_arenas = true; option java_outer_classname = "NodeProto"; diff --git a/src/frontends/tensorflow/src/proto/op_def.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/op_def.proto similarity index 98% rename from src/frontends/tensorflow/src/proto/op_def.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/op_def.proto index 4d5c66c39e16d7..31493fed26ce55 100644 --- a/src/frontends/tensorflow/src/proto/op_def.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/op_def.proto @@ -18,9 +18,10 @@ option java_outer_classname = "OpDefProtos"; option java_multiple_files = true; option java_package = "org.tensorflow.framework"; option go_package = "github.com/tensorflow/tensorflow/tensorflow/go/core/framework/op_def_go_proto"; -import "attr_value.proto"; -import "types.proto"; -import "resource_handle.proto"; + +import "ov_tensorflow/attr_value.proto"; +import "ov_tensorflow/types.proto"; +import "ov_tensorflow/resource_handle.proto"; // Defines an operation. A NodeDef in a GraphDef specifies an Op by // using the "op" field which should match the name of a OpDef. diff --git a/src/frontends/tensorflow/src/proto/reader_base.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/reader_base.proto similarity index 100% rename from src/frontends/tensorflow/src/proto/reader_base.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/reader_base.proto diff --git a/src/frontends/tensorflow/src/proto/remote_fused_graph_execute_info.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/remote_fused_graph_execute_info.proto similarity index 94% rename from src/frontends/tensorflow/src/proto/remote_fused_graph_execute_info.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/remote_fused_graph_execute_info.proto index abfcfdbec08007..3b17878e127cf9 100644 --- a/src/frontends/tensorflow/src/proto/remote_fused_graph_execute_info.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/remote_fused_graph_execute_info.proto @@ -14,9 +14,9 @@ syntax = "proto3"; package tensorflow; -import "graph.proto"; -import "tensor_shape.proto"; -import "types.proto"; +import "ov_tensorflow/graph.proto"; +import "ov_tensorflow/tensor_shape.proto"; +import "ov_tensorflow/types.proto"; option cc_enable_arenas = true; option java_outer_classname = "RemoteFusedGraphExecuteInfoProto"; diff --git a/src/frontends/tensorflow/src/proto/resource_handle.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/resource_handle.proto similarity index 96% rename from src/frontends/tensorflow/src/proto/resource_handle.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/resource_handle.proto index 4d872b6d9d8074..19b4dcc3b84ded 100644 --- a/src/frontends/tensorflow/src/proto/resource_handle.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/resource_handle.proto @@ -14,8 +14,8 @@ syntax = "proto3"; package tensorflow; -import "tensor_shape.proto"; -import "types.proto"; +import "ov_tensorflow/tensor_shape.proto"; +import "ov_tensorflow/types.proto"; option cc_enable_arenas = true; option java_outer_classname = "ResourceHandle"; diff --git a/src/frontends/tensorflow/src/proto/saved_model.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/saved_model.proto similarity index 97% rename from src/frontends/tensorflow/src/proto/saved_model.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/saved_model.proto index 0034fdfd46dcf8..f8660655229245 100644 --- a/src/frontends/tensorflow/src/proto/saved_model.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/saved_model.proto @@ -14,7 +14,7 @@ syntax = "proto3"; package tensorflow; -import "meta_graph.proto"; +import "ov_tensorflow/meta_graph.proto"; option cc_enable_arenas = true; option java_outer_classname = "SavedModelProtos"; diff --git a/src/frontends/tensorflow/src/proto/saved_object_graph.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/saved_object_graph.proto similarity index 97% rename from src/frontends/tensorflow/src/proto/saved_object_graph.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/saved_object_graph.proto index 671441075c3628..d0b2170044966c 100644 --- a/src/frontends/tensorflow/src/proto/saved_object_graph.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/saved_object_graph.proto @@ -14,13 +14,13 @@ syntax = "proto3"; package tensorflow; -import "any.proto"; -import "tensor_shape.proto"; -import "types.proto"; -import "variable.proto"; -import "versions.proto"; -import "struct.proto"; -import "trackable_object_graph.proto"; +import "google/protobuf/any.proto"; +import "ov_tensorflow/tensor_shape.proto"; +import "ov_tensorflow/types.proto"; +import "ov_tensorflow/variable.proto"; +import "ov_tensorflow/versions.proto"; +import "ov_tensorflow/struct.proto"; +import "ov_tensorflow/trackable_object_graph.proto"; option cc_enable_arenas = true; option go_package = "github.com/tensorflow/tensorflow/tensorflow/go/core/protobuf/for_core_protos_go_proto"; diff --git a/src/frontends/tensorflow/src/proto/saved_tensor_slice.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/saved_tensor_slice.proto similarity index 94% rename from src/frontends/tensorflow/src/proto/saved_tensor_slice.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/saved_tensor_slice.proto index 4645b2bdca9b89..9e628752bb1f5c 100644 --- a/src/frontends/tensorflow/src/proto/saved_tensor_slice.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/saved_tensor_slice.proto @@ -35,11 +35,11 @@ option java_outer_classname = "SavedTensorSliceProtos"; option java_multiple_files = true; option java_package = "org.tensorflow.util"; -import "tensor_shape.proto"; -import "tensor_slice.proto"; -import "tensor.proto"; -import "types.proto"; -import "versions.proto"; +import "ov_tensorflow/tensor_shape.proto"; +import "ov_tensorflow/tensor_slice.proto"; +import "ov_tensorflow/tensor.proto"; +import "ov_tensorflow/types.proto"; +import "ov_tensorflow/versions.proto"; // Metadata describing the set of slices of the same tensor saved in a // checkpoint file. diff --git a/src/frontends/tensorflow/src/proto/saver.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/saver.proto similarity index 100% rename from src/frontends/tensorflow/src/proto/saver.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/saver.proto diff --git a/src/frontends/tensorflow/src/proto/step_stats.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/step_stats.proto similarity index 97% rename from src/frontends/tensorflow/src/proto/step_stats.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/step_stats.proto index 04e0864a5aec49..027a1d79ee22e4 100644 --- a/src/frontends/tensorflow/src/proto/step_stats.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/step_stats.proto @@ -14,8 +14,8 @@ syntax = "proto3"; package tensorflow; -import "allocation_description.proto"; -import "tensor_description.proto"; +import "ov_tensorflow/allocation_description.proto"; +import "ov_tensorflow/tensor_description.proto"; option cc_enable_arenas = true; option java_outer_classname = "StepStatsProtos"; diff --git a/src/frontends/tensorflow/src/proto/struct.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/struct.proto similarity index 98% rename from src/frontends/tensorflow/src/proto/struct.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/struct.proto index d03201b685ac79..4126bd98c4a3d3 100644 --- a/src/frontends/tensorflow/src/proto/struct.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/struct.proto @@ -14,9 +14,9 @@ syntax = "proto3"; package tensorflow; -import "tensor.proto"; -import "tensor_shape.proto"; -import "types.proto"; +import "ov_tensorflow/tensor.proto"; +import "ov_tensorflow/tensor_shape.proto"; +import "ov_tensorflow/types.proto"; option go_package = "github.com/tensorflow/tensorflow/tensorflow/go/core/protobuf/for_core_protos_go_proto"; diff --git a/src/frontends/tensorflow/src/proto/summary.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/summary.proto similarity index 99% rename from src/frontends/tensorflow/src/proto/summary.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/summary.proto index 9e4b95f4bc3348..ce326176947dd4 100644 --- a/src/frontends/tensorflow/src/proto/summary.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/summary.proto @@ -14,7 +14,7 @@ syntax = "proto3"; package tensorflow; -import "tensor.proto"; +import "ov_tensorflow/tensor.proto"; option cc_enable_arenas = true; option java_outer_classname = "SummaryProtos"; diff --git a/src/frontends/tensorflow/src/proto/tensor.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/tensor.proto similarity index 96% rename from src/frontends/tensorflow/src/proto/tensor.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/tensor.proto index c2e1fd7eb6b627..42f063536e09e0 100644 --- a/src/frontends/tensorflow/src/proto/tensor.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/tensor.proto @@ -14,9 +14,9 @@ syntax = "proto3"; package tensorflow; -import "resource_handle.proto"; -import "tensor_shape.proto"; -import "types.proto"; +import "ov_tensorflow/resource_handle.proto"; +import "ov_tensorflow/tensor_shape.proto"; +import "ov_tensorflow/types.proto"; option cc_enable_arenas = true; option java_outer_classname = "TensorProtos"; diff --git a/src/frontends/tensorflow/src/proto/tensor_bundle.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/tensor_bundle.proto similarity index 94% rename from src/frontends/tensorflow/src/proto/tensor_bundle.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/tensor_bundle.proto index 43fea749b42172..21af38195c4e11 100644 --- a/src/frontends/tensorflow/src/proto/tensor_bundle.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/tensor_bundle.proto @@ -14,10 +14,10 @@ syntax = "proto3"; package tensorflow; -import "tensor_shape.proto"; -import "tensor_slice.proto"; -import "types.proto"; -import "versions.proto"; +import "ov_tensorflow/tensor_shape.proto"; +import "ov_tensorflow/tensor_slice.proto"; +import "ov_tensorflow/types.proto"; +import "ov_tensorflow/versions.proto"; option cc_enable_arenas = true; option java_outer_classname = "TensorBundleProtos"; diff --git a/src/frontends/tensorflow/src/proto/tensor_description.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/tensor_description.proto similarity index 90% rename from src/frontends/tensorflow/src/proto/tensor_description.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/tensor_description.proto index 3ab9c310a6f127..c03e1311c1f386 100644 --- a/src/frontends/tensorflow/src/proto/tensor_description.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/tensor_description.proto @@ -14,9 +14,9 @@ syntax = "proto3"; package tensorflow; -import "allocation_description.proto"; -import "tensor_shape.proto"; -import "types.proto"; +import "ov_tensorflow/allocation_description.proto"; +import "ov_tensorflow/tensor_shape.proto"; +import "ov_tensorflow/types.proto"; option cc_enable_arenas = true; option java_outer_classname = "TensorDescriptionProtos"; diff --git a/src/frontends/tensorflow/src/proto/tensor_shape.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/tensor_shape.proto similarity index 100% rename from src/frontends/tensorflow/src/proto/tensor_shape.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/tensor_shape.proto diff --git a/src/frontends/tensorflow/src/proto/tensor_slice.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/tensor_slice.proto similarity index 100% rename from src/frontends/tensorflow/src/proto/tensor_slice.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/tensor_slice.proto diff --git a/src/frontends/tensorflow/src/proto/trackable_object_graph.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/trackable_object_graph.proto similarity index 98% rename from src/frontends/tensorflow/src/proto/trackable_object_graph.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/trackable_object_graph.proto index f4a8e4da34f129..f0a9617432f617 100644 --- a/src/frontends/tensorflow/src/proto/trackable_object_graph.proto +++ b/src/frontends/tensorflow/src/proto/ov_tensorflow/trackable_object_graph.proto @@ -14,7 +14,7 @@ syntax = "proto3"; package tensorflow; -import "wrappers.proto"; +import "google/protobuf/wrappers.proto"; option cc_enable_arenas = true; option go_package = "github.com/tensorflow/tensorflow/tensorflow/go/core/protobuf/for_core_protos_go_proto"; diff --git a/src/frontends/tensorflow/src/proto/types.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/types.proto similarity index 100% rename from src/frontends/tensorflow/src/proto/types.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/types.proto diff --git a/src/frontends/tensorflow/src/proto/variable.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/variable.proto similarity index 100% rename from src/frontends/tensorflow/src/proto/variable.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/variable.proto diff --git a/src/frontends/tensorflow/src/proto/versions.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/versions.proto similarity index 100% rename from src/frontends/tensorflow/src/proto/versions.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/versions.proto diff --git a/src/frontends/tensorflow/src/proto/xla_data.proto b/src/frontends/tensorflow/src/proto/ov_tensorflow/xla_data.proto similarity index 100% rename from src/frontends/tensorflow/src/proto/xla_data.proto rename to src/frontends/tensorflow/src/proto/ov_tensorflow/xla_data.proto diff --git a/src/frontends/tensorflow/src/tf_utils.cpp b/src/frontends/tensorflow/src/tf_utils.cpp index c72e8e7bb9080a..e298f49f92889f 100644 --- a/src/frontends/tensorflow/src/tf_utils.cpp +++ b/src/frontends/tensorflow/src/tf_utils.cpp @@ -423,7 +423,7 @@ shared_ptr create_loop_for_tf_while(const std::string& while_node_name FRONT_END_GENERAL_CHECK( cond_results.size() == 1 && cond_results[0], "[TensorFlow Frontend] Internal error or inconsistent model: condition body must contain one Result node."); - auto body_condition_output_idx = static_cast(body_results.size()); + auto body_condition_output_idx = body_results.size(); body_model->add_results(cond_results); // type setting for body graph parameters is needed for TensorList support since DT_VARIANT type is present @@ -435,14 +435,18 @@ shared_ptr create_loop_for_tf_while(const std::string& while_node_name loop->set_function(body_model); // body_results may contain less nodes than body_params that means back edge exists not for all body_params - for (size_t input_ind = 0; input_ind < static_cast(body_condition_output_idx); ++input_ind) { + for (size_t input_ind = 0; input_ind < body_condition_output_idx; ++input_ind) { loop->set_merged_input(body_params[input_ind], ov_inputs[input_ind], body_results[input_ind]->input_value(0)); } - loop->set_special_body_ports({-1, body_condition_output_idx}); + loop->set_special_body_ports({-1, static_cast(body_condition_output_idx)}); + // set invariant inputs for the loop + for (size_t input_ind = body_condition_output_idx; input_ind < input_size; ++input_ind) { + loop->set_invariant_input(body_params[input_ind], ov_inputs[input_ind]); + } // set external outputs for Loop node // do not get execution condition outside of the Loop node - for (size_t output_ind = 0; output_ind < static_cast(body_condition_output_idx); ++output_ind) { + for (size_t output_ind = 0; output_ind < body_condition_output_idx; ++output_ind) { loop->get_iter_value(body_results[output_ind]); } loop->validate_and_infer_types(); diff --git a/src/frontends/tensorflow/src/tf_utils.hpp b/src/frontends/tensorflow/src/tf_utils.hpp index 5de9029a816e6c..861fb56f552685 100644 --- a/src/frontends/tensorflow/src/tf_utils.hpp +++ b/src/frontends/tensorflow/src/tf_utils.hpp @@ -4,8 +4,6 @@ #pragma once -#include "attr_value.pb.h" -#include "node_def.pb.h" #include "openvino/core/node.hpp" #include "openvino/core/partial_shape.hpp" #include "openvino/core/runtime_attribute.hpp" @@ -14,9 +12,11 @@ #include "openvino/frontend/node_context.hpp" #include "openvino/op/loop.hpp" #include "openvino/runtime/tensor.hpp" -#include "tensor.pb.h" -#include "tensor_shape.pb.h" -#include "types.pb.h" +#include "ov_tensorflow/attr_value.pb.h" +#include "ov_tensorflow/node_def.pb.h" +#include "ov_tensorflow/tensor.pb.h" +#include "ov_tensorflow/tensor_shape.pb.h" +#include "ov_tensorflow/types.pb.h" namespace ov { namespace frontend { diff --git a/src/frontends/tensorflow/src/variables_index.cpp b/src/frontends/tensorflow/src/variables_index.cpp index c24ffd8112bd09..2dcf3faf9e0b0c 100644 --- a/src/frontends/tensorflow/src/variables_index.cpp +++ b/src/frontends/tensorflow/src/variables_index.cpp @@ -11,8 +11,8 @@ #include "graph_iterator_saved_model.hpp" #include "openvino/core/type/element_type.hpp" #include "openvino/util/mmap_object.hpp" -#include "tensor_bundle.pb.h" -#include "trackable_object_graph.pb.h" +#include "ov_tensorflow/tensor_bundle.pb.h" +#include "ov_tensorflow/trackable_object_graph.pb.h" #ifdef ENABLE_SNAPPY_COMPRESSION # include "snappy.h" diff --git a/src/frontends/tensorflow/src/variables_index.hpp b/src/frontends/tensorflow/src/variables_index.hpp index df852a627994e7..aa805b264bc3d1 100644 --- a/src/frontends/tensorflow/src/variables_index.hpp +++ b/src/frontends/tensorflow/src/variables_index.hpp @@ -9,7 +9,7 @@ #include "graph_iterator_proto.hpp" #include "openvino/util/file_util.hpp" #include "openvino/util/mmap_object.hpp" -#include "saved_model.pb.h" +#include "ov_tensorflow/saved_model.pb.h" namespace ov { namespace frontend { diff --git a/src/frontends/tensorflow/tests/CMakeLists.txt b/src/frontends/tensorflow/tests/CMakeLists.txt index 45e64536b60f23..a532441ac393eb 100644 --- a/src/frontends/tensorflow/tests/CMakeLists.txt +++ b/src/frontends/tensorflow/tests/CMakeLists.txt @@ -10,6 +10,15 @@ if (NOT ENABLE_INTEL_CPU) set(EXCLUDED_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/compilation.cpp) endif() +ov_check_pip_packages(REQUIREMENTS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt" + MESSAGE_MODE WARNING + WARNING_MESSAGE "TensorFlow testing models weren't generated, some tests will fail due models not found" + RESULT_VAR tensorflow_FOUND) + +if(tensorflow_FOUND) + set(ctest_labels OV UNIT) +endif() + ov_add_test_target( NAME ${TARGET_NAME} ROOT ${CMAKE_CURRENT_SOURCE_DIR} @@ -22,16 +31,11 @@ ov_add_test_target( openvino_tensorflow_common ADD_CLANG_FORMAT LABELS - OV UNIT TF_FE + ${ctest_labels} TF_FE ) # Test model generating -ov_check_pip_packages(REQUIREMENTS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt" - MESSAGE_MODE WARNING - WARNING_MESSAGE "TensorFlow testing models weren't generated, some tests will fail due models not found" - RESULT_VAR tensorflow_FOUND) - set(TEST_TENSORFLOW_MODELS_DIRNAME ${TEST_MODEL_ZOO}/tensorflow_test_models) target_compile_definitions(${TARGET_NAME} PRIVATE -D TEST_TENSORFLOW_MODELS_DIRNAME=\"${TEST_TENSORFLOW_MODELS_DIRNAME}/\") diff --git a/src/frontends/tensorflow/tests/convert_model.cpp b/src/frontends/tensorflow/tests/convert_model.cpp index fc00a6784963e3..f6ec18cf9cc12c 100644 --- a/src/frontends/tensorflow/tests/convert_model.cpp +++ b/src/frontends/tensorflow/tests/convert_model.cpp @@ -15,7 +15,8 @@ static const std::vector models{ std::string("2in_2out/2in_2out.pb"), std::string("forward_edge_model/forward_edge_model.pbtxt"), std::string("forward_edge_model2/forward_edge_model2.pbtxt"), - std::string("concat_with_non_constant_axis/concat_with_non_constant_axis.pbtxt")}; + std::string("concat_with_non_constant_axis/concat_with_non_constant_axis.pbtxt"), + std::string("gather_tree_model/gather_tree_model.pbtxt")}; INSTANTIATE_TEST_SUITE_P(TFConvertModelTest, FrontEndConvertModelTest, diff --git a/src/frontends/tensorflow/tests/test_models/models_pbtxt/gather_tree_model.pbtxt b/src/frontends/tensorflow/tests/test_models/models_pbtxt/gather_tree_model.pbtxt new file mode 100644 index 00000000000000..54351036dd72a2 --- /dev/null +++ b/src/frontends/tensorflow/tests/test_models/models_pbtxt/gather_tree_model.pbtxt @@ -0,0 +1,103 @@ +node { + name: "step_ids" + op: "Placeholder" + attr { + key: "dtype" + value { + type: DT_INT32 + } + } + attr { + key: "shape" + value { + shape { + dim { + size: 20 + } + dim { + size: 2 + } + dim { + size: 30 + } + } + } + } +} +node { + name: "parent_ids" + op: "Placeholder" + attr { + key: "dtype" + value { + type: DT_INT32 + } + } + attr { + key: "shape" + value { + shape { + dim { + size: 20 + } + dim { + size: 2 + } + dim { + size: 30 + } + } + } + } +} +node { + name: "max_seq_len" + op: "Placeholder" + attr { + key: "dtype" + value { + type: DT_INT32 + } + } + attr { + key: "shape" + value { + shape { + dim { + size: 2 + } + } + } + } +} +node { + name: "end_token" + op: "Placeholder" + attr { + key: "dtype" + value { + type: DT_INT32 + } + } + attr { + key: "shape" + value { + shape { + } + } + } +} +node { + name: "Addons>GatherTree" + op: "Addons>GatherTree" + input: "step_ids" + input: "parent_ids" + input: "max_seq_len" + input: "end_token" + attr { + key: "T" + value { + type: DT_INT32 + } + } +} diff --git a/src/frontends/tensorflow/tests/tf_utils.cpp b/src/frontends/tensorflow/tests/tf_utils.cpp index 120b8ffab8659d..d742b53dcf8704 100644 --- a/src/frontends/tensorflow/tests/tf_utils.cpp +++ b/src/frontends/tensorflow/tests/tf_utils.cpp @@ -16,6 +16,8 @@ namespace frontend { namespace tensorflow { namespace tests { +const std::string TF_FE = "tf"; + shared_ptr convert_model(const string& model_path, const ConversionExtension::Ptr& conv_ext, const vector& input_names, diff --git a/src/frontends/tensorflow/tests/tf_utils.hpp b/src/frontends/tensorflow/tests/tf_utils.hpp index 1c48a95c85fee8..80addd43d61e9e 100644 --- a/src/frontends/tensorflow/tests/tf_utils.hpp +++ b/src/frontends/tensorflow/tests/tf_utils.hpp @@ -14,7 +14,7 @@ namespace ov { namespace frontend { namespace tensorflow { namespace tests { -static const std::string TF_FE = "tf"; +extern const std::string TF_FE; // a wrapper to create TensorFlow Frontend and configure the conversion pipeline // by registering new translator via extension, specifying (new) inputs, their shapes and types diff --git a/src/frontends/tensorflow_common/include/common_op_table.hpp b/src/frontends/tensorflow_common/include/common_op_table.hpp index 457a99de302d53..29efb83547d263 100644 --- a/src/frontends/tensorflow_common/include/common_op_table.hpp +++ b/src/frontends/tensorflow_common/include/common_op_table.hpp @@ -38,6 +38,7 @@ OP_CONVERTER(translate_arg_max_op); OP_CONVERTER(translate_arg_min_op); OP_CONVERTER(translate_avg_pool_op); OP_CONVERTER(translate_batch_mat_mul_op); +OP_CONVERTER(translate_batch_mat_mul_with_type_op); OP_CONVERTER(translate_batch_to_space_nd_op); OP_CONVERTER(translate_bias_add_op); OP_CONVERTER(translate_broadcast_args_op); @@ -71,6 +72,7 @@ OP_CONVERTER_NAMED(translate_fused_batch_norm_op); OP_CONVERTER(translate_gather_op); OP_CONVERTER(translate_gather_v2_op); OP_CONVERTER(translate_gather_nd_op); +OP_CONVERTER(translate_gather_tree_op); OP_CONVERTER(translate_identity_op); OP_CONVERTER(translate_identity_n_op); OP_CONVERTER(translate_input_arg_op); @@ -97,6 +99,7 @@ OP_CONVERTER(translate_placeholder_op); OP_CONVERTER(translate_placeholder_with_default_op); OP_CONVERTER(translate_no_op); OP_CONVERTER(translate_one_hot_op); +OP_CONVERTER(translate_ones_like_op); OP_CONVERTER(translate_pack_op); OP_CONVERTER(translate_pad_op); OP_CONVERTER(translate_padv2_op); @@ -140,14 +143,19 @@ OP_CONVERTER(translate_tensor_list_set_item_op); OP_CONVERTER(translate_tensor_list_stack_op); OP_CONVERTER(translate_tensor_list_resize_op); OP_CONVERTER(translate_tile_op); +OP_CONVERTER(translate_tobool_op); OP_CONVERTER_NAMED(translate_top_k_op); OP_CONVERTER_NAMED(translate_top_k_v2_op); OP_CONVERTER(translate_transpose_op); +OP_CONVERTER(translate_truncate_div_op); +OP_CONVERTER(translate_truncate_mod_op); OP_CONVERTER(translate_unpack_op); OP_CONVERTER(translate_unravel_index_op); OP_CONVERTER(translate_unsorted_segment_sum_op); OP_CONVERTER(translate_where_op); OP_CONVERTER(translate_x_div_y_op); +OP_CONVERTER(translate_xlog1py_op); +OP_CONVERTER(translate_xlogy_op); OP_CONVERTER(translate_zeros_like_op); // Translators for internal operations diff --git a/src/frontends/tensorflow_common/include/helper_ops/merge.hpp b/src/frontends/tensorflow_common/include/helper_ops/merge.hpp index eb7e611f3e21f0..6261dd0e67c229 100644 --- a/src/frontends/tensorflow_common/include/helper_ops/merge.hpp +++ b/src/frontends/tensorflow_common/include/helper_ops/merge.hpp @@ -33,20 +33,34 @@ class Merge : public InternalOperation { ov::PartialShape output_data_shape = ov::PartialShape::dynamic(); auto input_size = get_input_size(); - bool merge_output_shape = true; for (size_t input_ind = 0; input_ind < input_size; ++input_ind) { auto input_type = get_input_element_type(input_ind); if (input_type.is_static()) { output_data_type = input_type; } - // check if it still needs to merge input shapes - // if yes, it tries to merge them - if (merge_output_shape && - !PartialShape::merge_into(output_data_shape, get_input_partial_shape(input_ind))) { - merge_output_shape = false; - // reset output shape to dynamic rank + auto input_shape = get_input_partial_shape(input_ind); + if (input_shape.rank().is_dynamic()) { + continue; + } + + if (output_data_shape.rank().is_dynamic()) { + // firstly met shape of static rank + // immediately use this shape of static rank + output_data_shape = input_shape; + } else if (output_data_shape.rank().is_static() && + output_data_shape.rank().get_length() != input_shape.rank().get_length()) { + // different inputs have different rank means output must be of a dynamic rank output_data_shape = ov::PartialShape::dynamic(); + break; + } else { + auto output_rank = output_data_shape.rank().get_length(); + for (int64_t dim_ind = 0; dim_ind < output_rank; ++dim_ind) { + if (input_shape[dim_ind] != output_data_shape[dim_ind]) { + // different inputs can have different dimensions so it must combine them + output_data_shape[dim_ind] = ov::Dimension::dynamic(); + } + } } } diff --git a/src/frontends/tensorflow_common/include/helper_ops/next_iteration.hpp b/src/frontends/tensorflow_common/include/helper_ops/next_iteration.hpp index eb262b4307af7f..e556c9ad4478da 100644 --- a/src/frontends/tensorflow_common/include/helper_ops/next_iteration.hpp +++ b/src/frontends/tensorflow_common/include/helper_ops/next_iteration.hpp @@ -43,6 +43,10 @@ class NextIteration : public InternalOperation { producer_output_port_idx = m_producer_output_port_idx; } + void set_output_shape_and_type(const ov::PartialShape& output_shape, const ov::element::Type& output_type) { + set_output_type(0, output_type, output_shape); + } + private: bool m_back_edge_set; std::string m_producer_name; diff --git a/src/frontends/tensorflow_common/include/helper_ops/tensor_array.hpp b/src/frontends/tensorflow_common/include/helper_ops/tensor_array.hpp new file mode 100644 index 00000000000000..030ff12d5b68c5 --- /dev/null +++ b/src/frontends/tensorflow_common/include/helper_ops/tensor_array.hpp @@ -0,0 +1,60 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include + +#include "internal_operation.hpp" + +namespace ov { +namespace frontend { +namespace tensorflow { + +// Internal operation for TensorArrayV3 +// An array of Tensors of given size +// It has two outputs: +// 1. handle - resource (a reference) for tensor array +// 2. flow_out - float type will be used for storing tensor array +class TensorArrayV3 : public InternalOperation { +public: + OPENVINO_OP("TensorArrayV3", "ov::frontend::tensorflow", InternalOperation); + + TensorArrayV3(const Output& size, + const ov::element::Type element_type, + const std::shared_ptr& decoder = std::make_shared()) + : InternalOperation(decoder, OutputVector{size}, 2, "TensorArrayV3"), + m_element_type(element_type), + m_element_rank(-1) { + validate_and_infer_types(); + } + + void validate_and_infer_types() override { + set_output_type(0, m_element_type, ov::PartialShape::dynamic()); + set_output_type(1, m_element_type, ov::PartialShape::dynamic()); + } + + ov::element::Type get_element_type() const { + return m_element_type; + } + + int64_t get_element_rank() const { + return m_element_rank; + } + + void set_element_rank(int64_t element_rank) { + FRONT_END_GENERAL_CHECK( + element_rank >= 0, + "[TensorFlow Frontend] internal error: negavite element rank tries to set for TensorArrayV3"); + m_element_rank = element_rank; + } + +private: + ov::element::Type m_element_type; + int64_t m_element_rank; +}; + +} // namespace tensorflow +} // namespace frontend +} // namespace ov diff --git a/src/frontends/tensorflow_common/include/helper_transforms/tensor_array_v3_replacer.hpp b/src/frontends/tensorflow_common/include/helper_transforms/tensor_array_v3_replacer.hpp new file mode 100644 index 00000000000000..42e5a0ad754ea7 --- /dev/null +++ b/src/frontends/tensorflow_common/include/helper_transforms/tensor_array_v3_replacer.hpp @@ -0,0 +1,29 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "openvino/pass/graph_rewrite.hpp" +#include "openvino/pass/pass.hpp" + +namespace ov { +namespace frontend { +namespace tensorflow { +namespace pass { + +// This transformation replaces internal operation TensorArrayV3 with a Constant +// that simulates initial state of tensor array container +class TensorArrayV3Replacer : public ov::pass::MatcherPass { +public: + OPENVINO_RTTI("ov::frontend::tensorflow::pass::TensorArrayV3Replacer"); + TensorArrayV3Replacer(); +}; + +} // namespace pass +} // namespace tensorflow +} // namespace frontend +} // namespace ov diff --git a/src/frontends/tensorflow_common/src/helper_transforms/tensor_array_v3_replacer.cpp b/src/frontends/tensorflow_common/src/helper_transforms/tensor_array_v3_replacer.cpp new file mode 100644 index 00000000000000..72ed922511cd98 --- /dev/null +++ b/src/frontends/tensorflow_common/src/helper_transforms/tensor_array_v3_replacer.cpp @@ -0,0 +1,71 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "helper_transforms/tensor_array_v3_replacer.hpp" + +#include "helper_ops/tensor_array.hpp" +#include "openvino/op/broadcast.hpp" +#include "openvino/op/concat.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/reshape.hpp" +#include "openvino/pass/pattern/op/wrap_type.hpp" +#include "transformations/utils/utils.hpp" + +using namespace std; +using namespace ov; +using namespace ov::op; +using namespace ov::pass; + +ov::frontend::tensorflow::pass::TensorArrayV3Replacer::TensorArrayV3Replacer() { + auto tensor_array_v3 = pattern::wrap_type(); + + matcher_pass_callback callback = [=](pattern::Matcher& m) { + NodeRegistry rg; + + auto tensor_array_v3 = dynamic_pointer_cast(m.get_match_root()); + if (!tensor_array_v3) { + return false; + } + + int32_t tensor_element_rank = static_cast(tensor_array_v3->get_element_rank()); + if (tensor_element_rank < 0) { + return false; + } + + // retrieve all TensorArrayV3 inputs + auto size = tensor_array_v3->input_value(0); + auto element_type = tensor_array_v3->get_element_type(); + + // adjust size to have it of shape [1] for further concatenation with element shape + auto new_size_shape = rg.make(element::i32, Shape{1}, 1); + auto new_size = rg.make(size, new_size_shape, false); + + // create a vector of size element_shape.rank() with ones + // and compute a shape of initial tensor array [size, 1, ..., 1] + Output target_shape; + if (tensor_element_rank == 0) { + target_shape = new_size->output(0); + } else { + vector ones(tensor_element_rank, 1); + auto ones_const = rg.make(element::i32, Shape{ones.size()}, ones); + target_shape = rg.make(OutputVector{new_size, ones_const}, 0)->output(0); + } + + // create initial tensor array + auto scalar_value = make_shared(element_type, Shape{}, vector{0}); + auto initial_tensor_array = make_shared(scalar_value, target_shape); + + // preserve names of the node and the output tensor + initial_tensor_array->set_friendly_name(tensor_array_v3->get_friendly_name()); + copy_runtime_info(tensor_array_v3, rg.get()); + + ov::replace_node(tensor_array_v3, + ov::OutputVector{initial_tensor_array->output(0), initial_tensor_array->output(0)}); + return true; + }; + + auto m = + std::make_shared(tensor_array_v3, "ov::frontend::tensorflow::pass::TensorArrayV3Replacer"); + register_matcher(m, callback); +} diff --git a/src/frontends/tensorflow_common/src/op/gather_tree.cpp b/src/frontends/tensorflow_common/src/op/gather_tree.cpp new file mode 100644 index 00000000000000..e349efe6784e64 --- /dev/null +++ b/src/frontends/tensorflow_common/src/op/gather_tree.cpp @@ -0,0 +1,39 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/op/gather_tree.hpp" + +#include "common_op_table.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/reshape.hpp" + +using namespace std; +using namespace ov::op; + +namespace ov { +namespace frontend { +namespace tensorflow { +namespace op { + +OutputVector translate_gather_tree_op(const NodeContext& node) { + default_op_checks(node, 4, {"GatherTree", "Addons>GatherTree"}); + auto step_ids = node.get_input(0); + auto parent_ids = node.get_input(1); + auto max_sequence_lengths = node.get_input(2); + auto end_token = node.get_input(3); + + // adjust end_token that must be a scalar + auto new_shape_end_token = make_shared(element::i32, Shape{0}, vector{}); + end_token = make_shared(end_token, new_shape_end_token, false); + + auto gather_tree = make_shared(step_ids, parent_ids, max_sequence_lengths, end_token); + set_node_name(node.get_name(), gather_tree); + + return {gather_tree}; +} + +} // namespace op +} // namespace tensorflow +} // namespace frontend +} // namespace ov diff --git a/src/frontends/tensorflow_common/src/op/matmul.cpp b/src/frontends/tensorflow_common/src/op/matmul.cpp index dd3aba71ddf5cd..21a0591d109b69 100644 --- a/src/frontends/tensorflow_common/src/op/matmul.cpp +++ b/src/frontends/tensorflow_common/src/op/matmul.cpp @@ -35,6 +35,26 @@ OutputVector translate_batch_mat_mul_op(const NodeContext& node) { set_node_name(node.get_name(), result); return result->outputs(); } + +OutputVector translate_batch_mat_mul_with_type_op(const NodeContext& node) { + auto x = node.get_input(0); + auto y = node.get_input(1); + + auto input_type = x.get_element_type(); + + auto adj_x = node.get_attribute("adj_x", false); + auto adj_y = node.get_attribute("adj_y", false); + auto t_out = node.get_attribute("Tout", input_type); + + auto result = make_shared(x, y, adj_x, adj_y)->output(0); + + if (t_out != input_type) { + result = make_shared(result, t_out); + } + + set_node_name(node.get_name(), result.get_node_shared_ptr()); + return {result}; +} } // namespace op } // namespace tensorflow } // namespace frontend diff --git a/src/frontends/tensorflow_common/src/op/ones_like.cpp b/src/frontends/tensorflow_common/src/op/ones_like.cpp new file mode 100644 index 00000000000000..2084f3db1919cd --- /dev/null +++ b/src/frontends/tensorflow_common/src/op/ones_like.cpp @@ -0,0 +1,46 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_op_table.hpp" +#include "openvino/op/broadcast.hpp" +#include "openvino/op/concat.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/shape_of.hpp" +#include "openvino/op/squeeze.hpp" +#include "utils.hpp" + +using namespace std; +using namespace ov::op; + +namespace ov { +namespace frontend { +namespace tensorflow { +namespace op { + +OutputVector translate_ones_like_op(const NodeContext& node) { + default_op_checks(node, 1, {"OnesLike"}); + auto x = node.get_input(0); + Output shape_of = make_shared(x, element::i32); + auto one_const = create_same_type_const_scalar(x, 1); + + // in case of x to be scalar, we need handle it more specifically + // since Broadcast supports only broadcasting to rank greater 0 + // we have to introduce extra dimension for input scalar case + auto one_dim = make_shared(element::i32, Shape{1}, 1); + shape_of = make_shared(OutputVector{one_dim, shape_of}, 0); + + // create a tensor of zeros of shape with extra dimension + Output ones_like = make_shared(one_const, shape_of); + // remove extra dimension by squeezing + auto zero_dim_ind = make_shared(element::i32, Shape{1}, 0); + ones_like = make_shared(ones_like, zero_dim_ind); + + set_node_name(node.get_name(), ones_like.get_node_shared_ptr()); + return {ones_like}; +} + +} // namespace op +} // namespace tensorflow +} // namespace frontend +} // namespace ov diff --git a/src/frontends/tensorflow_common/src/op/tobool.cpp b/src/frontends/tensorflow_common/src/op/tobool.cpp new file mode 100644 index 00000000000000..a8d595800a4f5c --- /dev/null +++ b/src/frontends/tensorflow_common/src/op/tobool.cpp @@ -0,0 +1,68 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_op_table.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/equal.hpp" +#include "openvino/op/greater.hpp" +#include "openvino/op/logical_and.hpp" +#include "openvino/op/logical_or.hpp" +#include "openvino/op/not_equal.hpp" +#include "openvino/op/reduce_prod.hpp" +#include "openvino/op/select.hpp" +#include "openvino/op/shape_of.hpp" + +using namespace std; +using namespace ov::op; + +namespace ov { +namespace frontend { +namespace tensorflow { +namespace op { +OutputVector translate_tobool_op(const NodeContext& node) { + // (rank(x) == 0 && x != 0) || (rank > 0 && ReduceProd(ShapeOf(x))) > 0 + + default_op_checks(node, 1, {"ToBool"}); + auto x = node.get_input(0); + + // prepare auxiliary zero and zero constants of the same type as the inputs + auto zero = create_same_type_const_scalar(x, 0); + auto zero_2 = make_shared(element::i32, Shape{}, 0); + auto true_const = make_shared(element::boolean, Shape{}, true); + auto false_const = make_shared(element::boolean, Shape{}, false); + // compute a mask to get rank(x) == 0 + auto x_rank = compute_subgraph_scalar_rank(x, element::i32); + + // compute rank(x) == 0 + auto is_zero = make_shared(x_rank, zero_2); + + // compute mask to get x != 0 + auto is_not_zero = make_shared(x, zero); + + // compute (rank(x) == 0 && x != 0) + auto logical_and = make_shared(is_zero, is_not_zero); + // compute rank(x) > 0 + auto greater_than_zero = make_shared(x_rank, zero_2); + + // compute ShapeOf(x) + auto cond_shape = make_shared(x, element::i32); + // compute ReduceProd(ShapeOf(x))) and axis + auto axis = make_shared(element::i32, Shape{}, 0); + auto reduce_prod = make_shared(cond_shape, axis); + + // compute ReduceProd(ShapeOf(x))) > 0 + auto greater_than__zero_2 = make_shared(reduce_prod, zero_2); + // compute (rank > 0 && ReduceProd(ShapeOf(x))) > 0 + auto logical_and_2 = make_shared(greater_than_zero, greater_than__zero_2); + + auto logical_or = make_shared(logical_and, logical_and_2); + + auto tobool = make_shared(logical_or, true_const, false_const); + set_node_name(node.get_name(), tobool); + return tobool->outputs(); +} +} // namespace op +} // namespace tensorflow +} // namespace frontend +} // namespace ov \ No newline at end of file diff --git a/src/frontends/tensorflow_common/src/op/truncate_div.cpp b/src/frontends/tensorflow_common/src/op/truncate_div.cpp new file mode 100644 index 00000000000000..b725bbd76b44a3 --- /dev/null +++ b/src/frontends/tensorflow_common/src/op/truncate_div.cpp @@ -0,0 +1,36 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_op_table.hpp" +#include "openvino/op/ceiling.hpp" +#include "openvino/op/divide.hpp" +#include "openvino/op/equal.hpp" +#include "openvino/op/floor.hpp" +#include "openvino/op/less.hpp" +#include "openvino/op/mod.hpp" +#include "openvino/op/select.hpp" + +using namespace std; +using namespace ov::opset10; + +namespace ov { +namespace frontend { +namespace tensorflow { +namespace op { +OutputVector translate_truncate_div_op(const NodeContext& node) { + default_op_checks(node, 2, {"TruncateDiv"}); + auto x = node.get_input(0); + auto y = node.get_input(1); + + auto res = make_shared(x, y); + auto is_res_negative = make_shared(res, create_same_type_const_scalar(x, 0)); + auto final_res = make_shared(is_y_negative, negative_y, y); + + // check if floor_mod == zero + auto floor_mod = make_shared(x, y); + auto is_zero = make_shared(floor_mod, create_same_type_const_scalar(floor_mod, 0)); + + // floor_mod - y + auto other_res = make_shared(floor_mod, y); + + // select operation to handle the sign + auto result = make_shared(is_x_negative, other_res, floor_mod)); + + set_node_name(node.get_name(), result); + return result->outputs(); +} +} // namespace op +} // namespace tensorflow +} // namespace frontend +} // namespace ov diff --git a/src/frontends/tensorflow_common/src/op/xlog1py.cpp b/src/frontends/tensorflow_common/src/op/xlog1py.cpp new file mode 100644 index 00000000000000..cf24fec54382d3 --- /dev/null +++ b/src/frontends/tensorflow_common/src/op/xlog1py.cpp @@ -0,0 +1,43 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_op_table.hpp" +#include "openvino/op/add.hpp" +#include "openvino/op/equal.hpp" +#include "openvino/op/log.hpp" +#include "openvino/op/multiply.hpp" +#include "openvino/op/select.hpp" + +using namespace std; +using namespace ov::opset10; + +namespace ov { +namespace frontend { +namespace tensorflow { +namespace op { +OutputVector translate_xlog1py_op(const NodeContext& node) { + default_op_checks(node, 2, {"Xlog1py"}); + auto x = node.get_input(0); + auto y = node.get_input(1); + + // prepare auxiliary constants of the same type as the input + auto zero = create_same_type_const_scalar(x, 0); + auto one = create_same_type_const_scalar(y, 1); + + // compute a mask to identify where x is equal to 0 + auto is_zero = make_shared(x, zero); + + // compute x * log(y + 1) elementwise + auto xlog1py = make_shared(x, make_shared(make_shared(y, one))); + + // create the output tensor using Select to handle the x == 0 condition + auto result = make_shared(is_zero, zero, xlog_y); + + set_node_name(node.get_name(), result); + return result->outputs(); +} +} // namespace op +} // namespace tensorflow +} // namespace frontend +} // namespace ov diff --git a/src/frontends/tensorflow_lite/tests/CMakeLists.txt b/src/frontends/tensorflow_lite/tests/CMakeLists.txt index ddb2fba4d9c429..ef6ca4ee670732 100644 --- a/src/frontends/tensorflow_lite/tests/CMakeLists.txt +++ b/src/frontends/tensorflow_lite/tests/CMakeLists.txt @@ -4,6 +4,15 @@ set(TARGET_NAME "ov_tensorflow_lite_frontend_tests") +ov_check_pip_packages(REQUIREMENTS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt" + MESSAGE_MODE WARNING + WARNING_MESSAGE "TensorFlow Lite testing models weren't generated, some tests will fail due models not found" + RESULT_VAR tensorflow_FOUND) + +if(tensorflow_FOUND) + set(ctest_labels OV UNIT) +endif() + ov_add_test_target( NAME ${TARGET_NAME} ROOT ${CMAKE_CURRENT_SOURCE_DIR} @@ -16,16 +25,11 @@ ov_add_test_target( openvino_tensorflow_lite_frontend ADD_CLANG_FORMAT LABELS - OV UNIT TFL_FE + ${ctest_labels} TFL_FE ) # Test model generating -ov_check_pip_packages(REQUIREMENTS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt" - MESSAGE_MODE WARNING - WARNING_MESSAGE "TensorFlow Lite testing models weren't generated, some tests will fail due models not found" - RESULT_VAR tensorflow_FOUND) - set(TEST_TENSORFLOW_LITE_MODELS_DIRNAME ${TEST_MODEL_ZOO}/tensorflow_lite_test_models) target_compile_definitions(${TARGET_NAME} PRIVATE -D TEST_TENSORFLOW_LITE_MODELS_DIRNAME=\"${TEST_TENSORFLOW_LITE_MODELS_DIRNAME}/\") diff --git a/src/frontends/tests/frontend/shared/CMakeLists.txt b/src/frontends/tests/frontend/shared/CMakeLists.txt index f99a3d82e9f816..f413e359afb738 100644 --- a/src/frontends/tests/frontend/shared/CMakeLists.txt +++ b/src/frontends/tests/frontend/shared/CMakeLists.txt @@ -17,8 +17,10 @@ target_include_directories(${TARGET_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../ target_link_libraries(${TARGET_NAME} PUBLIC - offline_transformations - common_test_utils func_test_utils openvino::util + openvino::offline_transformations + common_test_utils + func_test_utils + openvino::util openvino::runtime PRIVATE cnpy) @@ -28,6 +30,6 @@ add_dependencies(${TARGET_NAME} test_builtin_extensions) target_compile_definitions(${TARGET_NAME} PRIVATE SHARED_LIB_PREFIX="${CMAKE_SHARED_LIBRARY_PREFIX}" - SHARED_LIB_SUFFIX="${IE_BUILD_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}") + SHARED_LIB_SUFFIX="${OV_BUILD_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}") ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}) diff --git a/src/frontends/tests/frontend/shared/src/conversion.cpp b/src/frontends/tests/frontend/shared/src/conversion.cpp index 286a5bd638adf4..34f3e9d6897eaa 100644 --- a/src/frontends/tests/frontend/shared/src/conversion.cpp +++ b/src/frontends/tests/frontend/shared/src/conversion.cpp @@ -30,7 +30,7 @@ void FrontEndConversionExtensionTest::initParamTest() { inline std::string get_lib_path(const std::string& lib_name) { return ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - lib_name + IE_BUILD_POSTFIX); + lib_name + OV_BUILD_POSTFIX); } /////////////////////////////////////////////////////////////////// diff --git a/src/frontends/tests/frontend/shared/src/library_extension.cpp b/src/frontends/tests/frontend/shared/src/library_extension.cpp index 75f68869775520..8a6bb23d82f0ef 100644 --- a/src/frontends/tests/frontend/shared/src/library_extension.cpp +++ b/src/frontends/tests/frontend/shared/src/library_extension.cpp @@ -9,6 +9,7 @@ #include "common_test_utils/file_utils.hpp" #include "openvino/op/relu.hpp" #include "openvino/op/swish.hpp" +#include "openvino/runtime/core.hpp" #include "utils.hpp" using namespace ov::frontend; @@ -31,7 +32,7 @@ void FrontendLibraryExtensionTest::initParamTest() { inline std::string get_lib_path(const std::string& lib_name) { return ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - lib_name + IE_BUILD_POSTFIX); + lib_name + OV_BUILD_POSTFIX); } /////////////////////////////////////////////////////////////////// @@ -88,3 +89,30 @@ TEST_P(FrontendLibraryExtensionTest, verifyFunctions) { nodes.end()); } } + +TEST_P(FrontendLibraryExtensionTest, loadExtensionBeforeFrontend) { + // release all frontends internally + ov::shutdown(); + + const auto& lib_path = get_lib_path("test_builtin_extensions"); + + ov::Core core; + core.add_extension(lib_path); + + auto model = core.read_model(m_param.m_modelName); + ASSERT_NE(nullptr, model); + + const auto nodes = model->get_ops(); + ASSERT_EQ(std::find_if(nodes.begin(), + nodes.end(), + [](const std::shared_ptr& n) { + return ov::is_type(n); + }), + nodes.end()); + ASSERT_NE(std::find_if(nodes.begin(), + nodes.end(), + [](const std::shared_ptr& n) { + return ov::is_type(n); + }), + nodes.end()); +} diff --git a/src/inference/CMakeLists.txt b/src/inference/CMakeLists.txt index 19bf83c27e18f9..11ad85b3740d6a 100644 --- a/src/inference/CMakeLists.txt +++ b/src/inference/CMakeLists.txt @@ -20,8 +20,8 @@ file (GLOB LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp_interfaces/interface/*.cpp ) -set(IE_STATIC_DEPENDENT_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/file_utils.cpp) -list(REMOVE_ITEM LIBRARY_SRC ${IE_STATIC_DEPENDENT_FILES}) +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 @@ -66,7 +66,7 @@ if(ENABLE_SSE42) list(APPEND LIBRARY_HEADERS ${SSE_HEADERS}) list(APPEND LIBRARY_SRC ${SSE_SRC}) - ie_sse42_optimization_flags(sse4_2_flags) + ov_sse42_optimization_flags(sse4_2_flags) set_source_files_properties(${SSE_SRC} PROPERTIES COMPILE_OPTIONS "${sse4_2_flags}") add_definitions(-DHAVE_SSE=1) @@ -118,7 +118,7 @@ ov_ncc_naming_style(FOR_TARGET ${TARGET_NAME}_plugin_api # Create object library add_library(${TARGET_NAME}_obj OBJECT - ${IE_STATIC_DEPENDENT_FILES} + ${OV_STATIC_DEPENDENT_FILES} ${LIBRARY_SRC} ${LIBRARY_HEADERS} ${PUBLIC_HEADERS}) @@ -174,7 +174,7 @@ target_link_libraries(${TARGET_NAME} INTERFACE openvino::runtime) target_include_directories(${TARGET_NAME} INTERFACE $ $) -ov_add_clang_format_target(${TARGET_NAME}_clang FOR_SOURCES ${IE_STATIC_DEPENDENT_FILES} ${LIBRARY_SRC} ${LIBRARY_HEADERS} ${PUBLIC_HEADERS}) +ov_add_clang_format_target(${TARGET_NAME}_clang FOR_SOURCES ${OV_STATIC_DEPENDENT_FILES} ${LIBRARY_SRC} ${LIBRARY_HEADERS} ${PUBLIC_HEADERS}) ov_ncc_naming_style(FOR_TARGET ${TARGET_NAME}_obj SOURCE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include/openvino" @@ -199,8 +199,8 @@ if(WIN32) set_target_properties(${TARGET_NAME}_s PROPERTIES COMPILE_PDB_NAME ${TARGET_NAME}_s) endif() -target_link_libraries(${TARGET_NAME}_s PRIVATE openvino::itt ${CMAKE_DL_LIBS} ngraph - frontend_common::static inference_engine_transformations openvino::pugixml) +target_link_libraries(${TARGET_NAME}_s PRIVATE openvino::itt ${CMAKE_DL_LIBS} + openvino::runtime::dev openvino::pugixml) target_compile_definitions(${TARGET_NAME}_s PUBLIC USE_STATIC_IE) @@ -215,7 +215,8 @@ set_target_properties(${TARGET_NAME}_obj # Export for developer package -openvino_developer_export_targets(COMPONENT core_legacy TARGETS ${TARGET_NAME}_plugin_api) +ov_developer_package_export_targets(TARGET ${TARGET_NAME}_s) +ov_developer_package_export_targets(TARGET ${TARGET_NAME}_plugin_api) # Install static libraries for case BUILD_SHARED_LIBS=OFF diff --git a/src/inference/dev_api/ie_icore.hpp b/src/inference/dev_api/ie_icore.hpp index 8852c1f4ecd8c9..2210f26bbfc6ef 100644 --- a/src/inference/dev_api/ie_icore.hpp +++ b/src/inference/dev_api/ie_icore.hpp @@ -191,7 +191,7 @@ class ICore : public ov::ICore { virtual InferenceEngine::RemoteContext::Ptr CreateContext(const std::string& deviceName, const ov::AnyMap&) = 0; /** - * @brief Get only configs that are suppored by device + * @brief Get only configs that are supported by device * @param deviceName Name of a device * @param config Map of configs that can contains configs that are not supported by device * @return map of configs that are supported by device diff --git a/src/inference/dev_api/ie_ngraph_utils.hpp b/src/inference/dev_api/ie_ngraph_utils.hpp index 57ea7a00036d51..aeaa0b4d9b0ba2 100644 --- a/src/inference/dev_api/ie_ngraph_utils.hpp +++ b/src/inference/dev_api/ie_ngraph_utils.hpp @@ -101,6 +101,8 @@ INFERENCE_ENGINE_1_0_DEPRECATED inline Precision convertPrecision(const ::ngraph return Precision(Precision::BIN); case ::ngraph::element::Type_t::boolean: return Precision(Precision::BOOL); + case ::ngraph::element::Type_t::nf4: + return Precision(Precision::NF4); case ::ngraph::element::Type_t::dynamic: return Precision(Precision::UNSPECIFIED); default: diff --git a/src/inference/dev_api/openvino/runtime/icore.hpp b/src/inference/dev_api/openvino/runtime/icore.hpp index e4d0a98f5be968..de2ca2ebf07c57 100644 --- a/src/inference/dev_api/openvino/runtime/icore.hpp +++ b/src/inference/dev_api/openvino/runtime/icore.hpp @@ -222,7 +222,7 @@ class OPENVINO_RUNTIME_API ICore { } /** - * @brief Get only properties that are suppored by specified device + * @brief Get only properties that are supported by specified device * @param full_device_name Name of a device (can be either virtual or hardware) * @param properties Properties that can contains configs that are not supported by device * @return map of properties that are supported by device diff --git a/src/inference/dev_api/openvino/runtime/isync_infer_request.hpp b/src/inference/dev_api/openvino/runtime/isync_infer_request.hpp index ed15438de2eb83..938fa8924fbb05 100644 --- a/src/inference/dev_api/openvino/runtime/isync_infer_request.hpp +++ b/src/inference/dev_api/openvino/runtime/isync_infer_request.hpp @@ -124,6 +124,12 @@ class OPENVINO_RUNTIME_API ISyncInferRequest : public IInferRequest { } }; + /** + * @brief Finds input or output port + * @return structure which contains index of Input/Output or report that port wasn't found + */ + FoundPort find_port(const ov::Output& port) const; + /** * @brief Converts batched tensors to tensor */ @@ -157,12 +163,9 @@ class OPENVINO_RUNTIME_API ISyncInferRequest : public IInferRequest { std::shared_ptr m_compiled_model; // Mutable to return reference to ov::Tensor mutable std::unordered_map, ov::SoPtr> m_tensors; - - /** - * @brief Finds input or output port - * @return structure which contains index of Input/Output or report that port wasn't found - */ - FoundPort find_port(const ov::Output& port) const; + // Cache ports + mutable std::unordered_map m_cached_ports; + mutable std::mutex m_cache_mutex; }; }; // namespace ov diff --git a/src/inference/include/ie/ie_precision.hpp b/src/inference/include/ie/ie_precision.hpp index 099a1d9881f593..17b995244e253b 100644 --- a/src/inference/include/ie/ie_precision.hpp +++ b/src/inference/include/ie/ie_precision.hpp @@ -41,6 +41,7 @@ class INFERENCE_ENGINE_1_0_DEPRECATED Precision { FP16 = 11, /**< 16bit floating point value, 5 bit for exponent, 10 bit for mantisa */ BF16 = 12, /**< 16bit floating point value, 8 bit for exponent, 7 bit for mantisa*/ FP64 = 13, /**< 64bit floating point value */ + NF4 = 14, /**< 4bit normalized float value */ Q78 = 20, /**< 16bit specific signed fixed point precision */ I16 = 30, /**< 16bit signed integer value */ U4 = 39, /**< 4bit unsigned integer value */ @@ -131,6 +132,7 @@ class INFERENCE_ENGINE_1_0_DEPRECATED Precision { CASE(FP64, double); CASE2(FP16, int16_t, uint16_t); CASE2(BF16, int16_t, uint16_t); + CASE(NF4, int8_t); CASE2(I4, int8_t, uint8_t); CASE(I8, int8_t); CASE(I16, int16_t); @@ -249,24 +251,11 @@ class INFERENCE_ENGINE_1_0_DEPRECATED Precision { static Precision FromStr(const std::string& str) { static const std::unordered_map names = { #define PRECISION_NAME(s) {#s, s} - PRECISION_NAME(Q78), - PRECISION_NAME(BOOL), - PRECISION_NAME(BF16), - PRECISION_NAME(I4), - PRECISION_NAME(I8), - PRECISION_NAME(I16), - PRECISION_NAME(I32), - PRECISION_NAME(I64), - PRECISION_NAME(U4), - PRECISION_NAME(U8), - PRECISION_NAME(U16), - PRECISION_NAME(U32), - PRECISION_NAME(U64), - PRECISION_NAME(FP32), - PRECISION_NAME(FP64), - PRECISION_NAME(FP16), - PRECISION_NAME(MIXED), - PRECISION_NAME(BIN), + PRECISION_NAME(Q78), PRECISION_NAME(BOOL), PRECISION_NAME(BF16), PRECISION_NAME(I4), + PRECISION_NAME(I8), PRECISION_NAME(I16), PRECISION_NAME(I32), PRECISION_NAME(I64), + PRECISION_NAME(U4), PRECISION_NAME(U8), PRECISION_NAME(U16), PRECISION_NAME(U32), + PRECISION_NAME(U64), PRECISION_NAME(FP32), PRECISION_NAME(FP64), PRECISION_NAME(FP16), + PRECISION_NAME(MIXED), PRECISION_NAME(NF4), PRECISION_NAME(BIN), #undef PRECISION_NAME }; auto i = names.find(str); @@ -311,7 +300,8 @@ class INFERENCE_ENGINE_1_0_DEPRECATED Precision { (precisionInfo.value == Precision::I16) || (precisionInfo.value == Precision::I8) || (precisionInfo.value == Precision::I32) || (precisionInfo.value == Precision::I64) || (precisionInfo.value == Precision::BIN) || (precisionInfo.value == Precision::BF16) || - (precisionInfo.value == Precision::CUSTOM) || (precisionInfo.value == Precision::I4); + (precisionInfo.value == Precision::CUSTOM) || (precisionInfo.value == Precision::I4) || + (precisionInfo.value == Precision::NF4); } protected: @@ -359,6 +349,7 @@ class INFERENCE_ENGINE_1_0_DEPRECATED Precision { CASE(FP64); CASE(FP16); CASE(BF16); + CASE(NF4); CASE(I4); CASE(I8); CASE(I16); @@ -475,6 +466,12 @@ struct INFERENCE_ENGINE_1_0_DEPRECATED PrecisionTrait { enum { is_float = false }; }; +template <> +struct INFERENCE_ENGINE_1_0_DEPRECATED PrecisionTrait { + using value_type = int8_t; + enum { is_float = false }; +}; + template INFERENCE_ENGINE_1_0_DEPRECATED inline uint8_t type_size_or_zero() { return sizeof(T); @@ -499,7 +496,7 @@ INFERENCE_ENGINE_1_0_DEPRECATED inline Precision::PrecisionInfo Precision::makeP Precision::PrecisionInfo info; info.name = name; - size_t nBits = precision == BIN ? 1 : (precision == U4 || precision == I4) ? 4 : 8; + size_t nBits = precision == BIN ? 1 : (precision == U4 || precision == I4 || precision == NF4) ? 4 : 8; info.bitsSize = nBits * type_size_or_zero::value_type>(); info.isFloat = PrecisionTrait::is_float; info.value = precision; diff --git a/src/inference/src/dev/isync_infer_request.cpp b/src/inference/src/dev/isync_infer_request.cpp index 8e0f554fedd900..94d714d9f134a5 100644 --- a/src/inference/src/dev/isync_infer_request.cpp +++ b/src/inference/src/dev/isync_infer_request.cpp @@ -4,6 +4,7 @@ #include "openvino/runtime/isync_infer_request.hpp" +#include #include #include @@ -17,6 +18,7 @@ #include "openvino/runtime/make_tensor.hpp" #include "openvino/runtime/plugin_itt.hpp" #include "openvino/runtime/tensor.hpp" +#include "openvino/util/common_util.hpp" namespace { void check_batched_tensors(const ov::Output& input, @@ -93,14 +95,18 @@ ov::IInferRequest::~IInferRequest() = default; ov::ISyncInferRequest::ISyncInferRequest(const std::shared_ptr& compiled_model) : m_compiled_model(compiled_model) { OPENVINO_ASSERT(m_compiled_model); - // Create map of empty tensors - for (const auto& input : get_inputs()) { - if (m_tensors.find(input.get_tensor_ptr()) == m_tensors.end()) - m_tensors[input.get_tensor_ptr()] = ov::SoPtr(); - } - for (const auto& output : get_outputs()) { - if (m_tensors.find(output.get_tensor_ptr()) == m_tensors.end()) - m_tensors[output.get_tensor_ptr()] = ov::SoPtr(); + // Create map of empty tensors and cache ports from the compiled model + auto port_type = ov::ISyncInferRequest::FoundPort::Type::INPUT; + for (const auto& ports : {get_inputs(), get_outputs()}) { + for (size_t i = 0; i < ports.size(); i++) { + const auto& port = ports[i]; + if (m_tensors.find(port.get_tensor_ptr()) == m_tensors.end()) + m_tensors[port.get_tensor_ptr()] = ov::SoPtr(); + size_t port_hash = ov::util::hash_combine(std::vector{std::hash()(port.get_node()), + std::hash()(port.get_index())}); + m_cached_ports[port_hash] = {i, port_type}; + } + port_type = ov::ISyncInferRequest::FoundPort::Type::OUTPUT; } } @@ -118,18 +124,30 @@ ov::ISyncInferRequest::FoundPort ov::ISyncInferRequest::find_port(const ov::Outp // This function is hotspot, need optimization. auto check_nodes = [](const ov::Node* node1, const ov::Node* node2) { return node1 == node2 || - (node1->get_friendly_name() == node2->get_friendly_name() && - node1->get_type_info() == node2->get_type_info() && - node1->outputs().size() == node2->outputs().size() && node1->inputs().size() == node2->inputs().size()); + (node1->outputs().size() == node2->outputs().size() && + node1->inputs().size() == node2->inputs().size() && node1->get_type_info() == node2->get_type_info() && + node1->get_friendly_name() == node2->get_friendly_name()); }; + // Find port without caching work slow because we need each time iterate over all ports and compare different + // strings So use WA with caching in order to make 2+ calls for the same ports faster. + // Calculate hash for the port + size_t port_hash = ov::util::hash_combine( + std::vector{std::hash()(port.get_node()), std::hash()(port.get_index())}); + { + std::lock_guard lock(m_cache_mutex); + if (m_cached_ports.find(port_hash) != m_cached_ports.end()) { + // Cached port for the hash was found + return m_cached_ports[port_hash]; + } + } ov::ISyncInferRequest::FoundPort::Type type = ov::ISyncInferRequest::FoundPort::Type::INPUT; for (const auto& ports : {get_inputs(), get_outputs()}) { for (size_t i = 0; i < ports.size(); i++) { - // TODO: Fix port comparison - // if (ports[i] == port) { if (ports[i].get_index() == port.get_index() && ports[i].get_names() == port.get_names() && check_nodes(ports[i].get_node(), port.get_node())) { - return {i, type}; + std::lock_guard lock(m_cache_mutex); + m_cached_ports[port_hash] = {i, type}; + return m_cached_ports[port_hash]; } } type = ov::ISyncInferRequest::FoundPort::Type::OUTPUT; @@ -275,10 +293,10 @@ void ov::ISyncInferRequest::allocate_tensor( void ov::ISyncInferRequest::check_tensors() const { const auto& inputs = m_compiled_model->inputs(); for (size_t i = 0; i < inputs.size(); i++) { - check_tensor(inputs[i], get_tensor_ptr(inputs[i])); + check_tensor(inputs[i], m_tensors.at(inputs[i].get_tensor_ptr())); } const auto& outputs = m_compiled_model->outputs(); for (size_t i = 0; i < outputs.size(); i++) { - check_tensor(outputs[i], get_tensor_ptr(outputs[i])); + check_tensor(outputs[i], m_tensors.at(outputs[i].get_tensor_ptr())); } } diff --git a/src/inference/src/dev/threading/cpu_streams_executor.cpp b/src/inference/src/dev/threading/cpu_streams_executor.cpp index dba0082d647080..691a3951615460 100644 --- a/src/inference/src/dev/threading/cpu_streams_executor.cpp +++ b/src/inference/src/dev/threading/cpu_streams_executor.cpp @@ -4,6 +4,7 @@ #include "openvino/runtime/threading/cpu_streams_executor.hpp" +#include #include #include #include @@ -22,8 +23,6 @@ namespace ov { namespace threading { -// maybe there are two CPUStreamsExecutors in the same thread. -thread_local std::map> t_stream_count_map; struct CPUStreamsExecutor::Impl { struct Stream { #if OV_THREAD == OV_THREAD_TBB || OV_THREAD == OV_THREAD_TBB_AUTO @@ -335,12 +334,58 @@ struct CPUStreamsExecutor::Impl { // will be counted by thread_local t_stream_count_map. // when the customer's thread is destoryed, the stream's count will became 1, // Call local() will reuse one of them, and release others. + // it's only a workaround for ticket CVS-111490, please be carefully when need to modify + // CustomeThreadLocal::local(), especially like operations that will affect the count of + // CustomThreadLocal::ThreadId class CustomThreadLocal : public ThreadLocal> { + class ThreadTracker { + public: + explicit ThreadTracker(const std::thread::id& id) + : _id(id), + _count_ptr(std::make_shared(1)) {} + ~ThreadTracker() { + _count_ptr->fetch_sub(1); + } + std::shared_ptr fetch() { + auto new_ptr = std::shared_ptr(new ThreadTracker(*this)); + auto pre_valule = new_ptr.get()->_count_ptr->fetch_add(1); + OPENVINO_ASSERT(pre_valule == 1, "this value must be 1, please check code CustomThreadLocal::local()"); + return new_ptr; + } + const std::thread::id& get_id() const { + return _id; + } + int count() const { + return *(_count_ptr.get()); + } + + private: + // disable all copy and move semantics, user only can use fetch() + // to create a new instance with a shared count num; + ThreadTracker(ThreadTracker const&) = default; + ThreadTracker(ThreadTracker&&) = delete; + ThreadTracker& operator=(ThreadTracker const&) = delete; + ThreadTracker& operator=(ThreadTracker&&) = delete; + std::thread::id _id; + std::shared_ptr _count_ptr; + }; + public: CustomThreadLocal(std::function()> callback_construct, Impl* impl) : ThreadLocal>(callback_construct), _impl(impl) {} std::shared_ptr local() { + // maybe there are two CPUStreamsExecutors in the same thread. + static thread_local std::map> t_stream_count_map; + // fix the memory leak issue that CPUStreamsExecutor is already released, + // but still exists CustomThreadLocal::ThreadTracker in t_stream_count_map + for (auto it = t_stream_count_map.begin(); it != t_stream_count_map.end();) { + if (this != it->first && it->second->count() == 1) { + t_stream_count_map.erase(it++); + } else { + it++; + } + } auto id = std::this_thread::get_id(); auto search = _thread_ids.find(id); if (search != _thread_ids.end()) { @@ -348,14 +393,13 @@ struct CPUStreamsExecutor::Impl { } std::lock_guard guard(_stream_map_mutex); for (auto& item : _stream_map) { - if (*(item.first.get()) == id) { - t_stream_count_map[(void*)this] = item.first; + if (item.first->get_id() == id) { return item.second; } } std::shared_ptr stream = nullptr; for (auto it = _stream_map.begin(); it != _stream_map.end();) { - if (it->first.use_count() == 1) { + if (it->first->count() == 1) { if (stream == nullptr) { stream = it->second; } @@ -367,9 +411,10 @@ struct CPUStreamsExecutor::Impl { if (stream == nullptr) { stream = std::make_shared(_impl); } - auto id_ptr = std::make_shared(id); - t_stream_count_map[(void*)this] = id_ptr; - _stream_map[id_ptr] = stream; + auto tracker_ptr = std::make_shared(id); + t_stream_count_map[(void*)this] = tracker_ptr; + auto new_tracker_ptr = tracker_ptr->fetch(); + _stream_map[new_tracker_ptr] = stream; return stream; } @@ -382,7 +427,7 @@ struct CPUStreamsExecutor::Impl { private: std::set _thread_ids; Impl* _impl; - std::map, std::shared_ptr> _stream_map; + std::map, std::shared_ptr> _stream_map; std::mutex _stream_map_mutex; }; @@ -397,7 +442,7 @@ struct CPUStreamsExecutor::Impl { auto numaNodes = get_available_numa_nodes(); if (_config._streams != 0) { std::copy_n(std::begin(numaNodes), - std::min(static_cast(_config._streams), numaNodes.size()), + std::min(_config._streams, numaNodes.size()), std::back_inserter(_usedNumaNodes)); } else { _usedNumaNodes = numaNodes; diff --git a/src/inference/src/dev/threading/cpu_streams_executor_internal.cpp b/src/inference/src/dev/threading/cpu_streams_executor_internal.cpp index 7936130997b6a2..d8f65b086fcbe0 100644 --- a/src/inference/src/dev/threading/cpu_streams_executor_internal.cpp +++ b/src/inference/src/dev/threading/cpu_streams_executor_internal.cpp @@ -131,23 +131,25 @@ void reserve_cpu_by_streams_info(const std::vector> _streams_in } for (size_t i = 0; i < _cpu_mapping_table.size(); i++) { - std::string cpu_string = std::to_string(_cpu_mapping_table[i][CPU_MAP_CORE_TYPE]) + - std::to_string(_cpu_mapping_table[i][CPU_MAP_NUMA_NODE_ID]) + - std::to_string(_cpu_mapping_table[i][CPU_MAP_SOCKET_ID]); - for (size_t j = 0; j < stream_conditions.size(); j++) { - if (std::find(stream_conditions[j].begin(), stream_conditions[j].end(), cpu_string) != - stream_conditions[j].end()) { - _stream_processors[stream_pos[j]].push_back(_cpu_mapping_table[i][CPU_MAP_PROCESSOR_ID]); - _cpu_mapping_table[i][CPU_MAP_USED_FLAG] = _cpu_status; - if (static_cast(_stream_processors[stream_pos[j]].size()) == - streams_table[j][THREADS_PER_STREAM]) { - stream_pos[j]++; - stream_num[j]++; - } - if (stream_num[j] >= streams_table[j][NUMBER_OF_STREAMS]) { - stream_conditions[j].clear(); + if (_cpu_mapping_table[i][CPU_MAP_USED_FLAG] == NOT_USED) { + std::string cpu_string = std::to_string(_cpu_mapping_table[i][CPU_MAP_CORE_TYPE]) + + std::to_string(_cpu_mapping_table[i][CPU_MAP_NUMA_NODE_ID]) + + std::to_string(_cpu_mapping_table[i][CPU_MAP_SOCKET_ID]); + for (size_t j = 0; j < stream_conditions.size(); j++) { + if (std::find(stream_conditions[j].begin(), stream_conditions[j].end(), cpu_string) != + stream_conditions[j].end()) { + _stream_processors[stream_pos[j]].push_back(_cpu_mapping_table[i][CPU_MAP_PROCESSOR_ID]); + _cpu_mapping_table[i][CPU_MAP_USED_FLAG] = _cpu_status; + if (static_cast(_stream_processors[stream_pos[j]].size()) == + streams_table[j][THREADS_PER_STREAM]) { + stream_pos[j]++; + stream_num[j]++; + } + if (stream_num[j] >= streams_table[j][NUMBER_OF_STREAMS]) { + stream_conditions[j].clear(); + } + break; } - break; } } } diff --git a/src/inference/src/ie_core.cpp b/src/inference/src/ie_core.cpp index 97dc6382aaccea..a5babd9192768c 100644 --- a/src/inference/src/ie_core.cpp +++ b/src/inference/src/ie_core.cpp @@ -31,10 +31,6 @@ #include "ie_plugin_config.hpp" #include "ie_remote_context.hpp" #include "itt.hpp" -#include "ngraph/graph_util.hpp" -#include "ngraph/ngraph.hpp" -#include "ngraph/opsets/opset.hpp" -#include "ngraph/pass/constant_folding.hpp" #include "openvino/core/except.hpp" #include "openvino/core/so_extension.hpp" #include "openvino/op/parameter.hpp" diff --git a/src/inference/src/ie_network_reader.cpp b/src/inference/src/ie_network_reader.cpp index 8e7c8ecb823033..f5aca3586e8339 100644 --- a/src/inference/src/ie_network_reader.cpp +++ b/src/inference/src/ie_network_reader.cpp @@ -20,6 +20,7 @@ #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 @@ -113,7 +114,7 @@ void registerReaders() { // try to load IR reader v7 if library exists try { reader_irv7 = - std::make_shared(std::string("inference_engine_ir_v7_reader") + std::string(IE_BUILD_POSTFIX)); + 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 } @@ -388,8 +389,8 @@ CNNNetwork details::ReadNetwork(const std::string& model, ov::AnyVector params{&modelStream}; if (weights) { char* data = weights->cbuffer().as(); - std::shared_ptr weights_buffer = - std::make_shared>(data, weights->byteSize(), weights); + std::shared_ptr weights_buffer = + std::make_shared>(data, weights->byteSize(), weights); params.emplace_back(weights_buffer); } diff --git a/src/inference/src/model_reader.cpp b/src/inference/src/model_reader.cpp index 1837d75a2d44aa..bc67f6d21b225a 100644 --- a/src/inference/src/model_reader.cpp +++ b/src/inference/src/model_reader.cpp @@ -9,6 +9,8 @@ #include "openvino/core/model.hpp" #include "openvino/core/preprocess/pre_post_process.hpp" #include "openvino/frontend/manager.hpp" +#include "openvino/runtime/aligned_buffer.hpp" +#include "openvino/runtime/shared_buffer.hpp" #include "openvino/util/file_util.hpp" #include "transformations/utils/utils.hpp" @@ -155,10 +157,10 @@ std::shared_ptr read_model(const std::string& model, ov::AnyVector params{&modelStream}; if (weights) { - std::shared_ptr weights_buffer = - std::make_shared>(reinterpret_cast(weights.data()), - weights.get_byte_size(), - weights); + std::shared_ptr weights_buffer = + std::make_shared>(reinterpret_cast(weights.data()), + weights.get_byte_size(), + weights); params.emplace_back(weights_buffer); } diff --git a/src/inference/src/os/lin/lin_system_conf.cpp b/src/inference/src/os/lin/lin_system_conf.cpp index 02fbe263e15902..6d8bb4afad2b3b 100644 --- a/src/inference/src/os/lin/lin_system_conf.cpp +++ b/src/inference/src/os/lin/lin_system_conf.cpp @@ -201,7 +201,9 @@ CPU::CPU() { _cpu_mapping_table); } - if ((_proc_type_table.size() == 0) || (_proc_type_table[0][MAIN_CORE_PROC] == 0)) { + if ((_proc_type_table.size() == 0) || + ((_proc_type_table[0][MAIN_CORE_PROC] == 0) && (_proc_type_table[0][ALL_PROC] > 0) && + (_proc_type_table[0][ALL_PROC] != _proc_type_table[0][EFFICIENT_CORE_PROC]))) { if (!get_freq_info_linux()) { parse_freq_info_linux(system_info_table, node_info_table, @@ -214,7 +216,9 @@ CPU::CPU() { } } - if ((_proc_type_table.size() == 0) || (_proc_type_table[0][MAIN_CORE_PROC] == 0)) { + if ((_proc_type_table.size() == 0) || + ((_proc_type_table[0][MAIN_CORE_PROC] == 0) && (_proc_type_table[0][ALL_PROC] > 0) && + (_proc_type_table[0][ALL_PROC] != _proc_type_table[0][EFFICIENT_CORE_PROC]))) { /*Previous CPU resource based on calculation*/ std::ifstream cpuinfo("/proc/cpuinfo"); std::vector processors; diff --git a/src/inference/tests/functional/CMakeLists.txt b/src/inference/tests/functional/CMakeLists.txt index 16bcc08d4b95c8..4a42e9eb5bd5b4 100644 --- a/src/inference/tests/functional/CMakeLists.txt +++ b/src/inference/tests/functional/CMakeLists.txt @@ -44,6 +44,8 @@ ov_add_test_target( LINK_LIBRARIES gmock func_test_utils + DEFINES + ${COMPILE_DEFINITIONS} INCLUDES $/src ${CMAKE_CURRENT_SOURCE_DIR} @@ -52,4 +54,4 @@ ov_add_test_target( OV UNIT RUNTIME ) -add_compile_definitions(${TARGET_NAME} ${COMPILE_DEFINITIONS}) +ov_set_threading_interface_for(${TARGET_NAME}) diff --git a/src/inference/tests/functional/caching_test.cpp b/src/inference/tests/functional/caching_test.cpp index 8a313792b87af5..2668eafc44a34e 100644 --- a/src/inference/tests/functional/caching_test.cpp +++ b/src/inference/tests/functional/caching_test.cpp @@ -161,7 +161,7 @@ class CachingTest : public ::testing::TestWithParam( ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("template_extension") + IE_BUILD_POSTFIX)); + std::string("template_extension") + OV_BUILD_POSTFIX)); ie.AddExtension(extension); } catch (const InferenceEngine::Exception& ex) { ASSERT_STR_CONTAINS(ex.what(), "name: custom_opset. Opset"); @@ -95,7 +95,7 @@ TEST_F(IECoreThreadingTests, RegisterPlugin) { [&]() { const std::string deviceName = std::to_string(index++); ie.RegisterPlugin(ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("mock_engine") + IE_BUILD_POSTFIX), + std::string("mock_engine") + OV_BUILD_POSTFIX), deviceName); ie.GetVersions(deviceName); ie.UnregisterPlugin(deviceName); @@ -118,7 +118,7 @@ TEST_F(IECoreThreadingTests, RegisterPlugins) { file << ov::util::FileTraits::file_separator; file << ov::util::FileTraits::library_prefix(); file << "mock_engine"; - file << IE_BUILD_POSTFIX; + file << OV_BUILD_POSTFIX; file << ov::util::FileTraits::dot_symbol; file << ov::util::FileTraits::library_ext(); file << "\" name=\""; diff --git a/src/inference/tests/functional/get_supported_property_test.cpp b/src/inference/tests/functional/get_supported_property_test.cpp index b92fbdf18a9962..c1fea82d2552de 100644 --- a/src/inference/tests/functional/get_supported_property_test.cpp +++ b/src/inference/tests/functional/get_supported_property_test.cpp @@ -33,7 +33,7 @@ class GetPropertyTest : public ::testing::TestWithParam { injectProxyEngine(plugin.get()); core.register_plugin(ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("mock_engine") + IE_BUILD_POSTFIX), + std::string("mock_engine") + OV_BUILD_POSTFIX), m_plugin_name); m_mock_plugin = plugin; } diff --git a/src/inference/tests/functional/ov_core_threading.cpp b/src/inference/tests/functional/ov_core_threading.cpp index c935c8952358f1..96f954b5dcbd6c 100644 --- a/src/inference/tests/functional/ov_core_threading.cpp +++ b/src/inference/tests/functional/ov_core_threading.cpp @@ -64,7 +64,7 @@ class CoreThreadingTests : public ::testing::Test { OPENVINO_SUPPRESS_DEPRECATED_START auto extension = std::make_shared( ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("template_extension") + IE_BUILD_POSTFIX)); + std::string("template_extension") + OV_BUILD_POSTFIX)); core.add_extension(extension); OPENVINO_SUPPRESS_DEPRECATED_END } catch (const ov::Exception& ex) { @@ -95,7 +95,7 @@ TEST_F(CoreThreadingTests, RegisterPlugin) { [&]() { const std::string deviceName = std::to_string(index++); core.register_plugin(ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("mock_engine") + IE_BUILD_POSTFIX), + std::string("mock_engine") + OV_BUILD_POSTFIX), deviceName); core.get_versions(deviceName); core.unload_plugin(deviceName); @@ -118,7 +118,7 @@ TEST_F(CoreThreadingTests, RegisterPlugins) { file << ov::util::FileTraits::file_separator; file << ov::util::FileTraits::library_prefix(); file << "mock_engine"; - file << IE_BUILD_POSTFIX; + file << OV_BUILD_POSTFIX; file << ov::util::FileTraits::dot_symbol; file << ov::util::FileTraits::library_ext(); file << "\" name=\""; diff --git a/src/inference/tests/functional/ov_extension_test.cpp b/src/inference/tests/functional/ov_extension_test.cpp index 41cfd4813b3481..394526c1bc47da 100644 --- a/src/inference/tests/functional/ov_extension_test.cpp +++ b/src/inference/tests/functional/ov_extension_test.cpp @@ -15,23 +15,23 @@ namespace { std::string getOVExtensionPath() { return ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("openvino_template_extension") + IE_BUILD_POSTFIX); + std::string("openvino_template_extension") + OV_BUILD_POSTFIX); } std::string getOldExtensionPath() { return ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("template_extension") + IE_BUILD_POSTFIX); + std::string("template_extension") + OV_BUILD_POSTFIX); } std::string getIncorrectExtensionPath() { return ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("incorrect") + IE_BUILD_POSTFIX); + std::string("incorrect") + OV_BUILD_POSTFIX); } std::string getRelativeOVExtensionPath() { std::string absolutePath = ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("openvino_template_extension") + IE_BUILD_POSTFIX); + std::string("openvino_template_extension") + OV_BUILD_POSTFIX); return ov::test::utils::getRelativePath(ov::test::utils::getCurrentWorkingDir(), absolutePath); } diff --git a/src/inference/tests/functional/ov_register_plugin_test.cpp b/src/inference/tests/functional/ov_register_plugin_test.cpp index 0708cd347d916d..a3830743efb919 100644 --- a/src/inference/tests/functional/ov_register_plugin_test.cpp +++ b/src/inference/tests/functional/ov_register_plugin_test.cpp @@ -45,7 +45,7 @@ TEST(RegisterPluginTests, getVersionforRegisteredPluginThrows) { // Registered plugin with invalid so here ASSERT_NO_THROW(core.register_plugin( ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("mock_registered_engine") + IE_BUILD_POSTFIX), + std::string("mock_registered_engine") + OV_BUILD_POSTFIX), mock_plugin_name)); ASSERT_THROW(core.get_versions("MOCK_REGISTERED_HARDWARE"), ov::Exception); } @@ -72,7 +72,7 @@ TEST(RegisterPluginTests, getVersionforNoRegisteredPluginNoThrows) { ASSERT_NO_THROW( core.register_plugin(ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("mock_engine") + IE_BUILD_POSTFIX), + std::string("mock_engine") + OV_BUILD_POSTFIX), mock_plugin_name)); ASSERT_NO_THROW(core.get_versions("MOCK_HARDWARE")); } @@ -87,7 +87,7 @@ TEST(RegisterPluginTests, registerNewPluginNoThrows) { std::string mock_plugin_name{"MOCK_HARDWARE"}; ASSERT_NO_THROW( core.register_plugin(ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("mock_engine") + IE_BUILD_POSTFIX), + std::string("mock_engine") + OV_BUILD_POSTFIX), mock_plugin_name)); ASSERT_NO_THROW(core.get_property(mock_plugin_name, ov::supported_properties)); @@ -104,10 +104,10 @@ TEST(RegisterPluginTests, registerExistingPluginThrows) { std::string mock_plugin_name{"MOCK_HARDWARE"}; ASSERT_NO_THROW( core.register_plugin(ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("mock_engine") + IE_BUILD_POSTFIX), + std::string("mock_engine") + OV_BUILD_POSTFIX), mock_plugin_name)); ASSERT_THROW(core.register_plugin(ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("mock_engine") + IE_BUILD_POSTFIX), + std::string("mock_engine") + OV_BUILD_POSTFIX), mock_plugin_name), ov::Exception); } @@ -118,7 +118,7 @@ inline std::string getPluginFile() { std::ostringstream stream; stream << ""; ov::test::utils::createFile(filename, stream.str()); return filename; diff --git a/src/inference/tests/functional/ov_shared_object_test.cpp b/src/inference/tests/functional/ov_shared_object_test.cpp index 1d60528fdcca40..3c268ea94fa610 100644 --- a/src/inference/tests/functional/ov_shared_object_test.cpp +++ b/src/inference/tests/functional/ov_shared_object_test.cpp @@ -16,7 +16,7 @@ class SharedObjectOVTests : public ::testing::Test { protected: std::string get_mock_engine_name() { return FileUtils::makePluginLibraryName(ov::test::utils::getExecutableDirectory(), - std::string("mock_engine") + IE_BUILD_POSTFIX); + std::string("mock_engine") + OV_BUILD_POSTFIX); } void loadDll(const string& libraryName) { diff --git a/src/inference/tests/unit/CMakeLists.txt b/src/inference/tests/unit/CMakeLists.txt index ef8e346aaf486b..8030fe0ddb7a15 100644 --- a/src/inference/tests/unit/CMakeLists.txt +++ b/src/inference/tests/unit/CMakeLists.txt @@ -19,3 +19,5 @@ ov_add_test_target( LABELS OV UNIT RUNTIME ) + +ov_set_threading_interface_for(${TARGET_NAME}) diff --git a/src/inference/tests/unit/cpu_map_parser/cache_parser_linux.cpp b/src/inference/tests/unit/cpu_map_parser/cache_parser_linux.cpp index b96a86d62f72cf..7dab5dc907ff0b 100644 --- a/src/inference/tests/unit/cpu_map_parser/cache_parser_linux.cpp +++ b/src/inference/tests/unit/cpu_map_parser/cache_parser_linux.cpp @@ -300,6 +300,92 @@ LinuxCpuMapTestCase cache_2sockets_104cores_hyperthreading = { }, // param[in]: The CPU cache information table of this simulated platform {{"0-51,104-155"}, {"52-103,156-207"}}, // param[in]: The numa node information table of this simulated platform }; +LinuxCpuMapTestCase cache_1sockets_96cores = { + 96, + 1, + 1, + 96, + {{96, 0, 96, 0, 0, 0}}, + { + {0, 0, 0, 0, EFFICIENT_CORE_PROC, 0, -1}, {1, 0, 0, 1, EFFICIENT_CORE_PROC, 0, -1}, + {2, 0, 0, 2, EFFICIENT_CORE_PROC, 0, -1}, {3, 0, 0, 3, EFFICIENT_CORE_PROC, 0, -1}, + {4, 0, 0, 4, EFFICIENT_CORE_PROC, 1, -1}, {5, 0, 0, 5, EFFICIENT_CORE_PROC, 1, -1}, + {6, 0, 0, 6, EFFICIENT_CORE_PROC, 1, -1}, {7, 0, 0, 7, EFFICIENT_CORE_PROC, 1, -1}, + {8, 0, 0, 8, EFFICIENT_CORE_PROC, 2, -1}, {9, 0, 0, 9, EFFICIENT_CORE_PROC, 2, -1}, + {10, 0, 0, 10, EFFICIENT_CORE_PROC, 2, -1}, {11, 0, 0, 11, EFFICIENT_CORE_PROC, 2, -1}, + {12, 0, 0, 12, EFFICIENT_CORE_PROC, 3, -1}, {13, 0, 0, 13, EFFICIENT_CORE_PROC, 3, -1}, + {14, 0, 0, 14, EFFICIENT_CORE_PROC, 3, -1}, {15, 0, 0, 15, EFFICIENT_CORE_PROC, 3, -1}, + {16, 0, 0, 16, EFFICIENT_CORE_PROC, 4, -1}, {17, 0, 0, 17, EFFICIENT_CORE_PROC, 4, -1}, + {18, 0, 0, 18, EFFICIENT_CORE_PROC, 4, -1}, {19, 0, 0, 19, EFFICIENT_CORE_PROC, 4, -1}, + {20, 0, 0, 20, EFFICIENT_CORE_PROC, 5, -1}, {21, 0, 0, 21, EFFICIENT_CORE_PROC, 5, -1}, + {22, 0, 0, 22, EFFICIENT_CORE_PROC, 5, -1}, {23, 0, 0, 23, EFFICIENT_CORE_PROC, 5, -1}, + {24, 0, 0, 24, EFFICIENT_CORE_PROC, 6, -1}, {25, 0, 0, 25, EFFICIENT_CORE_PROC, 6, -1}, + {26, 0, 0, 26, EFFICIENT_CORE_PROC, 6, -1}, {27, 0, 0, 27, EFFICIENT_CORE_PROC, 6, -1}, + {28, 0, 0, 28, EFFICIENT_CORE_PROC, 7, -1}, {29, 0, 0, 29, EFFICIENT_CORE_PROC, 7, -1}, + {30, 0, 0, 30, EFFICIENT_CORE_PROC, 7, -1}, {31, 0, 0, 31, EFFICIENT_CORE_PROC, 7, -1}, + {32, 0, 0, 32, EFFICIENT_CORE_PROC, 8, -1}, {33, 0, 0, 33, EFFICIENT_CORE_PROC, 8, -1}, + {34, 0, 0, 34, EFFICIENT_CORE_PROC, 8, -1}, {35, 0, 0, 35, EFFICIENT_CORE_PROC, 8, -1}, + {36, 0, 0, 36, EFFICIENT_CORE_PROC, 9, -1}, {37, 0, 0, 37, EFFICIENT_CORE_PROC, 9, -1}, + {38, 0, 0, 38, EFFICIENT_CORE_PROC, 9, -1}, {39, 0, 0, 39, EFFICIENT_CORE_PROC, 9, -1}, + {40, 0, 0, 40, EFFICIENT_CORE_PROC, 10, -1}, {41, 0, 0, 41, EFFICIENT_CORE_PROC, 10, -1}, + {42, 0, 0, 42, EFFICIENT_CORE_PROC, 10, -1}, {43, 0, 0, 43, EFFICIENT_CORE_PROC, 10, -1}, + {44, 0, 0, 44, EFFICIENT_CORE_PROC, 11, -1}, {45, 0, 0, 45, EFFICIENT_CORE_PROC, 11, -1}, + {46, 0, 0, 46, EFFICIENT_CORE_PROC, 11, -1}, {47, 0, 0, 47, EFFICIENT_CORE_PROC, 11, -1}, + {48, 0, 0, 48, EFFICIENT_CORE_PROC, 12, -1}, {49, 0, 0, 49, EFFICIENT_CORE_PROC, 12, -1}, + {50, 0, 0, 50, EFFICIENT_CORE_PROC, 12, -1}, {51, 0, 0, 51, EFFICIENT_CORE_PROC, 12, -1}, + {52, 0, 0, 52, EFFICIENT_CORE_PROC, 13, -1}, {53, 0, 0, 53, EFFICIENT_CORE_PROC, 13, -1}, + {54, 0, 0, 54, EFFICIENT_CORE_PROC, 13, -1}, {55, 0, 0, 55, EFFICIENT_CORE_PROC, 13, -1}, + {56, 0, 0, 56, EFFICIENT_CORE_PROC, 14, -1}, {57, 0, 0, 57, EFFICIENT_CORE_PROC, 14, -1}, + {58, 0, 0, 58, EFFICIENT_CORE_PROC, 14, -1}, {59, 0, 0, 59, EFFICIENT_CORE_PROC, 14, -1}, + {60, 0, 0, 60, EFFICIENT_CORE_PROC, 15, -1}, {61, 0, 0, 61, EFFICIENT_CORE_PROC, 15, -1}, + {62, 0, 0, 62, EFFICIENT_CORE_PROC, 15, -1}, {63, 0, 0, 63, EFFICIENT_CORE_PROC, 15, -1}, + {64, 0, 0, 64, EFFICIENT_CORE_PROC, 16, -1}, {65, 0, 0, 65, EFFICIENT_CORE_PROC, 16, -1}, + {66, 0, 0, 66, EFFICIENT_CORE_PROC, 16, -1}, {67, 0, 0, 67, EFFICIENT_CORE_PROC, 16, -1}, + {68, 0, 0, 68, EFFICIENT_CORE_PROC, 17, -1}, {69, 0, 0, 69, EFFICIENT_CORE_PROC, 17, -1}, + {70, 0, 0, 70, EFFICIENT_CORE_PROC, 17, -1}, {71, 0, 0, 71, EFFICIENT_CORE_PROC, 17, -1}, + {72, 0, 0, 72, EFFICIENT_CORE_PROC, 18, -1}, {73, 0, 0, 73, EFFICIENT_CORE_PROC, 18, -1}, + {74, 0, 0, 74, EFFICIENT_CORE_PROC, 18, -1}, {75, 0, 0, 75, EFFICIENT_CORE_PROC, 18, -1}, + {76, 0, 0, 76, EFFICIENT_CORE_PROC, 19, -1}, {77, 0, 0, 77, EFFICIENT_CORE_PROC, 19, -1}, + {78, 0, 0, 78, EFFICIENT_CORE_PROC, 19, -1}, {79, 0, 0, 79, EFFICIENT_CORE_PROC, 19, -1}, + {80, 0, 0, 80, EFFICIENT_CORE_PROC, 20, -1}, {81, 0, 0, 81, EFFICIENT_CORE_PROC, 20, -1}, + {82, 0, 0, 82, EFFICIENT_CORE_PROC, 20, -1}, {83, 0, 0, 83, EFFICIENT_CORE_PROC, 20, -1}, + {84, 0, 0, 84, EFFICIENT_CORE_PROC, 21, -1}, {85, 0, 0, 85, EFFICIENT_CORE_PROC, 21, -1}, + {86, 0, 0, 86, EFFICIENT_CORE_PROC, 21, -1}, {87, 0, 0, 87, EFFICIENT_CORE_PROC, 21, -1}, + {88, 0, 0, 88, EFFICIENT_CORE_PROC, 22, -1}, {89, 0, 0, 89, EFFICIENT_CORE_PROC, 22, -1}, + {90, 0, 0, 90, EFFICIENT_CORE_PROC, 22, -1}, {91, 0, 0, 91, EFFICIENT_CORE_PROC, 22, -1}, + {92, 0, 0, 92, EFFICIENT_CORE_PROC, 23, -1}, {93, 0, 0, 93, EFFICIENT_CORE_PROC, 23, -1}, + {94, 0, 0, 94, EFFICIENT_CORE_PROC, 23, -1}, {95, 0, 0, 95, EFFICIENT_CORE_PROC, 23, -1}, + }, + { + {"0", "0-3", "0-95"}, {"1", "0-3", "0-95"}, {"2", "0-3", "0-95"}, {"3", "0-3", "0-95"}, + {"4", "4-7", "0-95"}, {"5", "4-7", "0-95"}, {"6", "4-7", "0-95"}, {"7", "4-7", "0-95"}, + {"8", "8-11", "0-95"}, {"9", "8-11", "0-95"}, {"10", "8-11", "0-95"}, {"11", "8-11", "0-95"}, + {"12", "12-15", "0-95"}, {"13", "12-15", "0-95"}, {"14", "12-15", "0-95"}, {"15", "12-15", "0-95"}, + {"16", "16-19", "0-95"}, {"17", "16-19", "0-95"}, {"18", "16-19", "0-95"}, {"19", "16-19", "0-95"}, + {"20", "20-23", "0-95"}, {"21", "20-23", "0-95"}, {"22", "20-23", "0-95"}, {"23", "20-23", "0-95"}, + {"24", "24-27", "0-95"}, {"25", "24-27", "0-95"}, {"26", "24-27", "0-95"}, {"27", "24-27", "0-95"}, + {"28", "28-31", "0-95"}, {"29", "28-31", "0-95"}, {"30", "28-31", "0-95"}, {"31", "28-31", "0-95"}, + {"32", "32-35", "0-95"}, {"33", "32-35", "0-95"}, {"34", "32-35", "0-95"}, {"35", "32-35", "0-95"}, + {"36", "36-39", "0-95"}, {"37", "36-39", "0-95"}, {"38", "36-39", "0-95"}, {"39", "36-39", "0-95"}, + {"40", "40-43", "0-95"}, {"41", "40-43", "0-95"}, {"42", "40-43", "0-95"}, {"43", "40-43", "0-95"}, + {"44", "44-47", "0-95"}, {"45", "44-47", "0-95"}, {"46", "44-47", "0-95"}, {"47", "44-47", "0-95"}, + {"48", "48-51", "0-95"}, {"49", "48-51", "0-95"}, {"50", "48-51", "0-95"}, {"51", "48-51", "0-95"}, + {"52", "52-55", "0-95"}, {"53", "52-55", "0-95"}, {"54", "52-55", "0-95"}, {"55", "52-55", "0-95"}, + {"56", "56-59", "0-95"}, {"57", "56-59", "0-95"}, {"58", "56-59", "0-95"}, {"59", "56-59", "0-95"}, + {"60", "60-63", "0-95"}, {"61", "60-63", "0-95"}, {"62", "60-63", "0-95"}, {"63", "60-63", "0-95"}, + {"64", "64-67", "0-95"}, {"65", "64-67", "0-95"}, {"66", "64-67", "0-95"}, {"67", "64-67", "0-95"}, + {"68", "68-71", "0-95"}, {"69", "68-71", "0-95"}, {"70", "68-71", "0-95"}, {"71", "68-71", "0-95"}, + {"72", "72-75", "0-95"}, {"73", "72-75", "0-95"}, {"74", "72-75", "0-95"}, {"75", "72-75", "0-95"}, + {"76", "76-79", "0-95"}, {"77", "76-79", "0-95"}, {"78", "76-79", "0-95"}, {"79", "76-79", "0-95"}, + {"80", "80-83", "0-95"}, {"81", "80-83", "0-95"}, {"82", "80-83", "0-95"}, {"83", "80-83", "0-95"}, + {"84", "84-87", "0-95"}, {"85", "84-87", "0-95"}, {"86", "84-87", "0-95"}, {"87", "84-87", "0-95"}, + {"88", "88-91", "0-95"}, {"89", "88-91", "0-95"}, {"90", "88-91", "0-95"}, {"91", "88-91", "0-95"}, + {"92", "92-95", "0-95"}, {"93", "92-95", "0-95"}, {"94", "92-95", "0-95"}, {"95", "92-95", "0-95"}, + }, + { + {"0-95"}, + }, +}; LinuxCpuMapTestCase cache_2sockets_48cores_hyperthreading = { 96, 2, @@ -1092,6 +1178,7 @@ TEST_P(LinuxCpuMapCacheParserTests, LinuxCache) {} INSTANTIATE_TEST_SUITE_P(CPUMap, LinuxCpuMapCacheParserTests, testing::Values(cache_2sockets_104cores_hyperthreading, + cache_1sockets_96cores, cache_2sockets_48cores_hyperthreading, cache_2sockets_48cores_hyperthreading_1, cache_2sockets_24cores_hyperthreading, diff --git a/src/inference/tests/unit/cpu_reserve_test.cpp b/src/inference/tests/unit/cpu_reserve_test.cpp index 7a5427d777bea7..e5fe6b40abdf7b 100644 --- a/src/inference/tests/unit/cpu_reserve_test.cpp +++ b/src/inference/tests/unit/cpu_reserve_test.cpp @@ -44,6 +44,12 @@ class LinuxCpuReserveTests : public ov::test::TestsCommon, test_data._cpu_status); ASSERT_EQ(test_data._stream_processors, test_processors); + for (size_t i = 0; i < test_processors.size(); i++) { + for (size_t j = 0; j < test_processors[i].size(); j++) { + ASSERT_EQ(test_data._cpu_mapping_table[test_processors[i][j]][CPU_MAP_USED_FLAG], + test_data._cpu_status); + } + } } }; @@ -869,8 +875,6 @@ LinuxCpuReserveTestCase _1socket_16cores_hyper_4streams_ecoreonly = { }, NOT_USED, }; -// streams_info_table={1, MAIN_CORE_PROC, 36}, but the number of physical cores is 18, -// in this case, threads are assigned on physical and logical cores. LinuxCpuReserveTestCase _1socket_18cores_hyper_1streams = { 36, 1, @@ -933,6 +937,38 @@ LinuxCpuReserveTestCase _1socket_18cores_hyper_2streams = { }, NOT_USED, }; +// other plugin reserved 2 threads +LinuxCpuReserveTestCase _1socket_18cores_hyper_plugin_reserve_2threads = { + 36, + 1, + {{36, 18, 0, 18, 0, 0}}, + { + {0, 0, 0, 0, HYPER_THREADING_PROC, 0, -1}, {1, 0, 0, 0, HYPER_THREADING_PROC, 0, -1}, + {2, 0, 0, 1, HYPER_THREADING_PROC, 1, -1}, {3, 0, 0, 1, HYPER_THREADING_PROC, 1, -1}, + {4, 0, 0, 2, HYPER_THREADING_PROC, 2, -1}, {5, 0, 0, 2, HYPER_THREADING_PROC, 2, -1}, + {6, 0, 0, 3, HYPER_THREADING_PROC, 3, -1}, {7, 0, 0, 3, HYPER_THREADING_PROC, 3, -1}, + {8, 0, 0, 4, HYPER_THREADING_PROC, 4, -1}, {9, 0, 0, 4, HYPER_THREADING_PROC, 4, -1}, + {10, 0, 0, 5, HYPER_THREADING_PROC, 5, -1}, {11, 0, 0, 5, HYPER_THREADING_PROC, 5, -1}, + {12, 0, 0, 6, HYPER_THREADING_PROC, 6, -1}, {13, 0, 0, 6, HYPER_THREADING_PROC, 6, -1}, + {14, 0, 0, 7, HYPER_THREADING_PROC, 7, -1}, {15, 0, 0, 7, HYPER_THREADING_PROC, 7, -1}, + {16, 0, 0, 8, HYPER_THREADING_PROC, 8, -1}, {17, 0, 0, 9, HYPER_THREADING_PROC, 8, -1}, + {18, 0, 0, 0, MAIN_CORE_PROC, 0, CPU_USED}, {19, 0, 0, 1, MAIN_CORE_PROC, 1, CPU_USED}, + {20, 0, 0, 2, MAIN_CORE_PROC, 2, -1}, {21, 0, 0, 3, MAIN_CORE_PROC, 3, -1}, + {22, 0, 0, 4, MAIN_CORE_PROC, 4, -1}, {23, 0, 0, 5, MAIN_CORE_PROC, 5, -1}, + {24, 0, 0, 6, MAIN_CORE_PROC, 6, -1}, {25, 0, 0, 7, MAIN_CORE_PROC, 7, -1}, + {26, 0, 0, 8, MAIN_CORE_PROC, 8, -1}, {27, 0, 0, 9, MAIN_CORE_PROC, 9, -1}, + {28, 0, 0, 10, MAIN_CORE_PROC, 10, -1}, {29, 0, 0, 11, MAIN_CORE_PROC, 11, -1}, + {30, 0, 0, 12, MAIN_CORE_PROC, 12, -1}, {31, 0, 0, 13, MAIN_CORE_PROC, 13, -1}, + {32, 0, 0, 14, MAIN_CORE_PROC, 14, -1}, {33, 0, 0, 15, MAIN_CORE_PROC, 15, -1}, + {34, 0, 0, 16, MAIN_CORE_PROC, 16, -1}, {35, 0, 0, 17, MAIN_CORE_PROC, 17, -1}, + }, + {{16, MAIN_CORE_PROC, 1, 0, 0}, {16, HYPER_THREADING_PROC, 1, 0, 0}}, + { + {20}, {21}, {22}, {23}, {24}, {25}, {26}, {27}, {28}, {29}, {30}, {31}, {32}, {33}, {34}, {35}, + {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, + }, + NOT_USED, +}; LinuxCpuReserveTestCase _1socket_32cores_hyper_1streams = { 32, 1, @@ -986,6 +1022,7 @@ INSTANTIATE_TEST_SUITE_P(CPUReserve, _1socket_16cores_hyper_4streams_ecoreonly, _1socket_18cores_hyper_1streams, _1socket_18cores_hyper_2streams, + _1socket_18cores_hyper_plugin_reserve_2threads, _1socket_32cores_hyper_1streams)); #endif } // namespace diff --git a/src/inference/tests/unit/ie_extension_test.cpp b/src/inference/tests/unit/ie_extension_test.cpp index 3a68c157de0b7b..336bf5da71c9b7 100644 --- a/src/inference/tests/unit/ie_extension_test.cpp +++ b/src/inference/tests/unit/ie_extension_test.cpp @@ -23,7 +23,7 @@ OPENVINO_SUPPRESS_DEPRECATED_START static std::string getExtensionPath() { return FileUtils::makePluginLibraryName(ov::test::utils::getExecutableDirectory(), - std::string("template_extension") + IE_BUILD_POSTFIX); + std::string("template_extension") + OV_BUILD_POSTFIX); } TEST(ExtensionTests, testGetOpSets) { diff --git a/src/plugins/auto/tests/CMakeLists.txt b/src/plugins/auto/tests/CMakeLists.txt index bce0f68667ca23..59ce3e84bc86cf 100644 --- a/src/plugins/auto/tests/CMakeLists.txt +++ b/src/plugins/auto/tests/CMakeLists.txt @@ -1,8 +1,7 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 # -# RPATH is always enabled for unit tests -set(CMAKE_SKIP_RPATH OFF) + # 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}) diff --git a/src/plugins/auto/tests/functional/CMakeLists.txt b/src/plugins/auto/tests/functional/CMakeLists.txt index cd239db8806120..b15afe68b96660 100644 --- a/src/plugins/auto/tests/functional/CMakeLists.txt +++ b/src/plugins/auto/tests/functional/CMakeLists.txt @@ -31,4 +31,4 @@ ov_add_test_target( ) target_compile_definitions(${TARGET_NAME} PRIVATE ${COMPILE_DEFINITIONS}) -set_ie_threading_interface_for(${TARGET_NAME}) \ No newline at end of file +ov_set_threading_interface_for(${TARGET_NAME}) \ No newline at end of file diff --git a/src/plugins/auto/tests/functional/behavior/auto_func_test.cpp b/src/plugins/auto/tests/functional/behavior/auto_func_test.cpp index 1ba14b66d57207..123a41e3524744 100644 --- a/src/plugins/auto/tests/functional/behavior/auto_func_test.cpp +++ b/src/plugins/auto/tests/functional/behavior/auto_func_test.cpp @@ -30,7 +30,7 @@ namespace { std::string get_mock_engine_path() { std::string mockEngineName("mock_engine"); return ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - mockEngineName + IE_BUILD_POSTFIX); + mockEngineName + OV_BUILD_POSTFIX); } template @@ -623,7 +623,7 @@ void ov::auto_plugin::tests::AutoFuncTests::reg_plugin(ov::Core& core, injectProxyEngine(plugin.get()); core.register_plugin(ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("mock_engine") + IE_BUILD_POSTFIX), + std::string("mock_engine") + OV_BUILD_POSTFIX), device_name, properties); m_mock_plugins.emplace_back(plugin); diff --git a/src/plugins/auto_batch/CMakeLists.txt b/src/plugins/auto_batch/CMakeLists.txt index ffc873e5c6c833..9ff585740abc98 100644 --- a/src/plugins/auto_batch/CMakeLists.txt +++ b/src/plugins/auto_batch/CMakeLists.txt @@ -18,17 +18,13 @@ ov_add_plugin(NAME ${TARGET_NAME} SOURCES ${SOURCES} ${HEADERS} VERSION_DEFINES_FOR src/plugin.cpp ADD_CLANG_FORMAT) -target_link_libraries(${TARGET_NAME} PRIVATE Threads::Threads) +ov_set_threading_interface_for(${TARGET_NAME}) # must be called after all target_link_libraries ov_add_api_validator_post_build_step(TARGET ${TARGET_NAME}) set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO}) -if(ENABLE_FUNCTIONAL_TESTS) - add_subdirectory(tests/functional) -endif() - if(ENABLE_TESTS) - add_subdirectory(tests/unit) + add_subdirectory(tests) endif() diff --git a/src/plugins/auto_batch/tests/CMakeLists.txt b/src/plugins/auto_batch/tests/CMakeLists.txt new file mode 100644 index 00000000000000..9d4bb95917dcc9 --- /dev/null +++ b/src/plugins/auto_batch/tests/CMakeLists.txt @@ -0,0 +1,6 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# + +add_subdirectory(unit) +add_subdirectory(functional) diff --git a/src/plugins/hetero/CMakeLists.txt b/src/plugins/hetero/CMakeLists.txt index fdb972a7b427b4..8d20a7d6c5b03a 100644 --- a/src/plugins/hetero/CMakeLists.txt +++ b/src/plugins/hetero/CMakeLists.txt @@ -29,38 +29,31 @@ ov_add_api_validator_post_build_step(TARGET ${TARGET_NAME}) set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO}) -if(BUILD_SHARED_LIBS) - set(OBJ_NAME ${TARGET_NAME}_obj) - - add_library(${OBJ_NAME} OBJECT ${SOURCES} ${HEADERS}) - ov_link_system_libraries(${OBJ_NAME} PUBLIC openvino::pugixml) - - ov_add_version_defines(src/version.cpp ${OBJ_NAME}) +if(ENABLE_TESTS) + if(BUILD_SHARED_LIBS) + set(OBJ_NAME ${TARGET_NAME}_obj) - target_include_directories(${OBJ_NAME} - PRIVATE - $ - $ - PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - $) + add_library(${OBJ_NAME} OBJECT ${SOURCES} ${HEADERS}) + ov_link_system_libraries(${OBJ_NAME} PUBLIC openvino::pugixml) - ov_set_threading_interface_for(${OBJ_NAME}) + ov_add_version_defines(src/version.cpp ${OBJ_NAME}) - target_compile_definitions(${OBJ_NAME} - PRIVATE - USE_STATIC_IE IMPLEMENT_INFERENCE_ENGINE_PLUGIN IMPLEMENT_INFERENCE_EXTENSION_API - $ - $) + target_include_directories(${OBJ_NAME} + PRIVATE + $ + $ + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + $) - set_target_properties(${TARGET_NAME}_obj PROPERTIES EXCLUDE_FROM_ALL ON) - set_target_properties(${TARGET_NAME}_obj PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO}) -endif() + ov_set_threading_interface_for(${OBJ_NAME}) -if(ENABLE_TESTS) - add_subdirectory(tests/unit) -endif() + target_compile_definitions(${OBJ_NAME} + PRIVATE + USE_STATIC_IE IMPLEMENT_INFERENCE_ENGINE_PLUGIN IMPLEMENT_INFERENCE_EXTENSION_API + $ + $) + endif() -if(ENABLE_FUNCTIONAL_TESTS) - add_subdirectory(tests/functional) + add_subdirectory(tests) endif() diff --git a/src/plugins/hetero/src/sync_infer_request.cpp b/src/plugins/hetero/src/sync_infer_request.cpp index 21fbd0b4f2e2a3..0bb4bc4b7e9a4f 100644 --- a/src/plugins/hetero/src/sync_infer_request.cpp +++ b/src/plugins/hetero/src/sync_infer_request.cpp @@ -49,20 +49,15 @@ ov::hetero::InferRequest::InferRequest(const std::shared_ptr ov::hetero::InferRequest::get_request(const ov::Output& port) const { - auto check_nodes = [](const ov::Node* node1, const ov::Node* node2) { - return node1 == node2 || - (node1->get_friendly_name() == node2->get_friendly_name() && - node1->get_type_info() == node2->get_type_info() && - node1->outputs().size() == node2->outputs().size() && node1->inputs().size() == node2->inputs().size()); - }; - - for (const auto& kvp : m_port_to_subrequest_idx) { - if (kvp.first.get_index() == port.get_index() && kvp.first.get_names() == port.get_names() && - check_nodes(kvp.first.get_node(), port.get_node())) { - return m_subrequests[kvp.second]; - } + auto found_port = find_port(port); + ov::Output internal_port; + OPENVINO_ASSERT(found_port.found(), "Cannot find infer request for port ", port); + if (found_port.is_input()) { + internal_port = get_inputs().at(found_port.idx); + } else { + internal_port = get_outputs().at(found_port.idx); } - OPENVINO_THROW("Cannot find infer request for port ", port); + return m_subrequests[m_port_to_subrequest_idx.at(internal_port)]; } ov::SoPtr ov::hetero::InferRequest::get_tensor(const ov::Output& port) const { diff --git a/src/plugins/hetero/tests/CMakeLists.txt b/src/plugins/hetero/tests/CMakeLists.txt new file mode 100644 index 00000000000000..9d4bb95917dcc9 --- /dev/null +++ b/src/plugins/hetero/tests/CMakeLists.txt @@ -0,0 +1,6 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# + +add_subdirectory(unit) +add_subdirectory(functional) diff --git a/src/plugins/hetero/tests/functional/CMakeLists.txt b/src/plugins/hetero/tests/functional/CMakeLists.txt index a1726e31c5a413..550bfa0f075795 100644 --- a/src/plugins/hetero/tests/functional/CMakeLists.txt +++ b/src/plugins/hetero/tests/functional/CMakeLists.txt @@ -8,7 +8,6 @@ ov_add_test_target( NAME ${TARGET_NAME} ROOT ${CMAKE_CURRENT_SOURCE_DIR} DEPENDENCIES - openvino::runtime mock_engine openvino_hetero_plugin LINK_LIBRARIES diff --git a/src/plugins/hetero/tests/functional/hetero_tests.cpp b/src/plugins/hetero/tests/functional/hetero_tests.cpp index 4228a5c14ce8e6..55440556f0552b 100644 --- a/src/plugins/hetero/tests/functional/hetero_tests.cpp +++ b/src/plugins/hetero/tests/functional/hetero_tests.cpp @@ -32,7 +32,7 @@ namespace { std::string get_mock_engine_path() { std::string mock_engine_name("mock_engine"); return ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - mock_engine_name + IE_BUILD_POSTFIX); + mock_engine_name + OV_BUILD_POSTFIX); } template diff --git a/src/plugins/hetero/tests/unit/CMakeLists.txt b/src/plugins/hetero/tests/unit/CMakeLists.txt index 939229e4ee9ffb..ad2d38e156b5a9 100644 --- a/src/plugins/hetero/tests/unit/CMakeLists.txt +++ b/src/plugins/hetero/tests/unit/CMakeLists.txt @@ -24,7 +24,6 @@ ov_add_test_target( ov_models DEPENDENCIES mock_engine - ov_models ADD_CLANG_FORMAT LABELS OV UNIT HETERO diff --git a/src/plugins/intel_cpu/CMakeLists.txt b/src/plugins/intel_cpu/CMakeLists.txt index 4212bacb8cc055..8276d5a3188970 100644 --- a/src/plugins/intel_cpu/CMakeLists.txt +++ b/src/plugins/intel_cpu/CMakeLists.txt @@ -27,7 +27,7 @@ elseif(AARCH64) if(APPLE) # Apple M1 / M2 is assumed set(OV_CPU_ARM_TARGET_ARCH_DEFAULT arm64-v8.2-a) - add_definitions(-DOV_CPU_ARM_ENABLE_FP16) + add_compile_definitions(OV_CPU_ARM_ENABLE_FP16) else() set(OV_CPU_ARM_TARGET_ARCH_DEFAULT arm64-v8a) endif() @@ -44,7 +44,7 @@ if(X86 OR X86_64 OR AARCH64) else() set(ENABLE_MLAS_FOR_CPU_DEFAULT OFF) endif() -ie_option(ENABLE_MLAS_FOR_CPU "Enable MLAS for OpenVINO CPU Plugin" ${ENABLE_MLAS_FOR_CPU_DEFAULT}) +ov_option(ENABLE_MLAS_FOR_CPU "Enable MLAS for OpenVINO CPU Plugin" ${ENABLE_MLAS_FOR_CPU_DEFAULT}) add_subdirectory(thirdparty) diff --git a/src/plugins/intel_cpu/src/config.cpp b/src/plugins/intel_cpu/src/config.cpp index 277bdb412563e7..90e65a15495719 100644 --- a/src/plugins/intel_cpu/src/config.cpp +++ b/src/plugins/intel_cpu/src/config.cpp @@ -255,10 +255,16 @@ void Config::readProperties(const std::map &prop, cons // when both execution_mode and inference_precision are specified if (!inferencePrecisionSetExplicitly) { if (executionMode == ov::hint::ExecutionMode::PERFORMANCE) { + inferencePrecision = ov::element::f32; +#if defined(OV_CPU_ARM_ENABLE_FP16) + //fp16 precision is used as default precision on ARM for non-convolution networks + //fp16 ACL convolution is slower than fp32 + if (modelType != ModelType::CNN) + inferencePrecision = ov::element::f16; +#else if (mayiuse(avx512_core_bf16)) inferencePrecision = ov::element::bf16; - else - inferencePrecision = ov::element::f32; +#endif } else { inferencePrecision = ov::element::f32; } diff --git a/src/plugins/intel_cpu/src/cpu_types.cpp b/src/plugins/intel_cpu/src/cpu_types.cpp index 03fbe1a9923b7a..6f5a84701b184d 100644 --- a/src/plugins/intel_cpu/src/cpu_types.cpp +++ b/src/plugins/intel_cpu/src/cpu_types.cpp @@ -123,6 +123,7 @@ static const TypeToNameMap& get_type_to_name_tbl() { { "ScatterElementsUpdate", Type::ScatterElementsUpdate}, { "ScatterNDUpdate", Type::ScatterNDUpdate}, { "Interpolate", Type::Interpolate}, + { "RandomUniform", Type::RandomUniform}, { "ReduceL1", Type::Reduce}, { "ReduceL2", Type::Reduce}, { "ReduceLogicalAnd", Type::Reduce}, @@ -317,6 +318,7 @@ std::string NameFromType(const Type type) { CASE(PriorBox); CASE(PriorBoxClustered) CASE(MHA); + CASE(RandomUniform); CASE(Unique); CASE(Ngram); CASE(Unknown); diff --git a/src/plugins/intel_cpu/src/cpu_types.h b/src/plugins/intel_cpu/src/cpu_types.h index 403ed62d482f8b..9afbe2d7485ddd 100644 --- a/src/plugins/intel_cpu/src/cpu_types.h +++ b/src/plugins/intel_cpu/src/cpu_types.h @@ -110,6 +110,7 @@ enum class Type { PriorBoxClustered, Interaction, MHA, + RandomUniform, Unique, Ngram }; diff --git a/src/plugins/intel_cpu/src/dnnl_postops_composer.cpp b/src/plugins/intel_cpu/src/dnnl_postops_composer.cpp index c5e368ebd5efc0..1f85dd1f3ffbc6 100644 --- a/src/plugins/intel_cpu/src/dnnl_postops_composer.cpp +++ b/src/plugins/intel_cpu/src/dnnl_postops_composer.cpp @@ -251,41 +251,48 @@ void DnnlPostOpsComposer::appendClip(const std::vector& low, const std::v } } -MemoryPtr DnnlPostOpsComposer::prepackDecompressionParams(const std::vector& params, size_t icBlock) { +MemoryPtr DnnlPostOpsComposer::prepackDecompressionParams(const MemoryCPtr& params_ptr, size_t icBlock) { // Prepacking params from [oc] to [oc, icBlock] layout, where for each icBlock corresponding parameter is duplicated - DnnlBlockedMemoryDesc memoryDesc(InferenceEngine::Precision::FP32, Shape({icBlock * params.size()})); + const auto shape = params_ptr->getShape().getStaticDims(); + const size_t elements_count = std::accumulate(shape.begin(), shape.end(), 1, std::multiplies()); + DnnlBlockedMemoryDesc memoryDesc(InferenceEngine::Precision::FP32, Shape({icBlock * elements_count})); auto mem = std::make_shared(engine, memoryDesc); size_t dstIdx = 0; + auto decomp_scales_data = static_cast(params_ptr->getData()); auto decomp_scales_buf = static_cast(mem->getData()); - for (size_t oc = 0; oc < params.size(); oc++) { + for (size_t oc = 0; oc < elements_count; oc++) { for (size_t intIdx = 0; intIdx < icBlock; intIdx++) { - decomp_scales_buf[dstIdx] = params[oc]; + decomp_scales_buf[dstIdx] = decomp_scales_data[oc]; dstIdx++; } } return mem; } -void DnnlPostOpsComposer::appendDecompressionScales(const std::vector& scales, size_t icBlock) { - if (scales.empty()) +void DnnlPostOpsComposer::appendDecompressionScales(const MemoryCPtr& scales_ptr, size_t icBlock) { + if (scales_ptr == nullptr) return; - int mask = scales.size() > 1 ? weightScaleMaskPerChannel : 0; + const auto shape = scales_ptr->getShape().getStaticDims(); + const auto elements_count = std::accumulate(shape.begin(), shape.end(), 1, std::multiplies()); + int mask = elements_count > 1 ? weightScaleMaskPerChannel : 0; DEBUG_LOG("Set weights scales mask ", "DNNL_ARG: ", DNNL_ARG_WEIGHTS, " mask: ", mask); attr.set_scales_mask(DNNL_ARG_WEIGHTS, mask); - args[DNNL_ARG_ATTR_SCALES | DNNL_ARG_WEIGHTS] = prepackDecompressionParams(scales, icBlock); + args[DNNL_ARG_ATTR_SCALES | DNNL_ARG_WEIGHTS] = prepackDecompressionParams(scales_ptr, icBlock); } -void DnnlPostOpsComposer::appendDecompressionZeroPoints(const std::vector& zero_points, size_t icBlock) { - if (zero_points.empty()) +void DnnlPostOpsComposer::appendDecompressionZeroPoints(const MemoryCPtr& zero_points_ptr, size_t icBlock) { + if (zero_points_ptr == nullptr) return; - int mask = zero_points.size() > 1 ? weightScaleMaskPerChannel : 0; + const auto shape = zero_points_ptr->getShape().getStaticDims(); + const auto elements_count = std::accumulate(shape.begin(), shape.end(), 1, std::multiplies()); + int mask = elements_count > 1 ? weightScaleMaskPerChannel : 0; DEBUG_LOG("Set weights zero points mask ", "DNNL_ARG: ", DNNL_ARG_WEIGHTS, " mask: ", mask); attr.set_zero_points_mask(DNNL_ARG_WEIGHTS, mask); - args[DNNL_ARG_ATTR_ZERO_POINTS | DNNL_ARG_WEIGHTS] = prepackDecompressionParams(zero_points, icBlock); + args[DNNL_ARG_ATTR_ZERO_POINTS | DNNL_ARG_WEIGHTS] = prepackDecompressionParams(zero_points_ptr, icBlock); } } // namespace intel_cpu diff --git a/src/plugins/intel_cpu/src/dnnl_postops_composer.h b/src/plugins/intel_cpu/src/dnnl_postops_composer.h index 365ab0a6f32239..fd52863ed7a9bd 100644 --- a/src/plugins/intel_cpu/src/dnnl_postops_composer.h +++ b/src/plugins/intel_cpu/src/dnnl_postops_composer.h @@ -42,8 +42,8 @@ class DnnlPostOpsComposer { bool appendLinear(const std::vector& scale, const std::vector& shift, bool isLastPostOp, bool allowBinary = true); void appendClip(const std::vector& low, const std::vector& high); - void appendDecompressionScales(const std::vector& scales, size_t icBlock); - void appendDecompressionZeroPoints(const std::vector& zero_points, size_t icBlock); + void appendDecompressionScales(const MemoryCPtr& scales_ptr, size_t icBlock); + void appendDecompressionZeroPoints(const MemoryCPtr& zero_points_ptr, size_t icBlock); const VectorDims& getOutputDims() { return outputDims; @@ -69,7 +69,7 @@ class DnnlPostOpsComposer { void updateWeiScales(); void updateDestScales(); - MemoryPtr prepackDecompressionParams(const std::vector& params, size_t icBlock); + MemoryPtr prepackDecompressionParams(const MemoryCPtr& params_ptr, size_t icBlock); }; } // namespace intel_cpu diff --git a/src/plugins/intel_cpu/src/emitters/x64/cpu_generator.cpp b/src/plugins/intel_cpu/src/emitters/x64/cpu_generator.cpp index b23e068244512a..da6e2e39442777 100644 --- a/src/plugins/intel_cpu/src/emitters/x64/cpu_generator.cpp +++ b/src/plugins/intel_cpu/src/emitters/x64/cpu_generator.cpp @@ -25,25 +25,25 @@ #include -using namespace std; +namespace ov { #define CREATE_SNIPPETS_EMITTER(e_type) { \ - [this](const ov::snippets::lowered::ExpressionPtr& expr) -> std::shared_ptr { \ + [this](const snippets::lowered::ExpressionPtr& expr) -> std::shared_ptr { \ return std::make_shared(h.get(), isa, expr); \ }, \ [](const std::shared_ptr& n) -> std::set> { \ return e_type::get_supported_precisions(n); \ } \ -}; +} #define CREATE_CPU_EMITTER(e_type) { \ - [this](const ov::snippets::lowered::ExpressionPtr& expr) -> std::shared_ptr { \ + [this](const snippets::lowered::ExpressionPtr& expr) -> std::shared_ptr { \ return std::make_shared(h.get(), isa, expr->get_node()); \ }, \ - [](const std::shared_ptr& n) -> std::set> { \ + [](const std::shared_ptr& n) -> std::set> { \ return e_type::get_supported_precisions(n); \ } \ -}; +} class jit_snippet : public dnnl::impl::cpu::x64::jit_generator { public: @@ -58,94 +58,95 @@ class jit_snippet : public dnnl::impl::cpu::x64::jit_generator { } }; -ov::intel_cpu::CPUTargetMachine::CPUTargetMachine(dnnl::impl::cpu::x64::cpu_isa_t host_isa) +intel_cpu::CPUTargetMachine::CPUTargetMachine(dnnl::impl::cpu::x64::cpu_isa_t host_isa) : TargetMachine(), h(new jit_snippet()), isa(host_isa) { // data movement - jitters[ov::op::v0::Parameter::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(NopEmitter); - jitters[ov::op::v0::Result::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(NopEmitter); + jitters[op::v0::Parameter::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(NopEmitter); + jitters[op::v0::Result::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(NopEmitter); jitters[snippets::op::Buffer::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(NopEmitter); jitters[snippets::op::VectorBuffer::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(NopEmitter); - // jitters[ov::op::v1::Constant::get_type_info_static()] = CREATE_CPU_EMITTER(); // Not supported + jitters[snippets::op::RankNormalization::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(NopEmitter); + // jitters[op::v1::Constant::get_type_info_static()] = CREATE_CPU_EMITTER(); // Not supported jitters[snippets::op::Load::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(LoadEmitter); jitters[snippets::op::LoadReshape::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(LoadEmitter); jitters[snippets::op::BroadcastLoad::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(BroadcastLoadEmitter); - jitters[ov::intel_cpu::LoadConvertSaturation::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(LoadConvertEmitter); - jitters[ov::intel_cpu::LoadConvertTruncation::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(LoadConvertEmitter); + jitters[intel_cpu::LoadConvertSaturation::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(LoadConvertEmitter); + jitters[intel_cpu::LoadConvertTruncation::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(LoadConvertEmitter); jitters[snippets::op::Store::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(StoreEmitter); - jitters[ov::intel_cpu::StoreConvertSaturation::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(StoreConvertEmitter); - jitters[ov::intel_cpu::StoreConvertTruncation::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(StoreConvertEmitter); + jitters[intel_cpu::StoreConvertSaturation::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(StoreConvertEmitter); + jitters[intel_cpu::StoreConvertTruncation::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(StoreConvertEmitter); jitters[snippets::op::Scalar::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(ScalarEmitter); jitters[snippets::op::BroadcastMove::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(BroadcastMoveEmitter); // jitters[snippets::op::Nop::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(NopEmitter); // Not supported - // jitters[ov::op::v1::Broadcast::get_type_info_static()] = CREATE_CPU_EMITTER(); // Not supported + // jitters[op::v1::Broadcast::get_type_info_static()] = CREATE_CPU_EMITTER(); // Not supported - jitters[snippets::op::ConvertTruncation::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_convert_truncation_emitter); - jitters[snippets::op::ConvertSaturation::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_convert_saturation_emitter); - // jitters[ov::op::v1::FakeQuantize::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported + jitters[snippets::op::ConvertTruncation::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_convert_truncation_emitter); + jitters[snippets::op::ConvertSaturation::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_convert_saturation_emitter); + // jitters[op::v1::FakeQuantize::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported // ternary - jitters[ov::op::v1::Select::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_select_emitter); - jitters[ov::intel_cpu::FusedMulAdd::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_mul_add_emitter); + jitters[op::v1::Select::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_select_emitter); + jitters[intel_cpu::FusedMulAdd::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_mul_add_emitter); // binary - jitters[ov::op::v1::Add::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_add_emitter); - jitters[ov::op::v1::Divide::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_divide_emitter); - jitters[ov::op::v1::Equal::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_equal_emitter); - jitters[ov::op::v1::FloorMod::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_floor_mod_emitter); - jitters[ov::op::v1::Greater::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_greater_emitter); - jitters[ov::op::v1::GreaterEqual::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_greater_equal_emitter); - jitters[ov::op::v1::Less::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_less_emitter); - jitters[ov::op::v1::LessEqual::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_less_equal_emitter); - jitters[ov::op::v1::LogicalAnd::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_logical_and_emitter); - jitters[ov::op::v1::LogicalOr::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_logical_or_emitter); - jitters[ov::op::v1::LogicalXor::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_logical_xor_emitter); - jitters[ov::op::v1::Maximum::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_maximum_emitter); - jitters[ov::op::v1::Minimum::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_minimum_emitter); - jitters[ov::op::v1::Mod::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_mod_emitter); - jitters[ov::op::v1::Multiply::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_multiply_emitter); - jitters[ov::op::v1::NotEqual::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_not_equal_emitter); - jitters[snippets::op::PowerStatic::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_power_static_emitter); - jitters[ov::op::v1::Power::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_power_dynamic_emitter); - jitters[ov::op::v0::PRelu::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_prelu_emitter); - jitters[ov::op::v0::SquaredDifference::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_squared_difference_emitter); - jitters[ov::op::v1::Subtract::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_subtract_emitter); - jitters[ov::op::v0::Xor::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_logical_xor_emitter); + jitters[op::v1::Add::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_add_emitter); + jitters[op::v1::Divide::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_divide_emitter); + jitters[op::v1::Equal::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_equal_emitter); + jitters[op::v1::FloorMod::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_floor_mod_emitter); + jitters[op::v1::Greater::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_greater_emitter); + jitters[op::v1::GreaterEqual::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_greater_equal_emitter); + jitters[op::v1::Less::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_less_emitter); + jitters[op::v1::LessEqual::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_less_equal_emitter); + jitters[op::v1::LogicalAnd::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_logical_and_emitter); + jitters[op::v1::LogicalOr::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_logical_or_emitter); + jitters[op::v1::LogicalXor::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_logical_xor_emitter); + jitters[op::v1::Maximum::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_maximum_emitter); + jitters[op::v1::Minimum::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_minimum_emitter); + jitters[op::v1::Mod::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_mod_emitter); + jitters[op::v1::Multiply::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_multiply_emitter); + jitters[op::v1::NotEqual::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_not_equal_emitter); + jitters[snippets::op::PowerStatic::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_power_static_emitter); + jitters[op::v1::Power::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_power_dynamic_emitter); + jitters[op::v0::PRelu::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_prelu_emitter); + jitters[op::v0::SquaredDifference::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_squared_difference_emitter); + jitters[op::v1::Subtract::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_subtract_emitter); + jitters[op::v0::Xor::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_logical_xor_emitter); // unary - jitters[ov::op::v0::Abs::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_abs_emitter); - // jitters[ov::op::v1::Acos::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported - // jitters[ov::op::v1::Asin::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported - // jitters[ov::op::v1::Atan::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported - jitters[ov::op::v0::Ceiling::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_ceiling_emitter); - jitters[ov::op::v0::Clamp::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_clamp_emitter); - // jitters[ov::op::v1::Cos::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported - // jitters[ov::op::v1::Cosh::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported - jitters[ov::op::v0::Elu::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_elu_emitter); - jitters[ov::op::v0::Erf::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_erf_emitter); - jitters[ov::op::v0::Exp::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_exp_emitter); - jitters[ov::op::v0::Floor::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_floor_emitter); - jitters[ngraph::opset5::Round::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_round_emitter); - // jitters[ov::op::v1::Log::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported - jitters[ov::op::v1::LogicalNot::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_logical_not_emitter); - jitters[ov::op::v0::Negative::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_negative_emitter); - jitters[ov::op::v0::Relu::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_relu_emitter); - // jitters[ov::op::v1::Sign::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported - jitters[ov::op::v0::Sigmoid::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_sigmoid_emitter); - // jitters[ov::op::v1::Sin::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported - // jitters[ov::op::v1::Sinh::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported - jitters[ov::op::v0::Sqrt::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_sqrt_emitter); - // jitters[ov::op::v1::Tan::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported - jitters[ov::op::v0::Tanh::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_tanh_emitter); - - jitters[ov::intel_cpu::SwishNode::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_swish_emitter); - jitters[ngraph::op::v4::HSwish::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_hswish_emitter); - // jitters[ov::op::v1::HardSigmoid::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported - // jitters[ov::op::v1::Selu::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported - jitters[ngraph::op::v0::Gelu::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_gelu_v0_emitter); - jitters[ngraph::op::v7::Gelu::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_gelu_v7_emitter); + jitters[op::v0::Abs::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_abs_emitter); + // jitters[op::v1::Acos::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported + // jitters[op::v1::Asin::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported + // jitters[op::v1::Atan::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported + jitters[op::v0::Ceiling::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_ceiling_emitter); + jitters[op::v0::Clamp::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_clamp_emitter); + // jitters[op::v1::Cos::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported + // jitters[op::v1::Cosh::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported + jitters[op::v0::Elu::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_elu_emitter); + jitters[op::v0::Erf::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_erf_emitter); + jitters[op::v0::Exp::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_exp_emitter); + jitters[op::v0::Floor::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_floor_emitter); + jitters[ngraph::opset5::Round::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_round_emitter); + // jitters[op::v1::Log::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported + jitters[op::v1::LogicalNot::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_logical_not_emitter); + jitters[op::v0::Negative::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_negative_emitter); + jitters[op::v0::Relu::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_relu_emitter); + // jitters[op::v1::Sign::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported + jitters[op::v0::Sigmoid::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_sigmoid_emitter); + // jitters[op::v1::Sin::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported + // jitters[op::v1::Sinh::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported + jitters[op::v0::Sqrt::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_sqrt_emitter); + // jitters[op::v1::Tan::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported + jitters[op::v0::Tanh::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_tanh_emitter); + + jitters[intel_cpu::SwishNode::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_swish_emitter); + jitters[ngraph::op::v4::HSwish::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_hswish_emitter); + // jitters[op::v1::HardSigmoid::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported + // jitters[op::v1::Selu::get_type_info_static()] = CREATE_CPU_EMITTER(); // not supported + jitters[ngraph::op::v0::Gelu::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_gelu_v0_emitter); + jitters[ngraph::op::v7::Gelu::get_type_info_static()] = CREATE_CPU_EMITTER(intel_cpu::jit_gelu_v7_emitter); jitters[snippets::op::Fill::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(FillEmitter); jitters[snippets::op::HorizonMax::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(HorizonEmitter); @@ -154,11 +155,11 @@ ov::intel_cpu::CPUTargetMachine::CPUTargetMachine(dnnl::impl::cpu::x64::cpu_isa_ jitters[snippets::op::Kernel::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(KernelEmitter); jitters[snippets::op::LoopBegin::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(LoopBeginEmitter); jitters[snippets::op::LoopEnd::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(LoopEndEmitter); - jitters[ov::intel_cpu::BrgemmCPU::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(BrgemmEmitter); - jitters[ov::intel_cpu::BrgemmCopyB::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(BrgemmCopyBEmitter); + jitters[intel_cpu::BrgemmCPU::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(BrgemmEmitter); + jitters[intel_cpu::BrgemmCopyB::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(BrgemmCopyBEmitter); } -size_t ov::intel_cpu::CPUTargetMachine::get_lanes() const { +size_t intel_cpu::CPUTargetMachine::get_lanes() const { switch (isa) { case dnnl::impl::cpu::x64::avx2 : return dnnl::impl::cpu::x64::cpu_isa_traits::vlen / sizeof(float); case dnnl::impl::cpu::x64::sse41 : return dnnl::impl::cpu::x64::cpu_isa_traits::vlen / sizeof(float); @@ -167,28 +168,62 @@ size_t ov::intel_cpu::CPUTargetMachine::get_lanes() const { } } -bool ov::intel_cpu::CPUTargetMachine::is_supported() const { +dnnl::impl::cpu::x64::cpu_isa_t intel_cpu::CPUTargetMachine::get_isa() const { + return isa; +} + +bool intel_cpu::CPUTargetMachine::is_supported() const { return dnnl::impl::cpu::x64::mayiuse(isa); } -ov::snippets::code ov::intel_cpu::CPUTargetMachine::get_snippet() const { +snippets::CompiledSnippetPtr intel_cpu::CPUTargetMachine::get_snippet() { if (h->create_kernel() != dnnl::impl::status::success) { IE_THROW() << "Failed to create jit_kernel in get_snippet()"; } - return h->jit_ker(); + const auto& result = std::make_shared(std::unique_ptr(h.release())); + // Note that we reset all the generated code, since it was copied into CompiledSnippetCPU + h.reset(new jit_snippet()); + return result; +} + +intel_cpu::CompiledSnippetCPU::CompiledSnippetCPU(std::unique_ptr h) : h_compiled(std::move(h)) { + OPENVINO_ASSERT(h_compiled && h_compiled->jit_ker(), "Got invalid jit generator or kernel was nopt compiled"); } -ov::intel_cpu::CPUGenerator::CPUGenerator(dnnl::impl::cpu::x64::cpu_isa_t isa_) : Generator(std::make_shared(isa_)) { +const uint8_t* intel_cpu::CompiledSnippetCPU::get_code() const { + return h_compiled->jit_ker(); } -ov::snippets::Generator::opRegType ov::intel_cpu::CPUGenerator::get_specific_op_reg_type(const std::shared_ptr& op) const { - if (std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op)) +size_t intel_cpu::CompiledSnippetCPU::get_code_size() const { + return h_compiled->getSize(); +} + +bool intel_cpu::CompiledSnippetCPU::empty() const { + return get_code_size() == 0; +} + +intel_cpu::CPUGenerator::CPUGenerator(dnnl::impl::cpu::x64::cpu_isa_t isa_) : Generator(std::make_shared(isa_)) { +} + +std::shared_ptr intel_cpu::CPUGenerator::clone() const { + const auto& cpu_target_machine = std::dynamic_pointer_cast(target); + OPENVINO_ASSERT(cpu_target_machine, "Failed to clone CPUGenerator: the instance contains incompatible TargetMachine type"); + return std::make_shared(cpu_target_machine->get_isa()); +} + +snippets::Generator::opRegType intel_cpu::CPUGenerator::get_specific_op_reg_type(const std::shared_ptr& op) const { + if (std::dynamic_pointer_cast(op) || + std::dynamic_pointer_cast(op)) return gpr2gpr; else if ( - std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op)) + std::dynamic_pointer_cast(op) || + std::dynamic_pointer_cast(op)) return vec2vec; else OPENVINO_THROW("Register type of the operation " + std::string(op->get_type_name()) + " isn't determined!"); } +bool intel_cpu::CPUGenerator::uses_precompiled_kernel(const std::shared_ptr& e) const { + return std::dynamic_pointer_cast(e) || + std::dynamic_pointer_cast(e); +} +} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_cpu/src/emitters/x64/cpu_generator.hpp b/src/plugins/intel_cpu/src/emitters/x64/cpu_generator.hpp index 96ccbb4b0db97f..fa3528df6c9e6d 100644 --- a/src/plugins/intel_cpu/src/emitters/x64/cpu_generator.hpp +++ b/src/plugins/intel_cpu/src/emitters/x64/cpu_generator.hpp @@ -13,13 +13,23 @@ namespace ov { namespace intel_cpu { +class CompiledSnippetCPU : public snippets::CompiledSnippet { + const std::unique_ptr h_compiled; +public: + const uint8_t* get_code() const override; + size_t get_code_size() const override; + bool empty() const override; + explicit CompiledSnippetCPU(std::unique_ptr h); +}; + class CPUTargetMachine : public snippets::TargetMachine { public: - CPUTargetMachine(dnnl::impl::cpu::x64::cpu_isa_t host_isa); + explicit CPUTargetMachine(dnnl::impl::cpu::x64::cpu_isa_t host_isa); bool is_supported() const override; - snippets::code get_snippet() const override; + snippets::CompiledSnippetPtr get_snippet() override; size_t get_lanes() const override; + dnnl::impl::cpu::x64::cpu_isa_t get_isa() const; private: std::unique_ptr h; @@ -29,8 +39,10 @@ class CPUTargetMachine : public snippets::TargetMachine { class CPUGenerator : public snippets::Generator { public: CPUGenerator(dnnl::impl::cpu::x64::cpu_isa_t isa); + std::shared_ptr clone() const override; protected: + bool uses_precompiled_kernel(const std::shared_ptr& emitter) const override; opRegType get_specific_op_reg_type(const std::shared_ptr& op) const override; }; diff --git a/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.cpp b/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.cpp index a146141c85c268..072c3f7edcf60b 100644 --- a/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.cpp +++ b/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.cpp @@ -11,6 +11,7 @@ #include "snippets/lowered/port_connector.hpp" #include "transformations/snippets/x64/op/brgemm_copy_b.hpp" #include "transformations/snippets/x64/op//brgemm_cpu.hpp" +#include "snippets/op/rank_normalization.hpp" using namespace InferenceEngine; using namespace Xbyak; @@ -109,6 +110,10 @@ KernelEmitter::KernelEmitter(jit_generator* h, cpu_isa_t isa, const ExpressionPt IE_THROW() << "KernelEmitter invoked with op::Kernel that contains no compile_params"; body = kernel->region; jcp = *reinterpret_cast(kernel->compile_params); + master_shape = body.get_master_shape(); + // Note: plugin can prepend master shape with 1 to facilitate parallel execution (usually up to 6D tensor) + // so we have to reproduce this behavior here + master_shape.insert(master_shape.begin(), jcp.parallel_executor_ndims - master_shape.size(), 1); const auto& io_exprs = body.get_IO_ops(); num_inputs = 0; num_outputs = 0; @@ -117,7 +122,12 @@ KernelEmitter::KernelEmitter(jit_generator* h, cpu_isa_t isa, const ExpressionPt element::Type etype; switch (expr->get_type()) { case snippets::lowered::IOExpression::io_type::INPUT: { - desc = expr->get_output_port_descriptor(0); + const auto first_consumer = expr->get_output_port_connector(0)->get_consumers().begin()->get_expr(); + if (ov::is_type(first_consumer->get_node())) { + desc = first_consumer->get_output_port_descriptor(0); + } else { + desc = expr->get_output_port_descriptor(0); + } etype = expr->get_node()->get_output_element_type(0); num_inputs++; break; @@ -217,7 +227,7 @@ void KernelEmitter::init_data_pointers(const Xbyak::Reg64& reg_indexes, const Xb const std::vector& data_ptr_regs) const { const auto num_params = num_inputs + num_outputs; // Note that we don't need offset for the last dim, since it's handled directly by Tile emitter - const size_t offset_rank = jcp.master_shape.size() - 1; + const size_t offset_rank = master_shape.size() - 1; std::vector> data_offsets(num_params, std::vector{}); auto offset_calculation = [=](const std::vector& shape, const std::vector& layout, const size_t data_size) { // Strides represent distance between consecutive elements of corresponding dimension. @@ -243,11 +253,8 @@ void KernelEmitter::init_data_pointers(const Xbyak::Reg64& reg_indexes, const Xb strides = std::move(reordered_strides); } // the last stride is ignored, since the entire last dim is processed by kernel - // and no parallel_for data_ptr offsets can be applied in this case (cover tile_rank == 1) + // and no parallel_for data_ptr offsets can be applied in this case strides.pop_back(); - // if tile_rank > 1, then zero corresponding strides since no external offset can be applied - // for (auto j = 0; j < tile_rank - 1; j++) - // strides[strides.size() - 1 - j] = 0; // actual offset size might be larger that the shape size due to 6D scheduling strides.insert(strides.begin(), offset_rank - strides.size(), 0); @@ -260,7 +267,7 @@ void KernelEmitter::init_data_pointers(const Xbyak::Reg64& reg_indexes, const Xb std::function&, Reg64)> init_ptr_with_offset; init_ptr_with_offset = [&](Reg64 pointer, const std::vector& offsets, Reg64 reg_tmp) { for (size_t j = 0; j < offset_rank; j++) { - if (jcp.master_shape[j] != 1 && offsets[j] != 0) { + if (master_shape[j] != 1 && offsets[j] != 0) { h->mov(reg_tmp, offsets[j]); h->imul(reg_tmp, h->ptr[reg_indexes + j * sizeof(size_t)]); h->add(pointer, reg_tmp); diff --git a/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.hpp b/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.hpp index d7d8922612c47b..7019fb14c6ec29 100644 --- a/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.hpp +++ b/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.hpp @@ -35,8 +35,7 @@ struct jit_snippets_call_args { }; struct jit_snippets_compile_args { - std::vector master_shape{}; - size_t tile_rank = 0; + size_t parallel_executor_ndims = 1; }; /// /// \brief jit_container_emitter designed to wrap Emitters that contain other Emitters (for example, KernelEmitter) @@ -94,6 +93,7 @@ class KernelEmitter : public jit_container_emitter { jit_snippets_compile_args jcp; std::vector gp_regs_pool; + std::vector master_shape; size_t num_inputs; size_t num_outputs; size_t num_unique_buffers; diff --git a/src/plugins/intel_cpu/src/extension.cpp b/src/plugins/intel_cpu/src/extension.cpp index 71c84045e12848..1da8e866f7c4a1 100644 --- a/src/plugins/intel_cpu/src/extension.cpp +++ b/src/plugins/intel_cpu/src/extension.cpp @@ -157,6 +157,7 @@ std::map Extension::getOpSets() { NGRAPH_OP(Store, ov::snippets::op) NGRAPH_OP(Subgraph, ov::snippets::op) NGRAPH_OP(VectorBuffer, ov::snippets::op) + NGRAPH_OP(RankNormalization, ov::snippets::op) NGRAPH_OP_X64(LoadConvertSaturation, ov::intel_cpu) NGRAPH_OP_X64(LoadConvertTruncation, ov::intel_cpu) NGRAPH_OP_X64(StoreConvertSaturation, ov::intel_cpu) diff --git a/src/plugins/intel_cpu/src/graph.cpp b/src/plugins/intel_cpu/src/graph.cpp index ed18c01c848af1..5275259886ed91 100644 --- a/src/plugins/intel_cpu/src/graph.cpp +++ b/src/plugins/intel_cpu/src/graph.cpp @@ -1709,7 +1709,10 @@ void Graph::EnforceInferencePrecision() { if (inferPrec == Precision::FP32) return; // nothing to do, only precision reduction is currently allowed - +#if defined(OV_CPU_ARM_ENABLE_FP16) + if (inferPrec == Precision::FP16) + return; // precision of configured by ov::pass::ConvertPrecision +#endif std::function& skipNodes)> searchForNodesToSkip; searchForNodesToSkip = [&](const NodePtr& node, std::unordered_set& skipNodes) -> void { for (size_t i = 0; i < node->getParentEdges().size(); i++) { diff --git a/src/plugins/intel_cpu/src/graph_optimizer.cpp b/src/plugins/intel_cpu/src/graph_optimizer.cpp index 791ff04021737c..770527c09aa334 100644 --- a/src/plugins/intel_cpu/src/graph_optimizer.cpp +++ b/src/plugins/intel_cpu/src/graph_optimizer.cpp @@ -286,7 +286,7 @@ void GraphOptimizer::FuseConvMatmulFCDeconvAndDQScales(Graph &graph) { } void GraphOptimizer::FuseFCAndWeightsDecompression(Graph &graph) { - const std::set supportedWeightsPrecisions{InferenceEngine::Precision::U8}; + std::set supportedWeightsPrecisions{InferenceEngine::Precision::U8, InferenceEngine::Precision::NF4}; const std::set supportedDataPrecisions{InferenceEngine::Precision::FP32, InferenceEngine::Precision::BF16}; auto expectedNode = [](NodePtr node, Type expectedType) { return node->getType() == expectedType && node->getChildEdges().size() == 1; @@ -301,11 +301,19 @@ void GraphOptimizer::FuseFCAndWeightsDecompression(Graph &graph) { if (fcNode == nullptr) continue; - const auto parent = fcNode->getParentEdgesAtPort(1)[0]->getParent(); + auto parent = fcNode->getParentEdgesAtPort(1)[0]->getParent(); const bool withTranspose = parent->getType() == Type::Transpose; const NodePtr transposeNode = withTranspose ? parent : nullptr; + if (transposeNode) + parent = transposeNode->getParentEdgesAtPort(0)[0]->getParent(); - const auto multiplyNode = withTranspose ? parent->getParentEdgesAtPort(0)[0]->getParent() : parent; + const bool withReshape = parent->getType() == Type::Reshape; + const auto reshapeNode = withReshape ? parent : nullptr; + if (reshapeNode) { + parent = reshapeNode->getParentEdgesAtPort(0)[0]->getParent(); + } + + const auto multiplyNode = parent; if (!expectedNode(multiplyNode, Type::Eltwise) || multiplyNode->getAlgorithm() != Algorithm::EltwiseMultiply || !multiplyNode->isConstant()) continue; @@ -346,23 +354,41 @@ void GraphOptimizer::FuseFCAndWeightsDecompression(Graph &graph) { // Shape limitations const auto weightsShape = weightsNode->getOutputShapeAtPort(0); - const auto fcInputWeightsShape = multiplyNode->getOutputShapeAtPort(0); - if (weightsShape != fcInputWeightsShape) + if (weightsShape != multiplyNode->getOutputShapeAtPort(0)) + continue; + if (reshapeNode && (reshapeNode->getInputShapeAtPort(0).getRank() != 3 || reshapeNode->getOutputShapeAtPort(0).getRank() != 2)) continue; - const auto expectedDims = withTranspose ? VectorDims{1, weightsShape.getDims()[1]} - : VectorDims{weightsShape.getDims()[0], 1}; - if (multiplyConstNode->getOutputShapeAtPort(0).getDims() != expectedDims) + VectorDims decompressionConstShape; + const auto fcInputWeightsShape = fcNode->getInputShapeAtPort(1); + // Ordinary case: one decompression group + if (fcInputWeightsShape.getRank() == weightsShape.getRank()) { + const auto& out_channels = fcInputWeightsShape.getDims()[0]; + decompressionConstShape = withTranspose ? VectorDims{1, out_channels} : VectorDims{out_channels, 1}; + } else { + // Group decompression case: last 3 dimension (there could be also prepending '1's in the beginning) of weights shape must be: + // [N, G, O], if transpose = true + // [O, N, G], otherwise. + // O - output channels + // N - number of groups + // G - group size + const auto& weights_dims = weightsShape.getStaticDims(); + const auto& N = withTranspose ? *(weights_dims.rbegin() + 2) : *(weights_dims.rbegin() + 1); + const auto& O = withTranspose ? *weights_dims.rbegin() : *(weights_dims.rbegin() + 2); + // Group decompression is applied by O and N dims + decompressionConstShape = withTranspose ? VectorDims{N, 1, O} : VectorDims{O, N, 1}; + } + if (multiplyConstNode->getOutputShapeAtPort(0).getDims() != decompressionConstShape) continue; - if (withSubtract && subtractConstNode->getOutputShapeAtPort(0).getDims() != expectedDims) + if (withSubtract && subtractConstNode->getOutputShapeAtPort(0).getDims() != decompressionConstShape) continue; // HW specific shape limitations if (impl::cpu::x64::mayiuse(impl::cpu::x64::avx512_core_amx)) { // OneDNN AMX IP implementation has limited shapes support due to performance considerations. As a current solution conditions below are copied // from OneDNN to make sure correct IP impl will be used since fallback one doesn't support weights decompression feature. - size_t OC = withTranspose ? weightsShape.getDims()[1] : weightsShape.getDims()[0]; - size_t IC = withTranspose ? weightsShape.getDims()[0] : weightsShape.getDims()[1]; + size_t OC = fcInputWeightsShape.getDims()[0]; + size_t IC = fcInputWeightsShape.getDims()[1]; size_t simdWidth = 16; size_t vnniFactor = 2; size_t maxSize = 512; @@ -398,6 +424,10 @@ void GraphOptimizer::FuseFCAndWeightsDecompression(Graph &graph) { transposeNode->setOriginalInputPrecisionAtPort(0, weightsPrecision); transposeNode->setOriginalOutputPrecisionAtPort(0, weightsPrecision); } + if (withReshape) { + reshapeNode->setOriginalInputPrecisionAtPort(0, weightsPrecision); + reshapeNode->setOriginalOutputPrecisionAtPort(0, weightsPrecision); + } fcNode->setOriginalInputPrecisionAtPort(1, weightsPrecision); } } diff --git a/src/plugins/intel_cpu/src/node.cpp b/src/plugins/intel_cpu/src/node.cpp index e8fe6b89a00afc..ab02ae44dd6ce2 100644 --- a/src/plugins/intel_cpu/src/node.cpp +++ b/src/plugins/intel_cpu/src/node.cpp @@ -95,8 +95,6 @@ Node::Node(const std::shared_ptr& op, typeStr(op->get_type_name()), type(TypeFromName(op->get_type_name())), profiling(op->get_friendly_name()) { - const std::string errorPrefix = "Ngraph operation " + std::string(op->get_type_name()) + " with name " + op->get_friendly_name(); - for (size_t i = 0; i < op->get_input_size(); i++) { const auto &shape = op->get_input_partial_shape(i); if (shape.rank().is_dynamic()) { @@ -480,6 +478,8 @@ std::string Node::getPrimitiveDescriptorType() const { SEARCH_TYPE(_dw); SEARCH_TYPE(_1x1); +#undef SEARCH_TYPE + if (type == impl_desc_type::unknown) str_type = "unknown"; else if (str_type.empty()) diff --git a/src/plugins/intel_cpu/src/node.h b/src/plugins/intel_cpu/src/node.h index 5becbfa9863f70..864c08a95b04c6 100644 --- a/src/plugins/intel_cpu/src/node.h +++ b/src/plugins/intel_cpu/src/node.h @@ -41,6 +41,8 @@ #include "nodes/executors/mvn_list.hpp" #include "nodes/executors/executor.hpp" +#define THROW_CPU_NODE_ERR(...) OPENVINO_THROW(getTypeStr(), " node with name '", getName(), "' ", __VA_ARGS__) + namespace ov { namespace intel_cpu { @@ -353,7 +355,7 @@ class Node { inplace = InPlaceType::Unknown; } - std::string getPrimitiveDescriptorType() const; + virtual std::string getPrimitiveDescriptorType() const; PerfCount &PerfCounter() { return perfCounter; } diff --git a/src/plugins/intel_cpu/src/nodes/ctc_greedy_decoder.cpp b/src/plugins/intel_cpu/src/nodes/ctc_greedy_decoder.cpp index 494fb6176dd65e..0b2ee382e2a2a9 100644 --- a/src/plugins/intel_cpu/src/nodes/ctc_greedy_decoder.cpp +++ b/src/plugins/intel_cpu/src/nodes/ctc_greedy_decoder.cpp @@ -56,11 +56,11 @@ void CTCGreedyDecoder::initSupportedPrimitiveDescriptors() { return; Precision inDataPrecision = getOriginalInputPrecisionAtPort(DATA_INDEX); - if (inDataPrecision != Precision::FP32 && inDataPrecision != Precision::BF16) + if (!one_of(inDataPrecision, Precision::FP32, Precision::BF16, Precision::FP16)) IE_THROW() << errorPrefix << "has unsupported 'data' input precision: " << inDataPrecision; Precision seqLenPrecision = getOriginalInputPrecisionAtPort(SEQUENCE_LENGTH_INDEX); - if (seqLenPrecision != Precision::FP32 && seqLenPrecision != Precision::BF16) + if (!one_of(inDataPrecision, Precision::FP32, Precision::BF16, Precision::FP16)) IE_THROW() << errorPrefix << "has unsupported 'sequence_length' input precision: " << seqLenPrecision; addSupportedPrimDesc({{LayoutType::ncsp, Precision::FP32}, diff --git a/src/plugins/intel_cpu/src/nodes/ctc_greedy_decoder_seq_len.cpp b/src/plugins/intel_cpu/src/nodes/ctc_greedy_decoder_seq_len.cpp index be695d85b8c6f2..8e6e0617cd75f2 100644 --- a/src/plugins/intel_cpu/src/nodes/ctc_greedy_decoder_seq_len.cpp +++ b/src/plugins/intel_cpu/src/nodes/ctc_greedy_decoder_seq_len.cpp @@ -55,7 +55,7 @@ void CTCGreedyDecoderSeqLen::initSupportedPrimitiveDescriptors() { return; Precision inDataPrecision = getOriginalInputPrecisionAtPort(DATA_INDEX); - if (inDataPrecision != Precision::FP32 && inDataPrecision != Precision::BF16) + if (!one_of(inDataPrecision, Precision::FP32, Precision::BF16, Precision::FP16)) IE_THROW() << errorPrefix << "has unsupported 'data' input precision: " << inDataPrecision; Precision seqLenPrecision = getOriginalInputPrecisionAtPort(SEQUENCE_LENGTH_INDEX); diff --git a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_eltwise.cpp b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_eltwise.cpp index cb5911e90836fb..f22004a0d3e154 100644 --- a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_eltwise.cpp +++ b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_eltwise.cpp @@ -10,6 +10,11 @@ namespace intel_cpu { using namespace arm_compute; +static std::mutex & get_mtx_ifunc() { + static std::mutex mtx_ifunc; + return mtx_ifunc; +} + inline VectorDims reshape_sizes(VectorDims dims) { const size_t MAX_NUM_SHAPE = arm_compute::MAX_DIMS; VectorDims result_dims(MAX_NUM_SHAPE - 1); @@ -494,6 +499,11 @@ bool AclEltwiseExecutor::init(const EltwiseAttrs &eltwiseAttrs, const std::vecto default: IE_THROW() << "Unsupported operation type for ACL Eltwise executor: " << static_cast(aclEltwiseAttrs.algorithm); } + + // We get a problem (seg. faults, data race etc) for eltwise operations when we use several configure(...) functions in parallel. + // We created issue about this problem here: https://github.com/ARM-software/ComputeLibrary/issues/1073 + // TODO: change it when we will get an answer to our question in issue + std::lock_guard _lock {get_mtx_ifunc()}; ifunc = exec_func(); return true; } diff --git a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_ie_scheduler.cpp b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_ie_scheduler.cpp new file mode 100644 index 00000000000000..c617363aefebf6 --- /dev/null +++ b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_ie_scheduler.cpp @@ -0,0 +1,77 @@ +// Copyright (C) 2020-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "acl_ie_scheduler.hpp" + +#include "arm_compute/core/CPP/ICPPKernel.h" +#include "arm_compute/core/Error.h" +#include "arm_compute/core/Helpers.h" +#include + +namespace ov { +namespace intel_cpu { + +using namespace arm_compute; + +ACLScheduler::ACLScheduler() = default; + +unsigned int ACLScheduler::num_threads() const { + return parallel_get_num_threads(); +} + +void ACLScheduler::set_num_threads(unsigned int num_threads) {} + +void ACLScheduler::schedule_custom(ICPPKernel *kernel, const Hints &hints, const Window &window, ITensorPack &tensors) { + const Window & max_window = window; + const unsigned int num_iterations = max_window.num_iterations_total(); + const auto _num_threads = std::min(num_iterations, static_cast(parallel_get_num_threads())); + + if (num_iterations == 0) { + return; + } + + std::function main_run; + if (tensors.empty()) { + main_run = [&](const Window &window, const ThreadInfo &info) { + kernel->run(window, info); + }; + } else { + main_run = [&](const Window &window, const ThreadInfo &info) { + kernel->run_op(tensors, window, info); + }; + } + + if (!kernel->is_parallelisable() || _num_threads == 1) { + ThreadInfo info; + info.cpu_info = &cpu_info(); + main_run(max_window, info); + } else { + const auto num_windows = _num_threads; + const auto hints_split_dimension = hints.split_dimension(); + + InferenceEngine::parallel_for(num_windows, [&](int wid) { + Window win = max_window.split_window(hints_split_dimension, wid, num_windows); + win.validate(); + main_run(win, {wid, static_cast(_num_threads), &cpu_info()}); + }); + } +} + +void ACLScheduler::schedule(ICPPKernel *kernel, const Hints &hints) { + ITensorPack tensors; + schedule_custom(kernel, hints, kernel->window(), tensors); +} + +void ACLScheduler::schedule_op(ICPPKernel *kernel, const Hints &hints, const Window &window, ITensorPack &tensors) { + schedule_custom(kernel, hints, window, tensors); +} + +void ACLScheduler::run_workloads(std::vector &workloads) { + InferenceEngine::parallel_for(workloads.size(), [&](int wid) { + workloads[wid]({wid, static_cast(parallel_get_num_threads()), &cpu_info()}); + }); +} + +} // namespace intel_cpu +} // namespace ov diff --git a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_ie_scheduler.hpp b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_ie_scheduler.hpp new file mode 100644 index 00000000000000..1148f4ad5edd69 --- /dev/null +++ b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_ie_scheduler.hpp @@ -0,0 +1,31 @@ +// Copyright (C) 2020-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include "support/Mutex.h" + +namespace ov { +namespace intel_cpu { + +using namespace arm_compute; + +class ACLScheduler final : public IScheduler { +public: + ACLScheduler(); + ~ACLScheduler() override = default; + std::uint32_t num_threads() const override; + void set_num_threads(unsigned int num_threads) override; + void schedule(ICPPKernel *kernel, const Hints &hints) override; + void schedule_op(ICPPKernel *kernel, const Hints &hints, const Window &window, ITensorPack &tensors) override; +protected: + void run_workloads(std::vector &workloads) override; +private: + void schedule_custom(ICPPKernel *kernel, const Hints &hints, const Window &window, ITensorPack &tensors); +}; +} // namespace intel_cpu +} // namespace ov diff --git a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_pooling.cpp b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_pooling.cpp index 72021a5c6c5812..9cd6e3c43df7b0 100644 --- a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_pooling.cpp +++ b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_pooling.cpp @@ -20,7 +20,8 @@ bool AclPoolingExecutor::isSupported(const TensorInfo& srcTensorInfo, DataLayout dataLayout, const VectorDims* indDims, PoolingLayerInfo* pool_info, - Pooling3dLayerInfo* pool3d_info) { + Pooling3dLayerInfo* pool3d_info, + bool ignoreOutShapeErrors) { unsigned int pad_left = (poolingAttrs.data_pad_begin.size() >= 2u) ? poolingAttrs.data_pad_begin[1] : poolingAttrs.data_pad_begin[0]; unsigned int pad_right = (poolingAttrs.data_pad_end.size() >= 2u) ? poolingAttrs.data_pad_end[1] : poolingAttrs.data_pad_end[0]; unsigned int pad_top = (poolingAttrs.data_pad_begin.size() >= 2u) ? poolingAttrs.data_pad_begin[0] : 0; @@ -46,7 +47,12 @@ bool AclPoolingExecutor::isSupported(const TensorInfo& srcTensorInfo, // The combination of parameters: NCHW + CEIL gives an accuracy problem in AvgPool. // One workaround is to disable the ACL executor for these parameters. // Then OneDNN will run this case in ACL backend as reorder -> NHWC -> reorder - if (dataLayout == arm_compute::DataLayout::NCHW && poolingAttrs.rounding == op::RoundingType::CEIL) return false; + if (pool_type == PoolingType::AVG && + dataLayout == arm_compute::DataLayout::NCHW && + poolingAttrs.rounding == op::RoundingType::CEIL) { + DEBUG_LOG("NCHW + CEIL gives an accuracy problem in ACL AvgPool. ACL executor will not be created."); + return false; + } DimensionRoundingType round = (poolingAttrs.rounding == op::RoundingType::CEIL) ? DimensionRoundingType::CEIL : DimensionRoundingType::FLOOR; @@ -82,12 +88,22 @@ bool AclPoolingExecutor::isSupported(const TensorInfo& srcTensorInfo, arm_compute::Status s = arm_compute::NEPoolingLayer::validate(&srcTensorInfo, &dstTensorInfo, *pool_info, &indTensorInfo); if (!s) { DEBUG_LOG("NEPoolingLayer validation with indices failed: ", s.error_description()); + if (ignoreOutShapeErrors && + s.error_description().find("Tensors have different shapes") != std::string::npos) { + DEBUG_LOG("Ignore shape error because the flag ignoreOutShapeErrors is set"); + return true; + } return false; } } else { arm_compute::Status s = arm_compute::NEPoolingLayer::validate(&srcTensorInfo, &dstTensorInfo, *pool_info); if (!s) { DEBUG_LOG("NEPoolingLayer validation without indices failed: ", s.error_description()); + if (ignoreOutShapeErrors && + s.error_description().find("Tensors have different shapes") != std::string::npos) { + DEBUG_LOG("Ignore shape error because the flag ignoreOutShapeErrors is set"); + return true; + } return false; } } diff --git a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_pooling.hpp b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_pooling.hpp index 44a2e999057d32..2525ccb490468a 100644 --- a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_pooling.hpp +++ b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_pooling.hpp @@ -31,7 +31,8 @@ class AclPoolingExecutor : public PoolingExecutor { arm_compute::DataLayout dataLayout, const VectorDims* indDims, arm_compute::PoolingLayerInfo* pool_info, - arm_compute::Pooling3dLayerInfo* pool3d_info); + arm_compute::Pooling3dLayerInfo* pool3d_info, + bool ignoreOutShapeErrors = false); impl_desc_type getImplType() const override { return implType; @@ -79,8 +80,8 @@ class AclPoolingExecutorBuilder : public PoolingExecutorBuilder { if (dstDescs.size() == 2u && dstDescs[1]->getPrecision() != InferenceEngine::Precision::U32) { - DEBUG_LOG("AclPoolingExecutor does not support precisions:", - " dst[1]=", dstDescs[1]->getPrecision()); + DEBUG_LOG("AclPoolingExecutor supports U32 as indices precisions only. ", + "Passed indices precision: ", dstDescs[1]->getPrecision()); return false; } diff --git a/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp b/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp index fcb112c368131c..3add267195ae34 100644 --- a/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp +++ b/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp @@ -52,6 +52,7 @@ struct FCKey { dnnl::primitive_attr attr; impl_desc_type implType; bool useConv1x1; + bool useSparseWeights; size_t hash() const; bool operator==(const FCKey& rhs) const; @@ -72,6 +73,7 @@ size_t FCKey::hash() const { seed = hash_combine(seed, get_attr_hash(*attr.get())); seed = hash_combine(seed, implType); seed = hash_combine(seed, useConv1x1); + seed = hash_combine(seed, useSparseWeights); return seed; } @@ -90,7 +92,7 @@ bool FCKey::operator==(const FCKey &rhs) const { retVal = retVal && out && rhs.out && out->getDnnlDesc() == rhs.out->getDnnlDesc(); } retVal = retVal && *attr.get() == *rhs.attr.get() && - implType == rhs.implType && useConv1x1 == rhs.useConv1x1; + implType == rhs.implType && useConv1x1 == rhs.useConv1x1 && useSparseWeights == rhs.useSparseWeights; return retVal; } @@ -416,15 +418,20 @@ static dnnl::primitive_desc createPrimitiveDesc(const FCKey& key, const dnnl::en auto normalizedOutDims = { outDims[0] * outDims[1], outDims[2] }; outDesc = outDesc.reshape(normalizedOutDims); } - auto wghDescAny = dnnl::memory::desc(DnnlExtensionUtils::convertToDnnlDims(key.inp1->getShape().getStaticDims()), - key.inp1->getDataType(), memory::format_tag::any); + dnnl::memory::desc weiDesc; + if (key.useSparseWeights) { + weiDesc = key.inp1->getDnnlDesc(); + } else { + weiDesc = dnnl::memory::desc(DnnlExtensionUtils::convertToDnnlDims(key.inp1->getShape().getStaticDims()), + key.inp1->getDataType(), memory::format_tag::any); + } dnnl::inner_product_forward::primitive_desc prim_desc; if (key.bias) { prim_desc = dnnl::inner_product_forward::primitive_desc( engine, dnnl::prop_kind::forward_inference, inDesc, - wghDescAny, + weiDesc, key.bias->getDnnlDesc(), outDesc, key.attr); @@ -433,7 +440,7 @@ static dnnl::primitive_desc createPrimitiveDesc(const FCKey& key, const dnnl::en engine, dnnl::prop_kind::forward_inference, inDesc, - wghDescAny, + weiDesc, outDesc, key.attr); } @@ -542,7 +549,8 @@ void FullyConnected::prepareParams() { outDesc, attr, implementationTypeIP, - useConv1x1}; + useConv1x1, + useSparseWeights}; auto& engine = getEngine(); @@ -597,7 +605,8 @@ void FullyConnected::prepareParams() { // changed shapes may also cause the kernel type changed selected_pd->setImplementationType(execPtr->getImplementationType()); // WA: We update implType to know whether weights decompression was used inside the kernel - if (selected_pd->getImplementationType() == ov::intel_cpu::brgemm_avx512_amx && useSparseWeights) { + if (selected_pd->getImplementationType() == ov::intel_cpu::brgemm_avx512_amx && + execPtr->getDnnlWeightDesc().get_format_kind() == memory::format_kind::sparsed) { selected_pd->setImplementationType(ov::intel_cpu::brgemm_sparse_avx512_amx); } // maybe expected 1x1 conv is not created, update the flag depends on the real type @@ -720,10 +729,10 @@ void FullyConnected::setPostOps(dnnl::primitive_attr& attr, const VectorDims& di // and prepack runtime attributes accordingly for better performance bool withAMX = selected_pd->getImplementationType() & impl_desc_type::amx; int icBlock = withAMX ? 2 : 1; - if (!decompressionMultiply.empty()) - dnnlpoc.appendDecompressionScales(decompressionMultiply, icBlock); - if (!decompressionSubtract.empty()) - dnnlpoc.appendDecompressionZeroPoints(decompressionSubtract, icBlock); + if (decompressionMultiplyPtr) + dnnlpoc.appendDecompressionScales(decompressionMultiplyPtr, icBlock); + if (decompressionSubtractPtr) + dnnlpoc.appendDecompressionZeroPoints(decompressionSubtractPtr, icBlock); for (size_t i = 0; i < fusedWith.size(); ++i) { auto& node = fusedWith[i]; @@ -960,7 +969,7 @@ std::shared_ptr FullyConnected::getSrcMemDesc(const dnnl::primitive_ if (getInputShapeAtPort(idx).getRank() == 3 // report original plain layout for weight since it needs to be reordered dynamically at runtime - || idx == 1) { + || (idx == 1 && !useSparseWeights)) { return std::make_shared( DnnlExtensionUtils::DataTypeToIEPrecision(desc.get_data_type()), getInputShapeAtPort(idx)); } @@ -1124,26 +1133,32 @@ bool FullyConnected::useSparseWeightsDecompression() { } void FullyConnected::fuseDecompressionMultiply(const NodePtr& constData) { - fuseDecompressionConstant(constData, decompressionMultiply); + fuseDecompressionConstant(constData, decompressionMultiplyPtr); } void FullyConnected::fuseDecompressionSubtract(const NodePtr& constData) { - fuseDecompressionConstant(constData, decompressionSubtract); + fuseDecompressionConstant(constData, decompressionSubtractPtr); } -void FullyConnected::fuseDecompressionConstant(const NodePtr& constData, std::vector& decompressionValues) { +void FullyConnected::fuseDecompressionConstant(const NodePtr& constData, MemoryCPtr& decompressionValuesPtr) { auto *constInputNode = dynamic_cast(constData.get()); if (!constInputNode) { IE_THROW() << "Cannot cast " << constData->getName() << " to Input"; } - auto constBlob = constInputNode->getMemoryPtr(); - const auto elementsCount = constBlob->getDescWithType()->getPaddedElementsCount(); - decompressionValues.resize(elementsCount); - cpu_convert(constBlob->getData(), - &decompressionValues[0], - DnnlExtensionUtils::DataTypeToIEPrecision(constBlob->getDataType()), - Precision::FP32, - elementsCount); + const auto decompression_prc = InferenceEngine::Precision::FP32; + if (constInputNode->getOriginalOutputPrecisionAtPort(0) == decompression_prc) { + decompressionValuesPtr = constInputNode->getMemoryPtr(); + } else { + const auto constBlob = constInputNode->getMemoryPtr(); + DnnlBlockedMemoryDesc memoryDesc(decompression_prc, constBlob->getShape()); + decompressionValuesPtr = std::make_shared(getEngine(), memoryDesc, nullptr, false); + const auto elementsCount = constBlob->getDescWithType()->getPaddedElementsCount(); + cpu_convert(constBlob->getData(), + decompressionValuesPtr->getData(), + DnnlExtensionUtils::DataTypeToIEPrecision(constBlob->getDataType()), + Precision::FP32, + elementsCount); + } } DnnlMemoryDescPtr FullyConnected::makeTransposedWeightDescriptor(DnnlMemoryDescPtr desc) { diff --git a/src/plugins/intel_cpu/src/nodes/fullyconnected.h b/src/plugins/intel_cpu/src/nodes/fullyconnected.h index 8c25927ca06f36..956767bcea1219 100644 --- a/src/plugins/intel_cpu/src/nodes/fullyconnected.h +++ b/src/plugins/intel_cpu/src/nodes/fullyconnected.h @@ -61,10 +61,7 @@ class FullyConnected : public Node { } void fuseDecompressionMultiply(const NodePtr& constData); - const std::vector& getDecompressionMultiply() const { return decompressionMultiply; } - void fuseDecompressionSubtract(const NodePtr& constData); - const std::vector& getDecompressionSubtract() const { return decompressionSubtract; } private: void createDescriptorInternal(const dnnl::memory::desc &inputDesc, @@ -102,7 +99,7 @@ class FullyConnected : public Node { const dnnl::engine& engine); bool canBeExecutedInConv1x1() const; - void fuseDecompressionConstant(const NodePtr& constData, std::vector& decompressionValues); + void fuseDecompressionConstant(const NodePtr& constData, MemoryCPtr& decompressionValuesPtr); // sparse weights bool useSparseWeights = false; @@ -121,8 +118,8 @@ class FullyConnected : public Node { void prepareWeightsUsingDummyShape(); #endif bool useWeightsDecompressionImpl = false; - std::vector decompressionSubtract; - std::vector decompressionMultiply; + MemoryCPtr decompressionSubtractPtr = nullptr; + MemoryCPtr decompressionMultiplyPtr = nullptr; // FC with transposed weights bool weightsNonTransposed = false; diff --git a/src/plugins/intel_cpu/src/nodes/grid_sample.cpp b/src/plugins/intel_cpu/src/nodes/grid_sample.cpp index 798b04078352bf..6868e907fa7ae8 100644 --- a/src/plugins/intel_cpu/src/nodes/grid_sample.cpp +++ b/src/plugins/intel_cpu/src/nodes/grid_sample.cpp @@ -10,9 +10,11 @@ #include using namespace InferenceEngine; -using namespace dnnl::impl::cpu; using namespace ov::intel_cpu; using namespace ov::intel_cpu::node; +#if defined(OPENVINO_ARCH_X86_64) +using namespace dnnl::impl::cpu; +#endif // OPENVINO_ARCH_X86_64 #define THROW_ERROR IE_THROW() << getTypeStr() << " node with name '" << getName() << "' " @@ -23,10 +25,14 @@ bool GridSample::isSupportedOperation(const std::shared_ptr& op, errorMessage = "Not supported GridSample operation version. CPU plug-in supports only 9th version."; return false; } +#if defined(OPENVINO_ARCH_X86_64) if (!x64::mayiuse(x64::sse41)) { errorMessage = "Not supported CPU instructions set."; return false; } +#else + return false; +#endif // OPENVINO_ARCH_X86_64 } catch (...) { return false; } @@ -34,6 +40,8 @@ bool GridSample::isSupportedOperation(const std::shared_ptr& op, return true; } +#if defined(OPENVINO_ARCH_X86_64) + GridSample::GridSample(const std::shared_ptr& op, const GraphContext::CPtr context) : Node(op, context, NgraphShapeInferFactory(op, PortMask(1))) { std::string errorMessage; @@ -110,7 +118,7 @@ void GridSample::initSupportedPrimitiveDescriptors() { } void GridSample::createPrimitive() { - GridSampleKernelConfParams jcp; + kernel::GridSampleKernelConfParams jcp; jcp.inDataPrc = dataPrecision; jcp.gridPrc = gridPrecision; @@ -133,15 +141,13 @@ void GridSample::createPrimitive() { jcp.cannelNum = jcp.dynamicChannel ? 1lu : srcDataDims[1]; } -#if defined(OPENVINO_ARCH_X86_64) if (x64::mayiuse(x64::avx512_core)) { - jitKernel.reset(new GridSampleKernel(jcp)); + jitKernel.reset(new kernel::GridSampleKernel(jcp)); } else if (x64::mayiuse(x64::avx2)) { - jitKernel.reset(new GridSampleKernel(jcp)); + jitKernel.reset(new kernel::GridSampleKernel(jcp)); } else if (x64::mayiuse(x64::sse41)) { - jitKernel.reset(new GridSampleKernel(jcp)); + jitKernel.reset(new kernel::GridSampleKernel(jcp)); } -#endif // OPENVINO_ARCH_X86_64 if (!jitKernel) { THROW_ERROR << " could not create JIT kernel."; } @@ -268,7 +274,7 @@ void GridSample::execute(dnnl::stream strm) { auto threadBody = [&](const int ithr, const int nthr) { const auto& p = execParamsPerThread[ithr]; - auto arg = GridSamplesKernelExecArgs(); + auto arg = kernel::GridSamplesKernelExecArgs(); if (p.workAmount == 0lu) { return; } @@ -311,3 +317,5 @@ void GridSample::executeDynamicImpl(dnnl::stream strm) { bool GridSample::created() const { return getType() == Type::GridSample; } + +#endif // OPENVINO_ARCH_X86_64 diff --git a/src/plugins/intel_cpu/src/nodes/grid_sample.hpp b/src/plugins/intel_cpu/src/nodes/grid_sample.hpp index 89a1a409764615..78b5f9d66710ca 100644 --- a/src/plugins/intel_cpu/src/nodes/grid_sample.hpp +++ b/src/plugins/intel_cpu/src/nodes/grid_sample.hpp @@ -72,7 +72,7 @@ class GridSample : public Node { static constexpr size_t IN_DATA = 0; static constexpr size_t IN_GRID = 1; - std::shared_ptr jitKernel; + std::shared_ptr jitKernel; }; } // namespace node diff --git a/src/plugins/intel_cpu/src/nodes/kernels/x64/grid_sample.cpp b/src/plugins/intel_cpu/src/nodes/kernels/x64/grid_sample.cpp index 7501dd606427ce..89e658a7d6a6fc 100644 --- a/src/plugins/intel_cpu/src/nodes/kernels/x64/grid_sample.cpp +++ b/src/plugins/intel_cpu/src/nodes/kernels/x64/grid_sample.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Intel Corporation +// Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // @@ -8,12 +8,13 @@ using namespace dnnl::impl::cpu; namespace ov { namespace intel_cpu { +namespace kernel { #define GET_OFF(field) offsetof(GridSamplesKernelExecArgs, field) template GridSampleKernel::GridSampleKernel(const GridSampleKernelConfParams& jcp) : - GridSampleKernelBase(jit_name(), jcp) { + GridSampleKernelBase(jit_name(), jcp, isa) { vlen = x64::cpu_isa_traits::vlen; dataTypeSize = jcp.inDataPrc.size(); gridTypeSize = jcp.gridPrc.size(); @@ -2085,5 +2086,6 @@ template class GridSampleKernel; template class GridSampleKernel; template class GridSampleKernel; +} // namespace kernel } // namespace intel_cpu } // namespace ov diff --git a/src/plugins/intel_cpu/src/nodes/kernels/x64/grid_sample.hpp b/src/plugins/intel_cpu/src/nodes/kernels/x64/grid_sample.hpp index c24100259cd5bb..295c715fb8146b 100644 --- a/src/plugins/intel_cpu/src/nodes/kernels/x64/grid_sample.hpp +++ b/src/plugins/intel_cpu/src/nodes/kernels/x64/grid_sample.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Intel Corporation +// Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // @@ -14,6 +14,12 @@ namespace intel_cpu { enum class GridSampleInterpolationMode { BILINEAR, BICUBIC, NEAREST }; enum class GridSamplePaddingMode { ZEROS, BORDER, REFLECTION }; +namespace kernel { + +class GridSampleKernelBase; + +#if defined(OPENVINO_ARCH_X86_64) + struct GridSampleKernelConfParams { bool dynamicShapes = false; bool dynamicBatch = false; @@ -66,7 +72,8 @@ class GridSampleKernelBase: public JitKernelBase { assert(ker_); ker_(args); } - explicit GridSampleKernelBase(const char* name, const GridSampleKernelConfParams& jcp) : JitKernelBase(name), ker_(nullptr), jcp(jcp) {} + explicit GridSampleKernelBase(const char* name, const GridSampleKernelConfParams& jcp, dnnl::impl::cpu::x64::cpu_isa_t isa) + : JitKernelBase(name, isa), ker_(nullptr), jcp(jcp) {} virtual void create_ker() = 0; uint64_t getVecLen() { @@ -173,5 +180,8 @@ class GridSampleKernel : public GridSampleKernelBase { void hwShiftPs2dq(const Vmm& vDst, const Vmm& vHCoord, const Vmm& vWCoord, const Vmm& vWidth); }; +#endif // OPENVINO_ARCH_X86_64 + +} // namespace kernel } // namespace intel_cpu } // namespace ov diff --git a/src/plugins/intel_cpu/src/nodes/kernels/x64/jit_kernel_base.cpp b/src/plugins/intel_cpu/src/nodes/kernels/x64/jit_kernel_base.cpp index 6afbecf143f27b..bc0daaf6e33e2a 100644 --- a/src/plugins/intel_cpu/src/nodes/kernels/x64/jit_kernel_base.cpp +++ b/src/plugins/intel_cpu/src/nodes/kernels/x64/jit_kernel_base.cpp @@ -1,172 +1,243 @@ -// Copyright (C) 2022 Intel Corporation +// Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // #include "jit_kernel_base.hpp" -using namespace ov; -using namespace intel_cpu; using namespace dnnl::impl::cpu; +namespace ov { +namespace intel_cpu { +namespace kernel { -void JitKernelBase::uni_vfmsub132ps(const Xbyak::Xmm& vDst, - const Xbyak::Xmm& vSrc, +JitKernelBase::JitKernelBase(const char* name, x64::cpu_isa_t isa) + : x64::jit_generator(name, nullptr, x64::MAX_CODE_SIZE, true, isa), m_isa(isa) { + vlen = x64::isa_max_vlen(isa); +} + +void JitKernelBase::uni_vfmsub132ps(const Xbyak::Xmm& v_dst, + const Xbyak::Xmm& v_src, const Xbyak::Operand& op) { if (isValidIsa(x64::avx2)) { - vfmsub132ps(vDst, vSrc, op); + vfmsub132ps(v_dst, v_src, op); } else if (isValidIsa(x64::avx)) { - assert(vDst.getIdx() != vSrc.getIdx()); - vmulps(vDst, vDst, op); - vsubps(vDst, vDst, vSrc); + assert(v_dst.getIdx() != v_src.getIdx()); + vmulps(v_dst, v_dst, op); + vsubps(v_dst, v_dst, v_src); } else { - assert(vDst.getIdx() != vSrc.getIdx()); - mulps(vDst, op); - subps(vDst, vSrc); + assert(v_dst.getIdx() != v_src.getIdx()); + mulps(v_dst, op); + subps(v_dst, v_src); } } -void JitKernelBase::uni_vfnmadd132ps(const Xbyak::Xmm& vDst, - const Xbyak::Xmm& vSrc, +void JitKernelBase::uni_vfnmadd132ps(const Xbyak::Xmm& v_dst, + const Xbyak::Xmm& v_src, const Xbyak::Operand& op) { if (isValidIsa(x64::avx2)) { - vfnmadd132ps(vDst, vSrc, op); + vfnmadd132ps(v_dst, v_src, op); } else if (isValidIsa(x64::avx)) { - assert(vDst.getIdx() != vSrc.getIdx()); - vmulps(vDst, vDst, op); - vsubps(vDst, vSrc, vDst); + assert(v_dst.getIdx() != v_src.getIdx()); + vmulps(v_dst, v_dst, op); + vsubps(v_dst, v_src, v_dst); } else { - assert(vDst.getIdx() != vSrc.getIdx()); - mulps(vDst, op); - subps(vSrc, vDst); - movups(vDst, vSrc); + assert(v_dst.getIdx() != v_src.getIdx()); + mulps(v_dst, op); + subps(v_src, v_dst); + movups(v_dst, v_src); } } -void JitKernelBase::uni_vfmsub231ps(const Xbyak::Xmm& vDst, - const Xbyak::Xmm& vSrc, +void JitKernelBase::uni_vfmsub231ps(const Xbyak::Xmm& v_dst, + const Xbyak::Xmm& v_src, const Xbyak::Operand& op) { if (isValidIsa(x64::avx2)) { - vfmsub231ps(vDst, vSrc, op); + vfmsub231ps(v_dst, v_src, op); } else if (isValidIsa(x64::avx)) { - assert(!vDst.isEqualIfNotInherited(op)); - vmulps(vSrc, vSrc, op); - vsubps(vDst, vSrc, vDst); + assert(!v_dst.isEqualIfNotInherited(op)); + vmulps(v_src, v_src, op); + vsubps(v_dst, v_src, v_dst); } else { - assert(!vDst.isEqualIfNotInherited(op)); - mulps(vSrc, op); - subps(vSrc, vDst); - movups(vDst, vSrc); + assert(!v_dst.isEqualIfNotInherited(op)); + mulps(v_src, op); + subps(v_src, v_dst); + movups(v_dst, v_src); } } -void JitKernelBase::uni_vpaddd(const Xbyak::Ymm& vDst, - const Xbyak::Ymm& vSrc, +void JitKernelBase::uni_vpaddd(const Xbyak::Ymm& v_dst, + const Xbyak::Ymm& v_src, const Xbyak::Operand& op) { if (isValidIsa(x64::avx2)) { - vpaddd(vDst, vSrc, op); + vpaddd(v_dst, v_src, op); } else if (isValidIsa(x64::avx)) { - Xbyak::Xmm xmmDst(vDst.getIdx()); - vmovups(vDst, vSrc); + Xbyak::Xmm xmmDst(v_dst.getIdx()); + vmovups(v_dst, v_src); if (op.isYMM()) { Xbyak::Ymm ymmOp(op.getIdx()); Xbyak::Xmm xmmOp(op.getIdx()); paddd(xmmDst, xmmOp); - vperm2f128(vDst, vDst, vDst, 0x1); + vperm2f128(v_dst, v_dst, v_dst, 0x1); vperm2f128(ymmOp, ymmOp, ymmOp, 0x1); paddd(xmmDst, xmmOp); - vperm2f128(vDst, vDst, vDst, 0x1); + vperm2f128(v_dst, v_dst, v_dst, 0x1); vperm2f128(ymmOp, ymmOp, ymmOp, 0x1); } else if (op.isMEM()) { const int vlen = x64::cpu_isa_traits::vlen; paddd(xmmDst, op.getAddress()); - vperm2f128(vDst, vDst, vDst, 0x1); + vperm2f128(v_dst, v_dst, v_dst, 0x1); paddd(xmmDst, ptr[op.getAddress().getRegExp() + vlen]); - vperm2f128(vDst, vDst, vDst, 0x1); + vperm2f128(v_dst, v_dst, v_dst, 0x1); } else { IE_THROW() << "Not supported operand type."; } } else if (isValidIsa(x64::sse41)) { - assert(vDst.getIdx() != vSrc.getIdx()); - paddd(vDst, op); + assert(v_dst.getIdx() != v_src.getIdx()); + paddd(v_dst, op); } else { IE_THROW() << "Not defined behavior for instruction 'vpaddd' in current instructions set."; } } -void JitKernelBase::uni_vpsubd(const Xbyak::Ymm& vDst, - const Xbyak::Ymm& vSrc, +void JitKernelBase::uni_vpaddq(const Xbyak::Xmm& v_dst, + const Xbyak::Xmm& v_src, + const Xbyak::Operand& op) { + if (isValidIsa(x64::avx2)) { + vpaddq(v_dst, v_src, op); + } else { + if (v_dst.getIdx() != v_src.getIdx()) { + movups(v_dst, v_src); + } + paddq(v_dst, op); + } +} + +void JitKernelBase::uni_vpsubd(const Xbyak::Ymm& v_dst, + const Xbyak::Ymm& v_src, const Xbyak::Operand& op) { if (isValidIsa(x64::avx2)) { - vpsubd(vDst, vSrc, op); + vpsubd(v_dst, v_src, op); } else if (isValidIsa(x64::avx)) { - Xbyak::Xmm xmmDst(vDst.getIdx()); - vmovups(vDst, vSrc); + Xbyak::Xmm xmmDst(v_dst.getIdx()); + vmovups(v_dst, v_src); if (op.isYMM()) { Xbyak::Ymm ymmOp(op.getIdx()); Xbyak::Xmm xmmOp(op.getIdx()); psubd(xmmDst, xmmOp); - vperm2f128(vDst, vDst, vDst, 0x1); + vperm2f128(v_dst, v_dst, v_dst, 0x1); vperm2f128(ymmOp, ymmOp, ymmOp, 0x1); psubd(xmmDst, xmmOp); - vperm2f128(vDst, vDst, vDst, 0x1); + vperm2f128(v_dst, v_dst, v_dst, 0x1); vperm2f128(ymmOp, ymmOp, ymmOp, 0x1); } else if (op.isMEM()) { const int vlen = x64::cpu_isa_traits::vlen; psubd(xmmDst, op.getAddress()); - vperm2f128(vDst, vDst, vDst, 0x1); + vperm2f128(v_dst, v_dst, v_dst, 0x1); psubd(xmmDst, ptr[op.getAddress().getRegExp() + vlen]); - vperm2f128(vDst, vDst, vDst, 0x1); + vperm2f128(v_dst, v_dst, v_dst, 0x1); } else { IE_THROW() << "Not supported operand type."; } } else if (isValidIsa(x64::sse41)) { - assert(vDst.getIdx() != vSrc.getIdx()); - psubd(vDst, op); + assert(v_dst.getIdx() != v_src.getIdx()); + psubd(v_dst, op); } else { IE_THROW() << "Not defined behavior for instruction 'vpsubd' in current instructions set."; } } -void JitKernelBase::uni_vdivps(const Xbyak::Xmm& vDst, +void JitKernelBase::uni_vsubpd(const Xbyak::Xmm& v_dst, + const Xbyak::Xmm& v_src, + const Xbyak::Operand& op) { + if (isValidIsa(x64::avx)) { + vsubpd(v_dst, v_src, op); + } else { + if (v_dst.getIdx() != v_src.getIdx()) { + movups(v_dst, v_src); + } + subpd(v_dst, op); + } +} + +void JitKernelBase::uni_vmulpd(const Xbyak::Xmm& v_dst, + const Xbyak::Xmm& v_src, + const Xbyak::Operand& op) { + if (isValidIsa(x64::avx)) { + vmulpd(v_dst, v_src, op); + } else { + if (v_dst.getIdx() != v_src.getIdx()) { + movups(v_dst, v_src); + } + mulpd(v_dst, op); + } +} + +void JitKernelBase::uni_vpmuludq(const Xbyak::Xmm& v_dst, + const Xbyak::Xmm& v_src, + const Xbyak::Operand& op) { + if (isValidIsa(x64::avx2)) { + vpmuludq(v_dst, v_src, op); + } else { + if (v_dst.getIdx() != v_src.getIdx()) { + movups(v_dst, v_src); + } + pmuludq(v_dst, op); + } +} + +void JitKernelBase::uni_vdivps(const Xbyak::Xmm& v_dst, const Xbyak::Operand& op1, const Xbyak::Operand& op2) { if (isValidIsa(x64::avx)) { - vdivps(vDst, op1, op2); + vdivps(v_dst, op1, op2); + } else { + if (!v_dst.isEqualIfNotInherited(op1)) { + movups(v_dst, op1); + } + divps(v_dst, op2); + } +} + +void JitKernelBase::uni_vdivpd(const Xbyak::Xmm& v_dst, + const Xbyak::Xmm& v_src, + const Xbyak::Operand& op) { + if (isValidIsa(x64::avx)) { + vdivpd(v_dst, v_src, op); } else { - if (!vDst.isEqualIfNotInherited(op1)) { - movups(vDst, op1); + if (v_dst.getIdx() != v_src.getIdx()) { + movups(v_dst, v_src); } - divps(vDst, op2); + divpd(v_dst, op); } } -void JitKernelBase::uni_vandps(const Xbyak::Xmm& vDst, +void JitKernelBase::uni_vandps(const Xbyak::Xmm& v_dst, const Xbyak::Xmm& vSrs, const Xbyak::Operand &op) { if (isValidIsa(x64::avx)) { - vandps(vDst, vSrs, op); + vandps(v_dst, vSrs, op); } else { - if (!vDst.isEqualIfNotInherited(vSrs)) { - movups(vDst, vSrs); + if (!v_dst.isEqualIfNotInherited(vSrs)) { + movups(v_dst, vSrs); } - andps(vDst, op); + andps(v_dst, op); } } -void JitKernelBase::uni_vandnps(const Xbyak::Xmm& vDst, +void JitKernelBase::uni_vandnps(const Xbyak::Xmm& v_dst, const Xbyak::Xmm& vSrs, const Xbyak::Operand &op) { if (isValidIsa(x64::avx)) { - vandnps(vDst, vSrs, op); + vandnps(v_dst, vSrs, op); } else { - if (!vDst.isEqualIfNotInherited(vSrs)) { - movups(vDst, vSrs); + if (!v_dst.isEqualIfNotInherited(vSrs)) { + movups(v_dst, vSrs); } - andnps(vDst, op); + andnps(v_dst, op); } } -void JitKernelBase::gatherdd(const Xbyak::Xmm& vDst, +void JitKernelBase::gatherdd(const Xbyak::Xmm& v_dst, const Xbyak::Reg64& rSrcPtr, const Xbyak::Xmm& vSrcShift, const Xbyak::Opmask& kReadMask, @@ -178,28 +249,28 @@ void JitKernelBase::gatherdd(const Xbyak::Xmm& vDst, if (!useMask) kxnord(kReadMask, kReadMask, kReadMask); if (zeroFill) - uni_vpxor(vDst, vDst, vDst); + uni_vpxor(v_dst, v_dst, v_dst); - vpgatherdd(vDst | kReadMask, ptr[rSrcPtr + vSrcShift]); + vpgatherdd(v_dst | kReadMask, ptr[rSrcPtr + vSrcShift]); } -void JitKernelBase::gatherdd(const Xbyak::Xmm& vDst, +void JitKernelBase::gatherdd(const Xbyak::Xmm& v_dst, const Xbyak::Reg64& rSrcPtr, const Xbyak::Xmm& vSrcShift, const Xbyak::Xmm& vReadMask, const bool useMask, const bool zeroFill) { - if (vDst.getIdx() == vSrcShift.getIdx() || vDst.getIdx() == vReadMask.getIdx() || vSrcShift.getIdx() == vReadMask.getIdx()) { + if (v_dst.getIdx() == vSrcShift.getIdx() || v_dst.getIdx() == vReadMask.getIdx() || vSrcShift.getIdx() == vReadMask.getIdx()) { IE_THROW() << "Any pair of the index, mask, or destination registers cannot be the same."; } if (zeroFill) - pxor(vDst, vDst); // Don't use vpxor. It zeros the rest of the YMM register. + pxor(v_dst, v_dst); // Don't use vpxor. It zeros the rest of the YMM register. if (isValidIsa(x64::avx2)) { if (!useMask) uni_vpcmpeqd(vReadMask, vReadMask, vReadMask); - vpgatherdd(vDst, ptr[rSrcPtr + vSrcShift], vReadMask); + vpgatherdd(v_dst, ptr[rSrcPtr + vSrcShift], vReadMask); } else { auto rAux = getReg64(); Xbyak::Reg32 r32Aux = Xbyak::Reg32(rAux.getIdx()); @@ -213,7 +284,7 @@ void JitKernelBase::gatherdd(const Xbyak::Xmm& vDst, je(lLoopNext, T_NEAR); } uni_vpextrd(r32Aux, vSrcShift, i); - pinsrd(vDst, ptr[rSrcPtr + rAux], i); + pinsrd(v_dst, ptr[rSrcPtr + rAux], i); if (useMask) L(lLoopNext); @@ -221,30 +292,30 @@ void JitKernelBase::gatherdd(const Xbyak::Xmm& vDst, } } -void JitKernelBase::gatherdd(const Xbyak::Ymm& vDst, +void JitKernelBase::gatherdd(const Xbyak::Ymm& v_dst, const Xbyak::Reg64& rSrcPtr, const Xbyak::Ymm& vSrcShift, const Xbyak::Ymm& vReadMask, const bool useMask, const bool zeroFill) { - if (vDst.getIdx() == vSrcShift.getIdx() || vDst.getIdx() == vReadMask.getIdx() || vSrcShift.getIdx() == vReadMask.getIdx()) { + if (v_dst.getIdx() == vSrcShift.getIdx() || v_dst.getIdx() == vReadMask.getIdx() || vSrcShift.getIdx() == vReadMask.getIdx()) { IE_THROW() << "Any pair of the index, mask, or destination registers cannot be the same."; } if (isValidIsa(x64::avx2)) { if (!useMask) uni_vpcmpeqd(vReadMask, vReadMask, vReadMask); if (zeroFill) - uni_vpxor(vDst, vDst, vDst); + uni_vpxor(v_dst, v_dst, v_dst); - vpgatherdd(vDst, ptr[rSrcPtr + vSrcShift], vReadMask); + vpgatherdd(v_dst, ptr[rSrcPtr + vSrcShift], vReadMask); } else { - Xbyak::Xmm xmmDst = Xbyak::Xmm(vDst.getIdx()), + Xbyak::Xmm xmmDst = Xbyak::Xmm(v_dst.getIdx()), xmmSrcShft = Xbyak::Xmm(vSrcShift.getIdx()), xmmReadMask = Xbyak::Xmm(vReadMask.getIdx()); for (uint8_t i = 0; i < 2; i++) { gatherdd(xmmDst, rSrcPtr, xmmSrcShft, xmmReadMask, useMask, zeroFill); - vperm2f128(vDst, vDst, vDst, 0x1); + vperm2f128(v_dst, v_dst, v_dst, 0x1); vperm2f128(vSrcShift, vSrcShift, vSrcShift, 0x1); if (useMask) vperm2f128(vReadMask, vReadMask, vReadMask, 0x1); @@ -252,6 +323,15 @@ void JitKernelBase::gatherdd(const Xbyak::Ymm& vDst, } } +void JitKernelBase::uni_vpbroadcastq(const Xbyak::Xmm &x, const Xbyak::Operand &op) { + if (isValidIsa(x64::avx2)) { + vpbroadcastq(x, op); + } else { + movsd(x, op); + shufpd(x, x, 0x0); + } +} + void JitKernelBase::uni_vpbroadcastd(const Xbyak::Xmm &x, const Xbyak::Operand &op) { if (isValidIsa(x64::avx2)) { vpbroadcastd(x, op); @@ -285,6 +365,57 @@ void JitKernelBase::uni_vpbroadcastd(const Xbyak::Ymm &x, const Xbyak::Operand & } } +void JitKernelBase::uni_vroundpd(const Xbyak::Xmm& v_dst, const Xbyak::Operand& op, const uint8_t imm) { + if (isValidIsa(x64::avx512_core)) { + vrndscalepd(v_dst, op, imm & 0x3); + } else if (isValidIsa(x64::avx)) { + vroundpd(v_dst, op, imm); + } else { + roundpd(v_dst, op, imm); + } +} + +void JitKernelBase::uni_vcvtdq2pd(const Xbyak::Xmm& v_dst, + const Xbyak::Operand& op) { + if (isValidIsa(x64::avx)) { + vcvtdq2pd(v_dst, op); + } else { + cvtdq2pd(v_dst, op); + } +} + +void JitKernelBase::uni_vcvtpd2dq(const Xbyak::Xmm& v_dst, + const Xbyak::Operand& op) { + if (isValidIsa(x64::avx)) { + vcvtpd2dq(v_dst, op); + } else { + cvtpd2dq(v_dst, op); + } +} + +void JitKernelBase::uni_vpmovzxdq(const Xbyak::Xmm& v_dst, + const Xbyak::Operand& op) { + if (isValidIsa(x64::avx2)) { + vpmovzxdq(v_dst, op); + } else { + pmovzxdq(v_dst, op); + } +} + +void JitKernelBase::uni_vshufpd(const Xbyak::Xmm& v_dst, + const Xbyak::Xmm& v_src, + const Xbyak::Operand& op, + uint8_t imm) { + if (isValidIsa(x64::avx)) { + vshufpd(v_dst, v_src, op, imm); + } else { + if (v_dst.getIdx() != v_src.getIdx()) { + movups(v_dst, v_src); + } + shufpd(v_dst, op, imm); + } +} + void JitKernelBase::fillRestWorkMask(const Xbyak::Opmask& dstMask, const Xbyak::Reg64& rWorkRest) { auto rOnes = getReg64(); @@ -362,7 +493,7 @@ void JitKernelBase::fillRestWorkMask(const Xbyak::Ymm& ymmDstMask, L(lEnd); } -void JitKernelBase::load(const Xbyak::Xmm& vDst, +void JitKernelBase::load(const Xbyak::Xmm& v_dst, const Xbyak::Address& srcAddr, const Xbyak::Reg64& rLoadNum, const size_t typeSize, @@ -373,7 +504,7 @@ void JitKernelBase::load(const Xbyak::Xmm& vDst, const uint8_t elPerVec = x64::cpu_isa_traits::vlen / typeSize; Xbyak::Label lEnd; if (zeroFilling) - pxor(vDst, vDst); + pxor(v_dst, v_dst); for (uint8_t i = 0; i < elPerVec; i++) { cmp(rLoadNum, i); @@ -381,18 +512,18 @@ void JitKernelBase::load(const Xbyak::Xmm& vDst, const size_t offset = i * typeSize; if (typeSize == 1) - pinsrb(vDst, ptr[srcAddr.getRegExp() + offset], i); + pinsrb(v_dst, ptr[srcAddr.getRegExp() + offset], i); else if (typeSize == 2) - pinsrw(vDst, ptr[srcAddr.getRegExp() + offset], i); + pinsrw(v_dst, ptr[srcAddr.getRegExp() + offset], i); else if (typeSize == 4) - pinsrd(vDst, ptr[srcAddr.getRegExp() + offset], i); + pinsrd(v_dst, ptr[srcAddr.getRegExp() + offset], i); else if (typeSize == 8) - pinsrq(vDst, ptr[srcAddr.getRegExp() + offset], i); + pinsrq(v_dst, ptr[srcAddr.getRegExp() + offset], i); } L(lEnd); } -void JitKernelBase::load(const Xbyak::Ymm& vDst, +void JitKernelBase::load(const Xbyak::Ymm& v_dst, const Xbyak::Address& srcAddr, const Xbyak::Reg64& rLoadNum, const size_t typeSize, @@ -403,8 +534,8 @@ void JitKernelBase::load(const Xbyak::Ymm& vDst, const size_t elPerXmm = x64::cpu_isa_traits::vlen / typeSize; Xbyak::Label lEnd; if (zeroFilling) - uni_vpxor(vDst, vDst, vDst); - Xbyak::Xmm xmmDst(vDst.getIdx()); + uni_vpxor(v_dst, v_dst, v_dst); + Xbyak::Xmm xmmDst(v_dst.getIdx()); for (size_t i = 0lu; i < 2lu; i++) { Xbyak::Label lPerm; @@ -427,13 +558,13 @@ void JitKernelBase::load(const Xbyak::Ymm& vDst, } L(lPerm); - vperm2f128(vDst, vDst, vDst, 0x1); + vperm2f128(v_dst, v_dst, v_dst, 0x1); } L(lEnd); } void JitKernelBase::store(const Xbyak::Address& dstAddr, - const Xbyak::Xmm& vSrc, + const Xbyak::Xmm& v_src, const Xbyak::Reg64& rToStoreNum, const size_t typeSize) { if (!one_of(typeSize, 1u, 2u, 4u, 8u)) { @@ -448,27 +579,27 @@ void JitKernelBase::store(const Xbyak::Address& dstAddr, const size_t offset = i * typeSize; if (typeSize == 1) { - uni_vpextrb(ptr[dstAddr.getRegExp() + offset], vSrc, i); + uni_vpextrb(ptr[dstAddr.getRegExp() + offset], v_src, i); } else if (typeSize == 2) { - uni_vpextrw(ptr[dstAddr.getRegExp() + offset], vSrc, i); + uni_vpextrw(ptr[dstAddr.getRegExp() + offset], v_src, i); } else if (typeSize == 4) { - uni_vpextrd(ptr[dstAddr.getRegExp() + offset], vSrc, i); + uni_vpextrd(ptr[dstAddr.getRegExp() + offset], v_src, i); } else if (typeSize == 8) { - uni_vpextrq(ptr[dstAddr.getRegExp() + offset], vSrc, i); + uni_vpextrq(ptr[dstAddr.getRegExp() + offset], v_src, i); } } L(lEnd); } void JitKernelBase::store(const Xbyak::Address& dstAddr, - const Xbyak::Ymm& vSrc, + const Xbyak::Ymm& v_src, const Xbyak::Reg64& rToStoreNum, const size_t typeSize) { if (!one_of(typeSize, 1u, 2u, 4u, 8u)) { IE_THROW() << "Could not store data with type size " << typeSize; } Xbyak::Label lEnd; - Xbyak::Xmm xmmSrc(vSrc.getIdx()); + Xbyak::Xmm xmmSrc(v_src.getIdx()); const size_t elPerXmm = x64::cpu_isa_traits::vlen / typeSize; for (int i = 0; i < 2; i++) { @@ -493,7 +624,7 @@ void JitKernelBase::store(const Xbyak::Address& dstAddr, } L(lPerm); - vperm2f128(vSrc, vSrc, vSrc, 0x1); + vperm2f128(v_src, v_src, v_src, 0x1); } L(lEnd); } @@ -575,3 +706,7 @@ void JitKernelBase::memMovDD(const Xbyak::Reg64& rDst, } L(lEnd); } + +} // namespace kernel +} // namespace intel_cpu +} // namespace ov diff --git a/src/plugins/intel_cpu/src/nodes/kernels/x64/jit_kernel_base.hpp b/src/plugins/intel_cpu/src/nodes/kernels/x64/jit_kernel_base.hpp index e39efde753bbbc..f17eb9a02d8771 100644 --- a/src/plugins/intel_cpu/src/nodes/kernels/x64/jit_kernel_base.hpp +++ b/src/plugins/intel_cpu/src/nodes/kernels/x64/jit_kernel_base.hpp @@ -1,14 +1,23 @@ -// Copyright (C) 2022 Intel Corporation +// Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // #pragma once +#include "openvino/core/visibility.hpp" + +#if defined(OPENVINO_ARCH_X86_64) #include "cpu/x64/jit_generator.hpp" #include "registers_pool.hpp" +#endif // OPENVINO_ARCH_X86_64 namespace ov { namespace intel_cpu { +namespace kernel { + +class JitKernelBase; + +#if defined(OPENVINO_ARCH_X86_64) #define getReg64() RegistersPool::Reg(registersPool) #define getReg32() RegistersPool::Reg(registersPool) @@ -17,7 +26,11 @@ namespace intel_cpu { class JitKernelBase: public dnnl::impl::cpu::x64::jit_generator { public: - JitKernelBase(const char* name) : dnnl::impl::cpu::x64::jit_generator(name) {} + JitKernelBase(const char* name, dnnl::impl::cpu::x64::cpu_isa_t max_cpu_isa); + + dnnl::impl::cpu::x64::cpu_isa_t getIsa() { return m_isa; } + + size_t getVectorLen() { return vlen; } void uni_vfmsub132ps(const Xbyak::Xmm& vDst, const Xbyak::Xmm& vSrc, const Xbyak::Operand& op); @@ -31,14 +44,24 @@ class JitKernelBase: public dnnl::impl::cpu::x64::jit_generator { void uni_vpaddd(const Xbyak::Ymm& vDst, const Xbyak::Ymm& vSrc, const Xbyak::Operand& op); + void uni_vpaddq(const Xbyak::Xmm& vDst, const Xbyak::Xmm& vSrc, const Xbyak::Operand& op); + void uni_vpsubd(const Xbyak::Xmm& vDst, const Xbyak::Xmm& vSrc, const Xbyak::Operand& op) { jit_generator::uni_vpsubd(vDst, vSrc, op); } void uni_vpsubd(const Xbyak::Ymm& vDst, const Xbyak::Ymm& vSrc, const Xbyak::Operand& op); + void uni_vsubpd(const Xbyak::Xmm& v_dst, const Xbyak::Xmm& v_src, const Xbyak::Operand& op); + + void uni_vmulpd(const Xbyak::Xmm& v_dst, const Xbyak::Xmm& v_src, const Xbyak::Operand& op); + + void uni_vpmuludq(const Xbyak::Xmm& v_dst, const Xbyak::Xmm& op_1, const Xbyak::Operand& op_2); + void uni_vdivps(const Xbyak::Xmm& vDst, const Xbyak::Operand& op1, const Xbyak::Operand& op2); + void uni_vdivpd(const Xbyak::Xmm& v_dst, const Xbyak::Xmm& v_src, const Xbyak::Operand& op2); + void uni_vandps(const Xbyak::Xmm& vDst, const Xbyak::Xmm& vSrs, const Xbyak::Operand &op); void uni_vandnps(const Xbyak::Xmm& vDst, const Xbyak::Xmm& vSrs, const Xbyak::Operand &op); @@ -63,6 +86,18 @@ class JitKernelBase: public dnnl::impl::cpu::x64::jit_generator { void uni_vpbroadcastd(const Xbyak::Ymm &x, const Xbyak::Operand &op); + void uni_vpbroadcastq(const Xbyak::Xmm &x, const Xbyak::Operand &op); + + void uni_vroundpd(const Xbyak::Xmm& v_dst, const Xbyak::Operand& op, const uint8_t imm); + + void uni_vcvtdq2pd(const Xbyak::Xmm& v_dst, const Xbyak::Operand& op); + + void uni_vcvtpd2dq(const Xbyak::Xmm& v_dst, const Xbyak::Operand& op); + + void uni_vpmovzxdq(const Xbyak::Xmm& v_dst, const Xbyak::Operand& op); + + void uni_vshufpd(const Xbyak::Xmm& v_dst, const Xbyak::Xmm& v_srs, const Xbyak::Operand& op, uint8_t imm); + void gatherdd(const Xbyak::Xmm& vDst, const Xbyak::Reg64& rSrcPtr, const Xbyak::Xmm& vSrcShift, @@ -140,7 +175,9 @@ class JitKernelBase: public dnnl::impl::cpu::x64::jit_generator { return dnnl::impl::cpu::x64::mayiuse(isa); } + const dnnl::impl::cpu::x64::cpu_isa_t m_isa; RegistersPool::Ptr registersPool; + size_t vlen; enum { // Comparison predicate operand (immediate byte) for single-precision floating-point values. @@ -155,5 +192,70 @@ class JitKernelBase: public dnnl::impl::cpu::x64::jit_generator { }; }; +template +class JitKernel : public JitKernelBase { +public: + using KernelFunc = void (*)(const CallArgs *); + + explicit JitKernel(const char* name, const CompileParams& jcp, dnnl::impl::cpu::x64::cpu_isa_t max_cpu_isa) + : JitKernelBase{name, max_cpu_isa}, m_jcp{jcp}, m_func{nullptr} {} + + ~JitKernel() override = default; + + dnnl::impl::status_t create_kernel() override { + const dnnl::impl::status_t code = jit_generator::create_kernel(); + if (code != dnnl::impl::status::success) { + OPENVINO_THROW("Could not create kernel. Error code: ", std::to_string(code), ". ", + "Xbyak error code: ", Xbyak::ConvertErrorToString(Xbyak::GetError())); + } + m_func = (decltype(m_func))jit_ker(); + return code; + } + + void operator()(const CallArgs* args) const { + assert(m_func); + m_func(args); + } + + void operator()(const CallArgs& args) const { + this->operator()(&args); + } + + template class KernelT> + static std::shared_ptr> createInstance(const CompileParams& jcp) { + std::shared_ptr> res; + + try { +#define IF_ISA_CASE(ISA) \ + if (dnnl::impl::cpu::x64::mayiuse(ISA)) \ + res.reset(new KernelT(jcp)); \ + else + + IF_ISA_CASE(dnnl::impl::cpu::x64::avx512_core) + IF_ISA_CASE(dnnl::impl::cpu::x64::avx2) + IF_ISA_CASE(dnnl::impl::cpu::x64::sse41); + +#undef IF_ISA_CASE + + if (res) { + res->create_kernel(); + } + } catch (...) { + return nullptr; + } + + return res; + } + +protected: + CompileParams m_jcp; + +private: + KernelFunc m_func; +}; + +#endif // OPENVINO_ARCH_X86_64 + +} // namespace kernel } // namespace intel_cpu } // namespace ov diff --git a/src/plugins/intel_cpu/src/nodes/kernels/x64/random_uniform.cpp b/src/plugins/intel_cpu/src/nodes/kernels/x64/random_uniform.cpp new file mode 100644 index 00000000000000..301c2f7e08ff69 --- /dev/null +++ b/src/plugins/intel_cpu/src/nodes/kernels/x64/random_uniform.cpp @@ -0,0 +1,635 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "random_uniform.hpp" + +using namespace dnnl::impl::cpu; + +namespace ov { +namespace intel_cpu { +namespace kernel { + +#define GET_OFF(field) offsetof(RandomUniformCallArgs, field) + +template +RandomUniform::RandomUniform(const RandomUniformCompileParams& jcp) : + JitKernel(jit_name(), jcp, isa) { +} + +template +void RandomUniform::generate() { + this->preamble(); + registersPool = RegistersPool::create(isa, {rax, rcx, rsp, rdi, k0}); + + r64_dst = getReg64(); + r64_work_amount = getReg64(); + + mov(r64_work_amount, ptr[r64_params + GET_OFF(work_amount)]); + mov(r64_dst, ptr[r64_params + GET_OFF(dst_ptr)]); + + initVectors(); + process(); + + registersPool.reset(); + this->postamble(); +} + +template <> +void RandomUniform::initVectors() { + const auto r64_aux = getReg64(); + const auto r32_aux = Xbyak::Reg32(r64_aux.getIdx()); + const auto r16_aux = Xbyak::Reg16(r64_aux.getIdx()); + + v_max_mul_n_64 = getVmm(); + v_max_mul_c_64 = getVmm(); + v_add_low_k = getVmm(); + v_add_up_k = getVmm(); + v_n_inc = getVmm(); + v_range = getVmm(); + v_min = getVmm(); + v_key_64 = getVmm(); + v_counter_64 = getVmm(); + v_n_64 = getVmm(); + v_res_perm = getVmm(); + + if (m_jcp.out_data_type.is_real()) { + v_convert_0 = getVmm(); + v_convert_1 = getVmm(); + } + + // Initialize constants. +#define BROADCAST_R(F, V, R, C) \ + mov(R, C); \ + F(V, R); +#define BROADCAST_P(F, V, R, C) \ + mov(R, ptr[r64_params + GET_OFF(C)]); \ + F(V, ptr[R]); + + BROADCAST_R(vpbroadcastq, v_max_mul_n_64, r64_aux, STATISTIC_MAXIMIZING_MULTIPLIER_N) + BROADCAST_R(vpbroadcastq, v_max_mul_c_64, r64_aux, STATISTIC_MAXIMIZING_MULTIPLIER_COUNTER) + BROADCAST_R(vpbroadcastd, v_add_low_k, r32_aux, CRUSH_RESISTANCE_CONST_LOWER_VALUE) + BROADCAST_R(vpbroadcastd, v_add_up_k, r32_aux, CRUSH_RESISTANCE_CONST_UPPER_VALUE) + BROADCAST_R(vpbroadcastq, v_n_inc, r64_aux, 0x00000008) + + if (m_jcp.out_data_type == element::f32) { + BROADCAST_R(vpbroadcastd, v_convert_0, r32_aux, 0x3f800000) + BROADCAST_R(vpbroadcastd, v_convert_1, r32_aux, 0x007fffff) + BROADCAST_P(vpbroadcastd, v_range, r64_aux, range_ptr) + BROADCAST_P(vpbroadcastd, v_min, r64_aux, min_ptr) + } else if (m_jcp.out_data_type == element::f16 && x64::mayiuse(x64::avx512_core_fp16)) { + BROADCAST_R(vpbroadcastw, v_convert_0, r16_aux, 0x3c00) + BROADCAST_R(vpbroadcastw, v_convert_1, r16_aux, 0x03ff) + BROADCAST_P(vpbroadcastw, v_range, r64_aux, range_ptr) + BROADCAST_P(vpbroadcastw, v_min, r64_aux, min_ptr) + } else if (m_jcp.out_data_type == element::bf16 && x64::mayiuse(x64::avx512_core_bf16)) { + v_convert_2 = getVmm(); + const auto ymm_min = Xbyak::Ymm(v_min.getIdx()); + const auto ymm_range = Xbyak::Ymm(v_range.getIdx()); + + BROADCAST_R(vpbroadcastw, v_convert_0, r16_aux, 0x3f80) + BROADCAST_R(vpbroadcastw, v_convert_1, r16_aux, 0x007f) + BROADCAST_R(vpbroadcastd, v_convert_2, r32_aux, 0x3f800000) + + BROADCAST_P(vpbroadcastw, v_range, r64_aux, range_ptr) + vpmovzxwd(v_range, ymm_range); + uni_vpslld(v_range, v_range, 16); + + BROADCAST_P(vpbroadcastw, v_min, r64_aux, min_ptr) + vpmovzxwd(v_min, ymm_min); + uni_vpslld(v_min, v_min, 16); + } else if (m_jcp.out_data_type == element::i32) { + const auto ymm_range = Xbyak::Ymm(v_range.getIdx()); + + BROADCAST_P(vpbroadcastd, v_range, r64_aux, range_ptr) + BROADCAST_P(vpbroadcastd, v_min, r64_aux, min_ptr) + + uni_vcvtdq2pd(v_range, ymm_range); + } else { + OPENVINO_THROW("RandomUniform kernel does not support precision ", m_jcp.out_data_type, " for ", x64::get_isa_info()); + } + + // Initialize inputs. + BROADCAST_P(vpbroadcastq, v_key_64, r64_aux, key_ptr) + BROADCAST_P(vpbroadcastq, v_counter_64, r64_aux, counter_ptr) + BROADCAST_P(vpbroadcastq, v_n_64, r64_aux, n_ptr) + + if (m_jcp.out_data_type.size() <= 4) { + static const uint64_t n_inc_arr[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; + mov(r64_aux, reinterpret_cast(n_inc_arr)); + } else { + static const uint64_t n_inc_arr[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; // TODO: i64 + mov(r64_aux, reinterpret_cast(n_inc_arr)); + } + uni_vpaddq(v_n_64, v_n_64, ptr[r64_aux]); + + // Initialize auxiliary vectors. + static const uint32_t res_perm_mask[16] = { 0b00000000, 0b00010000, 0b00001000, 0b00011000, 0b00000010, 0b00010010, 0b00001010, 0b00011010, + 0b00000100, 0b00010100, 0b00001100, 0b00011100, 0b00000110, 0b00010110, 0b00001110, 0b00011110 }; + mov(r64_aux, reinterpret_cast(res_perm_mask)); + uni_vmovups(v_res_perm, ptr[r64_aux]); + + if (m_jcp.out_data_type == element::f16 && x64::mayiuse(x64::avx512_core_fp16)) { + v_perm_16 = getVmm(); + static const uint16_t perm_16[32] = { 0b00000000, 0b00000010, 0b00000100, 0b00000110, 0b00001000, 0b00001010, 0b00001100, 0b00001110, + 0b00010000, 0b00010010, 0b00010100, 0b00010110, 0b00011000, 0b00011010, 0b00011100, 0b00011110, + 0b00100000, 0b00100010, 0b00100100, 0b00100110, 0b00101000, 0b00101010, 0b00101100, 0b00101110, + 0b00110000, 0b00110010, 0b00110100, 0b00110110, 0b00111000, 0b00111010, 0b00111100, 0b00111110 }; + mov(r64_aux, reinterpret_cast(perm_16)); + uni_vmovups(v_perm_16, ptr[r64_aux]); + } + +#undef BROADCAST_R +#undef BROADCAST_P +} + +template // Works for AVX2, SSE41 +void RandomUniform::initVectors() { + const auto r64_aux = getReg64(); + + v_max_mul_n_64 = getVmm(); + v_max_mul_c_64 = getVmm(); + v_add_low_k = getVmm(); + v_add_up_k = getVmm(); + v_range = getVmm(); + v_key_64 = getVmm(); + v_counter_64 = getVmm(); + v_n_64 = getVmm(); + + r64_n_inc = getReg64(); + r64_min = getReg64(); + +#define INIT_ARR(A, V, R, T) \ + static const T A[8] = { V, V, V, V, V, V, V, V }; \ + if (isa == x64::avx2) { \ + mov(R, reinterpret_cast(A)); \ + } else { \ + static const T* A##_aligned = A + (reinterpret_cast(A) % 16) / sizeof(T); \ + mov(R, reinterpret_cast(A##_aligned)); \ + } + + // Initialize constants. + INIT_ARR(max_mul_n_64, STATISTIC_MAXIMIZING_MULTIPLIER_N, r64_aux, uint64_t); + uni_vmovups(v_max_mul_n_64, ptr[r64_aux]); + + INIT_ARR(max_mul_c_64, STATISTIC_MAXIMIZING_MULTIPLIER_COUNTER, r64_aux, uint64_t); + uni_vmovups(v_max_mul_c_64, ptr[r64_aux]); + + INIT_ARR(add_low_k, CRUSH_RESISTANCE_CONST_LOWER_VALUE, r64_aux, uint32_t); + uni_vmovups(v_add_low_k, ptr[r64_aux]); + + INIT_ARR(add_up_k, CRUSH_RESISTANCE_CONST_UPPER_VALUE, r64_aux, uint32_t); + uni_vmovups(v_add_up_k, ptr[r64_aux]); + + INIT_ARR(n_inc_step, isa == x64::avx2 ? 4 : 2, r64_n_inc, uint64_t); + + if (m_jcp.out_data_type == element::f32) { + r64_convert_0 = getReg64(); + r64_convert_1 = getReg64(); + + INIT_ARR(convert_0, 0x3f800000, r64_convert_0, uint32_t); + INIT_ARR(convert_1, 0x007fffff, r64_convert_1, uint32_t); + + mov(r64_aux, ptr[r64_params + GET_OFF(range_ptr)]); + uni_vpbroadcastd(v_range, ptr[r64_aux]); + + auto v_aux = getVmm(); + mov(r64_aux, ptr[r64_params + GET_OFF(min_ptr)]); + uni_vpbroadcastd(v_aux, ptr[r64_aux]); + static uint32_t min_arr[8]; + mov(r64_min, reinterpret_cast(min_arr)); + uni_vmovups(ptr[r64_min], v_aux); + } else if (m_jcp.out_data_type == element::i32) { + r64_f64_pow_52 = getReg64(); + const auto v_aux = getVmm(); + const auto xmm_range = Xbyak::Xmm(v_range.getIdx()); + + INIT_ARR(f64_pow_52, 0x4330000000000000, r64_f64_pow_52, uint64_t); + + mov(r64_aux, ptr[r64_params + GET_OFF(range_ptr)]); + uni_vpbroadcastd(v_range, ptr[r64_aux]); + + mov(r64_aux, ptr[r64_params + GET_OFF(min_ptr)]); + uni_vpbroadcastd(v_aux, ptr[r64_aux]); + static uint32_t min_arr[8]; + mov(r64_min, reinterpret_cast(min_arr)); + uni_vmovups(ptr[r64_min], v_aux); + + uni_vcvtdq2pd(v_range, xmm_range); + } else { + OPENVINO_THROW("RandomUniform kernel does not support precision ", m_jcp.out_data_type, " for ", x64::get_isa_info()); + } + + // Initialize inputs. + mov(r64_aux, ptr[r64_params + GET_OFF(key_ptr)]); + uni_vpbroadcastq(v_key_64, ptr[r64_aux]); + + mov(r64_aux, ptr[r64_params + GET_OFF(counter_ptr)]); + uni_vpbroadcastq(v_counter_64, ptr[r64_aux]); + + mov(r64_aux, ptr[r64_params + GET_OFF(n_ptr)]); + uni_vpbroadcastq(v_n_64, ptr[r64_aux]); + + if (m_jcp.out_data_type.size() <= 4) { + if (isa == x64::avx2) { + static const uint64_t n_inc_arr[4] = { 0, 1, 2, 3 }; + mov(r64_aux, reinterpret_cast(n_inc_arr)); + } else { + static uint64_t n_inc_arr[4]; + static uint64_t* n_inc_arr_aligned = n_inc_arr + (reinterpret_cast(n_inc_arr) % 16) / sizeof(uint64_t); + n_inc_arr_aligned[0] = 0; + n_inc_arr_aligned[1] = 1; + mov(r64_aux, reinterpret_cast(n_inc_arr_aligned)); + } + } else { + static const uint64_t n_inc_arr[4] = { 0, 1, 2, 3 }; // TODO: i64 + mov(r64_aux, reinterpret_cast(n_inc_arr)); + } + + uni_vpaddq(v_n_64, v_n_64, ptr[r64_aux]); + +#undef INIT_ARR +} + +template +void RandomUniform::process() { + auto v_dst_0 = getVmm(); + auto v_dst_1 = getVmm(); + std::vector v_res{ v_dst_0, v_dst_1 }; + + auto step = vlen; + if (one_of(m_jcp.out_data_type.size(), 2lu, 4lu)) { + step = vlen * 2 / sizeof(uint32_t); + } else if (m_jcp.out_data_type.size() == 8) { + step = vlen / sizeof(uint32_t); + } + + Xbyak::Label l_loop, l_tail; + L(l_loop); { + cmp(r64_work_amount, step); + jl(l_tail, T_NEAR); + + runPhilox(v_res, v_key_64, v_counter_64, v_n_64); + convert(v_res, v_res); + + uni_vmovups(ptr[r64_dst], v_dst_0); + add(r64_dst, vlen); + if (one_of(m_jcp.out_data_type.size(), 4lu, 8lu)) { + uni_vmovups(ptr[r64_dst], v_dst_1); + add(r64_dst, vlen); + } + + if (isa == x64::avx512_core) { + uni_vpaddd(v_n_64, v_n_64, v_n_inc); + } else { + uni_vpaddd(v_n_64, v_n_64, ptr[r64_n_inc]); + } + + sub(r64_work_amount, step); + jmp(l_loop, T_NEAR); + } + + L(l_tail); + tail(v_res); +} + +template +void RandomUniform::calculateRound(const Vmm& vmm_k_0, const Vmm& vmm_k_1, const Vmm& vmm_c_0, const Vmm& vmm_c_1, + const Vmm& vmm_n_0, const Vmm& vmm_n_1, const Vmm& vmm_aux_0, const Vmm& vmm_aux_1) { + uni_vpmuludq(vmm_aux_0, vmm_n_0, v_max_mul_n_64); // {p0,p1,p0,p1} = {n0,_,n0,_} * {m0,_,m0,_} + uni_vpmuludq(vmm_aux_1, vmm_c_0, v_max_mul_c_64); // {r0,r1,r0,r1} = {c0,_,c0,_} * {m0,_,m0,_} + + uni_vpshufd(vmm_c_0, vmm_aux_0, 0b10110001); // {p1,p0,p1,p0} = shuf {p0,p1,p0,p1} + uni_vxorps(vmm_c_0, vmm_c_0, vmm_c_1); // {c0,_,c0,_} = {p1,_,p1,_} ^ {c1,_,c1,_} + uni_vxorps(vmm_c_0, vmm_c_0, vmm_k_1); // {c0,_,c0,_} = {c0,_,c0,_} ^ {k1,_,k1,_} + + uni_vpshufd(vmm_n_0, vmm_aux_1, 0b10110001); // {r1,r0,r1,r0} = shuf {r0,r1,r0,r1} + uni_vxorps(vmm_n_0, vmm_n_0, vmm_n_1); // {n0,_,n0,_} = {r1,_,r1,_} ^ {n1,_,n1,_} + uni_vxorps(vmm_n_0, vmm_n_0, vmm_k_0); // {n0,_,n0,_} = {n0,_,n0,_} ^ {k0,_,k0,_} +} + +template +void RandomUniform::runPhilox(const std::vector& vmm_dst, const Vmm& vmm_key, const Vmm& vmm_counter, const Vmm& vmm_n) { + auto vmm_k_0 = getVmm(); + auto vmm_k_1 = getVmm(); + auto vmm_n_0 = getVmm(); + auto vmm_n_1 = vmm_dst[0]; + auto vmm_c_0 = getVmm(); + auto vmm_c_1 = getVmm(); + auto vmm_aux_0 = getVmm(); + auto vmm_aux_1 = vmm_dst[1]; + + uni_vmovups(vmm_k_0, vmm_key); // {k0,k1,k0,k1} -> {k0,_,k0,_} + uni_vpshufd(vmm_k_1, vmm_key, 0b10110001); // {k0,k1,k0,k1} -> {k1,_,k1,_} + + uni_vpmuludq(vmm_aux_0, vmm_n, v_max_mul_n_64); // {p0,p1,p0,p1} = {n0,_,n0,_} * {m0,_,m0,_} + uni_vpmuludq(vmm_aux_1, vmm_counter, v_max_mul_c_64); // {r0,r1,r0,r1} = {c0,_,c0,_} * {m0,_,m0,_} + + uni_vxorps(vmm_c_0, vmm_aux_0, vmm_counter); // {_,c0,_,c0} = {_,p1,_,p1} ^ {_,c1,_,c1} + uni_vxorps(vmm_c_0, vmm_c_0, vmm_key); // {_,c0,_,c0} = {_,c0,_,c0} ^ {_,k1,_,k1} + uni_vpshufd(vmm_c_0, vmm_c_0, 0b10110001); // {_,c0,_,c0} -> {c0,_,c0,_} + + uni_vxorps(vmm_n_0, vmm_aux_1, vmm_n); // {_,n0,_,n0} = {_,r1,_,r1} ^ {_,n1,_,n1} + uni_vpshufd(vmm_n_0, vmm_n_0, 0b10110001); // {_,n0,_,n0} -> {n0,_,n0,_} + uni_vxorps(vmm_n_0, vmm_n_0, vmm_key); // {n0,_,n0,_} = {n0,_,n0,_} ^ {k0,_,k0,_} + + for (size_t i = 0lu; i < ROUNDS_NUMBER - 1; i++) { + raiseKey(vmm_k_0, vmm_k_1); + + std::swap(vmm_c_1, vmm_aux_0); + std::swap(vmm_n_1, vmm_aux_1); + calculateRound(vmm_k_0, vmm_k_1, vmm_c_0, vmm_c_1, vmm_n_0, vmm_n_1, vmm_aux_0, vmm_aux_1); + } + std::swap(vmm_c_1, vmm_aux_0); + std::swap(vmm_n_1, vmm_aux_1); + + if (isa == x64::avx512_core) { + vpermt2d(vmm_n_0, v_res_perm, vmm_n_1); // {n0,n1,n0,n1} = perm {n0,_,n0,_} {n1,_,n1,_} + vpermt2d(vmm_c_0, v_res_perm, vmm_c_1); // {c0,c1,c0,c1} = perm {c0,_,c0,_} {c1,_,c1,_} + vshufpd(vmm_dst[0], vmm_n_0, vmm_c_0, 0b00000000); // {n0,n1,c0,c1} = shuf {n0,n1,n0,n1} {c0,c1,c0,c1} + vshufpd(vmm_dst[1], vmm_n_0, vmm_c_0, 0b11111111); // {n0,n1,c0,c1} = shuf {n0,n1,n0,n1} {c0,c1,c0,c1} + } else if (isa == x64::avx2) { + auto ymm_dst_0 = Xbyak::Ymm(vmm_dst[0].getIdx()); + auto ymm_dst_1 = Xbyak::Ymm(vmm_dst[1].getIdx()); + auto ymm_c_0 = Xbyak::Ymm(vmm_c_0.getIdx()); + + uni_vshufps(vmm_n_0, vmm_n_0, vmm_n_1, 0b10001000); // {n0,n0,n1,n1} = shuf {n0,_,n0,_} {n1,_,n1,_} + uni_vshufps(vmm_c_0, vmm_c_0, vmm_c_1, 0b10001000); // {c0,c0,c1,c1} = shuf {c0,_,c0,_} {c1,_,c1,_} + uni_vshufps(ymm_dst_1, vmm_n_0, vmm_c_0, 0b10001000); // {n0,n1,c0,c1} = shuf {n0,n0,n1,n1} {c0,c0,c1,c1} + uni_vshufps(vmm_c_0, vmm_n_0, vmm_c_0, 0b11011101); // {n0,n1,c0,c1} = shuf {n0,n0,n1,n1} {c0,c0,c1,c1} + vperm2f128(ymm_dst_0, ymm_dst_1, ymm_c_0, 0b00100000); + vperm2f128(ymm_dst_1, ymm_dst_1, ymm_c_0, 0b00110001); + } else { + uni_vshufps(vmm_n_0, vmm_n_0, vmm_n_1, 0b10001000); + uni_vshufps(vmm_c_0, vmm_c_0, vmm_c_1, 0b10001000); + uni_vshufps(vmm_dst[0], vmm_n_0, vmm_c_0, 0b10001000); + uni_vshufps(vmm_dst[1], vmm_n_0, vmm_c_0, 0b11011101); + } +} + +template +void RandomUniform::raiseKey(const Vmm& vmm_k_0, const Vmm& vmm_k_1) { + uni_vpaddd(vmm_k_0, vmm_k_0, v_add_low_k); // {k0,_,k0,_} + {l0,_,l0,_} + uni_vpaddd(vmm_k_1, vmm_k_1, v_add_up_k); // {k1,_,k1,_} + {u0,_,u0,_} +} + +template <> +void RandomUniform::convert(const std::vector& v_dst, const std::vector& v_src) { + if (m_jcp.out_data_type.size() == 4) { + for (size_t i = 0lu; i < v_src.size(); i++) { + const auto& vmm_src = v_src[i]; + const auto& vmm_dst = v_dst[i]; + + if (m_jcp.out_data_type == element::f32) { + uni_vandps(vmm_dst, vmm_src, v_convert_1); + uni_vorps(vmm_dst, vmm_dst, v_convert_0); + uni_vsubps(vmm_dst, vmm_dst, v_convert_0); + vfmadd132ps(vmm_dst, v_min, v_range); + } else if (m_jcp.out_data_type == element::i32) { + // x % (max - min) + min + const auto v_aux_0 = getVmm(); + const auto v_aux_1 = getVmm(); + const auto ymm_src = Xbyak::Ymm(vmm_src.getIdx()); + const auto ymm_dst = Xbyak::Ymm(vmm_dst.getIdx()); + const auto ymm_aux_1 = Xbyak::Ymm(v_aux_1.getIdx()); + + // Divide in the f64 due to the f32 loses accuracy here. + vcvtudq2pd(v_aux_0, ymm_src); + uni_vdivpd(v_aux_1, v_aux_0, v_range); + uni_vroundpd(v_aux_1, v_aux_1, 3); + vfnmadd132pd(v_aux_1, v_aux_0, v_range); + + vextractf64x4(ymm_dst, vmm_src, 1); + vcvtudq2pd(v_aux_0, ymm_dst); + uni_vcvtpd2dq(ymm_dst, v_aux_1); + uni_vdivpd(v_aux_1, v_aux_0, v_range); + uni_vroundpd(v_aux_1, v_aux_1, 3); + vfnmadd132pd(v_aux_1, v_aux_0, v_range); + uni_vcvtpd2dq(ymm_aux_1, v_aux_1); + vshuff64x2(vmm_dst, vmm_dst, v_aux_1, 0b01000100); + + uni_vpaddd(vmm_dst, vmm_dst, v_min); + } else { + OPENVINO_THROW("RandomUniform kernel does not support precision ", m_jcp.out_data_type, " for ", x64::get_isa_info()); + } + } + } else if (m_jcp.out_data_type.size() == 2) { + if (m_jcp.out_data_type == element::f16 && x64::mayiuse(x64::avx512_core_fp16)) { + const auto& vmm_dst = v_dst[0]; + + if (v_src[0].getIdx() != vmm_dst.getIdx()) { + uni_vmovups(vmm_dst, v_src[0]); + } + vpermt2w(vmm_dst, v_perm_16, v_src[1]); + + uni_vandps(vmm_dst, vmm_dst, v_convert_1); + uni_vorps(vmm_dst, vmm_dst, v_convert_0); + vsubph(vmm_dst, vmm_dst, v_convert_0); + vfmadd132ph(vmm_dst, v_min, v_range); + } else if (m_jcp.out_data_type == element::bf16 && x64::mayiuse(x64::avx512_core_bf16)) { + for (size_t i = 0lu; i < v_src.size(); i++) { + const auto& vmm_dst = v_dst[i]; + + uni_vandps(vmm_dst, v_src[i], v_convert_1); + uni_vorps(vmm_dst, vmm_dst, v_convert_0); + uni_vpslld(vmm_dst, vmm_dst, 16); + + uni_vsubps(vmm_dst, vmm_dst, v_convert_2); + vfmadd132ps(vmm_dst, v_min, v_range); + } + + vcvtne2ps2bf16(v_dst[0], v_dst[1], v_dst[0]); + } else { + OPENVINO_THROW("RandomUniform kernel does not support precision ", m_jcp.out_data_type, " for ", x64::get_isa_info()); + } + } else if (m_jcp.out_data_type.size() == 8) { + if (m_jcp.out_data_type == element::i64) { + // TODO: in scope of i64 enabling. + } + OPENVINO_THROW("RandomUniform kernel does not support precision ", m_jcp.out_data_type, " for ", x64::get_isa_info()); + } else { + OPENVINO_THROW("RandomUniform kernel does not support precision ", m_jcp.out_data_type, " for ", x64::get_isa_info()); + } +} + +template // Works for AVX2, SSE41 +void RandomUniform::convert(const std::vector& v_dst, const std::vector& v_src) { + if (m_jcp.out_data_type.size() == 4) { + for (size_t i = 0lu; i < v_src.size(); i++) { + auto vmm_src = v_src[i]; + auto vmm_dst = v_dst[i]; + + if (m_jcp.out_data_type == element::f32) { + uni_vandps(vmm_dst, vmm_src, ptr[r64_convert_1]); + uni_vorps(vmm_dst, vmm_dst, ptr[r64_convert_0]); + uni_vsubps(vmm_dst, vmm_dst, ptr[r64_convert_0]); + if (isa == x64::avx2) { + vfmadd213ps(vmm_dst, v_range, ptr[r64_min]); + } else { + uni_vmulps(vmm_dst, vmm_dst, v_range); + uni_vaddps(vmm_dst, vmm_dst, ptr[r64_min]); + } + } else if (m_jcp.out_data_type == element::i32) { + // x % (max - min) + min + const auto v_aux_0 = getVmm(); + const auto v_aux_1 = getVmm(); + const auto xmm_dst = Xbyak::Xmm(vmm_dst.getIdx()); + const auto ymm_dst = Xbyak::Ymm(vmm_dst.getIdx()); + const auto xmm_aux_1 = Xbyak::Xmm(v_aux_1.getIdx()); + + // Convert u32->f64. TODO: move to convert emitter after i64 enabling. + uni_vpmovzxdq(v_aux_0, xmm_dst); + uni_vorps(v_aux_0, v_aux_0, ptr[r64_f64_pow_52]); + uni_vsubpd(v_aux_0, v_aux_0, ptr[r64_f64_pow_52]); + + // Divide in the f64 due to the f32 loses accuracy here. + uni_vdivpd(v_aux_1, v_aux_0, v_range); + uni_vroundpd(v_aux_1, v_aux_1, 3); + if (isa == x64::avx2) { + vfnmadd132pd(v_aux_1, v_aux_0, v_range); + } else { + uni_vmulpd(v_aux_1, v_aux_1, v_range); + uni_vsubpd(v_aux_0, v_aux_0, v_aux_1); + uni_vmovups(v_aux_1, v_aux_0); + } + + if (isa == x64::avx2) { + vperm2f128(ymm_dst, ymm_dst, ymm_dst, 0b00000001); + } else { + uni_vshufpd(vmm_dst, vmm_dst, vmm_dst, 0b00000001); + } + // Convert u32->f64. TODO: move to convert emitter after i64 enabling. + uni_vpmovzxdq(v_aux_0, xmm_dst); + uni_vorps(v_aux_0, v_aux_0, ptr[r64_f64_pow_52]); + uni_vsubpd(v_aux_0, v_aux_0, ptr[r64_f64_pow_52]); + + uni_vcvtpd2dq(xmm_dst, v_aux_1); + uni_vdivpd(v_aux_1, v_aux_0, v_range); + uni_vroundpd(v_aux_1, v_aux_1, 3); + if (isa == x64::avx2) { + vfnmadd132pd(v_aux_1, v_aux_0, v_range); + } else { + uni_vmulpd(v_aux_1, v_aux_1, v_range); + uni_vsubpd(v_aux_0, v_aux_0, v_aux_1); + uni_vmovups(v_aux_1, v_aux_0); + } + uni_vcvtpd2dq(xmm_aux_1, v_aux_1); + if (isa == x64::avx2) { + vperm2f128(ymm_dst, ymm_dst, v_aux_1, 0b00100000); + } else { + uni_vshufpd(vmm_dst, vmm_dst, v_aux_1, 0b00000000); + } + + uni_vpaddd(vmm_dst, vmm_dst, ptr[r64_min]); + } else { + OPENVINO_THROW("RandomUniform kernel does not support precision ", m_jcp.out_data_type, " for ", x64::get_isa_info()); + } + } + } else if (m_jcp.out_data_type.size() == 8) { + if (m_jcp.out_data_type == element::i64) { + // TODO: in scope of i64 enabling. + } + OPENVINO_THROW("RandomUniform kernel does not support precision ", m_jcp.out_data_type, " for ", x64::get_isa_info()); + } else { + OPENVINO_THROW("RandomUniform kernel does not support precision ", m_jcp.out_data_type, " for ", x64::get_isa_info()); + } +} + +template <> +void RandomUniform::tail(const std::vector& vmm_dst) { + Xbyak::Label l_end; + const auto k_rest_mask = getMask(); + + cmp(r64_work_amount, 0); + jle(l_end, T_NEAR); + + runPhilox(vmm_dst, v_key_64, v_counter_64, v_n_64); + convert(vmm_dst, vmm_dst); + + if (m_jcp.out_data_type.size() == 4) { + Xbyak::Label l_0; + const auto step = vlen / sizeof(uint32_t); + + cmp(r64_work_amount, step); + jl(l_0, T_NEAR); + + uni_vmovups(ptr[r64_dst], vmm_dst[0]); + add(r64_dst, vlen); + sub(r64_work_amount, step); + fillRestWorkMask(k_rest_mask, r64_work_amount); + uni_vmovups(ptr[r64_dst] | k_rest_mask, vmm_dst[1]); + jmp(l_end, T_NEAR); + + L(l_0); + fillRestWorkMask(k_rest_mask, r64_work_amount); + uni_vmovups(ptr[r64_dst] | k_rest_mask, vmm_dst[0]); + } else if (m_jcp.out_data_type.size() == 2) { + fillRestWorkMask(k_rest_mask, r64_work_amount); + vmovdqu16(ptr[r64_dst] | k_rest_mask, vmm_dst[0]); + } + + L(l_end); +} + +template <> +void RandomUniform::tail(const std::vector& vmm_dst) { + Xbyak::Label l_0, l_end; + const auto step = vlen / sizeof(uint32_t); + + cmp(r64_work_amount, 0); + jle(l_end, T_NEAR); + + runPhilox(vmm_dst, v_key_64, v_counter_64, v_n_64); + convert(vmm_dst, vmm_dst); + const auto v_rest_mask = getVmm(); + + cmp(r64_work_amount, step); + jl(l_0, T_NEAR); + + uni_vmovups(ptr[r64_dst], vmm_dst[0]); + add(r64_dst, vlen); + sub(r64_work_amount, step); + fillRestWorkMask(v_rest_mask, r64_work_amount, m_jcp.out_data_type.size()); + vmaskmovps(ptr[r64_dst], v_rest_mask, vmm_dst[1]); + jmp(l_end, T_NEAR); + + L(l_0); + fillRestWorkMask(v_rest_mask, r64_work_amount, m_jcp.out_data_type.size()); + vmaskmovps(ptr[r64_dst], v_rest_mask, vmm_dst[0]); + + L(l_end); +} + +template +void RandomUniform::tail(const std::vector& vmm_dst) { + Xbyak::Label l_0, l_end; + const auto step = vlen / sizeof(uint32_t); + + cmp(r64_work_amount, 0); + jle(l_end, T_NEAR); + + runPhilox(vmm_dst, v_key_64, v_counter_64, v_n_64); + convert(vmm_dst, vmm_dst); + + cmp(r64_work_amount, step); + jl(l_0, T_NEAR); + + uni_vmovups(ptr[r64_dst], vmm_dst[0]); + add(r64_dst, vlen); + sub(r64_work_amount, step); + store(ptr[r64_dst], vmm_dst[1], r64_work_amount, m_jcp.out_data_type.size()); + jmp(l_end, T_NEAR); + + L(l_0); + store(ptr[r64_dst], vmm_dst[0], r64_work_amount, m_jcp.out_data_type.size()); + + L(l_end); +} + +template class RandomUniform; +template class RandomUniform; +template class RandomUniform; + +} // namespace kernel +} // namespace intel_cpu +} // namespace ov diff --git a/src/plugins/intel_cpu/src/nodes/kernels/x64/random_uniform.hpp b/src/plugins/intel_cpu/src/nodes/kernels/x64/random_uniform.hpp new file mode 100644 index 00000000000000..366be4c3a132ce --- /dev/null +++ b/src/plugins/intel_cpu/src/nodes/kernels/x64/random_uniform.hpp @@ -0,0 +1,99 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "jit_kernel_base.hpp" + +#if defined(OPENVINO_ARCH_X86_64) + +namespace ov { +namespace intel_cpu { +namespace kernel { + +struct RandomUniformCompileParams { + element::Type out_data_type = element::f32; +}; + +struct RandomUniformCallArgs { + void* dst_ptr; + const void* key_ptr; + const void* counter_ptr; + const void* n_ptr; + const void* min_ptr; + const void* range_ptr; + uint64_t work_amount = 0lu; +}; + +template +class RandomUniform : public JitKernel { +public: + DECLARE_CPU_JIT_AUX_FUNCTIONS(RandomUniform) + + explicit RandomUniform(const RandomUniformCompileParams& jcp); + + void generate() override; + +private: + using Vmm = typename dnnl::impl::utils::conditional3::type; + using Vmask = typename dnnl::impl::utils::conditional3::type; + + RegistersPool::Reg r64_dst; + RegistersPool::Reg r64_work_amount; + RegistersPool::Reg r64_n_inc; + RegistersPool::Reg r64_convert_0; + RegistersPool::Reg r64_convert_1; + RegistersPool::Reg r64_min; + RegistersPool::Reg r64_f64_pow_52; + + const Xbyak::Reg64 r64_params = Xbyak::Reg64(dnnl::impl::cpu::x64::abi_param_regs[0]); + + // Vector registers. + RegistersPool::Reg v_max_mul_n_64; + RegistersPool::Reg v_max_mul_c_64; + RegistersPool::Reg v_add_low_k; + RegistersPool::Reg v_add_up_k; + RegistersPool::Reg v_convert_0; + RegistersPool::Reg v_convert_1; + RegistersPool::Reg v_convert_2; + RegistersPool::Reg v_n_inc; + RegistersPool::Reg v_key_64; + RegistersPool::Reg v_counter_64; + RegistersPool::Reg v_n_64; + RegistersPool::Reg v_min; + RegistersPool::Reg v_range; + RegistersPool::Reg v_res_perm; + RegistersPool::Reg v_perm_16; + + void initVectors(); + + void process(); + + void runPhilox(const std::vector& vmm_res, const Vmm& vmm_key, const Vmm& vmm_counter, const Vmm& vmm_n); + + void calculateRound(const Vmm& vmm_k_0, const Vmm& vmm_k_1, const Vmm& vmm_c_0, const Vmm& vmm_c_1, + const Vmm& vmm_n_0, const Vmm& vmm_n_1, const Vmm& vmm_aux_0, const Vmm& vmm_aux_1); + + void raiseKey(const Vmm& vmm_k_0, const Vmm& vmm_k_1); + + void convert(const std::vector& vmm_dst, const std::vector& vmm_src); + + void tail(const std::vector& vmm_dst); + + static constexpr uint64_t ROUNDS_NUMBER = 10lu; + static constexpr uint32_t CRUSH_RESISTANCE_CONST_LOWER_VALUE = 0x9E3779B9; + static constexpr uint32_t CRUSH_RESISTANCE_CONST_UPPER_VALUE = 0xBB67AE85; + static constexpr uint64_t STATISTIC_MAXIMIZING_MULTIPLIER_N = 0xD2511F53; + static constexpr uint64_t STATISTIC_MAXIMIZING_MULTIPLIER_COUNTER = 0xCD9E8D57; +}; + +} // namespace kernel +} // namespace intel_cpu +} // namespace ov + +#endif // OPENVINO_ARCH_X86_64 diff --git a/src/plugins/intel_cpu/src/nodes/non_max_suppression.cpp b/src/plugins/intel_cpu/src/nodes/non_max_suppression.cpp index bfd1d8fa982901..d2a46ac97da017 100644 --- a/src/plugins/intel_cpu/src/nodes/non_max_suppression.cpp +++ b/src/plugins/intel_cpu/src/nodes/non_max_suppression.cpp @@ -626,7 +626,7 @@ void NonMaxSuppression::initSupportedPrimitiveDescriptors() { if (!supportedPrimitiveDescriptors.empty()) return; - const std::vector supportedFloatPrecision = {Precision::FP32, Precision::BF16}; + const std::vector supportedFloatPrecision = {Precision::FP32, Precision::BF16, Precision::FP16}; const std::vector supportedIntOutputPrecision = {Precision::I32, Precision::I64}; checkPrecision(getOriginalInputPrecisionAtPort(NMS_BOXES), supportedFloatPrecision, "boxes", inType); diff --git a/src/plugins/intel_cpu/src/nodes/non_zero.cpp b/src/plugins/intel_cpu/src/nodes/non_zero.cpp index 4571eaa9e8c998..be2a8d894fc7f8 100644 --- a/src/plugins/intel_cpu/src/nodes/non_zero.cpp +++ b/src/plugins/intel_cpu/src/nodes/non_zero.cpp @@ -57,7 +57,7 @@ void NonZero::initSupportedPrimitiveDescriptors() { return; const auto &inPrc = getOriginalInputPrecisionAtPort(0); - if (!one_of(inPrc, Precision::FP32, Precision::BF16, Precision::I32, Precision::U32, Precision::I8, Precision::U8)) { + if (!one_of(inPrc, Precision::FP32, Precision::BF16, Precision::FP16, Precision::I32, Precision::U32, Precision::I8, Precision::U8)) { IE_THROW() << "Can't create primitive descriptor for NonZero layer with name: " << getName() << " doesn't support " << inPrc.name() << " precision on 0 port"; } @@ -123,6 +123,7 @@ void NonZero::execute(dnnl::stream strm) { OV_SWITCH(intel_cpu, NonZeroExecute, ctx, inputPrec, OV_CASE(Precision::FP32, float), OV_CASE(Precision::BF16, bfloat16_t), + OV_CASE(Precision::FP16, float16), OV_CASE(Precision::I32, int), OV_CASE(Precision::U32, uint32_t), OV_CASE(Precision::I8, int8_t), diff --git a/src/plugins/intel_cpu/src/nodes/normalize.cpp b/src/plugins/intel_cpu/src/nodes/normalize.cpp index c4fc60a9d9e855..12f3ecf397764a 100644 --- a/src/plugins/intel_cpu/src/nodes/normalize.cpp +++ b/src/plugins/intel_cpu/src/nodes/normalize.cpp @@ -796,10 +796,14 @@ void NormalizeL2::initSupportedPrimitiveDescriptors() { inputPrecision = outputPrecision = Precision::BF16; } - if (!one_of(inputPrecision, Precision::FP32, Precision::BF16, Precision::I8, Precision::U8)) { + if (one_of(Precision::FP16, inputPrecision, outputPrecision) && mayiuse(cpu::x64::sse41)) { + inputPrecision = outputPrecision = Precision::FP32; + } + + if (!one_of(inputPrecision, Precision::FP32, Precision::BF16, Precision::FP16, Precision::I8, Precision::U8)) { THROW_ERROR << "has unsupported input precision: " << inputPrecision; } - if (!one_of(outputPrecision, Precision::FP32, Precision::BF16, Precision::I8, Precision::U8)) { + if (!one_of(outputPrecision, Precision::FP32, Precision::BF16, Precision::FP16, Precision::I8, Precision::U8)) { THROW_ERROR << "has unsupported output precision: " << outputPrecision; } @@ -1483,7 +1487,8 @@ std::shared_ptr NormalizeL2::NormalizeL2Execut OV_CASE2(Precision::U8, Precision::FP32, uint8_t, float), OV_CASE2(Precision::I8, Precision::FP32, int8_t, float), OV_CASE2(Precision::FP32, Precision::FP32, float, float), - OV_CASE2(Precision::BF16, Precision::BF16, bfloat16_t, bfloat16_t)); + OV_CASE2(Precision::BF16, Precision::BF16, bfloat16_t, bfloat16_t), + OV_CASE2(Precision::FP16, Precision::FP16, float16_t, float16_t)); return ctx.executor; } diff --git a/src/plugins/intel_cpu/src/nodes/pooling.cpp b/src/plugins/intel_cpu/src/nodes/pooling.cpp index 0bd6f3208c1e87..42aa97d062702b 100644 --- a/src/plugins/intel_cpu/src/nodes/pooling.cpp +++ b/src/plugins/intel_cpu/src/nodes/pooling.cpp @@ -271,14 +271,31 @@ void Pooling::getSupportedDescriptors() { const auto &childShape = getOutputShapeAtPort(0); const size_t inputRank = getInputShapeAtPort(0).getRank(); + if (isDynamicNode()) { + inShape = MemoryDescUtils::makeDummyShape(parentShape); + const auto& origDims = parentShape.getDims(); + const auto& origMaxDims = parentShape.getMaxDims(); + + auto inDims = inShape.getStaticDims(); + for (size_t i = 0; i < inDims.size() - 2; i++) { + if (origDims[i + 2] == Shape::UNDEFINED_DIM) { + inDims[i + 2] = std::min(origMaxDims[i + 2], std::max(inDims[i + 2], poolingAttrs.kernel[i])); + } + } + inShape = Shape(inDims); + } else { + inShape = parentShape; + } + #if defined(OV_CPU_WITH_ACL) // WA: we may specify any layout here (NCHW or NHWC) since both are supported by ACL - arm_compute::DataLayout dataLayout = (parentShape.getDims().size() == 5) ? arm_compute::DataLayout::NDHWC : arm_compute::DataLayout::NCHW; - arm_compute::TensorInfo srcTensorInfo = arm_compute::TensorInfo(shapeCast(parentShape.getDims()), + arm_compute::DataLayout dataLayout = (inShape.getDims().size() == 5) ? arm_compute::DataLayout::NDHWC : arm_compute::DataLayout::NCHW; + arm_compute::TensorInfo srcTensorInfo = arm_compute::TensorInfo(shapeCast(inShape.getDims()), 1, precisionToAclDataType(inputPrecision), dataLayout); - arm_compute::TensorInfo dstTensorInfo = arm_compute::TensorInfo(shapeCast(childShape.getDims()), + arm_compute::TensorInfo dstTensorInfo = arm_compute::TensorInfo(shapeCast(isDynamicNode() ? MemoryDescUtils::makeDummyShape(childShape).getDims() : + childShape.getDims()), 1, precisionToAclDataType(outputPrecision), dataLayout); @@ -287,16 +304,19 @@ void Pooling::getSupportedDescriptors() { useACL = AclPoolingExecutor::isSupported(srcTensorInfo, dstTensorInfo, poolingAttrs, - parentShape.getDims().size(), + inShape.getDims().size(), getOriginalOutputsNumber(), dataLayout, (getOriginalOutputsNumber() > 1) ? &getOutputShapeAtPort(1).getDims() : nullptr, &pool_info, - &pool3d_info); + &pool3d_info, + isDynamicNode()); //FIXME: 5D tensors case is not assigned to ACL because there is no way to check layout here //NEPooling3dLayer supports NDHWC only - if (parentShape.getDims().size() == 5) + if (inShape.getDims().size() == 5) { useACL = false; + DEBUG_LOG("FIXME: 5D tensors case is not assigned to ACL because there is no way to check layout in getSupportedDescriptors()"); + } #endif if (useACL) return; @@ -324,19 +344,7 @@ void Pooling::getSupportedDescriptors() { if ((inputRank < 3) || (inputRank > 5)) IE_THROW() << "Pooling layer. Unsupported mode. Only 3D, 4D and 5D blobs are supported as input."; - inShape = MemoryDescUtils::makeDummyShape(parentShape); - if (isDynamicNode()) { - const auto& origDims = parentShape.getDims(); - const auto& origMaxDims = parentShape.getMaxDims(); - auto inDims = inShape.getStaticDims(); - for (size_t i = 0; i < inDims.size() - 2; i++) { - if (origDims[i + 2] == Shape::UNDEFINED_DIM) { - inDims[i + 2] = std::min(origMaxDims[i + 2], std::max(inDims[i + 2], poolingAttrs.kernel[i])); - } - } - inShape = Shape(inDims); - } initEffectiveAttributes(inShape, MemoryDescUtils::makeDummyShape(childShape)); @@ -386,7 +394,12 @@ void Pooling::prepareParams() { } else { attr = initPrimitiveAttr(); } - + if (isDynamicNode()) { + if (poolingAttrs.auto_pad) { + poolingAttrs.data_pad_begin = shapeInference->get_pads_begin(); + poolingAttrs.data_pad_end = shapeInference->get_pads_end(); + } + } if (useACL) { auto dstMemPtr = getChildEdgeAt(0)->getMemoryPtr(); auto srcMemPtr = getParentEdgeAt(0)->getMemoryPtr(); @@ -414,10 +427,6 @@ void Pooling::prepareParams() { auto outDesc = getChildEdgesAtPort(0)[0]->getMemory().getDescWithType(); if (isDynamicNode()) { - if (poolingAttrs.auto_pad) { - poolingAttrs.data_pad_begin = shapeInference->get_pads_begin(); - poolingAttrs.data_pad_end = shapeInference->get_pads_end(); - } initEffectiveAttributes(inDesc->getShape(), outDesc->getShape()); } @@ -593,18 +602,17 @@ void Pooling::initSupportedPrimitiveDescriptors() { config.inConfs.resize(getParentEdges().size()); config.outConfs.resize(getOriginalOutputsNumber()); - config.inConfs[0].setMemDesc( - creatorsMap.at(format)->createSharedDesc(getOriginalInputPrecisionAtPort(0), getInputShapeAtPort(0))); - config.outConfs[0].setMemDesc( - creatorsMap.at(format)->createSharedDesc(getOriginalOutputPrecisionAtPort(0), getOutputShapeAtPort(0))); - std::vector srcMemoryDescs; - for (const auto& inConf : config.inConfs) { - srcMemoryDescs.push_back(inConf.getMemDesc()); + for (size_t i = 0; i < config.inConfs.size(); i++) { + config.inConfs[i].setMemDesc( + creatorsMap.at(format)->createSharedDesc(getOriginalInputPrecisionAtPort(i), getInputShapeAtPort(i))); + srcMemoryDescs.push_back(config.inConfs[i].getMemDesc()); } std::vector dstMemoryDescs; - for (const auto& outConf : config.outConfs) { - dstMemoryDescs.push_back(outConf.getMemDesc()); + for (size_t i = 0; i < config.outConfs.size(); i++) { + config.outConfs[i].setMemDesc( + creatorsMap.at(format)->createSharedDesc(getOriginalOutputPrecisionAtPort(i), getOutputShapeAtPort(i))); + dstMemoryDescs.push_back(config.outConfs[i].getMemDesc()); } auto factory = std::make_shared( diff --git a/src/plugins/intel_cpu/src/nodes/random_uniform.cpp b/src/plugins/intel_cpu/src/nodes/random_uniform.cpp new file mode 100644 index 00000000000000..77d823710c942f --- /dev/null +++ b/src/plugins/intel_cpu/src/nodes/random_uniform.cpp @@ -0,0 +1,532 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "random_uniform.hpp" + +#include "ie_parallel.hpp" +#include "ie_ngraph_utils.hpp" +#include +#include +#include "shape_inference/custom/random_uniform.hpp" + +namespace ov { +namespace intel_cpu { +namespace node { + +bool RandomUniform::isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept { + try { + if (op->get_type_info() != op::v8::RandomUniform::get_type_info_static()) { + errorMessage = "Only RandomUniform operation from the opset8 is supported by the CPU plugin."; + return false; + } + } catch (...) { + return false; + } + return true; +} + +RandomUniform::RandomUniform(const std::shared_ptr& op, const GraphContext::CPtr& context) + : Node(op, context, RandomUniformShapeInferFactory(op)) { + std::string errorMessage; + if (!isSupportedOperation(op, errorMessage)) { + THROW_CPU_NODE_ERR(errorMessage); + } + + // RandomUniform should generate new sequence each run even if all inputs are constants. So that method Node::IsConstant() + // doesn't return 'True' for RandomUniform with all constant inputs and the node generates new values for each inference, + // we set 'NoConst' value for 'ConstantType' in ctor. + constant = ConstantType::NoConst; + + auto rnd_op = as_type_ptr(op); + m_global_seed = rnd_op->get_global_seed(); + m_op_seed = rnd_op->get_op_seed(); + + m_output_prc = op->get_output_element_type(0); + + for (size_t i = 0lu; i < op->get_input_size(); i++) { + if (is_type(op->get_input_node_ptr(i))) { + m_const_inputs[i] = true; + } + } + + if (m_algo == STL) { + m_generator = std::default_random_engine{static_cast(m_op_seed)}; + } +} + +void RandomUniform::getSupportedDescriptors() { + if (getParentEdges().size() != 3) { + THROW_CPU_NODE_ERR("has incorrect number of input edges."); + } + if (getChildEdges().empty()) { + THROW_CPU_NODE_ERR("has incorrect number of output edges."); + } +} + +void RandomUniform::initSupportedPrimitiveDescriptors() { + auto shape_prc = getOriginalInputPrecisionAtPort(SHAPE); + if (!one_of(shape_prc, InferenceEngine::Precision::I32, InferenceEngine::Precision::I64)) { + shape_prc = InferenceEngine::Precision::I32; + } + + auto out_prc = getOriginalOutputPrecisionAtPort(0); + if (out_prc.is_float() && ((m_algo == PHILOX && + !one_of(out_prc, InferenceEngine::Precision::FP32, InferenceEngine::Precision::FP16, InferenceEngine::Precision::BF16)) || + (m_algo == STL && !one_of(out_prc, InferenceEngine::Precision::FP32)))) { + out_prc = InferenceEngine::Precision::FP32; + } + if (!out_prc.is_float() && !one_of(out_prc, InferenceEngine::Precision::I32, InferenceEngine::Precision::I64)) { + out_prc = InferenceEngine::Precision::I32; + } + m_output_prc = InferenceEngine::details::convertPrecision(out_prc); + + addSupportedPrimDesc({{LayoutType::ncsp, shape_prc, m_const_inputs[SHAPE]}, + {LayoutType::ncsp, out_prc, m_const_inputs[MIN_VAL]}, + {LayoutType::ncsp, out_prc, m_const_inputs[MAX_VAL]}}, + {{LayoutType::ncsp, out_prc}}, + ref_any); +} + +void RandomUniform::createPrimitive() { + if (m_const_inputs[MIN_VAL]) { + initEdgeValues(m_min_val, getParentEdgeAt(MIN_VAL)->getMemoryPtr()->getData(), m_output_prc); + } + if (m_const_inputs[MAX_VAL]) { + initEdgeValues(m_max_val, getParentEdgeAt(MAX_VAL)->getMemoryPtr()->getData(), m_output_prc); + evalRange(); + } + + if (m_algo == PHILOX) { +#if defined(OPENVINO_ARCH_X86_64) + kernel::RandomUniformCompileParams jcp; + + jcp.out_data_type = m_output_prc; + + m_jit_kernel = kernel::JitKernel::createInstance(jcp); + + if (m_jit_kernel) { + if (auto selected_pd = getSelectedPrimitiveDescriptor()) { + using namespace dnnl::impl::cpu; + if (m_jit_kernel->getIsa() == x64::avx512_core) { + selected_pd->setImplementationType(jit_avx512); + } else if (m_jit_kernel->getIsa() == x64::avx2) { + selected_pd->setImplementationType(jit_avx2); + } else if (m_jit_kernel->getIsa() == x64::sse41) { + selected_pd->setImplementationType(jit_sse42); + } + } + } +#endif // OPENVINO_ARCH_X86_64 + } + + if (m_const_inputs[SHAPE]) { + Node::createPrimitive(); + } +} + +bool RandomUniform::needPrepareParams() const { + if (m_out_shape != getChildEdgeAt(0)->getMemoryPtr()->getShape().getStaticDims()) { + return true; + } + return false; +} + +void RandomUniform::prepareParams() { + m_out_shape = getChildEdgeAt(0)->getMemoryPtr()->getShape().getStaticDims(); + m_out_el_num = std::accumulate(m_out_shape.begin(), m_out_shape.end(), 1lu, std::multiplies()); + + if (m_algo == PHILOX) { + m_skip_count = m_out_el_num * SKIP_CONST; + + if (m_out_el_num < PHILOX_PARALLEL_EXECUTION_THRESHOLD) { + m_threads_num = 1; + } else { + m_threads_num = parallel_get_max_threads(); + } + m_thread_params.resize(m_threads_num); + + parallel_nt(m_threads_num, [&](const int ithr, const int nthr) { + auto& p = m_thread_params[ithr]; + uint64_t start = 0lu, end = 0lu; + + if (m_jit_kernel) { +#if defined(OPENVINO_ARCH_X86_64) + const auto block_size = (m_jit_kernel->getVectorLen() / m_output_prc.size()) * 2; + const auto blocks_num = (m_out_el_num + block_size - 1) / block_size; + const auto blocks_per_thr = (blocks_num + nthr - 1) / nthr; + + start = ithr * blocks_per_thr * block_size; + end = (ithr + 1) * blocks_per_thr * block_size; +#endif // OPENVINO_ARCH_X86_64 + } else { + const auto groups_num = (m_out_el_num + PHILOX_GROUP_SIZE - 1) / PHILOX_GROUP_SIZE; + const auto groups_per_thr = (groups_num + nthr - 1) / nthr; + + start = ithr * groups_per_thr * PHILOX_GROUP_SIZE; + end = (ithr + 1) * groups_per_thr * PHILOX_GROUP_SIZE; + + p.step = m_output_prc.size() > 4 ? 2 : 4; + } + + if (end > m_out_el_num) { + end = m_out_el_num; + } + if (start > end) { + start = end; + } + p.work_amount = end - start; + p.n_shift = start / PHILOX_GROUP_SIZE; + p.dst_shift = start * m_output_prc.size(); + }); + } +} + +void RandomUniform::execute(dnnl::stream strm) { + if (!m_const_inputs[MIN_VAL]) { + initEdgeValues(m_min_val, getParentEdgeAt(MIN_VAL)->getMemoryPtr()->getData(), m_output_prc); + if (m_const_inputs[MAX_VAL]) { + evalRange(); + } + } + if (!m_const_inputs[MAX_VAL]) { + initEdgeValues(m_max_val, getParentEdgeAt(MAX_VAL)->getMemoryPtr()->getData(), m_output_prc); + evalRange(); + } + + auto data = getChildEdgeAt(0)->getMemoryPtr()->getData(); + + if (m_algo == PHILOX) { + m_state = computePhilox(data, m_out_el_num, m_state); + } else if (m_algo == STL) { + computeStl(data, m_out_el_num); + } else { + THROW_CPU_NODE_ERR("unsupported algorithm."); + } +} + +void RandomUniform::executeDynamicImpl(dnnl::stream strm) { + execute(strm); +} + +////////////// PHILOX algo /////////////// + +namespace { +// Following const values are taken from the original paper: +// https://www.thesalmons.org/john/random123/papers/random123sc11.pdf +constexpr uint32_t CRUSH_RESISTANCE_CONST_LOWER_VALUE = 0x9E3779B9; +constexpr uint32_t CRUSH_RESISTANCE_CONST_UPPER_VALUE = 0xBB67AE85; +constexpr uint64_t STATISTIC_MAXIMIZING_MULTIPLIER_N = 0xD2511F53; +constexpr uint64_t STATISTIC_MAXIMIZING_MULTIPLIER_COUNTER = 0xCD9E8D57; +constexpr uint64_t ROUNDS_NUMBER = 10llu; + +inline void calculateRound(const uint32_t* key, uint32_t* counter, uint32_t* n) { + uint64_t prod_0 = STATISTIC_MAXIMIZING_MULTIPLIER_N * n[0]; + uint64_t prod_1 = STATISTIC_MAXIMIZING_MULTIPLIER_COUNTER * counter[0]; + n[0] = static_cast(prod_1 >> 32) ^ n[1] ^ key[0]; + n[1] = static_cast(prod_1); + counter[0] = static_cast(prod_0 >> 32) ^ counter[1] ^ key[1]; + counter[1] = static_cast(prod_0); +} + +inline void raiseKey(uint32_t* key) { + key[0] += CRUSH_RESISTANCE_CONST_LOWER_VALUE; + key[1] += CRUSH_RESISTANCE_CONST_UPPER_VALUE; +} + +inline void runPhilox(uint64_t key, uint64_t counter, uint64_t n, uint32_t* res) { + uint32_t* key_32 = reinterpret_cast(&key); + uint32_t* counter_32 = reinterpret_cast(&counter); + uint32_t* n_32 = reinterpret_cast(&n); + + for (size_t i = 0lu; i < ROUNDS_NUMBER; i++) { + calculateRound(key_32, counter_32, n_32); + if (i < ROUNDS_NUMBER - 1) + raiseKey(key_32); + } + + res[0] = n_32[0]; + res[1] = n_32[1]; + res[2] = counter_32[0]; + res[3] = counter_32[1]; +} + +inline void convertToOutputType(const uint32_t* in, + float min, + float range, + float* out, + size_t el_to_copy) { + RandomUniform::OutputType out_val; + + for (size_t i = 0lu; i < el_to_copy; i++) { + out_val.u32 = 0x3f800000 | (in[i] & 0x7fffffu); + out[i] = (out_val.f32 - 1.f) * range + min; + } +} + +inline void convertToOutputType(const uint32_t* in, + float16 min, + float16 range, + float16* out, + size_t el_to_copy) { + RandomUniform::OutputType out_val; + + for (size_t i = 0lu; i < el_to_copy; i++) { + uint16_t x_uint16 = static_cast(in[i]); + out_val.u16 = 0x3c00 | (x_uint16 & 0x03ffu); + out[i] = (out_val.f16 - static_cast(1)) * range + min; + } +} + +inline void convertToOutputType(const uint32_t* in, + bfloat16 min, + bfloat16 range, + bfloat16* out, + size_t el_to_copy) { + RandomUniform::OutputType out_val; + + for (size_t i = 0lu; i < el_to_copy; i++) { + uint16_t x_uint16 = static_cast(in[i]); + out_val.u16 = 0x3f80 | (x_uint16 & 0x7fu); + out[i] = (out_val.bf16 - static_cast(1)) * range + min; + } +} + +inline void convertToOutputType(const uint32_t* in, + int32_t min, + int32_t range, + int32_t* out, + size_t el_to_copy) { + for (size_t i = 0lu; i < el_to_copy; i++) { + out[i] = static_cast(in[i] % range + min); + } +} + +inline void convertToOutputType(const uint32_t* in, + int64_t min, + int64_t range, + int64_t* out, + size_t el_to_copy) { + for (size_t i = 0lu; i < el_to_copy; i++) { + out[i] = static_cast(((static_cast(in[i * 2]) << 32) + in[i * 2 + 1]) % range + min); + } +} + +} // namespace + +std::pair RandomUniform::computePhilox(void* out, size_t out_el_num, const std::pair& prev_state) { + // When both seed values are equal to zero RandomUniform should generate non-deterministic sequence. + if (m_global_seed == 0lu && m_op_seed == 0lu) { + std::srand(static_cast(std::time(nullptr))); + m_global_seed = std::rand(); + } + + uint64_t n_state = prev_state.first; + uint64_t counter_state = prev_state.second; + + uint64_t counter = counter_state > 0 ? counter_state : m_op_seed; + + auto out_u8 = reinterpret_cast(out); + + if (m_jit_kernel) { +#if defined(OPENVINO_ARCH_X86_64) + parallel_nt(m_threads_num, [&](const int ithr, const int nthr) { + auto& p = m_thread_params[ithr]; + if (p.work_amount == 0lu) { + return; + } + auto n = n_state + p.n_shift; + + kernel::RandomUniformCallArgs args; + + args.dst_ptr = (out_u8 + p.dst_shift); + args.key_ptr = &m_global_seed; + args.counter_ptr = &counter; + args.n_ptr = &n; + args.min_ptr = &m_min_val; + args.range_ptr = &m_range_val; + args.work_amount = p.work_amount; + + (*m_jit_kernel)(&args); + }); +#endif // OPENVINO_ARCH_X86_64 + } else { + auto threadBody = [&](const int ithr, const int nthr) { + auto& p = m_thread_params[ithr]; + if (p.work_amount == 0lu) { + return; + } + auto n = n_state + p.n_shift; + auto out_cur = out_u8 + p.dst_shift; + auto work_rest = static_cast(p.work_amount); + uint32_t res[4]; + +#define EXEC_CASE(P) \ + case element::P: { \ + auto out_t = reinterpret_cast::value_type *>(out_cur); \ + for (; work_rest > 0l; work_rest -= p.step, out_t += p.step) { \ + runPhilox(m_global_seed, counter, n, res); \ + auto el_to_copy = std::min(p.step, static_cast(work_rest)); \ + convertToOutputType(res, m_min_val.P, m_range_val.P, out_t, el_to_copy); \ + if (++n == 0) { \ + counter++; \ + } \ + } \ + } break; + + switch (m_output_prc) { + EXEC_CASE(f32) + EXEC_CASE(f16) + EXEC_CASE(bf16) + EXEC_CASE(i32) + EXEC_CASE(i64) + default: THROW_CPU_NODE_ERR("Unsupported type of RandomUniform: ", m_output_prc.to_string()); + } + +#undef EXEC_CASE + }; + + parallel_nt(m_threads_num, threadBody); + } + + // Calculate counter values for next RandomUniform run. + n_state += m_skip_count; + if (n_state < m_skip_count) { + counter_state++; + } + + return { n_state, counter_state }; +} + +////////////// STL algo /////////////// +void RandomUniform::computeStl(void* out, size_t work_amount) { + switch (m_output_prc) { + case element::f32: { + generateData>( + std::uniform_real_distribution{m_min_val.f32, m_max_val.f32}, out, work_amount); + } break; + case element::i32: { + generateData>( + std::uniform_int_distribution{m_min_val.i32, m_max_val.i32}, out, work_amount); + } break; + case element::i64: { + generateData>( + std::uniform_int_distribution{m_min_val.i64, m_max_val.i64}, out, work_amount); + } break; + default: + THROW_CPU_NODE_ERR("has unsupported output type: ", m_output_prc); + } +} + +template +void RandomUniform::generateData(DISTR_TYPE distribution, void* out, size_t work_amount) { + auto dst = reinterpret_cast(out); + for (size_t i = 0; i < work_amount; i++) { + *dst = distribution(m_generator); + dst++; + } +} +////////////////////////////////// + +void RandomUniform::initEdgeValues(OutputType& dst, const void* src, const element::Type& output_type) { +#define EL_CASE(E) \ + case element::E: \ + dst.E = *reinterpret_cast::value_type *>(src); \ + break; + + switch (output_type) { + EL_CASE(f32) + EL_CASE(f16) + EL_CASE(bf16) + EL_CASE(i32) + EL_CASE(i64) + EL_CASE(f64) + default: + THROW_CPU_NODE_ERR("has unsupported output precision: ", output_type); + } + +#undef EL_CASE +} + +void RandomUniform::evalRange() { +#define EL_CASE(E) \ + case element::E: \ + m_range_val.E = m_max_val.E - m_min_val.E; \ + break; + + switch (m_output_prc) { + EL_CASE(f32) + EL_CASE(f16) + EL_CASE(bf16) + EL_CASE(i32) + EL_CASE(i64) + EL_CASE(f64) + default: + THROW_CPU_NODE_ERR("has unsupported output precision: ", m_output_prc); + } + +#undef EL_CASE +} + +std::string RandomUniform::getPrimitiveDescriptorType() const { + auto selectedPrimitiveDesc = getSelectedPrimitiveDescriptor(); + + impl_desc_type type = impl_desc_type::undef; + if (selectedPrimitiveDesc) { + type = selectedPrimitiveDesc->getImplementationType(); + } + + std::string str_type; + + auto add_type = [&](std::string t) { + if (!str_type.empty() && t.c_str()[0] != '_') + str_type += "_"; + str_type += t; + }; + +#define SEARCH_TYPE(_type) \ + if ((type & impl_desc_type::_type) == impl_desc_type::_type) \ + add_type(#_type) + + SEARCH_TYPE(undef); + SEARCH_TYPE(jit); + SEARCH_TYPE(ref); + + SEARCH_TYPE(avx512); + SEARCH_TYPE(avx2); + SEARCH_TYPE(sse42); + SEARCH_TYPE(any); + +#undef SEARCH_TYPE + + if (type == impl_desc_type::unknown) + str_type = "unknown"; + else if (str_type.empty()) + str_type = "undef"; + + if (selectedPrimitiveDesc) { + if (selectedPrimitiveDesc->getConfig().outConfs[0].getMemDesc()->getPrecision() != InferenceEngine::Precision::U8) { + str_type += "_" + std::string(selectedPrimitiveDesc->getConfig().outConfs[0].getMemDesc()->getPrecision().name()); + } else { + str_type += "_I8"; + } + } + + return str_type; +} + +bool RandomUniform::needShapeInfer() const { + return !m_const_inputs[SHAPE]; +} + +bool RandomUniform::isExecutable() const { + return !isInputTensorAtPortEmpty(SHAPE); +} + +bool RandomUniform::created() const { + return getType() == Type::RandomUniform; +} + +} // namespace node +} // namespace intel_cpu +} // namespace ov diff --git a/src/plugins/intel_cpu/src/nodes/random_uniform.hpp b/src/plugins/intel_cpu/src/nodes/random_uniform.hpp new file mode 100644 index 00000000000000..ecbfebdf5d79c6 --- /dev/null +++ b/src/plugins/intel_cpu/src/nodes/random_uniform.hpp @@ -0,0 +1,120 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include "kernels/x64/random_uniform.hpp" + +namespace ov { +namespace intel_cpu { +namespace node { + +class RandomUniform : public Node { +public: + union OutputType { + float f32; + float16 f16; + bfloat16 bf16; + double f64; + int32_t i32; + uint32_t u32; + uint16_t u16; + int64_t i64; + }; + + RandomUniform(const std::shared_ptr& op, const GraphContext::CPtr& context); + + void getSupportedDescriptors() override; + + void initSupportedPrimitiveDescriptors() override; + + bool needPrepareParams() const override; + + void prepareParams() override; + + void execute(dnnl::stream strm) override; + + void executeDynamicImpl(dnnl::stream strm) override; + + bool isExecutable() const override; + + void createPrimitive() override; + + bool created() const override; + + bool canBeInPlace() const override { return false; } + + static bool isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept; + + std::string getPrimitiveDescriptorType() const override; + +protected: + bool needShapeInfer() const override; + +private: + void computeStl(void* out, size_t work_amount); + + std::pair computePhilox(void* out, size_t work_amount, const std::pair& prev_state); + + template + void generateData(DISTR_TYPE distribution, void* out, size_t work_amount); + + void initOutShape(VectorDims& dst, const void* src, const element::Type& shape_type, size_t len); + + void initEdgeValues(OutputType& dst, const void* src, const element::Type& output_type); + + void evalRange(); + + enum { SHAPE = 0, MIN_VAL, MAX_VAL }; + enum AlgoType { STL, PHILOX }; + + bool m_const_inputs[3] = {false, false, false}; + + ov::element::Type m_output_prc; + uint64_t m_global_seed = 0lu; + uint64_t m_op_seed = 0lu; + std::pair m_state {0lu, 0lu}; + + VectorDims m_out_shape = {}; + uint64_t m_out_el_num = 1lu; + OutputType m_min_val; + OutputType m_max_val; + OutputType m_range_val; + AlgoType m_algo = PHILOX; + + std::default_random_engine m_generator; + + struct ThreadParams { + uint64_t work_amount = 0lu; + uint64_t dst_shift = 0lu; + uint64_t n_shift = 0lu; + uint64_t step = 0lu; + }; + + uint64_t m_threads_num = 0lu; + std::vector m_thread_params; + + ///// PHILOX constants ///// + + // Determines how many sequence elements of RNG sequence are skipped between runs. + // Can be any positive value, 256 is chosen for parity with Tensorflow. + static constexpr uint64_t SKIP_CONST = 256lu; + + // Philox algorithm returns 4 elements of RNG sequence per each invocation + static constexpr uint64_t PHILOX_GROUP_SIZE = 4lu; + + // Output elements number threshold to execute on one thread. + static constexpr uint64_t PHILOX_PARALLEL_EXECUTION_THRESHOLD = 1000lu; + + uint64_t m_skip_count = 0lu; + ///////////////////////////////////////////////////////////////////////////////// + + std::shared_ptr m_jit_kernel; +}; + +} // namespace node +} // namespace intel_cpu +} // namespace ov diff --git a/src/plugins/intel_cpu/src/nodes/reference.cpp b/src/plugins/intel_cpu/src/nodes/reference.cpp index b42dc99b390fb4..091e31813125cf 100644 --- a/src/plugins/intel_cpu/src/nodes/reference.cpp +++ b/src/plugins/intel_cpu/src/nodes/reference.cpp @@ -2,18 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include - -#include -#include +#include "reference.h" -#include "common/blocked_desc_creator.h" #include "common/cpu_memcpy.h" +#include #include "openvino/core/shape_util.hpp" -#include "openvino/runtime/tensor.hpp" -#include "reference.h" -using namespace dnnl; using namespace InferenceEngine; using namespace InferenceEngine::details; @@ -21,21 +15,15 @@ namespace ov { namespace intel_cpu { namespace node { -Reference::Reference(const std::shared_ptr& op, const GraphContext::CPtr context, +Reference::Reference(const std::shared_ptr& op, const GraphContext::CPtr& context, const std::string& errorMessage) : - Node(op, context, NgraphShapeInferFactory(op, FULL_PORT_MASK)), ngraphOp(op), additionalErrorMessage(errorMessage) { + Node(op, context, NgraphShapeInferFactory(op, FULL_PORT_MASK)), ovCoreNode(op), additionalErrorMessage(errorMessage) { if (!op->has_evaluate()) { IE_THROW(NotImplemented) << "Cannot fallback on ngraph reference implementation (Ngraph::Node::evaluate() is not implemented)"; } + setType(Type::Reference); setTypeStr("Reference"); - - // RandomUniform should generate new sequence each run even if all inputs are constants. So that method Node::IsConstant() - // doesn't return 'True' for RandomUniform with all constant inputs and the node generates new values for each inference, - // we set 'NoConst' value for 'ConstantType' in ctor - if (ov::is_type(ngraphOp)) { - constant = ConstantType::NoConst; - } } void Reference::getSupportedDescriptors() {} @@ -47,13 +35,13 @@ void Reference::initSupportedPrimitiveDescriptors() { std::vector inputConfigurators; inputConfigurators.reserve(inputShapes.size()); for (size_t i = 0; i < inputShapes.size(); i++) { - inputConfigurators.emplace_back(LayoutType::ncsp, convertPrecision(ngraphOp->get_input_element_type(i)), inputShapes[i]); + inputConfigurators.emplace_back(LayoutType::ncsp, convertPrecision(ovCoreNode->get_input_element_type(i)), inputShapes[i]); } std::vector outputConfigurators; outputConfigurators.reserve(inputShapes.size()); for (size_t i = 0; i < outputShapes.size(); i++) { - outputConfigurators.emplace_back(LayoutType::ncsp, convertPrecision(ngraphOp->get_output_element_type(i)), outputShapes[i]); + outputConfigurators.emplace_back(LayoutType::ncsp, convertPrecision(ovCoreNode->get_output_element_type(i)), outputShapes[i]); } addSupportedPrimDesc(inputConfigurators, outputConfigurators, impl_desc_type::ref); @@ -64,8 +52,8 @@ void Reference::createPrimitive() {} void Reference::execute(dnnl::stream strm) { auto inputs = prepareInputs(); auto outputs = prepareOutputs(); - if (!ngraphOp->evaluate(outputs, inputs)) { - IE_THROW() << "Evaluation failed on node of type: " << std::string(ngraphOp->get_type_name()) << " name: " << getName(); + if (!ovCoreNode->evaluate(outputs, inputs)) { + THROW_CPU_NODE_ERR("evaluation failed for core operation: ", std::string(ovCoreNode->get_type_name())); } } @@ -81,18 +69,16 @@ void Reference::executeDynamicImpl(dnnl::stream strm) { for (size_t i = 0; i < outputShapes.size(); ++i) { auto mem_desc = getBaseMemDescAtOutputPort(i); if (mem_desc->isDefined()) { - outputs.emplace_back(ngraphOp->get_output_element_type(i), mem_desc->getShape().getStaticDims()); + outputs.emplace_back(ovCoreNode->get_output_element_type(i), mem_desc->getShape().getStaticDims()); } else { - outputs.emplace_back(ngraphOp->get_output_element_type(i), ov::util::make_dynamic_shape()); + outputs.emplace_back(ovCoreNode->get_output_element_type(i), ov::util::make_dynamic_shape()); } } } else { - IE_THROW(Unexpected) << - "Unexpected shape infer result status during the inference of a node with type " << - getTypeStr() << " and name " << getName(); + THROW_CPU_NODE_ERR("got unexpected shape infer result status during the inference."); } - if (!ngraphOp->evaluate(outputs, inputs)) { - IE_THROW() << "Evaluation failed on node of type: " << std::string(ngraphOp->get_type_name()) << " name: " << getName(); + if (!ovCoreNode->evaluate(outputs, inputs)) { + THROW_CPU_NODE_ERR("evaluation failed for core operation: ", std::string(ovCoreNode->get_type_name())); } if (ShapeInferStatus::skip == result.status) { std::vector newOutputDims; @@ -105,8 +91,7 @@ void Reference::executeDynamicImpl(dnnl::stream strm) { auto memory = getChildEdgesAtPort(i)[0]->getMemoryPtr(); auto& tensor = outputs[i]; if (memory->getSize() != tensor.get_byte_size()) { - IE_THROW(Unexpected) << "Output tensor data size mismatch occurred during the inference of a node with type " << - getTypeStr() << " and name " << getName() << " on output port number " << i; + THROW_CPU_NODE_ERR("output tensor data size mismatch occurred during the inference on output port number ", i); } cpu_memcpy(memory->getData(), tensor.data(), tensor.get_byte_size()); } @@ -125,9 +110,9 @@ ov::TensorVector Reference::prepareInputs() const { ov::TensorVector inputs; for (size_t i = 0; i < inputShapes.size(); i++) { void *srcDataPtr = getParentEdgesAtPort(i)[0]->getMemory().getData(); - ov::Shape shape = ngraphOp->get_input_partial_shape(i).rank().get_length() == 0 ? + ov::Shape shape = ovCoreNode->get_input_partial_shape(i).rank().get_length() == 0 ? ov::Shape{} : getParentEdgesAtPort(i)[0]->getMemory().getStaticDims(); - inputs.push_back(ov::Tensor(ngraphOp->get_input_element_type(i), shape, srcDataPtr)); + inputs.push_back(ov::Tensor(ovCoreNode->get_input_element_type(i), shape, srcDataPtr)); } return inputs; } @@ -136,9 +121,9 @@ ov::TensorVector Reference::prepareOutputs() const { ov::TensorVector outputs; for (size_t i = 0; i < outputShapes.size(); i++) { void *dstDataPtr = getChildEdgesAtPort(i)[0]->getMemory().getData(); - ov::Shape shape = ngraphOp->get_output_partial_shape(i).rank().get_length() == 0 ? + ov::Shape shape = ovCoreNode->get_output_partial_shape(i).rank().get_length() == 0 ? ov::Shape{} : getChildEdgesAtPort(i)[0]->getMemory().getStaticDims(); - outputs.push_back(ov::Tensor(ngraphOp->get_output_element_type(i), shape, dstDataPtr)); + outputs.push_back(ov::Tensor(ovCoreNode->get_output_element_type(i), shape, dstDataPtr)); } return outputs; } diff --git a/src/plugins/intel_cpu/src/nodes/reference.h b/src/plugins/intel_cpu/src/nodes/reference.h index 4c2a8a1310806f..c2453835229138 100644 --- a/src/plugins/intel_cpu/src/nodes/reference.h +++ b/src/plugins/intel_cpu/src/nodes/reference.h @@ -12,7 +12,7 @@ namespace node { class Reference : public Node { public: - Reference(const std::shared_ptr& op, const GraphContext::CPtr context, const std::string& errorMessage); + Reference(const std::shared_ptr& op, const GraphContext::CPtr& context, const std::string& errorMessage); void getSupportedDescriptors() override; void initSupportedPrimitiveDescriptors() override; @@ -29,7 +29,7 @@ class Reference : public Node { ov::TensorVector prepareOutputs() const; private: - const std::shared_ptr ngraphOp; + const std::shared_ptr ovCoreNode; const std::string additionalErrorMessage; }; diff --git a/src/plugins/intel_cpu/src/nodes/rnn.cpp b/src/plugins/intel_cpu/src/nodes/rnn.cpp index 9992f0f392b893..f453b7a5a51e0b 100644 --- a/src/plugins/intel_cpu/src/nodes/rnn.cpp +++ b/src/plugins/intel_cpu/src/nodes/rnn.cpp @@ -133,6 +133,7 @@ inline bool haveAttention(const dnnl::algorithm& alg) { const std::map RNN::weightsByinputDataType { // layer data type weights data type {memory::data_type::f32, memory::data_type::f32}, + {memory::data_type::f16, memory::data_type::f16}, {memory::data_type::bf16, memory::data_type::bf16}, {memory::data_type::u8, memory::data_type::s8}, {memory::data_type::s8, memory::data_type::s8}, @@ -505,6 +506,10 @@ void RNN::configurePortDataTypes() { if (one_of(memory::data_type::bf16, inDataTypes[xIdx], inDataTypes[hIdx])) inDataTypes[xIdx] = outDataTypes[yIdx] = outDataTypes[hoIdx] = inDataTypes[hIdx] = memory::data_type::bf16; // required by oneDNN. + if (one_of(memory::data_type::f16, inDataTypes[xIdx], inDataTypes[hIdx])) + // onednn doesn't have fp16 instance + inDataTypes[xIdx] = outDataTypes[yIdx] = outDataTypes[hoIdx] = inDataTypes[hIdx] = memory::data_type::f32; // required by oneDNN. + if (outDataTypes[yIdx] == memory::data_type::bf16 && one_of(inDataTypes[xIdx], memory::data_type::s8, memory::data_type::u8)) outDataTypes[yIdx] = memory::data_type::f32; // oneDNN does not support bf16 output precision for quantized rnn primitive yet } @@ -882,7 +887,7 @@ void RNN::copyWeightsData() { } const auto& dataType = inDataTypes[xIdx]; - if (dataType == memory::data_type::bf16) { + if (one_of(dataType, memory::data_type::bf16, memory::data_type::f16)) { fillWeights(gate_map, wIdx, rIdx); } else if (dataType == memory::data_type::f32) { // WA To avoid different weights layer and iter formats in FP32 case diff --git a/src/plugins/intel_cpu/src/nodes/subgraph.cpp b/src/plugins/intel_cpu/src/nodes/subgraph.cpp index 286faee9b85d15..58c6c4f595a95f 100644 --- a/src/plugins/intel_cpu/src/nodes/subgraph.cpp +++ b/src/plugins/intel_cpu/src/nodes/subgraph.cpp @@ -13,14 +13,15 @@ #include #include -#include #include #include #include +#include #include "snippets/pass/matmul_to_brgemm.hpp" #include "utils/cpu_utils.hpp" #include "emitters/x64/cpu_generator.hpp" +#include "transformations/snippets/x64/pass/lowered/set_brgemm_copy_b_buffers_shape.hpp" #include "transformations/snippets/x64/pass/lowered/fuse_load_store_and_convert.hpp" #include "transformations/snippets/x64/pass/lowered/brgemm_blocking.hpp" #include "transformations/snippets/x64/pass/mul_add_to_fma.hpp" @@ -117,67 +118,36 @@ bool SnippetKey::operator==(const SnippetKey& rhs) const { return true; } -snippets::op::Subgraph::BlockedShapeVector getBlockedShapes(const std::vector>& memBlockedDims, - const std::vector>& memOrders, const std::vector& memPrecs) { - size_t numShapes = memBlockedDims.size(); - if (memOrders.size() != numShapes || memPrecs.size() != numShapes) - IE_THROW(Unexpected) << "Number of shapes is mismacthed for dimensions, orders and precisions"; - snippets::op::Subgraph::BlockedShapeVector blockedShapes(numShapes); - for (size_t i = 0; i < numShapes; i++) { - size_t dimSize = memBlockedDims[i].size(); - std::vector dims(dimSize); - for (size_t j = 0; j < dimSize; j++) { - dims[j] = memBlockedDims[i][j]; - } - ov::PartialShape shape(dims); - ov::AxisVector order(memOrders[i]); - ov::element::Type precision = InferenceEngine::details::convertPrecision(memPrecs[i]); - - blockedShapes[i] = snippets::op::Subgraph::BlockedShape{shape, order, precision}; - } - - return blockedShapes; -} } // namespace Snippet::Snippet(const std::shared_ptr& op, const GraphContext::CPtr& context) : Node(op, context, SnippetShapeInferFactory(op)) { host_isa = dnnl::impl::cpu::x64::mayiuse(dnnl::impl::cpu::x64::avx512_core) ? dnnl::impl::cpu::x64::avx512_core : dnnl::impl::cpu::x64::avx2; - original_snippet = ov::as_type_ptr(op); - if (!original_snippet) { - IE_THROW(NotImplemented) << "Node is not an instance of snippets::op::Subgraph"; - } - init_body_hash(); - is_dynamic = isDynamicNgraphNode(op); -} + const auto& tmp_snippet = ov::as_type_ptr(op); + OPENVINO_ASSERT(tmp_snippet, "Attempt to create Snippet node from an invalid op type"); + snippetAttrs.snippet = tmp_snippet->clone(); + snippetAttrs.bodyHash = get_body_hash(tmp_snippet); -void Snippet::copy_snippet() const { - ov::OutputVector subgraph_node_inputs; - for (const auto &input : original_snippet->input_values()) { - auto new_input = std::make_shared(input.get_element_type(), input.get_partial_shape()); - subgraph_node_inputs.push_back(new_input); - } - std::shared_ptr new_body = original_snippet->body_ptr()->clone(); - snippetAttrs.snippet = std::make_shared(subgraph_node_inputs, new_body); - ov::copy_runtime_info(original_snippet, snippetAttrs.snippet); - snippetAttrs.snippet->set_friendly_name(original_snippet->get_friendly_name()); #if defined(OPENVINO_ARCH_X86_64) snippetAttrs.snippet->set_generator(std::make_shared(host_isa)); #else - IE_THROW(NotImplemented) << "CPU plugin: code-generation is not supported on non-x64 platforms"; + OPENVINO_THROW("CPU plugin: Snippets code-generator is not supported on non-x64 platforms"); #endif // OPENVINO_ARCH_X86_64 + + // Note: we have to update shapeInfer, so it uses the per-thread op::Subgraph copy + shapeInference = SnippetShapeInferFactory(snippetAttrs.snippet).makeShapeInfer(); + is_dynamic = isDynamicNgraphNode(op); } -void Snippet::init_body_hash() { +uint64_t Snippet::get_body_hash(const std::shared_ptr& snippet) { uint64_t seed = 0; ov::snippets::pass::Hash hash_function(seed); - hash_function.run_on_model(original_snippet->body_ptr()); - snippetAttrs.bodyHash = seed; + hash_function.run_on_model(snippet->body_ptr()); + return seed; } void Snippet::initSupportedPrimitiveDescriptors() { - copy_snippet(); if (!supportedPrimitiveDescriptors.empty()) return; @@ -313,16 +283,29 @@ void Snippet::selectOptimalPrimitiveDescriptor() { } void Snippet::initOptimalPrimitiveDescriptor() { + const auto isPlanar = [](const VectorDims& order ) { + for (size_t i = 0; i < order.size(); ++i) + if (order[i] != i) + return false; + return true; + }; Node::initOptimalPrimitiveDescriptor(); // memory order and precision is determined now, there is no need to prepare for each dynamic shapes. const auto config = getSelectedPrimitiveDescriptor()->getConfig(); inputNum = config.inConfs.size(); + snippets::op::Subgraph::BlockedShapeVector in_blocked_shapes; snippetAttrs.inMemPrecs.resize(inputNum); snippetAttrs.inMemOrders.resize(inputNum); + in_blocked_shapes.reserve(inputNum); + snippetAttrs.has_non_planar_inputs = false; for (size_t i = 0; i < inputNum; i++) { const auto& memDesc = config.inConfs[i].getMemDesc(); snippetAttrs.inMemPrecs[i] = memDesc->getPrecision(); - snippetAttrs.inMemOrders[i] = memDesc->as()->getOrder(); + const auto& blockedDesc = memDesc->as(); + const auto& order = blockedDesc->getOrder(); + snippetAttrs.inMemOrders[i] = order; + snippetAttrs.has_non_planar_inputs |= !isPlanar(order); + in_blocked_shapes.emplace_back(blockedDesc->getBlockDims(), order); } outputNum = config.outConfs.size(); snippetAttrs.outMemPrecs.resize(outputNum); @@ -336,6 +319,52 @@ void Snippet::initOptimalPrimitiveDescriptor() { snippetAttrs.outMemBlockedDims.resize(outputNum); srcMemPtrs.resize(inputNum); dstMemPtrs.resize(outputNum); + + // here we should perform all shape-agnostic snippets passes + // * canonicalization (RankNormalization insert) + // * precision propagation & align element types + // * data flow optimizations + // The result of these transformations will be reused by all shapes + using Manager = snippets::pass::Manager; + std::vector backend_passes; +#if defined(OPENVINO_ARCH_X86_64) + using PassPosition = snippets::pass::Manager::PassPosition; + using Place = snippets::pass::Manager::PassPosition::Place; +# define SNIPPETS_REGISTER_PASS(PASS_POS, PASS, ...) \ + backend_passes.emplace_back(PASS_POS, std::make_shared(__VA_ARGS__)) +#else +# define SNIPPETS_REGISTER_PASS(PASS_POS, PASS, ...) +#endif // OPENVINO_ARCH_X86_64 + + SNIPPETS_REGISTER_PASS(PassPosition(Place::PipelineStart), ConvertToSwishCPU); + if (context->getConfig().inferencePrecision == ov::element::bf16 && snippetAttrs.snippet->has_domain_sensitive_ops()) { + // enforce BF16 precisions to supported operations + // MatMul has to be decomposed to Brgemm operations before enforcement + // Note, MatMul decomposition will be run later again for case if BF16 enforcement is not happened + SNIPPETS_REGISTER_PASS(PassPosition(Place::PipelineStart), ov::snippets::pass::MatMulToBrgemm); + SNIPPETS_REGISTER_PASS(PassPosition(Place::After, "MatMulToBrgemm"), pass::EnforcePrecision, element::f32, element::bf16); + } + + SNIPPETS_REGISTER_PASS(PassPosition(Place::Before, "PropagatePrecision"), ov::intel_cpu::pass::BrgemmToBrgemmCPU); + SNIPPETS_REGISTER_PASS(PassPosition(Place::Before, "PropagatePrecision"), ov::intel_cpu::pass::SetBrgemmCPUBlockingParams); + + SNIPPETS_REGISTER_PASS(PassPosition(Place::PipelineEnd), ov::intel_cpu::pass::RemoveConverts); + SNIPPETS_REGISTER_PASS(PassPosition(Place::PipelineEnd), ov::intel_cpu::pass::MulAddToFMA); + +#undef SNIPPETS_REGISTER_PASS + + std::vector input_precisions; + std::vector output_precisions; + input_precisions.reserve(inputNum); + for (const auto& p : snippetAttrs.inMemPrecs) { + input_precisions.push_back(InferenceEngine::details::convertPrecision(p)); + } + output_precisions.reserve(outputNum); + for (const auto& p : snippetAttrs.outMemPrecs) + output_precisions.push_back(InferenceEngine::details::convertPrecision(p)); + + snippetAttrs.snippet->data_flow_transformations(in_blocked_shapes, input_precisions, output_precisions, backend_passes); + snippetAttrs.snippet->convert_body_to_linear_ir(std::make_shared()); } InferenceEngine::Precision Snippet::getRuntimePrecision() const { @@ -359,9 +388,8 @@ void Snippet::prepareParams() { SnippetKey key = {snippetAttrs}; auto builder = [this](const SnippetKey& key) -> std::shared_ptr { - std::shared_ptr executor = std::make_shared(key.attrs, is_canonicalized, - is_dynamic, context->getConfig().inferencePrecision == ov::element::bf16); - is_canonicalized = true; + std::shared_ptr executor = + std::make_shared(key.attrs, is_dynamic, context->getConfig().inferencePrecision == ov::element::bf16); return executor; }; @@ -424,15 +452,17 @@ void Snippet::executeDynamicImpl(dnnl::stream strm) { } void Snippet::SnippetJitExecutor::exec(const std::vector& inMemPtrs, const std::vector& outMemPtrs) { - if (schedule.ptr == nullptr) { + if (schedule.lowering_result.compiled_snippet->empty()) { IE_THROW() << "Snippet can't use Optimized implementation and can't fallback to reference"; } auto initStartMemoryOffsets = [this, &inMemPtrs, &outMemPtrs]() { for (size_t i = 0; i < numInput; i++) { - start_offset_in[i] = inMemPtrs[i]->getDescWithType()->getOffsetPadding() * dataSize[i]; + start_offset_in[i] = + static_cast(inMemPtrs[i]->getDescWithType()->getOffsetPadding() * dataSize[i]); } for (size_t i = 0; i < numOutput; i++) { - start_offset_out[i] = outMemPtrs[i]->getDescWithType()->getOffsetPadding() * dataSize[i + numInput]; + start_offset_out[i] = + static_cast(outMemPtrs[i]->getDescWithType()->getOffsetPadding() * dataSize[i + numInput]); } }; // initialize start offsets to src and dst memory @@ -461,20 +491,20 @@ void Snippet::SnippetJitExecutor::update_ptrs(jit_snippets_call_args& call_args, } void Snippet::SnippetJitExecutor::schedule_6d(const std::vector& inMemPtrs, const std::vector& outMemPtrs) { - const auto& dom = exec_domain; + const auto& dom = parallel_exec_domain; // < N, C, H, W > < 1, 1, N, C*H*W> + const auto& callable = schedule.get_callable(); parallel_for5d(dom[0], dom[1], dom[2], dom[3], dom[4], [&](int64_t d0, int64_t d1, int64_t d2, int64_t d3, int64_t d4) { int64_t indexes[] = {d0, d1, d2, d3, d4}; jit_snippets_call_args call_args; update_ptrs(call_args, inMemPtrs, outMemPtrs); - - schedule.get_callable()(indexes, &call_args); + callable(indexes, &call_args); }); } void Snippet::SnippetJitExecutor::schedule_nt(const std::vector& inMemPtrs, const std::vector& outMemPtrs) { - const auto& work_size = exec_domain; + const auto& work_size = parallel_exec_domain; parallel_nt(0, [&](const int ithr, const int nthr) { jit_snippets_call_args call_args; update_ptrs(call_args, inMemPtrs, outMemPtrs); @@ -485,8 +515,8 @@ void Snippet::SnippetJitExecutor::schedule_nt(const std::vector& inMe std::vector indexes(work_size.size() - 1, 0); for (size_t iwork = start; iwork < end; ++iwork) { size_t tmp = iwork; - for (ptrdiff_t j = work_size.size() - 2; j >= 0; j--) { - indexes[j] = tmp % work_size[j]; + for (ptrdiff_t j = static_cast(work_size.size()) - 2; j >= 0; j--) { + indexes[j] = static_cast(tmp % work_size[j]); tmp /= work_size[j]; } @@ -495,49 +525,25 @@ void Snippet::SnippetJitExecutor::schedule_nt(const std::vector& inMe }); } -Snippet::SnippetExecutor::SnippetExecutor(const SnippetAttrs& attrs, bool is_canonicalized, bool is_dynamic, bool enforceBF16) - : snippetAttrs(attrs), is_canonicalized(is_canonicalized), is_dynamic(is_dynamic), enforceBF16(enforceBF16) {} +Snippet::SnippetExecutor::SnippetExecutor(SnippetAttrs attrs, bool is_dynamic, bool enforceBF16) + : snippetAttrs(std::move(attrs)), is_dynamic(is_dynamic), enforceBF16(enforceBF16) {} -Snippet::SnippetJitExecutor::SnippetJitExecutor(const SnippetAttrs& attrs, bool is_canonicalized, bool is_dynamic, bool enforceBF16) : - SnippetExecutor(attrs, is_canonicalized, is_dynamic, enforceBF16) { +Snippet::SnippetJitExecutor::SnippetJitExecutor(SnippetAttrs attrs, bool is_dynamic, bool enforceBF16) : + SnippetExecutor(std::move(attrs), is_dynamic, enforceBF16) { numInput = snippetAttrs.inMemBlockedDims.size(); numOutput = snippetAttrs.outMemBlockedDims.size(); start_offset_in.resize(numInput); start_offset_out.resize(numOutput); - auto local_copy = [this]() { - ov::OutputVector subgraph_node_inputs; - for (size_t i = 0; i < numInput; i++) { - const auto paramShape = snippetAttrs.snippet->body_ptr()->get_parameters()[i]->get_shape(); - const auto paramType = snippetAttrs.snippet->body_ptr()->get_parameters()[i]->get_element_type(); - auto new_input = std::make_shared(paramType, paramShape); - subgraph_node_inputs.push_back(new_input); - } - std::shared_ptr new_body = snippetAttrs.snippet->body_ptr()->clone(); - snippet_for_generation = std::make_shared(subgraph_node_inputs, new_body); - ov::copy_runtime_info(snippetAttrs.snippet, snippet_for_generation); - snippet_for_generation->set_friendly_name(snippetAttrs.snippet->get_friendly_name()); -#if defined(OPENVINO_ARCH_X86_64) - auto host_isa = dnnl::impl::cpu::x64::mayiuse(dnnl::impl::cpu::x64::avx512_core) - ? dnnl::impl::cpu::x64::avx512_core - : dnnl::impl::cpu::x64::avx2; - snippet_for_generation->set_generator(std::make_shared(host_isa)); -#else - IE_THROW(NotImplemented) << "CPU plugin: code-generation is not supported on non-x64 platforms"; -#endif // OPENVINO_ARCH_X86_64 - }; - - // is_canonicalized is ture means just reshape canonicalized graph with new input shapes, and get updated master shape, - // false means canonicalization, determine master_shape on snippetAttrs.snippet. - ov::PartialShape canonicalShape = canonicalizeBody(is_canonicalized); - - if (is_dynamic) { - // we need a local snippets for generation, which will be adjusted based on input shapes possibily. - // The adjustment may be not compatible with new input shape in dynamic node, such as broadcastMove inserted. - local_copy(); - } else { - snippet_for_generation = snippetAttrs.snippet; + // todo: snippets don't support backend-provided blocking, so we need to reshape body + // using blocked shapes first. This can be removed after [121670] + if (snippetAttrs.has_non_planar_inputs) { + std::vector in_shapes; + for (const auto& s : snippetAttrs.inMemBlockedDims) + in_shapes.emplace_back(s); + snippetAttrs.snippet->shape_infer(in_shapes); } + const VectorDims& canonicalShape = snippetAttrs.snippet->infer_master_shape(); // initialize by maximum output dimension. Dimensions of outputs should be broadcastable tensorRank = std::max(static_cast(rank6D), canonicalShape.size()); @@ -550,197 +556,39 @@ Snippet::SnippetJitExecutor::SnippetJitExecutor(const SnippetAttrs& attrs, bool }; initDataSizes(); - if (canonicalShape.is_dynamic()) + if (std::any_of(canonicalShape.begin(), canonicalShape.end(), + [](size_t x){return x == snippets::IShapeInferSnippets::DYNAMIC_DIMENSION;})) IE_THROW() << "Snippets: Canonicalization returned dynamic shape in static pipeline"; - masterShape = canonicalShape.get_shape(); - const auto &body = snippet_for_generation->body_ptr(); - normInputShapes.clear(); - for (const auto& p : body->get_parameters()) - normInputShapes.emplace_back(p->get_output_shape(0)); - normOutputShapes.clear(); - for (const auto& r : body->get_results()) - normOutputShapes.emplace_back(r->get_input_shape(0)); - - // prepare - masterShape = getNormalizedDimsBySize(masterShape, tensorRank); - std::vector original_input_shape_ranks; - for (auto& pshape : normInputShapes) { - original_input_shape_ranks.push_back(pshape.size()); - pshape = getNormalizedDimsBySize(pshape, tensorRank); - } - for (auto& pshape : normOutputShapes) - pshape = getNormalizedDimsBySize(pshape, tensorRank); - - tileRank = 1; - bool dims_collapsed = false; - fullWorkAmount = std::accumulate(masterShape.begin(), masterShape.end(), 1, std::multiplies()); - if (snippet_for_generation->has_domain_sensitive_ops()) { - tileRank = 2; - } else { - dims_collapsed = optimizeExecDomain(normInputShapes, normOutputShapes, masterShape, tileRank); - } - exec_domain = masterShape; - - std::vector scheduler_work_amounts; - // rename schedulerWorkAmount to harnessWorkAmount? - harnessWorkAmount = fullWorkAmount; - const auto rank = exec_domain.size(); - for (auto i = rank - tileRank; i < rank; i++) { - auto& dim = exec_domain[i]; - harnessWorkAmount /= dim; - scheduler_work_amounts.push_back(dim); - dim = 1; - } - - if (dims_collapsed) { - std::vector new_shapes; - for (size_t i = 0; i < normInputShapes.size(); i++) { - const auto norm_shape = normInputShapes[i]; - size_t ndims_to_skip = norm_shape.size() - original_input_shape_ranks[i]; - new_shapes.emplace_back(norm_shape.begin() + ndims_to_skip, norm_shape.end()); - } - snippet_for_generation->reshape_body(new_shapes); - } - snippet_for_generation->set_master_shape(ov::PartialShape(masterShape)); - snippet_for_generation->set_tile_rank(tileRank); + snippetAttrs.snippet->set_min_parallel_work_amount(static_cast(parallel_get_max_threads())); + // Note: minimal JIT work amount is a predefined value that describes the number of kernel iterations (work amount) + // needed to cover kernel call overhead. It is used for balancing between parallel and JIT work amounts in domain optimization. + snippetAttrs.snippet->set_min_jit_work_amount(256); // generate jit_snippets_compile_args jcp; - jcp.master_shape = masterShape; - jcp.tile_rank = tileRank; + jcp.parallel_executor_ndims = tensorRank; generate(&jcp); - buffer_scratchpad_size = snippet_for_generation->get_buffer_scratchpad_size(); + buffer_scratchpad_size = schedule.lowering_result.buffer_scratchpad_size; buffer_scratchpad.resize(buffer_scratchpad_size * parallel_get_max_threads(), 0); -} - -ov::PartialShape Snippet::SnippetJitExecutor::canonicalizeBody(bool reshape) { - ov::snippets::op::Subgraph::BlockedShapeVector input_blocked_shapes = getBlockedShapes( - snippetAttrs.inMemBlockedDims, snippetAttrs.inMemOrders, snippetAttrs.inMemPrecs); - if (reshape) { - const auto& canonicalShape = snippetAttrs.snippet->canonicalized_body_shape_infer(input_blocked_shapes); - return canonicalShape; - } else { - ov::snippets::op::Subgraph::BlockedShapeVector output_blocked_shapes = getBlockedShapes( - snippetAttrs.outMemBlockedDims, snippetAttrs.outMemOrders, snippetAttrs.outMemPrecs); - - const auto& canonicalShape = snippetAttrs.snippet->canonicalize(output_blocked_shapes, input_blocked_shapes); - return canonicalShape; - } -} - -bool Snippet::SnippetJitExecutor::optimizeExecDomain(std::vector& inputShapes, std::vector& outputShapes, - VectorDims &domain, size_t& TileRank) const { - const size_t minimalConcurrency = parallel_get_max_threads(); - const size_t minimalJitWorkAmount = 256; - const size_t ds = domain.size(); - if ( ds <= 2 || // not enough dimensions to collapse - domain[ds-1] >= minimalJitWorkAmount || // There is enough work for 1D Tiles, no need to collapse - domain[ds-1] * domain[ds-2] >= fullWorkAmount / minimalConcurrency) // There won't be enough work for every thread (even one iter) if we collapse - return false; - auto findDimsToCollapse = [&]() { - auto collapseLastDims = [](VectorDims& dims, size_t dimsToCollapse) { - if (dimsToCollapse >= dims.size() - 1) - IE_THROW() << "Got invalid number of dims to collapse. Expected < " << dims.size() - 1 << " got " << dimsToCollapse; - for (int i = dims.size() - 2; i > static_cast(dims.size() - dimsToCollapse - 2); i--) { - dims[dims.size() - 1] *= dims[i]; - } - - for (int i = dims.size() - 2; i >= static_cast(dimsToCollapse); i--) { - dims[i] = dims[i - dimsToCollapse]; - } - - for (int i = dimsToCollapse - 1; i >= 0; i--) { - dims[i] = 1; - } - }; - int collapsedDims = 0; - size_t currentJitWorkAmount = domain[domain.size() - 1]; - while (currentJitWorkAmount < minimalJitWorkAmount && currentJitWorkAmount < fullWorkAmount) { - if (static_cast(domain.size()) - collapsedDims - 2 < 0) - break; - - bool canCollapse = true; - for (size_t i = 0; i < inputShapes.size(); i++) { - const size_t last = inputShapes[i].size() - 1; - if ((inputShapes[i][last - 1] != 1 && inputShapes[i][last] == 1) || - (inputShapes[i][last - 1] == 1 && inputShapes[i][last] != 1)) { - canCollapse = false; - break; - } - } - - size_t nextJitWorkAmount = currentJitWorkAmount * domain[domain.size() - 2]; - if (fullWorkAmount / nextJitWorkAmount >= minimalConcurrency) { - currentJitWorkAmount = nextJitWorkAmount; - // if we cannot use dim collapsing we should use tile2D - if (!canCollapse) { - if (TileRank < maxTileRank) { - TileRank++; - continue; - } - - break; - } - collapsedDims++; - for (auto &d : inputShapes) - collapseLastDims(d, 1); - for (auto &d : outputShapes) - collapseLastDims(d, 1); - collapseLastDims(domain, 1); - } else { - break; - } - } - return collapsedDims > 0; - }; - return findDimsToCollapse(); + parallel_exec_domain = schedule.parallel_exec_domain; + harnessWorkAmount = std::accumulate(parallel_exec_domain.begin(), parallel_exec_domain.end(), 1, std::multiplies()); + parallel_exec_domain = getNormalizedDimsBySize(parallel_exec_domain, tensorRank); } void Snippet::SnippetJitExecutor::generate(const jit_snippets_compile_args* jcp) { - using Manager = snippets::pass::Manager; - std::vector backend_passes; -#if defined(OPENVINO_ARCH_X86_64) - using PassPosition = snippets::pass::Manager::PassPosition; - using Place = snippets::pass::Manager::PassPosition::Place; -# define SNIPPETS_REGISTER_PASS(PASS_POS, PASS, ...) \ - backend_passes.emplace_back(PASS_POS, std::make_shared(__VA_ARGS__)) -#else -# define SNIPPETS_REGISTER_PASS(PASS_POS, PASS, ...) -#endif // OPENVINO_ARCH_X86_64 - - SNIPPETS_REGISTER_PASS(PassPosition(Place::PipelineStart), ConvertToSwishCPU); - if (enforceBF16 && snippet_for_generation->has_domain_sensitive_ops()) { - // enforce BF16 precisions to supported operations - // MatMul has to be decomposed to Brgemm operations before enforcement - // Note, MatMul decomposition will be run later again for case if BF16 enforcement is not happened - SNIPPETS_REGISTER_PASS(PassPosition(Place::PipelineStart), ov::snippets::pass::MatMulToBrgemm); - SNIPPETS_REGISTER_PASS(PassPosition(Place::After, "MatMulToBrgemm"), pass::EnforcePrecision, element::f32, element::bf16); - } - - SNIPPETS_REGISTER_PASS(PassPosition(Place::Before, "PropagatePrecision"), ov::intel_cpu::pass::BrgemmToBrgemmCPU); - SNIPPETS_REGISTER_PASS(PassPosition(Place::Before, "PropagatePrecision"), ov::intel_cpu::pass::SetBrgemmCPUBlockingParams); - - SNIPPETS_REGISTER_PASS(PassPosition(Place::PipelineEnd), ov::intel_cpu::pass::RemoveConverts); - SNIPPETS_REGISTER_PASS(PassPosition(Place::PipelineEnd), ov::intel_cpu::pass::MulAddToFMA); - -#undef SNIPPETS_REGISTER_PASS - ov::snippets::lowered::pass::PassPipeline control_flow_markup_pipeline; - CPU_REGISTER_PASS_X64(control_flow_markup_pipeline, ov::intel_cpu::pass::BrgemmBlocking); + CPU_REGISTER_PASS_X64(control_flow_markup_pipeline, ov::intel_cpu::pass::BrgemmBlocking) ov::snippets::lowered::pass::PassPipeline control_flow_pipeline; - CPU_REGISTER_PASS_X64(control_flow_pipeline, ov::intel_cpu::pass::FuseLoadStoreConvert); - // Todo: We don't need shape infer factory now, since shape infer will be done through validate_and_infer_types - // pass std::make_shared() instead of nullptr, when shape infer is performed on LIR - schedule = snippet_for_generation->generate(backend_passes, - control_flow_markup_pipeline, - control_flow_pipeline, - nullptr, - reinterpret_cast(jcp)); + CPU_REGISTER_PASS_X64(control_flow_pipeline, ov::intel_cpu::pass::FuseLoadStoreConvert) + CPU_REGISTER_PASS_X64(control_flow_pipeline, ov::intel_cpu::pass::SetBrgemmCopyBBuffersShape); + schedule = snippetAttrs.snippet->generate_from_linear_ir(control_flow_markup_pipeline, + control_flow_pipeline, + reinterpret_cast(jcp)); } bool Snippet::SnippetJitExecutor::schedule_created() { - return schedule.ptr != nullptr; + return !schedule.lowering_result.compiled_snippet->empty(); } } // namespace node diff --git a/src/plugins/intel_cpu/src/nodes/subgraph.h b/src/plugins/intel_cpu/src/nodes/subgraph.h index ed706443e68ef6..0979aeee807d8f 100644 --- a/src/plugins/intel_cpu/src/nodes/subgraph.h +++ b/src/plugins/intel_cpu/src/nodes/subgraph.h @@ -48,31 +48,24 @@ class Snippet : public Node { // Local copy of subgraph node for canonization & code generation std::shared_ptr snippet; uint64_t bodyHash; - std::vector> inMemBlockedDims; - std::vector> inMemOrders; + std::vector inMemBlockedDims; + std::vector inMemOrders; std::vector inMemPrecs; - std::vector> outMemBlockedDims; - std::vector> outMemOrders; + std::vector outMemBlockedDims; + std::vector outMemOrders; std::vector outMemPrecs; + // todo: used flag if we need extra shape infer, can be removed after [121670] + bool has_non_planar_inputs; }; private: - static const size_t rank6D {6}; - typedef void (*kernel)(const void *, const void *); - // Create a deep local copy of the input snippet to perform canonicalization & code generation - // TODO: Probably better to implement a proper copy constructor - void copy_snippet() const; - void init_body_hash(); + static uint64_t get_body_hash(const std::shared_ptr& snippet); size_t inputNum = 0; size_t outputNum = 0; - // Original subgraph node - std::shared_ptr original_snippet; - mutable std::shared_ptr local_snippet; - // Holds ISA version used is codeGeneration target dnnl::impl::cpu::x64::cpu_isa_t host_isa; @@ -80,18 +73,17 @@ class Snippet : public Node { std::vector dstMemPtrs = {}; mutable SnippetAttrs snippetAttrs; - mutable bool is_canonicalized = false; bool is_dynamic = false; class SnippetExecutor { public: - SnippetExecutor(const SnippetAttrs& attrs, bool is_canonicalized, bool is_dynamic, bool enforceBF16); + SnippetExecutor(SnippetAttrs attrs, bool is_dynamic, bool enforceBF16); virtual void exec(const std::vector& inMemPtrs, const std::vector& outMemPtrs) = 0; virtual ~SnippetExecutor() = default; + std::shared_ptr shapeInference = nullptr; protected: SnippetAttrs snippetAttrs; - bool is_canonicalized = false; bool is_dynamic = false; bool enforceBF16 = false; }; @@ -100,7 +92,7 @@ class Snippet : public Node { class SnippetJitExecutor : public SnippetExecutor { public: - SnippetJitExecutor(const SnippetAttrs& attrs, bool is_canonicalized, bool is_dynamic, bool enforceBF16); + SnippetJitExecutor(SnippetAttrs attrs, bool is_dynamic, bool enforceBF16); void exec(const std::vector& inMemPtrs, const std::vector& outMemPtrs) override; bool schedule_created(); @@ -113,39 +105,25 @@ class Snippet : public Node { size_t numInput = 0; size_t numOutput = 0; - ov::PartialShape canonicalizeBody(bool reshape); - // returns true if exec domain was modified - bool optimizeExecDomain(std::vector&, std::vector&, VectorDims&, size_t&) const; - void generate(const jit_snippets_compile_args*); inline void update_ptrs(jit_snippets_call_args&, const std::vector& inMemPtrs, const std::vector& outMemPtrs); // Evaluates generated snippet using parallel backend void schedule_6d(const std::vector& inMemPtrs, const std::vector& outMemPtrs); void schedule_nt(const std::vector& inMemPtrs, const std::vector& outMemPtrs); - std::shared_ptr snippet_for_generation; - // Holds generated snippet with information about how to schedule it snippets::Schedule schedule; // Holds index of output used as in execution domain // it should be compatible with a schedule's work size - std::vector exec_domain = {}; + std::vector parallel_exec_domain = {}; /// scheduling info size_t tensorRank = 0; - size_t tileRank = 1; - size_t fullWorkAmount = 0; size_t harnessWorkAmount = 0; - const size_t maxTileRank = 2; std::vector dataSize = {}; - // master shape is mutable since we need to modify it inside const shapeInfer method - mutable VectorDims masterShape = {}; - mutable std::vector normInputShapes = {}; - mutable std::vector normOutputShapes = {}; - std::vector start_offset_in = {}; std::vector start_offset_out = {}; diff --git a/src/plugins/intel_cpu/src/nodes/tensoriterator.cpp b/src/plugins/intel_cpu/src/nodes/tensoriterator.cpp index b38ae2fde7e7db..b9b7345b37f493 100644 --- a/src/plugins/intel_cpu/src/nodes/tensoriterator.cpp +++ b/src/plugins/intel_cpu/src/nodes/tensoriterator.cpp @@ -513,7 +513,7 @@ void TensorIterator::createPrimitive() { lastUsedCond = initial_cond_check->getStatus(); } - if (isDynamicNode()) + if (runAsDynamic()) prepareDynamicBuffers(); Node::createPrimitive(); @@ -556,7 +556,7 @@ void TensorIterator::prepareParams() { prepareContinueCond(); prepareLoopBodyCurrentIteration(); - if (!isDynamicNode()) { + if (!runAsDynamic()) { prepareOutputPorts(); prepareBackEdges(); } @@ -568,6 +568,12 @@ void TensorIterator::prepareParams() { } void TensorIterator::execute(dnnl::stream strm) { + //Special case, the subgraph is dynamic while the node has all static shapes + if (runAsDynamic()) { + executeDynamicImpl(strm); + return; + } + sub_graph.ResetInferCount(); bool continue_cond = initial_cond_check->getStatus(); @@ -872,6 +878,10 @@ int TensorIterator::getNumIteration(const std::vector& inputPortMap, co return numIterations; } +bool TensorIterator::runAsDynamic() const { + return isDynamicNode() || Graph::Status::ReadyDynamic == sub_graph.getStatus(); +} + bool TensorIterator::created() const { return getType() == Type::TensorIterator; } diff --git a/src/plugins/intel_cpu/src/nodes/tensoriterator.h b/src/plugins/intel_cpu/src/nodes/tensoriterator.h index 8633be5c28df61..104ee077f9a163 100644 --- a/src/plugins/intel_cpu/src/nodes/tensoriterator.h +++ b/src/plugins/intel_cpu/src/nodes/tensoriterator.h @@ -138,6 +138,7 @@ class TensorIterator : public Node { void reshapeAndFillOutput(dnnl::stream strm); bool checkForInputAndBodyShapesInequality() const; int getNumIteration(const std::vector& inputPortMap, const std::vector& outputPortMap) const; + bool runAsDynamic() const; ExtensionManager::Ptr ext_mng; Graph sub_graph; diff --git a/src/plugins/intel_cpu/src/nodes_factory.cpp b/src/plugins/intel_cpu/src/nodes_factory.cpp index 3afe8aaa32c1d9..7add05741f04e1 100644 --- a/src/plugins/intel_cpu/src/nodes_factory.cpp +++ b/src/plugins/intel_cpu/src/nodes_factory.cpp @@ -79,6 +79,7 @@ #include "nodes/experimental_detectron_generate_proposals_single_image.h" #include "nodes/generate_proposals.h" #include "nodes/embedding_bag_packed_sum.h" +#include "nodes/random_uniform.hpp" #include "nodes/reduce.h" #include "nodes/if.h" #include "nodes/ctc_greedy_decoder.h" @@ -180,6 +181,7 @@ Node::NodesFactory::NodesFactory() INTEL_CPU_NODE(Unique, Type::Unique); INTEL_CPU_NODE(Ngram, Type::Ngram); INTEL_CPU_NODE(Interpolate, Type::Interpolate); + INTEL_CPU_NODE(RandomUniform, Type::RandomUniform); INTEL_CPU_NODE(Reduce, Type::Reduce); INTEL_CPU_NODE(Gather, Type::Gather); INTEL_CPU_NODE(NonMaxSuppression, Type::NonMaxSuppression); diff --git a/src/plugins/intel_cpu/src/plugin.cpp b/src/plugins/intel_cpu/src/plugin.cpp index ddf14ef59a7eab..96be8734ec0dce 100644 --- a/src/plugins/intel_cpu/src/plugin.cpp +++ b/src/plugins/intel_cpu/src/plugin.cpp @@ -38,6 +38,11 @@ #include #include +#if defined(OV_CPU_WITH_ACL) +#include "nodes/executors/acl/acl_ie_scheduler.hpp" +#include "arm_compute/runtime/CPP/CPPScheduler.h" +#endif + using namespace InferenceEngine; #define IE_CPU_PLUGIN_THROW(...) IE_THROW(__VA_ARGS__) << "CPU plugin: " @@ -137,11 +142,44 @@ class CPUSpecialSetup { }; #endif // __linux__ +#if defined(OV_CPU_WITH_ACL) +std::mutex Engine::SchedulerGuard::mutex; +std::weak_ptr Engine::SchedulerGuard::ptr; + +Engine::SchedulerGuard::SchedulerGuard() { +#if IE_THREAD == IE_THREAD_SEQ + // To save state for ACL cores in single-thread mode + arm_compute::Scheduler::set(arm_compute::Scheduler::Type::ST); +#else + arm_compute::Scheduler::set(std::make_shared()); +#endif +} + +std::shared_ptr Engine::SchedulerGuard::instance() { + std::lock_guard lock{SchedulerGuard::mutex}; + auto scheduler_guard_ptr = SchedulerGuard::ptr.lock(); + if (scheduler_guard_ptr == nullptr) { + SchedulerGuard::ptr = scheduler_guard_ptr = std::make_shared(); + } + return scheduler_guard_ptr; +} + +Engine::SchedulerGuard::~SchedulerGuard() { + // To save the state of scheduler after ACLScheduler has been executed + // TODO: find out the cause of the state + std::lock_guard lock{this->dest_mutex}; + arm_compute::Scheduler::set(arm_compute::Scheduler::Type::ST); +} +#endif + Engine::Engine() : deviceFullName(getDeviceFullName()), specialSetup(new CPUSpecialSetup) { _pluginName = "CPU"; extensionManager->AddExtension(std::make_shared()); +#if defined(OV_CPU_WITH_ACL) + scheduler_guard = SchedulerGuard::instance(); +#endif } Engine::~Engine() { diff --git a/src/plugins/intel_cpu/src/plugin.h b/src/plugins/intel_cpu/src/plugin.h index 20c6d315a2c623..3e9d616dcec02c 100644 --- a/src/plugins/intel_cpu/src/plugin.h +++ b/src/plugins/intel_cpu/src/plugin.h @@ -63,6 +63,20 @@ class Engine : public InferenceEngine::IInferencePlugin { const std::string deviceFullName; std::shared_ptr specialSetup; + +#if defined(OV_CPU_WITH_ACL) + struct SchedulerGuard { + SchedulerGuard(); + ~SchedulerGuard(); + static std::shared_ptr instance(); + static std::mutex mutex; + // separate mutex for saving ACLScheduler state in destructor + mutable std::mutex dest_mutex; + static std::weak_ptr ptr; + }; + + std::shared_ptr scheduler_guard; +#endif }; } // namespace intel_cpu diff --git a/src/plugins/intel_cpu/src/shape_inference/custom/matmul.cpp b/src/plugins/intel_cpu/src/shape_inference/custom/matmul.cpp index 1484e35b1793eb..6d327de50d65ed 100644 --- a/src/plugins/intel_cpu/src/shape_inference/custom/matmul.cpp +++ b/src/plugins/intel_cpu/src/shape_inference/custom/matmul.cpp @@ -29,7 +29,7 @@ Result MMShapeInfer::infer( if (rankA == 1 && rankB == 1 && shapeA[0] == shapeB[0]) { return {{m_shapeY}, ShapeInferStatus::success}; } - + OPENVINO_ASSERT(m_out_rank >= 2, "The output rank should be greater or euqal to 2."); m_shapeY[m_out_rank-2] = m_transpose_a ? shapeA[rankA-1] : shapeA[rankA-2]; m_shapeY[m_out_rank-1] = m_transpose_b ? shapeB[rankB-2] : shapeB[rankB-1]; @@ -54,7 +54,14 @@ ShapeInferPtr MMShapeInferFactory::makeShapeInfer() const { const auto output_rank = matmul->get_output_partial_shape(0).rank().get_length(); const bool transpose_a = matmul->get_transpose_a(); const bool transpose_b = matmul->get_transpose_b(); - return std::make_shared(output_rank, transpose_a, transpose_b); + const auto input_rank0 = matmul->get_input_partial_shape(0).rank().get_length(); + const auto input_rank1 = matmul->get_input_partial_shape(1).rank().get_length(); + if (input_rank0 == input_rank1) { + return std::make_shared(output_rank, transpose_a, transpose_b); + } else { + return std::make_shared(make_shape_inference(m_op), EMPTY_PORT_MASK); + } + } else { OPENVINO_THROW("Unexpected operation type in the MatMul shape inference factory"); } diff --git a/src/plugins/intel_cpu/src/shape_inference/custom/matmul.hpp b/src/plugins/intel_cpu/src/shape_inference/custom/matmul.hpp index dd38d984d0883c..25263cfa6fcb67 100644 --- a/src/plugins/intel_cpu/src/shape_inference/custom/matmul.hpp +++ b/src/plugins/intel_cpu/src/shape_inference/custom/matmul.hpp @@ -4,6 +4,7 @@ #include #include "shape_inference/shape_inference_cpu.hpp" +#include #pragma once namespace ov { diff --git a/src/plugins/intel_cpu/src/shape_inference/custom/one_hot.cpp b/src/plugins/intel_cpu/src/shape_inference/custom/one_hot.cpp index fa7352dd344aad..d8630b74f3bc4f 100644 --- a/src/plugins/intel_cpu/src/shape_inference/custom/one_hot.cpp +++ b/src/plugins/intel_cpu/src/shape_inference/custom/one_hot.cpp @@ -21,7 +21,9 @@ Result OneHotShapeInfer::infer( const std::vector>& input_shapes, const std::unordered_map& data_dependency) { auto depth = reinterpret_cast(data_dependency.at(1)->getData())[0]; - + if (depth < 0) { + OPENVINO_THROW("OneHot depth value can't be negative."); + } auto result = input_shapes.front().get(); result.insert(result.begin() + m_axis, depth); diff --git a/src/plugins/intel_cpu/src/shape_inference/custom/random_uniform.cpp b/src/plugins/intel_cpu/src/shape_inference/custom/random_uniform.cpp new file mode 100644 index 00000000000000..cca3c74cce86b0 --- /dev/null +++ b/src/plugins/intel_cpu/src/shape_inference/custom/random_uniform.cpp @@ -0,0 +1,47 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "random_uniform.hpp" +#include + +namespace ov { +namespace intel_cpu { +namespace node { + +// TODO: remove after fixing the issue 123011 +IShapeInfer::Result RandomUniformShapeInfer::infer( + const std::vector>& input_shapes, + const std::unordered_map& data_dependency) { + VectorDims dims; + const auto& mem = data_dependency.at(0); + const auto rank = mem->getShape().getElementsCount(); + auto shape_prc = mem->getDesc().getPrecision(); + switch (shape_prc) { + case InferenceEngine::Precision::I32: { + auto data = reinterpret_cast(mem->getData()); + dims.assign(data, data + rank); + } break; + case InferenceEngine::Precision::I64: { + auto data = reinterpret_cast(mem->getData()); + dims.assign(data, data + rank); + } break; + default: + OPENVINO_THROW("Unexpected Shape input precision: ", shape_prc); + } + + return {{dims}, ShapeInferStatus::success}; +} + +RandomUniformShapeInferFactory::RandomUniformShapeInferFactory(const std::shared_ptr& op) : m_op(op) { + OPENVINO_ASSERT(ov::is_type(m_op), + "Unexpected op type in RandomUniform shape inference factory: ", m_op->get_type_name()); +} + +ShapeInferPtr RandomUniformShapeInferFactory::makeShapeInfer() const { + return std::make_shared(); +} + +} // namespace node +} // namespace intel_cpu +} // namespace ov diff --git a/src/plugins/intel_cpu/src/shape_inference/custom/random_uniform.hpp b/src/plugins/intel_cpu/src/shape_inference/custom/random_uniform.hpp new file mode 100644 index 00000000000000..ce87a966a9cbc9 --- /dev/null +++ b/src/plugins/intel_cpu/src/shape_inference/custom/random_uniform.hpp @@ -0,0 +1,37 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shape_inference/shape_inference_cpu.hpp" +#include + +#pragma once + +namespace ov { +namespace intel_cpu { +namespace node { + +class RandomUniformShapeInfer : public ShapeInferEmptyPads { +public: + explicit RandomUniformShapeInfer() {} + IShapeInfer::Result infer( + const std::vector>& input_shapes, + const std::unordered_map& data_dependency) override; + + port_mask_t get_port_mask() const override { + return PortMask(0); + } +}; + +class RandomUniformShapeInferFactory : public ShapeInferFactory { +public: + explicit RandomUniformShapeInferFactory(const std::shared_ptr& op); + ShapeInferPtr makeShapeInfer() const override; + +private: + std::shared_ptr m_op; +}; + +} // namespace node +} // namespace intel_cpu +} // namespace ov diff --git a/src/plugins/intel_cpu/src/shape_inference/custom/strided_slice.cpp b/src/plugins/intel_cpu/src/shape_inference/custom/strided_slice.cpp index 19918455ae63a1..0ed160bf6e877a 100644 --- a/src/plugins/intel_cpu/src/shape_inference/custom/strided_slice.cpp +++ b/src/plugins/intel_cpu/src/shape_inference/custom/strided_slice.cpp @@ -50,8 +50,15 @@ Result StridedSliceShapeInfer::infer( if ((i >= shapeBegin[0]) || (shapeIn[i] == 0)) { m_outputShape[new_idx] = shapeIn[i]; } else { - auto begin = m_begin_mask_set.count(i) ? 0 : beginPtr[i]; - auto end = m_end_mask_set.count(i) ? shapeIn[i] : endPtr[i]; + int32_t begin = 0; + int32_t end = 0; + if (stridePtr[i] < 0) { + begin = m_begin_mask_set.count(i) ? shapeIn[i] : beginPtr[i]; + end = m_end_mask_set.count(i) ? (-1 - shapeIn[i]) : endPtr[i]; + } else { + begin = m_begin_mask_set.count(i) ? 0 : beginPtr[i]; + end = m_end_mask_set.count(i) ? shapeIn[i] : endPtr[i]; + } m_outputShape[new_idx] = ov::op::slice::get_sliced_value(shapeIn[i], begin, end, stridePtr[i]); } new_idx += 1; diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_copy_b.cpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_copy_b.cpp index e16088a15671b6..643b5d74fc963b 100644 --- a/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_copy_b.cpp +++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_copy_b.cpp @@ -57,39 +57,34 @@ void BrgemmCopyB::custom_constructor_validate_and_infer_types(std::vectorget_shape()); const auto& element_type = get_input_element_type(0); - const auto& pshape = snippets::utils::get_planar_pshape(input(0)); - validate(pshape, element_type); -} - -void BrgemmCopyB::validate(const ov::PartialShape& pshape, const ov::element::Type& element_type) { - NGRAPH_CHECK(one_of(element_type, element::bf16, element::i8), - "BrgemmCopyB doesn't support element type" + element_type.get_type_name()); - - if (pshape.is_dynamic()) { - set_output_type(0, element_type, ov::PartialShape {ov::Dimension::dynamic()}); - if (is_with_compensations()) { - set_output_type(1, ov::element::f32, ov::PartialShape {ov::Dimension::dynamic()}); - } - return; - } - - const auto shape = pshape.get_shape(); - const auto N = *shape.rbegin(); - const auto K = *(shape.rbegin() + 1); - - set_output_type(0, element_type, ov::PartialShape{ov::Dimension(rnd_up(K, m_brgemmVNNIFactor)), - ov::Dimension(rnd_up(N, m_N_blk))}); + const auto& planar_pshape = snippets::utils::get_planar_pshape(shape, port->get_layout()); + set_output_type(0, element_type, planar_pshape); if (is_with_compensations()) { - set_output_type(1, ov::element::f32, ov::PartialShape{ov::Dimension(rnd_up(N, m_N_blk))}); + set_output_type(1, ov::element::f32, planar_pshape); } + validate(planar_pshape, element_type); +} + +void BrgemmCopyB::validate(const ov::PartialShape& planar_pshape, const ov::element::Type& element_type) { + OPENVINO_ASSERT(one_of(element_type, element::bf16, element::i8), + "BrgemmCopyB doesn't support element type" + element_type.get_type_name()); } void intel_cpu::BrgemmCopyB::compute_block_size_values(const size_t blk_size_k, const size_t blk_size_n) { @@ -98,6 +93,17 @@ void intel_cpu::BrgemmCopyB::compute_block_size_values(const size_t blk_size_k, m_N_blk = blk_size_n != 0 ? blk_size_n : *input_shape.rbegin(); } +ov::Shape intel_cpu::BrgemmCopyB::get_data_repacking_shape(const ov::snippets::VectorDims& planar_dims) const { + const auto& N = *planar_dims.rbegin(); + const auto& K = *(planar_dims.rbegin() + 1); + return ov::Shape{rnd_up(K, m_brgemmVNNIFactor), rnd_up(N, m_N_blk)}; +} + +ov::Shape intel_cpu::BrgemmCopyB::get_compensation_shape(const ov::snippets::VectorDims& planar_dims) const { + const auto& N = *planar_dims.rbegin(); + return ov::Shape{rnd_up(N, m_N_blk)}; +} + std::shared_ptr intel_cpu::BrgemmCopyB::clone_with_new_inputs(const OutputVector& new_args) const { INTERNAL_OP_SCOPE(BrgemmRepack_clone_with_new_inputs); check_new_args_count(this, new_args); @@ -120,29 +126,13 @@ BrgemmCopyB::ShapeInfer::ShapeInfer(const std::shared_ptr& n) { OPENVINO_ASSERT(brg_copyb, "Got invalid node in BrgemmCopyB::ShapeInfer"); m_layout = snippets::lowered::PortDescriptorUtils::get_port_descriptor_ptr(n->input(0))->get_layout(); m_num_outs = brg_copyb->get_output_size(); - m_N_blk = brg_copyb->get_n_block_size(); - m_brgemmVNNIFactor = brg_copyb->m_brgemmVNNIFactor; } -snippets::IShapeInferSnippets::Result BrgemmCopyB::ShapeInfer::infer(const std::vector& input_shapes) { +ov::snippets::IShapeInferSnippets::Result BrgemmCopyB::ShapeInfer::infer(const std::vector& input_shapes) { OPENVINO_ASSERT(input_shapes.size() == 1, "Got unexpected number of input shapes"); - const auto& old_shape = input_shapes[0].get(); - snippets::VectorDims planar_shape; - planar_shape.reserve(old_shape.size()); - for (const auto idx : m_layout) - planar_shape.push_back(old_shape[idx]); - const auto N = *planar_shape.rbegin(); - const auto K = *(planar_shape.rbegin() + 1); - OPENVINO_ASSERT(N != DYNAMIC_DIMENSION && K != DYNAMIC_DIMENSION, - "BrgemmCopyB shape infer got dynamic N or K dimension, which is not supported"); - - std::vector new_shapes(m_num_outs); - new_shapes[0].push_back(rnd_up(K, m_brgemmVNNIFactor)); - new_shapes[0].push_back(rnd_up(N, m_N_blk)); - if (m_num_outs == 2) { - new_shapes[1].push_back(rnd_up(N, m_N_blk)); - } - return {new_shapes, snippets::ShapeInferStatus::success}; + const auto planar_shape = ov::snippets::utils::get_planar_vdims(input_shapes[0].get(), m_layout); + std::vector new_shapes(m_num_outs, planar_shape); + return {new_shapes, ov::snippets::ShapeInferStatus::success}; } } // namespace intel_cpu diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_copy_b.hpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_copy_b.hpp index 62703049aeaa38..9274ad026e5f01 100644 --- a/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_copy_b.hpp +++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_copy_b.hpp @@ -5,6 +5,7 @@ #pragma once #include "snippets/op/memory_access.hpp" +#include "snippets/shape_types.hpp" #include namespace ov { @@ -43,7 +44,11 @@ class BrgemmCopyB : public snippets::op::MemoryAccess { void set_k_block_size(size_t block_size) { m_K_blk = block_size; } void set_n_block_size(size_t block_size) { m_N_blk = block_size; } + ov::Shape get_data_repacking_shape(const ov::snippets::VectorDims& planar_dims) const; + ov::Shape get_compensation_shape(const ov::snippets::VectorDims& planar_dims) const; + Type get_type() const { return m_type; } + size_t get_brgemm_vnni_factor() const { return m_brgemmVNNIFactor; } element::Type get_src_element_type() const { return m_src_type; } bool is_with_compensations() const { return m_type == Type::WithCompensations; } @@ -55,8 +60,6 @@ class BrgemmCopyB : public snippets::op::MemoryAccess { class ShapeInfer : public snippets::IShapeInferSnippets { std::vector m_layout{}; size_t m_num_outs = 1; - size_t m_N_blk = 64; - size_t m_brgemmVNNIFactor = 1; public: explicit ShapeInfer(const std::shared_ptr& n); Result infer(const std::vector& input_shapes) override; @@ -64,7 +67,7 @@ class BrgemmCopyB : public snippets::op::MemoryAccess { private: void custom_constructor_validate_and_infer_types(std::vector layout_input = {}); - void validate(const ov::PartialShape& pshape, const ov::element::Type& element_type); + void validate(const ov::PartialShape& planar_pshape, const ov::element::Type& element_type); void compute_block_size_values(const size_t blk_size_k, const size_t blk_size_n); Type m_type = Type::OnlyRepacking; diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_cpu.cpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_cpu.cpp index 03e3325376cbf5..20f7fccafe311a 100644 --- a/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_cpu.cpp +++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_cpu.cpp @@ -114,21 +114,9 @@ void BrgemmCPU::validate_with_scratchpad(const ov::Shape& shape_b) const { // Additional check for 3rd input if (one_of(m_type, Type::WithCompensations, Type::AMX)) { const auto& pshape = get_input_partial_shape(2); - NGRAPH_CHECK(pshape.is_static(), "BRGEMM Scratch must have static shape"); - const auto shape = pshape.to_shape(); - const auto type = get_input_element_type(2); + OPENVINO_ASSERT(pshape.is_static(), "BRGEMM Scratch must have static shape"); if (is_with_compensations()) { - const auto expected_type = ov::element::f32; - NGRAPH_CHECK(expected_type == type, "BRGEMM Scratch with compensations must have FP32 element type"); - const auto N = *shape_b.rbegin(); - // If N block size is not set, there is no meaning in validating the scratchpad shape - if (m_N_blk != N) { - const auto expected_shape = ov::Shape{rnd_up(N, m_N_blk)}; - NGRAPH_CHECK(expected_shape == shape, "BRGEMM Scratch with compensations must have shape {rnd_up(N, m_N_blk)}"); - } - } else { - NGRAPH_CHECK(ov::shape_size(shape) == SCRATCH_BYTE_SIZE && type == ov::element::u8, - "BRGEMM Scratch for space workplace must be static, have U8 element type and size equal to " + std::to_string(SCRATCH_BYTE_SIZE)); + OPENVINO_ASSERT(get_input_element_type(2) == ov::element::f32, "BRGEMM Scratch with compensations must have FP32 element type"); } } } @@ -181,13 +169,5 @@ size_t BrgemmCPU::get_offset_scratch() const { return get_input_offset(2); } -BrgemmCPU::ShapeInfer::ShapeInfer(const std::shared_ptr& n) : Brgemm::ShapeInfer(n) { - const auto& brg = ov::as_type_ptr(n); - OPENVINO_ASSERT(brg, "Got invalid node in BrgemmCPU::ShapeInfer"); - const auto brgemm_copy = brg->is_with_data_repacking() ? brg->get_brgemm_copy() : nullptr; - if (brgemm_copy) - m_io_layouts[1] = snippets::lowered::PortDescriptorUtils::get_port_descriptor_ptr(brgemm_copy->input(0))->get_layout(); -} - } // namespace intel_cpu } // namespace ov diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_cpu.hpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_cpu.hpp index e1957bb66d2be1..bf07b7a8546eac 100644 --- a/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_cpu.hpp +++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_cpu.hpp @@ -69,12 +69,6 @@ class BrgemmCPU : public snippets::op::Brgemm { constexpr static size_t SCRATCH_BYTE_SIZE = 32 * 1024; - class ShapeInfer : public Brgemm::ShapeInfer { - public: - explicit ShapeInfer(const std::shared_ptr& n); - }; - - private: void custom_constructor_validate_and_infer_types(std::vector layout_a, std::vector layout_b, std::vector layout_c); void compute_block_size_values(const size_t blk_size_m, const size_t blk_size_k, const size_t blk_size_n); diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/op/fused_mul_add.cpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/fused_mul_add.cpp index 64db193d7773f1..bae9b2b1dd43cc 100644 --- a/src/plugins/intel_cpu/src/transformations/snippets/x64/op/fused_mul_add.cpp +++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/fused_mul_add.cpp @@ -43,3 +43,8 @@ void FusedMulAdd::validate_and_infer_types() { } set_output_type(0, element_type, pshape); } + +const ov::op::AutoBroadcastSpec& FusedMulAdd::get_autob() const { + static ov::op::AutoBroadcastSpec autob_spec(ov::op::AutoBroadcastType::NUMPY); + return autob_spec; +} diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/op/fused_mul_add.hpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/fused_mul_add.hpp index e55741986a2473..68a730c95aabd2 100644 --- a/src/plugins/intel_cpu/src/transformations/snippets/x64/op/fused_mul_add.hpp +++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/fused_mul_add.hpp @@ -24,6 +24,7 @@ class FusedMulAdd : public ngraph::op::Op { bool visit_attributes(AttributeVisitor& visitor) override; std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; void validate_and_infer_types() override; + const ov::op::AutoBroadcastSpec& get_autob() const override; }; } // namespace intel_cpu diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/lowered/set_brgemm_copy_b_buffers_shape.cpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/lowered/set_brgemm_copy_b_buffers_shape.cpp new file mode 100644 index 00000000000000..91bec8aee60d4a --- /dev/null +++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/lowered/set_brgemm_copy_b_buffers_shape.cpp @@ -0,0 +1,38 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "snippets/itt.hpp" + +#include "set_brgemm_copy_b_buffers_shape.hpp" +#include "snippets/snippets_isa.hpp" +#include "snippets/utils.hpp" + +#include "transformations/snippets/x64/op/brgemm_copy_b.hpp" + +bool ov::intel_cpu::pass::SetBrgemmCopyBBuffersShape::run(snippets::lowered::LinearIR& linear_ir) { + OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::SetBrgemmCopyBBuffersShape") + + auto get_buffer_from_output = [](const snippets::lowered::ExpressionPtr& expr, const size_t out_idx) { + const auto& consumers = expr->get_output_port_connector(out_idx)->get_consumers(); + OPENVINO_ASSERT(consumers.size() == 1, "BrgemmCopyB must have only 1 consumer"); + const auto buffer = ov::as_type_ptr(consumers.begin()->get_expr()->get_node()); + OPENVINO_ASSERT(buffer, "BrgemmCopyB consumer must be Buffer"); + return buffer; + }; + + bool modified = false; + for (const auto& expr : linear_ir) { + if (auto copy_b = ov::as_type_ptr(expr->get_node())) { + const auto buffer = get_buffer_from_output(expr, 0); + const auto& out_desc = expr->get_output_port_descriptor(0); + buffer->set_allocation_shape(copy_b->get_data_repacking_shape(out_desc->get_shape())); + if (copy_b->is_with_compensations()) { + const auto compensations_buffer = get_buffer_from_output(expr, 1); + compensations_buffer->set_allocation_shape(copy_b->get_compensation_shape(out_desc->get_shape())); + } + modified = true; + } + } + return modified; +} diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/lowered/set_brgemm_copy_b_buffers_shape.hpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/lowered/set_brgemm_copy_b_buffers_shape.hpp new file mode 100644 index 00000000000000..fcac51286e00a6 --- /dev/null +++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/lowered/set_brgemm_copy_b_buffers_shape.hpp @@ -0,0 +1,27 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "snippets/lowered/pass/pass.hpp" + +namespace ov { +namespace intel_cpu { +namespace pass { + +/** + * @interface SetBrgemmCopyBBuffersShape + * @brief Sets the allocation shape for the Buffers after BrgemmCopyB node using BrgemmCopyB parameters + * @ingroup snippets + */ +class SetBrgemmCopyBBuffersShape: public snippets::lowered::pass::Pass { +public: + SetBrgemmCopyBBuffersShape() = default; + OPENVINO_RTTI("SetBrgemmCopyBBuffersShape", "Pass"); + bool run(snippets::lowered::LinearIR& linear_ir) override; +}; + +} // namespace pass +} // namespace intel_cpu +} // namespace ov diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/set_brgemm_cpu_blocking_params.cpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/set_brgemm_cpu_blocking_params.cpp index db6f34a4e746f1..df88ffa7edcd82 100644 --- a/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/set_brgemm_cpu_blocking_params.cpp +++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/set_brgemm_cpu_blocking_params.cpp @@ -22,18 +22,6 @@ namespace ov { namespace intel_cpu { -using namespace snippets::lowered; -namespace { -template -void change_desc_shape(const T& port) { - const auto desc = PortDescriptorUtils::get_port_descriptor_ptr(port); - const auto& shape = port.get_shape(); - if (desc->get_shape() != shape) { - desc->set_shape(shape); - } -} -} // namespace - pass::SetBrgemmCPUBlockingParams::SetBrgemmCPUBlockingParams() { MATCHER_SCOPE(SetBrgemmCPUBlockingParams); @@ -73,7 +61,7 @@ pass::SetBrgemmCPUBlockingParams::SetBrgemmCPUBlockingParams() { const bool isAMXSupported = dnnl::impl::cpu::x64::mayiuse(dnnl::impl::cpu::x64::avx512_core_amx); const auto precision = brgemm_copy_b->get_src_element_type(); - const auto brgemmVNNIFactor = 4 / precision.size(); + const auto brgemmVNNIFactor = brgemm_copy_b->get_brgemm_vnni_factor(); const bool use_amx = isAMXSupported && precision != ov::element::f32 && (K % brgemmVNNIFactor == 0) && (N % brgemmVNNIFactor == 0); const size_t copy_b_block_size_k = use_amx ? brgemm_block_size_k : K; @@ -81,18 +69,8 @@ pass::SetBrgemmCPUBlockingParams::SetBrgemmCPUBlockingParams() { brgemm_copy_b->set_k_block_size(copy_b_block_size_k); brgemm_copy_b->set_n_block_size(copy_b_block_size_n); - // since N block size affects output shapes, the validation must be called explicitly right after the block size changing - brgemm_copy_b->validate_and_infer_types(); - change_desc_shape(brgemm_copy_b->output(0)); - if (brgemm_copy_b->is_with_compensations()) - change_desc_shape(brgemm_copy_b->output(1)); } - brgemm->validate_and_infer_types(); - change_desc_shape(brgemm->input(1)); - if (brgemm->is_with_scratchpad()) - change_desc_shape(brgemm->input(2)); - return false; }; diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/shape_inference.cpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/shape_inference.cpp index d09f3f218e67d9..6bb833262a516c 100644 --- a/src/plugins/intel_cpu/src/transformations/snippets/x64/shape_inference.cpp +++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/shape_inference.cpp @@ -28,6 +28,8 @@ ShapeInferPtr CPUShapeInferSnippetsFactory::get_specific_op_shape_infer(const ov { OP::get_type_info_static(), [](const std::shared_ptr& n) { return std::make_shared();} } #define SHAPE_INFER_OP_SPECIFIC(OP) \ { OP::get_type_info_static(), [](const std::shared_ptr& n) { return std::make_shared(n);} } +#define SHAPE_INFER_OP_SPECIFIC_EXTERNAL(OP, InferType) \ + { OP::get_type_info_static(), [](const std::shared_ptr& n) { return std::make_shared(n);} } const CPUShapeInferSnippetsFactory::TRegistry CPUShapeInferSnippetsFactory::specific_ops_registry { SHAPE_INFER_PREDEFINED(ov::intel_cpu::FusedMulAdd, NumpyBroadcastShapeInfer), @@ -36,9 +38,9 @@ const CPUShapeInferSnippetsFactory::TRegistry CPUShapeInferSnippetsFactory::spec SHAPE_INFER_PREDEFINED(ov::intel_cpu::LoadConvertTruncation, PassThroughShapeInfer), SHAPE_INFER_PREDEFINED(ov::intel_cpu::StoreConvertSaturation, PassThroughShapeInfer), SHAPE_INFER_PREDEFINED(ov::intel_cpu::StoreConvertTruncation, PassThroughShapeInfer), + SHAPE_INFER_OP_SPECIFIC_EXTERNAL(ov::intel_cpu::BrgemmCPU, BrgemmShapeInfer), // SHAPE_INFER_OP_SPECIFIC(ov::intel_cpu::BrgemmCopyB), - SHAPE_INFER_OP_SPECIFIC(ov::intel_cpu::BrgemmCPU), }; #undef SHAPE_INFER_OP_SPECIFIC #undef SHAPE_INFER_PREDEFINED diff --git a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp index bff7379e4aa684..f87bfb4f1b055f 100644 --- a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp +++ b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp @@ -195,21 +195,20 @@ void Transformations::PreLpt(const std::vector& defaultPrecis CPU_REGISTER_PASS_COMMON(manager, ov::pass::InitNodeInfo); CPU_REGISTER_PASS_COMMON(manager, ov::pass::MarkShapeOfSubgraphs); - CPU_REGISTER_PASS_COMMON(manager, ov::pass::KeepConstAndDecompression); - CPU_SET_CALLBACK_COMMON(manager, - [](const_node_ptr &node) -> bool { - const auto outputs = node->get_output_target_inputs(0); - return outputs.size() != 1 || !is_type(outputs.begin()->get_node()); - }, - ov::pass::KeepConstAndDecompression); - const bool useLpt = !defaultPrecisions.empty(); if (useLpt) { CPU_REGISTER_PASS_COMMON(manager, ov::pass::MarkDequantizationSubgraph, defaultPrecisions); } else { + // We need to fuse Transpose to MatMul to have a simpler callback for the next transformation + CPU_REGISTER_PASS_COMMON(manager, ov::pass::TransposeMatMul); + const ov::element::TypeVector decompression_precisions{ + ov::element::u8, + // TODO: Uncomment when group decompression is supported + // ov::element::nf4 + }; // MarkDequantizationSubgraph is used even in non-LPT pipeline on X64 platforms - // in order to keep compressed u8 MatMul weights with decompression operations as is - CPU_REGISTER_PASS_X64(manager, ov::pass::MarkDequantizationSubgraph, ov::element::TypeVector{ov::element::u8}, true); + // in order to keep compressed MatMul weights with decompression operations as is + CPU_REGISTER_PASS_X64(manager, ov::pass::MarkDequantizationSubgraph, decompression_precisions, true); CPU_SET_CALLBACK_X64(manager, [](const_node_ptr &node) -> bool { auto get_single_consumer = [](const_node_ptr &node) -> std::shared_ptr { const auto consumers = node->get_output_target_inputs(0); @@ -224,7 +223,15 @@ void Transformations::PreLpt(const std::vector& defaultPrecis if (ov::is_type(consumer)) { return false; - } else if (ov::is_type(consumer)) { + } + // TODO: Uncomment when group decompression is supported + // if (ov::is_type(consumer)) { + // consumer = get_single_consumer(consumer); + // if (consumer != nullptr && ov::is_type(consumer)) { + // return false; + // } + // } + if (ov::is_type(consumer)) { consumer = get_single_consumer(consumer); if (consumer != nullptr && ov::is_type(consumer)) { return false; @@ -234,7 +241,7 @@ void Transformations::PreLpt(const std::vector& defaultPrecis }, ov::pass::MarkDequantizationSubgraph); } - auto get_convert_precisions = []() { + auto get_convert_precisions = [&]() { precisions_map map = { {ov::element::i64, ov::element::i32}, {ov::element::u64, ov::element::i32}, @@ -242,7 +249,6 @@ void Transformations::PreLpt(const std::vector& defaultPrecis {ov::element::u16, ov::element::i32}, {ov::element::u32, ov::element::i32}, {ov::element::f64, ov::element::f32}, - {ov::element::f16, ov::element::f32}, {ov::element::boolean, ov::element::u8}, {ov::element::i4, ov::element::i8}, {ov::element::u4, ov::element::u8} @@ -250,12 +256,37 @@ void Transformations::PreLpt(const std::vector& defaultPrecis // @todo should we always convert to f32 regardless of hardware support, as it is done for f16? if (!dnnl::impl::cpu::x64::mayiuse(dnnl::impl::cpu::x64::avx512_core)) map.insert({ov::element::bf16, ov::element::f32}); - +#if defined(OV_CPU_ARM_ENABLE_FP16) + if (inferencePrecision != ov::element::f16) + map.insert({ov::element::f16, ov::element::f32}); +#else + map.insert({ov::element::f16, ov::element::f32}); +#endif return map; }; static const auto precisions = get_convert_precisions(); type_to_fuse_map type_to_fuse = {{ov::opset10::Convert::get_type_info_static(), fuse_type_to_convert}}; +#if defined(OV_CPU_ARM_ENABLE_FP16) + if (inferencePrecision == ov::element::f16) { + precisions_map fp_convert_precision_map = { + {ov::element::f32, ov::element::f16} + }; + type_to_fuse_map empty_fuse_map = {}; + const bool keep_precision_sensitive_in_fp32 = true; + CPU_REGISTER_PASS_COMMON(manager, ov::pass::ConvertPrecision, fp_convert_precision_map, + empty_fuse_map, + keep_precision_sensitive_in_fp32); + } +#endif + CPU_REGISTER_PASS_COMMON(manager, ov::pass::KeepConstAndDecompression); + CPU_SET_CALLBACK_COMMON(manager, + [](const_node_ptr &node) -> bool { + const auto outputs = node->get_output_target_inputs(0); + return outputs.size() != 1 || !is_type(outputs.begin()->get_node()); + }, + ov::pass::KeepConstAndDecompression); + CPU_REGISTER_PASS_COMMON(manager, ov::pass::AUGRUCellFusion); CPU_REGISTER_PASS_COMMON(manager, ov::pass::CommonOptimizations); CPU_REGISTER_PASS_COMMON(manager, ov::pass::WrapInterpolateIntoTransposes); @@ -589,8 +620,12 @@ void Transformations::MainSnippets(void) { CPU_REGISTER_PASS_X64(snippetsManager, SnippetsMarkSkipped, inferencePrecision != ov::element::f32); CPU_REGISTER_PASS_X64(snippetsManager, snippets::pass::SnippetsTokenization, tokenization_config); + // - MHA has BRGEMM that is supported only on AVX512 platforms + // - CPU Plugin Subgraph supports only f32, bf16 (and quantized) BRGEMM + // [122494] Need to add support of f16 const bool isMHASupported = - dnnl::impl::cpu::x64::mayiuse(dnnl::impl::cpu::x64::avx512_core); // MHA has BRGEMM that is supported only on AVX512 platforms + dnnl::impl::cpu::x64::mayiuse(dnnl::impl::cpu::x64::avx512_core) && + one_of(inferencePrecision, ov::element::bf16, ov::element::f32); if (!isMHASupported) { CPU_DISABLE_PASS_X64(snippetsManager, snippets::pass::TokenizeMHASnippets); CPU_DISABLE_PASS_X64(snippetsManager, snippets::pass::ExtractReshapesFromMHA); diff --git a/src/plugins/intel_cpu/tests/functional/behavior/ov_plugin/properties.cpp b/src/plugins/intel_cpu/tests/functional/behavior/ov_plugin/properties.cpp index 0e959ab865a6ed..10c0a244fcca31 100644 --- a/src/plugins/intel_cpu/tests/functional/behavior/ov_plugin/properties.cpp +++ b/src/plugins/intel_cpu/tests/functional/behavior/ov_plugin/properties.cpp @@ -173,13 +173,18 @@ TEST_F(OVClassConfigTestCPU, smoke_PluginSetConfigAffinityCore) { ASSERT_EQ(false, value); } +#if defined(OV_CPU_ARM_ENABLE_FP16) + const auto expected_precision_for_performance_mode = ov::element::f16; +#else + const auto expected_precision_for_performance_mode = InferenceEngine::with_cpu_x86_bfloat16() ? ov::element::bf16 : ov::element::f32; +#endif + TEST_F(OVClassConfigTestCPU, smoke_PluginSetConfigHintInferencePrecision) { ov::Core ie; auto value = ov::element::f32; - const auto precision = InferenceEngine::with_cpu_x86_bfloat16() ? ov::element::bf16 : ov::element::f32; ASSERT_NO_THROW(value = ie.get_property("CPU", ov::hint::inference_precision)); - ASSERT_EQ(precision, value); + ASSERT_EQ(expected_precision_for_performance_mode, value); const auto forcedPrecision = ov::element::f32; @@ -210,8 +215,6 @@ TEST_F(OVClassConfigTestCPU, smoke_PluginSetConfigEnableProfiling) { ASSERT_EQ(enableProfiling, value); } -const auto expected_precision_for_performance_mode = InferenceEngine::with_cpu_x86_bfloat16() ? ov::element::bf16 : ov::element::f32; - const auto bf16_if_can_be_emulated = InferenceEngine::with_cpu_x86_avx512_core() ? ov::element::bf16 : ov::element::f32; using ExpectedModeAndType = std::pair; diff --git a/src/plugins/intel_cpu/tests/functional/extension/extension.cpp b/src/plugins/intel_cpu/tests/functional/extension/extension.cpp index df4fe4b323836e..b2f9c1c59ac0c1 100644 --- a/src/plugins/intel_cpu/tests/functional/extension/extension.cpp +++ b/src/plugins/intel_cpu/tests/functional/extension/extension.cpp @@ -201,7 +201,7 @@ TEST(Extension, XmlModelWithCustomAbs) { static std::string get_extension_path() { return FileUtils::makePluginLibraryName(ov::test::utils::getExecutableDirectory(), - std::string("template_extension") + IE_BUILD_POSTFIX); + std::string("template_extension") + OV_BUILD_POSTFIX); } diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/ov_infer_request/infer_request_dynamic.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/ov_infer_request/infer_request_dynamic.cpp index fa66f4a2c7801d..9cbe69255db0e0 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/ov_infer_request/infer_request_dynamic.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/ov_infer_request/infer_request_dynamic.cpp @@ -11,11 +11,12 @@ using namespace ov::test::behavior; namespace { const std::vector configs = { - {} + {{ov::hint::inference_precision.name(), ov::element::f32}} }; const std::vector HeteroConfigs = { - {ov::device::priorities(ov::test::utils::DEVICE_CPU)} + {{ov::hint::inference_precision.name(), ov::element::f32}, + {ov::device::priorities(ov::test::utils::DEVICE_CPU)}}, }; std::shared_ptr getFunction1() { diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/ov_infer_request/iteration_chaining.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/ov_infer_request/iteration_chaining.cpp index 2c8678165426b3..567c877be8e8ab 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/ov_infer_request/iteration_chaining.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/ov_infer_request/iteration_chaining.cpp @@ -10,11 +10,12 @@ using namespace ov::test::behavior; namespace { const std::vector configs = { - {} + {{ov::hint::inference_precision.name(), ov::element::f32}} }; const std::vector HeteroConfigs = { - {ov::device::priorities(ov::test::utils::DEVICE_CPU)} + {{ov::hint::inference_precision.name(), ov::element::f32}, + {ov::device::priorities(ov::test::utils::DEVICE_CPU)}}, }; INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, OVIterationChaining, diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/binary_convolution.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/binary_convolution.cpp index 53a249873e2861..da2df80eb7dda0 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/binary_convolution.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/binary_convolution.cpp @@ -4,16 +4,17 @@ #include -#include "single_layer_tests/binary_convolution.hpp" +#include "single_op_tests/binary_convolution.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; +using ov::test::BinaryConvolutionLayerTest; namespace { -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, InferenceEngine::Precision::FP16, - InferenceEngine::Precision::I32}; +const std::vector model_types = { + ov::element::f32, + ov::element::f16, + ov::element::i32}; /* ============= 2D Binary Convolution ============= */ const std::vector> kernels = {{3, 3}, {3, 5}}; @@ -24,6 +25,10 @@ const std::vector> dilations = {{1, 1}, {3, 1}}; const std::vector numOutChannels = {1, 5}; const std::vector padValues = {0, 1}; +const std::vector> input_shapes_static = { + {{ 1, 3, 30, 30}}, +}; + const auto binConv2DParams_ExplicitPadding = ::testing::Combine( ::testing::ValuesIn(kernels), ::testing::ValuesIn(strides), @@ -48,12 +53,8 @@ INSTANTIATE_TEST_SUITE_P( smoke_BinaryConvolution2D_ExplicitPadding, BinaryConvolutionLayerTest, ::testing::Combine( binConv2DParams_ExplicitPadding, - ::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::ValuesIn(model_types), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), BinaryConvolutionLayerTest::getTestCaseName); @@ -61,12 +62,8 @@ INSTANTIATE_TEST_SUITE_P( smoke_BinaryConvolution2D_AutoPadValid, BinaryConvolutionLayerTest, ::testing::Combine( binConv2DParams_ValidPadding, - ::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::ValuesIn(model_types), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), BinaryConvolutionLayerTest::getTestCaseName); diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/bucketize.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/bucketize.cpp index 4ac333bb09c9f4..f1c08370ebfd8f 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/bucketize.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/bucketize.cpp @@ -4,53 +4,52 @@ #include -#include "single_layer_tests/bucketize.hpp" +#include "single_op_tests/bucketize.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - -const std::vector> dataShapes = { - {1, 20, 20}, - {2, 3, 50, 50} -}; - -const std::vector> bucketsShapes = { - {5}, - {20}, - {100} +using ov::test::BucketizeLayerTest; + +namespace { +const std::vector> input_shapes_static = { + //data_shape, bucket_shape + {{ 1, 20, 20 }, {5}}, + {{ 1, 20, 20 }, {20}}, + {{ 1, 20, 20 }, {100}}, + {{ 2, 3, 50, 50 }, {5}}, + {{ 2, 3, 50, 50 }, {20}}, + {{ 2, 3, 50, 50 }, {100}} }; -const std::vector inPrc = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::I64, - InferenceEngine::Precision::I32 +const std::vector in_types = { + ov::element::f32, + ov::element::f16, + ov::element::i64, + ov::element::i32 }; -const std::vector netPrc = { - InferenceEngine::Precision::I64, - InferenceEngine::Precision::I32 +const std::vector model_types = { + ov::element::i64, + ov::element::i32 }; const auto test_Bucketize_right_edge = ::testing::Combine( - ::testing::ValuesIn(dataShapes), - ::testing::ValuesIn(bucketsShapes), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::Values(true), - ::testing::ValuesIn(inPrc), - ::testing::ValuesIn(inPrc), - ::testing::ValuesIn(netPrc), + ::testing::ValuesIn(in_types), + ::testing::ValuesIn(in_types), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_CPU) ); const auto test_Bucketize_left_edge = ::testing::Combine( - ::testing::ValuesIn(dataShapes), - ::testing::ValuesIn(bucketsShapes), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::Values(false), - ::testing::ValuesIn(inPrc), - ::testing::ValuesIn(inPrc), - ::testing::ValuesIn(netPrc), + ::testing::ValuesIn(in_types), + ::testing::ValuesIn(in_types), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_CPU) ); INSTANTIATE_TEST_SUITE_P(smoke_TestsBucketize_right, BucketizeLayerTest, test_Bucketize_right_edge, BucketizeLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_TestsBucketize_left, BucketizeLayerTest, test_Bucketize_left_edge, BucketizeLayerTest::getTestCaseName); +} // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/cum_sum.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/cum_sum.cpp index f55650c696bc2a..19440f5ae88fe7 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/cum_sum.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/cum_sum.cpp @@ -4,27 +4,28 @@ #include -#include "single_layer_tests/cum_sum.hpp" +#include "single_op_tests/cum_sum.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - -const std::vector> shapes = { - {16}, - {9, 15}, - {16, 10, 12}, - {5, 14, 5, 7}, - {7, 8, 6, 7, 13}, - {2, 3, 4, 2, 3, 5}, - {4, 3, 6, 2, 3, 4, 5, 2, 3, 4}, +namespace { +using ov::test::CumSumLayerTest; + +const std::vector> shapes_static = { + {{16}}, + {{9, 15}}, + {{16, 10, 12}}, + {{5, 14, 5, 7}}, + {{7, 8, 6, 7, 13}}, + {{2, 3, 4, 2, 3, 5}}, + {{4, 3, 6, 2, 3, 4, 5, 2, 3, 4}}, }; -const std::vector inputPrecision = { - InferenceEngine::Precision::I8, - InferenceEngine::Precision::U8, - InferenceEngine::Precision::I16, - InferenceEngine::Precision::I32, - InferenceEngine::Precision::FP32 +const std::vector model_types = { + ov::element::i8, + ov::element::u8, + ov::element::i16, + ov::element::i32, + ov::element::f32 }; const std::vector axes = { 0, 1, 2, 3, 4, 5, 6}; @@ -34,8 +35,8 @@ const std::vector exclusive = {true, false}; const std::vector reverse = {true, false}; const auto testCasesNegativeAxis = ::testing::Combine( - ::testing::Values(std::vector{4, 16, 3, 6, 5, 2}), - ::testing::Values(InferenceEngine::Precision::FP32), + ::testing::Values(ov::test::static_shapes_to_test_representation({{4, 16, 3, 6, 5, 2}})), + ::testing::Values(ov::element::f32), ::testing::ValuesIn(negativeAxes), ::testing::ValuesIn(exclusive), ::testing::ValuesIn(reverse), @@ -43,8 +44,8 @@ const auto testCasesNegativeAxis = ::testing::Combine( ); const auto testCasesAxis_0 = ::testing::Combine( - ::testing::ValuesIn(shapes), - ::testing::ValuesIn(inputPrecision), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(shapes_static)), + ::testing::ValuesIn(model_types), ::testing::Values(axes[0]), ::testing::ValuesIn(exclusive), ::testing::ValuesIn(reverse), @@ -52,8 +53,9 @@ const auto testCasesAxis_0 = ::testing::Combine( ); const auto testCasesAxis_1 = ::testing::Combine( - ::testing::ValuesIn(std::vector>(shapes.begin() + 1, shapes.end())), - ::testing::ValuesIn(inputPrecision), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation( + std::vector>(shapes_static.begin() + 1, shapes_static.end()))), + ::testing::ValuesIn(model_types), ::testing::Values(axes[1]), ::testing::ValuesIn(exclusive), ::testing::ValuesIn(reverse), @@ -61,8 +63,9 @@ const auto testCasesAxis_1 = ::testing::Combine( ); const auto testCasesAxis_2 = ::testing::Combine( - ::testing::ValuesIn(std::vector>(shapes.begin() + 2, shapes.end())), - ::testing::ValuesIn(inputPrecision), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation( + std::vector>(shapes_static.begin() + 2, shapes_static.end()))), + ::testing::ValuesIn(model_types), ::testing::Values(axes[2]), ::testing::ValuesIn(exclusive), ::testing::ValuesIn(reverse), @@ -70,8 +73,9 @@ const auto testCasesAxis_2 = ::testing::Combine( ); const auto testCasesAxis_3 = ::testing::Combine( - ::testing::ValuesIn(std::vector>(shapes.begin() + 3, shapes.end())), - ::testing::ValuesIn(inputPrecision), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation( + std::vector>(shapes_static.begin() + 3, shapes_static.end()))), + ::testing::ValuesIn(model_types), ::testing::Values(axes[3]), ::testing::ValuesIn(exclusive), ::testing::ValuesIn(reverse), @@ -79,8 +83,9 @@ const auto testCasesAxis_3 = ::testing::Combine( ); const auto testCasesAxis_4 = ::testing::Combine( - ::testing::ValuesIn(std::vector>(shapes.begin() + 4, shapes.end())), - ::testing::ValuesIn(inputPrecision), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation( + std::vector>(shapes_static.begin() + 4, shapes_static.end()))), + ::testing::ValuesIn(model_types), ::testing::Values(axes[4]), ::testing::ValuesIn(exclusive), ::testing::ValuesIn(reverse), @@ -88,8 +93,9 @@ const auto testCasesAxis_4 = ::testing::Combine( ); const auto testCasesAxis_5 = ::testing::Combine( - ::testing::ValuesIn(std::vector>(shapes.begin() + 5, shapes.end())), - ::testing::ValuesIn(inputPrecision), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation( + std::vector>(shapes_static.begin() + 5, shapes_static.end()))), + ::testing::ValuesIn(model_types), ::testing::Values(axes[5]), ::testing::ValuesIn(exclusive), ::testing::ValuesIn(reverse), @@ -97,8 +103,9 @@ const auto testCasesAxis_5 = ::testing::Combine( ); const auto testCasesAxis_6 = ::testing::Combine( - ::testing::ValuesIn(std::vector>(shapes.begin() + 6, shapes.end())), - ::testing::ValuesIn(inputPrecision), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation( + std::vector>(shapes_static.begin() + 6, shapes_static.end()))), + ::testing::ValuesIn(model_types), ::testing::Values(axes[6]), ::testing::ValuesIn(exclusive), ::testing::ValuesIn(reverse), @@ -113,3 +120,4 @@ INSTANTIATE_TEST_SUITE_P(smoke_TestsCumSum_axis_3, CumSumLayerTest, testCasesAxi INSTANTIATE_TEST_SUITE_P(smoke_TestsCumSum_axis_4, CumSumLayerTest, testCasesAxis_4, CumSumLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_TestsCumSum_axis_5, CumSumLayerTest, testCasesAxis_5, CumSumLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_TestsCumSum_axis_6, CumSumLayerTest, testCasesAxis_6, CumSumLayerTest::getTestCaseName); +} // namespace \ No newline at end of file diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/deformable_psroi_pooling.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/deformable_psroi_pooling.cpp index e277e417c645f6..785aba8c1a1ef8 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/deformable_psroi_pooling.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/deformable_psroi_pooling.cpp @@ -4,17 +4,21 @@ #include -#include "single_layer_tests/deformable_psroi_pooling.hpp" +#include "single_op_tests/deformable_psroi_pooling.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { +using ov::test::DeformablePSROIPoolingLayerTest; + + std::vector> shapes_static { + //dataShape, roisShape, offsetsShape + {{3, 8, 16, 16}, {10, 5}}, + {{1, 8, 67, 32}, {10, 5}}, + {{3, 8, 16, 16}, {10, 5}, {10, 2, 2, 2}}, + {{1, 8, 67, 32}, {10, 5}, {10, 2, 2, 2}}, + }; + const auto deformablePSROIParams = ::testing::Combine( - ::testing::ValuesIn(std::vector>{{3, 8, 16, 16}, {1, 8, 67, 32}}), // data input shape - ::testing::Values(std::vector{10, 5}), // rois input shape - // Empty offsets shape means test without optional third input - ::testing::ValuesIn(std::vector>{{}, {10, 2, 2, 2}}), // offsets input shape ::testing::Values(2), // output_dim ::testing::Values(2), // group_size ::testing::ValuesIn(std::vector{1.0f, 0.5f, 0.0625f}), // spatial scale @@ -24,17 +28,20 @@ namespace { const auto deformablePSROICases_test_params = ::testing::Combine( deformablePSROIParams, - ::testing::Values(InferenceEngine::Precision::FP32), // Net precision - ::testing::Values(ov::test::utils::DEVICE_CPU)); // Device name + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(shapes_static)), + ::testing::Values(ov::element::f32), + ::testing::Values(ov::test::utils::DEVICE_CPU)); INSTANTIATE_TEST_SUITE_P(smoke_TestsDeformablePSROIPooling, DeformablePSROIPoolingLayerTest, deformablePSROICases_test_params, DeformablePSROIPoolingLayerTest::getTestCaseName); + std::vector> shapes_advanced_static { + //dataShape, roisShape, offsetsShape + {{2, 441, 63, 38}, {30, 5}, {30, 2, 3, 3}} + }; + const auto deformablePSROIParams_advanced = ::testing::Combine( - ::testing::ValuesIn(std::vector>{{2, 441, 63, 38}}), // data input shape - ::testing::Values(std::vector{30, 5}), // rois input shape - ::testing::Values(std::vector{30, 2, 3, 3}), // offsets input shape ::testing::Values(49), // output_dim ::testing::Values(3), // group_size ::testing::ValuesIn(std::vector{0.0625}), // spatial scale @@ -44,8 +51,9 @@ namespace { const auto deformablePSROICases_test_params_advanced = ::testing::Combine( deformablePSROIParams_advanced, - ::testing::Values(InferenceEngine::Precision::FP32), // Net precision - ::testing::Values(ov::test::utils::DEVICE_CPU)); // Device name + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(shapes_advanced_static)), + ::testing::Values(ov::element::f32), + ::testing::Values(ov::test::utils::DEVICE_CPU)); INSTANTIATE_TEST_SUITE_P(smoke_TestsDeformablePSROIPooling_advanced, DeformablePSROIPoolingLayerTest, deformablePSROICases_test_params_advanced, DeformablePSROIPoolingLayerTest::getTestCaseName); diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/depth_to_space.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/depth_to_space.cpp index aca6f2e621de51..5e84ede53312b5 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/depth_to_space.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/depth_to_space.cpp @@ -2,20 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include - -#include "single_layer_tests/depth_to_space.hpp" +#include "single_op_tests/depth_to_space.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; -using namespace ngraph::opset3; - namespace { -const std::vector inputPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::U8, - InferenceEngine::Precision::I16, +using ov::test::DepthToSpaceLayerTest; +using ov::op::v0::DepthToSpace; + +const std::vector model_types = { + ov::element::f32, + ov::element::u8, + ov::element::i16, }; const std::vector modes = { @@ -23,14 +20,22 @@ const std::vector modes = { DepthToSpace::DepthToSpaceMode::DEPTH_FIRST }; -const std::vector> inputShapesBS2 = { - {1, 4, 1, 1}, {1, 4, 2, 2}, {1, 4, 3, 3}, {2, 32, 3, 3}, {2, 16, 5, 4}, - {1, 8, 1, 1, 1}, {1, 8, 2, 2, 2}, {1, 8, 3, 3, 3}, {2, 32, 3, 3, 3}, {2, 16, 5, 4, 6} +const std::vector> input_shapes_bs2_static = { + {{1, 4, 1, 1}}, + {{1, 4, 2, 2}}, + {{1, 4, 3, 3}}, + {{2, 32, 3, 3}}, + {{2, 16, 5, 4}}, + {{1, 8, 1, 1, 1}}, + {{1, 8, 2, 2, 2}}, + {{1, 8, 3, 3, 3}}, + {{2, 32, 3, 3, 3}}, + {{2, 16, 5, 4, 6}} }; const auto DepthToSpaceBS2 = ::testing::Combine( - ::testing::ValuesIn(inputShapesBS2), - ::testing::ValuesIn(inputPrecisions), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_bs2_static)), + ::testing::ValuesIn(model_types), ::testing::ValuesIn(modes), ::testing::Values(1, 2), ::testing::Values(ov::test::utils::DEVICE_CPU) @@ -38,14 +43,22 @@ const auto DepthToSpaceBS2 = ::testing::Combine( INSTANTIATE_TEST_SUITE_P(smoke_DepthToSpaceBS2, DepthToSpaceLayerTest, DepthToSpaceBS2, DepthToSpaceLayerTest::getTestCaseName); -const std::vector> inputShapesBS3 = { - {1, 9, 1, 1}, {1, 9, 2, 2}, {1, 9, 3, 3}, {2, 36, 3, 3}, {2, 27, 5, 4}, - {1, 27, 1, 1, 1}, {1, 27, 2, 2, 2}, {1, 27, 3, 3, 3}, {2, 108, 3, 3, 3}, {2, 54, 5, 4, 6} +const std::vector> input_shapes_bs3_static = { + {{1, 9, 1, 1}}, + {{1, 9, 2, 2}}, + {{1, 9, 3, 3}}, + {{2, 36, 3, 3}}, + {{2, 27, 5, 4}}, + {{1, 27, 1, 1, 1}}, + {{1, 27, 2, 2, 2}}, + {{1, 27, 3, 3, 3}}, + {{2, 108, 3, 3, 3}}, + {{2, 54, 5, 4, 6}} }; const auto DepthToSpaceBS3 = ::testing::Combine( - ::testing::ValuesIn(inputShapesBS3), - ::testing::ValuesIn(inputPrecisions), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_bs3_static)), + ::testing::ValuesIn(model_types), ::testing::ValuesIn(modes), ::testing::Values(1, 3), ::testing::Values(ov::test::utils::DEVICE_CPU) diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/gather.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/gather.cpp index b82cadb87d9d80..68a16954a19a85 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/gather.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/gather.cpp @@ -9,6 +9,7 @@ namespace { using ov::test::Gather7LayerTest; using ov::test::Gather8LayerTest; +using ov::test::Gather8withIndicesDataLayerTest; const std::vector model_types = { ov::element::f32, @@ -203,4 +204,29 @@ const auto gatherParamsVec3 = testing::Combine( INSTANTIATE_TEST_CASE_P(smoke_Vec3, Gather8LayerTest, gatherParamsVec3, Gather8LayerTest::getTestCaseName); + +const ov::test::gather7ParamsTuple dummyParams = { + ov::test::static_shapes_to_test_representation(std::vector{{2, 3}}), // input shape + ov::Shape{2, 2}, // indices shape + std::tuple{1, 1}, // axis, batch + ov::element::f32, // model type + ov::test::utils::DEVICE_CPU // device +}; + +const std::vector> indicesData = { + {0, 1, 2, 0}, // positive in bound + {-1, -2, -3, -1}, // negative in bound + {-1, 0, 1, 2}, // positive and negative in bound + {0, 1, 2, 3}, // positive out of bound + {-1, -2, -3, -4}, // negative out of bound + {0, 4, -4, 0}, // positive and negative out of bound +}; + +const auto gatherWithIndicesParams = testing::Combine( + testing::Values(dummyParams), + testing::ValuesIn(indicesData) +); + +INSTANTIATE_TEST_CASE_P(smoke, Gather8withIndicesDataLayerTest, gatherWithIndicesParams, Gather8withIndicesDataLayerTest::getTestCaseName); + } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/interpolate.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/interpolate.cpp index f608a6d8b3b6f8..4da6623cd3a87c 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/interpolate.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/interpolate.cpp @@ -4,190 +4,173 @@ #include -#include "single_layer_tests/interpolate.hpp" +#include "single_op_tests/interpolate.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { +using ov::test::InterpolateLayerTest; -const std::vector netPrecisions = { - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32, +const std::vector model_types = { + ov::element::f16, + ov::element::f32, }; -const std::vector> inShapes = { - {1, 4, 6, 6}, +const std::vector input_shapes_static = { + {1, 4, 6, 6} }; -const std::vector modesWithoutNearest = { - ngraph::op::v4::Interpolate::InterpolateMode::LINEAR, - ngraph::op::v4::Interpolate::InterpolateMode::LINEAR_ONNX, - ngraph::op::v4::Interpolate::InterpolateMode::CUBIC, +const std::vector modes_without_nearest = { + ov::op::v4::Interpolate::InterpolateMode::LINEAR, + ov::op::v4::Interpolate::InterpolateMode::LINEAR_ONNX, + ov::op::v4::Interpolate::InterpolateMode::CUBIC, }; -const std::vector nearestMode = { - ngraph::op::v4::Interpolate::InterpolateMode::NEAREST, +const std::vector nearest_mode = { + ov::op::v4::Interpolate::InterpolateMode::NEAREST, }; -const std::vector coordinateTransformModes = { - ngraph::op::v4::Interpolate::CoordinateTransformMode::TF_HALF_PIXEL_FOR_NN, - ngraph::op::v4::Interpolate::CoordinateTransformMode::PYTORCH_HALF_PIXEL, - ngraph::op::v4::Interpolate::CoordinateTransformMode::HALF_PIXEL, - ngraph::op::v4::Interpolate::CoordinateTransformMode::ASYMMETRIC, - ngraph::op::v4::Interpolate::CoordinateTransformMode::ALIGN_CORNERS, +const std::vector coordinateTransformModes = { + ov::op::v4::Interpolate::CoordinateTransformMode::TF_HALF_PIXEL_FOR_NN, + ov::op::v4::Interpolate::CoordinateTransformMode::PYTORCH_HALF_PIXEL, + ov::op::v4::Interpolate::CoordinateTransformMode::HALF_PIXEL, + ov::op::v4::Interpolate::CoordinateTransformMode::ASYMMETRIC, + ov::op::v4::Interpolate::CoordinateTransformMode::ALIGN_CORNERS, }; -const std::vector shapeCalculationMode = { - ngraph::op::v4::Interpolate::ShapeCalcMode::SIZES, - ngraph::op::v4::Interpolate::ShapeCalcMode::SCALES, +const std::vector shapeCalculationMode = { + ov::op::v4::Interpolate::ShapeCalcMode::SIZES, + ov::op::v4::Interpolate::ShapeCalcMode::SCALES, }; -const std::vector nearestModes = { - ngraph::op::v4::Interpolate::NearestMode::SIMPLE, - ngraph::op::v4::Interpolate::NearestMode::ROUND_PREFER_FLOOR, - ngraph::op::v4::Interpolate::NearestMode::FLOOR, - ngraph::op::v4::Interpolate::NearestMode::CEIL, - ngraph::op::v4::Interpolate::NearestMode::ROUND_PREFER_CEIL, +const std::vector nearest_modes = { + ov::op::v4::Interpolate::NearestMode::SIMPLE, + ov::op::v4::Interpolate::NearestMode::ROUND_PREFER_FLOOR, + ov::op::v4::Interpolate::NearestMode::FLOOR, + ov::op::v4::Interpolate::NearestMode::CEIL, + ov::op::v4::Interpolate::NearestMode::ROUND_PREFER_CEIL, }; -const std::vector defaultNearestMode = { - ngraph::op::v4::Interpolate::NearestMode::ROUND_PREFER_FLOOR, +const std::vector default_nearest_mode = { + ov::op::v4::Interpolate::NearestMode::ROUND_PREFER_FLOOR, }; const std::vector> pads = { - {0, 0, 1, 1}, - {0, 0, 0, 0}, + {0, 0, 1, 1}, + {0, 0, 0, 0}, }; const std::vector antialias = { // Not enabled in Inference Engine // true, - false, + false, }; -const std::vector cubeCoefs = { - -0.75f, +const std::vector cube_coefs = { + -0.75f, }; -const std::vector> defaultAxes = { +const std::vector> default_axes = { {0, 1, 2, 3} }; -const std::vector> targetShapes = { +const std::vector target_shapes = { {1, 4, 8, 8}, }; -const std::vector> defaultScales = { +const std::vector> default_scales = { {1.f, 1.f, 1.333333f, 1.333333f} }; std::map additional_config = {}; const auto interpolateCasesWithoutNearest = ::testing::Combine( - ::testing::ValuesIn(modesWithoutNearest), + ::testing::ValuesIn(modes_without_nearest), ::testing::ValuesIn(shapeCalculationMode), ::testing::ValuesIn(coordinateTransformModes), - ::testing::ValuesIn(defaultNearestMode), + ::testing::ValuesIn(default_nearest_mode), ::testing::ValuesIn(antialias), ::testing::ValuesIn(pads), ::testing::ValuesIn(pads), - ::testing::ValuesIn(cubeCoefs), - ::testing::ValuesIn(defaultAxes), - ::testing::ValuesIn(defaultScales)); + ::testing::ValuesIn(cube_coefs), + ::testing::ValuesIn(default_axes), + ::testing::ValuesIn(default_scales)); const auto interpolateCases = ::testing::Combine( - ::testing::ValuesIn(nearestMode), + ::testing::ValuesIn(nearest_mode), ::testing::ValuesIn(shapeCalculationMode), ::testing::ValuesIn(coordinateTransformModes), - ::testing::ValuesIn(nearestModes), + ::testing::ValuesIn(nearest_modes), ::testing::ValuesIn(antialias), ::testing::ValuesIn(pads), ::testing::ValuesIn(pads), - ::testing::ValuesIn(cubeCoefs), - ::testing::ValuesIn(defaultAxes), - ::testing::ValuesIn(defaultScales)); + ::testing::ValuesIn(cube_coefs), + ::testing::ValuesIn(default_axes), + ::testing::ValuesIn(default_scales)); INSTANTIATE_TEST_SUITE_P(smoke_Interpolate_Basic, InterpolateLayerTest, ::testing::Combine( interpolateCasesWithoutNearest, - ::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(inShapes), - ::testing::ValuesIn(targetShapes), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), + ::testing::ValuesIn(target_shapes), ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::Values(additional_config)), InterpolateLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_Interpolate_Nearest, InterpolateLayerTest, ::testing::Combine( interpolateCases, - ::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(inShapes), - ::testing::ValuesIn(targetShapes), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), + ::testing::ValuesIn(target_shapes), ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::Values(additional_config)), InterpolateLayerTest::getTestCaseName); -const std::vector> targetShapesTailTest = { - {1, 4, 2, 11}, // cover down sample and tails process code path +const std::vector target_shapes_tail_test = { + {1, 4, 2, 11}, // cover down sample and tails process code path }; -const std::vector> defaultScalesTailTest = { +const std::vector> default_scalesTailTest = { {1.f, 1.f, 0.333333f, 1.833333f} }; const auto interpolateCasesWithoutNearestTail = ::testing::Combine( - ::testing::ValuesIn(modesWithoutNearest), + ::testing::ValuesIn(modes_without_nearest), ::testing::ValuesIn(shapeCalculationMode), ::testing::ValuesIn(coordinateTransformModes), - ::testing::ValuesIn(defaultNearestMode), + ::testing::ValuesIn(default_nearest_mode), ::testing::ValuesIn(antialias), ::testing::ValuesIn(pads), ::testing::ValuesIn(pads), - ::testing::ValuesIn(cubeCoefs), - ::testing::ValuesIn(defaultAxes), - ::testing::ValuesIn(defaultScalesTailTest)); + ::testing::ValuesIn(cube_coefs), + ::testing::ValuesIn(default_axes), + ::testing::ValuesIn(default_scalesTailTest)); const auto interpolateCasesTail = ::testing::Combine( - ::testing::ValuesIn(nearestMode), + ::testing::ValuesIn(nearest_mode), ::testing::ValuesIn(shapeCalculationMode), ::testing::ValuesIn(coordinateTransformModes), - ::testing::ValuesIn(nearestModes), + ::testing::ValuesIn(nearest_modes), ::testing::ValuesIn(antialias), ::testing::ValuesIn(pads), ::testing::ValuesIn(pads), - ::testing::ValuesIn(cubeCoefs), - ::testing::ValuesIn(defaultAxes), - ::testing::ValuesIn(defaultScalesTailTest)); + ::testing::ValuesIn(cube_coefs), + ::testing::ValuesIn(default_axes), + ::testing::ValuesIn(default_scalesTailTest)); INSTANTIATE_TEST_SUITE_P(smoke_Interpolate_Basic_Down_Sample_Tail, InterpolateLayerTest, ::testing::Combine( interpolateCasesWithoutNearestTail, - ::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(inShapes), - ::testing::ValuesIn(targetShapesTailTest), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), + ::testing::ValuesIn(target_shapes_tail_test), ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::Values(additional_config)), InterpolateLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_Interpolate_Nearest_Down_Sample_Tail, InterpolateLayerTest, ::testing::Combine( interpolateCasesTail, - ::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(inShapes), - ::testing::ValuesIn(targetShapesTailTest), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), + ::testing::ValuesIn(target_shapes_tail_test), ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::Values(additional_config)), InterpolateLayerTest::getTestCaseName); diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/is_inf.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/is_inf.cpp index 41e8c44950777f..74bec47ba16896 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/is_inf.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/is_inf.cpp @@ -2,14 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include "shared_test_classes/single_layer/is_inf.hpp" - -using namespace ov::test; -using namespace ov::test::subgraph; +#include "single_op_tests/is_inf.hpp" namespace { -std::vector> inShapesStatic = { +using ov::test::IsInfLayerTest; + +std::vector> input_shapes_static = { { {{}, {{2}}} }, { {{}, {{2, 200}}} }, { {{}, {{10, 200}}} }, @@ -29,45 +27,40 @@ std::vector> inShapesStatic = { { {{}, {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}} } }; -std::vector> inShapesDynamic = { +std::vector> input_shapes_dynamic = { {{{ngraph::Dimension(1, 10), 200}, {{2, 200}, {1, 200}}}} }; -std::vector netPrecisions = { +std::vector model_types = { ov::element::f32 }; -std::vector detectNegative = { +std::vector detect_negative = { true, false }; -std::vector detectPositive = { +std::vector detect_positive = { true, false }; std::map additional_config = {}; -const auto isInfParams = ::testing::Combine( - ::testing::ValuesIn(inShapesStatic), - ::testing::ValuesIn(detectNegative), - ::testing::ValuesIn(detectPositive), - ::testing::ValuesIn(netPrecisions), +const auto is_inf_params = ::testing::Combine( + ::testing::ValuesIn(input_shapes_static), + ::testing::ValuesIn(detect_negative), + ::testing::ValuesIn(detect_positive), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::Values(additional_config)); -const auto isInfParamsDyn = ::testing::Combine( - ::testing::ValuesIn(inShapesDynamic), - ::testing::ValuesIn(detectNegative), - ::testing::ValuesIn(detectPositive), - ::testing::ValuesIn(netPrecisions), +const auto is_inf_params_dynamic = ::testing::Combine( + ::testing::ValuesIn(input_shapes_dynamic), + ::testing::ValuesIn(detect_negative), + ::testing::ValuesIn(detect_positive), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::Values(additional_config)); - -TEST_P(IsInfLayerTest, CompareWithRefs) { - run(); -} - -INSTANTIATE_TEST_SUITE_P(smoke_static, IsInfLayerTest, isInfParams, IsInfLayerTest::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(smoke_dynamic, IsInfLayerTest, isInfParamsDyn, IsInfLayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_static, IsInfLayerTest, is_inf_params, IsInfLayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_dynamic, IsInfLayerTest, is_inf_params_dynamic, IsInfLayerTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/log_softmax.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/log_softmax.cpp index ea27ac854503d2..d16edfad904e65 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/log_softmax.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/log_softmax.cpp @@ -4,72 +4,61 @@ #include -#include "single_layer_tests/log_softmax.hpp" +#include "single_op_tests/log_softmax.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { +using ov::test::LogSoftmaxLayerTest; -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, +const std::vector model_types = { + ov::element::f32, }; -const std::vector inputShapes2D = { - InferenceEngine::SizeVector {1, 100}, - InferenceEngine::SizeVector {100, 1}, - InferenceEngine::SizeVector {10, 10}, +const std::vector> input_shapes_2d = { + {{1, 100}}, + {{100, 1}}, + {{10, 10}}, }; -const std::vector axis2D = { +const std::vector axis_2d = { -2, -1, 0, 1 }; -const auto params2D = testing::Combine( - 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(inputShapes2D), - testing::ValuesIn(axis2D), - testing::Values(ov::test::utils::DEVICE_CPU), - testing::Values(std::map()) +const auto params_2d = testing::Combine( + testing::ValuesIn(model_types), + testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_2d)), + testing::ValuesIn(axis_2d), + testing::Values(ov::test::utils::DEVICE_CPU) ); INSTANTIATE_TEST_SUITE_P( smoke_LogSoftmax2D, LogSoftmaxLayerTest, - params2D, + params_2d, LogSoftmaxLayerTest::getTestCaseName ); -const std::vector inputShapes4D = { - InferenceEngine::SizeVector {1, 100, 1, 1}, - InferenceEngine::SizeVector {1, 3, 4, 3}, - InferenceEngine::SizeVector {2, 3, 4, 5}, +const std::vector> input_shapes_4d = { + {{1, 100, 1, 1}}, + {{1, 3, 4, 3}}, + {{2, 3, 4, 5}}, }; -const std::vector axis4D = { +const std::vector axis_4d = { -4, -3, -2, -1, 0, 1, 2, 3 }; -const auto params4D = testing::Combine( - 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(inputShapes4D), - testing::ValuesIn(axis4D), - testing::Values(ov::test::utils::DEVICE_CPU), - testing::Values(std::map()) +const auto params_4d = testing::Combine( + testing::ValuesIn(model_types), + testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_4d)), + testing::ValuesIn(axis_4d), + testing::Values(ov::test::utils::DEVICE_CPU) ); INSTANTIATE_TEST_SUITE_P( smoke_LogSoftmax4D, LogSoftmaxLayerTest, - params4D, + params_4d, LogSoftmaxLayerTest::getTestCaseName ); diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/logical.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/logical.cpp index d8dd2ae9f112fe..6cef30f55580d3 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/logical.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/logical.cpp @@ -2,16 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include "single_layer_tests/logical.hpp" +#include "single_op_tests/logical.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; -using namespace LayerTestsDefinitions::LogicalParams; - namespace { +using ov::test::LogicalLayerTest; -std::map, std::vector>> inputShapes = { +std::map> input_shapes_static = { {{1}, {{1}, {17}, {1, 1}, {2, 18}, {1, 1, 2}, {2, 2, 3}, {1, 1, 2, 3}}}, {{5}, {{1}, {1, 1}, {2, 5}, {1, 1, 1}, {2, 2, 5}}}, {{2, 200}, {{1}, {200}, {1, 200}, {2, 200}, {2, 2, 200}}}, @@ -20,7 +17,7 @@ std::map, std::vector>> inputShapes = { {{2, 1, 1, 3, 1}, {{1}, {1, 3, 4}, {2, 1, 3, 4}, {1, 1, 1, 1, 1}}}, }; -std::map, std::vector>> inputShapesNot = { +std::map> input_shapes_not_static = { {{1}, {}}, {{5}, {}}, {{2, 200}, {}}, @@ -29,53 +26,53 @@ std::map, std::vector>> inputShapesNot {{2, 1, 1, 3, 1}, {}}, }; -std::vector inputsPrecisions = { - InferenceEngine::Precision::BOOL, -}; +std::vector> combine_shapes(const std::map>& input_shapes_static) { + std::vector> result; + for (const auto& input_shape : input_shapes_static) { + for (auto& item : input_shape.second) { + result.push_back({input_shape.first, item}); + } + + if (input_shape.second.empty()) { + result.push_back({input_shape.first, {}}); + } + } + return result; +} -std::vector logicalOpTypes = { - ngraph::helpers::LogicalTypes::LOGICAL_AND, - ngraph::helpers::LogicalTypes::LOGICAL_OR, - ngraph::helpers::LogicalTypes::LOGICAL_XOR, +std::vector model_types = { + ov::element::boolean, }; -std::vector secondInputTypes = { - ngraph::helpers::InputLayerType::CONSTANT, - ngraph::helpers::InputLayerType::PARAMETER, +std::vector logicalOpTypes = { + ov::test::utils::LogicalTypes::LOGICAL_AND, + ov::test::utils::LogicalTypes::LOGICAL_OR, + ov::test::utils::LogicalTypes::LOGICAL_XOR, }; -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, +std::vector secondInputTypes = { + ov::test::utils::InputLayerType::CONSTANT, + ov::test::utils::InputLayerType::PARAMETER, }; std::map additional_config = {}; const auto LogicalTestParams = ::testing::Combine( - ::testing::ValuesIn(LogicalLayerTest::combineShapes(inputShapes)), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(combine_shapes(input_shapes_static))), ::testing::ValuesIn(logicalOpTypes), ::testing::ValuesIn(secondInputTypes), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(inputsPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::Values(additional_config)); const auto LogicalTestParamsNot = ::testing::Combine( - ::testing::ValuesIn(LogicalLayerTest::combineShapes(inputShapesNot)), - ::testing::Values(ngraph::helpers::LogicalTypes::LOGICAL_NOT), - ::testing::Values(ngraph::helpers::InputLayerType::CONSTANT), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(inputsPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(combine_shapes(input_shapes_not_static))), + ::testing::Values(ov::test::utils::LogicalTypes::LOGICAL_NOT), + ::testing::Values(ov::test::utils::InputLayerType::CONSTANT), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::Values(additional_config)); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs, LogicalLayerTest, LogicalTestParams, LogicalLayerTest::getTestCaseName); - INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefsNot, LogicalLayerTest, LogicalTestParamsNot, LogicalLayerTest::getTestCaseName); - } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/loop.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/loop.cpp index f4ee4161943ecd..cadb1cd9998026 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/loop.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/loop.cpp @@ -2,67 +2,37 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include "single_layer_tests/loop.hpp" +#include "single_op_tests/loop.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { +using ov::test::LoopLayerTest; +using ov::test::LOOP_IN_TYPE; + // without clip values increase rapidly, so use only seq_lengths = 2 std::vector execute_first_iteration{true}; std::vector is_body_condition_const{true/*, false*/}; std::vector body_condition{true/*, false*/}; // works only if is_body_condition_const == true std::vector trip_count{1, 10/*, -1*/}; // -1 means infinity - std::vector, LOOP_IN_TYPE>>> inputs = { - {{{32, 1, 10}, LOOP_IN_TYPE::INVARIANT}, {{32, 1, 10}, LOOP_IN_TYPE::INVARIANT}, {{32, 1, 10}, LOOP_IN_TYPE::MERGED}}, - }; - std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; + std::vector input_shapes_static = {{32, 1, 10}}; + + std::vector> inputs_types = { + {LOOP_IN_TYPE::INVARIANT}, + {LOOP_IN_TYPE::MERGED}}; + + std::vector model_types = { + ov::element::f32, + ov::element::f16}; - INSTANTIATE_TEST_SUITE_P(smoke_LoopCommonZeroClip, LoopTest, + INSTANTIATE_TEST_SUITE_P(smoke_LoopCommonZeroClip, LoopLayerTest, ::testing::Combine( ::testing::ValuesIn(execute_first_iteration), ::testing::ValuesIn(is_body_condition_const), ::testing::ValuesIn(body_condition), ::testing::ValuesIn(trip_count), - ::testing::ValuesIn(inputs), - ::testing::ValuesIn(netPrecisions), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), + ::testing::ValuesIn(inputs_types), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_CPU)), - LoopTest::getTestCaseName); - - static const std::vector> static_loop_types { - // GCC4.8 limitation: have to specify type of each element in list - // static_trip_count | max | dynamic_exit | axis - std::tuple{ true , 5, -1, -1 }, // n_iter 5, no dynamic exit - std::tuple{ true , 5, 3, -1 }, // n_iter 3, dynamic exit on 3 - std::tuple{ true , 5, 7, -1 }, // n_iter 5, dynamic exit not reached - std::tuple{ true , -1, 5, -1 }, // n_iter 5, inf loop with dynamic exit on 5 - std::tuple{ true , 5, -1, 1 }, // n_iter 5, const for loop with auto concatenated out - std::tuple{ false , 5, -1, -1 }, // | - std::tuple{ false , 5, 3, -1 }, // | same with dynamic trip count - std::tuple{ false , 5, 7, -1 }, // | - std::tuple{ false , -1, 5, -1 } // | - }; - - using namespace testing; - using namespace InferenceEngine; - - INSTANTIATE_TEST_SUITE_P(smoke_StaticShapeLoop, StaticShapeLoopTest, - Combine( - ValuesIn(std::vector{true, false}), - Values(true), - ValuesIn(static_loop_types), - Values(7), - Values({2, 1, 4}), - Values(Precision::FP32, Precision::I32), - Values(ov::test::utils::DEVICE_CPU), - Values>({}))); - using namespace testing; - INSTANTIATE_TEST_SUITE_P(smoke_TrivialLoop, TrivialLoopTest, - Combine( - Values(Precision::FP32, Precision::I32), - Values({2, 3, 4}), - Values(ov::test::utils::DEVICE_CPU))); - + LoopLayerTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/lrn.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/lrn.cpp index 2554f63e7b7341..40e05cac3976ed 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/lrn.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/lrn.cpp @@ -2,94 +2,88 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "single_layer_tests/lrn.hpp" - -#include - +#include "single_op_tests/lrn.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; +namespace { +using ov::test::LrnLayerTest; + +// common values -const std::vector netPrecisions{ - InferenceEngine::Precision::FP32 -}; +const std::vector model_types{ov::element::f32}; const double alpha = 9.9e-05; const double beta = 2; const double bias = 1.0; const size_t size = 5; -namespace LRN2D { +// 2D -const std::vector> axes = {{1}}; +const std::vector> axes_2d = {{1}}; +std::vector input_shapes_2d_static = {{10, 16}}; INSTANTIATE_TEST_SUITE_P(smoke_LrnCheck_2D, LrnLayerTest, ::testing::Combine(::testing::Values(alpha), ::testing::Values(beta), ::testing::Values(bias), ::testing::Values(size), - ::testing::ValuesIn(axes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(std::vector({10, 16})), + ::testing::ValuesIn(axes_2d), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_2d_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), LrnLayerTest::getTestCaseName); -} // namespace LRN2D -namespace LRN3D { +// 3D -const std::vector> axes = {{1}, {2}}; +const std::vector> axes_3d = {{1}, {2}}; +std::vector input_shapes_3d_static = {{6, 10, 16}}; INSTANTIATE_TEST_SUITE_P(smoke_LrnCheck_3D, LrnLayerTest, ::testing::Combine(::testing::Values(alpha), ::testing::Values(beta), ::testing::Values(bias), ::testing::Values(size), - ::testing::ValuesIn(axes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(std::vector({6, 10, 16})), + ::testing::ValuesIn(axes_3d), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_3d_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), LrnLayerTest::getTestCaseName); -} // namespace LRN3D -namespace LRN4D { -const std::vector> axes = {{1}, {2, 3}, {3, 2}}; +// 4D + +const std::vector> axes_4d = {{1}, {2, 3}, {3, 2}}; +std::vector input_shapes_4d_static = {{10, 10, 3, 8}}; INSTANTIATE_TEST_SUITE_P(smoke_LrnCheck_4D, LrnLayerTest, ::testing::Combine(::testing::Values(alpha), ::testing::Values(beta), ::testing::Values(bias), ::testing::Values(size), - ::testing::ValuesIn(axes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(std::vector({10, 10, 3, 8})), + ::testing::ValuesIn(axes_4d), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_4d_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), LrnLayerTest::getTestCaseName); -} // namespace LRN4D -namespace LRN5D { -const std::vector> axes = {{1}, {2, 3, 4}, {4, 2, 3}}; +// 5D + +const std::vector> axes_5d = {{1}, {2, 3, 4}, {4, 2, 3}}; +std::vector input_shapes_5d_static = {{1, 10, 10, 7, 4}}; + INSTANTIATE_TEST_SUITE_P(smoke_LrnCheck_5D, LrnLayerTest, ::testing::Combine(::testing::Values(alpha), ::testing::Values(beta), ::testing::Values(bias), ::testing::Values(size), - ::testing::ValuesIn(axes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(std::vector({1, 10, 10, 7, 4})), + ::testing::ValuesIn(axes_5d), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_5d_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), LrnLayerTest::getTestCaseName); -} // namespace LRN5D +} // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/lstm_cell.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/lstm_cell.cpp index d950c2c3e2351d..6d44dcb427193e 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/lstm_cell.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/lstm_cell.cpp @@ -4,40 +4,45 @@ #include -#include "single_layer_tests/lstm_cell.hpp" +#include "single_op_tests/lstm_cell.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { - std::vector should_decompose{false, true}; - std::vector batch{5}; - std::vector hidden_size{1, 10}; - std::vector input_size{1, 30}; - std::vector> activations = {{"relu", "sigmoid", "tanh"}, {"sigmoid", "tanh", "tanh"}, - {"tanh", "relu", "sigmoid"}, {"sigmoid", "sigmoid", "sigmoid"}, - {"tanh", "tanh", "tanh"}, {"relu", "relu", "relu"}}; - std::vector clip{0.f, 0.7f}; - std::vector layer_types = { - ngraph::helpers::InputLayerType::CONSTANT, - ngraph::helpers::InputLayerType::PARAMETER - }; - std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - - INSTANTIATE_TEST_SUITE_P(smoke_LSTMCellCommon, LSTMCellTest, - ::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(layer_types), - ::testing::ValuesIn(layer_types), - ::testing::ValuesIn(layer_types), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - LSTMCellTest::getTestCaseName); +using ov::test::LSTMCellTest; +using ov::test::utils::InputLayerType; + +std::vector should_decompose{false, true}; +std::vector batch{5}; +std::vector hidden_size{1, 10}; +std::vector input_size{1, 30}; +std::vector clip{0.f, 0.7f}; + +std::vector> activations = {{"relu", "sigmoid", "tanh"}, {"sigmoid", "tanh", "tanh"}, + {"tanh", "relu", "sigmoid"}, {"sigmoid", "sigmoid", "sigmoid"}, + {"tanh", "tanh", "tanh"}, {"relu", "relu", "relu"}}; + +std::vector layer_types = { + InputLayerType::CONSTANT, + InputLayerType::PARAMETER +}; + +std::vector model_types = { + ov::element::f32, + ov::element::f16}; + +INSTANTIATE_TEST_SUITE_P(smoke_LSTMCellCommon, LSTMCellTest, + ::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(layer_types), + ::testing::ValuesIn(layer_types), + ::testing::ValuesIn(layer_types), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + LSTMCellTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/lstm_sequence.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/lstm_sequence.cpp index 12f1eadc5b5e2a..f9b555f23eb59b 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/lstm_sequence.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/lstm_sequence.cpp @@ -2,81 +2,84 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include "single_layer_tests/lstm_sequence.hpp" +#include "single_op_tests/lstm_sequence.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { - std::vector mode{ngraph::helpers::SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_CONST, - ngraph::helpers::SequenceTestsMode::CONVERT_TO_TI_RAND_SEQ_LEN_CONST, - ngraph::helpers::SequenceTestsMode::CONVERT_TO_TI_RAND_SEQ_LEN_PARAM, - ngraph::helpers::SequenceTestsMode::PURE_SEQ, - ngraph::helpers::SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_CONST, - ngraph::helpers::SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_PARAM}; - // output values increase rapidly without clip, so use only seq_lengths = 2 - std::vector seq_lengths_zero_clip{2}; - std::vector seq_lengths_clip_non_zero{20}; - std::vector batch{10}; - std::vector hidden_size{1, 10}; - std::vector input_size{10}; - std::vector> activations = {{"relu", "sigmoid", "tanh"}, {"sigmoid", "tanh", "tanh"}, - {"tanh", "relu", "sigmoid"}, {"sigmoid", "sigmoid", "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}; +using ov::test::LSTMSequenceTest; +using ov::test::utils::SequenceTestsMode; +using ov::test::utils::InputLayerType; + +std::vector mode{ + SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_CONST, + SequenceTestsMode::CONVERT_TO_TI_RAND_SEQ_LEN_CONST, + SequenceTestsMode::CONVERT_TO_TI_RAND_SEQ_LEN_PARAM, + SequenceTestsMode::PURE_SEQ, + SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_CONST, + SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_PARAM}; + +// output values increase rapidly without clip, so use only seq_lengths = 2 +std::vector seq_lengths_zero_clip{2}; +std::vector seq_lengths_clip_non_zero{20}; +std::vector batch{10}; +std::vector hidden_size{1, 10}; +std::vector input_size{10}; +std::vector> activations = {{"relu", "sigmoid", "tanh"}, {"sigmoid", "tanh", "tanh"}, + {"tanh", "relu", "sigmoid"}, {"sigmoid", "sigmoid", "sigmoid"}, + {"tanh", "tanh", "tanh"}, {"relu", "relu", "relu"}}; +std::vector clip{0.f}; +std::vector clip_non_zeros{0.7f}; +std::vector direction = {ov::op::RecurrentSequenceDirection::FORWARD, + ov::op::RecurrentSequenceDirection::REVERSE, + ov::op::RecurrentSequenceDirection::BIDIRECTIONAL +}; +std::vector model_types = { + ov::element::f32, + ov::element::f16}; - INSTANTIATE_TEST_SUITE_P(smoke_LSTMSequenceCommonZeroClip, LSTMSequenceTest, - ::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(ngraph::helpers::InputLayerType::CONSTANT), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - LSTMSequenceTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_LSTMSequenceCommonZeroClip, LSTMSequenceTest, + ::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(model_types), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + LSTMSequenceTest::getTestCaseName); - INSTANTIATE_TEST_SUITE_P(smoke_LSTMSequenceCommonZeroClipNonconstantWRB, LSTMSequenceTest, - ::testing::Combine( - ::testing::Values(ngraph::helpers::SequenceTestsMode::PURE_SEQ), - ::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(ngraph::helpers::InputLayerType::PARAMETER), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - LSTMSequenceTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_LSTMSequenceCommonZeroClipNonconstantWRB, LSTMSequenceTest, + ::testing::Combine( + ::testing::Values(SequenceTestsMode::PURE_SEQ), + ::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::PARAMETER), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + LSTMSequenceTest::getTestCaseName); - INSTANTIATE_TEST_SUITE_P(smoke_LSTMSequenceCommonClip, LSTMSequenceTest, - ::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(ngraph::helpers::InputLayerType::CONSTANT), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - LSTMSequenceTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_LSTMSequenceCommonClip, LSTMSequenceTest, + ::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(model_types), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + LSTMSequenceTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/mat_mul.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/mat_mul.cpp index b1925b9b8c0ab4..735dba7e8591a8 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/mat_mul.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/mat_mul.cpp @@ -4,60 +4,100 @@ #include -#include "single_layer_tests/mat_mul.hpp" - -using namespace LayerTestsDefinitions; +#include "single_op_tests/mat_mul.hpp" namespace { +using ov::test::MatMulLayerTest; +using ov::test::utils::InputLayerType; + +const std::vector model_types = { + ov::element::f32, + ov::element::i32, +}; -const std::vector inputPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::I32, +std::vector> input_shapes_no_transpose_static { + { {1, 4, 5, 6}, {1, 4, 6, 4} }, + { {4, 5, 6}, {6, 3} }, + { {9, 9, 9}, {9, 9} }, + { {1, 2, 3}, {1, 3, 10} }, + { {1, 2, 3}, {1, 1, 3, 2} }, + { {1, 3, 2, 4}, {2, 1, 4, 2} }, + { {2, 1, 2, 4}, {1, 3, 4, 2} }, + { {3, 2, 4}, {2, 1, 4, 2} }, + { {2, 1, 4, 2}, {3, 2, 4} }, + { {3}, {2, 2, 3, 1} }, + { {2, 2, 1, 3}, {3} }, + { {1, 5}, {5, 1} }, + { {1, 5}, {5} }, + { {5}, {5, 1} }, + { {5}, {5} }, }; -const std::vector shapeRelatedParams = { - { { {1, 4, 5, 6}, false }, { {1, 4, 6, 4}, false } }, - { { {4, 5, 6}, false }, { {6, 3}, false } }, - { { {9, 9, 9}, false }, { {9, 9}, false } }, - { { {1, 2, 3}, false }, { {1, 10, 3}, true } }, - { { {1, 2, 3}, false }, { {1, 3, 10}, false } }, - { { {1, 2, 3}, false }, { {1, 1, 3, 2}, false } }, - { { {1, 3, 2, 4}, false }, { {2, 1, 4, 2}, false } }, - { { {2, 1, 2, 4}, false }, { {1, 3, 4, 2}, false } }, - { { {3, 2, 4}, false }, { {2, 1, 4, 2}, false } }, - { { {2, 1, 4, 2}, false }, { {3, 2, 4}, false } }, - { { {2, 1, 2, 3}, true }, { {3, 2, 4}, false } }, - { { {2, 1, 3, 2}, false }, { {3, 4, 2}, true } }, - { { {2, 1, 2, 3}, true }, { {3, 4, 2}, true } }, - { { {3}, false }, { {2, 2, 3, 1}, false } }, - { { {2, 2, 1, 3}, false }, { {3}, false } }, - { { {1, 5}, false }, { {5, 1}, false } }, - { { {5, 1}, true }, { {5, 1}, false } }, - { { {1, 5}, false }, { {10, 5}, true } }, - { { {1, 5}, false }, { {5}, false } }, - { { {5}, false }, { {5, 1}, false } }, - { { {5}, false }, { {5}, false } }, - { { {5}, true }, { {5}, true } } +std::vector> input_shapes_first_transpose_static { + { {2, 1, 2, 3}, {3, 2, 4} }, + { {5, 1}, {5, 1} }, }; -std::vector secondaryInputTypes = { - ngraph::helpers::InputLayerType::CONSTANT, - ngraph::helpers::InputLayerType::PARAMETER, +std::vector> input_shapes_second_transpose_static { + { {1, 2, 3}, {1, 10, 3} }, + { {2, 1, 3, 2}, {3, 4, 2} }, + { {1, 5}, {10, 5} }, +}; + +std::vector> input_shapes_both_transpose_static { + { {2, 1, 2, 3}, {3, 4, 2} }, + { {5}, {5}, }, +}; + + +std::vector secondary_input_types = { + InputLayerType::CONSTANT, + InputLayerType::PARAMETER, }; std::map additional_config = {}; -INSTANTIATE_TEST_SUITE_P(smoke_MatMul, MatMulTest, +INSTANTIATE_TEST_SUITE_P(smoke_MatMul_NoTranspose, MatMulLayerTest, + ::testing::Combine( + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_no_transpose_static)), + ::testing::Values(std::make_pair(false, false)), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(secondary_input_types), + ::testing::Values(ov::test::utils::DEVICE_CPU), + ::testing::Values(additional_config)), + MatMulLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_MatMul_FirstTranspose, MatMulLayerTest, + ::testing::Combine( + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_first_transpose_static)), + ::testing::Values(std::make_pair(true, false)), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(secondary_input_types), + ::testing::Values(ov::test::utils::DEVICE_CPU), + ::testing::Values(additional_config)), + MatMulLayerTest::getTestCaseName); + + +INSTANTIATE_TEST_SUITE_P(smoke_MatMul_SecondTranspose, MatMulLayerTest, + ::testing::Combine( + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_second_transpose_static)), + ::testing::Values(std::make_pair(false, true)), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(secondary_input_types), + ::testing::Values(ov::test::utils::DEVICE_CPU), + ::testing::Values(additional_config)), + MatMulLayerTest::getTestCaseName); + + +INSTANTIATE_TEST_SUITE_P(smoke_MatMul_BothTranspose, MatMulLayerTest, ::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::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_both_transpose_static)), + ::testing::Values(std::make_pair(true, true)), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(secondary_input_types), ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::Values(additional_config)), - MatMulTest::getTestCaseName); + MatMulLayerTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/minimum_maximum.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/minimum_maximum.cpp index 5330cf472cff40..6244afb8216c04 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/minimum_maximum.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/minimum_maximum.cpp @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include "single_layer_tests/minimum_maximum.hpp" +#include "single_op_tests/minimum_maximum.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { +using ov::test::MaxMinLayerTest; +using ov::test::utils::InputLayerType; +using ov::test::utils::MinMaxOpType; -const std::vector>> inShapes = { +const std::vector> input_shapes_static = { {{2}, {1}}, {{1, 1, 1, 3}, {1}}, {{1, 2, 4}, {1}}, @@ -20,31 +20,27 @@ const std::vector>> inShapes = { {{8, 1, 6, 1}, {7, 1, 5}}, }; -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, +const std::vector model_types = { + ov::element::f32, + ov::element::f16, }; -const std::vector opType = { - ngraph::helpers::MinMaxOpType::MINIMUM, - ngraph::helpers::MinMaxOpType::MAXIMUM, +const std::vector op_types = { + MinMaxOpType::MINIMUM, + MinMaxOpType::MAXIMUM, }; -const std::vector inputType = { - ngraph::helpers::InputLayerType::CONSTANT, - ngraph::helpers::InputLayerType::PARAMETER, +const std::vector second_input_types = { + InputLayerType::CONSTANT, + InputLayerType::PARAMETER, }; INSTANTIATE_TEST_SUITE_P(smoke_maximum, MaxMinLayerTest, ::testing::Combine( - ::testing::ValuesIn(inShapes), - ::testing::ValuesIn(opType), - ::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(inputType), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), + ::testing::ValuesIn(op_types), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(second_input_types), ::testing::Values(ov::test::utils::DEVICE_CPU)), MaxMinLayerTest::getTestCaseName); diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/mvn.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/mvn.cpp index 8cf667daaebb75..9daa95881ec134 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/mvn.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/mvn.cpp @@ -4,38 +4,40 @@ #include -#include "single_layer_tests/mvn.hpp" +#include "single_op_tests/mvn.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - -const std::vector emptyAcrossChannels = {{}}; -const std::vector emptyReductionAxes = {{}}; - -const std::vector> inputShapes = { - {8}, - {1, 16}, - {3, 19}, - {1, 32, 17}, - {1, 37, 9}, - {1, 16, 5, 8}, - {2, 19, 5, 10}, - {7, 32, 2, 8}, - {5, 8, 3, 5}, - {4, 41, 6, 9}, - {1, 32, 8, 1, 6}, - {1, 9, 1, 15, 9}, - {6, 64, 6, 1, 18}, - {2, 31, 2, 9, 1}, - {10, 16, 5, 10, 6} -}; - -const std::vector acrossChannels = { +namespace { +using ov::test::Mvn1LayerTest; +using ov::test::Mvn6LayerTest; + +const std::vector empty_across_channels = {{}}; +const std::vector empty_reduction_axes = {{}}; + +const std::vector> input_shapes_static = { + {{8}}, + {{1, 16}}, + {{3, 19}}, + {{1, 32, 17}}, + {{1, 37, 9}}, + {{1, 16, 5, 8}}, + {{2, 19, 5, 10}}, + {{7, 32, 2, 8}}, + {{5, 8, 3, 5}}, + {{4, 41, 6, 9}}, + {{1, 32, 8, 1, 6}}, + {{1, 9, 1, 15, 9}}, + {{6, 64, 6, 1, 18}}, + {{2, 31, 2, 9, 1}}, + {{10, 16, 5, 10, 6}} +}; + +const std::vector across_channels = { true, false }; -const std::vector normalizeVariance = { +const std::vector normalize_variance = { true, false }; @@ -44,39 +46,44 @@ const std::vector epsilon = { 0.000000001 }; -std::vector dataPrecisions = { - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32 +std::vector model_types = { + ov::element::f16, + ov::element::f32 }; -const auto MvnAcrossChannels = ::testing::Combine( - ::testing::ValuesIn(inputShapes), - ::testing::ValuesIn(dataPrecisions), - ::testing::ValuesIn(emptyReductionAxes), - ::testing::ValuesIn(acrossChannels), - ::testing::ValuesIn(normalizeVariance), +const auto Mvnacross_channels = ::testing::Combine( + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(empty_reduction_axes), + ::testing::ValuesIn(across_channels), + ::testing::ValuesIn(normalize_variance), ::testing::ValuesIn(epsilon), ::testing::Values(ov::test::utils::DEVICE_CPU) ); +const std::vector> input_shapes_reduction_axes_static = { + {{1, 10, 5, 17}}, + {{1, 3, 8, 9}} +}; + const auto MvnReductionAxes = ::testing::Combine( - ::testing::ValuesIn(std::vector>{{1, 10, 5, 17}, {1, 3, 8, 9}}), - ::testing::Values(InferenceEngine::Precision::FP32), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_reduction_axes_static)), + ::testing::Values(ov::element::f32), ::testing::ValuesIn(std::vector{{1, 2, 3}, {2, 3}}), - ::testing::ValuesIn(emptyAcrossChannels), - ::testing::ValuesIn(normalizeVariance), + ::testing::ValuesIn(empty_across_channels), + ::testing::ValuesIn(normalize_variance), ::testing::ValuesIn(epsilon), ::testing::Values(ov::test::utils::DEVICE_CPU) ); -INSTANTIATE_TEST_SUITE_P(smoke_TestsMVN_AcrossChannels, Mvn1LayerTest, MvnAcrossChannels, Mvn1LayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_TestsMVN_across_channels, Mvn1LayerTest, Mvnacross_channels, Mvn1LayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_TestsMVN_ReductionAxes, Mvn1LayerTest, MvnReductionAxes, Mvn1LayerTest::getTestCaseName); -std::vector idxPrecisions = { - InferenceEngine::Precision::I32, - InferenceEngine::Precision::I64 +std::vector idx_types = { + ov::element::i32, + ov::element::i64 }; const std::vector epsMode = { @@ -88,98 +95,139 @@ const std::vector epsilonF = { 0.0001f }; +const std::vector> input_shapes_5d_static = { + {{1, 10, 5, 7, 8}}, + {{1, 3, 8, 9, 49}} +}; + INSTANTIATE_TEST_SUITE_P(smoke_MVN_5D, Mvn6LayerTest, ::testing::Combine( - ::testing::ValuesIn(std::vector>{{1, 10, 5, 7, 8}, {1, 3, 8, 9, 49}}), - ::testing::ValuesIn(dataPrecisions), - ::testing::ValuesIn(idxPrecisions), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_5d_static)), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(idx_types), ::testing::ValuesIn(std::vector>{{1, 2, 3, 4}, {2, 3, 4}, {-3, -2, -1}, {-1, -4, -2, -3}}), - ::testing::ValuesIn(normalizeVariance), + ::testing::ValuesIn(normalize_variance), ::testing::ValuesIn(epsilonF), ::testing::ValuesIn(epsMode), ::testing::Values(ov::test::utils::DEVICE_CPU)), Mvn6LayerTest::getTestCaseName); +const std::vector> input_shapes_4d_static = { + {{1, 10, 5, 17}}, + {{1, 3, 8, 9}} +}; + INSTANTIATE_TEST_SUITE_P(smoke_MVN_4D, Mvn6LayerTest, ::testing::Combine( - ::testing::ValuesIn(std::vector>{{1, 10, 5, 17}, {1, 3, 8, 9}}), - ::testing::ValuesIn(dataPrecisions), - ::testing::ValuesIn(idxPrecisions), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_4d_static)), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(idx_types), ::testing::ValuesIn(std::vector>{{1, 2, 3}, {2, 3}, {-2, -1}, {-2, -1, -3}}), - ::testing::ValuesIn(normalizeVariance), + ::testing::ValuesIn(normalize_variance), ::testing::ValuesIn(epsilonF), ::testing::ValuesIn(epsMode), ::testing::Values(ov::test::utils::DEVICE_CPU)), Mvn6LayerTest::getTestCaseName); +const std::vector> input_shapes_3d_static = { + {{1, 32, 17}}, + {{1, 37, 9}} +}; + INSTANTIATE_TEST_SUITE_P(smoke_MVN_3D, Mvn6LayerTest, ::testing::Combine( - ::testing::ValuesIn(std::vector>{{1, 32, 17}, {1, 37, 9}}), - ::testing::ValuesIn(dataPrecisions), - ::testing::ValuesIn(idxPrecisions), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_3d_static)), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(idx_types), ::testing::ValuesIn(std::vector>{{1, 2}, {2}, {-1}, {-1, -2}}), - ::testing::ValuesIn(normalizeVariance), + ::testing::ValuesIn(normalize_variance), ::testing::ValuesIn(epsilonF), ::testing::ValuesIn(epsMode), ::testing::Values(ov::test::utils::DEVICE_CPU)), Mvn6LayerTest::getTestCaseName); +const std::vector> input_shapes_2d_static = { + {{3, 5}}, + {{2, 55}} +}; + INSTANTIATE_TEST_SUITE_P(smoke_MVN_2D, Mvn6LayerTest, ::testing::Combine( - ::testing::ValuesIn(std::vector>{{3, 5}, {2, 55}}), - ::testing::ValuesIn(dataPrecisions), - ::testing::ValuesIn(idxPrecisions), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_2d_static)), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(idx_types), ::testing::ValuesIn(std::vector>{{1}}), - ::testing::ValuesIn(normalizeVariance), + ::testing::ValuesIn(normalize_variance), ::testing::ValuesIn(epsilonF), ::testing::ValuesIn(epsMode), ::testing::Values(ov::test::utils::DEVICE_CPU)), Mvn6LayerTest::getTestCaseName); +const std::vector> input_shapes_1d_static = { + {{3}}, + {{9}}, + {{55}} +}; + INSTANTIATE_TEST_SUITE_P(smoke_MVN_1D, Mvn6LayerTest, ::testing::Combine( - ::testing::ValuesIn(std::vector>{{3}, {9}, {55}}), - ::testing::ValuesIn(dataPrecisions), - ::testing::ValuesIn(idxPrecisions), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_1d_static)), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(idx_types), ::testing::ValuesIn(std::vector>{{0}}), - ::testing::ValuesIn(normalizeVariance), + ::testing::ValuesIn(normalize_variance), ::testing::ValuesIn(epsilonF), ::testing::ValuesIn(epsMode), ::testing::Values(ov::test::utils::DEVICE_CPU)), Mvn6LayerTest::getTestCaseName); +const std::vector> input_shapes_decomposition_3d_static = { + {{1, 32, 17}}, + {{1, 37, 9}} +}; + INSTANTIATE_TEST_SUITE_P(smoke_Decomposition_3D, Mvn6LayerTest, ::testing::Combine( - ::testing::ValuesIn(std::vector>{{1, 32, 17}, {1, 37, 9}}), - ::testing::ValuesIn(dataPrecisions), - ::testing::ValuesIn(idxPrecisions), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_decomposition_3d_static)), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(idx_types), ::testing::ValuesIn(std::vector>{{0, 1, 2}, {0}, {1}}), - ::testing::ValuesIn(normalizeVariance), + ::testing::ValuesIn(normalize_variance), ::testing::ValuesIn(epsilonF), ::testing::ValuesIn(epsMode), ::testing::Values(ov::test::utils::DEVICE_CPU)), Mvn6LayerTest::getTestCaseName); +const std::vector> input_shapes_decomposition_4d_static = { + {{1, 16, 5, 8}}, + {{2, 19, 5, 10}} +}; + INSTANTIATE_TEST_SUITE_P(smoke_Decomposition_4D, Mvn6LayerTest, ::testing::Combine( - ::testing::ValuesIn(std::vector>{{1, 16, 5, 8}, {2, 19, 5, 10}}), - ::testing::ValuesIn(dataPrecisions), - ::testing::ValuesIn(idxPrecisions), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_decomposition_4d_static)), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(idx_types), ::testing::ValuesIn(std::vector>{{0, 1, 2, 3}, {0, 1, 2}, {0, 3}, {0}, {1}, {2}, {3}}), - ::testing::ValuesIn(normalizeVariance), + ::testing::ValuesIn(normalize_variance), ::testing::ValuesIn(epsilonF), ::testing::ValuesIn(epsMode), ::testing::Values(ov::test::utils::DEVICE_CPU)), Mvn6LayerTest::getTestCaseName); +const std::vector> input_shapes_decomposition_10d_static = { + {{1, 3, 5, 4, 2, 6, 5, 3, 2, 1}}, +}; + INSTANTIATE_TEST_SUITE_P(smoke_Decomposition_10D, Mvn6LayerTest, ::testing::Combine( - ::testing::ValuesIn(std::vector>{{1, 3, 5, 4, 2, 6, 5, 3, 2, 1}}), - ::testing::ValuesIn(dataPrecisions), - ::testing::ValuesIn(idxPrecisions), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_decomposition_10d_static)), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(idx_types), ::testing::ValuesIn(std::vector>{{0, 1, 5, 8, 9}, {0, 1, 2, 3}, {0, 1, 2}, {0, 3}, {0}, {3}, {5}, {9}}), - ::testing::ValuesIn(normalizeVariance), + ::testing::ValuesIn(normalize_variance), ::testing::ValuesIn(epsilonF), ::testing::ValuesIn(epsMode), ::testing::Values(ov::test::utils::DEVICE_CPU)), Mvn6LayerTest::getTestCaseName); +} // namespace \ No newline at end of file diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/nonzero.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/nonzero.cpp index bbbb7f888dcd2f..629392a5d99829 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/nonzero.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/nonzero.cpp @@ -2,35 +2,34 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "single_layer_tests/nonzero.hpp" +#include "single_op_tests/nonzero.hpp" #include "common_test_utils/test_constants.hpp" #include -using namespace ngraph::helpers; -using namespace LayerTestsDefinitions; - namespace { - std::vector> inShapes = { - {1000}, - {4, 1000}, - {2, 4, 1000}, - {2, 4, 4, 1000}, - {2, 4, 4, 2, 1000}, - }; +using ov::test::NonZeroLayerTest; + +std::vector> input_shapes_static = { + {{1000}}, + {{4, 1000}}, + {{2, 4, 1000}}, + {{2, 4, 4, 1000}}, + {{2, 4, 4, 2, 1000}}, +}; - const std::vector inputPrecisions = { - InferenceEngine::Precision::I32, - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::U8, - }; +const std::vector model_types = { + ov::element::i32, + ov::element::f16, + ov::element::u8, +}; - ConfigMap config; +std::map config = {}; - INSTANTIATE_TEST_SUITE_P(smoke_nonzero, NonZeroLayerTest, - ::testing::Combine( - ::testing::ValuesIn(inShapes), - ::testing::ValuesIn(inputPrecisions), - ::testing::Values(ov::test::utils::DEVICE_CPU), - ::testing::Values(config)), - NonZeroLayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_nonzero, NonZeroLayerTest, + ::testing::Combine( + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::utils::DEVICE_CPU), + ::testing::Values(config)), + NonZeroLayerTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/normalize_l2.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/normalize_l2.cpp index 6941437751d567..7fbf1207bc4e29 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/normalize_l2.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/normalize_l2.cpp @@ -4,36 +4,38 @@ #include -#include "single_layer_tests/normalize_l2.hpp" - -using namespace LayerTestsDefinitions; +#include "single_op_tests/normalize_l2.hpp" namespace { -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16 +using ov::test::NormalizeL2LayerTest; + +const std::vector model_types = { + ov::element::f32, + ov::element::f16 }; const std::vector eps = {1e-12f, 1e-6f, 1e-3f, 0.1f, 100}; -const std::vector epsMode = { - ngraph::op::EpsMode::ADD, - ngraph::op::EpsMode::MAX, +const std::vector eps_modes = { + ov::op::EpsMode::ADD, + ov::op::EpsMode::MAX, }; /* ============= 1D ============= */ // [SKIPPED][CPU] Unsupported rank, Issue: 35627 -const std::vector> axes_1D = { +const std::vector> axes_1d = { {}, {0} }; +std::vector input_shape_1d_static = {{5}}; + const auto normL2params_1D = testing::Combine( - testing::ValuesIn(axes_1D), + testing::ValuesIn(axes_1d), testing::ValuesIn(eps), - testing::ValuesIn(epsMode), - testing::ValuesIn(std::vector>({{5}})), - testing::ValuesIn(netPrecisions), + testing::ValuesIn(eps_modes), + testing::Values(ov::test::static_shapes_to_test_representation(input_shape_1d_static)), + testing::ValuesIn(model_types), testing::Values(ov::test::utils::DEVICE_CPU) ); @@ -54,12 +56,14 @@ const std::vector> axes_2D = { // {0, 1}, }; +std::vector input_shape_2d_static = {{5, 3}}; + const auto normL2params_2D = testing::Combine( testing::ValuesIn(axes_2D), testing::ValuesIn(eps), - testing::ValuesIn(epsMode), - testing::ValuesIn(std::vector>({{5, 3}})), - testing::ValuesIn(netPrecisions), + testing::ValuesIn(eps_modes), + testing::Values(ov::test::static_shapes_to_test_representation(input_shape_2d_static)), + testing::ValuesIn(model_types), testing::Values(ov::test::utils::DEVICE_CPU) ); @@ -84,12 +88,14 @@ const std::vector> axes_3D = { // {0, 1, 2} }; +std::vector input_shape_3d_static = {{2, 5, 3}}; + const auto normL2params_3D = testing::Combine( testing::ValuesIn(axes_3D), testing::ValuesIn(eps), - testing::ValuesIn(epsMode), - testing::ValuesIn(std::vector>({{2, 5, 3}})), - testing::ValuesIn(netPrecisions), + testing::ValuesIn(eps_modes), + testing::Values(ov::test::static_shapes_to_test_representation(input_shape_3d_static)), + testing::ValuesIn(model_types), testing::Values(ov::test::utils::DEVICE_CPU) ); @@ -117,12 +123,14 @@ const std::vector> axes_4D = { // {0, 1, 2, 3} }; +std::vector input_shape_4d_static = {{2, 3, 10, 5}}; + const auto normL2params_4D = testing::Combine( testing::ValuesIn(axes_4D), testing::ValuesIn(eps), - testing::ValuesIn(epsMode), - testing::ValuesIn(std::vector>({{2, 3, 10, 5}})), - testing::ValuesIn(netPrecisions), + testing::ValuesIn(eps_modes), + testing::Values(ov::test::static_shapes_to_test_representation(input_shape_4d_static)), + testing::ValuesIn(model_types), testing::Values(ov::test::utils::DEVICE_CPU) ); @@ -153,12 +161,14 @@ const std::vector> axes_5D = { {0, 1, 2, 3} }; +std::vector input_shape_5d_static = {{2, 2, 3, 10, 5}}; + const auto normL2params_5D = testing::Combine( testing::ValuesIn(axes_5D), testing::ValuesIn(eps), - testing::ValuesIn(epsMode), - testing::ValuesIn(std::vector>({{2, 2, 3, 10, 5}})), - testing::ValuesIn(netPrecisions), + testing::ValuesIn(eps_modes), + testing::Values(ov::test::static_shapes_to_test_representation(input_shape_5d_static)), + testing::ValuesIn(model_types), testing::Values(ov::test::utils::DEVICE_CPU) ); diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/one_hot.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/one_hot.cpp index 4432eb7b7b2ea3..92272ba76b5bb9 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/one_hot.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/one_hot.cpp @@ -3,96 +3,97 @@ // #include -#include "single_layer_tests/one_hot.hpp" -using namespace LayerTestsDefinitions; +#include "single_op_tests/one_hot.hpp" namespace { -const std::vector netPrecisions = { - InferenceEngine::Precision::I32, +using ov::test::OneHotLayerTest; + +const std::vector model_types = { + ov::element::i32, }; -const std::vector argDepthType_IC = { ngraph::element::i32 }; -const std::vector argDepth_IC = { 1, 5, 1017 }; -const std::vector argSetType_IC = { ngraph::element::i32 }; -const std::vector argOnValue_IC = { 0, 1, -29 }; -const std::vector argOffValue_IC = { 0, 1, -127 }; -const std::vector argAxis_IC = {0}; -const std::vector> inputShapes_IC = {{4, 5}, {3, 7}}; +const std::vector arg_depth_type_ic = { ov::element::i32 }; +const std::vector arg_depth_ic = { 1, 5, 1017 }; +const std::vector arg_set_type_ic = { ov::element::i32 }; +const std::vector arg_on_value_ic = { 0, 1, -29 }; +const std::vector arg_off_value_ic = { 0, 1, -127 }; +const std::vector arg_axis_ic = {0}; +const std::vector> input_shapes_ic = {{{4, 5}}, {{3, 7}}}; -const auto oneHotParams_IC = testing::Combine( - testing::ValuesIn(argDepthType_IC), - testing::ValuesIn(argDepth_IC), - testing::ValuesIn(argSetType_IC), - testing::ValuesIn(argOnValue_IC), - testing::ValuesIn(argOffValue_IC), - testing::ValuesIn(argAxis_IC), - testing::ValuesIn(netPrecisions), - testing::ValuesIn(inputShapes_IC), +const auto oneHotParams_ic = testing::Combine( + testing::ValuesIn(arg_depth_type_ic), + testing::ValuesIn(arg_depth_ic), + testing::ValuesIn(arg_set_type_ic), + testing::ValuesIn(arg_on_value_ic), + testing::ValuesIn(arg_off_value_ic), + testing::ValuesIn(arg_axis_ic), + testing::ValuesIn(model_types), + testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_ic)), testing::Values(ov::test::utils::DEVICE_CPU) ); INSTANTIATE_TEST_SUITE_P( smoke_OneHotIntConst, OneHotLayerTest, - oneHotParams_IC, + oneHotParams_ic, OneHotLayerTest::getTestCaseName ); -const std::vector argDepthType_Ax = { ngraph::element::i32 }; -const std::vector argDepth_Ax = { 3 }; -const std::vector argSetType_Ax = { ngraph::element::i32, ngraph::element::f32 }; -const std::vector argOnValue_Ax = { 17 }; -const std::vector argOffValue_Ax = { -3 }; -const std::vector argAxis_Ax = {0, 1, 3, 5, -4, -5}; -const std::vector> inputShapes_Ax = {{4, 8, 5, 3, 2, 9}}; +const std::vector arg_depth_type_ax = { ov::element::i32 }; +const std::vector arg_depth_ax = { 3 }; +const std::vector arg_set_type_ax = { ov::element::i32, ov::element::f32 }; +const std::vector arg_on_value_ax = { 17 }; +const std::vector arg_off_value_ax = { -3 }; +const std::vector arg_axis_ax = {0, 1, 3, 5, -4, -5}; +const std::vector> input_shapes_ax = {{{4, 8, 5, 3, 2, 9}}}; -const auto oneHotParams_Ax = testing::Combine( - testing::ValuesIn(argDepthType_Ax), - testing::ValuesIn(argDepth_Ax), - testing::ValuesIn(argSetType_Ax), - testing::ValuesIn(argOnValue_Ax), - testing::ValuesIn(argOffValue_Ax), - testing::ValuesIn(argAxis_Ax), - testing::ValuesIn(netPrecisions), - testing::ValuesIn(inputShapes_Ax), +const auto oneHotParams_ax = testing::Combine( + testing::ValuesIn(arg_depth_type_ax), + testing::ValuesIn(arg_depth_ax), + testing::ValuesIn(arg_set_type_ax), + testing::ValuesIn(arg_on_value_ax), + testing::ValuesIn(arg_off_value_ax), + testing::ValuesIn(arg_axis_ax), + testing::ValuesIn(model_types), + testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_ax)), testing::Values(ov::test::utils::DEVICE_CPU) ); INSTANTIATE_TEST_SUITE_P( smoke_OneHotAxrng, OneHotLayerTest, - oneHotParams_Ax, + oneHotParams_ax, OneHotLayerTest::getTestCaseName ); -const std::vector argDepthType_T = { ngraph::element::i8, ngraph::element::u8 }; -const std::vector argDepth_T = { 1 }; -const std::vector argSetType_T = { ngraph::element::i8, ngraph::element::u8, - ngraph::element::bf16, ngraph::element::f32 }; -const std::vector argOnValue_T = { 1 }; -const std::vector argOffValue_T = { 1 }; -const std::vector argAxis_T = {-1}; -const std::vector> inputShapes_T = {{2, 2}}; +const std::vector arg_depth_type_t = { ov::element::i8, ov::element::u8 }; +const std::vector arg_depth_t = { 1 }; +const std::vector arg_set_type_t = { ov::element::i8, ov::element::u8, + ov::element::bf16, ov::element::f32 }; +const std::vector arg_on_value_t = { 1 }; +const std::vector arg_off_value_t = { 1 }; +const std::vector arg_axis_t = {-1}; +const std::vector> input_shapes_t = {{{2, 2}}}; -const auto oneHotParams_T = testing::Combine( - testing::ValuesIn(argDepthType_T), - testing::ValuesIn(argDepth_T), - testing::ValuesIn(argSetType_T), - testing::ValuesIn(argOnValue_T), - testing::ValuesIn(argOffValue_T), - testing::ValuesIn(argAxis_T), - testing::ValuesIn(netPrecisions), - testing::ValuesIn(inputShapes_T), +const auto oneHotParams_t = testing::Combine( + testing::ValuesIn(arg_depth_type_t), + testing::ValuesIn(arg_depth_t), + testing::ValuesIn(arg_set_type_t), + testing::ValuesIn(arg_on_value_t), + testing::ValuesIn(arg_off_value_t), + testing::ValuesIn(arg_axis_t), + testing::ValuesIn(model_types), + testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_t)), testing::Values(ov::test::utils::DEVICE_CPU) ); INSTANTIATE_TEST_SUITE_P( smoke_OneHotArgType, OneHotLayerTest, - oneHotParams_T, + oneHotParams_t, OneHotLayerTest::getTestCaseName ); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/pad.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/pad.cpp index 4d73dbf3aa070f..0dc19a7d79044f 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/pad.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/pad.cpp @@ -4,42 +4,45 @@ #include -#include "single_layer_tests/pad.hpp" - -using namespace LayerTestsDefinitions; +#include "single_op_tests/pad.hpp" namespace { -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::I32, - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::I16, - InferenceEngine::Precision::U16, - InferenceEngine::Precision::I8, - InferenceEngine::Precision::U8, +using ov::test::PadLayerTest; +using ov::op::PadMode; + +const std::vector model_types = { + ov::element::f32, + ov::element::i32, + ov::element::f16, + ov::element::i16, + ov::element::u16, + ov::element::i8, + ov::element::u8, }; -const std::vector argPadValue = {0.f, 1.f, -1.f, 2.5f}; +const std::vector arg_pad_values = {0.f, 1.f, -1.f, 2.5f}; -const std::vector padMode = { - ngraph::helpers::PadMode::EDGE, - ngraph::helpers::PadMode::REFLECT, - ngraph::helpers::PadMode::SYMMETRIC +const std::vector pad_modes = { + PadMode::EDGE, + PadMode::REFLECT, + PadMode::SYMMETRIC }; -const std::vector> padsBegin1D = {{0}, {1}, {2}, {-2}}; -const std::vector> padsEnd1D = {{0}, {1}, {2}, {-2}}; + +// 1D + +const std::vector> pads_begin_1d = {{0}, {1}, {2}, {-2}}; +const std::vector> pads_end_1d = {{0}, {1}, {2}, {-2}}; + +const std::vector input_shape_1d_static = {{5}}; const auto pad1DConstparams = testing::Combine( - testing::ValuesIn(padsBegin1D), - testing::ValuesIn(padsEnd1D), - testing::ValuesIn(argPadValue), - testing::Values(ngraph::helpers::PadMode::CONSTANT), - testing::ValuesIn(netPrecisions), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Layout::ANY), - testing::Values(std::vector{5}), + testing::ValuesIn(pads_begin_1d), + testing::ValuesIn(pads_end_1d), + testing::ValuesIn(arg_pad_values), + testing::Values(PadMode::CONSTANT), + testing::ValuesIn(model_types), + testing::Values(ov::test::static_shapes_to_test_representation(input_shape_1d_static)), testing::Values(ov::test::utils::DEVICE_CPU) ); @@ -51,15 +54,12 @@ INSTANTIATE_TEST_SUITE_P( ); const auto pad1Dparams = testing::Combine( - testing::ValuesIn(padsBegin1D), - testing::ValuesIn(padsEnd1D), + testing::ValuesIn(pads_begin_1d), + testing::ValuesIn(pads_end_1d), testing::Values(0), - testing::ValuesIn(padMode), - testing::ValuesIn(netPrecisions), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Layout::ANY), - testing::Values(std::vector{5}), + testing::ValuesIn(pad_modes), + testing::ValuesIn(model_types), + testing::Values(ov::test::static_shapes_to_test_representation(input_shape_1d_static)), testing::Values(ov::test::utils::DEVICE_CPU) ); @@ -70,19 +70,21 @@ INSTANTIATE_TEST_SUITE_P( PadLayerTest::getTestCaseName ); -const std::vector> padsBegin2D = {{0, 0}, {1, 1}, {-2, 0}, {0, 3}}; -const std::vector> padsEnd2D = {{0, 0}, {1, 1}, {0, 1}, {-3, -2}}; + +// 2D + +const std::vector> pads_begin_2d = {{0, 0}, {1, 1}, {-2, 0}, {0, 3}}; +const std::vector> pads_end_2d = {{0, 0}, {1, 1}, {0, 1}, {-3, -2}}; + +const std::vector input_shape_2d_static = {{13, 5}}; const auto pad2DConstparams = testing::Combine( - testing::ValuesIn(padsBegin2D), - testing::ValuesIn(padsEnd2D), - testing::ValuesIn(argPadValue), - testing::Values(ngraph::helpers::PadMode::CONSTANT), - testing::ValuesIn(netPrecisions), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Layout::ANY), - testing::Values(std::vector{13, 5}), + testing::ValuesIn(pads_begin_2d), + testing::ValuesIn(pads_end_2d), + testing::ValuesIn(arg_pad_values), + testing::Values(PadMode::CONSTANT), + testing::ValuesIn(model_types), + testing::Values(ov::test::static_shapes_to_test_representation(input_shape_2d_static)), testing::Values(ov::test::utils::DEVICE_CPU) ); @@ -94,15 +96,12 @@ INSTANTIATE_TEST_SUITE_P( ); const auto pad2Dparams = testing::Combine( - testing::ValuesIn(padsBegin2D), - testing::ValuesIn(padsEnd2D), + testing::ValuesIn(pads_begin_2d), + testing::ValuesIn(pads_end_2d), testing::Values(0), - testing::ValuesIn(padMode), - testing::ValuesIn(netPrecisions), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Layout::ANY), - testing::Values(std::vector{13, 5}), + testing::ValuesIn(pad_modes), + testing::ValuesIn(model_types), + testing::Values(ov::test::static_shapes_to_test_representation(input_shape_2d_static)), testing::Values(ov::test::utils::DEVICE_CPU) ); @@ -113,19 +112,21 @@ INSTANTIATE_TEST_SUITE_P( PadLayerTest::getTestCaseName ); -const std::vector> padsBegin4D = {{0, 0, 0, 0}, {0, 3, 0, 0}, {0, 0, 0, 1}, {0, 0, -1, 1}, {2, 0, 0, 0}, {0, 3, 0, -1}}; -const std::vector> padsEnd4D = {{0, 0, 0, 0}, {0, 3, 0, 0}, {1, 0, 0, 0}, {0, 0, 0, 2}, {1, -3, 0, 0}, {0, 3, 0, -1}}; + +// 4D + +const std::vector> pads_begin_4d = {{0, 0, 0, 0}, {0, 3, 0, 0}, {0, 0, 0, 1}, {0, 0, -1, 1}, {2, 0, 0, 0}, {0, 3, 0, -1}}; +const std::vector> pads_end_4d = {{0, 0, 0, 0}, {0, 3, 0, 0}, {1, 0, 0, 0}, {0, 0, 0, 2}, {1, -3, 0, 0}, {0, 3, 0, -1}}; + +const std::vector input_shape_4d_static = {{3, 5, 10, 11}}; const auto pad4DConstparams = testing::Combine( - testing::ValuesIn(padsBegin4D), - testing::ValuesIn(padsEnd4D), - testing::ValuesIn(argPadValue), - testing::Values(ngraph::helpers::PadMode::CONSTANT), - testing::ValuesIn(netPrecisions), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Layout::ANY), - testing::Values(std::vector{3, 5, 10, 11}), + testing::ValuesIn(pads_begin_4d), + testing::ValuesIn(pads_end_4d), + testing::ValuesIn(arg_pad_values), + testing::Values(PadMode::CONSTANT), + testing::ValuesIn(model_types), + testing::Values(ov::test::static_shapes_to_test_representation(input_shape_4d_static)), testing::Values(ov::test::utils::DEVICE_CPU) ); @@ -137,15 +138,12 @@ INSTANTIATE_TEST_SUITE_P( ); const auto pad4Dparams = testing::Combine( - testing::ValuesIn(padsBegin4D), - testing::ValuesIn(padsEnd4D), + testing::ValuesIn(pads_begin_4d), + testing::ValuesIn(pads_end_4d), testing::Values(0), - testing::ValuesIn(padMode), - testing::ValuesIn(netPrecisions), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Layout::ANY), - testing::Values(std::vector{3, 5, 10, 11}), + testing::ValuesIn(pad_modes), + testing::ValuesIn(model_types), + testing::Values(ov::test::static_shapes_to_test_representation(input_shape_4d_static)), testing::Values(ov::test::utils::DEVICE_CPU) ); @@ -155,5 +153,4 @@ INSTANTIATE_TEST_SUITE_P( pad4Dparams, PadLayerTest::getTestCaseName ); - } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/pooling.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/pooling.cpp index c57694a072f9e7..6d4b6a72e5819a 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/pooling.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/pooling.cpp @@ -4,209 +4,184 @@ #include -#include "single_layer_tests/pooling.hpp" +#include "single_op_tests/pooling.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { -// Common params -const std::vector inputPrecisions = { - InferenceEngine::Precision::FP32, -// InferenceEngine::Precision::FP16, // "[NOT_IMPLEMENTED] Input image format FP16 is not supported yet... - InferenceEngine::Precision::U8, -// InferenceEngine::Precision::I8 // Too much cases -}; +using ov::test::PoolingLayerTest; +using ov::test::MaxPoolingV8LayerTest; +using ov::test::utils::PoolingTypes; +using ov::test::poolSpecificParams; -const std::vector netPrecisions = { - InferenceEngine::Precision::FP16 +const std::vector model_types = { + ov::element::f16 }; const std::vector> kernels = {{3, 3}, {3, 5}}; -const std::vector> kernel3D = {{2, 2, 2}}; +const std::vector> kernel_3d = {{2, 2, 2}}; const std::vector> strides = {{1, 1}, {1, 2}, {2, 1}, {2, 2}}; -const std::vector> strides3D = {{1, 1, 1}, - {2, 2, 2}}; -const std::vector> stridess3D = {{2, 2, 2}}; -const std::vector> padBegins = {{0, 0}, - {0, 2}}; -const std::vector> padBegins3D = {{0, 0, 0}}; -const std::vector> padEnds = {{0, 0}, - {0, 2}}; -const std::vector> padEnds3D = {{0, 0, 0}}; -const std::vector roundingTypes = {ngraph::op::RoundingType::CEIL, - ngraph::op::RoundingType::FLOOR}; + +const std::vector> strides_3d = {{1, 1, 1}, + {2, 2, 2}}; + +const std::vector> pad_begins = {{0, 0}, + {0, 2}}; + +const std::vector> pad_begins_3d = {{0, 0, 0}}; + +const std::vector> pad_ends = {{0, 0}, + {0, 2}}; + +const std::vector> pad_ends_3d = {{0, 0, 0}}; + ////* ========== Max Polling ========== */ /* +========== Explicit Pad Floor Rounding ========== */ +std::vector input_shapes_static = {{1, 3, 30, 30}}; + const auto maxPool_ExplicitPad_FloorRounding_Params = ::testing::Combine( - ::testing::Values(ngraph::helpers::PoolingTypes::MAX), + ::testing::Values(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::ValuesIn(pad_begins), + ::testing::ValuesIn(pad_ends), + ::testing::Values(ov::op::RoundingType::FLOOR), + ::testing::Values(ov::op::PadType::EXPLICIT), ::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling ); INSTANTIATE_TEST_SUITE_P(smoke_MaxPool_ExplicitPad_FloorRounding, 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::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), PoolingLayerTest::getTestCaseName); /* +========== Same Upper Pad Floor Rounding ========== */ const auto maxPool_SameUpperPad_FloorRounding_Params = ::testing::Combine( - ::testing::Values(ngraph::helpers::PoolingTypes::MAX), + ::testing::Values(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::SAME_UPPER), + ::testing::ValuesIn(pad_begins), + ::testing::ValuesIn(pad_ends), + ::testing::Values(ov::op::RoundingType::FLOOR), + ::testing::Values(ov::op::PadType::SAME_UPPER), ::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling ); INSTANTIATE_TEST_SUITE_P(smoke_MaxPool_SameUpperPad_FloorRounding, PoolingLayerTest, ::testing::Combine( maxPool_SameUpperPad_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::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), PoolingLayerTest::getTestCaseName); /* +========== Same Lower Pad Floor Rounding ========== */ const auto maxPool_SameLowerPad_FloorRounding_Params = ::testing::Combine( - ::testing::Values(ngraph::helpers::PoolingTypes::MAX), + ::testing::Values(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::SAME_LOWER), + ::testing::ValuesIn(pad_begins), + ::testing::ValuesIn(pad_ends), + ::testing::Values(ov::op::RoundingType::FLOOR), + ::testing::Values(ov::op::PadType::SAME_LOWER), ::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling ); INSTANTIATE_TEST_SUITE_P(smoke_MaxPool_SameLowerPad_FloorRounding, PoolingLayerTest, ::testing::Combine( maxPool_SameUpperPad_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::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), PoolingLayerTest::getTestCaseName); /* ========== Explicit Pad Floor Rounding 5D input========== */ + +std::vector input_shapes_5d_static = {{32, 32, 2, 2, 2}}; + const auto maxPool_ExplicitPad_FloorRounding_5Dinput_Params = ::testing::Combine( - ::testing::Values(ngraph::helpers::PoolingTypes::MAX), - ::testing::ValuesIn(kernel3D), - ::testing::ValuesIn(strides3D), - ::testing::ValuesIn(padBegins3D), - ::testing::ValuesIn(padEnds3D), - ::testing::Values(ngraph::op::RoundingType::FLOOR), - ::testing::Values(ngraph::op::PadType::EXPLICIT), + ::testing::Values(PoolingTypes::MAX), + ::testing::ValuesIn(kernel_3d), + ::testing::ValuesIn(strides_3d), + ::testing::ValuesIn(pad_begins_3d), + ::testing::ValuesIn(pad_ends_3d), + ::testing::Values(ov::op::RoundingType::FLOOR), + ::testing::Values(ov::op::PadType::EXPLICIT), ::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling ); INSTANTIATE_TEST_SUITE_P(smoke_MaxPool_ExplicitPad_FloorRounding_5Dinput, PoolingLayerTest, ::testing::Combine( maxPool_ExplicitPad_FloorRounding_5Dinput_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({32, 32, 2, 2, 2})), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_5d_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), PoolingLayerTest::getTestCaseName); /* ========== Same Upper Pad Floor Rounding 5D input========== */ const auto maxPool_SameUpperPad_FloorRounding_5Dinput_Params = ::testing::Combine( - ::testing::Values(ngraph::helpers::PoolingTypes::MAX), - ::testing::ValuesIn(kernel3D), - ::testing::ValuesIn(strides3D), - ::testing::ValuesIn(padBegins3D), - ::testing::ValuesIn(padEnds3D), - ::testing::Values(ngraph::op::RoundingType::FLOOR), - ::testing::Values(ngraph::op::PadType::SAME_UPPER), + ::testing::Values(PoolingTypes::MAX), + ::testing::ValuesIn(kernel_3d), + ::testing::ValuesIn(strides_3d), + ::testing::ValuesIn(pad_begins_3d), + ::testing::ValuesIn(pad_ends_3d), + ::testing::Values(ov::op::RoundingType::FLOOR), + ::testing::Values(ov::op::PadType::SAME_UPPER), ::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling ); INSTANTIATE_TEST_SUITE_P(smoke_MaxPool_SameUpperPad_FloorRounding_5Dinput, PoolingLayerTest, ::testing::Combine( maxPool_SameUpperPad_FloorRounding_5Dinput_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({32, 32, 2, 2, 2})), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_5d_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), PoolingLayerTest::getTestCaseName); /* ========== Same Lower Pad Ceil Rounding 5D input========== */ const auto maxPool_SameLowerPad_CeilRounding_5Dinput_Params = ::testing::Combine( - ::testing::Values(ngraph::helpers::PoolingTypes::MAX), - ::testing::ValuesIn(kernel3D), - ::testing::ValuesIn(strides3D), - ::testing::ValuesIn(padBegins3D), - ::testing::ValuesIn(padEnds3D), - ::testing::Values(ngraph::op::RoundingType::CEIL), - ::testing::Values(ngraph::op::PadType::SAME_LOWER), + ::testing::Values(PoolingTypes::MAX), + ::testing::ValuesIn(kernel_3d), + ::testing::ValuesIn(strides_3d), + ::testing::ValuesIn(pad_begins_3d), + ::testing::ValuesIn(pad_ends_3d), + ::testing::Values(ov::op::RoundingType::CEIL), + ::testing::Values(ov::op::PadType::SAME_LOWER), ::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling ); INSTANTIATE_TEST_SUITE_P(smoke_MaxPool_SameLowerPad_CeilRounding_5Dinput, PoolingLayerTest, ::testing::Combine( maxPool_SameUpperPad_FloorRounding_5Dinput_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({32, 32, 2, 2, 2})), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_5d_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), PoolingLayerTest::getTestCaseName); /* ========== Explicit Pad Ceil Rounding ========== */ const auto maxPool_ExplicitPad_CeilRounding_Params = ::testing::Combine( - ::testing::Values(ngraph::helpers::PoolingTypes::MAX), + ::testing::Values(PoolingTypes::MAX), ::testing::ValuesIn(kernels), ::testing::ValuesIn(strides), - ::testing::ValuesIn(padBegins), - ::testing::ValuesIn(padEnds), - ::testing::Values(ngraph::op::RoundingType::CEIL), - ::testing::Values(ngraph::op::PadType::EXPLICIT), + ::testing::ValuesIn(pad_begins), + ::testing::ValuesIn(pad_ends), + ::testing::Values(ov::op::RoundingType::CEIL), + ::testing::Values(ov::op::PadType::EXPLICIT), ::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling ); INSTANTIATE_TEST_SUITE_P(smoke_MaxPool_ExplicitPad_CeilRounding, 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::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), PoolingLayerTest::getTestCaseName); @@ -214,55 +189,49 @@ INSTANTIATE_TEST_SUITE_P(smoke_MaxPool_ExplicitPad_CeilRounding, PoolingLayerTes ////* ========== Avg Pooling ========== */ /* +========== Explicit Pad Ceil Rounding ========== */ const auto avgPoolExplicitPadCeilRoundingParams = ::testing::Combine( - ::testing::Values(ngraph::helpers::PoolingTypes::AVG), + ::testing::Values(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. + // TODO: Non 1 strides fails in reference implementation with error "The end corner is out of bounds at axis 3" thrown in the test body. ::testing::ValuesIn(strides), ::testing::ValuesIn(std::vector>({{0, 0}, {1, 1}, {0, 1}})), ::testing::ValuesIn(std::vector>({{0, 0}, {1, 1}, {0, 1}})), - ::testing::Values(ngraph::op::RoundingType::CEIL), - ::testing::Values(ngraph::op::PadType::EXPLICIT), + ::testing::Values(ov::op::RoundingType::CEIL), + ::testing::Values(ov::op::PadType::EXPLICIT), ::testing::Values(true, false) ); INSTANTIATE_TEST_SUITE_P(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::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), PoolingLayerTest::getTestCaseName); -std::vector psParams({poolSpecificParams(ngraph::helpers::PoolingTypes::AVG, {2, 2}, {2, 2}, {0, 0}, {0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false), - poolSpecificParams(ngraph::helpers::PoolingTypes::AVG, {7, 7}, {1, 1}, {0, 0}, {1, 1}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false)}); +std::vector psParams({poolSpecificParams(PoolingTypes::AVG, {2, 2}, {2, 2}, {0, 0}, {0, 0}, + ov::op::RoundingType::CEIL, ov::op::PadType::EXPLICIT, false), + poolSpecificParams(PoolingTypes::AVG, {7, 7}, {1, 1}, {0, 0}, {1, 1}, + ov::op::RoundingType::CEIL, ov::op::PadType::EXPLICIT, false)}); + +std::vector input_shapes_explicit_pad_ceil_rounding_corner_static = {{1, 3, 30, 30}}; INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_ExplicitPad_CeilRounding_corner, PoolingLayerTest, ::testing::Combine( ::testing::ValuesIn(psParams), - ::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, 1024, 6, 6})), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_explicit_pad_ceil_rounding_corner_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), PoolingLayerTest::getTestCaseName); /* +========== Explicit Pad Floor Rounding ========== */ const auto avgPoolExplicitPadFloorRoundingParams = ::testing::Combine( - ::testing::Values(ngraph::helpers::PoolingTypes::AVG), + ::testing::Values(PoolingTypes::AVG), ::testing::ValuesIn(kernels), ::testing::ValuesIn(strides), ::testing::ValuesIn(std::vector>({{0, 0}, {1, 1}})), ::testing::ValuesIn(std::vector>({{0, 0}, {1, 1}})), - ::testing::Values(ngraph::op::RoundingType::FLOOR), - ::testing::Values(ngraph::op::PadType::EXPLICIT), + ::testing::Values(ov::op::RoundingType::FLOOR), + ::testing::Values(ov::op::PadType::EXPLICIT), ::testing::Values(true, false) ); @@ -270,114 +239,96 @@ const auto avgPoolExplicitPadFloorRoundingParams = ::testing::Combine( INSTANTIATE_TEST_SUITE_P(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::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), PoolingLayerTest::getTestCaseName); /* ========== Explicit Pad Floor Rounding 5D input========== */ const auto avgPool_ExplicitPad_FloorRounding_5Dinput_Params = ::testing::Combine( - ::testing::Values(ngraph::helpers::PoolingTypes::AVG), - ::testing::ValuesIn(kernel3D), - ::testing::ValuesIn(strides3D), - ::testing::ValuesIn(padBegins3D), - ::testing::ValuesIn(padEnds3D), - ::testing::Values(ngraph::op::RoundingType::FLOOR), - ::testing::Values(ngraph::op::PadType::EXPLICIT), + ::testing::Values(PoolingTypes::AVG), + ::testing::ValuesIn(kernel_3d), + ::testing::ValuesIn(strides_3d), + ::testing::ValuesIn(pad_begins_3d), + ::testing::ValuesIn(pad_ends_3d), + ::testing::Values(ov::op::RoundingType::FLOOR), + ::testing::Values(ov::op::PadType::EXPLICIT), ::testing::Values(true, false) ); +std::vector input_shapes_5d_2_static = {{32, 32, 2, 2, 4}}; + INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_ExplicitPad_FloorRounding_5Dinput, PoolingLayerTest, ::testing::Combine( avgPool_ExplicitPad_FloorRounding_5Dinput_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({32, 32, 2, 2, 4})), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_5d_2_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), PoolingLayerTest::getTestCaseName); /* ========== Same Upper Pad Floor Rounding 5D input========== */ const auto avgPool_SameUpperPad_FloorRounding_5Dinput_Params = ::testing::Combine( - ::testing::Values(ngraph::helpers::PoolingTypes::AVG), - ::testing::ValuesIn(kernel3D), - ::testing::ValuesIn(strides3D), - ::testing::ValuesIn(padBegins3D), - ::testing::ValuesIn(padEnds3D), - ::testing::Values(ngraph::op::RoundingType::FLOOR), - ::testing::Values(ngraph::op::PadType::SAME_UPPER), + ::testing::Values(PoolingTypes::AVG), + ::testing::ValuesIn(kernel_3d), + ::testing::ValuesIn(strides_3d), + ::testing::ValuesIn(pad_begins_3d), + ::testing::ValuesIn(pad_ends_3d), + ::testing::Values(ov::op::RoundingType::FLOOR), + ::testing::Values(ov::op::PadType::SAME_UPPER), ::testing::Values(true) ); INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_SameUpperPad_FloorRounding_5Dinput, PoolingLayerTest, ::testing::Combine( avgPool_SameUpperPad_FloorRounding_5Dinput_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({32, 32, 2, 2, 4})), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_5d_2_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), PoolingLayerTest::getTestCaseName); /* ========== Same Lower Pad Ceil Rounding 5D input========== */ const auto avgPool_SameLowerPad_CeilRounding_5Dinput_Params = ::testing::Combine( - ::testing::Values(ngraph::helpers::PoolingTypes::AVG), - ::testing::ValuesIn(kernel3D), - ::testing::ValuesIn(strides3D), - ::testing::ValuesIn(padBegins3D), - ::testing::ValuesIn(padEnds3D), - ::testing::Values(ngraph::op::RoundingType::CEIL), - ::testing::Values(ngraph::op::PadType::SAME_LOWER), + ::testing::Values(PoolingTypes::AVG), + ::testing::ValuesIn(kernel_3d), + ::testing::ValuesIn(strides_3d), + ::testing::ValuesIn(pad_begins_3d), + ::testing::ValuesIn(pad_ends_3d), + ::testing::Values(ov::op::RoundingType::CEIL), + ::testing::Values(ov::op::PadType::SAME_LOWER), ::testing::Values(true) ); INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_SameLowerPad_CeilRounding_5Dinput, PoolingLayerTest, ::testing::Combine( avgPool_SameLowerPad_CeilRounding_5Dinput_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({32, 32, 2, 2, 2})), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_5d_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), PoolingLayerTest::getTestCaseName); ////* ========== Max Pooling V8 ========== */ const std::vector> dilation = {{1, 1}, {2, 2}}; -const std::vector> dilation3D = {{1, 1, 1}, {2, 2, 2}}; +const std::vector> dilation_3d = {{1, 1, 1}, {2, 2, 2}}; /* ========== Explicit Pad Floor Rounding ========== */ const auto maxPoolv8_ExplicitPad_FloorRounding_Params = ::testing::Combine( ::testing::ValuesIn(kernels), ::testing::ValuesIn(strides), ::testing::ValuesIn(dilation), - ::testing::ValuesIn(padBegins), - ::testing::ValuesIn(padEnds), - ::testing::Values(ngraph::element::Type_t::i32), + ::testing::ValuesIn(pad_begins), + ::testing::ValuesIn(pad_ends), + ::testing::Values(ov::element::i32), ::testing::Values(0), - ::testing::Values(ngraph::op::RoundingType::FLOOR), - ::testing::Values(ngraph::op::PadType::EXPLICIT) + ::testing::Values(ov::op::RoundingType::FLOOR), + ::testing::Values(ov::op::PadType::EXPLICIT) ); INSTANTIATE_TEST_SUITE_P(smoke_MaxPoolV8_ExplicitPad_FloorRounding, MaxPoolingV8LayerTest, ::testing::Combine( maxPoolv8_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::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), MaxPoolingV8LayerTest::getTestCaseName); @@ -386,23 +337,19 @@ const auto maxPoolv8_SameUpperPad_FloorRounding_Params = ::testing::Combine( ::testing::ValuesIn(kernels), ::testing::ValuesIn(strides), ::testing::ValuesIn(dilation), - ::testing::ValuesIn(padBegins), - ::testing::ValuesIn(padEnds), - ::testing::Values(ngraph::element::Type_t::i32), + ::testing::ValuesIn(pad_begins), + ::testing::ValuesIn(pad_ends), + ::testing::Values(ov::element::i32), ::testing::Values(0), - ::testing::Values(ngraph::op::RoundingType::FLOOR), - ::testing::Values(ngraph::op::PadType::SAME_UPPER) + ::testing::Values(ov::op::RoundingType::FLOOR), + ::testing::Values(ov::op::PadType::SAME_UPPER) ); INSTANTIATE_TEST_SUITE_P(smoke_MaxPoolv8_SameUpperPad_FloorRounding, MaxPoolingV8LayerTest, ::testing::Combine( maxPoolv8_SameUpperPad_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::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), MaxPoolingV8LayerTest::getTestCaseName); @@ -411,98 +358,82 @@ const auto maxPoolv8_SameLowerPad_FloorRounding_Params = ::testing::Combine( ::testing::ValuesIn(kernels), ::testing::ValuesIn(strides), ::testing::ValuesIn(dilation), - ::testing::ValuesIn(padBegins), - ::testing::ValuesIn(padEnds), - ::testing::Values(ngraph::element::Type_t::i32), + ::testing::ValuesIn(pad_begins), + ::testing::ValuesIn(pad_ends), + ::testing::Values(ov::element::i32), ::testing::Values(0), - ::testing::Values(ngraph::op::RoundingType::FLOOR), - ::testing::Values(ngraph::op::PadType::SAME_LOWER) + ::testing::Values(ov::op::RoundingType::FLOOR), + ::testing::Values(ov::op::PadType::SAME_LOWER) ); INSTANTIATE_TEST_SUITE_P(smoke_MaxPoolv8_SameLowerPad_FloorRounding, MaxPoolingV8LayerTest, ::testing::Combine( maxPoolv8_SameLowerPad_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::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), MaxPoolingV8LayerTest::getTestCaseName); /* ========= Explicit Pad Floor Rounding 5D input========== */ const auto maxPoolv8_ExplicitPad_FloorRounding_5Dinput_Params = ::testing::Combine( - ::testing::ValuesIn(kernel3D), - ::testing::ValuesIn(strides3D), - ::testing::Values(dilation3D[0]), - ::testing::ValuesIn(padBegins3D), - ::testing::ValuesIn(padEnds3D), - ::testing::Values(ngraph::element::Type_t::i32), + ::testing::ValuesIn(kernel_3d), + ::testing::ValuesIn(strides_3d), + ::testing::Values(dilation_3d[0]), + ::testing::ValuesIn(pad_begins_3d), + ::testing::ValuesIn(pad_ends_3d), + ::testing::Values(ov::element::i32), ::testing::Values(0), - ::testing::Values(ngraph::op::RoundingType::FLOOR), - ::testing::Values(ngraph::op::PadType::EXPLICIT) + ::testing::Values(ov::op::RoundingType::FLOOR), + ::testing::Values(ov::op::PadType::EXPLICIT) ); INSTANTIATE_TEST_SUITE_P(smoke_MaxPoolv8_ExplicitPad_FloorRounding_5Dinput, MaxPoolingV8LayerTest, ::testing::Combine( maxPoolv8_ExplicitPad_FloorRounding_5Dinput_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({32, 32, 2, 2, 2})), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_5d_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), MaxPoolingV8LayerTest::getTestCaseName); /* ========= Same Upper Pad Floor Rounding 5D input========== */ const auto maxPoolv8_SameUpperPad_FloorRounding_5Dinput_Params = ::testing::Combine( - ::testing::ValuesIn(kernel3D), - ::testing::ValuesIn(strides3D), - ::testing::ValuesIn(dilation3D), - ::testing::ValuesIn(padBegins3D), - ::testing::ValuesIn(padEnds3D), - ::testing::Values(ngraph::element::Type_t::i32), + ::testing::ValuesIn(kernel_3d), + ::testing::ValuesIn(strides_3d), + ::testing::ValuesIn(dilation_3d), + ::testing::ValuesIn(pad_begins_3d), + ::testing::ValuesIn(pad_ends_3d), + ::testing::Values(ov::element::i32), ::testing::Values(0), - ::testing::Values(ngraph::op::RoundingType::FLOOR), - ::testing::Values(ngraph::op::PadType::SAME_UPPER) + ::testing::Values(ov::op::RoundingType::FLOOR), + ::testing::Values(ov::op::PadType::SAME_UPPER) ); INSTANTIATE_TEST_SUITE_P(smoke_MaxPoolv8_SameUpperPad_FloorRounding_5Dinput, MaxPoolingV8LayerTest, ::testing::Combine( maxPoolv8_SameUpperPad_FloorRounding_5Dinput_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({32, 32, 2, 2, 2})), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_5d_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), MaxPoolingV8LayerTest::getTestCaseName); /* ========= Same Lower Pad Ceil Rounding 5D input========== */ const auto maxPoolv8_SameLowerPad_CeilRounding_5Dinput_Params = ::testing::Combine( - ::testing::ValuesIn(kernel3D), - ::testing::ValuesIn(strides3D), - ::testing::ValuesIn(dilation3D), - ::testing::ValuesIn(padBegins3D), - ::testing::ValuesIn(padEnds3D), - ::testing::Values(ngraph::element::Type_t::i32), + ::testing::ValuesIn(kernel_3d), + ::testing::ValuesIn(strides_3d), + ::testing::ValuesIn(dilation_3d), + ::testing::ValuesIn(pad_begins_3d), + ::testing::ValuesIn(pad_ends_3d), + ::testing::Values(ov::element::i32), ::testing::Values(0), - ::testing::Values(ngraph::op::RoundingType::CEIL), - ::testing::Values(ngraph::op::PadType::SAME_LOWER) + ::testing::Values(ov::op::RoundingType::CEIL), + ::testing::Values(ov::op::PadType::SAME_LOWER) ); INSTANTIATE_TEST_SUITE_P(smoke_MaxPoolv8_SameLowerPad_CeilRounding_5Dinput, MaxPoolingV8LayerTest, ::testing::Combine( maxPoolv8_SameLowerPad_CeilRounding_5Dinput_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({32, 32, 2, 2, 2})), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_5d_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), MaxPoolingV8LayerTest::getTestCaseName); @@ -511,49 +442,41 @@ const auto maxPoolv8_ExplicitPad_CeilRounding_Params = ::testing::Combine( ::testing::ValuesIn(kernels), ::testing::ValuesIn(strides), ::testing::ValuesIn(dilation), - ::testing::ValuesIn(padBegins), - ::testing::ValuesIn(padEnds), - ::testing::Values(ngraph::element::Type_t::i32), + ::testing::ValuesIn(pad_begins), + ::testing::ValuesIn(pad_ends), + ::testing::Values(ov::element::i32), ::testing::Values(0), - ::testing::Values(ngraph::op::RoundingType::CEIL), - ::testing::Values(ngraph::op::PadType::EXPLICIT) + ::testing::Values(ov::op::RoundingType::CEIL), + ::testing::Values(ov::op::PadType::EXPLICIT) ); INSTANTIATE_TEST_SUITE_P(smoke_MaxPoolv8_ExplicitPad_CeilRounding, MaxPoolingV8LayerTest, ::testing::Combine( maxPoolv8_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::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), MaxPoolingV8LayerTest::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::Values(PoolingTypes::MAX, 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), + ov::op::RoundingType::FLOOR), // placeholder value - Rounding Type not applicable for Valid pad type + ::testing::Values(ov::op::PadType::VALID), ::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling ); INSTANTIATE_TEST_SUITE_P(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::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), PoolingLayerTest::getTestCaseName); @@ -563,21 +486,17 @@ const auto maxPoolv8_ValidPad_Params = ::testing::Combine( ::testing::ValuesIn(dilation), ::testing::Values(std::vector({0, 0})), ::testing::Values(std::vector({0, 0})), - ::testing::Values(ngraph::element::Type_t::i32), + ::testing::Values(ov::element::i32), ::testing::Values(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(ov::op::RoundingType::FLOOR), // placeholder value - Rounding Type not applicable for Valid pad type + ::testing::Values(ov::op::PadType::VALID) ); INSTANTIATE_TEST_SUITE_P(smoke_MAXPoolv8_ValidPad, MaxPoolingV8LayerTest, ::testing::Combine( maxPoolv8_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::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), MaxPoolingV8LayerTest::getTestCaseName); diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/prior_box.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/prior_box.cpp index 6c6a08be138b74..3b75acd67bc26d 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/prior_box.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/prior_box.cpp @@ -4,14 +4,16 @@ #include -#include "single_layer_tests/prior_box.hpp" +#include "single_op_tests/prior_box.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; +namespace { +using ov::test::PriorBoxLayerTest; + +const std::vector model_types = { + ov::element::i32, + ov::element::u16}; -const std::vector netPrecisions = { - InferenceEngine::Precision::I32, - InferenceEngine::Precision::U16}; const std::vector> min_sizes = { {256.0f}}; @@ -53,8 +55,7 @@ const std::vector scale_all_sizes = { const std::vector min_max_aspect_ratios_order = { false, true}; -const std::vector inputShape = {300, 300}; -const std::vector imageShape = {32, 32}; +const std::vector input_shapes_static = {{300, 300}, {32, 32}}; const auto layerSpecificParams = ::testing::Combine( ::testing::ValuesIn(min_sizes), @@ -74,12 +75,8 @@ const auto layerSpecificParams = ::testing::Combine( INSTANTIATE_TEST_SUITE_P(smoke_PriorBox_Basic, PriorBoxLayerTest, ::testing::Combine( layerSpecificParams, - ::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(inputShape), - ::testing::Values(imageShape), + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::Values(ov::test::utils::DEVICE_CPU)), PriorBoxLayerTest::getTestCaseName); +} // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/prior_box_clustered.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/prior_box_clustered.cpp index 34dfbf6031ec6c..2319c7367fb151 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/prior_box_clustered.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/prior_box_clustered.cpp @@ -3,17 +3,15 @@ // #include -#include "single_layer_tests/prior_box_clustered.hpp" +#include "single_op_tests/prior_box_clustered.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; -using namespace ngraph::helpers; - namespace { +using ov::test::PriorBoxClusteredLayerTest; // Common params -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16 +const std::vector model_types = { + ov::element::f32, + ov::element::f16 }; const std::vector> widths = { @@ -63,18 +61,14 @@ const auto layerSpeficParams = ::testing::Combine( ::testing::ValuesIn(variances) ); +std::vector input_shapes_static = {{4, 4}, {50, 50}}; + INSTANTIATE_TEST_SUITE_P(smoke_PriorBoxClustered_Basic, PriorBoxClusteredLayerTest, - ::testing::Combine( - layerSpeficParams, - ::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({ 4, 4 })), - ::testing::Values(std::vector({ 50, 50 })), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - PriorBoxClusteredLayerTest::getTestCaseName + ::testing::Combine( + layerSpeficParams, + ::testing::ValuesIn(model_types), + ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_static)), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + PriorBoxClusteredLayerTest::getTestCaseName ); - } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/roi_align.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/roi_align.cpp index 7009da247635e1..58eaa5174ee107 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/roi_align.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/roi_align.cpp @@ -4,30 +4,32 @@ #include -#include "single_layer_tests/roi_align.hpp" +#include "single_op_tests/roi_align.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; +using ov::test::ROIAlignLayerTest; +namespace { -const std::vector netPRCs = { - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32 +const std::vector model_types = { + ov::element::f16, + ov::element::f32 }; const auto ROIAlignCases_average = ::testing::Combine( ::testing::ValuesIn( - std::vector> { - { 3, 8, 16, 16 }, - { 2, 1, 16, 16 }, - { 2, 1, 8, 16 }}), - ::testing::Values(std::vector{ 2, 4 }), + ov::test::static_shapes_to_test_representation( + std::vector>{ + {{ 3, 8, 16, 16 }}, + {{ 2, 1, 16, 16 }}, + {{ 2, 1, 8, 16 }}})), + ::testing::Values(ov::Shape{ 2, 4 }), ::testing::Values(2), ::testing::Values(2), ::testing::ValuesIn(std::vector { 1, 0.625 }), ::testing::Values(2), ::testing::Values("avg"), - ::testing::ValuesIn(netPRCs), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_CPU) ); @@ -35,18 +37,21 @@ INSTANTIATE_TEST_SUITE_P(smoke_TestsROIAlign_average, ROIAlignLayerTest, ROIAlig const auto ROIAlignCases_max = ::testing::Combine( ::testing::ValuesIn( - std::vector> { - { 2, 8, 20, 20 }, - { 2, 1, 20, 20 }, - { 2, 1, 10, 20 }}), - ::testing::Values(std::vector{ 2, 4 }), + ov::test::static_shapes_to_test_representation( + std::vector>{ + {{ 2, 8, 20, 20 }}, + {{ 2, 1, 20, 20 }}, + {{ 2, 1, 10, 20 }}})), + ::testing::Values(ov::Shape{ 2, 4 }), ::testing::Values(2), ::testing::Values(2), ::testing::ValuesIn(std::vector { 1, 0.625 }), ::testing::Values(2), ::testing::Values("max"), - ::testing::ValuesIn(netPRCs), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_CPU) ); INSTANTIATE_TEST_SUITE_P(smoke_TestsROIAlign_max, ROIAlignLayerTest, ROIAlignCases_max, ROIAlignLayerTest::getTestCaseName); + +} // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/roi_pooling.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/roi_pooling.cpp index ff2be946948c6a..ca68bc6fa4d5ea 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/roi_pooling.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/roi_pooling.cpp @@ -4,62 +4,72 @@ #include -#include "single_layer_tests/roi_pooling.hpp" +#include "single_op_tests/roi_pooling.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; +using ov::test::ROIPoolingLayerTest; -const std::vector> inShapes = { - {1, 3, 8, 8}, - {3, 4, 50, 50} +namespace { + +const std::vector param_shapes = { + {{1, 3, 8, 8}}, + {{3, 4, 50, 50}} }; -const std::vector> pooledShapes_max = { - {1, 1}, - {2, 2}, - {3, 3}, - {6, 6} +const std::vector coord_shapes = { + {{1, 5}}, + {{3, 5}}, + {{5, 5}} }; -const std::vector> pooledShapes_bilinear = { - {1, 1}, - {2, 2}, - {3, 3}, - {6, 6} +auto input_shapes = [](const std::vector& in1, const std::vector& in2) { + std::vector> res; + for (const auto& sh1 : in1) + for (const auto& sh2 : in2) + res.push_back(ov::test::static_shapes_to_test_representation({sh1, sh2})); + return res; +}(param_shapes, coord_shapes); + +const std::vector pooled_shapes_max = { + {{1, 1}}, + {{2, 2}}, + {{3, 3}}, + {{6, 6}} }; -const std::vector> coordShapes = { - {1, 5}, - {3, 5}, - {5, 5} +const std::vector pooled_shapes_bilinear = { + {{1, 1}}, + {{2, 2}}, + {{3, 3}}, + {{6, 6}} }; -const std::vector netPRCs = { - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32 +const std::vector model_types = { + ov::element::f16, + ov::element::f32 }; const std::vector spatial_scales = {0.625f, 1.f}; const auto test_ROIPooling_max = ::testing::Combine( - ::testing::ValuesIn(inShapes), - ::testing::ValuesIn(coordShapes), - ::testing::ValuesIn(pooledShapes_max), + ::testing::ValuesIn(input_shapes), + ::testing::ValuesIn(pooled_shapes_max), ::testing::ValuesIn(spatial_scales), - ::testing::Values(ngraph::helpers::ROIPoolingTypes::ROI_MAX), - ::testing::ValuesIn(netPRCs), + ::testing::Values(ov::test::utils::ROIPoolingTypes::ROI_MAX), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_CPU) ); const auto test_ROIPooling_bilinear = ::testing::Combine( - ::testing::ValuesIn(inShapes), - ::testing::ValuesIn(coordShapes), - ::testing::ValuesIn(pooledShapes_bilinear), + ::testing::ValuesIn(input_shapes), + ::testing::ValuesIn(pooled_shapes_bilinear), ::testing::Values(spatial_scales[1]), - ::testing::Values(ngraph::helpers::ROIPoolingTypes::ROI_BILINEAR), - ::testing::ValuesIn(netPRCs), + ::testing::Values(ov::test::utils::ROIPoolingTypes::ROI_BILINEAR), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_CPU) ); INSTANTIATE_TEST_SUITE_P(smoke_TestsROIPooling_max, ROIPoolingLayerTest, test_ROIPooling_max, ROIPoolingLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_TestsROIPooling_bilinear, ROIPoolingLayerTest, test_ROIPooling_bilinear, ROIPoolingLayerTest::getTestCaseName); + +} // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp index 3daad41fd0fe5a..4eb40365fa95d7 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp @@ -24,8 +24,8 @@ std::vector disabledTestPatterns() { R"(.*(QuantGroupConv3D).*)", // TODO: Issue: 34518 R"(.*RangeLayerTest.*)", - R"(.*(RangeAddSubgraphTest).*Start=1.2.*Stop=(5.2|-5.2).*Step=(0.1|-0.1).*netPRC=FP16.*)", - R"(.*(RangeNumpyAddSubgraphTest).*netPRC=FP16.*)", + R"(.*(RangeAddSubgraphTest).*Start=1.2.*Stop=(5.2|-5.2).*Step=(0.1|-0.1).*ET=f16.*)", + R"(.*(RangeNumpyAddSubgraphTest).*ET=f16.*)", // TODO: Issue: 43793 R"(.*InferRequestPreprocessDynamicallyInSetBlobTest.*iPRC=0.*_iLT=1.*)", R"(.*InferRequestPreprocessDynamicallyInSetBlobTest.*oPRC=0.*_oLT=1.*)", @@ -64,8 +64,6 @@ std::vector disabledTestPatterns() { R"(.*BF16NetworkRestore1.*)", R"(.*MobileNet_ssd_with_branching.*)", - // TODO: 57562 No dynamic output shape support - R"(.*NonZeroLayerTest.*)", // Not expected behavior R"(.*Behavior.*InferRequestSetBlobByType.*Batched.*)", R"(.*OVCompiledModelBaseTest.*(CanGetInputsInfoAndCheck|canSetConfigToCompiledModel).*)", @@ -177,8 +175,6 @@ std::vector disabledTestPatterns() { R"(.*(Hetero).*InferRequestPreprocessTest.*SetPreProcessToInferRequest.*)", // TODO: for 22.2 (Issue 68949) R"(.*smoke_AutoBatching_CPU/AutoBatching_Test_DetectionOutput.*)", - // Issue: 117837 - R"(.*smoke_4D_out_of_range/GatherInPlaceLayerTestCPU.*_indices=\(\-15\).*)", // Issue: 120222 R"(.*smoke_TopK/TopKLayerTest.Inference.*_k=1_axis=3_.*_modelType=f16_trgDev=CPU.*)", R"(.*smoke_TopK/TopKLayerTest.Inference.*_k=7_axis=3_.*_modelType=f16_trgDev=CPU.*)", @@ -189,13 +185,13 @@ std::vector disabledTestPatterns() { // Issue: 121313 R"(smoke_GroupConvBackpropData.*paddingDefined/GroupConvBackpropLayerTest.Inference.*f16.*)", R"(smoke_GroupConvBackpropData.*paddingDefined/GroupConvBackpropLayerTest.Inference.*f32.*)", + // Issue: 122177 + R"(smoke_LSTMSequenceCommon.*LSTMSequenceTest.Inference.*CONVERT_TO_TI.*)", + // Issue: 122094 + R"(smoke_Interpolate_Basic_Down_Sample_Tail/InterpolateLayerTest.Inference.*(asymmetric|align_corners).*f16.*)", + // Need to generate sequence exactly in the i64 data type. Enable in scope of i64 enabling. + R"(.*RandomUniformLayerTestCPU.*OutPrc=i64.*)", }; -#if defined(__APPLE__) && defined(OPENVINO_ARCH_ARM64) - // Issue: 120950 - retVector.emplace_back(R"(.*smoke_TensorIteratorCommon/TensorIteratorTest.Inference.*_modelType=f16_targetDevice=CPU.*)"); - retVector.emplace_back(R"(.*smoke_CtcGreedyDecoderBasic/CTCGreedyDecoderLayerTest.Inference.*netPRC=f16.*trgDev=CPU.*)"); - retVector.emplace_back(R"(.*CTCGreedyDecoderSeqLenLayerTest.Inference.*dataPRC=f16.*trgDev=CPU.*)"); -#endif #if defined(OPENVINO_ARCH_X86) retVector.emplace_back(R"(.*DetectionOutputLayerTest.*)"); @@ -224,6 +220,18 @@ std::vector disabledTestPatterns() { retVector.emplace_back(R"(smoke_NegativeQuantizedMatMulMultiplyFusion.*)"); // int8 specific retVector.emplace_back(R"(smoke_Quantized.*)"); + +#if defined(OV_CPU_ARM_ENABLE_FP16) + // Issue: 123019 + retVector.emplace_back(R"(smoke_AvgPool_ExplicitPad_CeilRounding.*modelType=f16.*)"); + retVector.emplace_back(R"(smoke_AvgPool_ExplicitPad_FloorRounding_5Dinput/PoolingLayerTest.*modelType=f16.*)"); + retVector.emplace_back(R"(smoke_AvgPool_SameUpperPad_FloorRounding_5Dinput/PoolingLayerTest.*modelType=f16.*)"); + retVector.emplace_back(R"(smoke_AvgPool_SameLowerPad_CeilRounding_5Dinput/PoolingLayerTest.*modelType=f16.*)"); + retVector.emplace_back(R"(smoke_CompareWithRefs_Mvn.*INFERENCE_PRECISION_HINT=f16.*)"); + retVector.emplace_back(R"(smoke_staticShapes4D.*INFERENCE_PRECISION_HINT=f16.*)"); + retVector.emplace_back(R"(smoke_dynamicShapes4D.*INFERENCE_PRECISION_HINT=f16.*)"); +#endif + #endif #if defined(OPENVINO_ARCH_ARM) diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/add.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/add.cpp index 45aaf9f4eeafdf..bd2f1aad832550 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/add.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/add.cpp @@ -68,6 +68,9 @@ std::vector> inShapesAddPair { {{{}, {{1, 128, 9, 30}}}, {{}, {{1, 128, 1, 30}}}}, {{{}, {{1, 128, 9, 1}}}, {{}, {{1, 128, 1, 30}}}}, {{{}, {{1, 128, 9, 16}}}, {{}, {{1, 128, 9, 1}}}}, + // Test Canonicalization and Dimension collapsing + {{{}, {{2, 17, 3, 4}}}, {{}, {{1, 3, 4}}}}, + {{{}, {{2, 17, 3, 4}}}, {{}, {{1, 4}}}}, // DS {{{1, -1, {1, 10}, {1, 33}}, {{1, 128, 1, 1}, {1, 128, 1, 9}, {1, 128, 1, 17}, {1, 128, 1, 29}, {1, 128, 9, 1}, {1, 128, 1, 1}}}, {{{1, 1}, {128, 128}, {1, 10}, {1, 33}}, {{1, 128, 1, 1}, {1, 128, 1, 9}, {1, 128, 1, 17}, {1, 128, 1, 29}, {1, 128, 1, 30}, {1, 128, 1, 1}}}}, diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/conv_eltwise_fusion.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/conv_eltwise_fusion.cpp index 2e23919cfd6c4c..e92f457f369aa9 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/conv_eltwise_fusion.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/conv_eltwise_fusion.cpp @@ -8,7 +8,7 @@ #include "common_test_utils/test_constants.hpp" -using namespace SubgraphTestsDefinitions; +using namespace ov::test; namespace { const std::vector types{ov::element::f32, ov::element::f16}; diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/conv_strides_opt.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/conv_strides_opt.cpp index 6cedcfbbf88241..f33b57d639138f 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/conv_strides_opt.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/conv_strides_opt.cpp @@ -2,28 +2,30 @@ // SPDX-License-Identifier: Apache-2.0 // -#include - #include "subgraph_tests/conv_strides_opt.hpp" -#include "common_test_utils/test_constants.hpp" -using namespace SubgraphTestsDefinitions; +#include + +using namespace ov::test; namespace { - std::vector input_shapes{ - ngraph::Shape{1, 1, 4, 4}, - ngraph::Shape{1, 64, 56, 56}, - }; - std::vector pads{ - ngraph::op::PadType::SAME_UPPER, - ngraph::op::PadType::SAME_LOWER, - ngraph::op::PadType::EXPLICIT, - }; - INSTANTIATE_TEST_SUITE_P(smoke_Convolution_StridesOpt, ConvStridesOpt, - ::testing::Combine( - ::testing::ValuesIn(input_shapes), - ::testing::ValuesIn(pads), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - ConvStridesOpt::getTestCaseName); + +std::vector input_shapes{ + ov::Shape{1, 1, 4, 4}, + ov::Shape{1, 64, 56, 56}, +}; + +std::vector pads{ + ov::op::PadType::SAME_UPPER, + ov::op::PadType::SAME_LOWER, + ov::op::PadType::EXPLICIT, +}; + +INSTANTIATE_TEST_SUITE_P(smoke_Convolution_StridesOpt, + ConvStridesOpt, + ::testing::Combine(::testing::ValuesIn(input_shapes), + ::testing::ValuesIn(pads), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + ConvStridesOpt::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/convert_pad_to_group_conv.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/convert_pad_to_group_conv.cpp index 627094f4e717ad..d23a35201b9db7 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/convert_pad_to_group_conv.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/convert_pad_to_group_conv.cpp @@ -2,42 +2,41 @@ // SPDX-License-Identifier: Apache-2.0 // -#include - #include "subgraph_tests/convert_pad_to_group_conv.hpp" -#include "common_test_utils/test_constants.hpp" -using namespace SubgraphTestsDefinitions; +#include + +using namespace ov::test; namespace { - const std::vector> pads_1d{ - {0, 0, 0}, {0, 0, 1}, {0, 2, 0}, {3, 0, 0} - }; - - const std::vector values{0., 1.}; - - INSTANTIATE_TEST_SUITE_P(smoke_Pad_1D, ConvertPadToConvTests, - ::testing::Combine( - ::testing::Values(ngraph::Shape{1, 8, 64}), - ::testing::ValuesIn(pads_1d), - ::testing::ValuesIn(pads_1d), - ::testing::ValuesIn(values), - ::testing::Values(ngraph::op::PadMode::CONSTANT), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - ConvertPadToConvTests::getTestCaseName); - - const std::vector> pads_2d{ - {0, 0, 0, 0}, {0, 0, 1, 2}, {0, 0, 2, 1}, - {0, 0, 10, 10}, {0, 0, 0, 4}, {0, 0, 4, 0} - }; - - INSTANTIATE_TEST_SUITE_P(smoke_Pad_2D, ConvertPadToConvTests, - ::testing::Combine( - ::testing::Values(ngraph::Shape{1, 8, 64, 16}), - ::testing::ValuesIn(pads_2d), - ::testing::ValuesIn(pads_2d), - ::testing::ValuesIn(values), - ::testing::Values(ngraph::op::PadMode::CONSTANT), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - ConvertPadToConvTests::getTestCaseName); +const std::vector> pads_1d{{0, 0, 0}, {0, 0, 1}, {0, 2, 0}, {3, 0, 0}}; + +const std::vector values{0., 1.}; + +INSTANTIATE_TEST_SUITE_P(smoke_Pad_1D, + ConvertPadToConvTests, + ::testing::Combine(::testing::Values(ov::Shape{1, 8, 64}), + ::testing::ValuesIn(pads_1d), + ::testing::ValuesIn(pads_1d), + ::testing::ValuesIn(values), + ::testing::Values(ov::op::PadMode::CONSTANT), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + ConvertPadToConvTests::getTestCaseName); + +const std::vector> pads_2d{{0, 0, 0, 0}, + {0, 0, 1, 2}, + {0, 0, 2, 1}, + {0, 0, 10, 10}, + {0, 0, 0, 4}, + {0, 0, 4, 0}}; + +INSTANTIATE_TEST_SUITE_P(smoke_Pad_2D, + ConvertPadToConvTests, + ::testing::Combine(::testing::Values(ov::Shape{1, 8, 64, 16}), + ::testing::ValuesIn(pads_2d), + ::testing::ValuesIn(pads_2d), + ::testing::ValuesIn(values), + ::testing::Values(ov::op::PadMode::CONSTANT), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + ConvertPadToConvTests::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/get_output_before_activation.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/get_output_before_activation.cpp index ca731518e9feea..4b9feeed52d5b3 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/get_output_before_activation.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/get_output_before_activation.cpp @@ -2,33 +2,27 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include "common_test_utils/test_constants.hpp" +#include "subgraph_tests/get_output_before_activation.hpp" + +namespace ov { +namespace test { -namespace SubgraphTestsDefinitions { namespace { - std::vector input_sizes = { - 80, - 32, - 64, - 100 - }; +std::vector input_sizes = {80, 32, 64, 100}; + +std::vector midLayerTypes{midOutputType::Mul, midOutputType::Sub, midOutputType::Sum}; - std::vector midLayerTypes { - midOutputType::Mul, - midOutputType::Sub, - midOutputType::Sum - }; +ov::AnyMap additional_config = {}; +} // namespace - std::map additional_config = {}; -} // namespace +INSTANTIATE_TEST_SUITE_P(OutputBeforeActivation, + OutputBeforeActivation, + ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_CPU), + ::testing::Values(ov::element::f32), + ::testing::ValuesIn(input_sizes), + ::testing::ValuesIn(midLayerTypes), + ::testing::Values(additional_config)), + OutputBeforeActivation::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(OutputBeforeActivation, OutputBeforeActivation, - ::testing::Combine( - ::testing::Values(ov::test::utils::DEVICE_CPU), - ::testing::Values(InferenceEngine::Precision::FP32), - ::testing::ValuesIn(input_sizes), - ::testing::ValuesIn(midLayerTypes), - ::testing::Values(additional_config)), - OutputBeforeActivation::getTestCaseName); -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/matmul_const_transposes_extraction.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/matmul_const_transposes_extraction.cpp index 41ef64232302f2..1851fd30789f05 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/matmul_const_transposes_extraction.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/matmul_const_transposes_extraction.cpp @@ -4,7 +4,7 @@ #include "subgraph_tests/matmul_const_transposes_extraction.hpp" -using namespace SubgraphTestsDefinitions; +using namespace ov::test; namespace { std::vector shape_params = { @@ -21,12 +21,12 @@ std::vector shape_params = { {{2, 3, 5, 10}, {1, 1, 10, 1}, false}, }; -INSTANTIATE_TEST_SUITE_P(smoke_MatMulConstTransposesExtractionTest, MatMulConstTransposesExtractionTest, - ::testing::Combine( - ::testing::ValuesIn(shape_params), - ::testing::Values(true), // can be fused - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MatMulConstTransposesExtractionTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_MatMulConstTransposesExtractionTest, + MatMulConstTransposesExtractionTest, + ::testing::Combine(::testing::ValuesIn(shape_params), + ::testing::Values(true), // can be fused + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MatMulConstTransposesExtractionTest::getTestCaseName); std::vector negative_shape_params = { {{5}, {5}, false}, @@ -46,12 +46,12 @@ std::vector negative_shape_param {{2, 3, 5, 10}, {2, 3, 10, 7}, false}, }; -INSTANTIATE_TEST_SUITE_P(smoke_NegativeMatMulConstTransposesExtractionTest, MatMulConstTransposesExtractionTest, - ::testing::Combine( - ::testing::ValuesIn(negative_shape_params), - ::testing::Values(false), // cannot be fused - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MatMulConstTransposesExtractionTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_NegativeMatMulConstTransposesExtractionTest, + MatMulConstTransposesExtractionTest, + ::testing::Combine(::testing::ValuesIn(negative_shape_params), + ::testing::Values(false), // cannot be fused + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MatMulConstTransposesExtractionTest::getTestCaseName); std::vector shape_params2 = { {{2, 2}, {2, 2}, false}, @@ -63,11 +63,11 @@ std::vector shape_params2 = { {{2, 3, 5, 10}, {1, 1, 10, 7}, false}, }; -INSTANTIATE_TEST_SUITE_P(smoke_QuantizedMatMulConstTransposesExtractionTest, QuantizedMatMulConstTransposesExtractionTest, - ::testing::Combine( - ::testing::ValuesIn(shape_params2), - ::testing::Values(true), // can be fused - ::testing::Values(ov::test::utils::DEVICE_CPU)), - QuantizedMatMulConstTransposesExtractionTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_QuantizedMatMulConstTransposesExtractionTest, + QuantizedMatMulConstTransposesExtractionTest, + ::testing::Combine(::testing::ValuesIn(shape_params2), + ::testing::Values(true), // can be fused + ::testing::Values(ov::test::utils::DEVICE_CPU)), + QuantizedMatMulConstTransposesExtractionTest::getTestCaseName); -} // namespace +} // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/matmul_multiply_fusion.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/matmul_multiply_fusion.cpp index 1f10491ad5bf90..026a7595ed9381 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/matmul_multiply_fusion.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/matmul_multiply_fusion.cpp @@ -4,7 +4,7 @@ #include "subgraph_tests/matmul_multiply_fusion.hpp" -using namespace SubgraphTestsDefinitions; +using namespace ov::test; namespace { std::vector shape_params = { @@ -67,12 +67,12 @@ std::vector shape_params = { {{2, 3, 5, 10}, {2, 3, 7, 10}, true, {2, 3, 1, 7}}, }; -INSTANTIATE_TEST_SUITE_P(smoke_MatMulMultiplyFusion, MatMulMultiplyFusion, - ::testing::Combine( - ::testing::ValuesIn(shape_params), - ::testing::Values(true), // can be fused - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MatMulMultiplyFusion::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_MatMulMultiplyFusion, + MatMulMultiplyFusion, + ::testing::Combine(::testing::ValuesIn(shape_params), + ::testing::Values(true), // can be fused + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MatMulMultiplyFusion::getTestCaseName); std::vector negative_shape_params = { {{5}, {5}, false, {1}}, @@ -108,12 +108,12 @@ std::vector negative_shape_params = { {{2, 3, 5, 10}, {2, 3, 10, 7}, false, {1, 1, 1, 1, 7}}, }; -INSTANTIATE_TEST_SUITE_P(smoke_NegativeMatMulMultiplyFusion, MatMulMultiplyFusion, - ::testing::Combine( - ::testing::ValuesIn(negative_shape_params), - ::testing::Values(false), // cannot be fused - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MatMulMultiplyFusion::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_NegativeMatMulMultiplyFusion, + MatMulMultiplyFusion, + ::testing::Combine(::testing::ValuesIn(negative_shape_params), + ::testing::Values(false), // cannot be fused + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MatMulMultiplyFusion::getTestCaseName); std::vector shape_params2 = { {{2, 2}, {2, 2}, false, {}}, @@ -158,12 +158,12 @@ std::vector shape_params2 = { {{2, 3, 5, 10}, {2, 3, 7, 10}, true, {2, 3, 1, 7}}, }; -INSTANTIATE_TEST_SUITE_P(smoke_QuantizedMatMulMultiplyFusion, QuantizedMatMulMultiplyFusion, - ::testing::Combine( - ::testing::ValuesIn(shape_params2), - ::testing::Values(true), // can be fused - ::testing::Values(ov::test::utils::DEVICE_CPU)), - QuantizedMatMulMultiplyFusion::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_QuantizedMatMulMultiplyFusion, + QuantizedMatMulMultiplyFusion, + ::testing::Combine(::testing::ValuesIn(shape_params2), + ::testing::Values(true), // can be fused + ::testing::Values(ov::test::utils::DEVICE_CPU)), + QuantizedMatMulMultiplyFusion::getTestCaseName); std::vector negative_shape_params2 = { {{2, 2}, {2, 2}, false, {2, 2}}, @@ -198,11 +198,11 @@ std::vector negative_shape_params2 = { {{2, 3, 5, 10}, {3, 7, 10}, true, {2, 3, 5, 7}}, }; -INSTANTIATE_TEST_SUITE_P(smoke_NegativeQuantizedMatMulMultiplyFusion, QuantizedMatMulMultiplyFusion, - ::testing::Combine( - ::testing::ValuesIn(negative_shape_params2), - ::testing::Values(false), // cannot be fused - ::testing::Values(ov::test::utils::DEVICE_CPU)), - QuantizedMatMulMultiplyFusion::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_NegativeQuantizedMatMulMultiplyFusion, + QuantizedMatMulMultiplyFusion, + ::testing::Combine(::testing::ValuesIn(negative_shape_params2), + ::testing::Values(false), // cannot be fused + ::testing::Values(ov::test::utils::DEVICE_CPU)), + QuantizedMatMulMultiplyFusion::getTestCaseName); -} // namespace +} // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/matmul_squeeze_add.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/matmul_squeeze_add.cpp index db6bdc22104958..97319465428a5c 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/matmul_squeeze_add.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/matmul_squeeze_add.cpp @@ -2,46 +2,27 @@ // SPDX-License-Identifier: Apache-2.0 // -#include - -#include "common_test_utils/test_constants.hpp" #include "subgraph_tests/matmul_squeeze_add.hpp" -using namespace SubgraphTestsDefinitions; +#include + +using namespace ov::test; namespace { -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16 -}; - -const std::vector> configs = { - { } -}; - -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_CPU), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(input_shapes), - ::testing::ValuesIn(output_sizes)), - MatmulSqueezeAddTest::getTestCaseName); +const std::vector netPrecisions = {ov::element::f32, ov::element::f16}; + +const std::vector configs = {{}}; + +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_CPU), + ::testing::ValuesIn(configs), + ::testing::ValuesIn(input_shapes), + ::testing::ValuesIn(output_sizes)), + MatmulSqueezeAddTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/mul_conv_fusion.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/mul_conv_fusion.cpp index 480a538c6c68ad..4ab6ddfbaefdb9 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/mul_conv_fusion.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/mul_conv_fusion.cpp @@ -2,263 +2,268 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "subgraph_tests/mul_conv_fusion.hpp" + #include -#include "subgraph_tests/mul_conv_fusion.hpp" #include "common_test_utils/test_constants.hpp" -#include - -using namespace SubgraphTestsDefinitions; +using namespace ov::test; namespace { - const std::vector types{ngraph::element::f32}; +const std::vector types{ov::element::f32}; - const std::vector const_shapes_fprop_1d{ - {}, - {1}, - {1, 1}, - {8, 1}, - {1, 1, 1}, - {1, 8, 1}, - }; +const std::vector const_shapes_fprop_1d{ + {}, + {1}, + {1, 1}, + {8, 1}, + {1, 1, 1}, + {1, 8, 1}, +}; - INSTANTIATE_TEST_SUITE_P(smoke_Convolution_1D, MulConvFusion, - ::testing::Combine( - ::testing::Values(ngraph::opset8::Convolution::get_type_info_static()), - ::testing::Values(ngraph::Shape{1, 8, 64}), - ::testing::Values(ngraph::Shape{64, 8, 1}), - ::testing::ValuesIn(const_shapes_fprop_1d), - ::testing::ValuesIn(types), - ::testing::Values(false), // Positive test - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MulConvFusion::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_Convolution_1D, + MulConvFusion, + ::testing::Combine(::testing::Values(ov::op::v1::Convolution::get_type_info_static()), + ::testing::Values(ov::Shape{1, 8, 64}), + ::testing::Values(ov::Shape{64, 8, 1}), + ::testing::ValuesIn(const_shapes_fprop_1d), + ::testing::ValuesIn(types), + ::testing::Values(false), // Positive test + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MulConvFusion::getTestCaseName); - const std::vector const_shapes_fprop_2d{ - {}, - {1}, - {1, 1}, - {1, 1, 1}, - {8, 1, 1}, - {1, 1, 1, 1}, - {1, 8, 1, 1}, - }; +const std::vector const_shapes_fprop_2d{ + {}, + {1}, + {1, 1}, + {1, 1, 1}, + {8, 1, 1}, + {1, 1, 1, 1}, + {1, 8, 1, 1}, +}; - INSTANTIATE_TEST_SUITE_P(smoke_Convolution_2D, MulConvFusion, - ::testing::Combine( - ::testing::Values(ngraph::opset8::Convolution::get_type_info_static()), - ::testing::Values(ngraph::Shape{2, 8, 14, 14}), - ::testing::Values(ngraph::Shape{2, 8, 7, 7}), - ::testing::ValuesIn(const_shapes_fprop_2d), - ::testing::ValuesIn(types), - ::testing::Values(false), // Positive test - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MulConvFusion::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_Convolution_2D, + MulConvFusion, + ::testing::Combine(::testing::Values(ov::op::v1::Convolution::get_type_info_static()), + ::testing::Values(ov::Shape{2, 8, 14, 14}), + ::testing::Values(ov::Shape{2, 8, 7, 7}), + ::testing::ValuesIn(const_shapes_fprop_2d), + ::testing::ValuesIn(types), + ::testing::Values(false), // Positive test + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MulConvFusion::getTestCaseName); - const std::vector const_shapes_fprop_2d_kernel_same_as_input{ - {7}, - {1, 7}, - {1, 1, 7}, - {8, 1, 7}, - {1, 1, 1, 7}, - {1, 8, 1, 7}, - {7, 1}, - {1, 7, 1}, - {8, 7, 1}, - {1, 1, 7, 1}, - {1, 8, 7, 1}, - {1, 1, 7, 7}, - {1, 8, 7, 7}, - }; +const std::vector const_shapes_fprop_2d_kernel_same_as_input{ + {7}, + {1, 7}, + {1, 1, 7}, + {8, 1, 7}, + {1, 1, 1, 7}, + {1, 8, 1, 7}, + {7, 1}, + {1, 7, 1}, + {8, 7, 1}, + {1, 1, 7, 1}, + {1, 8, 7, 1}, + {1, 1, 7, 7}, + {1, 8, 7, 7}, +}; - INSTANTIATE_TEST_SUITE_P(smoke_Convolution_2D_kernel_same_as_input, MulConvFusion, - ::testing::Combine( - ::testing::Values(ngraph::opset8::Convolution::get_type_info_static()), - ::testing::Values(ngraph::Shape{2, 8, 7, 7}), - ::testing::Values(ngraph::Shape{3, 8, 7, 7}), - ::testing::ValuesIn(const_shapes_fprop_2d_kernel_same_as_input), - ::testing::ValuesIn(types), - ::testing::Values(false), // Positive test - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MulConvFusion::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_Convolution_2D_kernel_same_as_input, + MulConvFusion, + ::testing::Combine(::testing::Values(ov::op::v1::Convolution::get_type_info_static()), + ::testing::Values(ov::Shape{2, 8, 7, 7}), + ::testing::Values(ov::Shape{3, 8, 7, 7}), + ::testing::ValuesIn(const_shapes_fprop_2d_kernel_same_as_input), + ::testing::ValuesIn(types), + ::testing::Values(false), // Positive test + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MulConvFusion::getTestCaseName); - const std::vector const_shapes_conv_bprop{ - {}, - {1}, - {1, 1}, - {1, 1, 1}, - {1, 1, 1, 1}, - {3, 1, 1}, - {1, 3, 1, 1}, - }; - INSTANTIATE_TEST_SUITE_P(smoke_ConvolutionBackpropData_2D, MulConvFusion, - ::testing::Combine( - ::testing::Values(ngraph::opset8::ConvolutionBackpropData::get_type_info_static()), - ::testing::Values(ngraph::Shape{4, 3, 64, 64}), - ::testing::Values(ngraph::Shape{3, 20, 3, 3}), - ::testing::ValuesIn(const_shapes_conv_bprop), - ::testing::ValuesIn(types), - ::testing::Values(false), // Positive test - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MulConvFusion::getTestCaseName); +const std::vector const_shapes_conv_bprop{ + {}, + {1}, + {1, 1}, + {1, 1, 1}, + {1, 1, 1, 1}, + {3, 1, 1}, + {1, 3, 1, 1}, +}; +INSTANTIATE_TEST_SUITE_P( + smoke_ConvolutionBackpropData_2D, + MulConvFusion, + ::testing::Combine(::testing::Values(ov::op::v1::ConvolutionBackpropData::get_type_info_static()), + ::testing::Values(ov::Shape{4, 3, 64, 64}), + ::testing::Values(ov::Shape{3, 20, 3, 3}), + ::testing::ValuesIn(const_shapes_conv_bprop), + ::testing::ValuesIn(types), + ::testing::Values(false), // Positive test + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MulConvFusion::getTestCaseName); - const std::vector const_shapes_group_conv{ - {}, - {1}, - {1, 1}, - {1, 1, 1}, - {12, 1, 1}, - {1, 1, 1, 1}, - {1, 12, 1, 1}, - }; +const std::vector const_shapes_group_conv{ + {}, + {1}, + {1, 1}, + {1, 1, 1}, + {12, 1, 1}, + {1, 1, 1, 1}, + {1, 12, 1, 1}, +}; - INSTANTIATE_TEST_SUITE_P(smoke_GroupConvolution_2D, MulConvFusion, - ::testing::Combine( - ::testing::Values(ngraph::opset8::GroupConvolution::get_type_info_static()), - ::testing::Values(ngraph::Shape{2, 12, 14, 14}), - ::testing::Values(ngraph::Shape{4, 5, 3, 7, 7}), - ::testing::ValuesIn(const_shapes_group_conv), - ::testing::ValuesIn(types), - ::testing::Values(false), // Positive test - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MulConvFusion::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_GroupConvolution_2D, + MulConvFusion, + ::testing::Combine(::testing::Values(ov::op::v1::GroupConvolution::get_type_info_static()), + ::testing::Values(ov::Shape{2, 12, 14, 14}), + ::testing::Values(ov::Shape{4, 5, 3, 7, 7}), + ::testing::ValuesIn(const_shapes_group_conv), + ::testing::ValuesIn(types), + ::testing::Values(false), // Positive test + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MulConvFusion::getTestCaseName); - const std::vector const_shapes_group_conv_kernel_same_as_input{ - {14}, - {1, 14}, - {1, 1, 14}, - {12, 1, 14}, - {1, 1, 1, 14}, - {1, 12, 1, 14}, - {14, 1}, - {1, 14, 1}, - {12, 14, 1}, - {1, 1, 14, 1}, - {1, 12, 14, 1}, - {1, 1, 14, 14}, - {1, 12, 14, 14}, - }; +const std::vector const_shapes_group_conv_kernel_same_as_input{ + {14}, + {1, 14}, + {1, 1, 14}, + {12, 1, 14}, + {1, 1, 1, 14}, + {1, 12, 1, 14}, + {14, 1}, + {1, 14, 1}, + {12, 14, 1}, + {1, 1, 14, 1}, + {1, 12, 14, 1}, + {1, 1, 14, 14}, + {1, 12, 14, 14}, +}; - INSTANTIATE_TEST_SUITE_P(smoke_GroupConvolution_2D_kernel_same_as_input, MulConvFusion, - ::testing::Combine( - ::testing::Values(ngraph::opset8::GroupConvolution::get_type_info_static()), - ::testing::Values(ngraph::Shape{2, 12, 14, 14}), - ::testing::Values(ngraph::Shape{4, 5, 3, 14, 14}), - ::testing::ValuesIn(const_shapes_group_conv_kernel_same_as_input), - ::testing::ValuesIn(types), - ::testing::Values(false), // Positive test - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MulConvFusion::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_GroupConvolution_2D_kernel_same_as_input, + MulConvFusion, + ::testing::Combine(::testing::Values(ov::op::v1::GroupConvolution::get_type_info_static()), + ::testing::Values(ov::Shape{2, 12, 14, 14}), + ::testing::Values(ov::Shape{4, 5, 3, 14, 14}), + ::testing::ValuesIn(const_shapes_group_conv_kernel_same_as_input), + ::testing::ValuesIn(types), + ::testing::Values(false), // Positive test + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MulConvFusion::getTestCaseName); - const std::vector const_shapes_group_conv_bprop{ - {}, - {1}, - {1, 1}, - {1, 1, 1}, - {12, 1, 1}, - {1, 1, 1, 1}, - {1, 12, 1, 1}, - }; +const std::vector const_shapes_group_conv_bprop{ + {}, + {1}, + {1, 1}, + {1, 1, 1}, + {12, 1, 1}, + {1, 1, 1, 1}, + {1, 12, 1, 1}, +}; - INSTANTIATE_TEST_SUITE_P(smoke_GroupConvolutionBackpropData_2D, MulConvFusion, - ::testing::Combine( - ::testing::Values(ngraph::opset8::GroupConvolutionBackpropData::get_type_info_static()), - ::testing::Values(ngraph::Shape{2, 12, 10, 10}), - ::testing::Values(ngraph::Shape{4, 3, 5, 2, 2}), - ::testing::ValuesIn(const_shapes_group_conv_bprop), - ::testing::ValuesIn(types), - ::testing::Values(false), // Positive test - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MulConvFusion::getTestCaseName); +INSTANTIATE_TEST_SUITE_P( + smoke_GroupConvolutionBackpropData_2D, + MulConvFusion, + ::testing::Combine(::testing::Values(ov::op::v1::GroupConvolutionBackpropData::get_type_info_static()), + ::testing::Values(ov::Shape{2, 12, 10, 10}), + ::testing::Values(ov::Shape{4, 3, 5, 2, 2}), + ::testing::ValuesIn(const_shapes_group_conv_bprop), + ::testing::ValuesIn(types), + ::testing::Values(false), // Positive test + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MulConvFusion::getTestCaseName); - const std::vector negative_const_shapes{ - {12, 64, 64}, - {2, 1, 1, 1}, - {1, 1, 64, 64}, - {1, 12, 64, 64}, - {2, 12, 64, 64}, - }; +const std::vector negative_const_shapes{ + {12, 64, 64}, + {2, 1, 1, 1}, + {1, 1, 64, 64}, + {1, 12, 64, 64}, + {2, 12, 64, 64}, +}; - INSTANTIATE_TEST_SUITE_P(smoke_NegativeConvolution_2D, MulConvFusion, - ::testing::Combine( - ::testing::Values(ngraph::opset8::Convolution::get_type_info_static()), - ::testing::Values(ngraph::Shape{2, 12, 64, 64}), - ::testing::Values(ngraph::Shape{20, 12, 1, 1}), - ::testing::ValuesIn(negative_const_shapes), - ::testing::ValuesIn(types), - ::testing::Values(true), // Negative test - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MulConvFusion::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_NegativeConvolution_2D, + MulConvFusion, + ::testing::Combine(::testing::Values(ov::op::v1::Convolution::get_type_info_static()), + ::testing::Values(ov::Shape{2, 12, 64, 64}), + ::testing::Values(ov::Shape{20, 12, 1, 1}), + ::testing::ValuesIn(negative_const_shapes), + ::testing::ValuesIn(types), + ::testing::Values(true), // Negative test + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MulConvFusion::getTestCaseName); - INSTANTIATE_TEST_SUITE_P(smoke_NegativeConvolutionBackpropData_2D, MulConvFusion, - ::testing::Combine( - ::testing::Values(ngraph::opset8::ConvolutionBackpropData::get_type_info_static()), - ::testing::Values(ngraph::Shape{2, 12, 64, 64}), - ::testing::Values(ngraph::Shape{12, 20, 3, 3}), - ::testing::ValuesIn(negative_const_shapes), - ::testing::ValuesIn(types), - ::testing::Values(true), // Negative test - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MulConvFusion::getTestCaseName); +INSTANTIATE_TEST_SUITE_P( + smoke_NegativeConvolutionBackpropData_2D, + MulConvFusion, + ::testing::Combine(::testing::Values(ov::op::v1::ConvolutionBackpropData::get_type_info_static()), + ::testing::Values(ov::Shape{2, 12, 64, 64}), + ::testing::Values(ov::Shape{12, 20, 3, 3}), + ::testing::ValuesIn(negative_const_shapes), + ::testing::ValuesIn(types), + ::testing::Values(true), // Negative test + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MulConvFusion::getTestCaseName); - INSTANTIATE_TEST_SUITE_P(smoke_NegativeGroupConvolution_2D, MulConvFusion, - ::testing::Combine( - ::testing::Values(ngraph::opset8::GroupConvolution::get_type_info_static()), - ::testing::Values(ngraph::Shape{2, 12, 64, 64}), - ::testing::Values(ngraph::Shape{4, 5, 3, 1, 2}), - ::testing::ValuesIn(negative_const_shapes), - ::testing::ValuesIn(types), - ::testing::Values(true), // Negative test - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MulConvFusion::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_NegativeGroupConvolution_2D, + MulConvFusion, + ::testing::Combine(::testing::Values(ov::op::v1::GroupConvolution::get_type_info_static()), + ::testing::Values(ov::Shape{2, 12, 64, 64}), + ::testing::Values(ov::Shape{4, 5, 3, 1, 2}), + ::testing::ValuesIn(negative_const_shapes), + ::testing::ValuesIn(types), + ::testing::Values(true), // Negative test + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MulConvFusion::getTestCaseName); - INSTANTIATE_TEST_SUITE_P(smoke_NegativeGroupConvolutionBackpropData_2D, MulConvFusion, - ::testing::Combine( - ::testing::Values(ngraph::opset8::GroupConvolutionBackpropData::get_type_info_static()), - ::testing::Values(ngraph::Shape{2, 12, 64, 64}), - ::testing::Values(ngraph::Shape{4, 3, 5, 1, 1}), - ::testing::ValuesIn(negative_const_shapes), - ::testing::ValuesIn(types), - ::testing::Values(true), // Negative test - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MulConvFusion::getTestCaseName); +INSTANTIATE_TEST_SUITE_P( + smoke_NegativeGroupConvolutionBackpropData_2D, + MulConvFusion, + ::testing::Combine(::testing::Values(ov::op::v1::GroupConvolutionBackpropData::get_type_info_static()), + ::testing::Values(ov::Shape{2, 12, 64, 64}), + ::testing::Values(ov::Shape{4, 3, 5, 1, 1}), + ::testing::ValuesIn(negative_const_shapes), + ::testing::ValuesIn(types), + ::testing::Values(true), // Negative test + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MulConvFusion::getTestCaseName); - const std::vector negative_const_shapes_kernel_same_as_input{ - {7}, - {1, 7}, - {1, 1, 7}, - {12, 1, 7}, - {1, 1, 1, 7}, - {1, 12, 1, 7}, - {7, 1}, - {1, 7, 1}, - {12, 7, 1}, - {1, 1, 7, 1}, - {1, 12, 7, 1}, - {1, 1, 7, 7}, - {1, 12, 7, 7}, - }; +const std::vector negative_const_shapes_kernel_same_as_input{ + {7}, + {1, 7}, + {1, 1, 7}, + {12, 1, 7}, + {1, 1, 1, 7}, + {1, 12, 1, 7}, + {7, 1}, + {1, 7, 1}, + {12, 7, 1}, + {1, 1, 7, 1}, + {1, 12, 7, 1}, + {1, 1, 7, 7}, + {1, 12, 7, 7}, +}; - INSTANTIATE_TEST_SUITE_P(smoke_NegativeConvolutionBackpropData_2D_kernel_same_as_input, MulConvFusion, - ::testing::Combine( - ::testing::Values(ngraph::opset8::ConvolutionBackpropData::get_type_info_static()), - ::testing::Values(ngraph::Shape{2, 12, 7, 7}), - ::testing::Values(ngraph::Shape{12, 20, 7, 7}), - ::testing::ValuesIn(negative_const_shapes_kernel_same_as_input), - ::testing::ValuesIn(types), - ::testing::Values(true), // Negative test - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MulConvFusion::getTestCaseName); +INSTANTIATE_TEST_SUITE_P( + smoke_NegativeConvolutionBackpropData_2D_kernel_same_as_input, + MulConvFusion, + ::testing::Combine(::testing::Values(ov::op::v1::ConvolutionBackpropData::get_type_info_static()), + ::testing::Values(ov::Shape{2, 12, 7, 7}), + ::testing::Values(ov::Shape{12, 20, 7, 7}), + ::testing::ValuesIn(negative_const_shapes_kernel_same_as_input), + ::testing::ValuesIn(types), + ::testing::Values(true), // Negative test + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MulConvFusion::getTestCaseName); - INSTANTIATE_TEST_SUITE_P(smoke_NegativeGroupConvolutionBackpropData_2D_kernel_same_as_input, MulConvFusion, - ::testing::Combine( - ::testing::Values(ngraph::opset8::GroupConvolutionBackpropData::get_type_info_static()), - ::testing::Values(ngraph::Shape{2, 12, 7, 7}), - ::testing::Values(ngraph::Shape{4, 3, 5, 7, 7}), - ::testing::ValuesIn(negative_const_shapes_kernel_same_as_input), - ::testing::ValuesIn(types), - ::testing::Values(true), // Negative test - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MulConvFusion::getTestCaseName); +INSTANTIATE_TEST_SUITE_P( + smoke_NegativeGroupConvolutionBackpropData_2D_kernel_same_as_input, + MulConvFusion, + ::testing::Combine(::testing::Values(ov::op::v1::GroupConvolutionBackpropData::get_type_info_static()), + ::testing::Values(ov::Shape{2, 12, 7, 7}), + ::testing::Values(ov::Shape{4, 3, 5, 7, 7}), + ::testing::ValuesIn(negative_const_shapes_kernel_same_as_input), + ::testing::ValuesIn(types), + ::testing::Values(true), // Negative test + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MulConvFusion::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/multiply_add.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/multiply_add.cpp index f28990117a39d3..c46e92708949b0 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/multiply_add.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/multiply_add.cpp @@ -2,31 +2,29 @@ // SPDX-License-Identifier: Apache-2.0 // -#include - #include "subgraph_tests/multiply_add.hpp" -using namespace SubgraphTestsDefinitions; +#include + +using namespace ov::test; namespace { -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32 -}; +const std::vector input_type = {ov::element::f32}; -const std::vector> inputShapes = { - {1, 3, 2, 2, 4, 5}, - {1, 3, 2, 2, 2, 4, 5}, - {1, 3, 2, 2, 2, 2, 4, 5}, - {1, 3, 2, 2, 2, 2, 2, 4, 5}, - {1, 3, 2, 2, 2, 2, 2, 2, 4, 5}, +const std::vector inputShapes = { + {1, 3, 2, 2, 4, 5}, + {1, 3, 2, 2, 2, 4, 5}, + {1, 3, 2, 2, 2, 2, 4, 5}, + {1, 3, 2, 2, 2, 2, 2, 4, 5}, + {1, 3, 2, 2, 2, 2, 2, 2, 4, 5}, }; -INSTANTIATE_TEST_SUITE_P(smoke_MultipleAdd_Nd, MultiplyAddLayerTest, - ::testing::Combine( - ::testing::ValuesIn(inputShapes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MultiplyAddLayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_MultipleAdd_Nd, + MultiplyAddLayerTest, + ::testing::Combine(::testing::ValuesIn(inputShapes), + ::testing::ValuesIn(input_type), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MultiplyAddLayerTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/mvn_multiply_add.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/mvn_multiply_add.cpp index 4fe0990bfba66a..f27050440a7cf9 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/mvn_multiply_add.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/mvn_multiply_add.cpp @@ -4,91 +4,75 @@ #include "subgraph_tests/mvn_multiply_add.hpp" -using namespace SubgraphTestsDefinitions; -using namespace InferenceEngine; +using namespace ov::test; namespace { -const std::vector netPrecision = { - Precision::FP32 -}; +const std::vector netPrecision = {ov::element::f32}; -std::vector idxPrecision = { - Precision::I64 -}; +std::vector idxPrecision = {ov::element::i64}; -const std::vector acrossChannels = { - true, - false -}; +const std::vector acrossChannels = {true, false}; -const std::vector normalizeVariance = { - true, - false -}; +const std::vector normalizeVariance = {true, false}; -const std::vector epsilon = { - 0.000000001f -}; +const std::vector epsilon = {0.000000001f}; -const std::vector epsMode = { - "inside_sqrt", - "outside_sqrt" -}; +const std::vector epsMode = {"inside_sqrt", "outside_sqrt"}; -const std::vector> shapes_1D = { - std::pair{ SizeVector{5}, SizeVector{5}}, - std::pair{ SizeVector{64}, SizeVector{64}}, +const std::vector> shapes_1D = { + std::pair{ov::Shape{5}, ov::Shape{5}}, + std::pair{ov::Shape{64}, ov::Shape{64}}, }; -const std::vector> shapes_2D = { - std::pair{ SizeVector{1, 5}, SizeVector{1, 5}}, - std::pair{ SizeVector{2, 17}, SizeVector{1, 17}}, - std::pair{ SizeVector{9, 64}, SizeVector{1, 64}}, - std::pair{ SizeVector{5, 15}, SizeVector{1, 15}}, +const std::vector> shapes_2D = { + std::pair{ov::Shape{1, 5}, ov::Shape{1, 5}}, + std::pair{ov::Shape{2, 17}, ov::Shape{1, 17}}, + std::pair{ov::Shape{9, 64}, ov::Shape{1, 64}}, + std::pair{ov::Shape{5, 15}, ov::Shape{1, 15}}, }; -const std::vector> shapes_3D = { - std::pair{ SizeVector{1, 5, 8}, SizeVector{1, 5, 8}}, - std::pair{ SizeVector{2, 17, 9}, SizeVector{1, 1, 9}}, - std::pair{ SizeVector{1, 1, 10}, SizeVector{1, 1, 10}}, - std::pair{ SizeVector{2, 3, 3}, SizeVector{2, 3, 3}}, +const std::vector> shapes_3D = { + std::pair{ov::Shape{1, 5, 8}, ov::Shape{1, 5, 8}}, + std::pair{ov::Shape{2, 17, 9}, ov::Shape{1, 1, 9}}, + std::pair{ov::Shape{1, 1, 10}, ov::Shape{1, 1, 10}}, + std::pair{ov::Shape{2, 3, 3}, ov::Shape{2, 3, 3}}, }; -INSTANTIATE_TEST_SUITE_P(smoke_MVNMultiplyAdd_1D, MVNMultiplyAdd, - ::testing::Combine( - ::testing::ValuesIn(shapes_1D), - ::testing::ValuesIn(netPrecision), - ::testing::ValuesIn(idxPrecision), - ::testing::Values(std::vector{0}), - ::testing::ValuesIn(normalizeVariance), - ::testing::ValuesIn(epsilon), - ::testing::ValuesIn(epsMode), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MVNMultiplyAdd::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_MVNMultiplyAdd_2D, MVNMultiplyAdd, - ::testing::Combine( - ::testing::ValuesIn(shapes_2D), - ::testing::ValuesIn(netPrecision), - ::testing::ValuesIn(idxPrecision), - ::testing::Values(std::vector{1}), - ::testing::ValuesIn(normalizeVariance), - ::testing::ValuesIn(epsilon), - ::testing::ValuesIn(epsMode), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MVNMultiplyAdd::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_MVNMultiplyAdd_3D, MVNMultiplyAdd, - ::testing::Combine( - ::testing::ValuesIn(shapes_3D), - ::testing::ValuesIn(netPrecision), - ::testing::ValuesIn(idxPrecision), - ::testing::Values(std::vector{2}), - ::testing::ValuesIn(normalizeVariance), - ::testing::ValuesIn(epsilon), - ::testing::ValuesIn(epsMode), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MVNMultiplyAdd::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_MVNMultiplyAdd_1D, + MVNMultiplyAdd, + ::testing::Combine(::testing::ValuesIn(shapes_1D), + ::testing::ValuesIn(netPrecision), + ::testing::ValuesIn(idxPrecision), + ::testing::Values(std::vector{0}), + ::testing::ValuesIn(normalizeVariance), + ::testing::ValuesIn(epsilon), + ::testing::ValuesIn(epsMode), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MVNMultiplyAdd::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_MVNMultiplyAdd_2D, + MVNMultiplyAdd, + ::testing::Combine(::testing::ValuesIn(shapes_2D), + ::testing::ValuesIn(netPrecision), + ::testing::ValuesIn(idxPrecision), + ::testing::Values(std::vector{1}), + ::testing::ValuesIn(normalizeVariance), + ::testing::ValuesIn(epsilon), + ::testing::ValuesIn(epsMode), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MVNMultiplyAdd::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_MVNMultiplyAdd_3D, + MVNMultiplyAdd, + ::testing::Combine(::testing::ValuesIn(shapes_3D), + ::testing::ValuesIn(netPrecision), + ::testing::ValuesIn(idxPrecision), + ::testing::Values(std::vector{2}), + ::testing::ValuesIn(normalizeVariance), + ::testing::ValuesIn(epsilon), + ::testing::ValuesIn(epsMode), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MVNMultiplyAdd::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/parameter_result.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/parameter_result.cpp index 7f25b2ef54ef44..a70b3c7bbc3659 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/parameter_result.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/parameter_result.cpp @@ -11,12 +11,6 @@ using namespace ov::test; namespace { -INSTANTIATE_TEST_SUITE_P(smoke_Check, - ParameterResultSubgraphTestLegacyApi, - ::testing::Combine(::testing::Values(ov::test::InputShape{{1, 3, 10, 10}, {}}), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - ParameterResultSubgraphTestBase::getTestCaseName); - const std::vector inputShapes = { ov::test::InputShape{{1, 3, 10, 10}, {{1, 3, 10, 10}, {1, 3, 10, 10}}}, ov::test::InputShape{{-1, -1, -1, -1}, {{1, 3, 10, 10}, {2, 5, 3, 10}, {1, 3, 10, 10}, {1, 3, 10, 10}}}, diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/perm_conv_perm_concat.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/perm_conv_perm_concat.cpp index 4fe713ebc44187..8617d1e68c2742 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/perm_conv_perm_concat.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/perm_conv_perm_concat.cpp @@ -2,42 +2,45 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include "subgraph_tests/perm_conv_perm_concat.hpp" -#include "common_test_utils/test_constants.hpp" + +#include + namespace { -std::vector> input_shapes { +std::vector input_shapes{ {1, 1, 7, 32}, {1, 1, 8, 16}, }; -std::vector> kernel_shapes { +std::vector kernel_shapes{ {1, 3}, {1, 5}, }; -std::vector output_channels { +std::vector output_channels{ 32, 64, }; -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, +std::vector netPrecisions = { + ov::element::f32, + ov::element::f16, }; -std::map additional_config = { -}; -} // namespace - -namespace SubgraphTestsDefinitions { -INSTANTIATE_TEST_SUITE_P(smoke_basic, PermConvPermConcat, - ::testing::Combine( - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_CPU), - ::testing::ValuesIn(input_shapes), - ::testing::ValuesIn(kernel_shapes), - ::testing::ValuesIn(output_channels), - ::testing::Values(additional_config)), - PermConvPermConcat::getTestCaseName); -} // namespace SubgraphTestsDefinitions +ov::AnyMap additional_config = {}; +} // namespace + +namespace ov { +namespace test { + +INSTANTIATE_TEST_SUITE_P(smoke_basic, + PermConvPermConcat, + ::testing::Combine(::testing::ValuesIn(netPrecisions), + ::testing::Values(ov::test::utils::DEVICE_CPU), + ::testing::ValuesIn(input_shapes), + ::testing::ValuesIn(kernel_shapes), + ::testing::ValuesIn(output_channels), + ::testing::Values(additional_config)), + PermConvPermConcat::getTestCaseName); +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/range_add.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/range_add.cpp index 409ba17f27e68f..5b19f8b34d7f81 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/range_add.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/range_add.cpp @@ -2,97 +2,76 @@ // SPDX-License-Identifier: Apache-2.0 // -#include - #include "subgraph_tests/range_add.hpp" -#include "common_test_utils/test_constants.hpp" -using namespace SubgraphTestsDefinitions; +#include + +using namespace ov::test; namespace { -const std::vector positiveStart = { 1.0f, 1.2f }; -const std::vector positiveStop = { 5.0f, 5.2f }; -const std::vector positiveStep = { 1.0f, 0.1f }; +const std::vector positiveStart = {1.0f, 1.2f}; +const std::vector positiveStop = {5.0f, 5.2f}; +const std::vector positiveStep = {1.0f, 0.1f}; -const std::vector negativeStart = { 1.0f, 1.2f }; -const std::vector negativeStop = { -5.0f, -5.2f }; -const std::vector negativeStep = { -1.0f, -0.1f }; +const std::vector negativeStart = {1.0f, 1.2f}; +const std::vector negativeStop = {-5.0f, -5.2f}; +const std::vector negativeStep = {-1.0f, -0.1f}; -const std::vector trunc_start = { 1.2f, 1.9f }; -const std::vector trunc_stop = { 11.4f, 11.8f }; -const std::vector trunc_step = { 1.3f, 2.8f }; +const std::vector trunc_start = {1.2f, 1.9f}; +const std::vector trunc_stop = {11.4f, 11.8f}; +const std::vector trunc_step = {1.3f, 2.8f}; -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16 // "[NOT_IMPLEMENTED] Input image format FP16 is not supported yet... +const std::vector element_types = { + ov::element::f32, + ov::element::f16 // "[NOT_IMPLEMENTED] Input image format FP16 is not supported yet... }; // ------------------------------ V0 ------------------------------ -INSTANTIATE_TEST_SUITE_P(smoke_BasicPositive, RangeAddSubgraphTest, - ::testing::Combine( - ::testing::ValuesIn(positiveStart), - ::testing::ValuesIn(positiveStop), - ::testing::ValuesIn(positiveStep), - ::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_CPU)), - RangeAddSubgraphTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_BasicPositive, + RangeAddSubgraphTest, + ::testing::Combine(::testing::ValuesIn(positiveStart), + ::testing::ValuesIn(positiveStop), + ::testing::ValuesIn(positiveStep), + ::testing::ValuesIn(element_types), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + RangeAddSubgraphTest::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(smoke_BasicNegative, RangeAddSubgraphTest, - ::testing::Combine( - ::testing::ValuesIn(negativeStart), - ::testing::ValuesIn(negativeStop), - ::testing::ValuesIn(negativeStep), - ::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_CPU)), - RangeAddSubgraphTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_BasicNegative, + RangeAddSubgraphTest, + ::testing::Combine(::testing::ValuesIn(negativeStart), + ::testing::ValuesIn(negativeStop), + ::testing::ValuesIn(negativeStep), + ::testing::ValuesIn(element_types), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + RangeAddSubgraphTest::getTestCaseName); // ------------------------------ V4 ------------------------------ -INSTANTIATE_TEST_SUITE_P(smoke_BasicPositive, RangeNumpyAddSubgraphTest, - ::testing::Combine( - ::testing::ValuesIn(positiveStart), - ::testing::ValuesIn(positiveStop), - ::testing::ValuesIn(positiveStep), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - RangeNumpyAddSubgraphTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_BasicPositive, + RangeNumpyAddSubgraphTest, + ::testing::Combine(::testing::ValuesIn(positiveStart), + ::testing::ValuesIn(positiveStop), + ::testing::ValuesIn(positiveStep), + ::testing::ValuesIn(element_types), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + RangeNumpyAddSubgraphTest::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(smoke_BasicNegative, RangeNumpyAddSubgraphTest, - ::testing::Combine( - ::testing::ValuesIn(negativeStart), - ::testing::ValuesIn(negativeStop), - ::testing::ValuesIn(negativeStep), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - RangeNumpyAddSubgraphTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_BasicNegative, + RangeNumpyAddSubgraphTest, + ::testing::Combine(::testing::ValuesIn(negativeStart), + ::testing::ValuesIn(negativeStop), + ::testing::ValuesIn(negativeStep), + ::testing::ValuesIn(element_types), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + RangeNumpyAddSubgraphTest::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(smoke_BasicTruncateInputs, RangeNumpyAddSubgraphTest, - ::testing::Combine( - ::testing::ValuesIn(trunc_start), - ::testing::ValuesIn(trunc_stop), - ::testing::ValuesIn(trunc_step), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::I32), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - RangeNumpyAddSubgraphTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_BasicTruncateInputs, + RangeNumpyAddSubgraphTest, + ::testing::Combine(::testing::ValuesIn(trunc_start), + ::testing::ValuesIn(trunc_stop), + ::testing::ValuesIn(trunc_step), + ::testing::ValuesIn(element_types), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + RangeNumpyAddSubgraphTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/relu_shape_of.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/relu_shape_of.cpp index 18ad81aecc25d2..00559d09144d2d 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/relu_shape_of.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/relu_shape_of.cpp @@ -2,22 +2,20 @@ // SPDX-License-Identifier: Apache-2.0 // -#include - #include "subgraph_tests/relu_shape_of.hpp" -#include "common_test_utils/test_constants.hpp" -using namespace SubgraphTestsDefinitions; +#include + +using namespace ov::test; namespace { - const std::vector netPrecisions = { - InferenceEngine::Precision::I32 - }; +const std::vector input_types = {ov::element::i32}; - INSTANTIATE_TEST_SUITE_P(smoke_Check, ReluShapeOfSubgraphTest, - ::testing::Combine( - ::testing::ValuesIn(netPrecisions), - ::testing::Values(std::vector({20, 10, 10, 10})), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - ReluShapeOfSubgraphTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_Check, + ReluShapeOfSubgraphTest, + ::testing::Combine(::testing::ValuesIn(input_types), + ::testing::Values(ov::element::i64), + ::testing::Values(ov::Shape{20, 10, 10, 10}), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + ReluShapeOfSubgraphTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/reshape_squeeze_reshape_relu.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/reshape_squeeze_reshape_relu.cpp index 79743431999170..fa82dc5baa7f1e 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/reshape_squeeze_reshape_relu.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/reshape_squeeze_reshape_relu.cpp @@ -2,47 +2,46 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include "subgraph_tests/reshape_squeeze_reshape_relu.hpp" -#include "common_test_utils/test_constants.hpp" -using namespace SubgraphTestsDefinitions; +#include + +using namespace ov::test; namespace { - std::vector inputs{ - {{1, 1, 3}, {0, 1}}, - {{1, 1, 3}, {0}}, - {{1, 1, 3}, {1}}, - {{1, 3, 1}, {0, 2}}, - {{1, 3, 1}, {0}}, - {{1, 3, 1}, {2}}, - {{3, 1, 1}, {1, 2}}, - {{3, 1, 1}, {1}}, - {{3, 1, 1}, {2}}, - {{4, 1, 3, 1}, {1, 3}}, - {{4, 1, 1, 3}, {1, 2}}, - {{1, 4, 1, 3}, {0, 2}}, - {{1, 3, 5, 2, 1}, {0, 4}}, - {{3, 1, 2, 4, 4, 3}, {1}}, - {{1, 1, 1, 1, 1, 3}, {0, 1, 2, 3, 4}}, - {{1, 1, 1, 1, 1, 3}, {1, 3}}, - {{1}, {0}}, - }; +std::vector inputs{ + {{1, 1, 3}, {0, 1}}, + {{1, 1, 3}, {0}}, + {{1, 1, 3}, {1}}, + {{1, 3, 1}, {0, 2}}, + {{1, 3, 1}, {0}}, + {{1, 3, 1}, {2}}, + {{3, 1, 1}, {1, 2}}, + {{3, 1, 1}, {1}}, + {{3, 1, 1}, {2}}, + {{4, 1, 3, 1}, {1, 3}}, + {{4, 1, 1, 3}, {1, 2}}, + {{1, 4, 1, 3}, {0, 2}}, + {{1, 3, 5, 2, 1}, {0, 4}}, + {{3, 1, 2, 4, 4, 3}, {1}}, + {{1, 1, 1, 1, 1, 3}, {0, 1, 2, 3, 4}}, + {{1, 1, 1, 1, 1, 3}, {1, 3}}, + {{1}, {0}}, +}; - std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, - }; +std::vector input_types = { + ov::element::f32, + ov::element::f16, +}; - const std::vector opTypes = { - ngraph::helpers::SqueezeOpType::SQUEEZE, - ngraph::helpers::SqueezeOpType::UNSQUEEZE - }; +const std::vector opTypes = {ov::test::utils::SqueezeOpType::SQUEEZE, + ov::test::utils::SqueezeOpType::UNSQUEEZE}; - INSTANTIATE_TEST_SUITE_P(smoke_reshape_squeeze_reshape_relu, ReshapeSqueezeReshapeRelu, - ::testing::Combine( - ::testing::ValuesIn(inputs), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_CPU), - ::testing::ValuesIn(opTypes)), - ReshapeSqueezeReshapeRelu::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_reshape_squeeze_reshape_relu, + ReshapeSqueezeReshapeRelu, + ::testing::Combine(::testing::ValuesIn(inputs), + ::testing::ValuesIn(input_types), + ::testing::Values(ov::test::utils::DEVICE_CPU), + ::testing::ValuesIn(opTypes)), + ReshapeSqueezeReshapeRelu::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/split_conv_concat.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/split_conv_concat.cpp index 8e347ad75c31d4..1d60e68187709e 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/split_conv_concat.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/split_conv_concat.cpp @@ -2,28 +2,20 @@ // SPDX-License-Identifier: Apache-2.0 // -#include - #include "subgraph_tests/split_conv_concat.hpp" -#include "common_test_utils/test_constants.hpp" -using namespace SubgraphTestsDefinitions; +#include + +using namespace ov::test; namespace { -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16 -}; +const std::vector input_types = {ov::element::f32, ov::element::f16}; -INSTANTIATE_TEST_SUITE_P(smoke_NoReshape, SplitConvConcat, - ::testing::Combine( - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::SizeVector({1, 6, 40, 40})), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - SplitConvConcat::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_NoReshape, + SplitConvConcat, + ::testing::Combine(::testing::ValuesIn(input_types), + ::testing::Values(ov::Shape{1, 6, 40, 40}), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + SplitConvConcat::getTestCaseName); } // namespace - - - - diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/variadic_split_pad.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/variadic_split_pad.cpp index 7386a46ef3868a..27d63ad27ff852 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/variadic_split_pad.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/variadic_split_pad.cpp @@ -4,60 +4,52 @@ #include "subgraph_tests/variadic_split_pad.hpp" -using namespace SubgraphTestsDefinitions; +using namespace ov::test; namespace { -const std::vector netPrecision = { - InferenceEngine::Precision::FP32 -}; +const std::vector input_type = {ov::element::f32}; -const std::vector shapes = { - {1, 8, 3, 2}, - {3, 8, 8, 8}, +const std::vector shapes = { + {1, 8, 3, 2}, + {3, 8, 8, 8}, }; const std::vector> connectedIndexes = { - {0}, - {0, 2}, - {0, 1, 3}, - {0, 1, 1, 0}, - {0, 0, 0, 1}, + {0}, + {0, 2}, + {0, 1, 3}, + {0, 1, 1, 0}, + {0, 0, 0, 1}, }; -const std::vector> numSplits = { - {2, 2, 2, 2}, - {1, 2, 4, 1}, - {3, 2, 2, 1} -}; +const std::vector> numSplits = {{2, 2, 2, 2}, {1, 2, 4, 1}, {3, 2, 2, 1}}; const std::vector> padsBegin = { - {0, 0, 0, 0}, - {0, 0, 1, 1}, + {0, 0, 0, 0}, + {0, 0, 1, 1}, }; const std::vector> padsEnd = { - {0, 0, 0, 0}, - {0, 0, 1, 1}, -}; - -const std::vector padMode = { - ngraph::helpers::PadMode::CONSTANT, - ngraph::helpers::PadMode::EDGE, - ngraph::helpers::PadMode::REFLECT, - ngraph::helpers::PadMode::SYMMETRIC + {0, 0, 0, 0}, + {0, 0, 1, 1}, }; -INSTANTIATE_TEST_SUITE_P(smoke_CPU, VariadicSplitPad, - ::testing::Combine( - ::testing::ValuesIn(shapes), - ::testing::Values(1), - ::testing::ValuesIn(numSplits), - ::testing::ValuesIn(connectedIndexes), - ::testing::ValuesIn(padsBegin), - ::testing::ValuesIn(padsEnd), - ::testing::ValuesIn(padMode), - ::testing::ValuesIn(netPrecision), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - VariadicSplitPad::getTestCaseName); +const std::vector padMode = {ov::op::PadMode::CONSTANT, + ov::op::PadMode::EDGE, + ov::op::PadMode::REFLECT, + ov::op::PadMode::SYMMETRIC}; + +INSTANTIATE_TEST_SUITE_P(smoke_CPU, + VariadicSplitPad, + ::testing::Combine(::testing::ValuesIn(shapes), + ::testing::Values(1), + ::testing::ValuesIn(numSplits), + ::testing::ValuesIn(connectedIndexes), + ::testing::ValuesIn(padsBegin), + ::testing::ValuesIn(padsEnd), + ::testing::ValuesIn(padMode), + ::testing::ValuesIn(input_type), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + VariadicSplitPad::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/pooling.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/pooling.cpp new file mode 100644 index 00000000000000..e40771146cd0ec --- /dev/null +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/pooling.cpp @@ -0,0 +1,464 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "gtest/gtest.h" +#include "pooling.hpp" +#include "test_utils/cpu_test_utils.hpp" + +using namespace InferenceEngine; +using namespace CPUTestUtils; +using namespace ngraph::helpers; +using namespace ov::test; + +namespace CPULayerTestsDefinitions { + +std::string PoolingLayerCPUTest::getTestCaseName(const testing::TestParamInfo& obj) { + LayerTestsDefinitions::poolSpecificParams basicParamsSet; + InputShape inputShapes; + ElementType inPrc; + bool isInt8; + CPUSpecificParams cpuParams; + fusingSpecificParams fusingParams; + std::tie(basicParamsSet, inputShapes, inPrc, isInt8, cpuParams, fusingParams) = obj.param; + + ngraph::helpers::PoolingTypes poolType; + std::vector kernel, stride; + std::vector padBegin, padEnd; + ngraph::op::PadType padType; + ngraph::op::RoundingType roundingType; + bool excludePad; + std::tie(poolType, kernel, stride, padBegin, padEnd, roundingType, padType, excludePad) = basicParamsSet; + + std::ostringstream results; + results << "IS=("; + results << ov::test::utils::partialShape2str({inputShapes.first}) << ")_"; + results << "TS="; + for (const auto& shape : inputShapes.second) { + results << ov::test::utils::vec2str(shape) << "_"; + } + results << "Prc=" << inPrc << "_"; + switch (poolType) { + case ngraph::helpers::PoolingTypes::MAX: + results << "MaxPool_"; + break; + case ngraph::helpers::PoolingTypes::AVG: + results << "AvgPool_"; + results << "ExcludePad=" << excludePad << "_"; + break; + } + results << "K" << ov::test::utils::vec2str(kernel) << "_"; + results << "S" << ov::test::utils::vec2str(stride) << "_"; + results << "PB" << ov::test::utils::vec2str(padBegin) << "_"; + results << "PE" << ov::test::utils::vec2str(padEnd) << "_"; + results << "Rounding=" << roundingType << "_"; + results << "AutoPad=" << padType << "_"; + results << "INT8=" << isInt8 << "_"; + + results << CPUTestsBase::getTestCaseName(cpuParams); + results << CpuTestWithFusing::getTestCaseName(fusingParams); + return results.str(); +} + +void PoolingLayerCPUTest::SetUp() { + targetDevice = ov::test::utils::DEVICE_CPU; + + LayerTestsDefinitions::poolSpecificParams basicParamsSet; + InputShape inputShapes; + ElementType inPrc; + bool isInt8; + CPUSpecificParams cpuParams; + fusingSpecificParams fusingParams; + std::tie(basicParamsSet, inputShapes, inPrc, isInt8, cpuParams, fusingParams) = this->GetParam(); + + ngraph::helpers::PoolingTypes poolType; + std::vector kernel, stride; + std::vector padBegin, padEnd; + ngraph::op::PadType padType; + ngraph::op::RoundingType roundingType; + bool excludePad; + std::tie(poolType, kernel, stride, padBegin, padEnd, roundingType, padType, excludePad) = basicParamsSet; + + std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; + std::tie(postOpMgrPtr, fusedOps) = fusingParams; + + if (selectedType.empty()) { + selectedType = getPrimitiveType(); + } + if (isInt8) + selectedType = selectedType + "_I8"; + else + selectedType = makeSelectedTypeStr(selectedType, inPrc); + + init_input_shapes({inputShapes}); + + ov::ParameterVector params; + for (auto&& shape : inputDynamicShapes) { + params.push_back(std::make_shared(inPrc, shape)); + } + + std::shared_ptr poolInput = params[0]; + if (isInt8) { + ov::Shape newShape(poolInput->get_output_partial_shape(0).size(), 1); + poolInput = ngraph::builder::makeFakeQuantize(poolInput, inPrc, 256, newShape); + } + + std::shared_ptr pooling = ngraph::builder::makePooling(poolInput, + stride, + padBegin, + padEnd, + kernel, + roundingType, + padType, + excludePad, + poolType); + + function = makeNgraphFunction(inPrc, params, pooling, "PoolingCPU"); +} + +std::string MaxPoolingV8LayerCPUTest::getTestCaseName( + const testing::TestParamInfo& obj) { + LayerTestsDefinitions::maxPoolV8SpecificParams basicParamsSet; + InputShape inputShapes; + ElementType inPrc; + CPUSpecificParams cpuParams; + std::tie(basicParamsSet, inputShapes, inPrc, cpuParams) = obj.param; + + std::vector kernel, stride, dilation; + std::vector padBegin, padEnd; + ngraph::op::PadType padType; + ngraph::op::RoundingType roundingType; + ngraph::element::Type indexElementType; + int64_t axis; + std::tie(kernel, stride, dilation, padBegin, padEnd, indexElementType, axis, roundingType, padType) = + basicParamsSet; + + std::ostringstream results; + results << "IS=("; + results << ov::test::utils::partialShape2str({inputShapes.first}) << ")_"; + results << "TS="; + for (const auto& shape : inputShapes.second) { + results << ov::test::utils::vec2str(shape) << "_"; + } + results << "Prc=" << inPrc << "_"; + results << "MaxPool_"; + results << "K" << ov::test::utils::vec2str(kernel) << "_"; + results << "S" << ov::test::utils::vec2str(stride) << "_"; + results << "D" << ov::test::utils::vec2str(dilation) << "_"; + results << "PB" << ov::test::utils::vec2str(padBegin) << "_"; + results << "PE" << ov::test::utils::vec2str(padEnd) << "_"; + results << "Rounding=" << roundingType << "_"; + results << "AutoPad=" << padType << "_"; + + results << CPUTestsBase::getTestCaseName(cpuParams); + return results.str(); +} + +void MaxPoolingV8LayerCPUTest::SetUp() { + targetDevice = ov::test::utils::DEVICE_CPU; + + LayerTestsDefinitions::maxPoolV8SpecificParams basicParamsSet; + InputShape inputShapes; + ElementType inPrc; + CPUSpecificParams cpuParams; + std::tie(basicParamsSet, inputShapes, inPrc, cpuParams) = this->GetParam(); + + std::vector kernel, stride, dilation; + std::vector padBegin, padEnd; + ngraph::op::PadType padType; + ngraph::op::RoundingType roundingType; + ngraph::element::Type indexElementType; + int64_t axis; + std::tie(kernel, stride, dilation, padBegin, padEnd, indexElementType, axis, roundingType, padType) = + basicParamsSet; + std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; + if (selectedType.empty()) { + selectedType = getPrimitiveType(); + } + selectedType = makeSelectedTypeStr(selectedType, inPrc); + + init_input_shapes({inputShapes}); + + ov::ParameterVector params; + for (auto&& shape : inputDynamicShapes) { + params.push_back(std::make_shared(inPrc, shape)); + } + std::shared_ptr pooling = ngraph::builder::makeMaxPoolingV8(params[0], + stride, + dilation, + padBegin, + padEnd, + kernel, + roundingType, + padType, + indexElementType, + axis); + pooling->get_rt_info() = getCPUInfo(); + ngraph::ResultVector results{std::make_shared(pooling->output(0))}; + function = std::make_shared(results, params, "MaxPooling"); +} + +TEST_P(PoolingLayerCPUTest, CompareWithRefs) { + run(); + CheckPluginRelatedResults(compiledModel, "Pooling"); +} + +TEST_P(MaxPoolingV8LayerCPUTest, CompareWithRefs) { + run(); + CheckPluginRelatedResults(compiledModel, "Pooling"); +} + +namespace Pooling { + +// The combination of parameters: NCHW + CEIL gives an accuracy problem in ACL AvgPool +const ngraph::op::RoundingType expectedAvgRoundingType() { +#if defined(OPENVINO_ARCH_ARM) || defined(OPENVINO_ARCH_ARM64) + return ngraph::op::RoundingType::FLOOR; +#else + return ngraph::op::RoundingType::CEIL; +#endif +} + +const std::vector& paramsMax3D() { + static const std::vector paramsMax3D = { + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {2}, {2}, {0}, {0}, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {4}, {2}, {0}, {0}, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {2}, {1}, {0}, {0}, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false }, + }; + return paramsMax3D; +} + +const std::vector& paramsAvg3D() { + static const std::vector paramsAvg3D = { + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {3}, {1}, {1}, {0}, + expectedAvgRoundingType(), ngraph::op::PadType::SAME_UPPER, false }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {3}, {1}, {1}, {0}, + expectedAvgRoundingType(), ngraph::op::PadType::EXPLICIT, true }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {4}, {4}, {2}, {2}, + expectedAvgRoundingType(), ngraph::op::PadType::EXPLICIT, true }, + }; + return paramsAvg3D; +} + +const std::vector& inpOutPrecision() { + static const std::vector inpOutPrecision = {ElementType::f32/*, ElementType::bf16*/}; + return inpOutPrecision; +} + +const std::vector& paramsMax4D() { + static const std::vector paramsMax4D = { + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {2, 2}, {2, 2}, {0, 0}, {0, 0}, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_LOWER, false }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {2, 2}, {2, 2}, {0, 0}, {0, 0}, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_UPPER, false }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {4, 2}, {2, 2}, {0, 0}, {0, 0}, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {4, 2}, {2, 1}, {0, 0}, {0, 0}, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false }, + }; + return paramsMax4D; +} + +const std::vector& paramsMaxV84D() { + static const std::vector paramsMaxV84D = { + LayerTestsDefinitions::maxPoolV8SpecificParams{ {2, 2}, {2, 2}, {1, 1}, {0, 0}, {0, 0}, + ngraph::element::Type_t::i32, 0, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_LOWER }, + }; + return paramsMaxV84D; +} + +const std::vector& inputShapes3D() { + static const std::vector inputShapes3D = { + { {}, {{3, 4, 64}} }, + { {}, {{2, 8, 12}} }, + { {}, {{1, 16, 12}} }, + { {}, {{1, 21, 4}} }, + { {}, {{1, 32, 8}} }, + { + // dynamic + {-1, -1, -1}, + // target + { + {1, 32, 8}, + {1, 21, 4}, + {2, 8, 12} + } + }, + { + // dynamic + {{1, 5}, {4, 32}, {1, 64}}, + // target + { + {3, 4, 64}, + {1, 16, 12}, + {1, 32, 8} + } + } + }; + return inputShapes3D; +} + +const std::vector& inputShapes4D() { + static const std::vector inputShapes4D = { + { {}, {{3, 4, 64, 64}} }, + { {}, {{2, 8, 8, 12}} }, + { {}, {{1, 16, 16, 12}} }, + { {}, {{1, 21, 8, 4}} }, + { {}, {{1, 32, 8, 8}} }, + { + // dynamic + {-1, -1, -1, -1}, + // target + { + {1, 32, 8, 8}, + {1, 21, 8, 4}, + {2, 8, 8, 12}, + {1, 96, 125, 125} + } + }, + { + // dynamic + {{1, 5}, {4, 32}, {1, 64}, {1, 64}}, + // target + { + {3, 4, 64, 64}, + {1, 16, 16, 12}, + {1, 32, 8, 8} + } + }, + { + // dynamic + {{1, 10}, 16, 8, 8}, + // target + { + {1, 16, 8, 8}, + {2, 16, 8, 8}, + } + } + }; + return inputShapes4D; +} + +const std::vector& inputShapes5D() { + static const std::vector inputShapes5D = { + { {}, {{1, 4, 16, 16, 16}} }, + { {}, {{2, 8, 8, 8, 8}} }, + { {}, {{2, 16, 12, 16, 20}} }, + { {}, {{1, 19, 16, 20, 8}} }, + { {}, {{1, 32, 16, 8, 12}} }, + { + // dynamic + {-1, -1, -1, -1, -1}, + // target + { + {2, 8, 8, 8, 8}, + {1, 19, 16, 20, 8}, + {1, 4, 16, 16, 16} + } + }, + { + // dynamic + {{1, 5}, {4, 32}, {1, 64}, {1, 64}, {1, 25}}, + // target + { + {1, 4, 16, 16, 16}, + {1, 32, 16, 8, 12}, + {3, 16, 4, 8, 3} + } + } + }; + return inputShapes5D; +} + +const std::vector& paramsMaxV85D() { + static const std::vector paramsMaxV85D = { + LayerTestsDefinitions::maxPoolV8SpecificParams{ {2, 2, 2}, {1, 1, 1}, {1, 1, 1}, {0, 0, 0}, {0, 0, 0}, + ngraph::element::Type_t::i32, 0, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_LOWER }, + }; + return paramsMaxV85D; +} + +const std::vector& paramsAvg4D() { + static const std::vector paramsAvg4D = { + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2}, {2, 2}, {1, 0}, {0, 0}, + expectedAvgRoundingType(), ngraph::op::PadType::SAME_LOWER, true }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2}, {2, 2}, {1, 0}, {0, 0}, + expectedAvgRoundingType(), ngraph::op::PadType::SAME_UPPER, true }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2}, {2, 2}, {1, 0}, {0, 0}, + expectedAvgRoundingType(), ngraph::op::PadType::SAME_LOWER, false }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2}, {2, 2}, {1, 0}, {0, 0}, + expectedAvgRoundingType(), ngraph::op::PadType::SAME_UPPER, false }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2}, {2, 2}, {0, 0}, {0, 0}, + expectedAvgRoundingType(), ngraph::op::PadType::EXPLICIT, true }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {4, 4}, {4, 4}, {2, 2}, {2, 2}, + expectedAvgRoundingType(), ngraph::op::PadType::EXPLICIT, true }, + }; + return paramsAvg4D; +} + +const std::vector& paramsAvg5D() { + static const std::vector paramsAvg5D = { + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2, 2}, {2, 2, 2}, {1, 0, 0}, {0, 0, 0}, + expectedAvgRoundingType(), ngraph::op::PadType::SAME_LOWER, true }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2, 2}, {2, 2, 2}, {1, 0, 0}, {0, 0, 0}, + expectedAvgRoundingType(), ngraph::op::PadType::SAME_UPPER, true }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2, 2}, {2, 2, 2}, {1, 0, 0}, {0, 0, 0}, + expectedAvgRoundingType(), ngraph::op::PadType::SAME_LOWER, false }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2, 2}, {2, 2, 2}, {1, 0, 0}, {0, 0, 0}, + expectedAvgRoundingType(), ngraph::op::PadType::SAME_UPPER, false }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2, 2}, {2, 2, 2}, {0, 0, 0}, {0, 0, 0}, + expectedAvgRoundingType(), ngraph::op::PadType::EXPLICIT, true }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {3, 3, 3}, {3, 3, 3}, {1, 1, 1}, {0, 0, 0}, + expectedAvgRoundingType(), ngraph::op::PadType::EXPLICIT, true }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {4, 4, 4}, {2, 2, 2}, {2, 2, 2}, {2, 2, 2}, + expectedAvgRoundingType(), ngraph::op::PadType::EXPLICIT, true }, + }; + return paramsAvg5D; +} + +const std::vector& paramsMax5D() { + static const std::vector paramsMax5D = { + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {2, 2, 2}, {1, 1, 1}, {0, 0, 0}, {0, 0, 0}, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_LOWER, false }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {2, 2, 2}, {1, 1, 1}, {0, 0, 0}, {0, 0, 0}, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_UPPER, false }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {2, 2, 2}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false }, + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {3, 3, 3}, {2, 2, 2}, {1, 1, 1}, {1, 1, 1}, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false }, + }; + return paramsMax5D; +} + +const std::vector& paramsAvg4D_Large() { + static const std::vector paramsAvg4D_Large = { + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {65, 65}, {65, 65}, {0, 0}, {0, 0}, + ngraph::op::RoundingType::FLOOR, ngraph::op::PadType::VALID, true }, + }; + return paramsAvg4D_Large; +} + +const std::vector& inputShapes4D_Large() { + static const std::vector inputShapes4D_Large = { + { + // dynamic + {-1, -1, -1, -1}, + // target + { + {1, 16, 65, 65}, + {1, 8, 130, 130}, + {1, 16, 65, 65} + } + }, + }; + return inputShapes4D_Large; +} + + +} // namespace Pooling +} // namespace CPULayerTestsDefinitions \ No newline at end of file diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/pooling.hpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/pooling.hpp new file mode 100644 index 00000000000000..ecf12a0360de1f --- /dev/null +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/pooling.hpp @@ -0,0 +1,69 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "ov_models/builders.hpp" +#include "test_utils/cpu_test_utils.hpp" +#include "test_utils/fusing_test_utils.hpp" +#include "shared_test_classes/single_layer/pooling.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" + +using namespace ov::test; +using namespace CPUTestUtils; + +namespace CPULayerTestsDefinitions { + +using poolLayerCpuTestParamsSet = std::tuple; + +using maxPoolV8LayerCpuTestParamsSet = std::tuple; + +class PoolingLayerCPUTest : public testing::WithParamInterface, + virtual public SubgraphBaseTest, public CpuTestWithFusing { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; + +class MaxPoolingV8LayerCPUTest : public testing::WithParamInterface, + virtual public SubgraphBaseTest, public CPUTestsBase { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; + +namespace Pooling { +const std::vector& inpOutPrecision(); +const ngraph::op::RoundingType expectedAvgRoundingType(); + +const std::vector& paramsMax3D(); +const std::vector& paramsAvg3D(); +const std::vector& paramsMax4D(); + +const std::vector& paramsMaxV84D(); +const std::vector& paramsMaxV85D(); + +const std::vector& inputShapes3D(); +const std::vector& inputShapes4D(); +const std::vector& inputShapes4D_Large(); +const std::vector& inputShapes5D(); + +const std::vector& paramsAvg4D(); +const std::vector& paramsAvg4D_Large(); +const std::vector& paramsAvg5D(); +const std::vector& paramsMax5D(); +} // namespace Pooling +} // namespace CPULayerTestsDefinitions \ No newline at end of file diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/random_uniform.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/random_uniform.cpp new file mode 100644 index 00000000000000..2f9706e7d2562e --- /dev/null +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/random_uniform.cpp @@ -0,0 +1,265 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "random_uniform.hpp" +#include "ov_models/builders.hpp" + +using namespace CPUTestUtils; +using namespace ov::test; + +namespace CPULayerTestsDefinitions { + +std::string RandomUniformLayerTestCPU::getTestCaseName(const testing::TestParamInfo& obj) { + const auto& out_shape = std::get<0>(obj.param); + const auto& min_max = std::get<1>(obj.param); + + std::ostringstream result; + + result << "IS={" << out_shape.size(); + result << "}_OS=" << out_shape; + result << "_Min=" << std::get<0>(min_max); + result << "_Max=" << std::get<1>(min_max); + result << "_ShapePrc=" << std::get<2>(obj.param); + result << "_OutPrc=" << std::get<3>(obj.param); + result << "_GlobalSeed=" << std::get<4>(obj.param); + result << "_OperationalSeed=" << std::get<5>(obj.param); + result << "_ConstIn={" << utils::bool2str(std::get<6>(obj.param)) << "," + << utils::bool2str(std::get<7>(obj.param)) << "," + << utils::bool2str(std::get<8>(obj.param)) << "}"; + + result << CPUTestsBase::getTestCaseName(std::get<9>(obj.param)); + + const auto& config = std::get<10>(obj.param); + if (!config.empty()) { + result << "_PluginConf={"; + for (const auto& conf_item : config) { + result << "_" << conf_item.first << "="; + conf_item.second.print(result); + } + result << "}"; + } + + return result.str(); +} + +void RandomUniformLayerTestCPU::SetUp() { + targetDevice = utils::DEVICE_CPU; + + const auto& params = this->GetParam(); + m_output_shape = std::get<0>(params); + const auto& min_max = std::get<1>(params); + const auto& shape_prc = std::get<2>(params); + const auto& output_prc = std::get<3>(params); + m_global_seed = std::get<4>(params); + m_operational_seed = std::get<5>(params); + const auto& const_in_1 = std::get<6>(params); + const auto& const_in_2 = std::get<7>(params); + const auto& const_in_3 = std::get<8>(params); + const auto& cpu_params = std::get<9>(params); + configuration = std::get<10>(params); + + m_min_val = std::get<0>(min_max); + m_max_val = std::get<1>(min_max); + std::tie(inFmts, outFmts, priority, selectedType) = cpu_params; + +#if defined(OV_CPU_WITH_ACL) + updateSelectedType("ref_any", output_prc, configuration); +#else + if (output_prc == ElementType::i64) { + updateSelectedType(getPrimitiveType(), ElementType::i32, configuration); + } else if (output_prc == ElementType::f64) { + updateSelectedType(getPrimitiveType(), ElementType::f32, configuration); + } else if (output_prc == ElementType::f16) { + if (InferenceEngine::with_cpu_x86_avx512_core_fp16()) { + updateSelectedType(getPrimitiveType(), ElementType::f16, configuration); + } else { + updateSelectedType(getPrimitiveType(), ElementType::f32, configuration); + } + } else if (output_prc == ElementType::bf16) { + if (InferenceEngine::with_cpu_x86_bfloat16()) { + updateSelectedType(getPrimitiveType(), ElementType::bf16, configuration); + } else { + updateSelectedType("ref_any", ElementType::bf16, configuration); + } + } else { + updateSelectedType(getPrimitiveType(), output_prc, configuration); + } +#endif + + std::vector in_shapes; + ov::ParameterVector in_params; + std::vector> inputs; + + if (!const_in_1) { + in_shapes.push_back({{}, {{m_output_shape.size()}}}); + in_params.push_back(std::make_shared(shape_prc, ov::PartialShape{static_cast(m_output_shape.size())})); + in_params.back()->set_friendly_name("shape"); + inputs.push_back(in_params.back()); + } else { + inputs.push_back(ngraph::builder::makeConstant(shape_prc, {m_output_shape.size()}, m_output_shape)); + } + if (!const_in_2) { + in_shapes.push_back({{}, {{1}}}); + in_params.push_back(std::make_shared(output_prc, ov::PartialShape{1})); + in_params.back()->set_friendly_name("minval"); + inputs.push_back(in_params.back()); + } else { + inputs.push_back(ngraph::builder::makeConstant(output_prc, {1}, std::vector{m_min_val})); + } + if (!const_in_3) { + in_shapes.push_back({{}, {{1}}}); + in_params.push_back(std::make_shared(output_prc, ov::PartialShape{1})); + in_params.back()->set_friendly_name("maxval"); + inputs.push_back(in_params.back()); + } else { + inputs.push_back(ngraph::builder::makeConstant(output_prc, {1}, std::vector{m_max_val})); + } + + init_input_shapes(in_shapes); + + const auto rnd_op = std::make_shared(inputs[0], inputs[1], inputs[2], output_prc, m_global_seed, m_operational_seed); + const ov::ResultVector results{std::make_shared(rnd_op)}; + + function = std::make_shared(results, in_params, "RandomUniformLayerTestCPU"); +} + +template +void fill_data(TD* dst, const TS* src, size_t len) { + for (size_t i = 0llu; i < len; i++) { + dst[i] = static_cast(src[i]); + } +} + +void RandomUniformLayerTestCPU::generate_inputs(const std::vector& targetInputStaticShapes) { + inputs.clear(); + const auto& func_inputs = function->inputs(); + + for (size_t i = 0llu; i < func_inputs.size(); ++i) { + const auto& func_input = func_inputs[i]; + const auto& name = func_input.get_node()->get_friendly_name(); + const auto& in_prc = func_input.get_element_type(); + auto tensor = ov::Tensor(in_prc, targetInputStaticShapes[i]); + +#define CASE(P, S, L) \ +case P : \ +fill_data(tensor.data::value_type>(), S, L); break; + + if (name == "shape") { + switch (in_prc) { + CASE(ElementType::i32, m_output_shape.data(), m_output_shape.size()) + CASE(ElementType::i64, m_output_shape.data(), m_output_shape.size()) + default: + OPENVINO_THROW("RandomUniform does not support precision ", in_prc, " for the Shape input."); + } + } else if (name == "minval") { + switch (in_prc) { + CASE(ElementType::f32, &m_min_val, 1) + CASE(ElementType::f16, &m_min_val, 1) + CASE(ElementType::bf16, &m_min_val, 1) + CASE(ElementType::i32, &m_min_val, 1) + CASE(ElementType::i64, &m_min_val, 1) + CASE(ElementType::f64, &m_min_val, 1) + default: + OPENVINO_THROW("RandomUniform does not support precision ", in_prc, " for the Minval input."); + } + } else if (name == "maxval") { + switch (in_prc) { + CASE(ElementType::f32, &m_max_val, 1) + CASE(ElementType::f16, &m_max_val, 1) + CASE(ElementType::bf16, &m_max_val, 1) + CASE(ElementType::i32, &m_max_val, 1) + CASE(ElementType::i64, &m_max_val, 1) + CASE(ElementType::f64, &m_max_val, 1) + default: + OPENVINO_THROW("RandomUniform does not support precision ", in_prc, " for the Maxval input."); + } + } + +#undef CASE + + inputs.insert({func_input.get_node_shared_ptr(), tensor}); + } +} + +void RandomUniformLayerTestCPU::compare(const std::vector& expected, const std::vector& actual) { + if (m_global_seed != 0lu || m_operational_seed != 0lu) { + SubgraphBaseTest::compare(expected, actual); + return; + } + + // When both seed values are equal to zero, RandomUniform should generate non-deterministic sequence. + // In this case will use Mean and Variance metrics. + +#define CASE(X) case X : rndUCompare::value_type>(expected[0], actual[0]); break; + + switch (expected[0].get_element_type()) { + CASE(ElementType::f32) + CASE(ElementType::i32) + CASE(ElementType::f16) + CASE(ElementType::bf16) + CASE(ElementType::i64) + CASE(ElementType::f64) + default: OPENVINO_THROW("Unsupported element type: ", expected[0].get_element_type()); + } + +#undef CASE +} + +precisions_map RandomUniformLayerTestCPU::get_ref_precisions_convert_map() { + precisions_map precisions; + + if (!InferenceEngine::with_cpu_x86_avx512_core()) { + precisions.insert({ ov::element::bf16, ov::element::f32 }); + } + if (!InferenceEngine::with_cpu_x86_avx512_core_fp16()) { + precisions.insert({ ov::element::f16, ov::element::f32 }); + } + + return precisions; +} + +inline double less_or_equal(double a, double b) { + return (b - a) >= (std::fmax(std::fabs(a), std::fabs(b)) * std::numeric_limits::epsilon()); +} + +template +void RandomUniformLayerTestCPU::rndUCompare(const ov::Tensor& expected, const ov::Tensor& actual) { + auto actual_data = actual.data(); + size_t shape_size_cnt = ov::shape_size(expected.get_shape()); + double act_mean = 0.0; + double act_variance = 0.0; + const double exp_mean = (m_max_val + m_min_val) / 2.0; + const double exp_variance = std::pow(m_max_val - m_min_val, 2) / 12.0; + + for (size_t i = 0; i < shape_size_cnt; ++i) { + auto actual_value = static_cast(actual_data[i]); + if (std::isnan(actual_value)) { + std::ostringstream out_stream; + out_stream << "Actual value is NAN on coordinate: " << i; + throw std::runtime_error(out_stream.str()); + } + act_mean += actual_value; + act_variance += std::pow(actual_value - exp_mean, 2); + } + act_mean /= shape_size_cnt; + act_variance /= shape_size_cnt; + + auto rel_mean = (exp_mean - act_mean) / (m_max_val - m_min_val); + auto rel_variance = (exp_variance - act_variance) / std::pow(m_max_val - m_min_val, 2); + + if (!(less_or_equal(rel_mean, m_mean_threshold) && less_or_equal(rel_variance, m_variance_threshold))) { + std::ostringstream out_stream; + out_stream << "rel_mean < m_mean_threshold && rel_variance < m_variance_threshold" << + "\n\t rel_mean: " << rel_mean << + "\n\t rel_variance: " << rel_variance; + throw std::runtime_error(out_stream.str()); + } +} + +TEST_P(RandomUniformLayerTestCPU, CompareWithRefs) { + run(); + CheckPluginRelatedResults(compiledModel, "RandomUniform"); +} + +} // namespace CPULayerTestsDefinitions diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/random_uniform.hpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/random_uniform.hpp new file mode 100644 index 00000000000000..1cb9f5fccc451a --- /dev/null +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/random_uniform.hpp @@ -0,0 +1,53 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "test_utils/cpu_test_utils.hpp" + +namespace CPULayerTestsDefinitions { + +typedef std::tuple< + ov::Shape, // Output shapes + std::tuple, // Min and Max values + ov::test::ElementType, // Shape precision + ov::test::ElementType, // Output precision + uint64_t, // Global seed + uint64_t, // Operational seed + bool, // Is 1st input constant + bool, // Is 2nd input constant + bool, // Is 3rd input constant + CPUTestUtils::CPUSpecificParams, // CPU specific params + ov::AnyMap // Additional plugin configuration +> RandomUniformLayerTestCPUParamSet; + +class RandomUniformLayerTestCPU : public testing::WithParamInterface, + public ov::test::SubgraphBaseTest, public CPUTestUtils::CPUTestsBase { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; + + void generate_inputs(const std::vector& target_shapes) override; + + void compare(const std::vector& expected, const std::vector& actual) override; + + precisions_map get_ref_precisions_convert_map() override; + + template + void rndUCompare(const ov::Tensor& expected, const ov::Tensor& actual); + +private: + ov::Shape m_output_shape; + uint64_t m_global_seed; + uint64_t m_operational_seed; + double m_min_val; + double m_max_val; + static constexpr double m_mean_threshold = 0.05; + static constexpr double m_variance_threshold = 0.1; +}; + +} // namespace CPULayerTestsDefinitions diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/common/pooling.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/common/pooling.cpp new file mode 100644 index 00000000000000..e15408a6085b9d --- /dev/null +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/common/pooling.cpp @@ -0,0 +1,181 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "single_layer_tests/classes/pooling.hpp" +#include "shared_test_classes/single_layer/pooling.hpp" +#include "test_utils/cpu_test_utils.hpp" +#include "test_utils/fusing_test_utils.hpp" + +using namespace InferenceEngine; +using namespace CPUTestUtils; +using namespace ngraph::helpers; +using namespace ov::test; + +namespace CPULayerTestsDefinitions { +namespace Pooling { + +static CPUSpecificParams expectedCpuConfig() { +#if defined(OPENVINO_ARCH_ARM) || defined(OPENVINO_ARCH_ARM64) + return CPUSpecificParams{{}, {}, {"acl"}, "acl"}; +#else + return CPUSpecificParams{{}, {}, {"ref_any"}, "ref_any"}; +#endif +} +const std::vector vecCpuConfigs = {expectedCpuConfig()}; + +const std::vector paramsAvg3D_RefOnly = { + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2}, {2}, {2}, {2}, + expectedAvgRoundingType(), ngraph::op::PadType::EXPLICIT, false }, +}; + +INSTANTIATE_TEST_SUITE_P(smoke_MaxPool_CPU_3D, PoolingLayerCPUTest, + ::testing::Combine( + ::testing::ValuesIn(paramsMax3D()), + ::testing::ValuesIn(inputShapes3D()), + ::testing::ValuesIn((inpOutPrecision())), + ::testing::Values(false), + ::testing::ValuesIn(vecCpuConfigs), + ::testing::Values(emptyFusingSpec)), + PoolingLayerCPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_3D, PoolingLayerCPUTest, + ::testing::Combine( + ::testing::ValuesIn(paramsAvg3D()), + ::testing::ValuesIn(inputShapes3D()), + ::testing::ValuesIn((inpOutPrecision())), + ::testing::Values(false), + ::testing::ValuesIn(vecCpuConfigs), + ::testing::Values(emptyFusingSpec)), + PoolingLayerCPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_3D_NotOptimized, PoolingLayerCPUTest, + ::testing::Combine( + ::testing::ValuesIn(paramsAvg3D_RefOnly), + ::testing::ValuesIn(inputShapes3D()), + ::testing::ValuesIn((inpOutPrecision())), + ::testing::Values(false), + ::testing::Values(expectedCpuConfig()), + ::testing::Values(emptyFusingSpec)), + PoolingLayerCPUTest::getTestCaseName); + +const std::vector paramsAvg4D_RefOnly = { + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2}, {2, 2}, {2, 2}, {2, 2}, + expectedAvgRoundingType(), ngraph::op::PadType::EXPLICIT, false }, +}; + +INSTANTIATE_TEST_SUITE_P(smoke_MaxPool_CPU_4D, PoolingLayerCPUTest, + ::testing::Combine( + ::testing::ValuesIn(paramsMax4D()), + ::testing::ValuesIn(inputShapes4D()), + ::testing::ValuesIn((inpOutPrecision())), + ::testing::Values(false), + ::testing::ValuesIn(vecCpuConfigs), + ::testing::Values(emptyFusingSpec)), + PoolingLayerCPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_MaxPoolV8_CPU_4D, MaxPoolingV8LayerCPUTest, + ::testing::Combine( + ::testing::ValuesIn(paramsMaxV84D()), + ::testing::ValuesIn(inputShapes4D()), + ::testing::ValuesIn((inpOutPrecision())), + ::testing::ValuesIn(vecCpuConfigs)), + MaxPoolingV8LayerCPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_4D, PoolingLayerCPUTest, + ::testing::Combine( + ::testing::ValuesIn(paramsAvg4D()), + ::testing::ValuesIn(inputShapes4D()), + ::testing::ValuesIn((inpOutPrecision())), + ::testing::Values(false), + ::testing::ValuesIn(vecCpuConfigs), + ::testing::Values(emptyFusingSpec)), + PoolingLayerCPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_4D_NotOptimized, PoolingLayerCPUTest, + ::testing::Combine( + ::testing::ValuesIn(paramsAvg4D_RefOnly), + ::testing::ValuesIn(inputShapes4D()), + ::testing::ValuesIn((inpOutPrecision())), + ::testing::Values(false), + ::testing::Values(expectedCpuConfig()), + ::testing::Values(emptyFusingSpec)), + PoolingLayerCPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_Large, PoolingLayerCPUTest, + ::testing::Combine( + ::testing::ValuesIn(paramsAvg4D_Large()), + ::testing::ValuesIn(inputShapes4D_Large()), + ::testing::ValuesIn((inpOutPrecision())), + ::testing::Values(false), + ::testing::ValuesIn(vecCpuConfigs), + ::testing::Values(emptyFusingSpec)), + PoolingLayerCPUTest::getTestCaseName); + +const std::vector paramsMaxV85D_ref = { + LayerTestsDefinitions::maxPoolV8SpecificParams{ {2, 2, 2}, {1, 1, 1}, {2, 2, 2}, {0, 0, 0}, {0, 0, 0}, + ngraph::element::Type_t::i32, 0, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_UPPER }, + LayerTestsDefinitions::maxPoolV8SpecificParams{ {2, 2, 2}, {1, 1, 1}, {2, 2, 2}, {1, 1, 1}, {1, 1, 1}, + ngraph::element::Type_t::i32, 0, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT }, + LayerTestsDefinitions::maxPoolV8SpecificParams{ {2, 3, 4}, {2, 2, 2}, {2, 1, 1}, {1, 1, 1}, {1, 2, 2}, + ngraph::element::Type_t::i32, 0, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT }, +}; + +const std::vector paramsAvg5D_RefOnly = { + LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2, 2}, {2, 2, 2}, {2, 2, 2}, {2, 2, 2}, + expectedAvgRoundingType(), ngraph::op::PadType::EXPLICIT, false }, +}; + +//FIXME: 5D cases are temporarly disabled on ARM because ACL support check in Pooling::getSupportedDescriptors() can't check layout +#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64) +INSTANTIATE_TEST_SUITE_P(smoke_MaxPool_CPU_5D, PoolingLayerCPUTest, + ::testing::Combine( + ::testing::ValuesIn(paramsMax5D()), + ::testing::ValuesIn(inputShapes5D()), + ::testing::ValuesIn((inpOutPrecision())), + ::testing::Values(false), + ::testing::ValuesIn(vecCpuConfigs), + ::testing::Values(emptyFusingSpec)), + PoolingLayerCPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_MaxPoolV8_CPU_5D, MaxPoolingV8LayerCPUTest, + ::testing::Combine( + ::testing::ValuesIn(paramsMaxV85D()), + ::testing::ValuesIn(inputShapes5D()), + ::testing::ValuesIn((inpOutPrecision())), + ::testing::ValuesIn(vecCpuConfigs)), + MaxPoolingV8LayerCPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_MaxPoolV8_CPU_5D_ref, MaxPoolingV8LayerCPUTest, + ::testing::Combine( + ::testing::ValuesIn(paramsMaxV85D_ref), + ::testing::ValuesIn(inputShapes5D()), + ::testing::ValuesIn((inpOutPrecision())), + ::testing::Values(expectedCpuConfig())), + MaxPoolingV8LayerCPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_5D, PoolingLayerCPUTest, + ::testing::Combine( + ::testing::ValuesIn(paramsAvg5D()), + ::testing::ValuesIn(inputShapes5D()), + ::testing::ValuesIn((inpOutPrecision())), + ::testing::Values(false), + ::testing::ValuesIn(vecCpuConfigs), + ::testing::Values(emptyFusingSpec)), + PoolingLayerCPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_5D_NotOptimized, PoolingLayerCPUTest, + ::testing::Combine( + ::testing::ValuesIn(paramsAvg5D_RefOnly), + ::testing::ValuesIn(inputShapes5D()), + ::testing::ValuesIn((inpOutPrecision())), + ::testing::Values(false), + ::testing::Values(expectedCpuConfig()), + ::testing::Values(emptyFusingSpec)), + PoolingLayerCPUTest::getTestCaseName); +#endif +} // namespace Pooling +} // namespace CPULayerTestsDefinitions \ No newline at end of file diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/common/random_uniform.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/common/random_uniform.cpp new file mode 100644 index 00000000000000..f319fb6ada2719 --- /dev/null +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/common/random_uniform.cpp @@ -0,0 +1,68 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "single_layer_tests/classes/random_uniform.hpp" + +using namespace CPUTestUtils; +using namespace ov::test; + +namespace CPULayerTestsDefinitions { +namespace RandomUniform { + +static const std::vector shape_prc = { + ElementType::i32, + ElementType::i64 +}; + +static const std::vector output_shapes = { + {500}, + {4, 3, 210} +}; + +static const std::vector global_seed = { + 0, 8 +}; + +static const std::vector operational_seed = { + 0, 3, 5 +}; + +static const std::vector> min_max = { + {0, 50}, + {-50, 50}, + {-50, 0} +}; + +INSTANTIATE_TEST_SUITE_P(smoke_Param, RandomUniformLayerTestCPU, + ::testing::Combine( + ::testing::ValuesIn(output_shapes), + ::testing::ValuesIn(min_max), + ::testing::ValuesIn(shape_prc), + ::testing::Values(ElementType::f32, ElementType::i32), + ::testing::ValuesIn(global_seed), + ::testing::ValuesIn(operational_seed), + ::testing::Values(false), + ::testing::Values(false), + ::testing::Values(false), + ::testing::Values(emptyCPUSpec), + ::testing::Values(empty_plugin_config)), + RandomUniformLayerTestCPU::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_ParamConst, RandomUniformLayerTestCPU, + ::testing::Combine( + ::testing::Values(output_shapes[0]), + ::testing::Values(min_max[0]), + ::testing::Values(ElementType::i32), + ::testing::Values(ElementType::f32), + ::testing::Values(1), + ::testing::Values(0), + ::testing::Values(true, false), + ::testing::Values(true, false), + ::testing::Values(true, false), + ::testing::Values(emptyCPUSpec), + ::testing::Values(empty_plugin_config)), + RandomUniformLayerTestCPU::getTestCaseName); + +} // namespace RandomUniform +} // namespace CPULayerTestsDefinitions diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/x64/pooling.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/x64/pooling.cpp new file mode 100644 index 00000000000000..89331ea284d49a --- /dev/null +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/x64/pooling.cpp @@ -0,0 +1,148 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "single_layer_tests/classes/pooling.hpp" +#include "shared_test_classes/single_layer/pooling.hpp" +#include "test_utils/cpu_test_utils.hpp" +#include "test_utils/fusing_test_utils.hpp" +#include +#include + +using namespace InferenceEngine; +using namespace CPUTestUtils; +using namespace ngraph::helpers; +using namespace ov::test; + + +namespace CPULayerTestsDefinitions { +namespace Pooling { +namespace { + +const auto ref = CPUSpecificParams{{}, {}, {"ref_any"}, "ref_any"}; +const auto avx512 = CPUSpecificParams{{}, {}, {"jit_avx512"}, "jit_avx512"}; +const auto avx = CPUSpecificParams{{}, {}, {"jit_avx"}, "jit_avx"}; +const auto sse42 = CPUSpecificParams{{}, {}, {"jit_sse42"}, "jit_sse42"}; + +const std::vector vecCpuConfigs = {sse42, avx, avx512}; + +const std::vector paramsMaxV84D_ref = { + LayerTestsDefinitions::maxPoolV8SpecificParams{ {2, 2}, {2, 2}, {2, 2}, {0, 0}, {0, 0}, + ngraph::element::Type_t::i32, 0, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_UPPER }, + LayerTestsDefinitions::maxPoolV8SpecificParams{ {4, 2}, {2, 2}, {1, 2}, {0, 0}, {0, 0}, + ngraph::element::Type_t::i32, 0, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT }, + LayerTestsDefinitions::maxPoolV8SpecificParams{ {4, 2}, {2, 1}, {2, 2}, {0, 0}, {0, 0}, + ngraph::element::Type_t::i32, 0, + ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT }, +}; + +INSTANTIATE_TEST_SUITE_P(smoke_MaxPoolV8_CPU_4D_ref, MaxPoolingV8LayerCPUTest, + ::testing::Combine( + ::testing::ValuesIn(paramsMaxV84D_ref), + ::testing::ValuesIn(inputShapes4D()), + ::testing::ValuesIn((inpOutPrecision())), + ::testing::Values(ref)), + MaxPoolingV8LayerCPUTest::getTestCaseName); + +const auto avx512_nhwc = CPUSpecificParams{{nhwc}, {nhwc}, {"jit_avx512"}, "jit_avx512"}; +const auto avx512_ndhwc = CPUSpecificParams{{ndhwc}, {ndhwc}, {"jit_avx512"}, "jit_avx512"}; + +const auto avx2_nhwc = CPUSpecificParams{{nhwc}, {nhwc}, {"jit_avx2"}, "jit_avx2"}; +const auto avx2_ndhwc = CPUSpecificParams{{ndhwc}, {ndhwc}, {"jit_avx2"}, "jit_avx2"}; + +const auto sse42_nhwc = CPUSpecificParams{{nhwc}, {nhwc}, {"jit_sse42"}, "jit_sse42"}; +const auto sse42_ndhwc = CPUSpecificParams{{ndhwc}, {ndhwc}, {"jit_sse42"}, "jit_sse42"}; + +const std::vector vecCpuConfigsFusing_4D = {sse42_nhwc, avx2_nhwc, avx512_nhwc}; +const std::vector vecCpuConfigsFusing_5D = {sse42_ndhwc, avx2_ndhwc, avx512_ndhwc}; + +std::vector fusingParamsSet { + emptyFusingSpec, + fusingFakeQuantizePerTensor, + fusingFakeQuantizePerChannel, +}; + +const std::vector inputShapes4D_int8 = { + { {}, {{3, 4, 64, 64}} }, + { {}, {{2, 8, 8, 12}} }, + { {}, {{1, 16, 16, 12}} }, + { {}, {{1, 21, 8, 4}} }, + { {}, {{1, 32, 8, 8}} }, + { + // dynamic + {-1, 32, -1, -1}, + // target + { + {1, 32, 8, 8}, + {1, 32, 8, 4}, + {2, 32, 8, 12}, + {1, 32, 8, 8} + } + }, + { + // dynamic + {{1, 5}, 16, {1, 64}, {1, 64}}, + // target + { + {3, 16, 32, 32}, + {1, 16, 16, 12}, + {1, 16, 8, 8}, + {3, 16, 32, 32}, + } + } +}; + +INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_4D_I8, PoolingLayerCPUTest, + ::testing::Combine( + ::testing::ValuesIn(paramsAvg4D()), + ::testing::ValuesIn(inputShapes4D_int8), + ::testing::Values(ElementType::f32), + ::testing::Values(true), + ::testing::ValuesIn(filterCPUInfoForDevice(vecCpuConfigsFusing_4D)), + ::testing::ValuesIn(fusingParamsSet)), + PoolingLayerCPUTest::getTestCaseName); + +const std::vector inputShapes5D_int8 = { + { {}, {{1, 4, 16, 16, 16}} }, + { {}, {{2, 8, 8, 8, 8}} }, + { {}, {{2, 16, 12, 16, 20}} }, + { {}, {{1, 19, 16, 20, 8}} }, + { {}, {{1, 32, 16, 8, 12}} }, + { + // dynamic + {-1, 32, -1, -1, -1}, + // target + { + {2, 32, 8, 8, 8}, + {1, 32, 16, 20, 8}, + {1, 32, 16, 16, 16}, + {2, 32, 8, 8, 8} + } + }, + { + // dynamic + {{1, 5}, 16, {1, 64}, {1, 64}, {1, 25}}, + // target + { + {1, 16, 16, 16, 16}, + {1, 16, 16, 8, 12}, + {2, 16, 8, 8, 8}, + {1, 16, 16, 16, 16}, + } + } +}; + +INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_5D_I8, PoolingLayerCPUTest, + ::testing::Combine( + ::testing::ValuesIn(paramsAvg5D()), + ::testing::ValuesIn(inputShapes5D_int8), + ::testing::Values(ElementType::f32), + ::testing::Values(true), + ::testing::ValuesIn(filterCPUInfoForDevice(vecCpuConfigsFusing_5D)), + ::testing::ValuesIn(fusingParamsSet)), + PoolingLayerCPUTest::getTestCaseName); +} // namespace +} // namespace Pooling +} // namespace CPULayerTestsDefinitions \ No newline at end of file diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/x64/random_uniform.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/x64/random_uniform.cpp new file mode 100644 index 00000000000000..8fec42f382464d --- /dev/null +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/x64/random_uniform.cpp @@ -0,0 +1,46 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "single_layer_tests/classes/random_uniform.hpp" + +using namespace CPUTestUtils; +using namespace ov::test; + +namespace CPULayerTestsDefinitions { +namespace RandomUniform { + +static const std::vector output_prc_nightly = { + ElementType::f32, + ElementType::f16, + ElementType::bf16, + ElementType::i32, + ElementType::i64 +}; + +// Need to validate the Kernel corner cases. +static const std::vector output_shapes_nightly = { + {1}, {2}, {3}, {2, 2}, {5}, {2, 3}, {7}, {2, 2, 2}, {3, 3}, {2, 5}, {11}, {2, 3, 2}, {13}, {2, 7}, {3, 5}, + {4, 4}, {1, 17}, {2, 9}, {19}, {4, 5}, {21}, {11, 2}, {23, 1}, {4, 2, 3}, {5, 5}, {26}, {1, 27}, {14, 2}, + {29}, {10, 3}, {31}, {2, 8, 2}, {33}, {17, 2}, {5, 7}, {2, 3, 2, 3}, {37}, {2, 19}, {2, 20}, {41}, {42}, + {43}, {22, 2}, {3, 5, 3}, {5, 2, 5}, {1, 3, 1, 17, 1}, {26, 2}, {53}, {54}, {55}, {56}, {57}, {58}, {59}, + {2, 32}, {99}, {127}, {128}, {129}, {199}, {255}, {499}, {997}, {1753}, {2899} +}; + +INSTANTIATE_TEST_SUITE_P(nightly_Param, RandomUniformLayerTestCPU, + ::testing::Combine( + ::testing::ValuesIn(output_shapes_nightly), + ::testing::Values(std::tuple{-31, 17}), + ::testing::Values(ElementType::i32), + ::testing::ValuesIn(output_prc_nightly), + ::testing::Values(3), + ::testing::Values(1), + ::testing::Values(true, false), + ::testing::Values(true, false), + ::testing::Values(true, false), + ::testing::Values(emptyCPUSpec), + ::testing::Values(empty_plugin_config)), + RandomUniformLayerTestCPU::getTestCaseName); + +} // namespace RandomUniform +} // namespace CPULayerTestsDefinitions diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/loop.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/loop.cpp index b92646e458130e..cda499b042fb4e 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/loop.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/loop.cpp @@ -371,6 +371,65 @@ class LoopForConcatLayerCPUTest : public LoopLayerCPUTest { } }; +class StaticLoopDynamicSubgraphCPUTest : public SubgraphBaseTest { + void SetUp() override { + InputShape input_shape = {{25, 1, 1}, {{25, 1, 1}}}; + InputShape input_exec_flag_shape = {{1}, {{1}}}; + targetDevice = ov::test::utils::DEVICE_CPU; + ElementType netType = ov::element::f32; + init_input_shapes({input_shape, input_exec_flag_shape}); + + ov::ParameterVector params; + params.push_back(std::make_shared(netType, inputDynamicShapes[0])); + + // exec_condition + params.push_back(std::make_shared(ov::element::boolean, inputDynamicShapes[1])); + + auto trip_count_input = std::make_shared(ov::element::i64, ov::Shape{1}, 2); + auto body_condition_const = std::make_shared(ov::element::boolean, ov::Shape{1}, true); + + // Body parameters + ov::ParameterVector body_params = {std::make_shared(netType, ov::PartialShape{25, 1, -1})}; + + // Body + auto broadcast_target_shape = std::make_shared(ov::element::i64, ov::Shape{3}, std::vector{25, 1, 256}); + auto broadcast_axis_mapping = std::make_shared(ov::element::i64, ov::Shape{1}, 0); + auto broadcast = std::make_shared(body_params[0], broadcast_target_shape); + auto body = std::make_shared(ov::OutputVector{body_condition_const, broadcast}, body_params); + + auto loop = std::make_shared(trip_count_input, params[1]); + loop->set_function(body); + loop->set_special_body_ports(ov::op::v5::Loop::SpecialBodyPorts{-1, 0}); + + loop->set_merged_input(body_params.front(), params.front(), broadcast); + + auto out0 = loop->get_iter_value(body_condition_const, -1); + auto out1 = loop->get_iter_value(broadcast, -1); + + auto result0 = std::make_shared(out0); + auto result1 = std::make_shared(out1); + function = std::make_shared(ov::ResultVector{result0, result1}, params, "loop"); + } + void generate_inputs(const std::vector& targetInputStaticShapes) override { + inputs.clear(); + const auto& funcInputs = function->inputs(); + for (size_t i = 0; i < funcInputs.size(); ++i) { + const auto& funcInput = funcInputs[i]; + ov::Tensor tensor; + + if (i == 1) { + tensor = ov::Tensor(funcInput.get_element_type(), targetInputStaticShapes[i]); + auto* dataPtr = tensor.data(); + *dataPtr = true; + } else { + tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], 2560, 0, 256); + } + inputs.insert({funcInput.get_node_shared_ptr(), tensor}); + } + } +}; + + TEST_P(LoopLayerCPUTest, CompareWithRefs) { run(); } @@ -387,6 +446,10 @@ TEST_P(LoopForConcatLayerCPUTest, CompareWithRefs) { run(); } +TEST_F(StaticLoopDynamicSubgraphCPUTest, smoke_StaticLoopWithDynSubgraph) { + run(); +} + namespace { const std::vector inputPrecisions = { diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/normalize.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/normalize.cpp index 6e7277ce2e343f..c0e1427e32f476 100755 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/normalize.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/normalize.cpp @@ -80,6 +80,10 @@ class NormalizeL2LayerCPUTest : public testing::WithParamInterface& targetInputStaticShapes) override { diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/pooling.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/pooling.cpp deleted file mode 100644 index c6a76f7fee9fad..00000000000000 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/pooling.cpp +++ /dev/null @@ -1,704 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "ov_models/builders.hpp" -#include "test_utils/cpu_test_utils.hpp" -#include "test_utils/fusing_test_utils.hpp" -#include "shared_test_classes/single_layer/pooling.hpp" -#include "shared_test_classes/base/ov_subgraph.hpp" - -using namespace ov::test; -using namespace CPUTestUtils; - -namespace CPULayerTestsDefinitions { - -using poolLayerCpuTestParamsSet = std::tuple; - -using maxPoolV8LayerCpuTestParamsSet = std::tuple; - -class PoolingLayerCPUTest : public testing::WithParamInterface, - virtual public SubgraphBaseTest, public CpuTestWithFusing { -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj) { - LayerTestsDefinitions::poolSpecificParams basicParamsSet; - InputShape inputShapes; - ElementType inPrc; - bool isInt8; - CPUSpecificParams cpuParams; - fusingSpecificParams fusingParams; - std::tie(basicParamsSet, inputShapes, inPrc, isInt8, cpuParams, fusingParams) = obj.param; - - ngraph::helpers::PoolingTypes poolType; - std::vector kernel, stride; - std::vector padBegin, padEnd; - ngraph::op::PadType padType; - ngraph::op::RoundingType roundingType; - bool excludePad; - std::tie(poolType, kernel, stride, padBegin, padEnd, roundingType, padType, excludePad) = basicParamsSet; - - std::ostringstream results; - results << "IS=("; - results << ov::test::utils::partialShape2str({inputShapes.first}) << ")_"; - results << "TS="; - for (const auto& shape : inputShapes.second) { - results << ov::test::utils::vec2str(shape) << "_"; - } - results << "Prc=" << inPrc << "_"; - switch (poolType) { - case ngraph::helpers::PoolingTypes::MAX: - results << "MaxPool_"; - break; - case ngraph::helpers::PoolingTypes::AVG: - results << "AvgPool_"; - results << "ExcludePad=" << excludePad << "_"; - break; - } - results << "K" << ov::test::utils::vec2str(kernel) << "_"; - results << "S" << ov::test::utils::vec2str(stride) << "_"; - results << "PB" << ov::test::utils::vec2str(padBegin) << "_"; - results << "PE" << ov::test::utils::vec2str(padEnd) << "_"; - results << "Rounding=" << roundingType << "_"; - results << "AutoPad=" << padType << "_"; - results << "INT8=" << isInt8 << "_"; - - results << CPUTestsBase::getTestCaseName(cpuParams); - results << CpuTestWithFusing::getTestCaseName(fusingParams); - return results.str(); - } - -protected: - void SetUp() override { - targetDevice = ov::test::utils::DEVICE_CPU; - - LayerTestsDefinitions::poolSpecificParams basicParamsSet; - InputShape inputShapes; - ElementType inPrc; - bool isInt8; - CPUSpecificParams cpuParams; - fusingSpecificParams fusingParams; - std::tie(basicParamsSet, inputShapes, inPrc, isInt8, cpuParams, fusingParams) = this->GetParam(); - - ngraph::helpers::PoolingTypes poolType; - std::vector kernel, stride; - std::vector padBegin, padEnd; - ngraph::op::PadType padType; - ngraph::op::RoundingType roundingType; - bool excludePad; - std::tie(poolType, kernel, stride, padBegin, padEnd, roundingType, padType, excludePad) = basicParamsSet; - - std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; - std::tie(postOpMgrPtr, fusedOps) = fusingParams; - - if (selectedType.empty()) { - selectedType = getPrimitiveType(); - } - if (isInt8) - selectedType = selectedType + "_I8"; - else - selectedType = makeSelectedTypeStr(selectedType, inPrc); - - init_input_shapes({inputShapes}); - - ov::ParameterVector params; - for (auto&& shape : inputDynamicShapes) { - params.push_back(std::make_shared(inPrc, shape)); - } - std::shared_ptr poolInput = params[0]; - if (isInt8) { - ov::Shape newShape(poolInput->get_output_partial_shape(0).size(), 1); - poolInput = ngraph::builder::makeFakeQuantize(poolInput, inPrc, 256, newShape); - } - - std::shared_ptr pooling = ngraph::builder::makePooling(poolInput, - stride, - padBegin, - padEnd, - kernel, - roundingType, - padType, - excludePad, - poolType); - - function = makeNgraphFunction(inPrc, params, pooling, "PoolingCPU"); - } -}; - -class MaxPoolingV8LayerCPUTest : public testing::WithParamInterface, - virtual public SubgraphBaseTest, public CPUTestsBase { -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj) { - LayerTestsDefinitions::maxPoolV8SpecificParams basicParamsSet; - InputShape inputShapes; - ElementType inPrc; - CPUSpecificParams cpuParams; - std::tie(basicParamsSet, inputShapes, inPrc, cpuParams) = obj.param; - - std::vector kernel, stride, dilation; - std::vector padBegin, padEnd; - ngraph::op::PadType padType; - ngraph::op::RoundingType roundingType; - ngraph::element::Type indexElementType; - int64_t axis; - std::tie(kernel, stride, dilation, padBegin, padEnd, indexElementType, axis, roundingType, padType) = basicParamsSet; - - std::ostringstream results; - results << "IS=("; - results << ov::test::utils::partialShape2str({inputShapes.first}) << ")_"; - results << "TS="; - for (const auto& shape : inputShapes.second) { - results << ov::test::utils::vec2str(shape) << "_"; - } - results << "Prc=" << inPrc << "_"; - results << "MaxPool_"; - results << "K" << ov::test::utils::vec2str(kernel) << "_"; - results << "S" << ov::test::utils::vec2str(stride) << "_"; - results << "D" << ov::test::utils::vec2str(dilation) << "_"; - results << "PB" << ov::test::utils::vec2str(padBegin) << "_"; - results << "PE" << ov::test::utils::vec2str(padEnd) << "_"; - results << "Rounding=" << roundingType << "_"; - results << "AutoPad=" << padType << "_"; - - results << CPUTestsBase::getTestCaseName(cpuParams); - return results.str(); - } - -protected: - void SetUp() override { - targetDevice = ov::test::utils::DEVICE_CPU; - - LayerTestsDefinitions::maxPoolV8SpecificParams basicParamsSet; - InputShape inputShapes; - ElementType inPrc; - CPUSpecificParams cpuParams; - std::tie(basicParamsSet, inputShapes, inPrc, cpuParams) = this->GetParam(); - - std::vector kernel, stride, dilation; - std::vector padBegin, padEnd; - ngraph::op::PadType padType; - ngraph::op::RoundingType roundingType; - ngraph::element::Type indexElementType; - int64_t axis; - std::tie(kernel, stride, dilation, padBegin, padEnd, indexElementType, axis, roundingType, padType) = basicParamsSet; - std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; - if (selectedType.empty()) { - selectedType = getPrimitiveType(); - } - selectedType = makeSelectedTypeStr(selectedType, inPrc); - - init_input_shapes({inputShapes}); - - ov::ParameterVector params; - for (auto&& shape : inputDynamicShapes) { - params.push_back(std::make_shared(inPrc, shape)); - } - std::shared_ptr pooling = ngraph::builder::makeMaxPoolingV8(params[0], stride, dilation, padBegin, padEnd, - kernel, roundingType, padType, - indexElementType, axis); - pooling->get_rt_info() = getCPUInfo(); - ngraph::ResultVector results{std::make_shared(pooling->output(0))}; - function = std::make_shared(results, params, "MaxPooling"); - } -}; - -TEST_P(PoolingLayerCPUTest, CompareWithRefs) { - run(); - CheckPluginRelatedResults(compiledModel, "Pooling"); -} - -TEST_P(MaxPoolingV8LayerCPUTest, CompareWithRefs) { - run(); - CheckPluginRelatedResults(compiledModel, "Pooling"); -} - -namespace { - -const auto avx512 = CPUSpecificParams{{}, {}, {"jit_avx512"}, "jit_avx512"}; -const auto avx = CPUSpecificParams{{}, {}, {"jit_avx"}, "jit_avx"}; -const auto sse42 = CPUSpecificParams{{}, {}, {"jit_sse42"}, "jit_sse42"}; -const auto ref = CPUSpecificParams{{}, {}, {"ref_any"}, "ref_any"}; - -const std::vector vecCpuConfigs = {ref, sse42, avx, avx512}; -const std::vector inpOutPrecision = {ElementType::f32/*, ElementType::bf16*/}; - -const std::vector inputShapes3D = { - { {}, {{3, 4, 64}} }, - { {}, {{2, 8, 12}} }, - { {}, {{1, 16, 12}} }, - { {}, {{1, 21, 4}} }, - { {}, {{1, 32, 8}} }, - { - // dynamic - {-1, -1, -1}, - // target - { - {1, 32, 8}, - {1, 21, 4}, - {2, 8, 12} - } - }, - { - // dynamic - {{1, 5}, {4, 32}, {1, 64}}, - // target - { - {3, 4, 64}, - {1, 16, 12}, - {1, 32, 8} - } - } -}; - -const std::vector inputShapes4D = { - { {}, {{3, 4, 64, 64}} }, - { {}, {{2, 8, 8, 12}} }, - { {}, {{1, 16, 16, 12}} }, - { {}, {{1, 21, 8, 4}} }, - { {}, {{1, 32, 8, 8}} }, - { - // dynamic - {-1, -1, -1, -1}, - // target - { - {1, 32, 8, 8}, - {1, 21, 8, 4}, - {2, 8, 8, 12}, - {1, 96, 125, 125} - } - }, - { - // dynamic - {{1, 5}, {4, 32}, {1, 64}, {1, 64}}, - // target - { - {3, 4, 64, 64}, - {1, 16, 16, 12}, - {1, 32, 8, 8} - } - }, - { - // dynamic - {{1, 10}, 16, 8, 8}, - // target - { - {1, 16, 8, 8}, - {2, 16, 8, 8}, - } - } -}; - -const std::vector inputShapes5D = { - { {}, {{1, 4, 16, 16, 16}} }, - { {}, {{2, 8, 8, 8, 8}} }, - { {}, {{2, 16, 12, 16, 20}} }, - { {}, {{1, 19, 16, 20, 8}} }, - { {}, {{1, 32, 16, 8, 12}} }, - { - // dynamic - {-1, -1, -1, -1, -1}, - // target - { - {2, 8, 8, 8, 8}, - {1, 19, 16, 20, 8}, - {1, 4, 16, 16, 16} - } - }, - { - // dynamic - {{1, 5}, {4, 32}, {1, 64}, {1, 64}, {1, 25}}, - // target - { - {1, 4, 16, 16, 16}, - {1, 32, 16, 8, 12}, - {3, 16, 4, 8, 3} - } - } -}; - -/* ============= Pooling (1D) ============= */ -const std::vector paramsMax3D = { - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {2}, {2}, {0}, {0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {4}, {2}, {0}, {0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {2}, {1}, {0}, {0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false }, -}; - -const std::vector paramsAvg3D = { - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {3}, {1}, {1}, {0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_UPPER, false }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {3}, {1}, {1}, {0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, true }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {4}, {4}, {2}, {2}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, true }, -}; - -const std::vector paramsAvg3D_RefOnly = { - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2}, {2}, {2}, {2}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false }, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_MaxPool_CPU_3D, PoolingLayerCPUTest, - ::testing::Combine( - ::testing::ValuesIn(paramsMax3D), - ::testing::ValuesIn(inputShapes3D), - ::testing::ValuesIn(inpOutPrecision), - ::testing::Values(false), - ::testing::ValuesIn(filterCPUInfoForDevice(vecCpuConfigs)), - ::testing::Values(emptyFusingSpec)), - PoolingLayerCPUTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_3D, PoolingLayerCPUTest, - ::testing::Combine( - ::testing::ValuesIn(paramsAvg3D), - ::testing::ValuesIn(inputShapes3D), - ::testing::ValuesIn(inpOutPrecision), - ::testing::Values(false), - ::testing::ValuesIn(filterCPUInfoForDevice(vecCpuConfigs)), - ::testing::Values(emptyFusingSpec)), - PoolingLayerCPUTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_3D_NotOptimized, PoolingLayerCPUTest, - ::testing::Combine( - ::testing::ValuesIn(paramsAvg3D_RefOnly), - ::testing::ValuesIn(inputShapes3D), - ::testing::ValuesIn(inpOutPrecision), - ::testing::Values(false), - ::testing::Values(ref), - ::testing::Values(emptyFusingSpec)), - PoolingLayerCPUTest::getTestCaseName); - -/* ============= Pooling (2D) ============= */ -const std::vector paramsMax4D = { - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {2, 2}, {2, 2}, {0, 0}, {0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_LOWER, false }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {2, 2}, {2, 2}, {0, 0}, {0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_UPPER, false }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {4, 2}, {2, 2}, {0, 0}, {0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {4, 2}, {2, 1}, {0, 0}, {0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false }, -}; - -const std::vector paramsMaxV84D = { - LayerTestsDefinitions::maxPoolV8SpecificParams{ {2, 2}, {2, 2}, {1, 1}, {0, 0}, {0, 0}, - ngraph::element::Type_t::i32, 0, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_LOWER }, -}; - -const std::vector paramsMaxV84D_ref = { - LayerTestsDefinitions::maxPoolV8SpecificParams{ {2, 2}, {2, 2}, {2, 2}, {0, 0}, {0, 0}, - ngraph::element::Type_t::i32, 0, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_UPPER }, - LayerTestsDefinitions::maxPoolV8SpecificParams{ {4, 2}, {2, 2}, {1, 2}, {0, 0}, {0, 0}, - ngraph::element::Type_t::i32, 0, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT }, - LayerTestsDefinitions::maxPoolV8SpecificParams{ {4, 2}, {2, 1}, {2, 2}, {0, 0}, {0, 0}, - ngraph::element::Type_t::i32, 0, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT }, -}; - -const std::vector paramsAvg4D = { - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2}, {2, 2}, {1, 0}, {0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_LOWER, true }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2}, {2, 2}, {1, 0}, {0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_UPPER, true }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2}, {2, 2}, {1, 0}, {0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_LOWER, false }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2}, {2, 2}, {1, 0}, {0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_UPPER, false }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2}, {2, 2}, {0, 0}, {0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, true }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {4, 4}, {4, 4}, {2, 2}, {2, 2}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, true }, -}; - -const std::vector paramsAvg4D_RefOnly = { - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2}, {2, 2}, {2, 2}, {2, 2}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false }, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_MaxPool_CPU_4D, PoolingLayerCPUTest, - ::testing::Combine( - ::testing::ValuesIn(paramsMax4D), - ::testing::ValuesIn(inputShapes4D), - ::testing::ValuesIn(inpOutPrecision), - ::testing::Values(false), - ::testing::ValuesIn(filterCPUInfoForDevice(vecCpuConfigs)), - ::testing::Values(emptyFusingSpec)), - PoolingLayerCPUTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_MaxPoolV8_CPU_4D, MaxPoolingV8LayerCPUTest, - ::testing::Combine( - ::testing::ValuesIn(paramsMaxV84D), - ::testing::ValuesIn(inputShapes4D), - ::testing::ValuesIn(inpOutPrecision), - ::testing::ValuesIn(filterCPUInfoForDevice(vecCpuConfigs))), - MaxPoolingV8LayerCPUTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_MaxPoolV8_CPU_4D_ref, MaxPoolingV8LayerCPUTest, - ::testing::Combine( - ::testing::ValuesIn(paramsMaxV84D_ref), - ::testing::ValuesIn(inputShapes4D), - ::testing::ValuesIn(inpOutPrecision), - ::testing::Values(ref)), - MaxPoolingV8LayerCPUTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_4D, PoolingLayerCPUTest, - ::testing::Combine( - ::testing::ValuesIn(paramsAvg4D), - ::testing::ValuesIn(inputShapes4D), - ::testing::ValuesIn(inpOutPrecision), - ::testing::Values(false), - ::testing::ValuesIn(filterCPUInfoForDevice(vecCpuConfigs)), - ::testing::Values(emptyFusingSpec)), - PoolingLayerCPUTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_4D_NotOptimized, PoolingLayerCPUTest, - ::testing::Combine( - ::testing::ValuesIn(paramsAvg4D_RefOnly), - ::testing::ValuesIn(inputShapes4D), - ::testing::ValuesIn(inpOutPrecision), - ::testing::Values(false), - ::testing::Values(ref), - ::testing::Values(emptyFusingSpec)), - PoolingLayerCPUTest::getTestCaseName); - -const std::vector paramsAvg4D_Large = { - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {65, 65}, {65, 65}, {0, 0}, {0, 0}, - ngraph::op::RoundingType::FLOOR, ngraph::op::PadType::VALID, true }, -}; - -const std::vector inputShapes4D_Large = { - { - // dynamic - {-1, -1, -1, -1}, - // target - { - {1, 16, 65, 65}, - {1, 8, 130, 130}, - {1, 16, 65, 65} - } - }, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_Large, PoolingLayerCPUTest, - ::testing::Combine( - ::testing::ValuesIn(paramsAvg4D_Large), - ::testing::ValuesIn(inputShapes4D_Large), - ::testing::ValuesIn(inpOutPrecision), - ::testing::Values(false), - ::testing::ValuesIn(filterCPUInfoForDevice(vecCpuConfigs)), - ::testing::Values(emptyFusingSpec)), - PoolingLayerCPUTest::getTestCaseName); - -/* ============= Pooling (3D) ============= */ -const std::vector paramsMax5D = { - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {2, 2, 2}, {1, 1, 1}, {0, 0, 0}, {0, 0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_LOWER, false }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {2, 2, 2}, {1, 1, 1}, {0, 0, 0}, {0, 0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_UPPER, false }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {2, 2, 2}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::MAX, {3, 3, 3}, {2, 2, 2}, {1, 1, 1}, {1, 1, 1}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false }, -}; - -const std::vector paramsMaxV85D = { - LayerTestsDefinitions::maxPoolV8SpecificParams{ {2, 2, 2}, {1, 1, 1}, {1, 1, 1}, {0, 0, 0}, {0, 0, 0}, - ngraph::element::Type_t::i32, 0, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_LOWER }, -}; - -const std::vector paramsMaxV85D_ref = { - LayerTestsDefinitions::maxPoolV8SpecificParams{ {2, 2, 2}, {1, 1, 1}, {2, 2, 2}, {0, 0, 0}, {0, 0, 0}, - ngraph::element::Type_t::i32, 0, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_UPPER }, - LayerTestsDefinitions::maxPoolV8SpecificParams{ {2, 2, 2}, {1, 1, 1}, {2, 2, 2}, {1, 1, 1}, {1, 1, 1}, - ngraph::element::Type_t::i32, 0, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT }, - LayerTestsDefinitions::maxPoolV8SpecificParams{ {2, 3, 4}, {2, 2, 2}, {2, 1, 1}, {1, 1, 1}, {1, 2, 2}, - ngraph::element::Type_t::i32, 0, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT }, -}; - -const std::vector paramsAvg5D = { - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2, 2}, {2, 2, 2}, {1, 0, 0}, {0, 0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_LOWER, true }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2, 2}, {2, 2, 2}, {1, 0, 0}, {0, 0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_UPPER, true }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2, 2}, {2, 2, 2}, {1, 0, 0}, {0, 0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_LOWER, false }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2, 2}, {2, 2, 2}, {1, 0, 0}, {0, 0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::SAME_UPPER, false }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2, 2}, {2, 2, 2}, {0, 0, 0}, {0, 0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, true }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {3, 3, 3}, {3, 3, 3}, {1, 1, 1}, {0, 0, 0}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, true }, - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {4, 4, 4}, {2, 2, 2}, {2, 2, 2}, {2, 2, 2}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, true }, -}; - -const std::vector paramsAvg5D_RefOnly = { - LayerTestsDefinitions::poolSpecificParams{ ngraph::helpers::PoolingTypes::AVG, {2, 2, 2}, {2, 2, 2}, {2, 2, 2}, {2, 2, 2}, - ngraph::op::RoundingType::CEIL, ngraph::op::PadType::EXPLICIT, false }, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_MaxPool_CPU_5D, PoolingLayerCPUTest, - ::testing::Combine( - ::testing::ValuesIn(paramsMax5D), - ::testing::ValuesIn(inputShapes5D), - ::testing::ValuesIn(inpOutPrecision), - ::testing::Values(false), - ::testing::ValuesIn(filterCPUInfoForDevice(vecCpuConfigs)), - ::testing::Values(emptyFusingSpec)), - PoolingLayerCPUTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_MaxPoolV8_CPU_5D, MaxPoolingV8LayerCPUTest, - ::testing::Combine( - ::testing::ValuesIn(paramsMaxV85D), - ::testing::ValuesIn(inputShapes5D), - ::testing::ValuesIn(inpOutPrecision), - ::testing::ValuesIn(filterCPUInfoForDevice(vecCpuConfigs))), - MaxPoolingV8LayerCPUTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_MaxPoolV8_CPU_5D_ref, MaxPoolingV8LayerCPUTest, - ::testing::Combine( - ::testing::ValuesIn(paramsMaxV85D_ref), - ::testing::ValuesIn(inputShapes5D), - ::testing::ValuesIn(inpOutPrecision), - ::testing::Values(ref)), - MaxPoolingV8LayerCPUTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_5D, PoolingLayerCPUTest, - ::testing::Combine( - ::testing::ValuesIn(paramsAvg5D), - ::testing::ValuesIn(inputShapes5D), - ::testing::ValuesIn(inpOutPrecision), - ::testing::Values(false), - ::testing::ValuesIn(filterCPUInfoForDevice(vecCpuConfigs)), - ::testing::Values(emptyFusingSpec)), - PoolingLayerCPUTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_5D_NotOptimized, PoolingLayerCPUTest, - ::testing::Combine( - ::testing::ValuesIn(paramsAvg5D_RefOnly), - ::testing::ValuesIn(inputShapes5D), - ::testing::ValuesIn(inpOutPrecision), - ::testing::Values(false), - ::testing::Values(ref), - ::testing::Values(emptyFusingSpec)), - PoolingLayerCPUTest::getTestCaseName); - -/* === Fusing === */ - -const auto avx512_nhwc = CPUSpecificParams{{nhwc}, {nhwc}, {"jit_avx512"}, "jit_avx512"}; -const auto avx512_ndhwc = CPUSpecificParams{{ndhwc}, {ndhwc}, {"jit_avx512"}, "jit_avx512"}; - -const auto avx2_nhwc = CPUSpecificParams{{nhwc}, {nhwc}, {"jit_avx2"}, "jit_avx2"}; -const auto avx2_ndhwc = CPUSpecificParams{{ndhwc}, {ndhwc}, {"jit_avx2"}, "jit_avx2"}; - -const auto sse42_nhwc = CPUSpecificParams{{nhwc}, {nhwc}, {"jit_sse42"}, "jit_sse42"}; -const auto sse42_ndhwc = CPUSpecificParams{{ndhwc}, {ndhwc}, {"jit_sse42"}, "jit_sse42"}; - -const std::vector vecCpuConfigsFusing_4D = {sse42_nhwc, avx2_nhwc, avx512_nhwc}; -const std::vector vecCpuConfigsFusing_5D = {sse42_ndhwc, avx2_ndhwc, avx512_ndhwc}; - -std::vector fusingParamsSet { - emptyFusingSpec, - fusingFakeQuantizePerTensor, - fusingFakeQuantizePerChannel, -}; - -const std::vector inputShapes4D_int8 = { - { {}, {{3, 4, 64, 64}} }, - { {}, {{2, 8, 8, 12}} }, - { {}, {{1, 16, 16, 12}} }, - { {}, {{1, 21, 8, 4}} }, - { {}, {{1, 32, 8, 8}} }, - { - // dynamic - {-1, 32, -1, -1}, - // target - { - {1, 32, 8, 8}, - {1, 32, 8, 4}, - {2, 32, 8, 12}, - {1, 32, 8, 8} - } - }, - { - // dynamic - {{1, 5}, 16, {1, 64}, {1, 64}}, - // target - { - {3, 16, 32, 32}, - {1, 16, 16, 12}, - {1, 16, 8, 8}, - {3, 16, 32, 32}, - } - } -}; - -INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_4D_I8, PoolingLayerCPUTest, - ::testing::Combine( - ::testing::ValuesIn(paramsAvg4D), - ::testing::ValuesIn(inputShapes4D_int8), - ::testing::Values(ElementType::f32), - ::testing::Values(true), - ::testing::ValuesIn(filterCPUInfoForDevice(vecCpuConfigsFusing_4D)), - ::testing::ValuesIn(fusingParamsSet)), - PoolingLayerCPUTest::getTestCaseName); - -const std::vector inputShapes5D_int8 = { - { {}, {{1, 4, 16, 16, 16}} }, - { {}, {{2, 8, 8, 8, 8}} }, - { {}, {{2, 16, 12, 16, 20}} }, - { {}, {{1, 19, 16, 20, 8}} }, - { {}, {{1, 32, 16, 8, 12}} }, - { - // dynamic - {-1, 32, -1, -1, -1}, - // target - { - {2, 32, 8, 8, 8}, - {1, 32, 16, 20, 8}, - {1, 32, 16, 16, 16}, - {2, 32, 8, 8, 8} - } - }, - { - // dynamic - {{1, 5}, 16, {1, 64}, {1, 64}, {1, 25}}, - // target - { - {1, 16, 16, 16, 16}, - {1, 16, 16, 8, 12}, - {2, 16, 8, 8, 8}, - {1, 16, 16, 16, 16}, - } - } -}; - -INSTANTIATE_TEST_SUITE_P(smoke_AvgPool_CPU_5D_I8, PoolingLayerCPUTest, - ::testing::Combine( - ::testing::ValuesIn(paramsAvg5D), - ::testing::ValuesIn(inputShapes5D_int8), - ::testing::Values(ElementType::f32), - ::testing::Values(true), - ::testing::ValuesIn(filterCPUInfoForDevice(vecCpuConfigsFusing_5D)), - ::testing::ValuesIn(fusingParamsSet)), - PoolingLayerCPUTest::getTestCaseName); - -} // namespace - -} // namespace CPULayerTestsDefinitions diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/roi_pooling.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/roi_pooling.cpp index f8c2235f02cb09..c5d3047452a122 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/roi_pooling.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/roi_pooling.cpp @@ -155,12 +155,9 @@ class ROIPoolingCPULayerTest : public testing::WithParamInterface(tensor, feat_map_shape[0] - 1, height, width, 1.f, is_roi_max_mode); - break; - } - case ngraph::element::bf16: { - ov::test::utils::fill_data_roi(tensor, feat_map_shape[0] - 1, height, width, 1.f, is_roi_max_mode); + case ov::element::f32: + case ov::element::bf16: { + ov::test::utils::fill_data_roi(tensor, feat_map_shape[0] - 1, height, width, 1.f, is_roi_max_mode); break; } default: diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/matmul_weights_decompression.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/matmul_weights_decompression.cpp index 9fcd4d58689399..b107b406cd833a 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/matmul_weights_decompression.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/matmul_weights_decompression.cpp @@ -14,39 +14,62 @@ using namespace ov::test; namespace SubgraphTestsDefinitions { /* - * Subtract_const(U8) + * WP - weights precision + * DP - decompression precision + * IP - input precision + * Opt - optional + * Subtract_const(WP) * / - * Weights(U8) Convert(F32) + * Weights(WP) Convert(DP) * | / - * Convert(F32) Reshape - * \ / Multiply_const(F32) - * Subtract(opt) / - * \ Reshape - * \ / - * Multiply + * Convert(DP) Reshape (Opt) + * \ / Multiply_const(DP) + * Subtract(Opt) / + * \ Reshape (Opt) + * \ / + * Multiply * | - * Data(F32) Transpose(opt) + * Reshape (in case of group decompression) + * | + * Convert (if IP != DP) + * | + * Data(IP) Transpose(Opt) * \ / * Matmul * | * Bias */ -using MatmulWeightsDecompressionParams = std::tuple, // input shapes - ov::test::ElementType, // weights precision - bool, // transpose on weights - bool, // decompression subtract - bool, // reshape on decompression constants + +struct ShapeParams { + ShapeParams() = default; + ShapeParams(InputShape data_shape, ov::Shape weights_shape, int weights_group_size = -1) + : data_shape(std::move(data_shape)), + weights_shape(std::move(weights_shape)), + weights_group_size(weights_group_size) {} + + InputShape data_shape; + ov::Shape weights_shape; + // Decompression group size. If the value is equal to -1, ordinary decompression is used + int weights_group_size; +}; +using MatmulWeightsDecompressionParams = std::tuple, // additional config fusingSpecificParams, - bool>; // should use decompression implementation + bool>; // should use decompression implementation class MatmulWeightsDecompression : public testing::WithParamInterface, virtual public SubgraphBaseTest, public CpuTestWithFusing { public: static std::string getTestCaseName(testing::TestParamInfo obj) { - std::vector inputShapes; + ShapeParams shape_params; ov::test::ElementType weights_precision; + ov::test::ElementType decompression_precision; bool transpose; bool decompression_sub; bool reshape_on_decompression; @@ -54,8 +77,9 @@ class MatmulWeightsDecompression : public testing::WithParamInterface initSubgraph(std::vector& inputShapes, - const ov::element::Type data_precision, - const ov::element::Type weights_precision, - const bool transpose_weights, - const bool add_subtract, - const bool reshape_on_decompression) { - ov::ParameterVector params{std::make_shared(data_precision, inputShapes[0])}; + std::shared_ptr initDecompressionWeights(const ov::Shape& weights_shape, + const int group_size, + const ov::element::Type data_precision, + const ov::element::Type weights_precision, + const ov::element::Type decompression_precision, + const bool transpose_weights, + const bool add_subtract, + const bool reshape_on_decompression_constant) { auto transpose_if_necessary = [&](const ov::Shape& shape) { - if (!transpose_weights) - return shape; - auto transposed_shape = shape; - std::swap(*transposed_shape.rbegin(), *(transposed_shape.rbegin() + 1)); - return transposed_shape; + auto result_shape = shape; + if (transpose_weights) + std::swap(*result_shape.rbegin(), *(result_shape.rbegin() + 1)); + return result_shape; }; - auto weights_shape = transpose_if_necessary(inputShapes[1].to_shape()); - auto weights = ngraph::builder::makeConstant(weights_precision, weights_shape, {}, true); + const bool group_decompression = group_size != -1; + // Weights has shape [I, O], where + // I - input channels + // O - output channels + // In case of group decompression, input channels dimension is split into 2: I -> [N, G], where + // N - number of groups + // G - group size + auto transformed_weights_shape = transpose_if_necessary(weights_shape); + if (group_decompression) { + OPENVINO_ASSERT(weights_shape[0] % group_size == 0, + "Weights output channels count (", + weights_shape[0], + ") must be divisible by decompression group size (", + group_size, + ")."); + auto in_channel_idx = transpose_weights ? transformed_weights_shape.size() - 1 : transformed_weights_shape.size() - 2; + transformed_weights_shape[in_channel_idx] = weights_shape[0] / group_size; + transformed_weights_shape.insert(transformed_weights_shape.begin() + in_channel_idx + 1, group_size); + } + auto weights = ngraph::builder::makeConstant(weights_precision, transformed_weights_shape, {}, true); weights->set_friendly_name("Compressed_weights"); - auto weights_convert = std::make_shared(weights, data_precision); + auto weights_convert = std::make_shared(weights, decompression_precision); std::shared_ptr mul_parent = weights_convert; - auto output_channels = transpose_weights ? *(weights_shape.rbegin() + 1) : *weights_shape.rbegin(); - auto scaleshift_target_shape = transpose_if_necessary(ov::Shape{1, output_channels}); - auto scaleshift_const_shape = reshape_on_decompression ? ov::Shape{output_channels} : scaleshift_target_shape; + auto output_channels = *weights_shape.rbegin(); + + // Decompression constants shape: + // Ordinary decompression: [O, 1] + // Group decompression: [O, N, 1] + ov::Shape scaleshift_target_shape{output_channels}; + scaleshift_target_shape.insert(scaleshift_target_shape.begin(), group_decompression ? weights_shape[0] / group_size : 1); + scaleshift_target_shape = transpose_if_necessary(scaleshift_target_shape); + if (group_decompression) { + auto in_channel_idx = transpose_weights ? scaleshift_target_shape.size() - 1 : scaleshift_target_shape.size() - 2; + scaleshift_target_shape.insert(scaleshift_target_shape.begin() + in_channel_idx + 1, 1); + } + + auto scaleshift_const_shape = scaleshift_target_shape; + if (reshape_on_decompression_constant) + scaleshift_const_shape.erase(std::remove(scaleshift_const_shape.begin(), scaleshift_const_shape.end(), 1), scaleshift_const_shape.end()); if (add_subtract) { auto shift_const = ngraph::builder::makeConstant(weights_precision, scaleshift_const_shape, {}, true); - std::shared_ptr shift_convert = std::make_shared(shift_const, data_precision); - if (reshape_on_decompression) { + std::shared_ptr shift_convert = std::make_shared(shift_const, decompression_precision); + if (reshape_on_decompression_constant) { auto shift_reshape_const = ov::opset10::Constant::create(ov::element::i32, {scaleshift_target_shape.size()}, scaleshift_target_shape); auto shift_reshape = std::make_shared(shift_convert, shift_reshape_const, false); shift_convert = shift_reshape; @@ -129,33 +174,62 @@ class MatmulWeightsDecompression : public testing::WithParamInterface(weights_convert, shift_convert); } - std::shared_ptr scale_const = ngraph::builder::makeConstant(data_precision, scaleshift_const_shape, {}, true); - if (reshape_on_decompression) { + std::shared_ptr scale_const = ngraph::builder::makeConstant(decompression_precision, scaleshift_const_shape, {}, true); + if (reshape_on_decompression_constant) { auto scale_reshape_const = ov::opset10::Constant::create(ov::element::i32, {scaleshift_target_shape.size()}, scaleshift_target_shape); auto scale_reshape = std::make_shared(scale_const, scale_reshape_const, false); scale_const = scale_reshape; } - auto multiply = std::make_shared(mul_parent, scale_const); + std::shared_ptr last_node = std::make_shared(mul_parent, scale_const); - std::shared_ptr matmul_weights = multiply; + if (group_decompression) { + auto reshape_target_shape = transpose_weights ? std::vector{-1, static_cast(weights_shape[0])} + : std::vector{static_cast(weights_shape[0]), -1}; + auto target_shape_node = ov::opset10::Constant::create(ov::element::i32, {reshape_target_shape.size()}, reshape_target_shape); + last_node = std::make_shared(last_node, target_shape_node, false); + } + if (decompression_precision != data_precision) { + last_node = std::make_shared(last_node, data_precision); + } if (transpose_weights) { - const size_t rank = matmul_weights->get_output_partial_shape(0).size(); + const size_t rank = last_node->get_output_partial_shape(0).size(); std::vector order(rank); std::iota(order.begin(), order.end(), 0); std::swap(*order.rbegin(), *(order.rbegin() + 1)); auto transpose_constant = ov::opset10::Constant::create(ov::element::i32, {rank}, order); - auto transpose = std::make_shared(matmul_weights, transpose_constant); - matmul_weights = transpose; + last_node = std::make_shared(last_node, transpose_constant); } - auto matMul = builder::makeMatMul(params[0], matmul_weights); + return last_node; + } + + std::shared_ptr initSubgraph(const ov::PartialShape& data_shape, + const ov::Shape& weights_shape, + const int group_size, + const ov::element::Type data_precision, + const ov::element::Type weights_precision, + const ov::element::Type decompression_precision, + const bool transpose_weights, + const bool add_subtract, + const bool reshape_on_decompression) { + ov::ParameterVector params{std::make_shared(data_precision, data_shape)}; + const auto weights_subgraph = initDecompressionWeights(weights_shape, + group_size, + data_precision, + weights_precision, + decompression_precision, + transpose_weights, + add_subtract, + reshape_on_decompression); + auto matMul = builder::makeMatMul(params[0], weights_subgraph); return makeNgraphFunction(data_precision, params, matMul, "MatmulWeightsDecompression"); } void SetUp() override { targetDevice = ov::test::utils::DEVICE_CPU; - std::vector inputShapes; + ShapeParams shape_params; ov::test::ElementType weights_precision; + ov::test::ElementType decompression_precision; bool transpose_weights; bool decompression_sub; bool reshape_on_decompression; @@ -163,8 +237,9 @@ class MatmulWeightsDecompression : public testing::WithParamInterface(test_param); - bool should_fuse = std::get<7>(test_param); + const auto& weights_precision = std::get<1>(test_param); + // TODO: remove this condition when group decompression is supported + if (weights_precision == ov::element::nf4 || std::get<0>(test_param).weights_group_size != -1) { + return; + } + bool weights_found = false; for (const auto& n : compiledModel.get_runtime_model()->get_ordered_ops()) { if (n->get_friendly_name() == "Compressed_weights") { ASSERT_EQ(n->get_output_element_type(0), weights_precision); + weights_found = true; } } + ASSERT_TRUE(weights_found); - std::map additional_config = std::get<5>(test_param); + const bool should_fuse = std::get<8>(test_param); const size_t expected_count = should_fuse ? 0 : 1; CheckNumberOfNodesWithType(compiledModel, "Convert", expected_count); CheckNumberOfNodesWithType(compiledModel, "Eltwise", expected_count); @@ -235,22 +324,25 @@ bool shouldUseDecompressionKernelBasic() { return shouldUseDecompressionKernelBig(); } -const std::vector weights_precisions = {ov::element::u8}; -const std::vector> input_shapes_basic = { - {{{-1, -1, -1}, {{1, 4, 16}, {10, 16, 16}}}, {{}, {{16, 32}}}}, - {{{}, {{1, 4, 16}}}, {{}, {{1, 16, 32}}}}, - {{{}, {{10, 40, 496}}}, {{}, {{1, 496, 240}}}}, - {{{}, {{1, 4, 48}}}, {{}, {{48, 256}}}}, - {{{}, {{11, 339, 377}}}, {{}, {{377, 335}}}}, +const std::vector weights_precisions = {ov::element::u8, ov::element::nf4}; +const std::vector decompression_precisions = {ov::element::f32}; +const std::vector input_shapes_basic = { + {{{-1, -1, -1}, {{1, 4, 16}, {10, 16, 16}}}, {16, 32}}, + {{{}, {{1, 4, 16}}}, {16, 32}, 2ul}, + {{{}, {{1, 4, 16}}}, {1, 16, 32}}, + {{{}, {{10, 40, 496}}}, {1, 496, 240}}, + {{{}, {{1, 4, 48}}}, {48, 256}}, + {{{}, {{11, 339, 377}}}, {377, 335}}, }; -const std::vector> input_shapes_big = { - {{{-1, -1, -1}, {{10, 40, 480}, {11, 40, 480}}}, {{}, {{1, 480, 256}}}}, - {{{}, {{1, 4, 32}}}, {{}, {{32, 256}}}}, - {{{}, {{1, 4, 512}}}, {{}, {{512, 256}}}}, - {{{}, {{1, 16, 32}}}, {{}, {{32, 64}}}}, - {{{}, {{2, 4, 32}}}, {{}, {{32, 65}}}}, - {{{}, {{3, 12, 768}}}, {{}, {{768, 1024}}}}, - {{{}, {{11, 339, 577}}}, {{}, {{577, 335}}}}, +const std::vector input_shapes_big = { + {{{-1, -1, -1}, {{10, 40, 480}, {11, 40, 480}}}, {1, 480, 256}}, + {{{-1, 1, 4096}, {{1, 1, 4096}}}, {4096, 3840}, 128ul}, + {{{}, {{1, 4, 32}}}, {32, 256}}, + {{{}, {{1, 4, 512}}}, {512, 256}}, + {{{}, {{1, 16, 32}}}, {32, 64}}, + {{{}, {{2, 4, 32}}}, {32, 65}}, + {{{}, {{3, 12, 768}}}, {768, 1024}}, + {{{}, {{11, 339, 577}}}, {577, 335}}, }; const std::vector fusingParamsSet { emptyFusingSpec, @@ -261,6 +353,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_basic, MatmulWeightsDecompression, ::testing::Combine(::testing::ValuesIn(input_shapes_basic), ::testing::ValuesIn(weights_precisions), + ::testing::ValuesIn(decompression_precisions), ::testing::Values(true), ::testing::Values(true), ::testing::Values(true), @@ -273,6 +366,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_big, MatmulWeightsDecompression, ::testing::Combine(::testing::ValuesIn(input_shapes_big), ::testing::ValuesIn(weights_precisions), + ::testing::ValuesIn(decompression_precisions), ::testing::Values(true), ::testing::Values(true), ::testing::Values(true), @@ -281,22 +375,26 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_big, ::testing::Values(shouldUseDecompressionKernelBig())), MatmulWeightsDecompression::getTestCaseName); -const std::vector> input_shapes_corner_cases_basic = { - {{{-1, -1, -1}, {{1, 4, 16}}}, {{}, {{1, 16, 32}}}}, - {{{-1, -1, -1}, {{1, 4, 16}}}, {{}, {{16, 32}}}}, +const std::vector input_shapes_corner_cases_basic = { + {{{-1, -1, -1}, {{1, 4, 16}}}, {1, 16, 32}}, + {{{-1, -1, -1}, {{1, 4, 16}}}, {16, 32}}, + {{{-1, -1, -1}, {{1, 4, 16}}}, {16, 32}, 4ul}, }; -const std::vector> input_shapes_corner_cases_big = { - {{{-1, -1, -1}, {{10, 40, 480}, {11, 40, 480}}}, {{}, {{1, 480, 256}}}}, +const std::vector input_shapes_corner_cases_big = { + {{{-1, -1, -1}, {{10, 40, 480}, {11, 40, 480}}}, {1, 480, 256}}, + {{{-1, -1, -1}, {{1, 1, 4096}}}, {4096, 4096}, 128ul}, }; const std::vector transpose_weights = {true, false}; const std::vector add_decompression_sub = {true, false}; const std::vector reshape_on_decompression = {true, false}; +const std::vector decompression_precisions_corner_cases = {ov::element::f16, ov::element::f32}; INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_corner_cases_basic, MatmulWeightsDecompression, ::testing::Combine(::testing::ValuesIn(input_shapes_corner_cases_basic), ::testing::ValuesIn(weights_precisions), + ::testing::ValuesIn(decompression_precisions_corner_cases), ::testing::ValuesIn(transpose_weights), ::testing::ValuesIn(add_decompression_sub), ::testing::ValuesIn(reshape_on_decompression), @@ -309,6 +407,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_corner_cases_big, MatmulWeightsDecompression, ::testing::Combine(::testing::ValuesIn(input_shapes_corner_cases_big), ::testing::ValuesIn(weights_precisions), + ::testing::ValuesIn(decompression_precisions_corner_cases), ::testing::ValuesIn(transpose_weights), ::testing::ValuesIn(add_decompression_sub), ::testing::ValuesIn(reshape_on_decompression), @@ -317,5 +416,4 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_corner_cases_big, ::testing::Values(shouldUseDecompressionKernelBig())), MatmulWeightsDecompression::getTestCaseName); } // namespace - } // namespace SubgraphTestsDefinitions diff --git a/src/plugins/intel_cpu/tests/functional/test_utils/cpu_test_utils.hpp b/src/plugins/intel_cpu/tests/functional/test_utils/cpu_test_utils.hpp index d8deddfebe5d69..fff65f9e1c442f 100644 --- a/src/plugins/intel_cpu/tests/functional/test_utils/cpu_test_utils.hpp +++ b/src/plugins/intel_cpu/tests/functional/test_utils/cpu_test_utils.hpp @@ -170,6 +170,7 @@ class CPUTestsBase { // common parameters const auto emptyCPUSpec = CPUSpecificParams{{}, {}, {}, {}}; const std::map cpuEmptyPluginConfig; +const ov::AnyMap empty_plugin_config{}; const std::map cpuFP32PluginConfig = { { InferenceEngine::PluginConfigParams::KEY_ENFORCE_BF16, InferenceEngine::PluginConfigParams::NO } }; const std::map cpuBF16PluginConfig = diff --git a/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/binary_elementwise_arithmetic.cpp b/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/binary_elementwise_arithmetic.cpp index 1b515222b85002..4943144ff7e2dc 100644 --- a/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/binary_elementwise_arithmetic.cpp +++ b/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/binary_elementwise_arithmetic.cpp @@ -83,7 +83,7 @@ TYPED_TEST_P(CpuShapeInferenceTest_BEA, shape_inference_aubtob_none) { } TYPED_TEST_P(CpuShapeInferenceTest_BEA, shape_inference_aubtob_none_incompatible_shapes) { - GTEST_SKIP() << "Skipping test, please check CVS-108946"; + GTEST_SKIP() << "CVS-122351 Skipping test, eltwiseShapeInfer only implemented numpy type boardcast"; auto A = std::make_shared(element::f32, PartialShape{-1, -1, -1, -1}); auto B = std::make_shared(element::f32, PartialShape{-1, -1, -1, -1}); @@ -92,7 +92,6 @@ TYPED_TEST_P(CpuShapeInferenceTest_BEA, shape_inference_aubtob_none_incompatible std::vector static_input_shapes = {StaticShape{3, 4, 6, 5}, StaticShape{3, 1, 6, 1}}, static_output_shapes = {StaticShape{}}; - //TODO cvs-108946, below test can't pass. OV_EXPECT_THROW(unit_test::cpu_test_shape_infer(node.get(), static_input_shapes, static_output_shapes), ov::Exception, testing::HasSubstr("Eltwise shape infer input shapes dim index:")); diff --git a/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/matmul.cpp b/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/matmul.cpp index b503b5e965ae7f..26dec0165c6529 100644 --- a/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/matmul.cpp +++ b/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/matmul.cpp @@ -4,6 +4,8 @@ #include #include "custom_shape_infer.hpp" +#include "openvino/core/dimension.hpp" +#include "openvino/core/partial_shape.hpp" #include "openvino/op/ops.hpp" namespace ov { namespace intel_cpu { @@ -33,7 +35,7 @@ class CPUMatMulTest : public TestWithParam { protected: void SetUp() override { std::tie(a_shape, b_shape) = GetParam(); - + (*exp_shape).clear(); set_exp_shape(); output_shapes.clear(); output_shapes.push_back(exp_shape); @@ -82,39 +84,35 @@ class CPUMatMulTest : public TestWithParam { }; TEST_P(CPUMatMulTest, no_input_transpose) { - GTEST_SKIP() << "Skipping test, please check CVS-108946"; const auto matmul = make_matmul(a_shape.size(), b_shape.size(), false, false); std::vector static_input_shapes = {a_shape, b_shape}; - // TODO 108946,below test case can't pass + matmul->set_output_type(0, element::i64, ov::PartialShape(std::vector(exp_shape.size(), -1))); unit_test::cpu_test_shape_infer(matmul.get(), static_input_shapes, output_shapes); } TEST_P(CPUMatMulTest, transpose_input_a) { - GTEST_SKIP() << "Skipping test, please check CVS-108946"; const auto matmul = make_matmul(a_shape.size(), b_shape.size(), true, false); const auto a_transpose = make_transpose_input(a_shape); std::vector static_input_shapes = {a_transpose, b_shape}; - // TODO 108946,below test case can't pass + matmul->set_output_type(0, element::i64, ov::PartialShape(std::vector(exp_shape.size(), -1))); unit_test::cpu_test_shape_infer(matmul.get(), static_input_shapes, output_shapes); } TEST_P(CPUMatMulTest, transpose_input_b) { - GTEST_SKIP() << "Skipping test, please check CVS-108946"; const auto matmul = make_matmul(a_shape.size(), b_shape.size(), false, true); const auto b_transpose = make_transpose_input(b_shape); std::vector static_input_shapes = {a_shape, b_transpose}; - // TODO 108946,below test case can't pass + matmul->set_output_type(0, element::i64, ov::PartialShape(std::vector(exp_shape.size(), -1))); unit_test::cpu_test_shape_infer(matmul.get(), static_input_shapes, output_shapes); } TEST_P(CPUMatMulTest, transpose_inputs_a_b) { - GTEST_SKIP() << "Skipping test, please check CVS-108946"; const auto matmul = make_matmul(a_shape.size(), b_shape.size(), true, true); const auto a_transpose = make_transpose_input(a_shape); @@ -122,7 +120,7 @@ TEST_P(CPUMatMulTest, transpose_inputs_a_b) { std::vector static_input_shapes = {a_transpose, b_transpose}; - // TODO 108946,below test case can't pass + matmul->set_output_type(0, element::i64, ov::PartialShape(std::vector(exp_shape.size(), -1))); unit_test::cpu_test_shape_infer(matmul.get(), static_input_shapes, output_shapes); } diff --git a/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/one_hot.cpp b/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/one_hot.cpp index 57e007c7d9a863..99ed87e83fcf7f 100644 --- a/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/one_hot.cpp +++ b/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/one_hot.cpp @@ -89,7 +89,6 @@ INSTANTIATE_TEST_SUITE_P( using OneHotCpuShapeInferenceThrowExceptionTest = OneHotCpuShapeInferenceTest; TEST_P(OneHotCpuShapeInferenceThrowExceptionTest, wrong_pattern) { - GTEST_SKIP() << "Skipping test, please check CVS-108946"; const auto depth = std::make_shared(element::i64, ov::Shape{}); const auto on = std::make_shared(element::i32, ov::Shape{}); const auto off = std::make_shared(element::i32, ov::Shape{}); @@ -101,9 +100,9 @@ TEST_P(OneHotCpuShapeInferenceThrowExceptionTest, wrong_pattern) { const auto off_tensor = ov::Tensor(element::i32, ov::Shape{}, &m_off); const std::unordered_map constant_data = {{1, depth_tensor}, {2, on_tensor}, {3, off_tensor}}; - // TODO , implementation should throw exception - ASSERT_THROW(unit_test::cpu_test_shape_infer(op.get(), input_shapes, output_shapes, constant_data), - ov::Exception); + OV_EXPECT_THROW(unit_test::cpu_test_shape_infer(op.get(), input_shapes, output_shapes, constant_data), + ov::Exception, + testing::HasSubstr("OneHot depth value can't be negative")); } INSTANTIATE_TEST_SUITE_P( diff --git a/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/shape_node.cpp b/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/shape_node.cpp index 6611b760b406a5..9d8f63802bdeb8 100644 --- a/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/shape_node.cpp +++ b/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/shape_node.cpp @@ -39,19 +39,6 @@ TEST(CpuShapeInfer, v3ShapeOf5DTest) { unit_test::cpu_test_shape_infer(shapeof.get(), static_input_shapes, static_output_shapes); } -TEST(CpuShapeInfer, ShapeOf0DTest) { - GTEST_SKIP() << "Skipping test, please check CVS-108946"; - auto data = std::make_shared(element::f32, PartialShape{}); - - auto shapeof = - std::make_shared(data); - - std::vector static_input_shapes = {StaticShape{}}, - static_output_shapes = {StaticShape{}}; - // TODO , can't pass implementation don't support 0D shape input - unit_test::cpu_test_shape_infer(shapeof.get(), static_input_shapes, static_output_shapes); -} - } // namespace cpu_shape_infer } // namespace unit_test } // namespace intel_cpu diff --git a/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/strided_slice.cpp b/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/strided_slice.cpp index 9a9fe23f00afbe..fa25928d60e4de 100644 --- a/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/strided_slice.cpp +++ b/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/strided_slice.cpp @@ -101,29 +101,11 @@ INSTANTIATE_TEST_SUITE_P( make_tuple(unit_test::ShapeVector{{3, 2, 3}, {3}, {3}, {3}}, std::vector>{{1, 0, 0}, {0, 0, 0}, {1, 1, 1}}, std::vector{0, 1, 1}, std::vector(3, 1), StaticShape({2, 2, 3})), make_tuple(unit_test::ShapeVector{{3, 2, 3}, {3}, {3}, {3}}, std::vector>{{0, 1, 0}, {2, 0, 0}, {1, 1, 2}}, - std::vector{1, 0, 1}, std::vector{0, 1, 1}, StaticShape({2, 1, 2}))), - // TODO 108946, can't pass; - // make_tuple(unit_test::ShapeVector{{3, 2, 3}, {3}, {3}, {3}}, std::vector>{{0, 0, 0}, {1, 0, 0}, {1, 1, -1}}, - // std::vector{0, 1, 1}, std::vector{0, 1, 1}, StaticShape({1, 1, 3}))), + std::vector{1, 0, 1}, std::vector{0, 1, 1}, StaticShape({2, 1, 2})), + make_tuple(unit_test::ShapeVector{{3, 2, 3}, {3}, {3}, {3}}, std::vector>{{0, 0, 0}, {1, 0, 0}, {1, 1, -1}}, + std::vector{0, 1, 1}, std::vector{0, 1, 1}, StaticShape({1, 2, 3}))), StridedSliceCpuShapeInferenceTest::getTestCaseName); -TEST(CpuShapeInfer, StridedSliceDefault_stride) { - GTEST_SKIP() << "Skipping test, please check CVS-108946"; - const auto mask = std::vector{0, 1, 0}; - - const auto data = std::make_shared(element::f32, ov::PartialShape::dynamic()); - // only supprot i32 - const auto begin = op::v0::Constant::create(element::i32, ov::Shape{3}, {0, 0, 0}); - const auto end = op::v0::Constant::create(element::i32, ov::Shape{3}, {1, 0, 2}); - const auto op = std::make_shared(data, begin, end, mask, mask); - - std::vector static_input_shapes = {{3, 2, 3}, {3}, {3}}; - std::vector static_output_shapes = {StaticShape{1, 2, 2}}; - // implementation depends on some output information of the op - op->set_output_type(0, element::i32, {-1, -1, -1}); - // TODO 108946,there is some issue in implementation, this test case can't pass - unit_test::cpu_test_shape_infer(op.get(), static_input_shapes, static_output_shapes); -} } // namespace cpu_shape_infer } // namespace unit_test } // namespace intel_cpu diff --git a/src/plugins/intel_cpu/tests/unit/snippets_transformations/mul_add_to_fma.cpp b/src/plugins/intel_cpu/tests/unit/snippets_transformations/mul_add_to_fma.cpp index 7a6ef6e67c1d21..3a760050d0159a 100644 --- a/src/plugins/intel_cpu/tests/unit/snippets_transformations/mul_add_to_fma.cpp +++ b/src/plugins/intel_cpu/tests/unit/snippets_transformations/mul_add_to_fma.cpp @@ -6,8 +6,10 @@ #include #include #include +#include #include "snippets/op/scalar.hpp" #include "lowering_utils.hpp" +#include "common_test_utils/common_utils.hpp" #include "snippets/pass_manager.hpp" namespace ov { @@ -61,7 +63,7 @@ class EltwiseWithMulAddFunction : public SnippetsFunctionBase { ParameterVector parameters{data0, data1}; std::shared_ptr data2; if (scalar_input) { - data2 = std::make_shared(precision, Shape{}, 2.f); + data2 = std::make_shared(precision, Shape{1}, 2.f); } else { auto parameter = std::make_shared(precision, input_shapes[2]); parameters.push_back(parameter); @@ -110,8 +112,8 @@ class MulAddToFMATests : public LoweringTests, public testing::WithParamInterfac std::ostringstream result; for (size_t i = 0; i < inputShapes.size(); i++) - result << "IS[" << i << "]=" << inputShapes[i] << "_"; - result << "MS=" << master_shape << "_"; + result << "IS[" << i << "]=" << ov::test::utils::partialShape2str({inputShapes[i]}) << "_"; + result << "MS=" << ov::test::utils::partialShape2str({master_shape}) << "_"; result << "add_input_idx=" << add_input_idx; return result.str(); } @@ -146,7 +148,8 @@ TEST_P(MulAddToFMATests, MulAddToFMATests) { backend_passes, {}, {}, - generator); + generator, + std::make_shared()); model = subgraph->body_ptr(); model_ref = snippets_model->getLowered(); } diff --git a/src/plugins/intel_cpu/tests/unit/streams_info/streams_e2e_test.cpp b/src/plugins/intel_cpu/tests/unit/streams_info/streams_e2e_test.cpp index 7174b616377456..6836e6e75fb8de 100644 --- a/src/plugins/intel_cpu/tests/unit/streams_info/streams_e2e_test.cpp +++ b/src/plugins/intel_cpu/tests/unit/streams_info/streams_e2e_test.cpp @@ -553,8 +553,134 @@ StreamGenerateionTestCase generation_tput_2sockets_48cores_9 = { {{48, 48, 0, 0, -1, -1}, {24, 24, 0, 0, 0, 0}, {24, 24, 0, 0, 1, 1}}, {{24, MAIN_CORE_PROC, 1, 0, 0}, {24, MAIN_CORE_PROC, 1, 1, 1}}, }; +StreamGenerateionTestCase generation_latency_1sockets_96cores_pinning = { + 1, + false, + 0, + 0, + 0, + ov::hint::SchedulingCoreType::ANY_CORE, + false, + false, + true, + true, + ov::hint::PerformanceMode::LATENCY, + ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, + {{96, 0, 96, 0, 0, 0}}, + ov::hint::SchedulingCoreType::ANY_CORE, + false, + true, + ov::hint::PerformanceMode::LATENCY, + {{96, 0, 96, 0, 0, 0}}, + {{1, EFFICIENT_CORE_PROC, 96, 0, 0}}, +}; +StreamGenerateionTestCase generation_tput_1sockets_96cores_pinning = { + 1, + false, + 0, + 0, + 0, + ov::hint::SchedulingCoreType::ANY_CORE, + false, + false, + true, + true, + ov::hint::PerformanceMode::THROUGHPUT, + ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, + {{96, 0, 96, 0, 0, 0}}, + ov::hint::SchedulingCoreType::ANY_CORE, + false, + true, + ov::hint::PerformanceMode::THROUGHPUT, + {{96, 0, 96, 0, 0, 0}}, + {{24, EFFICIENT_CORE_PROC, 4, 0, 0}}, +}; +StreamGenerateionTestCase generation_tput_1sockets_96cores_2_pinning = { + 1, + false, + 0, + 0, + 0, + ov::hint::SchedulingCoreType::PCORE_ONLY, + true, + true, + true, + true, + ov::hint::PerformanceMode::THROUGHPUT, + ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, + {{96, 0, 96, 0, 0, 0}}, + ov::hint::SchedulingCoreType::ANY_CORE, + false, + true, + ov::hint::PerformanceMode::THROUGHPUT, + {{96, 0, 96, 0, 0, 0}}, + {{24, EFFICIENT_CORE_PROC, 4, 0, 0}}, +}; +StreamGenerateionTestCase generation_latency_1sockets_96cores_unpinning = { + 1, + false, + 0, + 0, + 0, + ov::hint::SchedulingCoreType::ANY_CORE, + false, + false, + true, + true, + ov::hint::PerformanceMode::LATENCY, + ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, + {{96, 0, 96, 0, 0, 0}}, + ov::hint::SchedulingCoreType::ANY_CORE, + false, + false, + ov::hint::PerformanceMode::LATENCY, + {{96, 0, 96, 0, 0, 0}}, + {{1, EFFICIENT_CORE_PROC, 96, 0, 0}}, +}; +StreamGenerateionTestCase generation_tput_1sockets_96cores_unpinning = { + 1, + false, + 0, + 0, + 0, + ov::hint::SchedulingCoreType::ANY_CORE, + false, + false, + false, + false, + ov::hint::PerformanceMode::THROUGHPUT, + ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, + {{96, 0, 96, 0, 0, 0}}, + ov::hint::SchedulingCoreType::ANY_CORE, + false, + false, + ov::hint::PerformanceMode::THROUGHPUT, + {{96, 0, 96, 0, 0, 0}}, + {{24, EFFICIENT_CORE_PROC, 4, 0, 0}}, +}; +StreamGenerateionTestCase generation_tput_1sockets_96cores_2_unpinning = { + 1, + false, + 0, + 0, + 0, + ov::hint::SchedulingCoreType::PCORE_ONLY, + true, + true, + false, + true, + ov::hint::PerformanceMode::THROUGHPUT, + ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, + {{96, 0, 96, 0, 0, 0}}, + ov::hint::SchedulingCoreType::ANY_CORE, + false, + false, + ov::hint::PerformanceMode::THROUGHPUT, + {{96, 0, 96, 0, 0, 0}}, + {{24, EFFICIENT_CORE_PROC, 4, 0, 0}}, +}; -#if defined (__linux__) || defined(_WIN32) +#if defined(__linux__) || defined(_WIN32) INSTANTIATE_TEST_SUITE_P(smoke_StreamsGeneration, StreamGenerationTests, ::testing::Values(generation_latency_1sockets_14cores_3, @@ -574,7 +700,10 @@ INSTANTIATE_TEST_SUITE_P(smoke_StreamsGeneration, generation_tput_2sockets_48cores_6, generation_tput_2sockets_48cores_7, generation_tput_2sockets_48cores_8, - generation_tput_2sockets_48cores_9)); + generation_tput_2sockets_48cores_9, + generation_latency_1sockets_96cores_pinning, + generation_tput_1sockets_96cores_pinning, + generation_tput_1sockets_96cores_2_pinning)); #else INSTANTIATE_TEST_SUITE_P(smoke_StreamsGeneration, StreamGenerationTests, @@ -595,7 +724,10 @@ INSTANTIATE_TEST_SUITE_P(smoke_StreamsGeneration, generation_tput_2sockets_48cores_6, generation_tput_2sockets_48cores_7, generation_tput_2sockets_48cores_8, - generation_tput_2sockets_48cores_9)); + generation_tput_2sockets_48cores_9, + generation_latency_1sockets_96cores_unpinning, + generation_tput_1sockets_96cores_unpinning, + generation_tput_1sockets_96cores_2_unpinning)); #endif } // namespace \ No newline at end of file diff --git a/src/plugins/intel_cpu/thirdparty/mlas b/src/plugins/intel_cpu/thirdparty/mlas index c7c8a631315000..f6425b13943348 160000 --- a/src/plugins/intel_cpu/thirdparty/mlas +++ b/src/plugins/intel_cpu/thirdparty/mlas @@ -1 +1 @@ -Subproject commit c7c8a631315000f17c650af34431009d2f22129c +Subproject commit f6425b1394334822390fcd9da12788c9cd0d11da diff --git a/src/plugins/intel_cpu/tools/commit_slider/utils/helpers.py b/src/plugins/intel_cpu/tools/commit_slider/utils/helpers.py index c30c5773467b4f..3adf6e65025af4 100644 --- a/src/plugins/intel_cpu/tools/commit_slider/utils/helpers.py +++ b/src/plugins/intel_cpu/tools/commit_slider/utils/helpers.py @@ -191,14 +191,10 @@ def runCommandList(commit, cfgData, enforceClean=False): ) proc = subprocess.Popen( formattedCmd, cwd=cwd, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT + stderr=subprocess.STDOUT, + encoding="utf-8", errors="replace" ) for line in proc.stdout: - # decode if line is byte-type - try: - line = line.decode("utf-8") - except (UnicodeDecodeError, AttributeError): - pass sys.stdout.write(line) commitLogger.info(line) if "catchMsg" in cmd: diff --git a/src/plugins/intel_gna/CMakeLists.txt b/src/plugins/intel_gna/CMakeLists.txt index 566253a3c6a318..107ea8a5a0cdc9 100644 --- a/src/plugins/intel_gna/CMakeLists.txt +++ b/src/plugins/intel_gna/CMakeLists.txt @@ -23,7 +23,7 @@ file(GLOB_RECURSE HEADERS # build avx2.cpp with AVX2 support, only for Windows if(ENABLE_AVX2 AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - ie_avx2_optimization_flags(avx2_flags) + 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() 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 index 32903887e81181..b1eb1e0539e9a0 100644 --- 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 @@ -51,6 +51,7 @@ #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" @@ -475,6 +476,11 @@ void CNNLayerCreator::on_adapter(const std::string& name, ::ngraph::ValueAccesso 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); 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 index 03cf9af92fbaa7..765846056930f8 100644 --- a/src/plugins/intel_gna/tests/deprecated/helpers/single_layer_common.hpp +++ b/src/plugins/intel_gna/tests/deprecated/helpers/single_layer_common.hpp @@ -20,10 +20,6 @@ # 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)) -#elif defined USE_BOOST_RE -# include -# define REPLACE_WITH_STR(SRC, PATTERN, STR) SRC = boost::regex_replace(SRC, boost::regex(PATTERN), STR) -# define FIND_STR(SRC, PATTERN) boost::regex_search(SRC, boost::regex(PATTERN)) #else # error "Cannot implement regex" # define REPLACE_WITH_STR(SRC, PATTERN, STR) diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/tests_common.hpp b/src/plugins/intel_gna/tests/deprecated/helpers/tests_common.hpp index f164fc1e8ca361..c9b5cea167f1dd 100644 --- a/src/plugins/intel_gna/tests/deprecated/helpers/tests_common.hpp +++ b/src/plugins/intel_gna/tests/deprecated/helpers/tests_common.hpp @@ -44,7 +44,7 @@ class TestsCommon : public ::testing::Test { void SetUp() override; static std::string make_so_name(const std::string & input) { - return ov::test::utils::pre + input + IE_BUILD_POSTFIX + ov::test::utils::ext; + return ov::test::utils::pre + input + OV_BUILD_POSTFIX + ov::test::utils::ext; } void TearDown() override; diff --git a/src/plugins/intel_gna/tests/deprecated/unit/CMakeLists.txt b/src/plugins/intel_gna/tests/deprecated/unit/CMakeLists.txt index fd85b52a313767..035e05de64516b 100644 --- a/src/plugins/intel_gna/tests/deprecated/unit/CMakeLists.txt +++ b/src/plugins/intel_gna/tests/deprecated/unit/CMakeLists.txt @@ -8,9 +8,6 @@ set(TARGET_NAME InferenceEngineUnitTests) ov_disable_deprecated_warnings() -# rpath enabled for unit tests only -SET (CMAKE_SKIP_RPATH OFF) - # collect sources file(GLOB 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 index ef6c7eb8257725..07cbd0dd905afc 100644 --- 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 @@ -2,31 +2,31 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include "subgraph_tests/get_output_before_activation.hpp" -#include "common_test_utils/test_constants.hpp" - -namespace SubgraphTestsDefinitions { +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"}}}; +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(InferenceEngine::Precision::FP32), + ::testing::Values(ov::element::f32), ::testing::ValuesIn(input_sizes), ::testing::ValuesIn(midLayerTypes), ::testing::ValuesIn(configs)), OutputBeforeActivation::getTestCaseName); -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov 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 index b5ece0ac7f71b6..aafc875bc5866d 100644 --- 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 @@ -8,17 +8,15 @@ #include "common_test_utils/test_constants.hpp" -using namespace SubgraphTestsDefinitions; +using namespace ov::test; namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; +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"}}}; +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 input_shapes = {{1, 8}, {1, 42}, {1, 100}, {1, 128}, {1, 512}}; std::vector output_sizes = {1000, 512, 128, 42, 16, 8}; diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/perm_conv_perm_concat.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/perm_conv_perm_concat.cpp deleted file mode 100644 index 299935865f1ca5..00000000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/perm_conv_perm_concat.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/perm_conv_perm_concat.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" -namespace { -std::vector> input_shapes{ - {1, 1, 7, 32}, - {1, 1, 8, 16}, -}; - -std::vector> kernel_shapes{ - {1, 3}, - {1, 5}, -}; - -std::vector output_channels{ - 32, - 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"}}}; -} // namespace - -namespace SubgraphTestsDefinitions { -INSTANTIATE_TEST_SUITE_P(smoke_basic, - PermConvPermConcat, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(input_shapes), - ::testing::ValuesIn(kernel_shapes), - ::testing::ValuesIn(output_channels), - ::testing::ValuesIn(configs)), - PermConvPermConcat::getTestCaseName); -} // namespace SubgraphTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/reshape_squeeze_reshape_relu.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/reshape_squeeze_reshape_relu.cpp deleted file mode 100644 index f702ba9b3ec5f7..00000000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/reshape_squeeze_reshape_relu.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/reshape_squeeze_reshape_relu.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -std::vector inputs{ - {{1, 1, 3}, {0, 1}}, - {{1, 1, 3}, {0}}, - {{1, 1, 3}, {1}}, - {{1, 3, 1}, {0, 2}}, - {{1, 3, 1}, {0}}, - {{1, 3, 1}, {2}}, - {{3, 1, 1}, {1, 2}}, - {{3, 1, 1}, {1}}, - {{3, 1, 1}, {2}}, - {{4, 1, 3, 1}, {1, 3}}, - {{4, 1, 1, 3}, {1, 2}}, - {{1, 4, 1, 3}, {0, 2}}, - {{1, 3, 5, 2, 1}, {0, 4}}, - {{3, 1, 2, 4, 4, 3}, {1}}, - {{1, 1, 1, 1, 1, 3}, {0, 1, 2, 3, 4}}, - {{1, 1, 1, 1, 1, 3}, {1, 3}}, - {{1}, {0}}, -}; - -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -const std::vector opTypes = {ngraph::helpers::SqueezeOpType::SQUEEZE, - ngraph::helpers::SqueezeOpType::UNSQUEEZE}; - -INSTANTIATE_TEST_SUITE_P(smoke_reshape_squeeze_reshape_relu, - ReshapeSqueezeReshapeRelu, - ::testing::Combine(::testing::ValuesIn(inputs), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(opTypes)), - ReshapeSqueezeReshapeRelu::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/split_conv_concat.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/split_conv_concat.cpp deleted file mode 100644 index 1d9cea34c783ac..00000000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/split_conv_concat.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/split_conv_concat.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -std::vector> inputShapes = {{1, 32, 1, 130}, {1, 64, 1, 170}, {1, 32, 1, 1026}}; - -INSTANTIATE_TEST_SUITE_P(smoke_SplitConvConcat, - SplitConvConcat, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(inputShapes), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - SplitConvConcat::getTestCaseName); diff --git a/src/plugins/intel_gna/tests/unit/CMakeLists.txt b/src/plugins/intel_gna/tests/unit/CMakeLists.txt index 87f4223a643f79..cb77a5e190ca74 100644 --- a/src/plugins/intel_gna/tests/unit/CMakeLists.txt +++ b/src/plugins/intel_gna/tests/unit/CMakeLists.txt @@ -4,9 +4,6 @@ set(TARGET_NAME ov_gna_unit_tests) -# RPATH is always enabled for unit tests -set(CMAKE_SKIP_RPATH OFF) - # 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}) diff --git a/src/plugins/intel_gpu/CMakeLists.txt b/src/plugins/intel_gpu/CMakeLists.txt index 2561407b6faaa7..b0c66a435d6470 100644 --- a/src/plugins/intel_gpu/CMakeLists.txt +++ b/src/plugins/intel_gpu/CMakeLists.txt @@ -65,6 +65,8 @@ target_link_libraries(${TARGET_NAME} PRIVATE openvino_intel_gpu_graph openvino:: target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/) +ov_set_threading_interface_for(${TARGET_NAME}) + set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO}) # Workaround to avoid warnings during LTO build diff --git a/src/plugins/intel_gpu/docs/memory_allocation_gpu_plugin.md b/src/plugins/intel_gpu/docs/memory_allocation_gpu_plugin.md index eb548eb386abe4..1ad9039435fb56 100644 --- a/src/plugins/intel_gpu/docs/memory_allocation_gpu_plugin.md +++ b/src/plugins/intel_gpu/docs/memory_allocation_gpu_plugin.md @@ -20,7 +20,7 @@ calls the corresponding memory object wrapper for each allocation type: [gpu_buf ## Dump memory allocation history -The memory allocation history is being managed by the `engine`, which can be dumped by setting the environment variable `OV_GPU_Verbose=1` if OpenVino is built with the cmake configuration `ENABLE_DEBUG_CAPS=ON`. +The memory allocation history is being managed by the `engine`, which can be dumped by setting the environment variable `OV_GPU_Verbose=2` if OpenVINO is built with the cmake configuration `ENABLE_DEBUG_CAPS=ON`. ```cpp ... GPU_Debug: Allocate 58982400 bytes of usm_host allocation type (current=117969612; max=117969612) diff --git a/src/plugins/intel_gpu/include/intel_gpu/graph/network.hpp b/src/plugins/intel_gpu/include/intel_gpu/graph/network.hpp index 1474543428a7b7..ab5d6b5e0af140 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/graph/network.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/graph/network.hpp @@ -283,6 +283,8 @@ struct network { size_t _weights_cache_capacity = 1; std::unordered_map _events; + // This map is used to temporarily hold events that will be deallocated later + std::unordered_map _old_events; output_chains_map _output_chains; std::unique_ptr _shape_predictor; diff --git a/src/plugins/intel_gpu/include/intel_gpu/op/rms.hpp b/src/plugins/intel_gpu/include/intel_gpu/op/rms.hpp new file mode 100644 index 00000000000000..a6b7432ac28c51 --- /dev/null +++ b/src/plugins/intel_gpu/include/intel_gpu/op/rms.hpp @@ -0,0 +1,48 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/op/op.hpp" + +namespace ov { +namespace intel_gpu { +namespace op { +/// \brief Operator performing Root Mean Square Normalization +/// +/// \note Performs re-scaling invariance and regularizes the summed input according to RMS statistics +class RMS : public ov::op::Op { +public: + OPENVINO_OP("RMS", "gpu_opset"); + + RMS() = default; + /// \brief Constructs an RMS operation. + /// + /// \param data Input tensor with data + /// \param gamma Gamma values for weight + /// \param eps Epsilon for not dividing by zero while normalizing the value + /// \param output_type Output element type + RMS(const Output& data, + const Output& gamma, + double epsilson, + const ov::element::Type output_type = ov::element::undefined); + + bool visit_attributes(ov::AttributeVisitor& visitor) override; + + void validate_and_infer_types() override; + + std::shared_ptr clone_with_new_inputs(const ov::OutputVector& new_args) const override; + + double get_epsilon() const { return m_epsilon; } + + void set_epsilon(double epsilon) { m_epsilon = epsilon; } + +private: + double m_epsilon{0}; + ov::element::Type m_output_type; +}; + +} // namespace op +} // namespace intel_gpu +} // namespace ov diff --git a/src/plugins/intel_gpu/include/intel_gpu/plugin/primitives_list.hpp b/src/plugins/intel_gpu/include/intel_gpu/plugin/primitives_list.hpp index 1ae7ef4f76618e..ceba5be5a5dd53 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/plugin/primitives_list.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/plugin/primitives_list.hpp @@ -257,6 +257,7 @@ REGISTER_FACTORY(v11, Interpolate); REGISTER_FACTORY(v11, TopK); // ------------------------------ Supported v12 ops ----------------------------- // +REGISTER_FACTORY(v12, GroupNormalization); REGISTER_FACTORY(v12, Pad); REGISTER_FACTORY(v12, ScatterElementsUpdate); @@ -267,3 +268,4 @@ REGISTER_FACTORY(internal, NmsStaticShapeIE8); REGISTER_FACTORY(internal, MulticlassNmsIEInternal); REGISTER_FACTORY(internal, FullyConnected); REGISTER_FACTORY(internal, FullyConnectedCompressed); +REGISTER_FACTORY(internal, RMS); diff --git a/src/plugins/intel_gpu/include/intel_gpu/plugin/remote_allocators.hpp b/src/plugins/intel_gpu/include/intel_gpu/plugin/remote_allocators.hpp deleted file mode 100644 index 877c2c707f1791..00000000000000 --- a/src/plugins/intel_gpu/include/intel_gpu/plugin/remote_allocators.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/runtime/so_ptr.hpp" - -#include - -namespace ov { -namespace intel_gpu { - -class RemoteTensorImpl; -class RemoteContextImpl; - -class USMHostAllocator final { -private: - ov::SoPtr _usm_host_tensor = { nullptr, nullptr }; - std::shared_ptr _context = nullptr; - -public: - using Ptr = std::shared_ptr; - - explicit USMHostAllocator(std::shared_ptr context) : _context(context) { } - - /** - * @brief Allocates memory - * @param size The size in bytes to allocate - * @return Handle to the allocated resource - */ - void* allocate(const size_t bytes, const size_t alignment = alignof(max_align_t)) noexcept; - /** - * @brief Releases handle and all associated memory resources which invalidates the handle. - * @return false if handle cannot be released, otherwise - true. - */ - bool deallocate(void* handle, const size_t bytes, size_t alignment = alignof(max_align_t)) noexcept; - - bool is_equal(const USMHostAllocator& other) const; -}; - -} // namespace intel_gpu -} // namespace ov diff --git a/src/plugins/intel_gpu/include/intel_gpu/plugin/remote_tensor.hpp b/src/plugins/intel_gpu/include/intel_gpu/plugin/remote_tensor.hpp index 939c7b89784fc9..f7f72cc77a16a3 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/plugin/remote_tensor.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/plugin/remote_tensor.hpp @@ -15,6 +15,7 @@ #endif #include "openvino/runtime/iremote_tensor.hpp" +#include "intel_gpu/runtime/memory_caps.hpp" #include "intel_gpu/runtime/memory.hpp" #include "intel_gpu/runtime/engine.hpp" #include "intel_gpu/plugin/common_utils.hpp" @@ -52,9 +53,12 @@ class RemoteTensorImpl : public ov::IRemoteTensor { bool is_allocated() const noexcept; bool is_surface() const noexcept; + bool is_shared() const noexcept; cldnn::memory::ptr get_memory() const; cldnn::memory::ptr get_original_memory() const; + void set_memory(cldnn::memory::ptr memory, size_t actual_size); + std::shared_ptr get_context() const; private: @@ -74,10 +78,12 @@ class RemoteTensorImpl : public ov::IRemoteTensor { uint32_t m_plane; size_t m_hash = 0; - bool is_shared() const; bool supports_caching() const; + void update_hash(); void update_strides(); - void init_properties(); + void update_properties(); + + static TensorType allocation_type_to_tensor_type(cldnn::allocation_type t); }; } // namespace intel_gpu diff --git a/src/plugins/intel_gpu/include/intel_gpu/plugin/sync_infer_request.hpp b/src/plugins/intel_gpu/include/intel_gpu/plugin/sync_infer_request.hpp index 1fd6d035dd48af..3050846e2c2354 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/plugin/sync_infer_request.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/plugin/sync_infer_request.hpp @@ -90,9 +90,7 @@ class SyncInferRequest : public ov::ISyncInferRequest { bool need_lockable_mem) const; std::shared_ptr reinterpret_device_tensor(std::shared_ptr tensor, const ov::Shape new_shape) const; std::shared_ptr create_host_tensor(const ov::PartialShape& port_shape, const ov::element::Type& port_element_type) const; - std::shared_ptr create_device_tensor(const ov::Shape& pshape, ov::element::Type element_type, - bool need_lockable_memory = false, void* mem_ptr = nullptr) const; - std::shared_ptr create_shared_device_tensor(const ov::Shape& pshape, ov::element::Type element_type, void* usm_host_mem) const; + std::shared_ptr create_device_tensor(const ov::PartialShape& pshape, ov::element::Type element_type, bool need_lockable_memory = false) const; void allocate_inputs(); void allocate_outputs(); diff --git a/src/plugins/intel_gpu/include/intel_gpu/plugin/usm_host_tensor.hpp b/src/plugins/intel_gpu/include/intel_gpu/plugin/usm_host_tensor.hpp new file mode 100644 index 00000000000000..d410fa046651e5 --- /dev/null +++ b/src/plugins/intel_gpu/include/intel_gpu/plugin/usm_host_tensor.hpp @@ -0,0 +1,42 @@ +// Copyright (C) 2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/runtime/itensor.hpp" + +#include + +namespace ov { +namespace intel_gpu { + +class RemoteContextImpl; +class RemoteTensorImpl; + +class USMHostTensor : public ov::ITensor { +public: + USMHostTensor(std::shared_ptr context, const element::Type element_type, const Shape& shape); + explicit USMHostTensor(std::shared_ptr tensor); + + ~USMHostTensor() override = default; + + void* data(const element::Type& element_type) const override; + const element::Type& get_element_type() const override; + + const Shape& get_shape() const override; + + const Strides& get_strides() const override; + + void set_shape(ov::Shape new_shape) override; + + void set_memory(std::shared_ptr tensor); + + std::shared_ptr get_impl() const; + +private: + std::shared_ptr m_impl; +}; + +} // namespace intel_gpu +} // namespace ov diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/condition.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/condition.hpp index 5ad37c7dfa55bf..4301f7cc10d31a 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/primitives/condition.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/condition.hpp @@ -54,8 +54,8 @@ struct condition : public primitive_base { const std::vector& inputs, const branch& branch_true, const branch& branch_false, - const padding& output_padding = padding()) - : primitive_base(id, inputs, {output_padding}), + const size_t num_outputs = 1) + : primitive_base(id, inputs, {padding()}, {optional_data_type()}, num_outputs), branch_true(branch_true), branch_false(branch_false) {} diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/gather.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/gather.hpp index 2a7dad7fe4774d..cbc64a0e143ec2 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/primitives/gather.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/gather.hpp @@ -21,6 +21,7 @@ struct gather : public primitive_base { /// @param dict Input dictionary primitive id. /// @param idx Input indexes primitive id. /// @param axis Gathering axis. + /// @param input_rank Input rank. /// @param output_shape Output shape. /// @param batch_dim Batch_dim /// @param support_neg_ind Support negative indexes @@ -28,18 +29,22 @@ struct gather : public primitive_base { const input_info& dict, const input_info& idx, const int64_t axis, + const int64_t input_rank, const ov::Shape& output_shape, const int64_t batch_dim = 0, const bool support_neg_ind = false, const padding& output_padding = padding()) : primitive_base(id, {dict, idx}, {output_padding}) , axis(axis) + , input_rank(input_rank) , output_shape(output_shape) , batch_dim(batch_dim) , support_neg_ind(support_neg_ind) {} /// @brief Gathering axis int64_t axis = 0; + /// @brief Gather input rank + int64_t input_rank; /// @brief Gather output shape ov::Shape output_shape; /// @brief Gathering batch_dim @@ -69,6 +74,7 @@ struct gather : public primitive_base { void save(BinaryOutputBuffer& ob) const override { primitive_base::save(ob); ob << axis; + ob << input_rank; ob << output_shape; ob << batch_dim; ob << support_neg_ind; @@ -77,6 +83,7 @@ struct gather : public primitive_base { void load(BinaryInputBuffer& ib) override { primitive_base::load(ib); ib >> axis; + ib >> input_rank; ib >> output_shape; ib >> batch_dim; ib >> support_neg_ind; diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/group_normalization.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/group_normalization.hpp new file mode 100644 index 00000000000000..d8c7e385f4c9a7 --- /dev/null +++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/group_normalization.hpp @@ -0,0 +1,73 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#pragma once +#include "primitive.hpp" + +namespace cldnn { + +/// @brief Performs the following transformation of the input tensor: +/// y = scale * (x - mean) / sqrt(variance + epsilon) + bias +/// The operation is applied per batch, per group of channels. +struct group_normalization : public primitive_base { + CLDNN_DECLARE_PRIMITIVE(group_normalization) + + group_normalization() : primitive_base("", {}) {} + + /// @brief Constructs group_normalization primitive. + /// @param id This primitive id. + /// @param data The input tensor to be normalized. + /// @param scale Scale values tensor. + /// @param bias Bias values. + /// @param num_groups Number of groups the channel dimension will be divided into. + /// @param epsilon A value added to the variance which ensures that division by zero. + /// does not occur for any normalized element. + group_normalization(const primitive_id& id, + const input_info& data, + const input_info& scale, + const input_info& bias, + std::int64_t num_groups, + double epsilon, + const padding& output_padding = padding()) + : primitive_base(id, {data, scale, bias}, {output_padding}), num_groups{num_groups}, epsilon{epsilon} {} + + /// @brief Number of groups the channel dimension will be divided into + /// @details + /// Specifies the number of groups G that the channel dimension will be divided into. + std::int64_t num_groups{}; + + /// @brief A value added to the variance which ensures that division by zero. + /// @details + /// A very small value added to the variance for numerical stability. + /// Ensures that division by zero does not occur for any normalized element. + double epsilon{}; + + std::size_t hash() const override { + size_t seed = primitive::hash(); + seed = hash_combine(seed, num_groups); + return hash_combine(seed, epsilon); + } + + bool operator==(const primitive& rhs) const override { + if (!compare_common_params(rhs)) + return false; + + const auto& rhs_casted = downcast(rhs); + + return num_groups == rhs_casted.num_groups && epsilon == rhs_casted.epsilon; + } + + void save(BinaryOutputBuffer& ob) const override { + primitive_base::save(ob); + ob << num_groups; + ob << epsilon; + } + + void load(BinaryInputBuffer& ib) override { + primitive_base::load(ib); + ib >> num_groups; + ib >> epsilon; + } +}; + +} // namespace cldnn diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/loop.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/loop.hpp index c27a88e1975f1c..282147cc9e9d3d 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/primitives/loop.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/loop.hpp @@ -7,8 +7,8 @@ #include #include "primitive.hpp" #include "intel_gpu/graph/topology.hpp" +#include "intel_gpu/graph/program.hpp" -#define DEFAULT_MAX_NUM_ITERATION 256 namespace cldnn { /// @@ -53,18 +53,35 @@ struct loop : public primitive_base { CLDNN_DECLARE_PRIMITIVE(loop) loop() : primitive_base("", {}), - max_iteration(0) {} + max_num_iterations(0) {} struct io_primitive_map { /// @brief Constructs a mapping from external input/output primitive to input/output primitive in body topology - /// + /// or a mapping from output of body topology to input of body topology for the next iteration. + /// @param external_id Primitive id of input of loop or output of body network. + /// @param internal_id Primitive id of input of body network. + /// @param axis Axis to iterate through. Negative value means the axis will not iterate through and start, end, stride arguments will be ignored. + /// @param start Index where the iteration starts from. Applies only when axis >=0. + /// @param end Index where iteration ends. Negative value means counting indexes from the end. Applies only when axis >=0. + /// @param stride Step of iteration. Negative value means backward iteration. Applies only when axis >=0. + io_primitive_map(primitive_id external_id, primitive_id internal_id, + int64_t axis = -1, int64_t start = 0, int64_t end = -1, int64_t stride = 1) : + external_id(external_id, 0), + internal_id(internal_id, 0), + axis(axis), + start(start), + end(end), + stride(stride) {} + + /// @brief Constructs a mapping from external input/output primitive to input/output primitive in body topology + /// or a mapping from output of body topology to input of body topology for the next iteration. /// @param external_id Primitive id of input of loop or output of body network. /// @param internal_id Primitive id of input of body network. /// @param axis Axis to iterate through. Negative value means the axis will not iterate through and start, end, stride arguments will be ignored. /// @param start Index where the iteration starts from. Applies only when axis >=0. /// @param end Index where iteration ends. Negative value means counting indexes from the end. Applies only when axis >=0. /// @param stride Step of iteration. Negative value means backward iteration. Applies only when axis >=0. - io_primitive_map(primitive_id external_id = "", primitive_id internal_id = "", + io_primitive_map(input_info external_id = input_info(), input_info internal_id = input_info(), int64_t axis = -1, int64_t start = 0, int64_t end = -1, int64_t stride = 1) : external_id(std::move(external_id)), internal_id(std::move(internal_id)), @@ -73,8 +90,8 @@ struct loop : public primitive_base { end(end), stride(stride) {} - primitive_id external_id; - primitive_id internal_id; + input_info external_id; + input_info internal_id; int64_t axis; int64_t start; int64_t end; @@ -125,68 +142,69 @@ struct loop : public primitive_base { /// /// @param id This primitive id. /// @param inputs Input data primitive ids. - /// @param body Topology to be recurrently executed. + /// @param body_program body program to be recurrently executed. /// @param trip_count_id Data primitive id in external topology specifying maximum number of iterations. /// Its data primitive should have 1 integer element. Negative value means infinite /// number of iteration. - /// @param initial_condition_id Data primitive id in external topology specifying initial execution + /// @param first_execution_condition_id Data primitive id in external topology specifying initial execution /// condition. Its data primitive should have 1 integer element. Zero means /// loop will not be executed, otherwise loop will be executed. /// @param num_iteration_id mutable_data primitive id to get the actual number of loop iterations. - /// @param current_iteration_id Optional data primitive id in the body network to specify current iteration. - /// If current_iteration_id is specified but body does not have data whose primitive - /// id is same as current_iteration_id, data primitive will be added in the body network. - /// @param condition_id Optional data primitive id in the body network to specify execution condition + /// @param body_current_iteration_id Optional data primitive id in the body network to specify current iteration. + /// If body_current_iteration_id is specified but body does not have data whose primitive + /// id is same as body_current_iteration_id, data primitive will be added in the body network. + /// @param body_execution_condition_id Optional data primitive id in the body network to specify execution condition /// for the next iteration. Its data primitive should have 1 integer element. Zero means - /// loop will not be executed, otherwise loop will be executed. If condition_id - /// is specified but body does not have data whose primitive id is same as condition_id, + /// loop will not be executed, otherwise loop will be executed. If body_execution_condition_id + /// is specified but body does not have data whose primitive id is same as body_execution_condition_id, /// data primitive will be added in the body network. /// @param primitive_map Rules to map input of loop or output of body topology to input of the body topology /// @param back_edges Output data primitive id. /// @param output_padding Optional padding for output from primitive. loop(const primitive_id& id, const std::vector& inputs, - const topology& body, + const program::ptr body_program, const primitive_id& trip_count_id, - const primitive_id& initial_condition_id, + const primitive_id& first_execution_condition_id, const primitive_id& num_iteration_id, const std::vector& input_primitive_maps, const std::vector& output_primitive_maps, const std::vector& back_edges, - int64_t max_iteration = -1, - const primitive_id& current_iteration_id = primitive_id(), - const primitive_id& condition_id = primitive_id(), - const padding& output_padding = padding()) - : primitive_base(id, inputs, {output_padding}), - body(body), + int64_t max_num_iterations = -1, + const primitive_id& body_current_iteration_id = primitive_id(), + const primitive_id& body_execution_condition_id = primitive_id(), + const size_t num_outputs = 1) + : primitive_base(id, inputs, {padding()}, {optional_data_type()}, num_outputs), + body_program(std::move(body_program)), trip_count_id(trip_count_id), - initial_execution_id(initial_condition_id), + first_execution_condition_id(first_execution_condition_id), num_iteration_id(num_iteration_id), - current_iteration_id(current_iteration_id), - condition_id(condition_id), + body_current_iteration_id(body_current_iteration_id), + body_execution_condition_id(body_execution_condition_id), input_primitive_maps(input_primitive_maps), output_primitive_maps(output_primitive_maps), back_edges(back_edges), - max_iteration(max_iteration) - {} + max_num_iterations(max_num_iterations) { + OPENVINO_ASSERT(inputs.front().pid == num_iteration_id, "first input of inputs should be num_iteration_id"); + } - /// @brief Topology to be recurrently executed. - topology body; + /// @brief Body program to be recurrently executed. + program::ptr body_program; /// @brief Data primitive id in external topology specifying maximum number of iterations. primitive_id trip_count_id; /// @brief Data primitive id in external topology specifying initial execution condition. - primitive_id initial_execution_id; + primitive_id first_execution_condition_id; /// @brief mutable_data primitive id to get the actual number of loop iterations. primitive_id num_iteration_id; /// @brief Data primitive id in the body network to store current iteration - primitive_id current_iteration_id; + primitive_id body_current_iteration_id; /// @brief Data primitive id in the body network to store execution condition - primitive_id condition_id; + primitive_id body_execution_condition_id; /// @brief Rules to map input or output data of loop layer onto input or output data of body topology. std::vector input_primitive_maps; @@ -195,7 +213,7 @@ struct loop : public primitive_base { /// @brief Rules to transfer data from body outputs at one iteration to body input at the next iteration. std::vector back_edges; - int64_t max_iteration; + int32_t max_num_iterations; size_t hash() const override { size_t seed = primitive::hash(); @@ -206,42 +224,43 @@ struct loop : public primitive_base { void save(BinaryOutputBuffer& ob) const override { primitive_base::save(ob); ob << trip_count_id; - ob << initial_execution_id; + ob << first_execution_condition_id; ob << num_iteration_id; - ob << current_iteration_id; - ob << condition_id; + ob << body_current_iteration_id; + ob << body_execution_condition_id; ob << input_primitive_maps; ob << output_primitive_maps; ob << back_edges; - ob << max_iteration; + ob << max_num_iterations; } void load(BinaryInputBuffer& ib) override { primitive_base::load(ib); ib >> trip_count_id; - ib >> initial_execution_id; + ib >> first_execution_condition_id; ib >> num_iteration_id; - ib >> current_iteration_id; - ib >> condition_id; + ib >> body_current_iteration_id; + ib >> body_execution_condition_id; ib >> input_primitive_maps; ib >> output_primitive_maps; ib >> back_edges; - ib >> max_iteration; + ib >> max_num_iterations; } protected: std::vector> get_dependencies() const override { - std::vector> ret{ - std::ref(trip_count_id), std::ref(initial_execution_id), std::ref(num_iteration_id) - }; + std::vector> ret; + ret.push_back(std::ref(num_iteration_id)); + if (!trip_count_id.empty()) ret.push_back(std::ref(trip_count_id)); + if (!first_execution_condition_id.empty()) ret.push_back(std::ref(first_execution_condition_id)); + // add external_id in dependencies if not exist for (const auto& mapping : input_primitive_maps) { auto target = std::find_if(input.begin(), input.end(), - [&](const input_info& info) { - return info.pid == mapping.external_id; - }); + [&](const input_info& info) { + return info.pid == mapping.external_id.pid;}); if (target == input.end()) { - ret.push_back(std::ref(mapping.external_id)); + ret.push_back(std::ref(mapping.external_id.pid)); } } return ret; diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/primitive.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/primitive.hpp index bc55ed80e4f362..72c841a7578ab4 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/primitives/primitive.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/primitive.hpp @@ -70,8 +70,19 @@ struct input_info { ib >> pid; ib >> idx; } + + std::string to_string() const { + std::stringstream ss; + ss << "input_info(pid:" << pid << ",idx:" << idx << ")"; + return ss.str(); + } }; +static inline std::ostream& operator<< (std::ostream& os, input_info& info) { + os << info.to_string(); + return os; +} + struct prim_map_storage { static prim_map_storage& instance() { static prim_map_storage instance; diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/rms.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/rms.hpp new file mode 100644 index 00000000000000..cf2ad7af502da9 --- /dev/null +++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/rms.hpp @@ -0,0 +1,58 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once +#include "primitive.hpp" + +namespace cldnn { + +/// @brief Root Mean Square Normalization primitive +/// @details Performs re-scaling invariance and regularizes the summed input according to RMS statistics +struct rms : public primitive_base { + CLDNN_DECLARE_PRIMITIVE(rms); + + rms() : primitive_base("", {}) {} + + /// @brief Constructs rms primitive + /// @param id This primitive id + /// @param input Input primitive id + /// @param gamma Gamma values for weight + /// @param epsilon Epsilon for not dividing by zero while normalizing + rms(const primitive_id& id, + const input_info& input, + const input_info& gamma, + const float epsilon, + const padding& output_padding = padding()) + : primitive_base(id, {input, gamma}, {output_padding}), + epsilon(epsilon) {} + + /// @brief Epsilon for not dividing by zero while normalizing + float epsilon; + + size_t hash() const override { + size_t seed = primitive::hash(); + seed = hash_combine(seed, epsilon); + return seed; + } + + bool operator==(const primitive& rhs) const override { + if (!compare_common_params(rhs)) + return false; + + auto rhs_casted = downcast(rhs); + + return epsilon == rhs_casted.epsilon; + } + + void save(BinaryOutputBuffer& ob) const override { + primitive_base::save(ob); + ob << epsilon; + } + + void load(BinaryInputBuffer& ib) override { + primitive_base::load(ib); + ib >> epsilon; + } +}; +} // namespace cldnn diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/format.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/format.hpp index fb6bfaa3fc8224..ea3e2aec0274d0 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/runtime/format.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/format.hpp @@ -90,6 +90,8 @@ struct format { b_fs_zyx_fsv2, b_fs_yx_fsv4, ///< format for input for IMAD convolutions b_fs_zyx_fsv4, ///< format for input for IMAD 3D convolutions + b_fs_yx_fsv8, + b_fs_zyx_fsv8, b_fs_yx_fsv16, ///< format used for blocked convolution b_fs_yx_fsv32, ///< format used for blocked int8 convolution b_fs_zyx_fsv16, ///< format used for 3D blocked convolution (features blocked by 16) @@ -107,6 +109,8 @@ struct format { bs_fs_zyx_bsv8_fsv2, ///< format used for 3D blocked convolution (batch and features blocked by 8 and 2) bs_fs_yx_bsv16_fsv2, ///< format used for 2D blocked convolution (batch and features blocked by 16 and 2) bs_fs_zyx_bsv16_fsv2, ///< format used for 3D blocked convolution (batch and features blocked by 16 and 2) + bs_fs_yx_bsv16_fsv8, ///< format used for 2D blocked convolution (batch and features blocked by 16 and 8) + bs_fs_zyx_bsv16_fsv8, ///< format used for 3D blocked convolution (batch and features blocked by 16 and 8) bs_fs_yx_bsv4_fsv2, ///< format used for 2D blocked convolution (batch blocked by 4, features blocked by 2) bs_fs_zyx_bsv4_fsv4, ///< format used for 3D blocked convolution (batch and features blocked by 4) bs_fs_zyx_bsv4_fsv2, ///< format used for 3D blocked convolution (batch blocked by 4, features blocked by 2) @@ -135,7 +139,10 @@ struct format { oyix, oxiy, os_iyx_osv16, ///< format used only for convolution weights + o_is_yx_isv2, ///< format used only for convolution weights + o_is_yx_isv4, ///< format used only for convolution weights o_is_yx_isv16, ///< format used only for convolution weights + o_is_zyx_isv16, ///< format used only for convolution weights os_yxi_osv16, ///< format used only for convolution weights os_is_yx_osv16_isv2, ///< format used only for convolution weights os_is_yx_osv16_isv16, ///< format used for convolution i8 weights @@ -145,6 +152,7 @@ struct format { os_is_yx_isv16_osv16, ///< format used for blocked convolution os_is_zyx_isv16_osv16, ///< format used for weights for blocked 3D convolution is_os_zyx_isv16_osv16, ///< format used for weights for blocked 3D deconvolution + is_os_yx_osv8_isv4, ///< format used for weights for blocked deconvolution is_os_yx_isv16_osv16, ///< format used for weights for blocked deconvolution is_os_yx_isv16_osv8, ///< format used for weights for blocked deconvolution is_os_yx_isv16_osv4, ///< format used for weights for blocked deconvolution @@ -232,6 +240,8 @@ struct format { os_zyx_is_osv8_isv4, os_zy_is_x_osv8_isv2, os_zy_is_x_osv8_isv4, + os_is_yx_osv4_isv16, + os_is_yx_osv2_isv16, goiyx, ///< format used for weights for 2D convolution gioyx, ///< format used for weights for 2D deconvolution @@ -241,7 +251,9 @@ struct format { g_os_iyx_osv8, ///< format used for weights for 2D convolution g_os_iyx_osv16, ///< format used for weights for 2D convolution g_os_iyx_osv32, ///< format used for weights for 2D convolution + gs_oiyx_gsv8, ///< format used for weights for 2D convolution gs_oiyx_gsv16, ///< format used for weights for 2D convolution + gs_oizyx_gsv8, ///< format used for weights for 3D convolution gs_oizyx_gsv16, ///< format used for weights for 3D convolution gs_oiyx_gsv32, ///< format used for weights for 2D convolution gs_oizyx_gsv32, ///< format used for weights for 3D convolution diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/layout.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/layout.hpp index 3dad0cea4e008b..679f4c51ea6881 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/runtime/layout.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/layout.hpp @@ -13,10 +13,10 @@ #include #include #include -#include -#include -#include +#include "openvino/core/partial_shape.hpp" +#include "openvino/core/type/element_type.hpp" +#include "openvino/core/type/element_type_traits.hpp" #include "intel_gpu/graph/serialization/binary_buffer.hpp" #include "intel_gpu/graph/serialization/vector_serializer.hpp" @@ -28,33 +28,9 @@ namespace cldnn { /// @addtogroup cpp_memory Memory description and management /// @{ -constexpr size_t float_type_mask = 0x80; -constexpr size_t uint_type_mask = 0x40; -constexpr size_t bin_type_mask = 0x20; - /// @brief Possible data types could be stored in memory. using data_types = ov::element::Type_t; -/// Converts @ref data_types to C++ type. -template -struct data_type_to_type; -#ifndef DOXYGEN_SHOULD_SKIP_THIS -template <> -struct data_type_to_type { typedef uint32_t type; }; -template <> -struct data_type_to_type { typedef uint8_t type; }; -template <> -struct data_type_to_type { typedef int8_t type; }; -template <> -struct data_type_to_type { typedef int32_t type; }; -template <> -struct data_type_to_type { typedef int64_t type; }; -template <> -struct data_type_to_type { typedef ov::float16 type; }; -template <> -struct data_type_to_type { typedef float type; }; -#endif - /// Helper class to identify key properties for data_types. struct data_type_traits { static size_t size_of(data_types data_type) { @@ -72,52 +48,27 @@ struct data_type_traits { return et.is_quantized() && et.bitwidth() == 8; } - static size_t align_of(data_types data_type) { - switch (data_type) { - case data_types::u1: - return alignof(data_type_to_type::type); - case data_types::i8: - return alignof(data_type_to_type::type); - case data_types::u8: - return alignof(data_type_to_type::type); - case data_types::i32: - return alignof(data_type_to_type::type); - case data_types::i64: - return alignof(data_type_to_type::type); - case data_types::f16: - return alignof(data_type_to_type::type); - case data_types::f32: - return alignof(data_type_to_type::type); - default: - return size_t(1); - } - } - - static std::string name(data_types data_type) { - return ov::element::Type(data_type).get_type_name(); - } + static ov::element::Type max_type(ov::element::Type t1, ov::element::Type t2) { + if (t1 == ov::element::u1) + return t2; - static data_types max_type(data_types dt1, data_types dt2) { - if (dt1 == data_types::u1) - return dt2; + if (t2 == ov::element::u1) + return t1; - if (dt2 == data_types::u1) - return dt1; + if (t1.bitwidth() < t2.bitwidth()) + return t2; - if (size_of(dt1) < size_of(dt2)) - return dt2; + if (t1.bitwidth() > t2.bitwidth()) + return t1; - if (size_of(dt1) > size_of(dt2)) - return dt1; + if (t2.is_real()) + return t2; - if (is_floating_point(dt2)) - return dt2; - - return dt1; + return t1; } - static bool is_quantized(data_types dt) { - return is_i8_u8(dt); + static bool is_quantized(ov::element::Type t) { + return t.is_quantized(); } template @@ -132,7 +83,7 @@ struct data_type_traits { case data_types::i64: return static_cast(std::numeric_limits::max()); case data_types::f16: - return static_cast(65504); + return static_cast(std::numeric_limits::max()); case data_types::f32: return static_cast(std::numeric_limits::max()); default: @@ -152,7 +103,7 @@ struct data_type_traits { case data_types::i64: return static_cast(std::numeric_limits::lowest()); case data_types::f16: - return static_cast(-65504); + return static_cast(std::numeric_limits::lowest()); case data_types::f32: return static_cast(std::numeric_limits::lowest()); default: @@ -170,44 +121,17 @@ inline data_types element_type_to_data_type(ov::element::Type t) { switch (t) { case ov::element::Type_t::i16: case ov::element::Type_t::u16: - case ov::element::Type_t::f32: case ov::element::Type_t::f64: return cldnn::data_types::f32; - case ov::element::Type_t::f16: - return cldnn::data_types::f16; - case ov::element::Type_t::u8: - return cldnn::data_types::u8; - case ov::element::Type_t::i8: - return cldnn::data_types::i8; - case ov::element::Type_t::i32: case ov::element::Type_t::u32: case ov::element::Type_t::u64: return cldnn::data_types::i32; - case ov::element::Type_t::i64: - return cldnn::data_types::i64; case ov::element::Type_t::boolean: return cldnn::data_types::u8; - case ov::element::Type_t::u1: - return cldnn::data_types::u1; - default: - throw std::runtime_error("Can't convert " + t.get_type_name() + " element type"); + default: return t; } } -/// Helper function to get both data_types and format::type in a single, unique value. Useable in 'case' statement. -constexpr auto fuse(data_types dt, cldnn::format::type fmt) -> decltype(static_cast::type>(dt) | - static_cast::type>(fmt)) { - using dt_type = std::underlying_type::type; - using fmt_type = std::underlying_type::type; - using fmt_narrow_type = int16_t; - - return static_cast(fmt) <= std::numeric_limits::max() && - static_cast(dt) <= (std::numeric_limits::max() >> (sizeof(fmt_narrow_type) * 8)) - ? (static_cast(dt) << (sizeof(fmt_narrow_type) * 8)) | - (static_cast(fmt) >= 0 ? static_cast(fmt) : static_cast(-1)) - : throw std::invalid_argument("data_type and/or format values are too big to be fused into single value"); -} - /// @brief Represents data padding information. struct padding { /// @brief Filling value for padding area. diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/shape_predictor.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/shape_predictor.hpp index 2f2e614c29f2c6..51f09989502a13 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/runtime/shape_predictor.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/shape_predictor.hpp @@ -50,7 +50,7 @@ struct ShapePredictor { /// says if shape is successfully predicted and can be preallocated, and the second element is ov::Shape itself. std::pair predict_preallocation_shape(const std::string& id, const ov::Shape& current_shape, - size_t dt_size, + size_t dt_bitwidth, bool can_reuse_buffer); bool can_preallocate(size_t desired_buffer_size); diff --git a/src/plugins/intel_gpu/src/graph/CMakeLists.txt b/src/plugins/intel_gpu/src/graph/CMakeLists.txt index 67a0a3282cda13..731b580718ea84 100644 --- a/src/plugins/intel_gpu/src/graph/CMakeLists.txt +++ b/src/plugins/intel_gpu/src/graph/CMakeLists.txt @@ -61,7 +61,7 @@ endif() ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE}) if(ENABLE_SSE42) - ie_sse42_optimization_flags(sse4_2_flags) + ov_sse42_optimization_flags(sse4_2_flags) set_source_files_properties(impls/cpu/detection_output.cpp PROPERTIES COMPILE_FLAGS "${sse4_2_flags}" COMPILE_DEFINITIONS "HAVE_SSE") diff --git a/src/plugins/intel_gpu/src/graph/condition.cpp b/src/plugins/intel_gpu/src/graph/condition.cpp index 842495e0b24e0d..8da80347ea66fd 100644 --- a/src/plugins/intel_gpu/src/graph/condition.cpp +++ b/src/plugins/intel_gpu/src/graph/condition.cpp @@ -215,7 +215,7 @@ std::string condition_inst::to_string(condition_node const& node) { } /* -Condition primitive is resuing memory with the input. +Condition primitive is reusing memory with the input. */ condition_inst::typed_primitive_inst(network& network, condition_node const& node) : parent(network, node), diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/compile_graph.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/compile_graph.cpp index 537fa7412b09f5..9c3eb7c813045d 100644 --- a/src/plugins/intel_gpu/src/graph/graph_optimizer/compile_graph.cpp +++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/compile_graph.cpp @@ -14,6 +14,7 @@ #include "arg_max_min_inst.h" #include "fully_connected_inst.h" #include "condition_inst.h" +#include "loop_inst.h" #include "program_node.h" #include @@ -74,7 +75,7 @@ void compile_graph::run(program& p) { if (node->is_dynamic() && !is_planar) can_select_impl = false; - if (node->is_type() || node->is_type()) + if (node->is_type() || node->is_type() || node->is_type()) can_select_impl = true; if (can_select_impl) { diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/concat_input_order.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/concat_input_order.cpp index 1f2016e8d6706e..de6d6c62859bd9 100644 --- a/src/plugins/intel_gpu/src/graph/graph_optimizer/concat_input_order.cpp +++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/concat_input_order.cpp @@ -23,6 +23,8 @@ bool can_shuffle_features(program_node& node, stream& stream) { if (node.is_type()) { auto& conv_node = node.as(); auto& wei_node = conv_node.weights(); + if (ov::element::Type(wei_node.get_output_layout().data_type).bitwidth() < 8) + return false; return conv_node.get_groups() == 1 && conv_node.get_deformable_groups() == 1 && !conv_node.get_transposed() && @@ -32,6 +34,8 @@ bool can_shuffle_features(program_node& node, stream& stream) { if (node.is_type()) { auto& fc_node = node.as(); auto& wei_node = fc_node.weights(); + if (ov::element::Type(wei_node.get_output_layout().data_type).bitwidth() < 8) + return false; return wei_node.is_type() && wei_node.is_constant() && !wei_node.is_output(); } diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/graph_initializations.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/graph_initializations.cpp index 8a031e45582314..cf9f44a9a59686 100644 --- a/src/plugins/intel_gpu/src/graph/graph_optimizer/graph_initializations.cpp +++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/graph_initializations.cpp @@ -402,6 +402,7 @@ void graph_initializations::set_outputs(program& p) { auto custom_outputs = p.get_config().get_property(ov::intel_gpu::custom_outputs); if (!custom_outputs.empty()) { for (auto const& output : custom_outputs) { + OPENVINO_ASSERT(p.has_node(output), "not found custom output node in current cldnn::program: ", output); auto o_node = p.get_node_ptr(output); o_node->set_output(true); p.outputs.push_back(o_node.get()); diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_primitive_fusing.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_primitive_fusing.cpp index d50d306700b902..cc9d8602316fa5 100644 --- a/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_primitive_fusing.cpp +++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_primitive_fusing.cpp @@ -1221,8 +1221,11 @@ void prepare_primitive_fusing::fuse_constant_transposes(program& p) { return format::find_format(new_order, fmt.block_sizes()); }; - auto itr = p.get_processing_order().begin(); - while (itr != p.get_processing_order().end()) { + std::vector> to_replace_nodes; + + auto& proc_order = p.get_processing_order(); + auto itr = proc_order.begin(); + while (itr != proc_order.end()) { auto& node = *itr++; if (!node->is_type()) @@ -1271,6 +1274,35 @@ void prepare_primitive_fusing::fuse_constant_transposes(program& p) { p.replace(prev_const, new_const_node); new_const_node.recalc_output_layout(false); + + // Add format reorder in case of onednn to avoid overhead during execution on weights memory allocation + if (_lo.get_preferred_impl_type(const_cast(*weightable_node), format::any /*dummy*/) == impl_types::onednn) { + auto next_node = new_const_node.get_users().front(); + bool can_be_fused = next_node->is_type() && + next_node->as().is_simple_reorder() && + next_node->get_users().size() == 1; + if (can_be_fused) { + layout reorder_layout = next_node->get_output_layout(); + reorder_layout.format = format::bfyx; + + auto new_reorder = std::make_shared(next_node->id() + "_reorder_fmt", new_const_node.id(), reorder_layout); + auto& new_reorder_node = p.get_or_create(new_reorder); + to_replace_nodes.emplace_back(std::make_pair(next_node, &new_reorder_node)); + } else { + layout reorder_layout = new_const_node.get_output_layout(); + reorder_layout.format = format::bfyx; + + auto new_reorder = std::make_shared(new_const_node.id() + "_reorder_fmt", new_const_node.id(), reorder_layout); + auto& new_reorder_node = p.get_or_create(std::move(new_reorder)); + p.add_intermediate(new_reorder_node, *new_const_node.get_users().front(), new_const_node); + new_reorder_node.recalc_output_layout(false); + } + } + } + + for (auto& nodes : to_replace_nodes) { + p.replace(*nodes.first, *nodes.second); + nodes.second->recalc_output_layout(false); } } diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_quantization.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_quantization.cpp index d1b125aa8f1df5..f55d99b6a5fa80 100644 --- a/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_quantization.cpp +++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_quantization.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "fully_connected_inst.h" #include "pooling_inst.h" #include "quantize_inst.h" #include "reorder_inst.h" @@ -847,6 +848,42 @@ bool prepare_quantization::optimize_quantize(program &p, quantize_node& quantize return true; } +static void optimize_weights_decompression_parameters(fully_connected_node& fc_node, program& p) { + auto fc_prim = fc_node.get_primitive(); + if (!fc_prim->compressed_weights) + return; + + auto reorder_bfyx_to_fbyx = [&](size_t dep_id) { + auto& dep = fc_node.get_dependency(dep_id); + auto target_layout = dep.get_output_layout(); + target_layout.format = format::fbyx; + auto reorder_prim = std::make_shared(dep.id() + "_reorder", dep.id(), target_layout); + p.add_intermediate(reorder_prim, fc_node, dep_id, true); + fc_node.get_dependency(dep_id).recalc_output_layout(false); + }; + + auto need_reorder = [&](size_t dep_id) { + auto dep_layout = fc_node.get_input_layout(dep_id); + auto dep_pshape = dep_layout.get_partial_shape(); + + auto groups_count = dep_pshape[dep_pshape.size() - 1].get_length(); + + return groups_count > 1; + }; + + auto decompression_scale_idx = !fc_node.bias_term() ? 2 : 3; + if (need_reorder(decompression_scale_idx)) { + reorder_bfyx_to_fbyx(decompression_scale_idx); + } + + if (!fc_prim->decompression_zero_point.empty()) { + auto decompression_zp_idx = decompression_scale_idx + 1; + if (need_reorder(decompression_zp_idx)) { + reorder_bfyx_to_fbyx(decompression_zp_idx); + } + } +} + void prepare_quantization::run(program& p) { auto itr = p.get_processing_order().begin(); while (itr != p.get_processing_order().end()) { @@ -859,6 +896,8 @@ void prepare_quantization::run(program& p) { remove_fake_reorders(p, node->as()); } else if (node->is_type()) { prepare_asymmetric_quantization(p, node->as()); + } else if (node->is_type()) { + optimize_weights_decompression_parameters(node->as(), p); } } } diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/reorder_inputs.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/reorder_inputs.cpp index 094e645a69e05f..769134e440b848 100644 --- a/src/plugins/intel_gpu/src/graph/graph_optimizer/reorder_inputs.cpp +++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/reorder_inputs.cpp @@ -121,15 +121,10 @@ struct travel_direction_wrapper { static format get_target_output_format(layout_optimizer& lo, const std::map& fmt_map, program_node *node, program_node *next) { auto user_idx = node->get_user_index(*next); - bool allow_new_shape_infer = node->get_program().get_config().get_property(ov::intel_gpu::allow_new_shape_infer); // 1. Check selected preferred_output_format - if (lo.get_optimization_attributes().use_onednn_impls || allow_new_shape_infer) { - // If onednn is not used, need to ignore get_preferred_output_fmt result as it is from onednn - auto ret = node->get_preferred_output_fmt(user_idx); - - if (ret != format::any) - return ret; - } + auto ret = node->get_preferred_output_fmt(user_idx); + if (ret != format::any) + return ret; // 2. Check fmt if (fmt_map.count(node) > 0) @@ -142,14 +137,10 @@ static format get_target_output_format(layout_optimizer& lo, const std::map& fmt_map, program_node *node, program_node *prev) { auto dep_idx = node->get_dependency_index(*prev); - bool allow_new_shape_infer = node->get_program().get_config().get_property(ov::intel_gpu::allow_new_shape_infer); // 1. Check selected preferred_input_format - if (lo.get_optimization_attributes().use_onednn_impls || allow_new_shape_infer) { - // If onednn is not used, need to ignore get_preferred_input_fmt result as it is from onednn - auto ret = node->get_preferred_input_fmt(dep_idx); - if (ret != format::any) - return ret; - } + auto ret = node->get_preferred_input_fmt(dep_idx); + if (ret != format::any) + return ret; // 2. Check fmt if (fmt_map.count(node) > 0) diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/select_preferred_formats.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/select_preferred_formats.cpp index 05dacd336a43f5..8b2b3a118a501f 100644 --- a/src/plugins/intel_gpu/src/graph/graph_optimizer/select_preferred_formats.cpp +++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/select_preferred_formats.cpp @@ -32,11 +32,21 @@ void select_preferred_formats::run(program& p) { return; #ifdef ENABLE_ONEDNN_FOR_GPU + auto forcing_map = _lo.get_implementation_forcing(); + engine.create_onednn_engine(p.get_config()); for (auto n : p.get_processing_order()) { - if (n->is_input() || !_lo.are_data_types_suitable_for_onednn(*n)) { + if (n->is_input() || !layout_optimizer::is_node_suitable_for_onednn(*n)) { continue; } + + // skip to set preferred_formats if forcing_impl is not onednn. + if (std::find_if(forcing_map.begin(), forcing_map.end(), + [&n](std::map>::value_type const& it) { + return (it.first == n->id() && it.second.second != impl_types::onednn); + }) != forcing_map.end()) + continue; + // Onednn primitive descriptor creation may fail, for example, due to asymmetric weight. try { if (n->is_type()) { diff --git a/src/plugins/intel_gpu/src/graph/group_normalization.cpp b/src/plugins/intel_gpu/src/graph/group_normalization.cpp new file mode 100644 index 00000000000000..69b06343362570 --- /dev/null +++ b/src/plugins/intel_gpu/src/graph/group_normalization.cpp @@ -0,0 +1,42 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "group_normalization_inst.h" +#include "primitive_type_base.h" +#include "json_object.h" + +namespace cldnn { +GPU_DEFINE_PRIMITIVE_TYPE_ID(group_normalization) + +layout group_normalization_inst::calc_output_layout(group_normalization_node const& node, kernel_impl_params const& impl_param) { + assert(static_cast(impl_param.desc->output_data_types[0]) == false && + "Output data type forcing is not supported for group_normalization_node!"); + auto output_layout = impl_param.get_input_layout(); + + if (impl_param.has_fused_primitives()) + output_layout.data_type = impl_param.get_fused_output_layout().data_type; + + return output_layout; +} + +std::string group_normalization_inst::to_string(group_normalization_node const& node) { + auto desc = node.get_primitive(); + auto node_info = node.desc_to_json(); + + std::stringstream primitive_description; + + json_composite group_normalization_info; + group_normalization_info.add("dimension", desc->num_groups); + group_normalization_info.add("epsilon", desc->epsilon); + + node_info->add("group_normalization_info", group_normalization_info); + node_info->dump(primitive_description); + + return primitive_description.str(); +} + +group_normalization_inst::typed_primitive_inst(network& network, group_normalization_node const& node) : parent(network, node) { +} + +} // namespace cldnn diff --git a/src/plugins/intel_gpu/src/graph/impls/common/loop.cpp b/src/plugins/intel_gpu/src/graph/impls/common/loop.cpp index 81f244051a25aa..b774b72dd506ec 100644 --- a/src/plugins/intel_gpu/src/graph/impls/common/loop.cpp +++ b/src/plugins/intel_gpu/src/graph/impls/common/loop.cpp @@ -12,6 +12,77 @@ namespace cldnn { namespace common { + +// read scala value from data primitive +static int64_t read_scalar_value(memory::ptr mem, stream& stream) { + int64_t trip_count = 0; + const layout& prim_layout = mem->get_layout(); + + switch (prim_layout.data_type) { + case data_types::u8: { + mem_lock lock_prim_output{mem, stream}; + trip_count = *lock_prim_output.data(); + break; + } + case data_types::i8: { + mem_lock lock_prim_output{mem, stream}; + trip_count = *lock_prim_output.data(); + break; + } + case data_types::i32: { + mem_lock lock_prim_output{mem, stream}; + trip_count = *lock_prim_output.data(); + break; + } + case data_types::i64: { + mem_lock lock_prim_output{mem, stream}; + trip_count = *lock_prim_output.data(); + break; + } + default: + OPENVINO_THROW("Invalid data type : ", ov::element::Type(prim_layout.data_type).get_type_name()); + } + return trip_count; +} + +template +static inline void validate_input_value(int64_t input) { + OPENVINO_ASSERT((input >= std::numeric_limits::min() && input <= std::numeric_limits::max()), + "Invalid data value : ", input); +} + +static void write_scalar_value(memory::ptr mem, stream& stream, int64_t input) { + const layout& prim_layout = mem->get_layout(); + + switch (prim_layout.data_type) { + case data_types::u8: { + validate_input_value(input); + mem_lock lock_prim_output{mem, stream}; + lock_prim_output[0] = static_cast(input); + break; + } + case data_types::i8: { + validate_input_value(input); + mem_lock lock_prim_output{mem, stream}; + lock_prim_output[0] = static_cast(input); + break; + } + case data_types::i32: { + validate_input_value(input); + mem_lock lock_prim_output{mem, stream}; + lock_prim_output[0] = static_cast(input); + break; + } + case data_types::i64: { + mem_lock lock_prim_output{mem, stream}; + lock_prim_output[0] = input; + break; + } + default: + OPENVINO_THROW("Invalid data type : ", ov::element::Type(prim_layout.data_type).get_type_name()); + } +} + struct loop_impl : typed_primitive_impl { using parent = typed_primitive_impl; using parent::parent; @@ -27,7 +98,6 @@ struct loop_impl : typed_primitive_impl { loop_impl() : parent() {} loop_impl(const loop_impl& other) : typed_primitive_impl(other), - _max_iteration(other._max_iteration), _back_edges(other._back_edges) {} explicit loop_impl(const loop_node& node) { @@ -37,63 +107,169 @@ struct loop_impl : typed_primitive_impl { void set_node_params(const program_node& arg) override { OPENVINO_ASSERT(arg.is_type()); const auto& node = arg.as(); - _max_iteration = node.get_max_iteration(); _back_edges = node.get_back_edges(); } + void set_memory_in_body_network(cldnn::network::ptr body_network, + const std::shared_ptr& inst, memory::ptr mem) const { + if (inst->is_input()) { + body_network->set_input_data(inst->id(), mem); + } else if (inst->is_output()) { + body_network->set_output_memory(inst->id(), mem); + } else { + inst->set_output_memory(mem, false); + } + } + + std::vector handle_buffers_for_next_iteration(const loop_inst::backedge_memory_mapping& mapping, + network::ptr body_network, int64_t iter, bool is_dynamic) const { + std::vector event_vec; + OPENVINO_ASSERT(iter >= 0, "iteration should not be negative : ", iter); + if (mapping.type == loop_inst::backedge_memory_mapping::CONCAT_OUTPUT) { + if (iter == 0) { + set_memory_in_body_network(body_network, mapping.to_primitive, mapping.initial_mem); + } else if (iter > 0) { + if (is_dynamic) { + auto from_id = mapping.from_primitive->id(); + if (body_network->has_event(from_id)) { + auto ev = body_network->get_primitive_event(from_id); + if (ev) ev->wait(); + } + // In dynamic model, just copy data from inner body output to inner body input in back_edges. + memory::ptr mem1 = mapping.to_primitive->output_memory_ptr(); + memory::ptr mem2 = mapping.from_primitive->output_memory_ptr(); + auto ev = mem1->copy_from(body_network->get_stream(), *(mem2)); + if (ev) event_vec = {ev}; + } else { + auto mem = mapping.concat_mem_mapping->get_sliced_mems().at(iter - 1); + set_memory_in_body_network(body_network, mapping.to_primitive, mem); + } + } + } else if (mapping.type == loop_inst::backedge_memory_mapping::SINGLE_SHARED) { + if (iter == 0) { + if (mapping.from_mem != nullptr) { + auto ev = mapping.from_mem->copy_from(body_network->get_stream(), *(mapping.initial_mem)); + if (ev) event_vec = {ev}; + } + } else { + // In dynamic model, output memory is not defined before execution. + // After body network execution, replace input memory from initial_mem(external input memory) to output memory. + if (mapping.from_mem == nullptr) { + mapping.from_mem = mapping.from_primitive->output_memory_ptr(); + OPENVINO_ASSERT(mapping.from_mem != nullptr, "from_mem should not be null"); + set_memory_in_body_network(body_network, mapping.to_primitive, mapping.from_mem); + } + } + } else if (mapping.type == loop_inst::backedge_memory_mapping::SINGLE) { + memory::ptr mem1 = mapping.to_primitive->output_memory_ptr(); + if (iter == 0) { + auto ev = mem1->copy_from(body_network->get_stream(), *(mapping.initial_mem)); + if (ev) event_vec = {ev}; + } else { + if (is_dynamic) { + // In dynamic model, do not set memory buffer between input and output in inner body network. + // Just copy data from input buffer memory to output buffer memory. + auto from_id = mapping.from_primitive->id(); + if (body_network->has_event(from_id)) { + auto ev = body_network->get_primitive_event(from_id); + if (ev) ev->wait(); + } + memory::ptr mem2 = mapping.from_primitive->output_memory_ptr(); + auto ev = mem1->copy_from(body_network->get_stream(), *(mem2)); + if (ev) event_vec = {ev}; + } else { + // In static model, swap memory buffer between output and input in inner body network + memory::ptr mem2 = mapping.from_primitive->output_memory_ptr(); + set_memory_in_body_network(body_network, mapping.to_primitive, std::move(mem2)); + set_memory_in_body_network(body_network, mapping.from_primitive, std::move(mem1)); + } + } + } + return event_vec; + } + event::ptr execute_impl(const std::vector& events, loop_inst& instance) override { - const auto& primitive = instance.get_typed_desc(); + const auto& impl_params = instance.get_impl_params(); + const auto& primitive = impl_params->typed_desc(); auto& outer_network = instance.get_network(); auto& stream = outer_network.get_stream(); + const auto max_num_iterations = primitive->max_num_iterations; auto body_network = instance.get_body_network(); + int64_t current_iteration_idx = 0; auto ev = stream.create_user_event(false); - if (!instance.preproc_memories_done) { - instance.preprocess_output_memory(); - instance.preprocess_input_memory(); - instance.preprocess_backedge_memory(); - - // set input data for current_iteration primitive if current_iteration is used - if (!primitive->current_iteration_id.empty()) { - auto current_iteration_prim = body_network->get_primitive(primitive->current_iteration_id); - auto input_layout_prim = std::dynamic_pointer_cast(current_iteration_prim); - if (input_layout_prim == nullptr) { - CLDNN_ERROR_MESSAGE(instance.id(), "current_iteration primitive is not input_layout"); - } else { - const auto& backedge_mapping = instance.get_current_iteration_backedge_mapping(); - input_layout_prim->set_data(backedge_mapping.initial_mem); - } - } - instance.preproc_memories_done = true; - } + OPENVINO_ASSERT(!primitive->num_iteration_id.empty(), "loop operation should have num_iteration_id"); + ////////////////////////////////////////// + // memory pointers for outer network + ////////////////////////////////////////// // read trip_count from outer network - bool update_num_iterations = false; - memory::ptr trip_count_mem = outer_network.get_primitive(primitive->trip_count_id)->output_memory_ptr(); - int64_t trip_count = loop_node::read_scalar_value(std::move(trip_count_mem), stream); - if (trip_count < 0) { - trip_count = _max_iteration; - update_num_iterations = true; + int64_t trip_count = -1; + if (!primitive->trip_count_id.empty()) { + memory::ptr trip_count_mem = outer_network.get_primitive(primitive->trip_count_id)->output_memory_ptr(); + trip_count = read_scalar_value(std::move(trip_count_mem), stream); + } else { + trip_count = max_num_iterations; } // read initial execution condition from outer network - memory::ptr initial_execution_mem = outer_network.get_primitive(primitive->initial_execution_id)->output_memory_ptr(); - int64_t execution_condition = loop_node::read_scalar_value(initial_execution_mem, stream); + int64_t execution_condition = 1; + if (!primitive->first_execution_condition_id.empty()) { + memory::ptr first_execution_condition_mem = outer_network.get_primitive(primitive->first_execution_condition_id)->output_memory_ptr(); + execution_condition = read_scalar_value(first_execution_condition_mem, stream); + } + + // When execution_condition is false or trip_count is zero, return execute_impl without any body_network execution. + if (!execution_condition || trip_count == 0) { + // Update num_iterations (actual number of iterations) + memory::ptr num_actual_iterations_mem = outer_network.get_primitive(primitive->num_iteration_id)->output_memory_ptr(); + write_scalar_value(num_actual_iterations_mem, stream, current_iteration_idx); + + instance.update_output_layout(); + ev->set(); + return ev; + } + ////////////////////////////////////////// + // memory pointers for body network + ////////////////////////////////////////// // shortcut of execution_condition memory in body network - memory::ptr execution_condition_mem = nullptr; - if (!primitive->condition_id.empty()) { - execution_condition_mem = body_network->get_primitive(primitive->condition_id)->output_memory_ptr(); + memory::ptr body_execution_condition_mem = nullptr; + if (!primitive->body_execution_condition_id.empty()) { + body_execution_condition_mem = body_network->get_primitive(primitive->body_execution_condition_id)->output_memory_ptr(); + } + + // shortcut of current_iteration memory in body network + if (!primitive->body_current_iteration_id.empty()) { + memory::ptr body_current_iteration_mem = body_network->get_primitive(primitive->body_current_iteration_id)->output_memory_ptr(); + write_scalar_value(body_current_iteration_mem, body_network->get_stream(), 0); + } + + const auto is_dynamic = instance.is_dynamic(); + if (is_dynamic) { + instance.update_shape(); + if (instance.shape_changed()) { + instance.preproc_memories_done = false; + instance.reset_memory(); + } + } + + if (!instance.preproc_memories_done) { + instance.preprocess_output_memory(trip_count); + instance.preprocess_input_memory(trip_count); + instance.preprocess_backedge_memory(); + instance.preproc_memories_done = true; } const auto& concatenated_input_mem_mappings = instance.concatenated_input_mem_mappings; const auto& concatenated_output_mem_mappings = instance.concatenated_output_mem_mappings; + const auto& backedge_memory_mappings = instance.backedge_memory_mappings; // If there are concatenated_output_mem_mappings or backedge_memory_mappings we need to wait for // previous tasks before accessing memory in get_sliced_mem() and setup_iteration() functions - if (!concatenated_input_mem_mappings.empty() || !instance.backedge_memory_mappings.empty()) { + if (!concatenated_input_mem_mappings.empty() || !backedge_memory_mappings.empty()) { for (auto& e : events) { e->wait(); } @@ -102,37 +278,36 @@ struct loop_impl : typed_primitive_impl { // Set sliced input data for (size_t i = 0; i < concatenated_input_mem_mappings.size(); ++i) { const auto& concatenated_input = concatenated_input_mem_mappings.at(i); - memory::ptr mem = concatenated_input.get_sliced_mem(0); - if (mem) { - body_network->set_input_data(concatenated_input.sliced_data_prim->id(), mem); - } else { - CLDNN_ERROR_MESSAGE(instance.id(), "sliced input memory of loop is not allocated properly"); - } + memory::ptr mem = concatenated_input->get_sliced_mem(0); + OPENVINO_ASSERT(mem != nullptr, instance.id(), "sliced input memory of loop is not allocated properly"); + body_network->set_input_data(concatenated_input->sliced_data_prim->id(), mem); } std::vector all_events; std::vector loop_carried_dep(events.begin(), events.end()); - int64_t current_iteration_idx = 0; - while (current_iteration_idx < trip_count && execution_condition) { + while (((trip_count <= 0) || (current_iteration_idx < trip_count)) && execution_condition) { // Copy & Set sliced input memory for (size_t i = 0; i < concatenated_input_mem_mappings.size(); ++i) { const auto& concatenated_input = concatenated_input_mem_mappings.at(i); - memory::ptr mem = concatenated_input.get_sliced_mem(current_iteration_idx); - if (mem) { - concatenated_input.sliced_data_prim->set_output_memory(mem); - } else { - CLDNN_ERROR_MESSAGE(instance.id(), "sliced input memory of loop is not allocated properly"); - } + memory::ptr mem = concatenated_input->get_sliced_mem(current_iteration_idx); + OPENVINO_ASSERT(mem != nullptr, instance.id(), " sliced input memory of loop is not allocated properly"); + concatenated_input->sliced_data_prim->set_output_memory(mem); } - // Set backedges - for (const auto& backedge_memory_mapping : instance.backedge_memory_mappings) { - backedge_memory_mapping.setup_iteration(current_iteration_idx); + // Set backedges and output memory + for (auto& backedge_memory_mapping : backedge_memory_mappings) { + auto event_vec = handle_buffers_for_next_iteration(backedge_memory_mapping, body_network, current_iteration_idx, is_dynamic); + for (auto ev : event_vec) { + loop_carried_dep.push_back(ev); + } } - // Set sliced output memory - for (const auto& concat_output_mem_mapping : concatenated_output_mem_mappings) { - concat_output_mem_mapping.setup_sliced_output_memory(current_iteration_idx); + if (!is_dynamic) { + // Set sliced output memory for static shape model + // because body network generate output memory during the body network execution in dynamic model + for (const auto& concat_output_mem_mapping : concatenated_output_mem_mappings) { + concat_output_mem_mapping->setup_sliced_output_memory(current_iteration_idx); + } } // execute body network @@ -141,9 +316,10 @@ struct loop_impl : typed_primitive_impl { loop_carried_dep.clear(); for (const auto& backedge : _back_edges) { event::ptr body_event; - if (body_network->has_event(backedge.from)) + if (body_network->has_event(backedge.from)) { body_event = body_network->get_primitive_event(backedge.from); - loop_carried_dep.emplace_back(body_event); + loop_carried_dep.emplace_back(body_event); + } } // Collect output events for waiting for all iterations finishing @@ -155,42 +331,59 @@ struct loop_impl : typed_primitive_impl { } } - //TODO: execution_condition is prepared as they are presented in the - // ngraph opset document for loop operation. - // However they are not being used yet and only TensorIterator which - // has fixed sequence length is being validated. - if (!primitive->condition_id.empty()) { - execution_condition = loop_node::read_scalar_value(execution_condition_mem, stream); + // Store output of sliced_data_prim to sliced mems vector + // After execution of body network, sliced_data_prim will has output memory buffer + // current memory buffer move to sliced_mems and new memory buffer will be allocated in sliced_data_prim + if (is_dynamic) { + for (const auto& concat_output_mem_mapping : concatenated_output_mem_mappings) { + auto sliced_data_prim = concat_output_mem_mapping->sliced_data_prim; + auto output_mem_ptr = sliced_data_prim->output_memory_ptr(); + + auto sliced_id = sliced_data_prim->id(); + if (body_network->has_event(sliced_id)) { + auto ev = body_network->get_primitive_event(sliced_id); + if (ev) ev->wait(); + } + memory::ptr new_sliced_mem = concat_output_mem_mapping->get_or_create_sliced_mem(current_iteration_idx, + output_mem_ptr->get_layout()); + auto ev = new_sliced_mem->copy_from(body_network->get_stream(), *output_mem_ptr); + if (ev) { + loop_carried_dep.push_back(ev); + all_events.push_back(ev); + } + } } - // update index & execution condition for the next iteration - ++current_iteration_idx; + // execution condition is the result of body network execution + if (body_execution_condition_mem != nullptr) { + auto execution_id = primitive->body_execution_condition_id; + if (body_network->has_event(execution_id)) { + auto ev = body_network->get_primitive_event(execution_id); + if (ev) ev->wait(); + } + execution_condition = read_scalar_value(body_execution_condition_mem, body_network->get_stream()); + } + GPU_DEBUG_IF(!execution_condition) { + GPU_DEBUG_LOG << "body_exec_condition is false at "<< current_iteration_idx << " iterations" << std::endl; + } + + current_iteration_idx++; } // Reset network and wait for all collected events body_network->reset_execution(false); stream.wait_for_events(all_events); - // Concatenate sliced output to the outer network - for (size_t i = 0; i < concatenated_output_mem_mappings.size(); ++i) { - const auto& concat_output = concatenated_output_mem_mappings.at(i); - concat_output.restore_concatenated_mem(); - } + // Update actual num iteration + // update num_iterations (actual number of iterations) + memory::ptr num_actual_iterations_mem = outer_network.get_primitive(primitive->num_iteration_id)->output_memory_ptr(); + write_scalar_value(num_actual_iterations_mem, stream, current_iteration_idx); + GPU_DEBUG_LOG << "current_iteration(" << primitive->num_iteration_id << ", " + << num_actual_iterations_mem << ") : " << current_iteration_idx << std::endl; - if (update_num_iterations) { - // update num_iterations (actual number of iterations) - int64_t actual_iterations = 0; - if (!primitive->current_iteration_id.empty()) { - const auto& backedge_mapping = instance.get_current_iteration_backedge_mapping(); - auto current_iteration_mem = backedge_mapping.from_primitive->output_memory_ptr(); - actual_iterations = loop_node::read_scalar_value(current_iteration_mem, stream); - } else { - actual_iterations = current_iteration_idx; - } - - memory::ptr num_actual_iterations_mem = outer_network.get_primitive(primitive->num_iteration_id)->output_memory_ptr(); - loop_node::write_scalar_value(num_actual_iterations_mem, stream, actual_iterations); - } + if (is_dynamic) + instance.update_output_layout(); + instance.postprocess_output_memory(is_dynamic); ev->set(); return ev; @@ -202,23 +395,25 @@ struct loop_impl : typed_primitive_impl { void save(BinaryOutputBuffer& ob) const override { parent::save(ob); - ob << _max_iteration; ob << _back_edges; } void load(BinaryInputBuffer& ib) override { parent::load(ib); - ib >> _max_iteration; ib >> _back_edges; } private: - int64_t _max_iteration = 0; std::vector _back_edges; }; namespace detail { attach_loop_common::attach_loop_common() { + implementation_map::add(impl_types::common, + shape_types::dynamic_shape, + loop_impl::create, + {}, + {}); implementation_map::add(impl_types::common, loop_impl::create, {}); } } // namespace detail diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/activation.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/activation.cpp index 57c0f057455ba7..7f1e7abcb9b580 100644 --- a/src/plugins/intel_gpu/src/graph/impls/cpu/activation.cpp +++ b/src/plugins/intel_gpu/src/graph/impls/cpu/activation.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/core/type/element_type_traits.hpp" #include "register.hpp" #include "activation_inst.h" #include "implementation_map.hpp" @@ -108,7 +109,7 @@ struct activation_impl : public typed_primitive_impl { input_host_tensors.push_back(make_tensor(params->input_layouts[i], input_mem_ptrs[i]->lock(stream, mem_lock_type::read))); // Most of the evaluate functions expect same data type for all inputs, so we need to convert params from float - typename data_type_to_type
::type param_a = static_cast::type>(additional_params.a); + auto param_a = static_cast::value_type>(additional_params.a); auto input_dt = instance.get_input_layout().data_type; diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/detection_output.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/detection_output.cpp index 9e9cd8b1c93389..f15d143e28539c 100644 --- a/src/plugins/intel_gpu/src/graph/impls/cpu/detection_output.cpp +++ b/src/plugins/intel_gpu/src/graph/impls/cpu/detection_output.cpp @@ -839,11 +839,11 @@ struct detection_output_impl : typed_primitive_impl { std::vector>>> scoreIndexPairs; if (instance.location_memory()->get_layout().data_type == data_types::f32) { - prepare_data::type>(stream, instance, bboxes, confidences, scoreIndexPairs); - generate_detections::type>(stream, instance, num_of_images, bboxes, confidences, scoreIndexPairs); + prepare_data::value_type>(stream, instance, bboxes, confidences, scoreIndexPairs); + generate_detections::value_type>(stream, instance, num_of_images, bboxes, confidences, scoreIndexPairs); } else { - prepare_data::type>(stream, instance, bboxes, confidences, scoreIndexPairs); - generate_detections::type>(stream, instance, num_of_images, bboxes, confidences, scoreIndexPairs); + prepare_data::value_type>(stream, instance, bboxes, confidences, scoreIndexPairs); + generate_detections::value_type>(stream, instance, num_of_images, bboxes, confidences, scoreIndexPairs); } ev->set(); diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/non_max_suppression.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/non_max_suppression.cpp index 7afca0cb91c91f..cfb05c176c06ca 100644 --- a/src/plugins/intel_gpu/src/graph/impls/cpu/non_max_suppression.cpp +++ b/src/plugins/intel_gpu/src/graph/impls/cpu/non_max_suppression.cpp @@ -149,9 +149,9 @@ vector2D load_boxes(stream& stream, memory::ptr mem, bool center_p auto data_type = mem->get_layout().data_type; switch (data_type) { case cldnn::data_types::f16: - return load_boxes_impl::type>(stream, mem, center_point); + return load_boxes_impl::value_type>(stream, mem, center_point); case cldnn::data_types::f32: - return load_boxes_impl::type>(stream, mem, center_point); + return load_boxes_impl::value_type>(stream, mem, center_point); default: throw std::runtime_error("Non max suppression - unsupported boxes data type"); } @@ -186,9 +186,9 @@ vector3D load_scores(stream& stream, memory::ptr mem) { auto data_type = mem->get_layout().data_type; switch (data_type) { case cldnn::data_types::f16: - return load_scores_impl::type>(stream, mem); + return load_scores_impl::value_type>(stream, mem); case cldnn::data_types::f32: - return load_scores_impl::type>(stream, mem); + return load_scores_impl::value_type>(stream, mem); default: throw std::runtime_error("Non max suppression - unsupported scores data type"); } @@ -207,11 +207,11 @@ T load_scalar(stream& stream, memory::ptr mem) { auto data_type = mem->get_layout().data_type; switch (data_type) { case cldnn::data_types::i32: - return load_scalar_impl::type>(stream, mem); + return load_scalar_impl::value_type>(stream, mem); case cldnn::data_types::f16: - return load_scalar_impl::type>(stream, mem); + return load_scalar_impl::value_type>(stream, mem); case cldnn::data_types::f32: - return load_scalar_impl::type>(stream, mem); + return load_scalar_impl::value_type>(stream, mem); default: throw std::runtime_error("Non max suppression - unsupported data type"); } @@ -244,13 +244,13 @@ void store_result(stream& stream, memory::ptr mem, const std::vectorget_layout().data_type; switch (data_type) { case cldnn::data_types::i32: - store_result_impl::type>(stream, mem, result); + store_result_impl::value_type>(stream, mem, result); break; case cldnn::data_types::f16: - store_result_impl::type>(stream, mem, result); + store_result_impl::value_type>(stream, mem, result); break; case cldnn::data_types::f32: - store_result_impl::type>(stream, mem, result); + store_result_impl::value_type>(stream, mem, result); break; default: throw std::runtime_error("Non max suppression - unsupported output data type"); @@ -261,10 +261,10 @@ void store_first_output(stream& stream, memory::ptr mem, const std::vectorget_layout().data_type; switch (data_type) { case cldnn::data_types::i32: - store_result_impl::type>(stream, mem, result); + store_result_impl::value_type>(stream, mem, result); break; case cldnn::data_types::i64: - store_result_impl::type>(stream, mem, result); + store_result_impl::value_type>(stream, mem, result); break; default: throw std::runtime_error("Non max suppression - unsupported output data type"); @@ -298,10 +298,10 @@ void store_second_output(stream& stream, memory::ptr mem, const std::vectorget_layout().data_type; switch (data_type) { case cldnn::data_types::f16: - store_second_output_impl::type>(stream, mem, result); + store_second_output_impl::value_type>(stream, mem, result); break; case cldnn::data_types::f32: - store_second_output_impl::type>(stream, mem, result); + store_second_output_impl::value_type>(stream, mem, result); break; default: throw std::runtime_error("Non max suppression - unsupported second output data type"); @@ -319,10 +319,10 @@ void store_third_output(stream& stream, memory::ptr mem, const std::vectorget_layout().data_type; switch (data_type) { case cldnn::data_types::i32: - store_third_output_impl::type>(stream, mem, result); + store_third_output_impl::value_type>(stream, mem, result); break; case cldnn::data_types::i64: - store_third_output_impl::type>(stream, mem, result); + store_third_output_impl::value_type>(stream, mem, result); break; default: throw std::runtime_error("Non max suppression - unsupported third output data type"); diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/proposal.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/proposal.cpp index 461035c1defd75..2670949f8e9284 100644 --- a/src/plugins/intel_gpu/src/graph/impls/cpu/proposal.cpp +++ b/src/plugins/intel_gpu/src/graph/impls/cpu/proposal.cpp @@ -396,9 +396,9 @@ struct proposal_impl : typed_primitive_impl { auto ev = instance.get_network().get_stream().create_user_event(false); im_info_t im_info; if (instance.dep_memory(proposal_inst::image_info_index).get_layout().data_type == data_types::f16) { - read_image_info::type>(stream, instance, im_info); + read_image_info::value_type>(stream, instance, im_info); } else { - read_image_info::type>(stream, instance, im_info); + read_image_info::value_type>(stream, instance, im_info); } if (instance.dep_memory(proposal_inst::cls_scores_index).get_layout().data_type != @@ -408,26 +408,26 @@ struct proposal_impl : typed_primitive_impl { if (instance.dependencies().size() == 4) { auto proposal_probabilities = instance.dep_memory_ptr(proposal_inst::proposal_probabilities_out); if (instance.dep_memory(proposal_inst::cls_scores_index).get_layout().data_type == data_types::f16) { - mem_lock::type, mem_lock_type::read> proposal_prob_ptr{proposal_probabilities, stream}; - execute::type>(stream, instance, im_info, proposal_prob_ptr.data()); + mem_lock::value_type, mem_lock_type::read> proposal_prob_ptr{proposal_probabilities, stream}; + execute::value_type>(stream, instance, im_info, proposal_prob_ptr.data()); } else { - mem_lock::type, mem_lock_type::read> proposal_prob_ptr{proposal_probabilities, stream}; - execute::type>(stream, instance, im_info, proposal_prob_ptr.data()); + mem_lock::value_type, mem_lock_type::read> proposal_prob_ptr{proposal_probabilities, stream}; + execute::value_type>(stream, instance, im_info, proposal_prob_ptr.data()); } } else if (instance.outputs_memory_count() == 2) { auto proposal_probabilities = instance.output_memory_ptr(1); if (instance.dep_memory(proposal_inst::cls_scores_index).get_layout().data_type == data_types::f16) { - mem_lock::type, mem_lock_type::write> proposal_prob_ptr{proposal_probabilities, stream}; - execute::type>(stream, instance, im_info, proposal_prob_ptr.data()); + mem_lock::value_type, mem_lock_type::write> proposal_prob_ptr{proposal_probabilities, stream}; + execute::value_type>(stream, instance, im_info, proposal_prob_ptr.data()); } else { - mem_lock::type, mem_lock_type::write> proposal_prob_ptr{proposal_probabilities, stream}; - execute::type>(stream, instance, im_info, proposal_prob_ptr.data()); + mem_lock::value_type, mem_lock_type::write> proposal_prob_ptr{proposal_probabilities, stream}; + execute::value_type>(stream, instance, im_info, proposal_prob_ptr.data()); } } else { if (instance.dep_memory(proposal_inst::cls_scores_index).get_layout().data_type == data_types::f16) { - execute::type>(stream, instance, im_info); + execute::value_type>(stream, instance, im_info); } else { - execute::type>(stream, instance, im_info); + execute::value_type>(stream, instance, im_info); } } diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/fully_connected.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/fully_connected.cpp index 43ce081d2f69ea..19007a481579f6 100644 --- a/src/plugins/intel_gpu/src/graph/impls/ocl/fully_connected.cpp +++ b/src/plugins/intel_gpu/src/graph/impls/ocl/fully_connected.cpp @@ -110,20 +110,13 @@ struct fully_connected_impl : typed_primitive_impl_ocl { bool has_scale = !primitive->decompression_scale.empty(); size_t offset = primitive->bias.empty() ? 2 : 3; - const auto& weights_pshape = input1_layout.get_partial_shape(); if (has_scale) { auto scale_layout = input_layouts[offset++]; - if (input1_pshape.size() != 2) { - scale_layout.set_partial_shape(reshape_to_2d(scale_layout.get_partial_shape(), weights_pshape[0], primitive->weights_rank)); - } layouts.push_back(scale_layout); } if (has_zp) { auto zp_layout = input_layouts[offset]; - if (input1_pshape.size() != 2) { - zp_layout.set_partial_shape(reshape_to_2d(zp_layout.get_partial_shape(), weights_pshape[0], primitive->weights_rank)); - } layouts.push_back(zp_layout); } diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/group_normalization.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/group_normalization.cpp new file mode 100644 index 00000000000000..5296c1dda7e7aa --- /dev/null +++ b/src/plugins/intel_gpu/src/graph/impls/ocl/group_normalization.cpp @@ -0,0 +1,71 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#include "primitive_base.hpp" +#include "group_normalization_inst.h" +#include "group_normalization/group_normalization_kernel_ref.h" +#include "group_normalization/group_normalization_kernel_selector.h" + +namespace cldnn { +namespace ocl { + +struct group_normalization_impl : typed_primitive_impl_ocl { + using parent = typed_primitive_impl_ocl; + using parent::parent; + using kernel_selector_t = kernel_selector::group_normalization_kernel_selector; + using kernel_params_t = std::pair; + + DECLARE_OBJECT_TYPE_SERIALIZATION(cldnn::ocl::group_normalization_impl) + + std::unique_ptr clone() const override { + return make_unique(*this); + } + + static kernel_params_t get_kernel_params(const kernel_impl_params& impl_param, bool is_shape_agnostic = false) { + const auto& primitive = impl_param.typed_desc(); + auto params = get_default_params(impl_param, is_shape_agnostic); + params.inputs.push_back(convert_data_tensor(impl_param.get_input_layout(1))); + params.inputs.push_back(convert_data_tensor(impl_param.get_input_layout(2))); + auto optional_params = get_default_optional_params(impl_param.get_program()); + params.num_groups = primitive->num_groups; + params.epsilon = primitive->epsilon; + return {params, optional_params}; + } + + void update_dispatch_data(const kernel_impl_params& impl_param) override { + auto kernel_params = get_kernel_params(impl_param, true); + (_kernel_data.update_dispatch_data_func)(kernel_params.first, _kernel_data); + } +}; + +namespace detail { + +attach_group_normalization_impl::attach_group_normalization_impl() { + auto types = {data_types::f16, data_types::f32}; + auto formats = { + format::bfyx, + format::byxf, + format::yxfb, + format::bfzyx, + format::b_fs_yx_fsv2, + format::b_fs_zyx_fsv2, + format::b_fs_yx_fsv4, + format::b_fs_zyx_fsv4, + format::b_fs_yx_fsv16, + format::b_fs_yx_fsv32, + format::b_fs_zyx_fsv16, + format::b_fs_zyx_fsv32, + }; + + implementation_map::add(impl_types::ocl, shape_types::static_shape, + typed_primitive_impl_ocl::create, + types, + formats); +} + +} // namespace detail +} // namespace ocl +} // namespace cldnn + +BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::group_normalization_impl) +BIND_BINARY_BUFFER_WITH_TYPE(cldnn::group_normalization) diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp index 12e7d1b28b93ee..f0872d3702970e 100644 --- a/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp +++ b/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp @@ -219,6 +219,8 @@ kernel_selector::data_layout to_data_layout(format f) { return kernel_selector::data_layout::b_fs_yx_fsv2; case format::b_fs_yx_fsv4: return kernel_selector::data_layout::b_fs_yx_fsv4; + case format::b_fs_yx_fsv8: + return kernel_selector::data_layout::b_fs_yx_fsv8; case format::b_fs_yx_fsv16: return kernel_selector::data_layout::b_fs_yx_fsv16; case format::b_fs_yx_fsv32: @@ -227,6 +229,8 @@ kernel_selector::data_layout to_data_layout(format f) { return kernel_selector::data_layout::b_fs_zyx_fsv2; case format::b_fs_zyx_fsv4: return kernel_selector::data_layout::b_fs_zyx_fsv4; + case format::b_fs_zyx_fsv8: + return kernel_selector::data_layout::b_fs_zyx_fsv8; case format::b_fs_zyx_fsv32: return kernel_selector::data_layout::b_fs_zyx_fsv32; case format::bs_f_bsv16: @@ -277,6 +281,10 @@ kernel_selector::data_layout to_data_layout(format f) { return kernel_selector::data_layout::bs_fs_yx_bsv16_fsv2; case format::bs_fs_zyx_bsv16_fsv2: return kernel_selector::data_layout::bs_fs_zyx_bsv16_fsv2; + case format::bs_fs_yx_bsv16_fsv8: + return kernel_selector::data_layout::bs_fs_yx_bsv16_fsv8; + case format::bs_fs_zyx_bsv16_fsv8: + return kernel_selector::data_layout::bs_fs_zyx_bsv16_fsv8; case format::bs_fs_yx_bsv8_fsv2: return kernel_selector::data_layout::bs_fs_yx_bsv8_fsv2; case format::bs_fs_zyx_bsv8_fsv2: @@ -320,10 +328,14 @@ cldnn::format from_data_layout(kernel_selector::data_layout l) { return cldnn::format::b_fs_yx_fsv2; case kernel_selector::data_layout::b_fs_yx_fsv4: return cldnn::format::b_fs_yx_fsv4; + case kernel_selector::data_layout::b_fs_yx_fsv8: + return cldnn::format::b_fs_yx_fsv8; case kernel_selector::data_layout::b_fs_yx_fsv16: return cldnn::format::b_fs_yx_fsv16; case kernel_selector::data_layout::b_fs_yx_fsv32: return cldnn::format::b_fs_yx_fsv32; + case kernel_selector::data_layout::b_fs_zyx_fsv8: + return cldnn::format::b_fs_zyx_fsv8; case kernel_selector::data_layout::b_fs_zyx_fsv32: return cldnn::format::b_fs_zyx_fsv32; case kernel_selector::data_layout::bs_f_bsv8__af8: @@ -366,6 +378,10 @@ cldnn::format from_data_layout(kernel_selector::data_layout l) { return cldnn::format::bs_fs_yx_bsv16_fsv2; case kernel_selector::data_layout::bs_fs_zyx_bsv16_fsv2: return cldnn::format::bs_fs_zyx_bsv16_fsv2; + case kernel_selector::data_layout::bs_fs_yx_bsv16_fsv8: + return cldnn::format::bs_fs_yx_bsv16_fsv8; + case kernel_selector::data_layout::bs_fs_zyx_bsv16_fsv8: + return cldnn::format::bs_fs_zyx_bsv16_fsv8; case kernel_selector::data_layout::bs_fs_yx_bsv8_fsv2: return cldnn::format::bs_fs_yx_bsv8_fsv2; case kernel_selector::data_layout::bs_fs_yx_bsv32_fsv32: @@ -406,8 +422,14 @@ kernel_selector::weights_layout to_weights_layout(format f, bool is_grouped) { return kernel_selector::weights_layout::yxio; case format::os_yxi_osv16: return kernel_selector::weights_layout::os_yxi_osv16; + case format::o_is_yx_isv2: + return kernel_selector::weights_layout::o_is_yx_isv2; + case format::o_is_yx_isv4: + return kernel_selector::weights_layout::o_is_yx_isv4; case format::o_is_yx_isv16: return kernel_selector::weights_layout::o_is_yx_isv16; + case format::o_is_zyx_isv16: + return kernel_selector::weights_layout::o_is_zyx_isv16; case format::os_iyx_osv16: return kernel_selector::weights_layout::os_iyx_osv16; case format::os_is_yx_osv16_isv2: @@ -474,6 +496,10 @@ kernel_selector::weights_layout to_weights_layout(format f, bool is_grouped) { return kernel_selector::weights_layout::os_is_zyx_osv8_isv2; case format::os_is_yx_osv8_isv4: return kernel_selector::weights_layout::os_is_yx_osv8_isv4; + case format::os_is_yx_osv4_isv16: + return kernel_selector::weights_layout::os_is_yx_osv4_isv16; + case format::os_is_yx_osv2_isv16: + return kernel_selector::weights_layout::os_is_yx_osv2_isv16; case format::os_is_zyx_osv8_isv4: return kernel_selector::weights_layout::os_is_zyx_osv8_isv4; case format::os_is_yx_osa4_isa8_osv8_isv4_swizzled_by_4: @@ -527,6 +553,8 @@ kernel_selector::weights_layout to_weights_layout(format f, bool is_grouped) { return kernel_selector::weights_layout::is_os_zyx_isv16_osv16; case format::os_is_zyx_osv32_isv16: return kernel_selector::weights_layout::os_is_zyx_osv32_isv16; + case format::is_os_yx_osv8_isv4: + return kernel_selector::weights_layout::is_os_yx_osv8_isv4; case format::is_os_yx_isv16_osv16: return kernel_selector::weights_layout::is_os_yx_isv16_osv16; case format::is_os_yx_isv16_osv8: @@ -567,6 +595,10 @@ kernel_selector::weights_layout to_weights_layout(format f, bool is_grouped) { return kernel_selector::weights_layout::g_os_iyx_osv16; case format::g_os_iyx_osv32: return kernel_selector::weights_layout::g_os_iyx_osv32; + case format::gs_oiyx_gsv8: + return kernel_selector::weights_layout::gs_oiyx_gsv8; + case format::gs_oizyx_gsv8: + return kernel_selector::weights_layout::gs_oizyx_gsv8; case format::gs_oiyx_gsv16: return kernel_selector::weights_layout::gs_oiyx_gsv16; case format::gs_oizyx_gsv16: @@ -711,8 +743,14 @@ cldnn::format::type from_weights_layout(kernel_selector::weights_layout l) { return cldnn::format::yxio; case kernel_selector::weights_layout::os_yxi_osv16: return cldnn::format::os_yxi_osv16; + case kernel_selector::weights_layout::o_is_yx_isv2: + return cldnn::format::o_is_yx_isv2; + case kernel_selector::weights_layout::o_is_yx_isv4: + return cldnn::format::o_is_yx_isv4; case kernel_selector::weights_layout::o_is_yx_isv16: return cldnn::format::o_is_yx_isv16; + case kernel_selector::weights_layout::o_is_zyx_isv16: + return cldnn::format::o_is_zyx_isv16; case kernel_selector::weights_layout::os_iyx_osv16: return cldnn::format::os_iyx_osv16; case kernel_selector::weights_layout::os_is_yx_isv16_osv16: @@ -821,6 +859,8 @@ cldnn::format::type from_weights_layout(kernel_selector::weights_layout l) { return cldnn::format::os_is_zyx_isv16_osv16; case kernel_selector::weights_layout::is_os_zyx_isv16_osv16: return cldnn::format::is_os_zyx_isv16_osv16; + case kernel_selector::weights_layout::is_os_yx_osv8_isv4: + return cldnn::format::is_os_yx_osv8_isv4; case kernel_selector::weights_layout::is_os_yx_isv16_osv16: return cldnn::format::is_os_yx_isv16_osv16; case kernel_selector::weights_layout::is_os_yx_isv16_osv8: @@ -855,6 +895,10 @@ cldnn::format::type from_weights_layout(kernel_selector::weights_layout l) { return cldnn::format::os_is_zyx_osv8_isv2; case kernel_selector::weights_layout::os_is_yx_osv8_isv4: return cldnn::format::os_is_yx_osv8_isv4; + case kernel_selector::weights_layout::os_is_yx_osv4_isv16: + return cldnn::format::os_is_yx_osv4_isv16; + case kernel_selector::weights_layout::os_is_yx_osv2_isv16: + return cldnn::format::os_is_yx_osv2_isv16; case kernel_selector::weights_layout::os_is_zyx_osv8_isv4: return cldnn::format::os_is_zyx_osv8_isv4; case kernel_selector::weights_layout::os_is_zyx_isv8_osv16_isv2: @@ -871,6 +915,10 @@ cldnn::format::type from_weights_layout(kernel_selector::weights_layout l) { return cldnn::format::g_os_iyx_osv16; case kernel_selector::weights_layout::g_os_iyx_osv32: return cldnn::format::g_os_iyx_osv32; + case kernel_selector::weights_layout::gs_oiyx_gsv8: + return cldnn::format::gs_oiyx_gsv8; + case kernel_selector::weights_layout::gs_oizyx_gsv8: + return cldnn::format::gs_oizyx_gsv8; case kernel_selector::weights_layout::gs_oiyx_gsv16: return cldnn::format::gs_oiyx_gsv16; case kernel_selector::weights_layout::gs_oizyx_gsv16: diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/register.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/register.cpp index 3a287bdeda4f7d..3cc96ee00735ce 100644 --- a/src/plugins/intel_gpu/src/graph/impls/ocl/register.cpp +++ b/src/plugins/intel_gpu/src/graph/impls/ocl/register.cpp @@ -40,6 +40,7 @@ void register_implementations() { REGISTER_OCL(gemm); REGISTER_OCL(generate_proposals); REGISTER_OCL(grid_sample); + REGISTER_OCL(group_normalization); REGISTER_OCL(lrn); REGISTER_OCL(lstm_gemm); REGISTER_OCL(lstm_elt); @@ -64,6 +65,7 @@ void register_implementations() { REGISTER_OCL(reshape); REGISTER_OCL(reverse); REGISTER_OCL(reverse_sequence); + REGISTER_OCL(rms); REGISTER_OCL(roi_align); REGISTER_OCL(roi_pooling); REGISTER_OCL(roll); diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/register.hpp b/src/plugins/intel_gpu/src/graph/impls/ocl/register.hpp index a5fb5a5817e395..d591499148e77a 100644 --- a/src/plugins/intel_gpu/src/graph/impls/ocl/register.hpp +++ b/src/plugins/intel_gpu/src/graph/impls/ocl/register.hpp @@ -35,6 +35,7 @@ #include "intel_gpu/primitives/gemm.hpp" #include "intel_gpu/primitives/grid_sample.hpp" #include "intel_gpu/primitives/grn.hpp" +#include "intel_gpu/primitives/group_normalization.hpp" #include "intel_gpu/primitives/lrn.hpp" #include "intel_gpu/primitives/lstm.hpp" #include "intel_gpu/primitives/lstm_dynamic.hpp" @@ -58,6 +59,7 @@ #include "intel_gpu/primitives/resample.hpp" #include "intel_gpu/primitives/reshape.hpp" #include "intel_gpu/primitives/reverse_sequence.hpp" +#include "intel_gpu/primitives/rms.hpp" #include "intel_gpu/primitives/roi_align.hpp" #include "intel_gpu/primitives/roi_pooling.hpp" #include "intel_gpu/primitives/roll.hpp" @@ -120,6 +122,7 @@ REGISTER_OCL(gather_elements); REGISTER_OCL(gemm); REGISTER_OCL(generate_proposals); REGISTER_OCL(grid_sample); +REGISTER_OCL(group_normalization); REGISTER_OCL(lrn); REGISTER_OCL(lstm_gemm); REGISTER_OCL(lstm_elt); @@ -144,6 +147,7 @@ REGISTER_OCL(reorg_yolo); REGISTER_OCL(reshape); REGISTER_OCL(reverse); REGISTER_OCL(reverse_sequence); +REGISTER_OCL(rms); REGISTER_OCL(roi_align); REGISTER_OCL(roi_pooling); REGISTER_OCL(roll); diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/rms.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/rms.cpp new file mode 100644 index 00000000000000..71f44e685157b0 --- /dev/null +++ b/src/plugins/intel_gpu/src/graph/impls/ocl/rms.cpp @@ -0,0 +1,65 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "primitive_base.hpp" + +#include "rms_inst.h" +#include "rms/rms_kernel_selector.h" +#include "rms/rms_kernel_ref.h" + +namespace cldnn { +namespace ocl { + +struct rms_impl : typed_primitive_impl_ocl { + using parent = typed_primitive_impl_ocl; + using parent::parent; + using kernel_selector_t = kernel_selector::rms_kernel_selector; + using kernel_params_t = std::pair; + + DECLARE_OBJECT_TYPE_SERIALIZATION(cldnn::ocl::rms_impl); + + std::unique_ptr clone() const override { + return make_unique(*this); + } + + static kernel_params_t get_kernel_params(const kernel_impl_params& impl_param, bool is_shape_agnostic = false) { + const auto& primitive = impl_param.typed_desc(); + auto params = get_default_params(impl_param, is_shape_agnostic); + auto optional_params = get_default_optional_params(impl_param.get_program()); + + params.inputs.push_back(convert_data_tensor(impl_param.get_input_layout(1))); + params.epsilon = primitive->epsilon; + return {params, optional_params}; + } + + void update_dispatch_data(const kernel_impl_params& impl_param) override { + auto kernel_params = get_kernel_params(impl_param, true); + (_kernel_data.update_dispatch_data_func)(kernel_params.first, _kernel_data); + } +}; + +namespace detail { + +attach_rms_impl::attach_rms_impl() { + auto types = { + data_types::f32, + data_types::f16, + data_types::i32 + }; + + auto formats = { + format::bfyx, + format::bfzyx + }; + + implementation_map::add(impl_types::ocl, + shape_types::any, + typed_primitive_impl_ocl::create, + types, + formats); +} + +} // namespace detail +} // namespace ocl +} // namespace cldnn diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/convolution_onednn.cpp b/src/plugins/intel_gpu/src/graph/impls/onednn/convolution_onednn.cpp index f1d1ab0a6c0745..aa11884b2445bc 100644 --- a/src/plugins/intel_gpu/src/graph/impls/onednn/convolution_onednn.cpp +++ b/src/plugins/intel_gpu/src/graph/impls/onednn/convolution_onednn.cpp @@ -53,33 +53,40 @@ struct convolution_onednn : typed_primitive_onednn_impl { dnnl::memory::desc desc = onednn::layout_to_memory_desc(a_zp->get_layout(), dnnl::memory::format_tag::a, true); args.insert({DNNL_ARG_ATTR_ZERO_POINTS | DNNL_ARG_SRC, a_zp->get_onednn_memory(desc)}); - auto dnnl_mem = a_zp->get_onednn_memory(desc); - void *mapped_ptr = dnnl_mem.map_data(); - if (mapped_ptr) { - GPU_DEBUG_TRACE_DETAIL << instance.id() << " activations_zero_points: "; - for (size_t i = 0; i < desc.get_size(); ++i) { - GPU_DEBUG_TRACE_DETAIL << static_cast(mapped_ptr)[i] << " "; + GPU_DEBUG_GET_INSTANCE(debug_config); + GPU_DEBUG_IF(debug_config->verbose >= static_cast(ov::intel_gpu::LogLevel::TRACE_DETAIL)) { + auto dnnl_mem = a_zp->get_onednn_memory(desc); + void *mapped_ptr = dnnl_mem.map_data(); + if (mapped_ptr) { + GPU_DEBUG_TRACE_DETAIL << instance.id() << " activations_zero_points: "; + for (size_t i = 0; i < desc.get_size(); ++i) { + GPU_DEBUG_TRACE_DETAIL << static_cast(mapped_ptr)[i] << " "; + } + GPU_DEBUG_TRACE_DETAIL << std::endl; + dnnl_mem.unmap_data(mapped_ptr); } - GPU_DEBUG_TRACE_DETAIL << std::endl; - dnnl_mem.unmap_data(mapped_ptr); } } if (instance.weights_zero_points_term()) { - auto w_zp = instance.weights_zero_points_memory(); - dnnl::memory::desc desc = onednn::layout_to_memory_desc(w_zp->get_layout(), dnnl::memory::format_tag::a, true); - args.insert({DNNL_ARG_ATTR_ZERO_POINTS | DNNL_ARG_WEIGHTS, w_zp->get_onednn_memory(desc)}); - - auto dnnl_mem = w_zp->get_onednn_memory(desc); - void *mapped_ptr = dnnl_mem.map_data(); - if (mapped_ptr) { - GPU_DEBUG_TRACE_DETAIL << instance.id() << " weights_zero_points: "; - for (size_t i = 0; i < desc.get_size(); ++i) { - GPU_DEBUG_TRACE_DETAIL << static_cast(mapped_ptr)[i] << " "; - } - GPU_DEBUG_TRACE_DETAIL << std::endl; - dnnl_mem.unmap_data(mapped_ptr); - } + throw std::runtime_error("Convolution oneDNN primitive doesn't support asymmetric weights quantization"); + // auto w_zp = instance.weights_zero_points_memory(); + // dnnl::memory::desc desc = onednn::layout_to_memory_desc(w_zp->get_layout(), dnnl::memory::format_tag::a, true); + // args.insert({DNNL_ARG_ATTR_ZERO_POINTS | DNNL_ARG_WEIGHTS, w_zp->get_onednn_memory(desc)}); + + // GPU_DEBUG_GET_INSTANCE(debug_config); + // GPU_DEBUG_IF(debug_config->verbose >= static_cast(ov::intel_gpu::LogLevel::TRACE_DETAIL)) { + // auto dnnl_mem = w_zp->get_onednn_memory(desc); + // void *mapped_ptr = dnnl_mem.map_data(); + // if (mapped_ptr) { + // GPU_DEBUG_TRACE_DETAIL << instance.id() << " weights_zero_points: "; + // for (size_t i = 0; i < desc.get_size(); ++i) { + // GPU_DEBUG_TRACE_DETAIL << static_cast(mapped_ptr)[i] << " "; + // } + // GPU_DEBUG_TRACE_DETAIL << std::endl; + // dnnl_mem.unmap_data(mapped_ptr); + // } + // } } return args; @@ -114,9 +121,9 @@ struct convolution_onednn : typed_primitive_onednn_impl { } if (a_zp_dtype == data_types::i8) { - set_activation_zero_points_attr::type>(attrs, a_zp.as(), zero_point_mask); + set_activation_zero_points_attr::value_type>(attrs, a_zp.as(), zero_point_mask); } else { // if (a_zp_dtype == data_types::u8) - set_activation_zero_points_attr::type>(attrs, a_zp.as(), zero_point_mask); + set_activation_zero_points_attr::value_type>(attrs, a_zp.as(), zero_point_mask); } } @@ -255,6 +262,8 @@ attach_convolution_onednn::attach_convolution_onednn() { format::b_fs_zyx_fsv2, format::b_fs_yx_fsv4, format::b_fs_zyx_fsv4, + format::b_fs_yx_fsv8, + format::b_fs_zyx_fsv8, format::b_fs_yx_fsv16, format::b_fs_zyx_fsv16, format::b_fs_zyx_fsv32, @@ -269,9 +278,11 @@ attach_convolution_onednn::attach_convolution_onednn() { format::bs_fs_zyx_bsv32_fsv32, format::bs_fs_yx_bsv4_fsv4, format::bs_fs_yx_bsv8_fsv4, + format::bs_fs_yx_bsv16_fsv8, format::bs_fs_yx_bsv16_fsv4, format::bs_fs_yx_bsv16_fsv2, format::bs_fs_zyx_bsv8_fsv4, + format::bs_fs_zyx_bsv16_fsv8, format::bs_fs_zyx_bsv16_fsv4, format::bs_fs_zyx_bsv16_fsv2, format::bs_fs_yx_bsv8_fsv2, diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cpp b/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cpp index 6905c074be8a86..d72aba88cb1177 100644 --- a/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cpp +++ b/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cpp @@ -13,23 +13,6 @@ namespace cldnn { namespace onednn { -namespace { -std::string convert_data_format_string(cldnn::format fmt) { - switch (fmt) { - case cldnn::format::b_fs_yx_fsv2: return "aBcd2b"; - case cldnn::format::b_fs_zyx_fsv2: return "aBcde2b"; - case cldnn::format::bs_fs_yx_bsv16_fsv2: return "ABcd16a2b"; - case cldnn::format::bs_fs_zyx_bsv16_fsv2: return "ABcde16a2b"; - case cldnn::format::bs_fs_yx_bsv16_fsv4: return "ABcd16a4b"; - case cldnn::format::bs_fs_zyx_bsv16_fsv4: return "ABcde16a4b"; - case cldnn::format::bs_fs_yx_bsv16_fsv32: return "ABcd16a32b"; - case cldnn::format::bs_fs_zyx_bsv16_fsv32: return "ABcde16a32b"; - default: throw std::invalid_argument("[clDNN] Unsupported conversion from cldnn to onednn layout string" + fmt_to_str(fmt)); - } -} - -} // namespace - template cldnn::memory::ptr convert_zp_data_to_s32(const memory::ptr zp_memory) { auto engine = zp_memory->get_engine(); @@ -132,9 +115,11 @@ std::vector> format_map = { { cldnn::format::bzyxf, dnnl::memory::format_tag::ndhwc }, { cldnn::format::b_fs_yx_fsv2, dnnl::memory::format_tag::undef }, { cldnn::format::b_fs_yx_fsv4, dnnl::memory::format_tag::aBcd4b }, + { cldnn::format::b_fs_yx_fsv8, dnnl::memory::format_tag::aBcd8b }, { cldnn::format::b_fs_yx_fsv16, dnnl::memory::format_tag::nChw16c }, { cldnn::format::b_fs_yx_fsv32, dnnl::memory::format_tag::aBcd32b }, { cldnn::format::b_fs_zyx_fsv4, dnnl::memory::format_tag::aBcde4b }, + { cldnn::format::b_fs_zyx_fsv8, dnnl::memory::format_tag::aBcde8b }, { cldnn::format::b_fs_zyx_fsv16, dnnl::memory::format_tag::nCdhw16c }, { cldnn::format::b_fs_zyx_fsv32, dnnl::memory::format_tag::aBcde32b }, { cldnn::format::bs_fs_yx_bsv16_fsv16, dnnl::memory::format_tag::NChw16n16c }, @@ -157,8 +142,10 @@ dnnl::memory::format_tag convert_data_format(cldnn::format fmt) { auto ret = std::find_if(format_map.begin(), format_map.end(), [fmt](std::pair &e) { return e.first == fmt; }); - if (ret == format_map.end()) - return dnnl::memory::format_tag::undef; + if (ret == format_map.end()) { + GPU_DEBUG_INFO << "[clDNN] Unsupported conversion from "+ fmt.to_string() + " to onednn format_tag. Any tag will be used instead." << std::endl; + return dnnl::memory::format_tag::any; + } return ret->second; } @@ -233,8 +220,6 @@ dnnl::memory::desc layout_to_memory_desc(cldnn::layout l, dnnl::memory::format_t dnnl::memory::data_type dt = convert_data_type(l.data_type); dnnl::memory::format_tag fmt = target_fmt == dnnl::memory::format_tag::undef ? convert_data_format(l.format) : target_fmt; - - OPENVINO_ASSERT(fmt != dnnl::memory::format_tag::undef, "[GPU] Unexpected fmt: ", convert_data_format_string(l.format)); dnnl::memory::desc res(dims, dt, fmt); return res; diff --git a/src/plugins/intel_gpu/src/graph/include/group_normalization_inst.h b/src/plugins/intel_gpu/src/graph/include/group_normalization_inst.h new file mode 100644 index 00000000000000..27fe382146999b --- /dev/null +++ b/src/plugins/intel_gpu/src/graph/include/group_normalization_inst.h @@ -0,0 +1,39 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#pragma once +#include "intel_gpu/primitives/group_normalization.hpp" +#include "primitive_inst.h" + +namespace cldnn { +template <> +struct typed_program_node : public typed_program_node_base { + using parent = typed_program_node_base; + +public: + using parent::parent; + + std::vector get_shape_infer_dependencies() const override { return {}; } +}; +using group_normalization_node = typed_program_node; + +template <> +class typed_primitive_inst : public typed_primitive_inst_base { + using parent = typed_primitive_inst_base; + using parent::parent; + +public: + template + static std::vector calc_output_layouts(group_normalization_node const& /*node*/, const kernel_impl_params& impl_param) { + return forward_input0_shape(impl_param); + } + + static layout calc_output_layout(group_normalization_node const& node, kernel_impl_params const& impl_param); + static std::string to_string(group_normalization_node const& node); + + typed_primitive_inst(network& network, group_normalization_node const& desc); +}; + +using group_normalization_inst = typed_primitive_inst; + +} // namespace cldnn diff --git a/src/plugins/intel_gpu/src/graph/include/layout_optimizer.h b/src/plugins/intel_gpu/src/graph/include/layout_optimizer.h index fd048838c704ea..e9ed4ec959ae1c 100644 --- a/src/plugins/intel_gpu/src/graph/include/layout_optimizer.h +++ b/src/plugins/intel_gpu/src/graph/include/layout_optimizer.h @@ -169,6 +169,7 @@ class layout_optimizer { impl_types get_preferred_impl_type(program_node& node, format preferred_format); impl_types get_forced_impl_type_by_config(program_node& node); + static bool is_node_suitable_for_onednn(program_node& node); static bool are_data_types_suitable_for_onednn(program_node& node); bool are_layouts_suitable_for_onednn(program_node& node); static bool onednn_check_data_types_for_pooling(data_types in_dt, data_types out_dt); @@ -188,6 +189,7 @@ class layout_optimizer { optimization_attributes get_optimization_attributes() { return _optimization_attributes; } void set_implementation_forcing(const ov::intel_gpu::ImplForcingMap& map); + const std::map> get_implementation_forcing() const; void update_formats_map(const convolution_node& node); bool is_format_optimized(const convolution_node& node, const format& format, bool use_weak_restrictions = false); diff --git a/src/plugins/intel_gpu/src/graph/include/loop_inst.h b/src/plugins/intel_gpu/src/graph/include/loop_inst.h index 5d7dd710892181..22f4489ae507b5 100644 --- a/src/plugins/intel_gpu/src/graph/include/loop_inst.h +++ b/src/plugins/intel_gpu/src/graph/include/loop_inst.h @@ -21,163 +21,52 @@ template<> struct typed_program_node : public typed_program_node_base { private: using parent = typed_program_node_base; - mutable topology body; - std::vector input_primitive_maps; - std::vector output_primitive_maps; - mutable std::vector back_edges; - bool use_current_iteration; - bool use_execution_condition; - mutable program::ptr body_program; + std::vector& input_primitive_maps; + std::vector& output_primitive_maps; + std::vector& back_edges; public: - typed_program_node(std::shared_ptr prim, program& prog) : + typed_program_node(std::shared_ptr prim, program& prog) : parent(prim, prog), - body(this->get_primitive()->body), - input_primitive_maps(this->get_primitive()->input_primitive_maps), - output_primitive_maps(this->get_primitive()->output_primitive_maps), - back_edges(this->get_primitive()->back_edges), - use_current_iteration(!this->get_primitive()->current_iteration_id.empty()), - use_execution_condition(!this->get_primitive()->condition_id.empty()), - iteration_axis(0), - max_iteration(this->get_primitive()->max_iteration < 0 ? DEFAULT_MAX_NUM_ITERATION : this->get_primitive()->max_iteration) {} - - mutable size_t iteration_axis; - int64_t max_iteration; - - int64_t get_max_iteration() const { return max_iteration; } - program::ptr get_body_program() const { return body_program; } - bool is_current_iteration_used() const { return use_current_iteration; } - bool is_execution_condition_used() const { return use_execution_condition; } - - static size_t convert_to_raw_axis(size_t axis, size_t ndim) { - // convert between bfyx, bfzyx, bfzyxw and tensor.size.raw - if (axis >= ndim) { - throw std::runtime_error("axis should be less than ndim"); - } - - if (axis < 2) { - return axis; - } - return (ndim - 1) - (axis - 2); - } - - // read scala value from data primitive - static int64_t read_scalar_value(memory::ptr mem, stream& stream) { - int64_t trip_count = 0; - const layout& prim_layout = mem->get_layout(); - - switch (prim_layout.data_type) { - case data_types::u8: { - mem_lock lock_prim_output{mem, stream}; - trip_count = *lock_prim_output.data(); - break; - } - case data_types::i8: { - mem_lock lock_prim_output{mem, stream}; - trip_count = *lock_prim_output.data(); - break; - } - case data_types::i32: { - mem_lock lock_prim_output{mem, stream}; - trip_count = *lock_prim_output.data(); - break; - } - case data_types::i64: { - mem_lock lock_prim_output{mem, stream}; - trip_count = *lock_prim_output.data(); - break; - } - default: - throw std::runtime_error("Invalid data type : " + ov::element::Type(prim_layout.data_type).get_type_name()); - } - return trip_count; - } + input_primitive_maps(prim->input_primitive_maps), + output_primitive_maps(prim->output_primitive_maps), + back_edges(prim->back_edges) {} - template - static inline void validate_input_value(int64_t input) { - if (input < std::numeric_limits::min() || input > std::numeric_limits::max()) { - throw std::runtime_error("Invalid data value : " + std::to_string(input)); - } - } + program::ptr get_body_program() const { return get_primitive()->body_program; } - static void write_scalar_value(memory::ptr mem, stream& stream, int64_t input) { - const layout& prim_layout = mem->get_layout(); - - switch (prim_layout.data_type) { - case data_types::u8: { - validate_input_value(input); - mem_lock lock_prim_output{mem, stream}; - lock_prim_output[0] = static_cast(input); - break; - } - case data_types::i8: { - validate_input_value(input); - mem_lock lock_prim_output{mem, stream}; - lock_prim_output[0] = static_cast(input); - break; - } - case data_types::i32: { - validate_input_value(input); - mem_lock lock_prim_output{mem, stream}; - lock_prim_output[0] = static_cast(input); - break; - } - case data_types::i64: { - mem_lock lock_prim_output{mem, stream}; - lock_prim_output[0] = input; - break; - } - default: - throw std::runtime_error("Invalid data type : " + ov::element::Type(prim_layout.data_type).get_type_name()); - } - } - - layout calc_body_input_layout(const loop::io_primitive_map& inputDesc) const { - const auto& dependency_list = this->get_dependencies(); - auto input = std::find_if(dependency_list.begin(), dependency_list.end(), [&inputDesc](const std::pair& dep){ - return dep.first->id() == inputDesc.external_id; - }); - if (input == dependency_list.end()) { - throw std::runtime_error("Can't find input from dependency_list"); - } - layout calculated_layout = (*input).first->get_output_layout(); - auto shape = calculated_layout.get_tensor().sizes(calculated_layout.format); - - if (inputDesc.axis >= 0) { - iteration_axis = convert_to_raw_axis(static_cast(inputDesc.axis), shape.size()); - auto calculated_size = calculated_layout.get_tensor(); - calculated_size.raw[iteration_axis] = 1; // cropped inputs shape - calculated_layout.set_tensor(calculated_size); - } - - return calculated_layout; - } + const primitive_id& get_trip_count_id() const { return get_primitive()->trip_count_id; } + const primitive_id& get_initial_execution_id() const { return get_primitive()->first_execution_condition_id; } + const primitive_id& get_current_iteration_id() const { return get_primitive()->body_current_iteration_id; } + const primitive_id& get_execution_condition_id() const { return get_primitive()->body_execution_condition_id; } + const primitive_id& get_num_iterations_id() const { return get_primitive()->num_iteration_id; } + const int32_t get_max_num_iteration() const { return get_primitive()->max_num_iterations; } const std::vector& get_input_primitive_maps() const { return input_primitive_maps; } const std::vector& get_output_primitive_maps() const { return output_primitive_maps; } + const std::vector& get_back_edges() const { return back_edges;} void update_primitive_map(const primitive_id& prevID, const primitive_id& newID, bool external_id = true) { if (external_id) { for (auto& pm : input_primitive_maps) { - if (pm.external_id == prevID) { - pm.external_id = newID; + if (pm.external_id.pid == prevID) { + pm.external_id.pid = newID; } } for (auto& pm : output_primitive_maps) { - if (pm.external_id == prevID) { - pm.external_id = newID; + if (pm.external_id.pid == prevID) { + pm.external_id.pid = newID; } } } else { for (auto& pm : input_primitive_maps) { - if (pm.internal_id == prevID) { - pm.internal_id = newID; + if (pm.internal_id.pid == prevID) { + pm.internal_id.pid = newID; } } for (auto& pm : output_primitive_maps) { - if (pm.internal_id == prevID) { - pm.internal_id = newID; + if (pm.internal_id.pid == prevID) { + pm.internal_id.pid = newID; } } for (auto& back_edge : back_edges) { @@ -191,157 +80,266 @@ struct typed_program_node : public typed_program_node_base { } } - const std::vector& get_back_edges() const { return back_edges;} - - static bool is_integer(const data_types& data_type) { - switch (data_type) { - case data_types::u8: - case data_types::i8: - case data_types::i32: - case data_types::i64: - return true; - default: - return false; - } + // current_iteration is necessary to calculate output layout in dynamic shape + std::vector get_shape_infer_dependencies() const override { return {0}; } + + using parent::get_kernel_impl_params; + std::unique_ptr get_kernel_impl_params(const std::vector& in_layouts, const std::vector& out_layouts) const override { + auto params = parent::get_kernel_impl_params(in_layouts, out_layouts); + params->inner_progs = { get_primitive()->body_program }; + // Set memory_deps using custom get_memory_deps to add current_iteration(mutable_data) into memory_deps + params->memory_deps = get_memory_deps(); + return params; } - void process_current_iteration() const { - const primitive_id& current_iteration_id = get_current_iteration_id(); - if (current_iteration_id.empty()) { - return; - } +private: + std::map get_memory_deps() const; +}; - const topology_map& body_topology_map = body.get_primitives(); - const layout body_input_layout(data_types::i64, format::bfyx, {1, 1, 1, 1}); +using loop_node = typed_program_node; - // add current_iteration primitive if current_iteration primitive is not exist in body - if (body_topology_map.find(current_iteration_id) == body_topology_map.end()) { - body.add_primitive(std::make_shared(current_iteration_id, body_input_layout)); - } else { - const auto& body_input_prim = body.at(current_iteration_id); - const auto input_layout_prim = std::dynamic_pointer_cast(body_input_prim); - OPENVINO_ASSERT(input_layout_prim, "[GPU] current_iteration primitive should be cldnn::input_layout in node", this->id()); - input_layout_prim->change_layout(body_input_layout); +template <> +class typed_primitive_inst : public typed_primitive_inst_base { + using parent = typed_primitive_inst_base; + using parent::parent; + +public: + struct concatenated_memory_mapping { + using ptr = std::shared_ptr; + using cptr = std::shared_ptr; + concatenated_memory_mapping(int64_t axis, + memory::ptr concatenated_mem, + std::vector sliced_mems, // To change shared ptr vector + stream& stream, + engine& engine, + int64_t iteration_elements = 0, + int64_t stride = 0, + int64_t initial_offset = 0) : + axis(axis), + concatenated_mem(concatenated_mem), + sliced_mems(sliced_mems), + stream(stream), + engine(engine), + iteration_elements(iteration_elements), + stride(stride), + initial_offset(initial_offset) { + calculate_concatenated_mem(); + } + + concatenated_memory_mapping(const concatenated_memory_mapping& o) : + axis(o.axis), + concat_data_prim(o.concat_data_prim), + sliced_data_prim(o.sliced_data_prim), + + concatenated_mem(o.concatenated_mem), + sliced_mems(o.sliced_mems), + stream(o.stream), + engine(o.engine), + iteration_elements(o.iteration_elements), + stride(o.stride), + initial_offset(o.initial_offset), + + bytes_per_element(o.bytes_per_element), + batch_size(o.batch_size), + bytes_batch_stride(o.bytes_batch_stride), + bytes_iteration(o.bytes_iteration), + bytes_iteration_stride(o.bytes_iteration_stride), + bytes_iteration_initial_offset(o.bytes_iteration_initial_offset) {} + + + static int64_t get_batch_size(layout mem_layout, int64_t axis) { + if (axis < 0) { + throw std::runtime_error("axis should be positive integer or zero"); + } + + if (mem_layout.is_dynamic()) { + return -1; + } + + int64_t batch_size = 1; + for (int64_t i = 0; i < axis; ++i) { + batch_size *= mem_layout.get_tensor().raw[i]; + } + for (int64_t i = axis-1; i >= 2; --i) { + batch_size *= mem_layout.get_tensor().raw[i]; + } + return batch_size; } - // add incremental data: 1 - // it is used to update current_iteration in body network - const primitive_id increment_value_id = current_iteration_id + "_inc"; - auto mem = get_program().get_engine().allocate_memory(body_input_layout); - auto& stream = get_program().get_stream(); - write_scalar_value(mem, stream, 1); - body.add_primitive(std::make_shared(increment_value_id, mem)); - - // add eltwise sum updating current_iteration with incremental data - const primitive_id updated_currnet_iteration_id = current_iteration_id + "_update"; - body.add_primitive(std::make_shared(updated_currnet_iteration_id, - current_iteration_id, increment_value_id, eltwise_mode::sum)); - - // set backedge - back_edges.emplace_back(updated_currnet_iteration_id, current_iteration_id); - } + void calculate_concatenated_mem() const { + if (!sliced_mems.empty() && concatenated_mem != nullptr) { + auto& sliced_layout = sliced_mems.front()->get_layout(); + const int64_t num_elements_batch = get_batch_size(sliced_layout, axis); + iteration_elements = sliced_layout.count() / num_elements_batch; + bytes_per_element = data_type_traits::size_of(concatenated_mem->get_layout().data_type); + batch_size = get_batch_size(concatenated_mem->get_layout(), axis); + bytes_batch_stride = (static_cast(concatenated_mem->get_layout().count()) / batch_size) * bytes_per_element; + bytes_iteration = iteration_elements * bytes_per_element; + bytes_iteration_stride = stride * bytes_iteration; + bytes_iteration_initial_offset = initial_offset * bytes_iteration; + } + } - void process_single_int_output(const primitive_id& id) const { - // add mutable if not exist - const topology_map& body_topology_map = body.get_primitives(); - layout body_output_layout(data_types::i64, format::bfyx, {1, 1, 1, 1}); - if (!id.empty()) { - auto body_output = body_topology_map.find(id); - if (body_output == body_topology_map.end()) { - auto mem = get_program().get_engine().allocate_memory(body_output_layout); - auto md = std::make_shared(id, mem); - body.add_primitive(md); + void update_concatenated_mem(memory::ptr mem) { + if (concatenated_mem != nullptr && concatenated_mem->get_layout() == mem->get_layout()) { + concatenated_mem = mem; } else { - auto body_output_prim = body.at(body_output->first); - auto mem = get_program().get_engine().allocate_memory(body_output_layout); - body_output_prim.reset(new mutable_data(body_output->first, std::move(mem))); + concatenated_mem = mem; + calculate_concatenated_mem(); } } - } - void build_body_program() const { - for (const auto& pm : input_primitive_maps) { - layout calculated_layout = calc_body_input_layout(pm); - const primitive_id& internal_input_id = pm.internal_id; + void restore_concatenated_mem() const { + OPENVINO_ASSERT(concatenated_mem != nullptr, "concatenated_mem should not be nullptr"); + mem_lock concat_mem_lock{ concatenated_mem, stream }; + int64_t iteration_offset = bytes_iteration_initial_offset; + for (const auto& sliced_mem : sliced_mems) { + // To support multi-batch, just repeat memcpy for each batch + for (int64_t batch = 0; batch < batch_size; ++batch) { + const int64_t src_offset = batch * bytes_iteration; + const int64_t dst_offset = batch * bytes_batch_stride + iteration_offset; + mem_lock sliced_mem_lock{ sliced_mem, stream }; + uint8_t* src = sliced_mem_lock.data() + src_offset; + uint8_t* dst = concat_mem_lock.data() + dst_offset; + std::copy(src, src + bytes_iteration, dst); + } + iteration_offset += bytes_iteration_stride; + } + } - // add inputs for body network if not exist - if (body.get_primitives().count(internal_input_id) == 0) { - body.add_primitive(std::make_shared(internal_input_id, calculated_layout)); - } else { - body.change_input_layout(internal_input_id, calculated_layout); + // Get sliced mem for the iteration idx and copy data from external input to sliced mem + // In the case of dynamic model, concatenated_mem is always non nullptr. + memory::ptr get_sliced_mem(int64_t iteration) const { + OPENVINO_ASSERT(!sliced_mems.empty(), "For input data, sliced_mems should not be empty"); + mem_lock from_lock{ concatenated_mem, stream }; + int64_t batch_offset = 0; + auto sliced_mem = get_or_create_sliced_mem(iteration, sliced_mems.front()->get_layout()); + const int64_t iteration_offset = bytes_iteration_initial_offset + + bytes_iteration_stride * iteration; + // To support multi-batch, just repeat memcpy for each batch + for (int64_t batch = 0; batch < batch_size; ++batch) { + const int64_t src_offset = batch_offset + iteration_offset; + const int64_t dst_offset = batch * bytes_iteration; + mem_lock to_lock{ sliced_mem, stream }; + const auto src = from_lock.begin() + src_offset; + const auto dst = to_lock.begin() + dst_offset; + std::copy(src, src + bytes_iteration, dst); + batch_offset += bytes_batch_stride; } + return sliced_mem; } - // setup internal output - OPENVINO_ASSERT(!output_primitive_maps.empty(), "[GPU] Output primitive map should have at least 1 mapping in primitive ", this->id()); - std::set output_names; - output_names.insert(output_primitive_maps.front().internal_id); - - // add current_iteration_id in body network, condition_id if exist - process_current_iteration(); - process_single_int_output(get_condition_id()); - - // setup outputs for backedges - for (auto& back_edge : back_edges) { - // check whether the back_edge.to has its corresponding io_primitive_map - const auto& input_map = std::find_if(input_primitive_maps.begin(), input_primitive_maps.end(), - [&](const loop::io_primitive_map& pm) { - return pm.internal_id == back_edge.to; - }); - - // backedge which is current_iteration does not have - // input primitive map because its initial value is always - // zero and the value will be set in execute_impl() - if (back_edge.to != get_current_iteration_id() && input_map == input_primitive_maps.end()) { - std::string msg = "[GPU] No primitive mapping for backedge (internal_id: " + back_edge.to + ") for primitive " + this->id(); - OPENVINO_ASSERT(false, msg.c_str()); + memory::ptr get_or_create_sliced_mem(int64_t idx, const layout& mem_layout) const { + bool recalc_data = !sliced_mems.empty(); + while (sliced_mems.size() <= static_cast(idx)) { + memory::ptr sliced_mem = engine.allocate_memory(mem_layout, 0); + sliced_mems.push_back(sliced_mem); } + if (recalc_data) { + calculate_concatenated_mem(); + } + return sliced_mems.at(idx); + } - output_names.insert(back_edge.from); + void setup_sliced_output_memory(uint64_t iteration) const { + if (sliced_data_prim) { + OPENVINO_ASSERT(iteration < sliced_mems.size(), "invalid index"); + const auto& sliced_output_mem = sliced_mems.at(iteration); + sliced_data_prim->set_output_memory(sliced_output_mem); + } } - // if execution_condition_id is specified, we need to add the id in build_option::outputs - if (!get_condition_id().empty()) { - output_names.insert(get_condition_id()); + std::vector& get_sliced_mems() const { return sliced_mems; } + + void reset_data_for_shape_changed() { + bytes_per_element = 0; + batch_size = 0; + bytes_batch_stride = 0; + bytes_iteration = 0; + bytes_iteration_stride = 0; + bytes_iteration_initial_offset = 0; + if (concatenated_mem) concatenated_mem = nullptr; + iteration_elements = 0; + sliced_mems.clear(); } - std::vector output_names_vec(output_names.begin(), output_names.end()); - auto config = get_program().get_config(); - config.set_property(ov::intel_gpu::custom_outputs(output_names_vec)); - body_program = program::build_program(get_program().get_engine(), body, config, get_program().get_task_executor(), false, false, true); - } + std::string to_string() const { + std::stringstream ss; + ss << "concatenated_memory_mapping [" << std::endl; + ss << "* axis : " << axis << std::endl; + ss << "* bytes_per_element : " << bytes_per_element << std::endl; + ss << "* batch_size : " << batch_size << std::endl; + if (concatenated_mem != nullptr && concatenated_mem->get_layout().is_static()) { + ss << "* bytes_batch_stride : " << bytes_batch_stride << " = (static_cast(" + << concatenated_mem->get_layout().count() << ") / batch_size:" << batch_size << ") * bytes_per_element:" << bytes_per_element << std::endl; + } else { + ss << "* bytes_batch_stride : " << bytes_batch_stride << std::endl; + } + ss << "* bytes_iteration : " << bytes_iteration << " = (iteration_elements:" + << iteration_elements << " * bytes_per_element:" << bytes_per_element << ")" << std::endl; + ss << "* bytes_iteration_stride : " << bytes_iteration_stride << std::endl; + ss << "* bytes_iteration_initial_offset : " << bytes_iteration_initial_offset << std::endl; + ss << "* concat_data_prim : " << ((concat_data_prim != nullptr)? concat_data_prim->id() : "nullptr") << std::endl; + ss << "* sliced_data_prim : " << ((sliced_data_prim != nullptr)? sliced_data_prim->id() : "nullptr") << std::endl; + if (concatenated_mem) { + ss << "* concatenated_mem : " << concatenated_mem->get_layout().to_short_string() << std::endl; + } else { + ss << "* concatenated_mem : nullptr" << std::endl; + } + ss << "* iteration_elements : " << iteration_elements << std::endl; + ss << "* stride : " << stride << std::endl; + ss << "* initial_offset : " << initial_offset << std::endl; + ss << "* sliced_mems :{ "; + for (auto mem : sliced_mems) { + ss << mem->get_layout().to_short_string() << ","; + } + ss << "}]" << std::endl; + return ss.str(); + } - const primitive_id& get_trip_count_id() const { return get_primitive()->trip_count_id; } - const primitive_id& get_initial_execution_id() const { return get_primitive()->initial_execution_id; } - const primitive_id& get_current_iteration_id() const { return get_primitive()->current_iteration_id; } - const primitive_id& get_condition_id() const { return get_primitive()->condition_id; } - const primitive_id& get_num_iteration_id() const { return get_primitive()->num_iteration_id; } - const topology& get_body_topology() const { return get_primitive()->body; } -}; + const int64_t axis; + std::shared_ptr concat_data_prim; + std::shared_ptr sliced_data_prim; -using loop_node = typed_program_node; +private: + mutable memory::ptr concatenated_mem; + mutable std::vector sliced_mems; + cldnn::stream& stream; + cldnn::engine& engine; + mutable int64_t iteration_elements = 0; + const int64_t stride = 0; + const int64_t initial_offset = 0; -template <> -class typed_primitive_inst : public typed_primitive_inst_base { - using parent = typed_primitive_inst_base; - using parent::parent; + // element size + mutable int64_t bytes_per_element; + // number of higher level of dimension of slicing axis + mutable int64_t batch_size; + // stride of batch in concatenated memory + mutable int64_t bytes_batch_stride; + // byte size of each iteration per batch in a sliced memory + mutable int64_t bytes_iteration; + // byte size of each iteration (bytes_iteration * batch_size) in a sliced memory + mutable int64_t bytes_iteration_stride; + // byte offset of 1st iteration in a batch in a sliced memory + mutable int64_t bytes_iteration_initial_offset; + }; -public: struct backedge_memory_mapping { enum backedge_type { // output memory(from_primitive) of body network needs to be concatenated CONCAT_OUTPUT, - // output memory(from_primitive) of body network does not need to be concateneated + // output memory(from_primitive) of body network does not need to be concatenated // input memory is shared by output memory SINGLE_SHARED, - // output memory(from_primitive) of body network does not need to be concateneated - // input memory is not shared by output memroy + // output memory(from_primitive) of body network does not need to be concatenated + // input memory is not shared by output memory // each iteration input memory and output memory are swapped SINGLE, }; std::shared_ptr from_primitive; std::shared_ptr to_primitive; - std::vector from_mems; + std::shared_ptr concat_mem_mapping; + mutable memory::ptr from_mem; memory::ptr initial_mem; cldnn::stream& stream; backedge_type type; @@ -349,10 +347,11 @@ class typed_primitive_inst : public typed_primitive_inst_base { backedge_memory_mapping( std::shared_ptr _from_primitive, std::shared_ptr _to_primitive, - std::vector _from_mems, memory::ptr _initial_mem, cldnn::stream& _stream, backedge_type _type = CONCAT_OUTPUT): + std::shared_ptr _concat_mem_mapping, memory::ptr _initial_mem, + cldnn::stream& _stream, backedge_type _type = CONCAT_OUTPUT): from_primitive(_from_primitive), to_primitive(std::move(_to_primitive)), - from_mems(_from_mems), + concat_mem_mapping(std::move(_concat_mem_mapping)), initial_mem(std::move(_initial_mem)), stream(_stream), type(_type), @@ -365,7 +364,7 @@ class typed_primitive_inst : public typed_primitive_inst_base { memory::ptr _from_mem, memory::ptr _initial_mem, cldnn::stream& _stream, backedge_type _type = SINGLE_SHARED): from_primitive(_from_primitive), to_primitive(std::move(_to_primitive)), - from_mems{std::move(_from_mem)}, + from_mem{std::move(_from_mem)}, initial_mem(std::move(_initial_mem)), stream(_stream), type(_type), @@ -385,161 +384,67 @@ class typed_primitive_inst : public typed_primitive_inst_base { validate_backedge_memory(); } - void setup_iteration(int64_t iter) const { - if (type == CONCAT_OUTPUT) { - if (iter == 0) { - to_primitive->set_output_memory(initial_mem); - } else if (iter > 0) { - to_primitive->set_output_memory(from_mems.at(iter - 1)); - } else { - throw std::runtime_error("Invalid iteraton count" + std::to_string(iter)); - } - } else if (type == SINGLE_SHARED && iter == 0) { - from_mems.front()->copy_from(stream, *initial_mem); - } else if (type == SINGLE) { - memory::ptr mem1 = to_primitive->output_memory_ptr(); - if (iter == 0) { - mem1->copy_from(stream, *initial_mem); - } else { - memory::ptr mem2 = from_primitive->output_memory_ptr(); - to_primitive->set_output_memory(std::move(mem2)); - from_primitive->set_output_memory(mem1); - } - } - } - private: void validate_backedge_memory() { - for (const auto& from_mem : from_mems) { + if (from_mem) { const size_t from_mem_bytes = from_mem->get_layout().bytes_count(); - if (from_mem_bytes != total_bytes) { - throw std::runtime_error("Invalid backedge memory layout: " - "size not matched with that of initial_mem"); - } + OPENVINO_ASSERT((from_mem_bytes == total_bytes), "Invalid backedge memory layout: size(", + from_mem_bytes, ",", from_mem->get_layout().to_short_string(), + ") not matched with that of initial_mem(", total_bytes, + ",", initial_mem->get_layout().to_short_string(), ")"); } - } - }; - - struct concatenated_memory_mapping { - concatenated_memory_mapping(int64_t axis, - memory::ptr concatenated_mem, - std::vector sliced_mems, - stream& stream, - int64_t iteration_elements = 0, - int64_t stride = 0, - int64_t initial_offset = 0) : - axis(axis), - concatenated_mem(concatenated_mem), - sliced_mems(sliced_mems), - stream(stream), - bytes_per_element(data_type_traits::size_of(concatenated_mem->get_layout().data_type)), - batch_size(get_batch_size(concatenated_mem->get_layout(), axis)), - bytes_batch_stride((static_cast(concatenated_mem->get_layout().count()) / batch_size) * bytes_per_element), - bytes_iteration(iteration_elements * bytes_per_element), - bytes_iteration_stride(stride * bytes_iteration), - bytes_iteration_initial_offset(initial_offset * bytes_iteration) {} - - static int64_t get_batch_size(layout mem_layout, int64_t axis) { - if (axis < 0) { - throw std::runtime_error("axis should be positive integer or zero"); - } - - int64_t batch_size = 1; - for (int64_t i = 0; i < axis; ++i) { - batch_size *= mem_layout.get_tensor().raw[i]; - } - for (int64_t i = axis-1; i >= 2; --i) { - batch_size *= mem_layout.get_tensor().raw[i]; - } - return batch_size; - } - - void restore_concatenated_mem() const { - mem_lock concat_mem_lock{ concatenated_mem, stream }; - int64_t iteration_offset = bytes_iteration_initial_offset; - for (const auto& sliced_mem : sliced_mems) { - for (int64_t batch = 0; batch < batch_size; ++batch) { - const int64_t src_offset = batch * bytes_iteration; - const int64_t dst_offset = batch * bytes_batch_stride + iteration_offset; - mem_lock sliced_mem_lock{ sliced_mem, stream }; - uint8_t* src = sliced_mem_lock.data() + src_offset; - uint8_t* dst = concat_mem_lock.data() + dst_offset; - std::copy(src, src + bytes_iteration, dst); + if (concat_mem_mapping) { + for (const auto& from_mem : concat_mem_mapping->get_sliced_mems()) { + const size_t from_mem_bytes = from_mem->get_layout().bytes_count(); + OPENVINO_ASSERT((from_mem_bytes == total_bytes), "Invalid backedge memory layout: size(", + from_mem_bytes, ",", from_mem->get_layout().to_short_string(), + ") not matched with that of initial_mem(", total_bytes, + ",", initial_mem->get_layout().to_short_string(), ")"); } - iteration_offset += bytes_iteration_stride; } } - - void setup_sliced_output_memory(uint64_t iteration) const { - const auto& sliced_output_mem = sliced_mems.at(iteration); - sliced_data_prim->set_output_memory(sliced_output_mem); - } - - memory::ptr get_sliced_mem(int64_t iteration) const { - mem_lock from_lock{ concatenated_mem, stream }; - int64_t batch_offset = 0; - const int64_t iteration_offset = bytes_iteration_initial_offset + - bytes_iteration_stride * iteration; - for (int64_t batch = 0; batch < batch_size; ++batch) { - const int64_t src_offset = batch_offset + iteration_offset; - const int64_t dst_offset = batch * bytes_iteration; - mem_lock to_lock{ sliced_mems.at(iteration), stream }; - const auto src = from_lock.begin() + src_offset; - const auto dst = to_lock.begin() + dst_offset; - std::copy(src, src + bytes_iteration, dst); - batch_offset += bytes_batch_stride; - } - return sliced_mems.at(iteration); - } - - const int64_t axis; - std::shared_ptr concat_data_prim; - std::shared_ptr sliced_data_prim; - memory::ptr concatenated_mem; - std::vector sliced_mems; - cldnn::stream& stream; - // element size - const int64_t bytes_per_element; - // number of higher level of dimension of slicing axis - const int64_t batch_size; - // stride of batch in concatanated memory - const int64_t bytes_batch_stride; - // byte size of each iteration per batch in a sliced memory - const int64_t bytes_iteration; - // byte size of each iteration (bytes_iteration * batch_size) in a sliced memory - const int64_t bytes_iteration_stride; - // byte offset of 1st iteration in a batch in a sliced memory - const int64_t bytes_iteration_initial_offset; }; - static layout calc_output_layout(const loop_node& node, kernel_impl_params const& impl_param); + template + static std::vector calc_output_layouts(loop_node const& /*node*/, kernel_impl_params const& impl_param); + static layout calc_output_layout(const loop_node& /*node*/, kernel_impl_params const& impl_param); bool preproc_memories_done = false; std::vector backedge_memory_mappings; - std::vector concatenated_input_mem_mappings; - std::vector concatenated_output_mem_mappings; + std::vector concatenated_input_mem_mappings; + std::vector concatenated_output_mem_mappings; static std::string to_string(const loop_node& node); - size_t current_iteratoin_backedge_mapping_idx = 0; public: typed_primitive_inst(network& network, const loop_node& node); network::ptr get_body_network() const { return body_network; } - void preprocess_input_memory(); - void preprocess_output_memory(); + void preprocess_input_memory(const int64_t trip_count); + void preprocess_output_memory(const int64_t trip_count); void preprocess_backedge_memory(); void update_mapped_memory(); + void update_input_mapped_memory(); + void update_output_mapped_memory(); + void update_backedge_mapped_memory(); + void postprocess_output_memory(bool is_dynamic); + concatenated_memory_mapping::ptr create_concat_memory_map(const input_info& id, + const cldnn::loop::io_primitive_map& io_prim_map, + memory::ptr mem_ptr, + const int64_t trip_count); event::ptr set_output_memory(memory::ptr mem, bool check = true, size_t idx = 0) override; - const backedge_memory_mapping& get_current_iteration_backedge_mapping() const { - OPENVINO_ASSERT(node->is_current_iteration_used(), "[GPU] No backedge mapping for current_iteration for primitive ", node->id()); - return backedge_memory_mappings.at(current_iteratoin_backedge_mapping_idx); - } + void reset_memory(); + void save(BinaryOutputBuffer& ob) const override; void load(BinaryInputBuffer& ib) override; + void validate_backedges(loop_node const & node) const; + + void update_shape() override { primitive_inst::update_shape(); } + void update_output_layout(); private: network::ptr body_network; - memory::ptr get_external_memory(const primitive_id& external_id) const; - std::vector get_sliced_mem(const primitive_id& internal_id) const; + memory::ptr get_external_memory(const primitive_id& external_id, size_t mem_idx = 0) const; + layout get_external_output_layout(const primitive_id& external_id, size_t mem_idx = 0) const; + std::shared_ptr get_sliced_mem(const primitive_id& internal_id) const; std::vector _input_primitive_maps; std::vector _output_primitive_maps; std::vector _back_edges; @@ -547,9 +452,13 @@ class typed_primitive_inst : public typed_primitive_inst_base { primitive_id _initial_execution_id; primitive_id _current_iteration_id; primitive_id _condition_id; - primitive_id _num_iteration_id; - int64_t _max_iteration = 0; + primitive_id _num_iterations_id; }; using loop_inst = typed_primitive_inst; + +static inline std::ostream& operator<< (std::ostream& os, loop_inst::concatenated_memory_mapping& map) { + os << map.to_string(); + return os; +} } // namespace cldnn diff --git a/src/plugins/intel_gpu/src/graph/include/rms_inst.h b/src/plugins/intel_gpu/src/graph/include/rms_inst.h new file mode 100644 index 00000000000000..a7800249f40421 --- /dev/null +++ b/src/plugins/intel_gpu/src/graph/include/rms_inst.h @@ -0,0 +1,44 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once +#include "intel_gpu/primitives/rms.hpp" +#include "primitive_inst.h" + +#include + +namespace cldnn { + +template <> +struct typed_program_node : public typed_program_node_base { + using parent = typed_program_node_base; + +public: + using parent::parent; + + program_node& input(size_t index = 0) const { return get_dependency(index); } + std::vector get_shape_infer_dependencies() const override { return {}; } +}; + +using rms_node = typed_program_node; + +template <> +class typed_primitive_inst : public typed_primitive_inst_base { + using parent = typed_primitive_inst_base; + using parent::parent; + +public: + template + static std::vector calc_output_layouts(rms_node const& /*node*/, const kernel_impl_params& impl_params) { + return forward_input0_shape(impl_params); + } + static layout calc_output_layout(rms_node const& node, kernel_impl_params const& impl_params); + static std::string to_string(rms_node const& node); + + typed_primitive_inst(network& network, rms_node const& node); +}; + +using rms_inst = typed_primitive_inst; + +} // namespace cldnn diff --git a/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp b/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp index 63e1b04e5dbf91..69b1e12fa3b4ae 100644 --- a/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp +++ b/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp @@ -32,6 +32,7 @@ #include "region_yolo_inst.h" #include "prior_box_inst.h" #include "scatter_nd_update_inst.h" +#include "gather_inst.h" #include "to_string_utils.h" #include #include @@ -306,7 +307,7 @@ bool layout_optimizer::can_fuse_reorder(program_node& prev, program_node& next, (fmt_prev == format::b_fs_yx_fsv4 && prev_output_layout.feature() % 32 == 0 && prev_output_layout.spatial(0) == 1 && - prev_output_layout.spatial(1) == 1))) + prev_output_layout.spatial(1) == 1)) && is_input_reorder(prev, next)) return true; if (next.is_type() && fmt_prev == format::b_fs_yx_fsv16 && fmt_next == format::b_fs_yx_fsv4 && is_input_idx(0)) @@ -849,6 +850,18 @@ static bool is_node_for_onednn(reduce_node const& node, format preferred_format) return true; } +static bool is_node_for_onednn(convolution_node const& node) { + if (!layout_optimizer::are_data_types_suitable_for_onednn((program_node&)node)) + return false; + + auto input_layout = node.get_input_layout(0); + auto output_layout = node.get_output_layout(0); + if (input_layout.is_dynamic() || output_layout.is_dynamic()) + return false; + + return true; +} + static bool is_node_for_onednn(deconvolution_node const& node) { auto prim = node.get_primitive(); auto input_layout = node.get_input_layout(0); @@ -871,6 +884,9 @@ static bool is_node_for_onednn(deconvolution_node const& node) { static bool is_node_for_onednn(fully_connected_node const& node) { + if (!layout_optimizer::are_data_types_suitable_for_onednn((program_node&)node)) + return false; + auto fc_prim = node.get_primitive(); // onednn impl doesn't support compressed weights for now if (fc_prim->compressed_weights) @@ -891,6 +907,10 @@ static bool is_node_for_onednn(fully_connected_node const& node) { return true; } +static bool is_node_for_onednn(gemm_node const& node) { + return layout_optimizer::are_data_types_suitable_for_onednn((program_node&)node); +} + // This function is needed to avoid performance regressions for the convolutions with byxf layout // Previously some topologies had scale operations which prevented byxf usage // Now instead of scale we have eltwise + fused_ops which might enable byxf convolution in unexpected cases @@ -1242,6 +1262,20 @@ format layout_optimizer::get_expected_format(quantize_node const& node) { return expected; } +bool layout_optimizer::is_node_suitable_for_onednn(program_node& node) { + if (node.is_type()) { + return is_node_for_onednn(node.as()); + } else if (node.is_type()) { + return is_node_for_onednn(node.as()); + } else if (node.is_type()) { + return is_node_for_onednn(node.as()); + } else if (node.is_type()) { + return is_node_for_onednn(node.as()); + } + + return false; +} + bool layout_optimizer::are_data_types_suitable_for_onednn(program_node& node) { auto in_dt = node.get_input_layout(0).data_type; auto out_dt = node.get_output_layout(false).data_type; @@ -1535,28 +1569,32 @@ impl_types layout_optimizer::get_preferred_impl_type(program_node& node, format std::vector onednn_optimized_formats = { format::byxf, format::bzyxf, - format::b_fs_zyx_fsv32, - format::b_fs_yx_fsv32, - format::b_fs_zyx_fsv16, + format::b_fs_yx_fsv8, + format::b_fs_zyx_fsv8, format::b_fs_yx_fsv16, - format::bs_fs_zyx_bsv16_fsv16, + format::b_fs_zyx_fsv16, + format::b_fs_yx_fsv32, + format::b_fs_zyx_fsv32, + format::bs_fs_yx_bsv4_fsv2, + format::bs_fs_yx_bsv4_fsv4, + format::bs_fs_yx_bsv8_fsv2, + format::bs_fs_zyx_bsv8_fsv2, + format::bs_fs_yx_bsv8_fsv4, + format::bs_fs_zyx_bsv8_fsv4, + format::bs_fs_yx_bsv16_fsv2, + format::bs_fs_zyx_bsv16_fsv2, + format::bs_fs_yx_bsv16_fsv4, + format::bs_fs_zyx_bsv16_fsv4, + format::bs_fs_yx_bsv16_fsv8, + format::bs_fs_zyx_bsv16_fsv8, format::bs_fs_yx_bsv16_fsv16, - format::bs_fs_zyx_bsv16_fsv32, + format::bs_fs_zyx_bsv16_fsv16, format::bs_fs_yx_bsv16_fsv32, - format::bs_fs_zyx_bsv32_fsv16, + format::bs_fs_zyx_bsv16_fsv32, format::bs_fs_yx_bsv32_fsv16, - format::bs_fs_zyx_bsv32_fsv32, + format::bs_fs_zyx_bsv32_fsv16, format::bs_fs_yx_bsv32_fsv32, - format::bs_fs_zyx_bsv8_fsv4, - format::bs_fs_yx_bsv8_fsv4, - format::bs_fs_yx_bsv16_fsv4, - format::bs_fs_zyx_bsv16_fsv4, - format::bs_fs_yx_bsv16_fsv2, - format::bs_fs_zyx_bsv16_fsv2, - format::bs_fs_zyx_bsv8_fsv2, - format::bs_fs_yx_bsv8_fsv2, - format::bs_fs_yx_bsv4_fsv4, - format::bs_fs_yx_bsv4_fsv2, + format::bs_fs_zyx_bsv32_fsv32, }; impl_types impl_candidate = impl_types::onednn; @@ -1715,9 +1753,9 @@ format layout_optimizer::get_preferred_format(program_node& node) { expected = get_expected_format(node.as()); } else if (node.is_type()) { auto input_layout = node.get_input_layout(0); - if (input_layout.format.dimension() == 5 && - (input_layout.data_type == data_types::f32 || input_layout.data_type == data_types::f16)) - expected = format::bfzyx; + if (input_layout.data_type == data_types::f32 || input_layout.data_type == data_types::f16) { + expected = format::get_default_format(input_layout.get_rank()); + } } else if (node.is_type()) { // if the resample is in the last part of the network and there are no users using blocked format, // it is better to reorder to bfyx before resample is done. @@ -1766,6 +1804,10 @@ format layout_optimizer::get_preferred_format(program_node& node) { node.set_preferred_input_fmt(0, format::bfyx); } } + } else if (node.is_type()) { + // Gather needs the original input/output rank because + // the parameters as indices, batch_dims and axis depend on the rank. + node.set_preferred_input_fmt(0, format::get_default_format(node.as().get_primitive()->input_rank)); } if (allow_new_shape_infer && node.get_preferred_input_fmt() != format::any) { @@ -2085,6 +2127,10 @@ void layout_optimizer::set_implementation_forcing(const ov::intel_gpu::ImplForci } } +const std::map> layout_optimizer::get_implementation_forcing() const { + return _forcing_map; +} + const std::vector> layout_optimizer::optimized_formats = { {format::b_fs_yx_fsv16, true}, {format::b_fs_yx_fsv16, false}, diff --git a/src/plugins/intel_gpu/src/graph/loop.cpp b/src/plugins/intel_gpu/src/graph/loop.cpp index 4e33f14e507084..a51c2d0d85973e 100644 --- a/src/plugins/intel_gpu/src/graph/loop.cpp +++ b/src/plugins/intel_gpu/src/graph/loop.cpp @@ -3,6 +3,8 @@ // #include "loop_inst.h" +#include "data_inst.h" +#include "mutable_data_inst.h" #include "json_object.h" #include "primitive_type_base.h" #include "intel_gpu/primitives/data.hpp" @@ -15,6 +17,41 @@ namespace cldnn { GPU_DEFINE_PRIMITIVE_TYPE_ID(loop) +std::map loop_node::get_memory_deps() const { + auto memory_deps = get_const_memory_deps(); + for (auto& i : get_shape_infer_dependencies()) { + auto& dep = get_dependency(i); + auto dep_id = dep.id(); + if (memory_deps.count(i) > 0 || i >= get_dependencies().size()) { + continue; + } + + memory::ptr mem_ptr = nullptr; + if (dep.is_type()) { + mem_ptr = dep.as().get_attached_memory_ptr(); + } else if (dep.is_type()) { + mem_ptr = dep.as().get_attached_memory_ptr(); + } + + if (mem_ptr) { + memory_deps.insert({i, mem_ptr}); + } + } + return memory_deps; +} + +static size_t convert_to_raw_axis(size_t axis, size_t ndim) { + // convert between bfyx, bfzyx, bfzyxw and tensor.size.raw + if (axis >= ndim) { + throw std::runtime_error("axis should be less than ndim"); + } + + if (axis < 2) { + return axis; + } + return (ndim - 1) - (axis - 2); +} + static bool check_if_axis_is_set_properly(loop_node const & node) { const auto& input_primitive_maps = node.get_input_primitive_maps(); @@ -30,11 +67,11 @@ static bool check_if_axis_is_set_properly(loop_node const & node) { int32_t iteration_size = -1; for (const auto& pm : input_with_axis_iteration) { auto found = std::find_if(dependencies.begin(), dependencies.end(), - [&pm](const std::pair& dep){ return dep.first->id() == pm.get().external_id; }); + [&pm](const std::pair& dep){ return dep.first->id() == pm.get().external_id.pid; }); assert(found != dependencies.end()); const layout input_layout = (*found).first->get_output_layout(); const auto shape = input_layout.get_tensor().sizes(input_layout.format); - const size_t iteration_axis = node.convert_to_raw_axis(pm.get().axis, static_cast(shape.size())); + const size_t iteration_axis = convert_to_raw_axis(pm.get().axis, static_cast(shape.size())); if (iteration_size < 0) { iteration_size = shape[iteration_axis]; } else { @@ -48,7 +85,7 @@ static bool check_if_axis_is_set_properly(loop_node const & node) { for (const auto& input_ref : input_with_axis_iteration) { const loop::io_primitive_map& input = input_ref.get(); auto dep = std::find_if(dependencies.begin(), dependencies.end(), - [&input](const std::pair& dep) { return input.external_id == dep.first->id(); }); + [&input](const std::pair& dep) { return input.external_id.pid == dep.first->id(); }); // if corresponding external id is not found if (dep == dependencies.end()) { @@ -58,75 +95,104 @@ static bool check_if_axis_is_set_properly(loop_node const & node) { return true; } -static void validate_backedges(loop_node const & node) { - const auto& back_edges = node.get_back_edges(); - const auto& input_primitive_maps = node.get_input_primitive_maps(); +layout loop_inst::calc_output_layout(loop_node const& /*node*/, kernel_impl_params const& impl_param) { + auto prim = impl_param.typed_desc(); - // check input with iteration axis has backedge - for (const auto& back_edge : back_edges) { - for (const auto& mapping : input_primitive_maps) { - if (mapping.internal_id == back_edge.to && mapping.axis >= 0) { - CLDNN_ERROR_MESSAGE(node.id(), - "input with iteration axis should not have backedges"); - } - } - } -} + // finds internal output + const auto& output_primitive_maps = prim->output_primitive_maps; + const auto& output_mapping = output_primitive_maps.front(); -layout loop_inst::calc_output_layout(loop_node const & node, kernel_impl_params const& impl_param) { - // body program should be built here to calculate body input layout - // from outputs of loop's dependency and calculate loop output layout - // from the outputs of body program - if (!node.get_body_program()) { - const_cast(node).build_body_program(); - } + const auto& body_program = impl_param.inner_progs.front(); + const auto& body_outputs = body_program->get_outputs(); - // type checks - const primitive_id& num_iteration_id = node.get_num_iteration_id(); - if (!node.get_program().get_node(num_iteration_id).is_type()) { - CLDNN_ERROR_MESSAGE(node.id(), "num_iteration is not mutable_data"); + const primitive_id& output_internal_id = output_mapping.internal_id.pid; + auto target = std::find_if(body_outputs.begin(), body_outputs.end(), [&](const cldnn::program_node * output) { + return output->id() == output_internal_id; + }); + OPENVINO_ASSERT(target != body_outputs.end(), impl_param.desc->id, "output not found"); + + // set body output layout + layout loop_output_layout = (*target)->get_output_layout(); + const int64_t axis_to_iterate_through = output_mapping.axis; + if (axis_to_iterate_through != -1) { + const size_t ndim = loop_output_layout.get_rank(); + auto shape = loop_output_layout.get_dims(); + shape[axis_to_iterate_through] = static_cast(prim->max_num_iterations); + loop_output_layout.set_tensor(tensor(format::get_default_format(ndim), shape)); } - if (!check_if_axis_is_set_properly(node)) { - CLDNN_ERROR_MESSAGE(node.id(), "axis is not set properly"); - } + return loop_output_layout; +} +template +static std::vector get_output_layouts(kernel_impl_params const& impl_param, std::vector body_outputs, const int64_t num_iterations = -1) { + auto prim = impl_param.typed_desc(); + std::vector output_layouts; + + const auto& output_primitive_maps = prim->output_primitive_maps; + for (auto& output_mapping : output_primitive_maps) { + const primitive_id& output_internal_id = output_mapping.internal_id.pid; + auto target = std::find_if(body_outputs.begin(), body_outputs.end(), [&](const T output) { + return output->id() == output_internal_id; + }); + OPENVINO_ASSERT(target != body_outputs.end(), impl_param.desc->id, "output not found"); - // finds internal output - const auto& output_primitive_maps = node.get_output_primitive_maps(); - const auto& output_mapping = output_primitive_maps.front(); - const auto& body_outputs = node.get_body_program()->get_outputs(); - const primitive_id& output_internal_id = output_mapping.internal_id; - auto target = std::find_if(body_outputs.begin(), body_outputs.end(), [&](const cldnn::program_node * output) { - return output->id() == output_internal_id; - }); - layout loop_output_layout; - if (target == body_outputs.end()) { - CLDNN_ERROR_MESSAGE(impl_param.desc->id, "output not found"); - } else { // set body output layout - loop_output_layout = (*target)->get_output_layout(); - const int64_t axis_to_iterate_throgh = output_mapping.axis; - if (axis_to_iterate_throgh != -1) { - const size_t ndim = loop_output_layout.get_rank(); - auto shape = loop_output_layout.get_dims(); - shape[axis_to_iterate_throgh] = static_cast(node.get_max_iteration()); - loop_output_layout.set_tensor(tensor(format::get_default_format(ndim), shape)); + layout loop_output_layout = (*target)->get_output_layout(); + const int64_t axis_to_iterate_through = output_mapping.axis; + if (axis_to_iterate_through != -1) { + auto shape = loop_output_layout.get_partial_shape(); + shape[axis_to_iterate_through] = static_cast(num_iterations); + loop_output_layout.set_partial_shape(shape); } + output_layouts.push_back(loop_output_layout); } - return loop_output_layout; + return output_layouts; +} + +template +std::vector loop_inst::calc_output_layouts(loop_node const& /*node*/, kernel_impl_params const& impl_param) { + std::vector output_layouts; + auto prim = impl_param.typed_desc(); + if (impl_param.inner_nets.empty()) { + OPENVINO_ASSERT(impl_param.inner_progs.size() == 1, "Loop(", prim->id, ") should have only one inner network"); + const auto& body_outputs = impl_param.inner_progs.front()->get_outputs(); + output_layouts = get_output_layouts(impl_param, body_outputs); + } else { + auto& memory_deps = impl_param.memory_deps; + const size_t current_iteration_idx = 0; + OPENVINO_ASSERT(memory_deps.count(current_iteration_idx) > 0, "The count of memory deps(current_iteration) should not be zero"); + cldnn::mem_lock current_iterations_lock(memory_deps.at(current_iteration_idx), impl_param.get_stream()); + int64_t current_iteration = static_cast(*current_iterations_lock.data()); + GPU_DEBUG_LOG << "* current_iteration(" << memory_deps.at(current_iteration_idx) << ") : " << current_iteration << std::endl; + + OPENVINO_ASSERT(impl_param.inner_nets.size() == 1, "Loop(", prim->id, ") should have only one inner program"); + const auto& body_outputs = impl_param.inner_nets.front()->get_outputs(); + output_layouts = get_output_layouts>(impl_param, body_outputs, current_iteration); + } + return output_layouts; } +template std::vector loop_inst::calc_output_layouts(loop_node const& node, const kernel_impl_params& impl_param); + + std::string loop_inst::to_string(const loop_node & node) { auto desc = node.get_primitive(); auto node_info = node.desc_to_json(); + std::vector body_inputs; + { + for (auto& input : desc->body_program->get_inputs()) { + body_inputs.push_back(input->id()); + } + } + json_composite loop_info; - loop_info.add("body input id", desc->body.get_primitives_ids()); + loop_info.add("body input id", body_inputs); loop_info.add("trip_count_id", desc->trip_count_id); - loop_info.add("initial_execution_id", desc->initial_execution_id); - loop_info.add("current_iteration_id", desc->current_iteration_id); - loop_info.add("condition_id", desc->condition_id); + loop_info.add("first_execution_condition_id", desc->first_execution_condition_id); + loop_info.add("body_current_iteration_id", desc->body_current_iteration_id); + loop_info.add("body_execution_condition_id", desc->body_execution_condition_id); std::stringstream primitive_description; node_info->add("loop info", loop_info); @@ -142,23 +208,23 @@ static std::vector find_io_primitive_maps( std::vector ret; if (is_external) { for (const auto& it : input_primitive_maps) { - if (it.external_id == prim_id) { + if (it.external_id.pid == prim_id) { ret.push_back(&it); } } for (const auto& it : output_primitive_maps) { - if (it.external_id == prim_id) { + if (it.external_id.pid == prim_id) { ret.push_back(&it); } } } else { for (const auto& it : input_primitive_maps) { - if (it.internal_id == prim_id) { + if (it.internal_id.pid == prim_id) { ret.push_back(&it); } } for (const auto& it : output_primitive_maps) { - if (it.internal_id == prim_id) { + if (it.internal_id.pid == prim_id) { ret.push_back(&it); } } @@ -175,24 +241,19 @@ static void validate_mappings(loop_node const & node) { for (const auto& id : outer_inputs) { if (id == node.get_trip_count_id() || id == node.get_initial_execution_id() || - id == node.get_num_iteration_id()) { + id == node.get_num_iterations_id()) { continue; } const auto results = find_io_primitive_maps(node.get_input_primitive_maps(), node.get_output_primitive_maps(), id, true); - if (results.size() == 0) { - std::string msg = "outer input '" + id + "' does not have primitive map"; - CLDNN_ERROR_MESSAGE(node.id(), msg.c_str()); - } + OPENVINO_ASSERT(results.size() > 0, node.id(), " : outer input '", id, "' does not have primitive map"); } // check all io_primitive_maps have their corresponding external id for (const auto& pm : input_primitive_maps) { - auto found = std::find(outer_inputs.begin(), outer_inputs.end(), pm.external_id); - if (found == outer_inputs.end()) { - std::string msg = "external id '" + pm.external_id + "' in primitive map cannot be found loop inputs"; - CLDNN_ERROR_MESSAGE(node.id(), msg.c_str()); - } + auto found = std::find(outer_inputs.begin(), outer_inputs.end(), pm.external_id.pid); + OPENVINO_ASSERT(found != outer_inputs.end(), node.id(), + " : external id '", pm.external_id.pid, "' in primitive map cannot be found loop inputs"); } const auto& nodes = node.get_body_program()->get_processing_order(); @@ -200,50 +261,25 @@ static void validate_mappings(loop_node const & node) { // check all io_primitive_maps have their corresponding interal id for (const auto& pm : input_primitive_maps) { auto found = std::find_if(nodes.begin(), nodes.end(), [&pm](const program_node* body_input) { - return body_input->id() == pm.internal_id; + return body_input->id() == pm.internal_id.pid; }); - if (found == nodes.end()) { - std::string msg = "internal id '" + pm.internal_id + "' in primitive map cannot be found loop body"; - CLDNN_ERROR_MESSAGE(node.id(), msg.c_str()); - } + OPENVINO_ASSERT(found != nodes.end(), node.id(), + " : internal id '", pm.internal_id.pid, "' in primitive map cannot be found loop body"); } for (const auto& pm : output_primitive_maps) { auto found = std::find_if(nodes.begin(), nodes.end(), [&pm](const program_node* body_output) { - return body_output->id() == pm.internal_id; + return body_output->id() == pm.internal_id.pid; }); - if (found == nodes.end()) { - std::string msg = "internal id '" + pm.internal_id + "' in primitive map cannot be found body body"; - CLDNN_ERROR_MESSAGE(node.id(), msg.c_str()); - } + OPENVINO_ASSERT(found != nodes.end(), node.id(), + " : internal id '", pm.internal_id.pid, "' in primitive map cannot be found body body"); } } -void loop_inst::update_mapped_memory() { - if (!preproc_memories_done) { - return; - } - // update output memory - for (size_t i = 0; i < _output_primitive_maps.size(); ++i) { - const auto& output_mapping = _output_primitive_maps.at(i); - const primitive_id& external_id = output_mapping.external_id; - const primitive_id& internal_id = output_mapping.internal_id; - memory::ptr to_mem = get_external_memory(external_id); - if (output_mapping.axis < 0) { - body_network->get_primitive(internal_id)->set_output_memory(to_mem); - } else { - for (auto& mem_mapping : concatenated_output_mem_mappings) { - if (mem_mapping.sliced_data_prim->id() == internal_id) { - mem_mapping.concatenated_mem = to_mem; - break; - } - } - } - } - // update input memory +void loop_inst::update_input_mapped_memory() { for (size_t memory_num = 0; memory_num < inputs_memory_count(); memory_num++) { const primitive_id& input_external_id = dependencies().at(memory_num).first->id(); auto input_map_ptrs = find_io_primitive_maps(_input_primitive_maps, - _output_primitive_maps, input_external_id, true); + _output_primitive_maps, input_external_id, true); if (input_map_ptrs.empty()) { if (input_external_id == _trip_count_id || input_external_id == _initial_execution_id) { @@ -257,36 +293,69 @@ void loop_inst::update_mapped_memory() { bool is_concatenated_input = (input_map->axis >= 0); if (is_concatenated_input) { for (auto& mem_mapping : concatenated_input_mem_mappings) { - if (mem_mapping.sliced_data_prim->id() == input_map->internal_id) { - mem_mapping.concatenated_mem = memory; + if (mem_mapping->sliced_data_prim->id() == input_map->internal_id.pid) { + mem_mapping->update_concatenated_mem(memory); break; } } } else { - body_network->set_input_data(input_map->internal_id, memory); + body_network->set_input_data(input_map->internal_id.pid, memory); } } } - //update backedges memory +} + +void loop_inst::update_output_mapped_memory() { + if (is_dynamic()) { + if (!outputs_allocated()) { + _outputs = allocate_outputs(_impl_params.get(), true, true); + } + } + + for (size_t i = 0; i < _output_primitive_maps.size(); ++i) { + const auto& output_mapping = _output_primitive_maps.at(i); + const primitive_id& external_id = output_mapping.external_id.pid; + const size_t external_mem_idx = output_mapping.external_id.idx; + const primitive_id& internal_id = output_mapping.internal_id.pid; + const size_t internal_mem_idx = output_mapping.internal_id.idx; + + memory::ptr to_mem = get_external_memory(external_id, external_mem_idx); + if (to_mem) { + if (output_mapping.axis < 0) { + body_network->get_primitive(internal_id)->set_output_memory(to_mem, true, internal_mem_idx); + } else { + for (auto& mem_mapping : concatenated_output_mem_mappings) { + if (mem_mapping->sliced_data_prim->id() == internal_id) { + mem_mapping->update_concatenated_mem(to_mem); + break; + } + } + } + } + } +} + +void loop_inst::update_backedge_mapped_memory() { // checking if memory is a destination of a backedge for (const auto& back_edge : _back_edges) { //find corresponding input of the backedge const auto input_map_ptrs = find_io_primitive_maps(_input_primitive_maps, - _output_primitive_maps, back_edge.to, false); + _output_primitive_maps, back_edge.to, false); assert(input_map_ptrs.size() == 1); const auto& input_map = input_map_ptrs.front(); - auto backedged_sliced_output_mems = get_sliced_mem(back_edge.from); + auto backedged_sliced_output = get_sliced_mem(back_edge.from); const auto backedge_to_prim = body_network->get_primitive(back_edge.to); const auto backedge_from_prim = body_network->get_primitive(back_edge.from); - memory::ptr initial_mem = get_external_memory(input_map->external_id); + + memory::ptr initial_mem = get_external_memory(input_map->external_id.pid, input_map->external_id.idx); for (auto& backedge_mapping : backedge_memory_mappings) { if (backedge_mapping.from_primitive->id() == backedge_from_prim->id() && backedge_mapping.to_primitive->id() == backedge_to_prim->id()) { - if (backedged_sliced_output_mems.empty()) { + if (backedged_sliced_output == nullptr) { // backedge output which does not need concatenation const auto output_mapping = find_io_primitive_maps(_input_primitive_maps, - _output_primitive_maps, back_edge.from, false); + _output_primitive_maps, back_edge.from, false); memory::ptr backedge_mem; if (output_mapping.empty()) { // from and to primitives in backedge are connected directly @@ -300,14 +369,15 @@ void loop_inst::update_mapped_memory() { backedge_mem = body_network->get_engine().allocate_memory(output_layout, 0); } } else { - backedge_mem = get_external_memory(output_mapping.front()->external_id); + auto external_id = output_mapping.front()->external_id; + backedge_mem = get_external_memory(external_id.pid, external_id.idx); } body_network->set_input_data(back_edge.to, backedge_mem); body_network->set_output_memory(back_edge.from, backedge_mem); - backedge_mapping.from_mems = { backedge_mem }; + backedge_mapping.from_mem = backedge_mem; backedge_mapping.initial_mem = initial_mem; } else { - backedge_mapping.from_mems = backedged_sliced_output_mems; + backedge_mapping.concat_mem_mapping = backedged_sliced_output; backedge_mapping.initial_mem = initial_mem; } break; @@ -316,92 +386,138 @@ void loop_inst::update_mapped_memory() { } } + +void loop_inst::update_mapped_memory() { + if (!preproc_memories_done) { + return; + } + + update_output_mapped_memory(); + update_input_mapped_memory(); + update_backedge_mapped_memory(); +} + event::ptr loop_inst::set_output_memory(memory::ptr mem, bool check, size_t idx) { auto ev = primitive_inst::set_output_memory(mem, check, idx); update_mapped_memory(); return ev; } -void loop_inst::preprocess_output_memory() { - auto& engine = _network.get_engine(); - concatenated_output_mem_mappings.reserve(_output_primitive_maps.size()); - for (size_t i = 0; i < _output_primitive_maps.size(); ++i) { - const auto& output_mapping = _output_primitive_maps.at(i); - const primitive_id& external_id = output_mapping.external_id; - const primitive_id& internal_id = output_mapping.internal_id; - if (output_mapping.axis < 0) { - memory::ptr memory = get_external_memory(external_id); - body_network->get_primitive(internal_id)->set_output_memory(memory); +loop_inst::concatenated_memory_mapping::ptr loop_inst::create_concat_memory_map(const input_info& internal_id, + const cldnn::loop::io_primitive_map& io_prim_map, + memory::ptr mem_ptr, + const int64_t trip_count) { + auto& engine = body_network->get_engine(); + auto& stream = body_network->get_stream(); + auto prim = body_network->get_primitive(internal_id.pid); + const int64_t start = io_prim_map.start < 0? trip_count - 1: io_prim_map.start; + + std::vector sliced_mems; + int64_t num_elements_iteration = 0; + + // if memory is nullptr, that means memory is not allocated yet because current network is dynamic shape model. + // In dynamic model, we can't calculate num_element_iteration, start, and sliced_layout. + // will recalculate that parameters in backedge preprocessing map after first execution. + if (mem_ptr != nullptr) { + layout sliced_layout = prim->output_memory(internal_id.idx).get_layout(); + + // When trip_count is -1, allocate first sliced_mem and allocate sliced memory if additional sliced mem is required + if (trip_count < 0) { + memory::ptr sliced_mem = engine.allocate_memory(sliced_layout, 0); + sliced_mems.push_back(sliced_mem); } else { - memory::ptr to_mem = get_external_memory(external_id); - auto output_prim = body_network->get_primitive(internal_id); - layout sliced_layout = output_prim->output_memory().get_layout(); - - const int64_t max_iteration = _max_iteration; - std::vector sliced_mems; - sliced_mems.reserve(max_iteration); - for (int32_t j = 0; j < max_iteration; ++j) { + sliced_mems.reserve(trip_count); + for (int j=0; j < trip_count; ++j) { memory::ptr sliced_mem = engine.allocate_memory(sliced_layout, 0); sliced_mems.push_back(sliced_mem); } + } - const int64_t num_elements_batch = concatenated_memory_mapping::get_batch_size( - sliced_layout, output_mapping.axis); - const int64_t num_elements_iteration = sliced_layout.count() / num_elements_batch; - const int64_t start = output_mapping.start < 0? _max_iteration - 1: output_mapping.start; - concatenated_memory_mapping memory_mapping_info( - output_mapping.axis, std::move(to_mem), sliced_mems, _network.get_stream(), - num_elements_iteration, output_mapping.stride, start); - memory_mapping_info.sliced_data_prim = body_network->get_primitive(internal_id); - memory_mapping_info.concat_data_prim = get_network().get_primitive(external_id); - concatenated_output_mem_mappings.push_back(memory_mapping_info); + const int64_t num_elements_batch = concatenated_memory_mapping::get_batch_size( + sliced_layout, io_prim_map.axis); + num_elements_iteration = sliced_layout.count() / num_elements_batch; + } + + auto concat_memory_mapping = std::make_shared( + io_prim_map.axis, mem_ptr, sliced_mems, stream, + engine, num_elements_iteration, io_prim_map.stride, start); + concat_memory_mapping->sliced_data_prim = body_network->get_primitive(internal_id.pid); + return concat_memory_mapping; +} + +void loop_inst::preprocess_output_memory(const int64_t trip_count) { + if (concatenated_output_mem_mappings.empty()) + concatenated_output_mem_mappings.reserve(_output_primitive_maps.size()); + for (size_t i = 0; i < _output_primitive_maps.size(); ++i) { + const auto& output_mapping = _output_primitive_maps.at(i); + const auto& external_id = output_mapping.external_id; + const auto& internal_id = output_mapping.internal_id; + GPU_DEBUG_LOG << i << ") output mapping - external " << external_id.to_string() << std::endl; + GPU_DEBUG_LOG << i << ") output mapping - internal " << internal_id.to_string() << std::endl; + + memory::ptr memory = get_external_memory(external_id.pid, external_id.idx); + if (output_mapping.axis < 0) { + // In dynamic model, Don't get output memory of loop node because body network's output layouts are not calculated + if (memory != nullptr) { + body_network->get_primitive(internal_id.pid)->set_output_memory(memory, true, internal_id.idx); + } + } else { + auto iter = std::find_if(concatenated_output_mem_mappings.begin(), concatenated_output_mem_mappings.end(), + [&](loop_inst::concatenated_memory_mapping::ptr concat_mem_map) -> bool { + return concat_mem_map->sliced_data_prim->id() == internal_id.pid; + }); + if (iter == concatenated_output_mem_mappings.end()) { + auto memory_mapping_info = create_concat_memory_map(internal_id, output_mapping, memory, trip_count); + memory_mapping_info->concat_data_prim = get_network().get_primitive(external_id.pid); + concatenated_output_mem_mappings.push_back(memory_mapping_info); + GPU_DEBUG_LOG << i << ") generate concat output memory mapping: " << memory_mapping_info->to_string() << std::endl; + } + GPU_DEBUG_IF(iter != concatenated_output_mem_mappings.end()) { + GPU_DEBUG_LOG << i << ") memory_mapping_info is already existed : " << (*iter)->to_string() << std::endl; + } } } } -void loop_inst::preprocess_input_memory() { - auto& engine = _network.get_engine(); - auto& iteration_mem = concatenated_input_mem_mappings; +void loop_inst::preprocess_input_memory(const int64_t trip_count) { for (size_t memory_num = 0; memory_num < inputs_memory_count(); memory_num++) { const primitive_id& input_external_id = dependencies().at(memory_num).first->id(); auto input_map_ptrs = find_io_primitive_maps(_input_primitive_maps, - _output_primitive_maps, input_external_id, true); + _output_primitive_maps, input_external_id, true); if (input_map_ptrs.size() == 0) { - if (input_external_id == _trip_count_id || - input_external_id == _initial_execution_id) { - continue; - } - CLDNN_ERROR_MESSAGE(id(), "loop primitive_map is incomplete"); + OPENVINO_ASSERT((input_external_id == _trip_count_id + || input_external_id == _num_iterations_id + || input_external_id == _initial_execution_id), + id(), "loop primitive_map is incomplete " + "input_external_id(", input_external_id, ") != _trip_count_id(", _trip_count_id, ")", + "input_external_id(", input_external_id, ") != _num_iterations_id(", _num_iterations_id, ")", + " && input_external_id(", input_external_id, ") != _initial_execution_id(", _initial_execution_id, ")"); + continue; } auto memory = input_memory_ptr(memory_num); for (size_t i = 0; i < input_map_ptrs.size(); ++i) { const auto input_map = input_map_ptrs.at(i); - bool is_concatenated_input = (input_map->axis >= 0); - if (is_concatenated_input) { - layout sliced_layout - = body_network->get_primitive(input_map->internal_id)->output_memory().get_layout(); - const int64_t max_iteration = _max_iteration; - std::vector sliced_mems; - sliced_mems.reserve(max_iteration); - for (int j=0; j < max_iteration; ++j) { - memory::ptr sliced_mem = engine.allocate_memory(sliced_layout, 0); - sliced_mems.push_back(sliced_mem); - } - const int64_t num_elements_batch = concatenated_memory_mapping::get_batch_size( - sliced_layout, input_map->axis); - const int64_t num_elements_iteration = sliced_layout.count() / num_elements_batch; - const int64_t start = input_map->start < 0? _max_iteration - 1: input_map->start; - concatenated_memory_mapping concatenated_input_mem_mapping_info( - input_map->axis, memory, sliced_mems, _network.get_stream(), - num_elements_iteration, input_map->stride, start); - concatenated_input_mem_mapping_info.sliced_data_prim = body_network->get_primitive(input_map->internal_id); - iteration_mem.push_back(concatenated_input_mem_mapping_info); + const auto& external_id = input_map->external_id; + const auto& internal_id = input_map->internal_id; + GPU_DEBUG_LOG << i << ") input mapping - external " << external_id.to_string() << std::endl; + GPU_DEBUG_LOG << i << ") input mapping - internal " << internal_id.to_string() << std::endl; + + if (input_map->axis >= 0) { + OPENVINO_ASSERT(trip_count > 0, "In preprocessing concat input mapping, trip_count should be positive"); + OPENVINO_ASSERT(memory != nullptr, "In preprocessing concat input mapping, concat memory should be allocated"); + auto memory_mapping_info = create_concat_memory_map(internal_id, *input_map, memory, trip_count); + concatenated_input_mem_mappings.push_back(memory_mapping_info); + GPU_DEBUG_LOG << i << ") generate concat input memory mapping: " << memory_mapping_info->to_string() << std::endl; } else { - if (memory->get_layout().data_type != body_network->get_primitive(input_map->internal_id)->output_memory().get_layout().data_type) { - CLDNN_ERROR_MESSAGE(id(), "incompatible datatypes"); + auto input_inst = body_network->get_primitive(internal_id.pid); + if (memory->get_layout() != input_inst->get_output_layout()) { + input_inst->set_output_layout(memory->get_layout()); + GPU_DEBUG_LOG << input_inst->id() << " is changed memory because layout is changed from " + << input_inst->get_output_layout().to_short_string() + << " to " << memory->get_layout().to_short_string() << std::endl; } - body_network->set_input_data(input_map->internal_id, memory); + body_network->set_input_data(internal_id.pid, memory); } } } @@ -409,88 +525,141 @@ void loop_inst::preprocess_input_memory() { void loop_inst::preprocess_backedge_memory() { // checking if memory is a destination of a backedge - for (const auto& back_edge : _back_edges) { + for (size_t idx = 0; idx < _back_edges.size(); idx++) { + const auto& back_edge = _back_edges[idx]; //find corresponding input of the backedge const auto input_map_ptrs = find_io_primitive_maps(_input_primitive_maps, - _output_primitive_maps, back_edge.to, false); + _output_primitive_maps, back_edge.to, false); const auto backedge_to_prim = body_network->get_primitive(back_edge.to); const auto backedge_from_prim = body_network->get_primitive(back_edge.from); memory::ptr initial_mem; - if (back_edge.to == _current_iteration_id) { - const layout current_iteration_layout = backedge_to_prim->output_memory().get_layout(); - initial_mem = get_network().get_engine().allocate_memory(current_iteration_layout); - auto& stream = get_network().get_stream(); - loop_node::write_scalar_value(initial_mem, stream, 0); - current_iteratoin_backedge_mapping_idx = backedge_memory_mappings.size(); + OPENVINO_ASSERT(!input_map_ptrs.empty(), id(), " has no input_mapping for backedged input"); + auto& external_id = input_map_ptrs.front()->external_id; + initial_mem = get_external_memory(external_id.pid, external_id.idx); + + GPU_DEBUG_LOG << idx << ") back_edge mapping - back_edge.from " << back_edge.from << std::endl; + GPU_DEBUG_LOG << idx << ") back_edge mapping - back_edge.to " << back_edge.to << std::endl; + + auto backedged_sliced_output = get_sliced_mem(back_edge.from); + const auto output_mapping = find_io_primitive_maps(_input_primitive_maps, + _output_primitive_maps, back_edge.from, false); + if (backedged_sliced_output != nullptr) { + // CONCAT_OUTPUT mode, backedge output which needs concatenation + backedge_memory_mappings.emplace_back( + backedge_from_prim, backedge_to_prim, backedged_sliced_output, initial_mem, body_network->get_stream()); + GPU_DEBUG_LOG << idx << ") add back_edge mapping with CONCAT_OUTPUT type, backedged_sliced_output(" + << backedged_sliced_output << "), initial_mem(" << initial_mem << ")" << std::endl; + } else if (output_mapping.empty() && backedge_to_prim == backedge_from_prim->dependencies().front().first) { + // SINGLE mode, from and to primitives in backedge are connected directly + backedge_memory_mappings.emplace_back( + backedge_from_prim, backedge_to_prim, initial_mem, body_network->get_stream()); + GPU_DEBUG_LOG << idx << ") add back_edge mapping with SINGLE type, initial_mem(" << initial_mem << ")" << std::endl; } else { - if (input_map_ptrs.empty()) { - CLDNN_ERROR_MESSAGE(id(), "no input_mapping for backedged input"); - } - initial_mem = get_external_memory(input_map_ptrs.front()->external_id); - } - - auto backedged_sliced_output_mems = get_sliced_mem(back_edge.from); - if (backedged_sliced_output_mems.empty()) { - // backedge output which does not need concatenation - const auto output_mapping = find_io_primitive_maps(_input_primitive_maps, - _output_primitive_maps, back_edge.from, false); + // SINGLE_SHARED mode memory::ptr backedge_mem; - if (output_mapping.empty()) { - // from and to primitives in backedge are connected directly - if (backedge_to_prim == backedge_from_prim->dependencies().front().first) { - backedge_memory_mappings.emplace_back( - backedge_from_prim, backedge_to_prim, initial_mem, body_network->get_stream()); - continue; + auto output_prim = body_network->get_primitive(back_edge.from); + + if (is_dynamic()) { + if (output_prim->outputs_allocated()) { + auto internal_output_prim_mem = output_prim->output_memory_ptr(); + if (internal_output_prim_mem->get_layout() == initial_mem->get_layout()) { + backedge_mem = internal_output_prim_mem; + body_network->set_input_data(back_edge.to, backedge_mem); + GPU_DEBUG_LOG << idx << ") Get backedge_mem(" << backedge_mem + << ") from back_edge.from(" << back_edge.from << ")" << std::endl; + } else { + // When input layout is changed or backedge_mem is null + // because output layout of body network is not calculated yet, + // Set backedge_mem to nullptr and update it after first execution. + body_network->set_input_data(back_edge.to, initial_mem); + GPU_DEBUG_LOG << idx << ") Just set input data using initial_mem because back_edge.from(" + << back_edge.from << ") layout is changed or backedge_mem is nullptr" << std::endl; + } } else { - auto output_prim = body_network->get_primitive(back_edge.from); - layout output_layout = output_prim->output_memory().get_layout(); - backedge_mem = body_network->get_engine().allocate_memory(output_layout, 0); + body_network->set_input_data(back_edge.to, initial_mem); + GPU_DEBUG_LOG << idx << ") Just set input data using initial_mem because back_edge.from(" + << back_edge.from << ") has dynamic layout now" << std::endl; } } else { - backedge_mem = get_external_memory(output_mapping.front()->external_id); + if (output_mapping.empty()) { + backedge_mem = output_prim->output_memory_ptr(); + body_network->set_input_data(back_edge.to, backedge_mem); + GPU_DEBUG_LOG << idx << ") Get backedge_mem(" << backedge_mem + << ") from back_edge.from(" << back_edge.from << ")" << std::endl; + } else { + // Set input and output memory for body_network using external output memory of loop op + auto& out_mapping_ext_id = output_mapping.front()->external_id; + backedge_mem = get_external_memory(out_mapping_ext_id.pid, out_mapping_ext_id.idx); + GPU_DEBUG_LOG << idx << ") Get backedge_mem(" << backedge_mem << ") from output_mapping_external_id.pid(" + << out_mapping_ext_id.pid << ")" << std::endl; + + body_network->set_input_data(back_edge.to, backedge_mem); + body_network->set_output_memory(back_edge.from, backedge_mem); + } } - body_network->set_input_data(back_edge.to, backedge_mem); - body_network->set_output_memory(back_edge.from, backedge_mem); + backedge_memory_mappings.emplace_back( backedge_from_prim, backedge_to_prim, backedge_mem, initial_mem, body_network->get_stream()); - } else { - // backedge output which needs concatenation - backedge_memory_mappings.emplace_back( - backedge_from_prim, backedge_to_prim, backedged_sliced_output_mems, initial_mem, body_network->get_stream()); + GPU_DEBUG_LOG << idx << ") add back_edge mapping with SINGLE_SHARED type, backedge_mem(" + << backedge_mem << "), initial_mem(" << initial_mem << ")" << std::endl; } } } -std::vector loop_inst::get_sliced_mem(const primitive_id& internal_id) const { +std::shared_ptr loop_inst::get_sliced_mem(const primitive_id& internal_id) const { for (const auto& mem_mapping : concatenated_input_mem_mappings) { - if (mem_mapping.sliced_data_prim->id() == internal_id) { - return mem_mapping.sliced_mems; + if (mem_mapping->sliced_data_prim->id() == internal_id) { + return mem_mapping; } } for (const auto& mem_mapping : concatenated_output_mem_mappings) { - if (mem_mapping.sliced_data_prim->id() == internal_id) { - return mem_mapping.sliced_mems; + if (mem_mapping->sliced_data_prim->id() == internal_id) { + return mem_mapping; + } + } + return nullptr; // not found +} + +void loop_inst::validate_backedges(loop_node const & node) const { + const auto& back_edges = node.get_back_edges(); + const auto& input_primitive_maps = node.get_input_primitive_maps(); + + // check input with iteration axis has backedge + for (const auto& back_edge : back_edges) { + for (const auto& mapping : input_primitive_maps) { + OPENVINO_ASSERT((mapping.internal_id.pid != back_edge.to || mapping.axis < 0), + node.id(), ": input with iteration axis should not have backedges"); } } - return {}; // not found } -memory::ptr loop_inst::get_external_memory(const primitive_id& external_id) const { +memory::ptr loop_inst::get_external_memory(const primitive_id& external_id, size_t mem_idx) const { const auto outputPrim = _network.get_primitive(external_id); - return outputPrim->output_memory_ptr(); + if (outputPrim->outputs_allocated()) { + return outputPrim->output_memory_ptr(mem_idx); + } + return nullptr; +} + +layout loop_inst::get_external_output_layout(const primitive_id& external_id, size_t mem_idx) const { + const auto outputPrim = _network.get_primitive(external_id); + return outputPrim->get_output_layout(mem_idx); } loop_inst::typed_primitive_inst(network & network, loop_node const & node) : parent(network, node), - preproc_memories_done(false), - body_network(network::allocate_network(network.get_stream_ptr(), - node.get_body_program(), - false, - network.is_primary_stream())) { - if (!check_if_axis_is_set_properly(node)) - CLDNN_ERROR_MESSAGE(node.id(), "axis is not set properly"); - + preproc_memories_done(false), + body_network(network::allocate_network(network.get_stream_ptr(), + node.get_body_program(), + false, + network.is_primary_stream())) { + const primitive_id& num_iterations_id = node.get_num_iterations_id(); + OPENVINO_ASSERT(node.get_program().get_node(num_iterations_id).is_type(), + node.id(), ": num_iterations is not mutable_data"); + OPENVINO_ASSERT(check_if_axis_is_set_properly(node), node.id(), ": axis is not set properly"); + + set_inner_networks({body_network}); validate_backedges(node); validate_mappings(node); @@ -500,9 +669,8 @@ loop_inst::typed_primitive_inst(network & network, loop_node const & node) _trip_count_id = node.get_trip_count_id(); _initial_execution_id = node.get_initial_execution_id(); _current_iteration_id = node.get_current_iteration_id(); - _condition_id = node.get_condition_id(); - _num_iteration_id = node.get_num_iteration_id(); - _max_iteration = node.get_max_iteration(); + _condition_id = node.get_execution_condition_id(); + _num_iterations_id = node.get_num_iterations_id(); } void loop_inst::save(BinaryOutputBuffer& ob) const { @@ -514,8 +682,7 @@ void loop_inst::save(BinaryOutputBuffer& ob) const { ob << _initial_execution_id; ob << _current_iteration_id; ob << _condition_id; - ob << _num_iteration_id; - ob << _max_iteration; + ob << _num_iterations_id; body_network->save(ob); } @@ -529,9 +696,97 @@ void loop_inst::load(BinaryInputBuffer& ib) { ib >> _initial_execution_id; ib >> _current_iteration_id; ib >> _condition_id; - ib >> _num_iteration_id; - ib >> _max_iteration; + ib >> _num_iterations_id; body_network = std::make_shared(ib, get_network().get_stream_ptr(), get_network().get_engine(), get_network().is_primary_stream(), 0); } +void loop_inst::postprocess_output_memory(bool is_dynamic) { + if (is_dynamic) { + for (size_t i = 0; i < _output_primitive_maps.size(); ++i) { + const auto& output_mapping = _output_primitive_maps.at(i); + const auto& external_id = output_mapping.external_id; + const auto& internal_id = output_mapping.internal_id; + if (output_mapping.axis < 0) { + auto internalOutputPrim = get_body_network()->get_primitive(internal_id.pid); + auto internal_mem = internalOutputPrim->output_memory_ptr(internal_id.idx); + if (internal_mem == nullptr) { + continue; + } + auto externalOutputPrim = _network.get_primitive(external_id.pid); + if (!externalOutputPrim->outputs_allocated()) { + externalOutputPrim->set_output_memory(internal_mem, external_id.idx); + } else { + auto external_mem = externalOutputPrim->output_memory_ptr(external_id.idx); + if (external_mem->get_layout() != internal_mem->get_layout()) { + externalOutputPrim->set_output_memory(internal_mem, external_id.idx); + } else if (external_mem != internal_mem) { + external_mem->copy_from(get_network().get_stream(), *internal_mem); + } + } + } else { + auto externalOutputPrim = _network.get_primitive(external_id.pid); + if (!externalOutputPrim->outputs_allocated() || shape_changed()) { + auto concat_layout = _impl_params->get_output_layout(external_id.idx); + auto concat_mem = _network.get_engine().allocate_memory(concat_layout, 0); + externalOutputPrim->set_output_memory(concat_mem, external_id.idx); + auto iter = std::find_if(concatenated_output_mem_mappings.begin(), + concatenated_output_mem_mappings.end(), + [&](std::shared_ptr &concat_output){ + return concat_output->concat_data_prim->id() == external_id.pid; + }); + if (iter != concatenated_output_mem_mappings.end()) { + (*iter)->update_concatenated_mem(concat_mem); + } + } + } + } + } + + for (size_t i = 0; i < concatenated_output_mem_mappings.size(); ++i) { + const auto& concat_output = concatenated_output_mem_mappings.at(i); + concat_output->restore_concatenated_mem(); + } +} + +void loop_inst::reset_memory() { + backedge_memory_mappings.clear(); + concatenated_input_mem_mappings.clear(); + for (auto concat_mem_map : concatenated_output_mem_mappings) { + concat_mem_map->reset_data_for_shape_changed(); + } +} + + +void loop_inst::update_output_layout() { + if (_node == nullptr) + return; + + auto memory_deps = _node->get_const_memory_deps(); + for (auto& i : _node->get_shape_infer_dependencies()) { + auto dep_id = _node->get_dependency(i).id(); + if (memory_deps.count(i) > 0 || i >= _node->get_dependencies().size()) { + continue; + } + + auto dep_mem = _network.get_output_memory(dep_id); + memory_deps.insert({i, dep_mem}); + } + _impl_params->memory_deps = memory_deps; + + auto new_layouts = _node->type()->calc_output_layouts(*_node, *_impl_params); + if (new_layouts.empty()) { + auto new_layout = _node->type()->calc_output_layout(*_node, *_impl_params); + new_layout.data_padding = padding::max(_node->get_primitive()->output_paddings[0], new_layout.data_padding); + _impl_params->output_layouts[0] = new_layout; + } else { + if (_impl_params->output_layouts.size() < new_layouts.size()) { + _impl_params->output_layouts.resize(new_layouts.size()); + } + for (size_t i = 0; i < new_layouts.size(); ++i) { + auto new_layout = new_layouts[i]; + new_layout.data_padding = padding::max(_node->get_primitive()->output_paddings[i], new_layout.data_padding); + _impl_params->output_layouts[i] = new_layout; + } + } +} } // namespace cldnn diff --git a/src/plugins/intel_gpu/src/graph/network.cpp b/src/plugins/intel_gpu/src/graph/network.cpp index 51b988076d18f3..240db96d5b4988 100644 --- a/src/plugins/intel_gpu/src/graph/network.cpp +++ b/src/plugins/intel_gpu/src/graph/network.cpp @@ -758,7 +758,10 @@ void network::reset_execution(bool wait) { get_stream().wait_for_events(events); } } - _events.clear(); + + // Move events to temporarily map to deallocate them at the end of network::execute() call for better overlapping with + // kernels execution, since it may take significant time for high amount of events + _old_events = std::move(_events); } event::ptr network::set_input_data(const primitive_id& id, memory::ptr data) { @@ -1457,6 +1460,9 @@ void network::execute_impl(const std::vector& events) { // In scenarios with a big number of very small networks it can provide performance drop. get_stream().flush(); + // Deallocate events from the previos iteration + _old_events.clear(); + GPU_DEBUG_IF(debug_config->dump_runtime_memory_pool > 0) { get_memory_pool().dump(get_id()); } diff --git a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp b/src/plugins/intel_gpu/src/graph/primitive_inst.cpp index eea18ca1fe6b79..6c1e88de349115 100644 --- a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp +++ b/src/plugins/intel_gpu/src/graph/primitive_inst.cpp @@ -425,7 +425,7 @@ event::ptr primitive_inst::realloc_if_needed() { auto current_shape = actual_layout.get_shape(); auto& sp = get_network().get_shape_predictor(); - auto dt_size = data_type_traits::size_of(actual_layout.data_type); + auto dt_size = ov::element::Type(actual_layout.data_type).bitwidth(); auto prealloc_info = sp.predict_preallocation_shape(id(), current_shape, dt_size, can_reuse_buffer); if (prealloc_info.first && sp.can_preallocate(ov::shape_size(prealloc_info.second) * dt_size)) { auto new_layout = actual_layout; @@ -685,6 +685,7 @@ void primitive_inst::do_runtime_skip_reorder() { GPU_DEBUG_TRACE_DETAIL << "[do runtime skip reorder] update shape for user " << u->id() << std::endl; u->update_shape(); u->update_shape_done_by_other = true; + if (u->_impl_params->get_input_layout() == u->_impl_params->get_output_layout()) { std::function>)> update_memory_dependencies; update_memory_dependencies = [&](std::vector> users) { @@ -699,6 +700,10 @@ void primitive_inst::do_runtime_skip_reorder() { update_memory_dependencies(u->get_user_insts()); u->set_can_be_optimized(true); + // Opt out reorder which has _needs_completion_event = true causes syncronization failed in dGPU. + if (_needs_completion_event == false && u->_needs_completion_event == true) { + _needs_completion_event = true; + } GPU_DEBUG_TRACE_DETAIL << "[do runtime skip reorder] set user " << u->id() << " as can_be_optimized" << std::endl; } else { GPU_DEBUG_TRACE_DETAIL << "[do runtime skip reorder] user " << u->id() << " cannot be optimized" << std::endl; diff --git a/src/plugins/intel_gpu/src/graph/prior_box.cpp b/src/plugins/intel_gpu/src/graph/prior_box.cpp index 899f0db6f2ba4a..571a2c6d92c218 100644 --- a/src/plugins/intel_gpu/src/graph/prior_box.cpp +++ b/src/plugins/intel_gpu/src/graph/prior_box.cpp @@ -401,12 +401,12 @@ void prior_box_node::calc_result() { // perform calculations if (get_output_layout().data_type == data_types::f16) - calculate_prior_box_output::type>(result, + calculate_prior_box_output::value_type>(result, get_program().get_stream(), input().get_output_layout(), *typed_desc()); else - calculate_prior_box_output::type>(result, + calculate_prior_box_output::value_type>(result, get_program().get_stream(), input().get_output_layout(), *typed_desc()); diff --git a/src/plugins/intel_gpu/src/graph/program_dump_graph.cpp b/src/plugins/intel_gpu/src/graph/program_dump_graph.cpp index 684057ee4726f8..f8aa9fb1c08c60 100644 --- a/src/plugins/intel_gpu/src/graph/program_dump_graph.cpp +++ b/src/plugins/intel_gpu/src/graph/program_dump_graph.cpp @@ -188,6 +188,25 @@ void dump_graph_init(std::ofstream& graph, return out; }; + const auto dump_mem_preferred_info = [](const program_node* ptr) { + std::string out = ""; + auto input_fmts = ptr->get_preferred_input_fmts(); + if (!input_fmts.empty()) { + out += "preferred_in_fmt"; + for (auto& fmt : input_fmts) { + out += ":" + fmt_to_str(fmt); + } + } + auto output_fmts = ptr->get_preferred_output_fmts(); + if (!output_fmts.empty()) { + out += "\npreferred_out_fmt"; + for (auto& fmt : output_fmts) { + out += ":" + fmt_to_str(fmt); + } + } + + return out; + }; graph << "digraph cldnn_program {\n"; for (auto& node : program.get_processing_order()) { @@ -220,6 +239,7 @@ void dump_graph_init(std::ofstream& graph, } } graph << "\n" + dump_mem_info(node); + graph << "\n" + dump_mem_preferred_info(node); graph << "\""; #ifdef __clang__ #pragma clang diagnostic pop diff --git a/src/plugins/intel_gpu/src/graph/program_node.cpp b/src/plugins/intel_gpu/src/graph/program_node.cpp index 62c11e2f7e8066..dc9b2029ff408c 100644 --- a/src/plugins/intel_gpu/src/graph/program_node.cpp +++ b/src/plugins/intel_gpu/src/graph/program_node.cpp @@ -208,7 +208,8 @@ std::unique_ptr program_node::desc_to_json() const { #endif impls.push_back(selected_impl->get_kernel_name()); - if (get_preferred_impl_type() == impl_types::ocl) { + auto preferred_impl_type = get_preferred_impl_type(); + if (preferred_impl_type != impl_types::onednn && preferred_impl_type != impl_types::cpu) { json_composite cl_dump_info; cl_dump_info.add("batch_hash", selected_impl->get_kernels_dump_info().first); cl_dump_info.add("kernel_entry", selected_impl->get_kernels_dump_info().second); @@ -331,6 +332,8 @@ layout program_node::get_non_padded_output_layout(bool invalidate_users_if_chang bool program_node::set_output_layout(layout& new_layout, bool invalidate_users_if_changed, size_t idx) { merge_output_padding(new_layout.data_padding, idx); + OPENVINO_ASSERT(idx < output_layouts.size(), id(), " has invalid index : index is ", std::to_string(idx), + " but output_layouts length is ", std::to_string(output_layouts.size())); new_layout.data_padding = output_layouts[idx].data_padding; bool changed = (new_layout != output_layouts[idx]); if (changed && invalidate_users_if_changed) // output_layout has changed! invalidate users diff --git a/src/plugins/intel_gpu/src/graph/rms.cpp b/src/plugins/intel_gpu/src/graph/rms.cpp new file mode 100644 index 00000000000000..5002417df57394 --- /dev/null +++ b/src/plugins/intel_gpu/src/graph/rms.cpp @@ -0,0 +1,41 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "rms_inst.h" + +#include "primitive_type_base.h" +#include "json_object.h" +#include + +namespace cldnn { +GPU_DEFINE_PRIMITIVE_TYPE_ID(rms); + +layout rms_inst::calc_output_layout(rms_node const& node, kernel_impl_params const& impl_param) { + auto desc = impl_param.typed_desc(); + auto input_layout = impl_param.get_input_layout(); + auto output_type = desc->output_data_types[0].value_or(input_layout.data_type); + auto output_format = input_layout.format; + + return layout(output_type, output_format, input_layout.get_tensor()); +} + +std::string rms_inst::to_string(rms_node const& node) { + auto desc = node.get_primitive(); + auto node_info = node.desc_to_json(); + + std::stringstream primitive_description; + + json_composite rms_info; + rms_info.add("input_id", node.input(0).id()); + rms_info.add("epsilon", desc->epsilon); + + node_info->add("rms_info", rms_info); + node_info->dump(primitive_description); + + return primitive_description.str(); +} + +rms_inst::typed_primitive_inst(network& network, rms_node const& node) : parent(network, node) {} + +} // namespace cldnn diff --git a/src/plugins/intel_gpu/src/graph/scatter_nd_update.cpp b/src/plugins/intel_gpu/src/graph/scatter_nd_update.cpp index 40d2b48d8edfaf..0f64b64a0bcad7 100644 --- a/src/plugins/intel_gpu/src/graph/scatter_nd_update.cpp +++ b/src/plugins/intel_gpu/src/graph/scatter_nd_update.cpp @@ -69,8 +69,9 @@ scatter_nd_update_inst::typed_primitive_inst(network& network, scatter_nd_update void scatter_nd_update_inst::on_execute() { auto input1_shape = _impl_params->input_layouts[1].get_partial_shape(); auto input2_shape = _impl_params->input_layouts[2].get_partial_shape(); + auto same_layouts = _impl_params->input_layouts[0] == _impl_params->output_layouts[0]; - if ((ov::shape_size(input1_shape.to_shape()) == 0) || (ov::shape_size(input2_shape.to_shape()) == 0)) + if (same_layouts && ((ov::shape_size(input1_shape.to_shape()) == 0) || (ov::shape_size(input2_shape.to_shape()) == 0))) reuse_input(); } diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/fully_connected_gpu_bf_tiled.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/fully_connected_gpu_bf_tiled.cl index d4992801a80447..f6dacec4a73c80 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/fully_connected_gpu_bf_tiled.cl +++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/fully_connected_gpu_bf_tiled.cl @@ -120,7 +120,7 @@ KERNEL(fc)( uint input_offset = out_b * TILE_IN_B_PITCH + INPUT0_OFFSET; uint weights_offset = out_f * INPUT_ELEMENTS_COUNT; -#if COMPRESSED_WEIGHTS +#if COMPRESSED_WEIGHTS && DECOMPRESSION_SCALE_GROUPS_NUM == 1 #if DECOMPRESSION_SCALE_LENGTH > 1 && DECOMPRESSION_SCALE_LENGTH % SIMD == 0 ACCUMULATOR_VEC_TYPE d_scale = BLOCK_READN(ACCUMULATOR_TYPE, TILE_OFM, decompression_scale, out_f); #elif DECOMPRESSION_SCALE_LENGTH > 1 && DECOMPRESSION_SCALE_LENGTH % SIMD != 0 @@ -134,9 +134,11 @@ KERNEL(fc)( ACCUMULATOR_VEC_TYPE d_scale = decompression_scale[0]; #endif - #if !DECOMPRESSION_ZP_TERM - ACCUMULATOR_VEC_TYPE d_zp = 0; - #elif DECOMPRESSION_ZP_LENGTH > 1 && DECOMPRESSION_ZP_LENGTH % SIMD == 0 + ACCUMULATOR_TYPE* d_scales = (ACCUMULATOR_TYPE*)(&d_scale); +#endif + +#if COMPRESSED_WEIGHTS && DECOMPRESSION_ZP_TERM && DECOMPRESSION_ZP_GROUPS_NUM == 1 + #if DECOMPRESSION_ZP_LENGTH > 1 && DECOMPRESSION_ZP_LENGTH % SIMD == 0 ACCUMULATOR_VEC_TYPE d_zp = BLOCK_READN(ACCUMULATOR_TYPE, TILE_OFM, decompression_zp, out_f); #elif DECOMPRESSION_ZP_LENGTH > 1 && DECOMPRESSION_ZP_LENGTH % SIMD != 0 ACCUMULATOR_VEC_TYPE d_zp = 0; @@ -148,9 +150,7 @@ KERNEL(fc)( #else ACCUMULATOR_VEC_TYPE d_zp = decompression_zp[0]; #endif - - ACCUMULATOR_TYPE* ds = (ACCUMULATOR_TYPE*)(&d_scale); - ACCUMULATOR_TYPE* dzp = (ACCUMULATOR_TYPE*)(&d_zp); + ACCUMULATOR_TYPE* d_zps = (ACCUMULATOR_TYPE*)(&d_zp); #endif #if REALIGN_FP16_OFFSET @@ -193,7 +193,28 @@ KERNEL(fc)( ACCUMULATOR_TYPE* w = (ACCUMULATOR_TYPE*)(&wei); unroll_for(uint kii = 0; kii < TILE_K; ++kii) { unroll_for(uint fi = 0; fi < TILE_OFM; ++fi) { - w[kii * TILE_OFM + fi] = (w[kii * TILE_OFM + fi] - dzp[fi]) * ds[fi]; + const uint w_idx = kii * TILE_OFM + fi; + const uint offset_ofm = out_f + fi*SIMD + sglid; + #if DECOMPRESSION_SCALE_GROUPS_NUM > 1 + const uint scale_offset = (offset_ofm % DECOMPRESSION_SCALE_BATCH_NUM) * DECOMPRESSION_SCALE_BATCH_PITCH + + ((kii + ki*TILE_K + ni*TILE_IFM*SIMD) / DECOMPRESSION_SCALE_GROUP_SIZE)*DECOMPRESSION_SCALE_FEATURE_PITCH; + ACCUMULATOR_TYPE ds = decompression_scale[scale_offset]; + #else + ACCUMULATOR_TYPE ds = d_scales[fi]; + #endif + + #if DECOMPRESSION_ZP_TERM + #if DECOMPRESSION_ZP_GROUPS_NUM > 1 + const uint zp_offset = (offset_ofm % DECOMPRESSION_ZP_BATCH_NUM) * DECOMPRESSION_ZP_BATCH_PITCH + + ((kii + ki*TILE_K + ni*TILE_IFM*SIMD) / DECOMPRESSION_ZP_GROUP_SIZE) * DECOMPRESSION_ZP_FEATURE_PITCH; + ACCUMULATOR_TYPE dzp = decompression_zp[zp_offset]; + #else + ACCUMULATOR_TYPE dzp = d_zps[fi]; + #endif + #else + ACCUMULATOR_TYPE dzp = ACCUMULATOR_VAL_ZERO; + #endif + w[w_idx] = (w[w_idx] - dzp) * ds; } } #endif @@ -230,7 +251,28 @@ KERNEL(fc)( ACCUMULATOR_TYPE* w = (ACCUMULATOR_TYPE*)(&wei); unroll_for(uint kii = 0; kii < TILE_K; ++kii) { unroll_for(uint fi = 0; fi < TILE_OFM; ++fi) { - w[kii * TILE_OFM + fi] = (w[kii * TILE_OFM + fi] - dzp[fi]) * ds[fi]; + const uint w_idx = kii * TILE_OFM + fi; + uint offset_ofm = out_f + fi*SIMD + get_sub_group_local_id(); + #if DECOMPRESSION_SCALE_GROUPS_NUM > 1 + const uint scale_offset = (offset_ofm % DECOMPRESSION_SCALE_BATCH_NUM) * DECOMPRESSION_SCALE_BATCH_PITCH + + ((kii + ki*TILE_K + ni*TILE_IFM*SIMD) / DECOMPRESSION_SCALE_GROUP_SIZE)*DECOMPRESSION_SCALE_FEATURE_PITCH; + ACCUMULATOR_TYPE ds = decompression_scale[scale_offset]; + #else + ACCUMULATOR_TYPE ds = d_scales[fi]; + #endif + + #if DECOMPRESSION_ZP_TERM + #if DECOMPRESSION_ZP_GROUPS_NUM > 1 + const uint zp_offset = (offset_ofm % DECOMPRESSION_ZP_BATCH_NUM) * DECOMPRESSION_ZP_BATCH_PITCH + + ((kii + ki*TILE_K + ni*TILE_IFM*SIMD) / DECOMPRESSION_ZP_GROUP_SIZE) * DECOMPRESSION_ZP_FEATURE_PITCH; + ACCUMULATOR_TYPE dzp = decompression_zp[zp_offset]; + #else + ACCUMULATOR_TYPE dzp = d_zps[fi]; + #endif + #else + ACCUMULATOR_TYPE dzp = ACCUMULATOR_VAL_ZERO; + #endif + w[w_idx] = (w[w_idx] - dzp) * ds; } } #endif diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/fully_connected_gpu_bfyx_ref.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/fully_connected_gpu_bfyx_ref.cl index 72e8d6d7d3d855..6374e65c4f5fcc 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/fully_connected_gpu_bfyx_ref.cl +++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/fully_connected_gpu_bfyx_ref.cl @@ -36,18 +36,24 @@ KERNEL(fc)( for (uint x = 0; x < INPUT0_SIZE_X; ++x) { const uint input0_idx = INPUT0_GET_INDEX(b, ofm, y, x); - const uint filter_idx = GET_FILTER_INDEX(FILTER, 0, oym, y, 0, 0); #if COMPRESSED_WEIGHTS - ACCUMULATOR_TYPE filter_compressed = TO_ACCUMULATOR_TYPE(weights[filter_idx]); #if DECOMPRESSION_ZP_TERM - ACCUMULATOR_TYPE zp = TO_ACCUMULATOR_TYPE(decompression_zp[DECOMPRESSION_ZP_GET_INDEX_SAFE(0, oym, 0, 0)]); + const uint zp_offset = DECOMPRESSION_ZP_GET_INDEX_SAFE(oym, y / DECOMPRESSION_ZP_GROUP_SIZE, 0, 0); + ACCUMULATOR_TYPE zp = TO_ACCUMULATOR_TYPE(decompression_zp[zp_offset]); #else ACCUMULATOR_TYPE zp = ACCUMULATOR_VAL_ZERO; #endif - DECOMPRESSION_SCALE_TYPE scale = decompression_scale[DECOMPRESSION_SCALE_GET_INDEX_SAFE(0, oym, 0, 0)]; - ACCUMULATOR_TYPE filter_val = (TO_ACCUMULATOR_TYPE(filter_compressed) - TO_ACCUMULATOR_TYPE(zp)) * scale; + const uint decomp_offset = DECOMPRESSION_SCALE_GET_INDEX_SAFE(oym, y / DECOMPRESSION_SCALE_GROUP_SIZE, 0, 0); + DECOMPRESSION_SCALE_TYPE scale = decompression_scale[decomp_offset]; + #endif + + #if COMPRESSED_WEIGHTS_INT8 + const uint filter_idx = GET_FILTER_INDEX(FILTER, 0, oym, y, 0, 0); + ACCUMULATOR_TYPE filter_compressed = TO_ACCUMULATOR_TYPE(weights[filter_idx]); + ACCUMULATOR_TYPE filter_val = (filter_compressed - zp) * scale; dotProd += (ACCUMULATOR_TYPE)(input[input0_idx]) * (ACCUMULATOR_TYPE)(filter_val); #else + const uint filter_idx = GET_FILTER_INDEX(FILTER, 0, oym, y, 0, 0); dotProd += (ACCUMULATOR_TYPE)(input[input0_idx]) * (ACCUMULATOR_TYPE)(weights[filter_idx]); #endif } @@ -67,19 +73,25 @@ KERNEL(fc)( for (uint x = 0; x < INPUT0_SIZE_X; ++x) { const uint input0_idx = INPUT0_GET_INDEX(b, ifm, y, x); - const uint filter_idx = GET_FILTER_INDEX(FILTER, 0, ofm, ifm, y, x); #if COMPRESSED_WEIGHTS - FILTER_TYPE filter_compressed = weights[filter_idx]; #if DECOMPRESSION_ZP_TERM - ACCUMULATOR_TYPE zp = decompression_zp[DECOMPRESSION_ZP_GET_INDEX_SAFE(0, ofm, 0, 0)]; + const uint zp_offset = DECOMPRESSION_ZP_GET_INDEX_SAFE(ofm, ifm / DECOMPRESSION_ZP_GROUP_SIZE, 0, 0); + ACCUMULATOR_TYPE zp = TO_ACCUMULATOR_TYPE(decompression_zp[zp_offset]); #else ACCUMULATOR_TYPE zp = ACCUMULATOR_VAL_ZERO; #endif + const uint decomp_offset = DECOMPRESSION_SCALE_GET_INDEX_SAFE(ofm, ifm / DECOMPRESSION_SCALE_GROUP_SIZE, 0, 0); + DECOMPRESSION_SCALE_TYPE scale = decompression_scale[decomp_offset]; + #endif - DECOMPRESSION_SCALE_TYPE scale = decompression_scale[DECOMPRESSION_SCALE_GET_INDEX_SAFE(0, ofm, 0, 0)]; - ACCUMULATOR_TYPE filter_val = (TO_ACCUMULATOR_TYPE(filter_compressed) - TO_ACCUMULATOR_TYPE(zp)) * scale; + + #if COMPRESSED_WEIGHTS_INT8 + const uint filter_idx = GET_FILTER_INDEX(FILTER, 0, ofm, ifm, y, x); + FILTER_TYPE filter_compressed = weights[filter_idx]; + ACCUMULATOR_TYPE filter_val = (TO_ACCUMULATOR_TYPE(filter_compressed) - zp) * scale; dotProd += (ACCUMULATOR_TYPE)(input[input0_idx]) * (ACCUMULATOR_TYPE)(filter_val); #else + const uint filter_idx = GET_FILTER_INDEX(FILTER, 0, ofm, ifm, y, x); dotProd += (ACCUMULATOR_TYPE)(input[input0_idx]) * (ACCUMULATOR_TYPE)(weights[filter_idx]); #endif } diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/group_normalization_gpu_ref.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/group_normalization_gpu_ref.cl new file mode 100644 index 00000000000000..2715f90780071d --- /dev/null +++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/group_normalization_gpu_ref.cl @@ -0,0 +1,144 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "include/batch_headers/common.cl" + +#define NUM_CHANNELS_IN_GROUP (INPUT0_FEATURE_NUM / NUM_GROUPS) +#define CHANNEL_SIZE (INPUT0_BATCH_PITCH / INPUT0_FEATURE_NUM) +#define GROUP_SIZE (NUM_CHANNELS_IN_GROUP * CHANNEL_SIZE) + +#if MEAN_KERNEL_ENABLED || STANDARD_DEVIATION_KERNEL_ENABLED +inline void FUNC(kahan_summation)(INPUT0_TYPE elem, __private float* compensation, __private float* sum) { + if (isfinite(elem) && isfinite(*sum)) { + float temp = *sum + (elem - *compensation); + *compensation = (temp - *sum) - (elem - *compensation); + *sum = temp; + } else { + *sum += elem; + } +} +#endif + +#if MEAN_KERNEL_ENABLED + +KERNEL (calc_mean_ref)( __global INPUT0_TYPE* input + , __global float* output +#if HAS_FUSED_OPS_DECLS + , FUSED_OPS_DECLS +#endif +) +{ + const int batch = get_global_id(0); + if (batch >= INPUT0_BATCH_NUM) + return; + const int group = get_global_id(1); + const int feature_begin = group * NUM_CHANNELS_IN_GROUP; + const int feature_end = group * NUM_CHANNELS_IN_GROUP + NUM_CHANNELS_IN_GROUP; + float variance = 0.f, error = 0.f, mean_value = 0.f; + for (int feature = feature_begin; feature < feature_end; feature++) + { + if (feature >= INPUT0_FEATURE_NUM) + continue; +#if OUTPUT_DIMS > 4 + for (int z = 0; z < INPUT0_SIZE_Z; z++) +#endif + for (int y = 0; y < INPUT0_SIZE_Y; y++) + for (int x = 0; x < INPUT0_SIZE_X; x++) + { +#if OUTPUT_DIMS == 5 + size_t input_idx = INPUT0_GET_INDEX(batch, feature, z, y, x); +#elif OUTPUT_DIMS == 4 + size_t input_idx = INPUT0_GET_INDEX(batch, feature, y, x); +#endif + FUNC_CALL(kahan_summation)(input[input_idx], &error, &mean_value); + } + } + mean_value /= GROUP_SIZE; + output[batch * NUM_GROUPS + group] = mean_value; +} + +#elif STANDARD_DEVIATION_KERNEL_ENABLED + +KERNEL (calc_standard_deviation_ref)( __global INPUT0_TYPE* input + , __global float* mean + , __global float* output +#if HAS_FUSED_OPS_DECLS + , FUSED_OPS_DECLS +#endif +) +{ + const int batch = get_global_id(0); + if (batch >= INPUT0_BATCH_NUM) + return; + const int group = get_global_id(1); + const output_idx = batch * NUM_GROUPS + group; + const int feature_begin = group * NUM_CHANNELS_IN_GROUP; + const int feature_end = group * NUM_CHANNELS_IN_GROUP + NUM_CHANNELS_IN_GROUP; + float variance = 0.f, error = 0.f; + + for (int feature = feature_begin; feature < feature_end; feature++) + { + if (feature >= INPUT0_FEATURE_NUM) + continue; +#if OUTPUT_DIMS > 4 + for (int z = 0; z < INPUT0_SIZE_Z; z++) +#endif + for (int y = 0; y < INPUT0_SIZE_Y; y++) + for (int x = 0; x < INPUT0_SIZE_X; x++) + { +#if OUTPUT_DIMS == 5 + size_t input_idx = INPUT0_GET_INDEX(batch, feature, z, y, x); +#elif OUTPUT_DIMS == 4 + size_t input_idx = INPUT0_GET_INDEX(batch, feature, y, x); +#endif + FUNC_CALL(kahan_summation)(pow(input[input_idx] - mean[output_idx], 2), &error, &variance); + } + } + variance /= GROUP_SIZE; + float standard_deviation = sqrt(variance + EPSILON); + output[output_idx] = standard_deviation; +} +#elif NORMALIZE_KERNEL_ENABLED +KERNEL (normalize_ref)( __global INPUT0_TYPE* input + , __global INPUT0_TYPE* scale_values + , __global INPUT0_TYPE* bias_values + , __global float* mean_values + , __global float* standard_deviation_values + , __global OUTPUT_TYPE* output +#if HAS_FUSED_OPS_DECLS + , FUSED_OPS_DECLS +#endif +) +{ + const int batch = get_global_id(0); +#if OUTPUT_DIMS == 4 + const int feature = get_global_id(1); +#elif OUTPUT_DIMS == 5 + const int feature = get_global_id(1) / OUTPUT_SIZE_Z; + const int z = get_global_id(1) % OUTPUT_SIZE_Z; +#endif + const int y = get_global_id(2) / OUTPUT_SIZE_X; + const int x = get_global_id(2) % OUTPUT_SIZE_X; + const int group = feature / NUM_CHANNELS_IN_GROUP; + float mean = mean_values[batch * NUM_GROUPS + group]; + float standard_deviation = standard_deviation_values[batch * NUM_GROUPS + group]; +#if OUTPUT_DIMS == 4 + size_t output_idx = OUTPUT_GET_INDEX(batch, feature, y, x); +#elif OUTPUT_DIMS == 5 + size_t output_idx = OUTPUT_GET_INDEX(batch, feature, z, y, x); +#endif + OUTPUT_TYPE res = ((input[output_idx] - mean) / standard_deviation) * scale_values[feature] + bias_values[feature]; +#if HAS_FUSED_OPS + FUSED_OPS; + output[output_idx] = FUSED_OPS_RESULT; +#else + output[output_idx] = ACTIVATION(res, ACTIVATION_PARAMS); +#endif +} + +#endif + +#undef NUM_CHANNELS_IN_GROUP +#undef CHANNEL_SIZE +#undef GROUP_SIZE diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/fetch_data.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/fetch_data.cl index eaf56e090abb77..d2cc9d3cc77a3d 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/fetch_data.cl +++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/fetch_data.cl @@ -293,6 +293,38 @@ inline uint get_b_fs_yx_fsv_index_safe(uint b, uint f, uint y, uint x, CAT(prefix, _PAD_BEFORE_SIZE_X), \ CAT(prefix, _PAD_AFTER_SIZE_X), 4) +#define GET_DATA_B_FS_YX_FSV8_INDEX(prefix, b, f, y, x) \ + get_b_fs_yx_fsv_index( \ + b, f, y, x, \ + CAT(prefix, _SIZE_X ), \ + CAT(prefix, _SIZE_Y), \ + CAT(prefix, _FEATURE_NUM), \ + CAT(prefix, _BATCH_NUM), \ + CAT(prefix, _PAD_BEFORE_BATCH_NUM), \ + CAT(prefix, _PAD_AFTER_BATCH_NUM), \ + CAT(prefix, _PAD_BEFORE_FEATURE_NUM), \ + CAT(prefix, _PAD_AFTER_FEATURE_NUM), \ + CAT(prefix, _PAD_BEFORE_SIZE_Y), \ + CAT(prefix, _PAD_AFTER_SIZE_Y), \ + CAT(prefix, _PAD_BEFORE_SIZE_X), \ + CAT(prefix, _PAD_AFTER_SIZE_X), 8) + +#define GET_DATA_B_FS_YX_FSV8_INDEX_SAFE(prefix, b, f, y, x) \ + get_b_fs_yx_fsv_index_safe( \ + b, f, y, x, \ + CAT(prefix, _SIZE_X ), \ + CAT(prefix, _SIZE_Y), \ + CAT(prefix, _FEATURE_NUM), \ + CAT(prefix, _BATCH_NUM), \ + CAT(prefix, _PAD_BEFORE_BATCH_NUM), \ + CAT(prefix, _PAD_AFTER_BATCH_NUM), \ + CAT(prefix, _PAD_BEFORE_FEATURE_NUM), \ + CAT(prefix, _PAD_AFTER_FEATURE_NUM), \ + CAT(prefix, _PAD_BEFORE_SIZE_Y), \ + CAT(prefix, _PAD_AFTER_SIZE_Y), \ + CAT(prefix, _PAD_BEFORE_SIZE_X), \ + CAT(prefix, _PAD_AFTER_SIZE_X), 8) + #define GET_DATA_B_FS_YX_FSV32_INDEX(prefix, b, f, y, x) \ get_b_fs_yx_fsv_index( \ b, f, y, x, \ @@ -482,6 +514,38 @@ inline uint get_fs_b_yx_fsv32_index_safe(uint b, uint f, uint y, uint x, CAT(prefix, _PAD_BEFORE_SIZE_X), \ CAT(prefix, _PAD_AFTER_SIZE_X), 4) +#define GET_DATA_B_FS_ZYX_FSV8_INDEX(prefix, b, f, z, y, x) \ + get_b_fs_zyx_fsv_index( \ + b, f, z, y, x, \ + CAT(prefix, _SIZE_X ), \ + CAT(prefix, _SIZE_Y), \ + CAT(prefix, _SIZE_Z), \ + CAT(prefix, _FEATURE_NUM), \ + CAT(prefix, _PAD_BEFORE_FEATURE_NUM), \ + CAT(prefix, _PAD_AFTER_FEATURE_NUM), \ + CAT(prefix, _PAD_BEFORE_SIZE_Z), \ + CAT(prefix, _PAD_AFTER_SIZE_Z), \ + CAT(prefix, _PAD_BEFORE_SIZE_Y), \ + CAT(prefix, _PAD_AFTER_SIZE_Y), \ + CAT(prefix, _PAD_BEFORE_SIZE_X), \ + CAT(prefix, _PAD_AFTER_SIZE_X), 8) + +#define GET_DATA_B_FS_ZYX_FSV8_INDEX_SAFE(prefix, b, f, z, y, x) \ + get_b_fs_zyx_fsv_index_safe( \ + b, f, z, y, x, \ + CAT(prefix, _SIZE_X), \ + CAT(prefix, _SIZE_Y), \ + CAT(prefix, _SIZE_Z), \ + CAT(prefix, _FEATURE_NUM), \ + CAT(prefix, _PAD_BEFORE_FEATURE_NUM), \ + CAT(prefix, _PAD_AFTER_FEATURE_NUM), \ + CAT(prefix, _PAD_BEFORE_SIZE_Z), \ + CAT(prefix, _PAD_AFTER_SIZE_Z), \ + CAT(prefix, _PAD_BEFORE_SIZE_Y), \ + CAT(prefix, _PAD_AFTER_SIZE_Y), \ + CAT(prefix, _PAD_BEFORE_SIZE_X), \ + CAT(prefix, _PAD_AFTER_SIZE_X), 8) + #define GET_DATA_B_FS_ZYX_FSV16_INDEX(prefix, b, f, z, y, x) \ get_b_fs_zyx_fsv_index( \ b, f, z, y, x, \ @@ -775,6 +839,38 @@ inline uint get_bs_fs_zyx_bsv_fsv_index(uint b, uint f, uint z, uint y, uint x, CAT(prefix, _PAD_BEFORE_SIZE_X), \ CAT(prefix, _PAD_AFTER_SIZE_X), 16, 4) +#define GET_DATA_BS_FS_ZYX_BSV16_FSV8_INDEX(prefix, b, f, z, y, x) \ + get_bs_fs_zyx_bsv_fsv_index( \ + b, f, z, y, x, \ + CAT(prefix, _SIZE_X), \ + CAT(prefix, _SIZE_Y), \ + CAT(prefix, _SIZE_Z), \ + CAT(prefix, _FEATURE_NUM), \ + CAT(prefix, _PAD_BEFORE_FEATURE_NUM), \ + CAT(prefix, _PAD_AFTER_FEATURE_NUM), \ + CAT(prefix, _PAD_BEFORE_SIZE_Z), \ + CAT(prefix, _PAD_AFTER_SIZE_Z), \ + CAT(prefix, _PAD_BEFORE_SIZE_Y), \ + CAT(prefix, _PAD_AFTER_SIZE_Y), \ + CAT(prefix, _PAD_BEFORE_SIZE_X), \ + CAT(prefix, _PAD_AFTER_SIZE_X), 16, 8) + +#define GET_DATA_BS_FS_YX_BSV16_FSV8_INDEX(prefix, b, f, y, x) \ + get_bs_fs_zyx_bsv_fsv_index( \ + b, f, 0, y, x, \ + CAT(prefix, _SIZE_X), \ + CAT(prefix, _SIZE_Y), \ + CAT(prefix, _SIZE_Z), \ + CAT(prefix, _FEATURE_NUM), \ + CAT(prefix, _PAD_BEFORE_FEATURE_NUM), \ + CAT(prefix, _PAD_AFTER_FEATURE_NUM), \ + CAT(prefix, _PAD_BEFORE_SIZE_Z), \ + CAT(prefix, _PAD_AFTER_SIZE_Z), \ + CAT(prefix, _PAD_BEFORE_SIZE_Y), \ + CAT(prefix, _PAD_AFTER_SIZE_Y), \ + CAT(prefix, _PAD_BEFORE_SIZE_X), \ + CAT(prefix, _PAD_AFTER_SIZE_X), 16, 8) + #define GET_DATA_BS_FS_ZYX_BSV8_FSV4_INDEX(prefix, b, f, z, y, x) \ get_bs_fs_zyx_bsv_fsv_index( \ b, f, z, y, x, \ @@ -1053,6 +1149,40 @@ inline uint get_bs_fs_zyx_bsv_fsv_index(uint b, uint f, uint z, uint y, uint x, CAT(prefix, _PAD_BEFORE_SIZE_X), \ CAT(prefix, _PAD_AFTER_SIZE_X), 16, 4) +#define GET_DATA_BS_FS_YX_BSV16_FSV8_INDEX_SAFE(prefix, b, f, y, x) \ + get_bs_fs_zyx_bsv_fsv_index_safe( \ + b, f, 0, y, x, \ + CAT(prefix, _SIZE_X), \ + CAT(prefix, _SIZE_Y), \ + CAT(prefix, _SIZE_Z), \ + CAT(prefix, _FEATURE_NUM), \ + CAT(prefix, _BATCH_NUM), \ + CAT(prefix, _PAD_BEFORE_FEATURE_NUM), \ + CAT(prefix, _PAD_AFTER_FEATURE_NUM), \ + CAT(prefix, _PAD_BEFORE_SIZE_Z), \ + CAT(prefix, _PAD_AFTER_SIZE_Z), \ + CAT(prefix, _PAD_BEFORE_SIZE_Y), \ + CAT(prefix, _PAD_AFTER_SIZE_Y), \ + CAT(prefix, _PAD_BEFORE_SIZE_X), \ + CAT(prefix, _PAD_AFTER_SIZE_X), 16, 8) + +#define GET_DATA_BS_FS_ZYX_BSV16_FSV8_INDEX_SAFE(prefix, b, f, z, y, x) \ + get_bs_fs_zyx_bsv_fsv_index_safe( \ + b, f, z, y, x, \ + CAT(prefix, _SIZE_X), \ + CAT(prefix, _SIZE_Y), \ + CAT(prefix, _SIZE_Z), \ + CAT(prefix, _FEATURE_NUM), \ + CAT(prefix, _BATCH_NUM), \ + CAT(prefix, _PAD_BEFORE_FEATURE_NUM), \ + CAT(prefix, _PAD_AFTER_FEATURE_NUM), \ + CAT(prefix, _PAD_BEFORE_SIZE_Z), \ + CAT(prefix, _PAD_AFTER_SIZE_Z), \ + CAT(prefix, _PAD_BEFORE_SIZE_Y), \ + CAT(prefix, _PAD_AFTER_SIZE_Y), \ + CAT(prefix, _PAD_BEFORE_SIZE_X), \ + CAT(prefix, _PAD_AFTER_SIZE_X), 16, 8) + #define GET_DATA_BS_FS_YX_BSV8_FSV4_INDEX_SAFE(prefix, b, f, y, x) \ get_bs_fs_zyx_bsv_fsv_index_safe( \ b, f, 0, y, x, \ diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/fetch_weights.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/fetch_weights.cl index 37512661a91119..939ec0f495d5dd 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/fetch_weights.cl +++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/fetch_weights.cl @@ -16,6 +16,18 @@ isv \ ) +#define GET_FILTER_IS_OS_YX_OSV_ISV_INDEX(prefix, o, i, y, x, osv, isv) \ + get_os_is_zyx_isv_osv_index( \ + i, o, 0, y, x, \ + CAT(prefix, _SIZE_X), \ + CAT(prefix, _SIZE_Y), \ + 1, \ + CAT(prefix, _OFM_NUM), \ + CAT(prefix, _IFM_NUM), \ + isv, \ + osv \ + ) + #define GET_FILTER_IS_OS_YX_ISV_OSV_INDEX(prefix, o, i, y, x, osv, isv) \ get_is_os_zyx_isv_osv_index( \ o, i, 0, y, x, \ @@ -1447,6 +1459,22 @@ inline uint get_g_os_is_yx_osv_isv(uint g, uint o, uint i, uint y, uint x, x_size, y_size, 1, i_size, o_size, osv_size, isv_size); } +#define GET_FILTER_OS_IS_YX_OSV2_ISV16_INDEX(prefix, o, i, y, x) \ + get_g_os_is_yx_osv_isv( \ + 0, o, i, y, x, \ + CAT(prefix, _IFM_NUM), \ + CAT(prefix, _OFM_NUM), \ + CAT(prefix, _SIZE_X), \ + CAT(prefix, _SIZE_Y), 2, 16) + +#define GET_FILTER_OS_IS_YX_OSV4_ISV16_INDEX(prefix, o, i, y, x) \ + get_g_os_is_yx_osv_isv( \ + 0, o, i, y, x, \ + CAT(prefix, _IFM_NUM), \ + CAT(prefix, _OFM_NUM), \ + CAT(prefix, _SIZE_X), \ + CAT(prefix, _SIZE_Y), 4, 16) + #define GET_FILTER_OS_IS_YX_OSV8_ISV2_INDEX(prefix, o, i, y, x) \ get_g_os_is_yx_osv_isv( \ 0, o, i, y, x, \ @@ -1826,14 +1854,15 @@ inline uint get_g_os_zyx_is_osv_isv_index(uint g, uint o, uint i, uint z, uint y #define GET_FILTER_G_OS_ZYX_IS_OSV32_ISV16_INDEX(tensor, g, o, i, z, y, x) GET_FILTER_G_OS_ZYX_IS_OSV_ISV_INDEX(tensor, g, o, i, z, y, x, 32, 16) #define GET_FILTER_G_OS_ZYX_IS_OSV32_ISV32_INDEX(tensor, g, o, i, z, y, x) GET_FILTER_G_OS_ZYX_IS_OSV_ISV_INDEX(tensor, g, o, i, z, y, x, 32, 32) -#define GET_FILTER_O_IS_YX_ISV16_INDEX(prefix, o, i, y, x, isv) \ - CAT(prefix, _OFFSET) + \ - ((i) % (isv)) + \ - (o)*CAT(prefix, _OFM_PITCH) + \ - (isv)*( \ - (x)*CAT(prefix, _X_PITCH) + \ - (y)*CAT(prefix, _Y_PITCH) + \ - ((i) / (isv))*CAT(prefix, _IFM_PITCH) \ +#define GET_FILTER_O_IS_ZYX_ISV16_INDEX(prefix, o, i, z, y, x, isv) \ + CAT(prefix, _OFFSET) + \ + ((i) % (isv)) + \ + (o)*CAT(prefix, _OFM_PITCH) + \ + (isv)*( \ + (x)*CAT(prefix, _X_PITCH) + \ + (y)*CAT(prefix, _Y_PITCH) + \ + (z)*CAT(prefix, _Z_PITCH) + \ + ((i) / (isv))*CAT(prefix, _IFM_PITCH) \ ) #define GET_FILTER_OS_YXI_OSV16(prefix, o, i, y, x) \ diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/reorder_weights.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/reorder_weights.cl index 0dfbd30862437c..052c6721a88141 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/reorder_weights.cl +++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/reorder_weights.cl @@ -280,8 +280,14 @@ inline uint FUNC(get_input_index)(uint g, uint o, uint i, uint z, uint y, uint x return GET_FILTER_OS_IYX_OSV_INDEX(INPUT0, o, i, y, x, 32); #elif defined INPUT0_LAYOUT_OS_IYX_OSV32__AI32 return GET_FILTER_OS_IYX_OSV_INDEX(INPUT0, o, i, y, x, 32); +#elif defined INPUT0_LAYOUT_O_IS_YX_ISV2 + return GET_FILTER_O_IS_ZYX_ISV16_INDEX(INPUT0, o, i, 0, y, x, 2); +#elif defined INPUT0_LAYOUT_O_IS_YX_ISV4 + return GET_FILTER_O_IS_ZYX_ISV16_INDEX(INPUT0, o, i, 0, y, x, 4); #elif defined INPUT0_LAYOUT_O_IS_YX_ISV16 - return GET_FILTER_O_IS_YX_ISV16_INDEX(INPUT0, o, i, y, x, 16); + return GET_FILTER_O_IS_ZYX_ISV16_INDEX(INPUT0, o, i, 0, y, x, 16); +#elif defined INPUT0_LAYOUT_O_IS_ZYX_ISV16 + return GET_FILTER_O_IS_ZYX_ISV16_INDEX(INPUT0, o, i, z, y, x, 16); #elif defined INPUT0_LAYOUT_IYX_OSV64 return GET_FILTER_OS_IYX_OSV_INDEX(INPUT0, o, i, y, x, 64); #elif defined INPUT0_LAYOUT_OS_IYX_OSV16_ROTATE_180 @@ -320,6 +326,8 @@ inline uint FUNC(get_input_index)(uint g, uint o, uint i, uint z, uint y, uint x return GET_FILTER_IS_OS_YX_ISV16_OSV16_INDEX(INPUT0, o, i, y, x, SUB_GROUP_SIZE); #elif defined INPUT0_LAYOUT_IS_OS_YX_ISV16_OSV8 return GET_FILTER_IS_OS_YX_ISV16_OSV8_INDEX(INPUT0, o, i, y, x, SUB_GROUP_SIZE); +#elif defined INPUT0_LAYOUT_IS_OS_YX_OSV8_ISV4 + return GET_FILTER_IS_OS_YX_OSV_ISV_INDEX(INPUT0, o, i, y, x, 8, 4); #elif defined INPUT0_LAYOUT_IS_OS_YX_ISV16_OSV4 return GET_FILTER_IS_OS_YX_ISV_OSV_INDEX(INPUT0, o, i, y, x, 16, 4); #elif defined INPUT0_LAYOUT_IS_OS_YX_ISV16_OSV2 @@ -384,6 +392,10 @@ inline uint FUNC(get_input_index)(uint g, uint o, uint i, uint z, uint y, uint x return GET_FILTER_G_OS_IYX_OSV16(INPUT0, g, o, i, y, x, 16); #elif defined INPUT0_LAYOUT_G_OS_IYX_OSV32 return GET_FILTER_G_OS_IYX_OSV16(INPUT0, g, o, i, y, x, 32); +#elif defined INPUT0_LAYOUT_GS_OIYX_GSV8 + return GET_FILTER_GS_OIYX_GSV16(INPUT0, g, o, i, y, x, 8); +#elif defined INPUT0_LAYOUT_GS_OIZYX_GSV8 + return GET_FILTER_GS_OIZYX_GSV16(INPUT0, g, o, i, z, y, x, 8); #elif defined INPUT0_LAYOUT_GS_OIYX_GSV16 return GET_FILTER_GS_OIYX_GSV16(INPUT0, g, o, i, y, x, 16); #elif defined INPUT0_LAYOUT_GS_OIZYX_GSV16 @@ -426,6 +438,10 @@ inline uint FUNC(get_input_index)(uint g, uint o, uint i, uint z, uint y, uint x return GET_FILTER_OS_IS_YX_OSV8_ISV4_INDEX(INPUT0, o, i, y, x); #elif defined INPUT0_LAYOUT_OS_IS_ZYX_OSV8_ISV4 return GET_FILTER_OS_IS_ZYX_OSV8_ISV4_INDEX(INPUT0, o, i, z, y, x); +#elif defined INPUT0_LAYOUT_OS_IS_YX_OSV2_ISV16 + return GET_FILTER_OS_IS_YX_OSV2_ISV16_INDEX(INPUT0, o, i, y, x); +#elif defined INPUT0_LAYOUT_OS_IS_YX_OSV4_ISV16 + return GET_FILTER_OS_IS_YX_OSV4_ISV16_INDEX(INPUT0, o, i, y, x); #elif defined INPUT0_LAYOUT_G_OS_IS_ZYX_OSV16_ISV16 return GET_FILTER_G_OS_IS_ZYX_OSV16_ISV16_INDEX(INPUT0, g, o, i, z, y, x); #elif defined INPUT0_LAYOUT_OS_IS_ZYX_OSV32_ISV16 @@ -487,8 +503,14 @@ inline uint FUNC(get_output_index)(uint g, uint o, uint i, uint z, uint y, uint return GET_FILTER_OS_IYX_OSV_INDEX(OUTPUT, o, i, y, x, 32); #elif defined OUTPUT_LAYOUT_OS_IYX_OSV64 return GET_FILTER_OS_IYX_OSV_INDEX(OUTPUT, o, i, y, x, 64); +#elif defined OUTPUT_LAYOUT_O_IS_YX_ISV2 + return GET_FILTER_O_IS_ZYX_ISV16_INDEX(OUTPUT, o, i, 0, y, x, 2); +#elif defined OUTPUT_LAYOUT_O_IS_YX_ISV4 + return GET_FILTER_O_IS_ZYX_ISV16_INDEX(OUTPUT, o, i, 0, y, x, 4); #elif defined OUTPUT_LAYOUT_O_IS_YX_ISV16 - return GET_FILTER_O_IS_YX_ISV16_INDEX(OUTPUT, o, i, y, x, 16); + return GET_FILTER_O_IS_ZYX_ISV16_INDEX(OUTPUT, o, i, 0, y, x, 16); +#elif defined OUTPUT_LAYOUT_O_IS_ZYX_ISV16 + return GET_FILTER_O_IS_ZYX_ISV16_INDEX(OUTPUT, o, i, z, y, x, 16); #elif defined OUTPUT_LAYOUT_OS_IYX_OSV16_ROTATE_180 return GET_FILTER_OS_IYX_OSV_ROTATE_180_INDEX(OUTPUT, o, i, y, x, SUB_GROUP_SIZE); #elif defined OUTPUT_LAYOUT_I_YXS_OS_YXSV2_OSV16 @@ -523,6 +545,10 @@ inline uint FUNC(get_output_index)(uint g, uint o, uint i, uint z, uint y, uint return GET_FILTER_OS_IS_YX_OSV8_ISV4_INDEX(OUTPUT, o, i, y, x); #elif defined OUTPUT_LAYOUT_OS_IS_ZYX_OSV8_ISV4 return GET_FILTER_OS_IS_ZYX_OSV8_ISV4_INDEX(OUTPUT, o, i, z, y, x); +#elif defined OUTPUT_LAYOUT_OS_IS_YX_OSV2_ISV16 + return GET_FILTER_OS_IS_YX_OSV2_ISV16_INDEX(OUTPUT, o, i, y, x); +#elif defined OUTPUT_LAYOUT_OS_IS_YX_OSV4_ISV16 + return GET_FILTER_OS_IS_YX_OSV4_ISV16_INDEX(OUTPUT, o, i, y, x); #elif defined OUTPUT_LAYOUT_OS_IS_YX_OSV32_ISV4_SWIZZLED_BY_2 return GET_FILTER_OS_IS_YX_OSV32_ISV4_SWIZZLED_BY_2_INDEX(OUTPUT, o, i, y, x); #elif defined OUTPUT_LAYOUT_OS_IS_YX_OSV32_ISV4 @@ -583,6 +609,8 @@ inline uint FUNC(get_output_index)(uint g, uint o, uint i, uint z, uint y, uint return GET_FILTER_IS_OS_YX_ISV16_OSV16_INDEX(OUTPUT, o, i, y, x, SUB_GROUP_SIZE); #elif defined OUTPUT_LAYOUT_IS_OS_YX_ISV16_OSV8 return GET_FILTER_IS_OS_YX_ISV16_OSV8_INDEX(OUTPUT, o, i, y, x, SUB_GROUP_SIZE); +#elif defined OUTPUT_LAYOUT_IS_OS_YX_OSV8_ISV4 + return GET_FILTER_IS_OS_YX_OSV_ISV_INDEX(OUTPUT, o, i, y, x, 8, 4); #elif defined OUTPUT_LAYOUT_IS_OS_YX_ISV16_OSV4 return GET_FILTER_IS_OS_YX_ISV_OSV_INDEX(OUTPUT, o, i, y, x, 16, 4); #elif defined OUTPUT_LAYOUT_IS_OS_YX_ISV16_OSV2 @@ -645,6 +673,10 @@ inline uint FUNC(get_output_index)(uint g, uint o, uint i, uint z, uint y, uint return GET_FILTER_G_OS_IYX_OSV16(OUTPUT, g, o, i, y, x, 16); #elif defined OUTPUT_LAYOUT_G_OS_IYX_OSV32 return GET_FILTER_G_OS_IYX_OSV16(OUTPUT, g, o, i, y, x, 32); +#elif defined OUTPUT_LAYOUT_GS_OIYX_GSV8 + return GET_FILTER_GS_OIYX_GSV16(OUTPUT, g, o, i, y, x, 8); +#elif defined OUTPUT_LAYOUT_GS_OIZYX_GSV8 + return GET_FILTER_GS_OIZYX_GSV16(OUTPUT, g, o, i, z, y, x, 8); #elif defined OUTPUT_LAYOUT_GS_OIYX_GSV16 return GET_FILTER_GS_OIYX_GSV16(OUTPUT, g, o, i, y, x, 16); #elif defined OUTPUT_LAYOUT_GS_OIZYX_GSV16 diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/rms_gpu_bfyx_opt.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/rms_gpu_bfyx_opt.cl new file mode 100644 index 00000000000000..77d16d06405aa5 --- /dev/null +++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/rms_gpu_bfyx_opt.cl @@ -0,0 +1,72 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "include/batch_headers/fetch_data.cl" + +KERNEL(rms_gpu_bfyx_opt)( + OPTIONAL_SHAPE_INFO_ARG + const __global INPUT0_TYPE* input, + const __global INPUT1_TYPE* gamma, + __global OUTPUT_TYPE* output) +{ + const uint in_data_idx = get_global_id(0); + const uint data_idx = get_global_id(1); + const uint lws_size = LWS; + const uint items_num = VEC_SIZE; + const uint data_size = DATA_SIZE; + const uint total_items_num = lws_size * items_num; +#if !IS_DYNAMIC + const uint leftovers = LEFTOVERS; +#else + const uint leftovers = data_size % items_num; +#endif + + const uint data_offset = data_idx * data_size; + const uint in_data_offset = data_offset + in_data_idx * items_num; + const uint gamma_offset = in_data_idx * items_num; + + ACCUMULATOR_TYPE rms = ACCUMULATOR_VAL_ZERO; + + __local ACCUMULATOR_TYPE slm_buf[SLM_SIZE]; + + INPUT_VEC_TYPE inputs = AS_INPUT_VEC_TYPE(VLOAD(0, input + in_data_offset)); + ACCUMULATOR_VEC_TYPE square = native_powr(TO_ACCUMULATOR_VEC_TYPE(inputs), (ACCUMULATOR_VEC_TYPE)(2)); + unroll_for (uint i = 0; i < VEC_SIZE; ++i) { + rms += square[i]; + } + + if (in_data_idx < leftovers) { + const uint input_idx = data_offset + total_items_num + in_data_idx; + rms += native_powr(TO_ACCUMULATOR_TYPE(input[input_idx]), 2); + } + + slm_buf[in_data_idx] = rms; + + barrier(CLK_LOCAL_MEM_FENCE); + if (in_data_idx == 0) { +#if !IS_DYNAMIC + unroll_for (uint i = 1; i < LWS; ++i) +#else + for (uint i = 1; i < lws_size; ++i) +#endif + rms += slm_buf[i]; + + rms = rms / data_size; + slm_buf[0] = native_powr(sqrt(rms + TO_ACCUMULATOR_TYPE(EPSILON)), -1); + } + barrier(CLK_LOCAL_MEM_FENCE); + + rms = slm_buf[0]; + + OUTPUT_VEC_TYPE results = TO_OUTPUT_VEC_TYPE((ACCUMULATOR_VEC_TYPE)(rms) * TO_ACCUMULATOR_VEC_TYPE(inputs) * AS_ACCUMULATOR_VEC_TYPE(VLOAD(0, gamma + gamma_offset))); + VSTORE(results, 0, output + in_data_offset); + + if (in_data_idx < leftovers) { + const uint input_idx = data_offset + total_items_num + in_data_idx; + const uint output_idx = data_offset + total_items_num + in_data_idx; + const uint gamma_idx = total_items_num + in_data_idx; + OUTPUT_TYPE result = TO_OUTPUT_TYPE(rms * TO_ACCUMULATOR_TYPE(input[input_idx]) * TO_ACCUMULATOR_TYPE(gamma[gamma_idx])); + output[output_idx] = result; + } +} diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/rms_gpu_ref.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/rms_gpu_ref.cl new file mode 100644 index 00000000000000..88c5eb520d33e3 --- /dev/null +++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/rms_gpu_ref.cl @@ -0,0 +1,45 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "include/fetch_utils.cl" + +KERNEL(rms_gpu_ref)( + OPTIONAL_SHAPE_INFO_ARG + const __global INPUT0_TYPE* input, + const __global INPUT1_TYPE* gamma, + __global OUTPUT_TYPE* output) +{ + const uint b = get_global_id(0); + const uint f = get_global_id(1); + const uint w = 0; + + ACCUMULATOR_TYPE rms = ACCUMULATOR_VAL_ZERO; + for (uint z = 0; z < INPUT0_SIZE_Z; z++) { + for (uint y = 0; y < INPUT0_SIZE_Y; y++) { + for (uint x = 0; x < INPUT0_SIZE_X; x++) { + const uint input_idx = FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR b, f, w, z, y, x); + rms += pow(TO_ACCUMULATOR_TYPE(input[input_idx]), 2); + } + } + } + + rms /= INPUT0_SIZE_X * INPUT0_SIZE_Y * INPUT0_SIZE_Z; + rms = pow(sqrt(rms + TO_ACCUMULATOR_TYPE(EPSILON)), -1); + + for (uint z = 0; z < INPUT0_SIZE_Z; z++) { + for (uint y = 0; y < INPUT0_SIZE_Y; y++) { + for (uint x = 0; x < INPUT0_SIZE_X; x++) { + const uint input_idx = FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR b, f, w, z, y, x); + const uint output_idx = FUNC_CALL(get_output_index)(OPTIONAL_SHAPE_INFO_TENSOR b, f, w, z, y, x); +#if INPUT0_DIMS == 4 + const uint gamma_idx = y; +#elif INPUT0_DIMS == 5 + const uint gamma_idx = z; +#endif + OUTPUT_TYPE result = TO_OUTPUT_TYPE(rms) * TO_OUTPUT_TYPE(input[input_idx]) * TO_OUTPUT_TYPE(gamma[gamma_idx]); + output[output_idx] = result; + } + } + } +} diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/scatter_nd_update_ref.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/scatter_nd_update_ref.cl index 4ec9b665760e34..8c48ad4d4e9979 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/scatter_nd_update_ref.cl +++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/scatter_nd_update_ref.cl @@ -36,8 +36,10 @@ KERNEL(scatter_nd_update_ref)(OPTIONAL_SHAPE_INFO_ARG const __global INPUT0_TYPE* data, +#ifdef IS_SECOND_ITER const __global INPUT1_TYPE* indices, const __global INPUT2_TYPE* updates, +#endif __global OUTPUT_TYPE* output #if HAS_FUSED_OPS_DECLS , FUSED_OPS_DECLS @@ -56,8 +58,9 @@ KERNEL(scatter_nd_update_ref)(OPTIONAL_SHAPE_INFO_ARG const uint f = dim2 % OUTPUT_FEATURE_NUM; const uint b = dim2 / OUTPUT_FEATURE_NUM; + const uint input_idx = GET_UPDATES_INDEX(INPUT0, ORDER); const uint output_idx = GET_OUTPUT_INDEX(ORDER); - INPUT0_TYPE val = data[output_idx]; + INPUT0_TYPE val = data[input_idx]; #if HAS_FUSED_OPS FUSED_OPS_FIRST_KERNEL; output[output_idx] = TO_OUTPUT_TYPE(FUSED_OPS_RESULT_FIRST_KERNEL); diff --git a/src/plugins/intel_gpu/src/kernel_selector/common_types.h b/src/plugins/intel_gpu/src/kernel_selector/common_types.h index 148b6c10e39183..8c841b6001f44d 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/common_types.h +++ b/src/plugins/intel_gpu/src/kernel_selector/common_types.h @@ -32,6 +32,7 @@ enum class KernelType { RESHAPE, COUNT_NONZERO, GATHER_NONZERO, + GROUP_NORMALIZATION, PERMUTE, CONCATENATION, RESAMPLE, @@ -96,6 +97,7 @@ enum class KernelType { MULTICLASS_NMS, UNIQUE_COUNT, UNIQUE_GATHER, + RMS, }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp b/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp index 20d8e63ae29580..67c25b89025eb9 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp @@ -440,10 +440,12 @@ JitDefinitions DataTensorJitConstant::GetDefinitions() const { layout == DataLayout::b_fs_yx_fsv32 || layout == DataLayout::b_fs_yx_fsv2 || layout == DataLayout::b_fs_yx_fsv4 || + layout == DataLayout::b_fs_yx_fsv8 || layout == DataLayout::fs_b_yx_fsv32 || layout == DataLayout::bs_fs_yx_bsv16_fsv16 || layout == DataLayout::bs_fs_yx_bsv16_fsv32 || layout == DataLayout::bs_fs_yx_bsv4_fsv4 || + layout == DataLayout::bs_fs_yx_bsv16_fsv8 || layout == DataLayout::bs_fs_yx_bsv16_fsv4 || layout == DataLayout::bs_fs_yx_bsv16_fsv2 || layout == DataLayout::bs_fs_yx_bsv8_fsv4 || @@ -508,6 +510,10 @@ JitDefinitions DataTensorJitConstant::GetDefinitions() const { index_func_val = "GET_DATA_BS_FS_ZYX_BSV16_FSV16_INDEX(" + _name + ", b, f, z, y, x)"; raw_index_func_val = "GET_DATA_BS_FS_ZYX_BSV16_FSV16_INDEX(" + _name + ", b, f, z, y, x)"; safe_index_func_val = "GET_DATA_BS_FS_ZYX_BSV16_FSV16_INDEX_SAFE(" + _name + ", b, f, z, y, x)"; + } else if (layout == DataLayout::bs_fs_zyx_bsv16_fsv8) { + index_func_val = "GET_DATA_BS_FS_ZYX_BSV16_FSV8_INDEX(" + _name + ", b, f, z, y, x)"; + raw_index_func_val = "GET_DATA_BS_FS_ZYX_BSV16_FSV8_INDEX(" + _name + ", b, f, z, y, x)"; + safe_index_func_val = "GET_DATA_BS_FS_ZYX_BSV16_FSV8_INDEX_SAFE(" + _name + ", b, f, z, y, x)"; } else if (layout == DataLayout::b_fs_zyx_fsv32) { index_func_val = "GET_DATA_B_FS_ZYX_FSV32_INDEX(" + _name + ", b, f, z, y, x)"; raw_index_func_val = "GET_DATA_B_FS_ZYX_FSV32_INDEX(" + _name + ", b, f, z, y, x)"; @@ -536,6 +542,10 @@ JitDefinitions DataTensorJitConstant::GetDefinitions() const { index_func_val = "GET_DATA_B_FS_ZYX_FSV4_INDEX(" + _name + ", b, f, z, y, x)"; raw_index_func_val = "GET_DATA_B_FS_ZYX_FSV4_INDEX(" + _name + ", b, f, z, y, x)"; safe_index_func_val = "GET_DATA_B_FS_ZYX_FSV4_INDEX_SAFE(" + _name + ", b, f, z, y, x)"; + } else if (layout == DataLayout::b_fs_zyx_fsv8) { + index_func_val = "GET_DATA_B_FS_ZYX_FSV8_INDEX(" + _name + ", b, f, z, y, x)"; + raw_index_func_val = "GET_DATA_B_FS_ZYX_FSV8_INDEX(" + _name + ", b, f, z, y, x)"; + safe_index_func_val = "GET_DATA_B_FS_ZYX_FSV8_INDEX_SAFE(" + _name + ", b, f, z, y, x)"; } else { index_func_val = "GET_DATA_INDEX_5D_RAW(" + _name + ", b, f, z, y, x)"; safe_index_func_val = "GET_DATA_INDEX_5D_RAW(" + _name + ", b, f, z, y, x)"; diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernel_base_opencl.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernel_base_opencl.cpp index d0d052b44c4ed3..b382561afdac34 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernel_base_opencl.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernel_base_opencl.cpp @@ -80,6 +80,10 @@ std::string KernelBaseOpenCL::GetEntryPoint(const std::string& templateName, // UniqueID = program_id + processing_index + additional weight/reorder tag kernelID += "_" + params.uniqueID + "_" + std::to_string(partID); + // Add "__sa" suffix for shape agnostic kernels + if (params.is_shape_agnostic) + kernelID += "__sa"; + return kernelID; } diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_common.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_common.cpp index 49e3e2a1f2edd4..8c6d2af2fd8f69 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_common.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_common.cpp @@ -96,6 +96,7 @@ std::string toString(DataLayout l) { case kernel_selector::DataLayout::fyxb: return "FYXB"; case kernel_selector::DataLayout::b_fs_yx_fsv2: return "B_FS_YX_FSV2"; case kernel_selector::DataLayout::b_fs_yx_fsv4: return "B_FS_YX_FSV4"; + case kernel_selector::DataLayout::b_fs_yx_fsv8: return "B_FS_YX_FSV8"; case kernel_selector::DataLayout::b_fs_yx_fsv16: return "B_FS_YX_FSV16"; case kernel_selector::DataLayout::b_fs_yx_fsv32: return "B_FS_YX_FSV32"; case kernel_selector::DataLayout::b_fs_zyx_fsv32: return "B_FS_ZYX_FSV32"; @@ -109,6 +110,7 @@ std::string toString(DataLayout l) { case kernel_selector::DataLayout::bfwzyx: return "BFWZYX"; case kernel_selector::DataLayout::bfuwzyx: return "BFUWZYX"; case kernel_selector::DataLayout::bfvuwzyx: return "BFVUWZYX"; + case kernel_selector::DataLayout::b_fs_zyx_fsv8: return "B_FS_ZYX_FSV8"; case kernel_selector::DataLayout::b_fs_zyx_fsv16: return "B_FS_ZYX_FSV16"; case kernel_selector::DataLayout::bs_fs_yx_bsv16_fsv16: return "BS_FS_YX_BSV16_FSV16"; case kernel_selector::DataLayout::bs_fs_yx_bsv16_fsv32: return "BS_FS_YX_BSV16_FSV32"; @@ -117,6 +119,8 @@ std::string toString(DataLayout l) { case kernel_selector::DataLayout::bs_fs_yx_bsv4_fsv4: return "BS_FS_YX_BSV4_FSV4"; case kernel_selector::DataLayout::bs_fs_yx_bsv8_fsv4: return "BS_FS_YX_BSV8_FSV4"; case kernel_selector::DataLayout::bs_fs_zyx_bsv8_fsv4: return "BS_FS_ZYX_BSV8_FSV4"; + case kernel_selector::DataLayout::bs_fs_yx_bsv16_fsv8: return "BS_FS_YX_BSV16_FSV8"; + case kernel_selector::DataLayout::bs_fs_zyx_bsv16_fsv8: return "BS_FS_ZYX_BSV16_FSV8"; case kernel_selector::DataLayout::bs_fs_yx_bsv16_fsv4: return "BS_FS_YX_BSV16_FSV4"; case kernel_selector::DataLayout::bs_fs_zyx_bsv16_fsv4: return "BS_FS_ZYX_BSV16_FSV4"; case kernel_selector::DataLayout::bs_fs_yx_bsv16_fsv2: return "BS_FS_YX_BSV16_FSV2"; @@ -312,7 +316,10 @@ std::string toString(WeightsLayout layout) { case WeightsLayout::os_is_zyx_osv16_isv16: return "OS_IS_ZYX_OSV16_ISV16"; case WeightsLayout::os_is_zyx_osv32_isv16: return "OS_IS_ZYX_OSV32_ISV16"; case WeightsLayout::os_is_zyx_osv64_isv16: return "OS_IS_ZYX_OSV64_ISV16"; + case WeightsLayout::o_is_yx_isv2: return "O_IS_YX_ISV2"; + case WeightsLayout::o_is_yx_isv4: return "O_IS_YX_ISV4"; case WeightsLayout::o_is_yx_isv16: return "O_IS_YX_ISV16"; + case WeightsLayout::o_is_zyx_isv16: return "O_IS_ZYX_ISV16"; case WeightsLayout::os_yxi_osv16: return "OS_YXI_OSV16"; case WeightsLayout::os_iyx_osv16: return "OS_IYX_OSV16"; case WeightsLayout::os_iyx_osv32: return "OS_IYX_OSV32"; @@ -364,6 +371,7 @@ std::string toString(WeightsLayout layout) { case WeightsLayout::os_is_zyx_isa8_osv8_isv2: return "OS_IS_ZYX_ISA8_OSV8_ISV2"; case WeightsLayout::is_os_yx_isa8_osv8_isv2: return "IS_OS_YX_ISA8_OSV8_ISV2"; case WeightsLayout::is_os_yx_isa8_osv8_isv4: return "IS_OS_YX_ISA8_OSV8_ISV4"; + case WeightsLayout::is_os_yx_osv8_isv4: return "IS_OS_YX_OSV8_ISV4"; case WeightsLayout::is_os_yx_osa8_isv16_osv4: return "IS_OS_YX_OSA8_ISV16_OSV4"; case WeightsLayout::os_is_yx_isa8_osv8_isv2: return "OS_IS_YX_ISA8_OSV8_ISV2"; case WeightsLayout::os_is_zyx_isv8_osv16_isv2: return "OS_IS_ZYX_ISV8_OSV16_ISV2"; @@ -374,6 +382,8 @@ std::string toString(WeightsLayout layout) { case WeightsLayout::os_is_yx_osv8_isv4: return "OS_IS_YX_OSV8_ISV4"; case WeightsLayout::os_is_zyx_osv8_isv4: return "OS_IS_ZYX_OSV8_ISV4"; case WeightsLayout::os_is_yx_osv8_isv2: return "OS_IS_YX_OSV8_ISV2"; + case WeightsLayout::os_is_yx_osv2_isv16: return "OS_IS_YX_OSV2_ISV16"; + case WeightsLayout::os_is_yx_osv4_isv16: return "OS_IS_YX_OSV4_ISV16"; case WeightsLayout::os_is_zyx_osv8_isv2: return "OS_IS_ZYX_OSV8_ISV2"; case WeightsLayout::goiyx: return "GOIYX"; case WeightsLayout::gioyx: return "GIOYX"; @@ -383,6 +393,8 @@ std::string toString(WeightsLayout layout) { case WeightsLayout::g_os_iyx_osv8: return "G_OS_IYX_OSV8"; case WeightsLayout::g_os_iyx_osv16: return "G_OS_IYX_OSV16"; case WeightsLayout::g_os_iyx_osv32: return "G_OS_IYX_OSV32"; + case WeightsLayout::gs_oiyx_gsv8: return "GS_OIYX_GSV8"; + case WeightsLayout::gs_oizyx_gsv8: return "GS_OIZYX_GSV8"; case WeightsLayout::gs_oiyx_gsv16: return "GS_OIYX_GSV16"; case WeightsLayout::gs_oizyx_gsv16: return "GS_OIZYX_GSV16"; case WeightsLayout::gs_oiyx_gsv32: return "GS_OIYX_GSV32"; diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_utils.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_utils.cpp index a2e0226367d7e7..bb3eb06e32b3b0 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_utils.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_utils.cpp @@ -252,12 +252,14 @@ std::vector GetOptimalLocalWorkGroupSizes(std::vector gws, const auto blocked_fsv_layout = output_layout == DataLayout::b_fs_yx_fsv2 || output_layout == DataLayout::b_fs_zyx_fsv2 || output_layout == DataLayout::b_fs_yx_fsv4 || output_layout == DataLayout::b_fs_zyx_fsv4 || + output_layout == DataLayout::b_fs_yx_fsv8 || output_layout == DataLayout::b_fs_zyx_fsv8 || output_layout == DataLayout::b_fs_yx_fsv16 || output_layout == DataLayout::b_fs_zyx_fsv16 || output_layout == DataLayout::b_fs_yx_fsv32 || output_layout == DataLayout::b_fs_zyx_fsv32 || output_layout == DataLayout::fs_b_yx_fsv32; auto blocked_bsv_fsv_layout = output_layout == DataLayout::bs_fs_yx_bsv16_fsv2 || output_layout == DataLayout::bs_fs_zyx_bsv16_fsv2 || output_layout == DataLayout::bs_fs_yx_bsv16_fsv4 || output_layout == DataLayout::bs_fs_zyx_bsv16_fsv4 || + output_layout == DataLayout::bs_fs_yx_bsv16_fsv8 || output_layout == DataLayout::bs_fs_zyx_bsv16_fsv8 || output_layout == DataLayout::bs_fs_yx_bsv16_fsv16 || output_layout == DataLayout::bs_fs_yx_bsv16_fsv32 || output_layout == DataLayout::bs_fs_yx_bsv32_fsv16 || output_layout == DataLayout::bs_fs_yx_bsv32_fsv32 || output_layout == DataLayout::bs_fs_zyx_bsv16_fsv16 || output_layout == DataLayout::bs_fs_zyx_bsv16_fsv32 || @@ -318,10 +320,10 @@ std::vector GetOptimalLocalWorkGroupSizes(std::vector gws, const break; } } else if (blocked_fsv_layout) { - if (output_layout == DataLayout::b_fs_yx_fsv2 || output_layout == DataLayout::b_fs_yx_fsv4 || + if (output_layout == DataLayout::b_fs_yx_fsv2 || output_layout == DataLayout::b_fs_yx_fsv4 || output_layout == DataLayout::b_fs_yx_fsv8 || output_layout == DataLayout::b_fs_yx_fsv16 || output_layout == DataLayout::b_fs_yx_fsv32) { layout_order = { f, x, y, b, z, w, u, v }; - } else if (output_layout == DataLayout::b_fs_zyx_fsv2 || output_layout == DataLayout::b_fs_zyx_fsv4 || + } else if (output_layout == DataLayout::b_fs_zyx_fsv2 || output_layout == DataLayout::b_fs_zyx_fsv4 || output_layout == DataLayout::b_fs_zyx_fsv8 || output_layout == DataLayout::b_fs_zyx_fsv16 || output_layout == DataLayout::b_fs_zyx_fsv32) { layout_order = { f, x, y, z, b, w, u, v }; } else { // output_layout == DataLayout::fs_b_yx_fsv32 @@ -453,13 +455,18 @@ bool CheckInputsOutputNoPitchSameDims(const base_params& params) { {DataLayout::b_fs_zyx_fsv16, {1, 16}}, {DataLayout::b_fs_yx_fsv32, {1, 32}}, {DataLayout::b_fs_zyx_fsv32, {1, 32}}, + {DataLayout::bs_fs_yx_bsv16_fsv8, {16, 8}}, {DataLayout::bs_fs_yx_bsv16_fsv16, {16, 16}}, {DataLayout::bs_fs_yx_bsv16_fsv32, {16, 32}}, + {DataLayout::bs_fs_zyx_bsv16_fsv8, {16, 8}}, {DataLayout::bs_fs_zyx_bsv16_fsv16, {16, 16}}, {DataLayout::bs_fs_zyx_bsv16_fsv32, {16, 32}}, {DataLayout::bs_f_bsv8__af8, {8, 8}}, {DataLayout::bs_f_bsv16__af8, {16, 8}}, {DataLayout::b_fs_yx_fsv4, {1, 4}}, + {DataLayout::b_fs_zyx_fsv4, {1, 4}}, + {DataLayout::b_fs_yx_fsv8, {1, 8}}, + {DataLayout::b_fs_zyx_fsv8, {1, 8}}, {DataLayout::fs_b_yx_fsv32, {1, 32}}, {DataLayout::b_fs_yx_32fp, {1, 32}}, {DataLayout::bs_fs_yx_bsv32_fsv16, {32, 16}}, diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/fully_connected/fully_connected_kernel_base.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/fully_connected/fully_connected_kernel_base.cpp index 3e9eb35cdaaff0..a75d35469837f7 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernels/fully_connected/fully_connected_kernel_base.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/fully_connected/fully_connected_kernel_base.cpp @@ -24,11 +24,23 @@ JitConstants FullyConnectedKernelBase::GetJitConstants(const fully_connected_par if (params.compressed) { jit.AddConstants({MakeJitConstant("COMPRESSED_WEIGHTS", 1)}); + if (params.weights.GetDType() == WeightsType::INT8 || params.weights.GetDType() == WeightsType::UINT8) { + jit.AddConstants({MakeJitConstant("COMPRESSED_WEIGHTS_INT8", 1)}); + } + + const size_t scale_groups_num = params.decompression_scale.Feature().v; + const size_t scale_group_size = params.weights.IFM().v / params.decompression_scale.Feature().v; jit.AddConstants({MakeJitConstant("DECOMPRESSION_SCALE_TERM", 1)}); jit.AddConstants({MakeJitConstant("DECOMPRESSION_SCALE", params.decompression_scale)}); + jit.AddConstants({MakeJitConstant("DECOMPRESSION_SCALE_GROUPS_NUM", scale_groups_num)}); + jit.AddConstants({MakeJitConstant("DECOMPRESSION_SCALE_GROUP_SIZE", scale_group_size)}); if (params.has_decompression_zp) { + const size_t zp_groups_num = params.decompression_zero_point.Feature().v; + const size_t zp_group_size = params.weights.IFM().v / params.decompression_zero_point.Feature().v; jit.AddConstants({MakeJitConstant("DECOMPRESSION_ZP_TERM", 1)}); jit.AddConstants({MakeJitConstant("DECOMPRESSION_ZP", params.decompression_zero_point)}); + jit.AddConstants({MakeJitConstant("DECOMPRESSION_ZP_GROUPS_NUM", zp_groups_num)}); + jit.AddConstants({MakeJitConstant("DECOMPRESSION_ZP_GROUP_SIZE", zp_group_size)}); } } diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/fully_connected/fully_connected_kernel_bf_tiled.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/fully_connected/fully_connected_kernel_bf_tiled.cpp index 6b0407f6580cad..c272124627db23 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernels/fully_connected/fully_connected_kernel_bf_tiled.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/fully_connected/fully_connected_kernel_bf_tiled.cpp @@ -241,6 +241,9 @@ FullyConnected_bf_tiled::GetAutoTuneParams(const fully_connected_params& params, .Case(tune_params(8, std::min(max_tile_ofm, 2u), 1, 1, 1, 1, EXE_MODE_AGE_BASED)); } + if (params.compressed && batch == 1) + selector.Case(tune_params(1, std::min(max_tile_ofm, 2u), 4, 2, 1, 1, EXE_MODE_AGE_BASED)); + selector.Case([&](const fully_connected_params&) -> tune_params { tune_params result(8, std::min(max_tile_ofm, 2u), 1, 2, 1, 1, EXE_MODE_DEFAULT); diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/group_normalization/group_normalization_kernel_ref.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/group_normalization/group_normalization_kernel_ref.cpp new file mode 100644 index 00000000000000..a6dd21c43fe4e3 --- /dev/null +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/group_normalization/group_normalization_kernel_ref.cpp @@ -0,0 +1,170 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "group_normalization_kernel_ref.h" +#include + +namespace kernel_selector { + +ParamsKey GroupNormalizationKernelRef::GetSupportedKey() const { + ParamsKey k; + k.EnableInputDataType(Datatype::F16); + k.EnableInputDataType(Datatype::F32); + k.EnableOutputDataType(Datatype::F16); + k.EnableOutputDataType(Datatype::F32); + k.EnableAllInputLayout(); + k.EnableAllOutputLayout(); + k.EnableTensorOffset(); + k.EnableTensorPitches(); + k.EnableBatching(); + k.EnableDifferentTypes(); + return k; +} + +static std::size_t InternalBufferSize(const group_normalization_params ¶ms) { + const auto& output = params.outputs[0]; + return output.Batch().v * params.num_groups * sizeof(float); +} + +static GroupNormalizationKernelRef::KernelId operator++(GroupNormalizationKernelRef::KernelId& id) { + id = static_cast(static_cast(id) + 1); + return id; +} + +GroupNormalizationKernelRef::DispatchData GroupNormalizationKernelRef::SetDefault( + KernelId id, const group_normalization_params ¶ms) const { + DispatchData dispatch_data; + auto& output = params.outputs[0]; + switch (id) { + case eCalcMeanKernel: + case eCalcStandardDeviationKernel: { + auto maxWorkGroupSize = params.engineInfo.maxWorkGroupSize; + dispatch_data.gws = std::vector{ + output.Batch().v, + static_cast(params.num_groups), + 1 + }; + dispatch_data.lws = std::vector{ + output.Batch().v * params.num_groups > maxWorkGroupSize ? maxWorkGroupSize / params.num_groups : output.Batch().v, + static_cast(params.num_groups), + 1}; + break; + } + case eNormalize: { + auto in_layout = params.inputs[0].GetLayout(); + auto out_layout = output.GetLayout(); + std::vector> dims_by_gws = { + { Tensor::DataChannelName::BATCH }, + { Tensor::DataChannelName::FEATURE, Tensor::DataChannelName::Z }, + { Tensor::DataChannelName::X, Tensor::DataChannelName::Y }}; + dispatch_data.gws = std::vector{ + output.Batch().v, + output.Feature().v * output.Z().v, + output.X().v * output.Y().v}; + dispatch_data.lws = GetOptimalLocalWorkGroupSizes(dispatch_data.gws, params.engineInfo, + in_layout, out_layout, dims_by_gws); + break; + } + default: + assert(false); + break; + } + return dispatch_data; +} + +JitConstants GroupNormalizationKernelRef::GetJitConstants(KernelId kernelId, + const group_normalization_params ¶ms) const { + auto jit = MakeBaseParamsJitConstants(params); + jit.AddConstant(MakeJitConstant("EPSILON", static_cast(params.epsilon))); + jit.AddConstant(MakeJitConstant("NUM_GROUPS", params.num_groups)); + switch (kernelId) { + case eCalcMeanKernel: + jit.AddConstant(MakeJitConstant("MEAN_KERNEL_ENABLED", true)); + break; + case eCalcStandardDeviationKernel: + jit.AddConstant(MakeJitConstant("STANDARD_DEVIATION_KERNEL_ENABLED", true)); + break; + case eNormalize: { + jit.AddConstant(MakeJitConstant("NORMALIZE_KERNEL_ENABLED", true)); + jit.AddConstant(MakeJitConstant("INPUT_INDICES_ORDER", "batch, feature, z, y, x")); + if (!params.fused_ops.empty()) { + FusedOpsConfiguration conf{ + "", + params.outputs[0].Dimentions() == 5 ? std::vector{"batch", "feature", "z", "y", "x"} : + std::vector{"batch", "feature", "y", "x"}, + "res", + params.outputs[0].GetDType() + }; + jit.Merge(MakeFusedOpsJitConstants(params, {conf})); + } + break; + } + default: + assert(false); + break; + } + return jit; +} + +void GroupNormalizationKernelRef::SetKernelArguments(const group_normalization_params& params, + KernelId kernelId, + cldnn::arguments_desc& arguments, + std::vector& internalBufferSizes) { + switch (kernelId) { + case eCalcMeanKernel: { + arguments.push_back({ArgumentDescriptor::Types::INPUT, 0}); + arguments.push_back({ArgumentDescriptor::Types::INTERNAL_BUFFER, 0}); + internalBufferSizes.push_back(InternalBufferSize(params)); + break; + } + case eCalcStandardDeviationKernel: { + arguments.push_back({ArgumentDescriptor::Types::INPUT, 0}); + arguments.push_back({ArgumentDescriptor::Types::INTERNAL_BUFFER, 0}); + arguments.push_back({ArgumentDescriptor::Types::INTERNAL_BUFFER, 1}); + internalBufferSizes.push_back(InternalBufferSize(params)); + break; + } + case eNormalize: { + arguments.push_back({ArgumentDescriptor::Types::INPUT, 0}); + arguments.push_back({ArgumentDescriptor::Types::INPUT, 1}); + arguments.push_back({ArgumentDescriptor::Types::INPUT, 2}); + arguments.push_back({ArgumentDescriptor::Types::INTERNAL_BUFFER, 0}); + arguments.push_back({ArgumentDescriptor::Types::INTERNAL_BUFFER, 1}); + arguments.push_back({ArgumentDescriptor::Types::OUTPUT, 0}); + break; + } + default: + assert(false); + break; + } +} + +KernelsData GroupNormalizationKernelRef::GetKernelsData(const Params ¶ms, const optional_params &options) const { + const group_normalization_params& parameters = static_cast(params); + KernelData kd = KernelData::Default(params, eKernelsNum); + kd.internalBufferDataType = Datatype::F32; + for (KernelId id = eCalcMeanKernel; id < eKernelsNum; ++id) { + auto& kernel = kd.kernels[id]; + const auto entryPoint = GetEntryPoint(kernelName, parameters.layerID, params, options, id); + auto jitConstants = GetJitConstants(id, parameters); + const auto jit = CreateJit(kernelName, jitConstants, entryPoint); + const auto dispatchData = SetDefault(id, parameters); + FillCLKernelData(kernel, + dispatchData, + params.engineInfo, + kernelName, + jit, + entryPoint, + "", + false, + false, + 0, + 0, + 0); + SetKernelArguments(parameters, id, kernel.params.arguments, kd.internalBufferSizes); + } + return {kd}; +} + +} // namespace kernel_selector diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/group_normalization/group_normalization_kernel_ref.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/group_normalization/group_normalization_kernel_ref.h new file mode 100644 index 00000000000000..0737c4d45089bf --- /dev/null +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/group_normalization/group_normalization_kernel_ref.h @@ -0,0 +1,60 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#pragma once +#include "kernel_base_opencl.h" +#include "kernel_selector_params.h" + +namespace kernel_selector { +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// GroupNormalizationParams +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +struct group_normalization_params : public base_params { + group_normalization_params() : base_params(KernelType::GROUP_NORMALIZATION) {} + + std::int64_t num_groups{}; + double epsilon{}; + + ParamsKey GetParamsKey() const override { + return base_params::GetParamsKey(); + } +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// group_normalization_optional_params +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +struct group_normalization_optional_params : optional_params { + group_normalization_optional_params() : optional_params(KernelType::GROUP_NORMALIZATION) {} +}; + +class GroupNormalizationKernelRef : public KernelBaseOpenCL { +public: + using DispatchData = CommonDispatchData; + enum KernelId { + eCalcMeanKernel, + eCalcStandardDeviationKernel, + eNormalize, + eKernelsNum + }; + + GroupNormalizationKernelRef() : KernelBaseOpenCL{"group_normalization_gpu_ref"} {} + KernelsData GetKernelsData(const Params& params, const optional_params& options) const override; + ParamsKey GetSupportedKey() const override; + std::vector GetSupportedFusedOps() const override { + return { + FusedOpType::ACTIVATION, + FusedOpType::QUANTIZE, + FusedOpType::ELTWISE + }; + } + +protected: + DispatchData SetDefault(KernelId id, const group_normalization_params& params) const; + JitConstants GetJitConstants(KernelId kernelId, const group_normalization_params& params) const; + static void SetKernelArguments(const group_normalization_params& params, + KernelId kernelId, + cldnn::arguments_desc& arguments, + std::vector& internalBufferSizes); +}; + +} // namespace kernel_selector diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/group_normalization/group_normalization_kernel_selector.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/group_normalization/group_normalization_kernel_selector.cpp new file mode 100644 index 00000000000000..40a5044c5216b5 --- /dev/null +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/group_normalization/group_normalization_kernel_selector.cpp @@ -0,0 +1,18 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#include "group_normalization_kernel_selector.h" +#include "group_normalization_kernel_ref.h" + +namespace kernel_selector { + +group_normalization_kernel_selector::group_normalization_kernel_selector() { + Attach(); +} + +KernelsData group_normalization_kernel_selector::GetBestKernels(const Params ¶ms, + const optional_params &options) const { + return GetNaiveBestKernel(params, options, KernelType::GROUP_NORMALIZATION); +} + +} // namespace kernel_selector diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/group_normalization/group_normalization_kernel_selector.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/group_normalization/group_normalization_kernel_selector.h new file mode 100644 index 00000000000000..8e8579e61de41c --- /dev/null +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/group_normalization/group_normalization_kernel_selector.h @@ -0,0 +1,19 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#pragma once +#include "kernel_selector.h" + +namespace kernel_selector { +class group_normalization_kernel_selector : public kernel_selector_base { +public: + static group_normalization_kernel_selector& Instance() { + static group_normalization_kernel_selector instance_; + return instance_; + } + + group_normalization_kernel_selector(); + + KernelsData GetBestKernels(const Params& params, const optional_params& options) const override; +}; +} // namespace kernel_selector diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_kernel_base.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_kernel_base.cpp index 1653ef019cbaf7..7fecbc14345cd0 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_kernel_base.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_kernel_base.cpp @@ -12,6 +12,8 @@ namespace kernel_selector { inline uint32_t SubGroupSize(WeightsLayout l) { switch (l) { + case WeightsLayout::o_is_yx_isv16: + case WeightsLayout::o_is_zyx_isv16: case WeightsLayout::os_iyx_osv16: case WeightsLayout::os_iyx_osv32: case WeightsLayout::os_iyx_osv64: @@ -50,6 +52,8 @@ inline uint32_t SubGroupSize(WeightsLayout l) { case WeightsLayout::iy_xs_os_xsv2_osv8__ao32: case WeightsLayout::giy_xs_os_xsv2_osv8__ao32: case WeightsLayout::g_os_iyx_osv8: + case WeightsLayout::gs_oiyx_gsv8: + case WeightsLayout::gs_oizyx_gsv8: return 8; default: return 1; diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_base.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_base.cpp new file mode 100644 index 00000000000000..f93cee2876de93 --- /dev/null +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_base.cpp @@ -0,0 +1,94 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "rms_kernel_base.h" +#include "kernel_selector_utils.h" + +namespace kernel_selector { +bool RMSKernelBase::Validate(const Params& p, const optional_params& o) const { + if (!KernelBaseOpenCL::Validate(p, o)) + return false; + + const rms_params& params = static_cast(p); + auto supported_dyn_layouts = { DataLayout::bfyx, DataLayout::bfzyx }; + if (params.has_dynamic_tensors() && (!layout_is_one_of(params.inputs, supported_dyn_layouts) || !layout_is_one_of(params.outputs, supported_dyn_layouts))) + return false; + + return true; +} + +JitConstants RMSKernelBase::GetJitConstants(const rms_params& params, RMSKernelBase::DispatchData) const { + JitConstants jit = MakeBaseParamsJitConstants(params); + + jit.AddConstant(MakeJitConstant("EPSILON", params.epsilon)); + jit.Merge(MakeTypeJitConstants(GetAccumulatorType(params), "ACCUMULATOR")); + + return jit; +} + +RMSKernelBase::DispatchData RMSKernelBase::SetDefault(const rms_params& params) const { + DispatchData dispatchData; + const auto& output = params.outputs[0]; + + dispatchData.gws = {output.Batch().v, output.Feature().v, 1}; + dispatchData.lws = GetOptimalLocalWorkGroupSizes(dispatchData.gws, params.engineInfo); + + return dispatchData; +} + +KernelsData RMSKernelBase::GetCommonKernelsData(const Params& params, const optional_params& options) const { + assert(params.GetType() == KernelType::RMS); + + if (!Validate(params, options)) + return {}; + + const rms_params& orgParams = static_cast(params); + auto dispatchData = SetDefault(orgParams); + + KernelData kd = KernelData::Default(params); + + auto cldnn_jit = GetJitConstants(orgParams, dispatchData); + auto entry_point = GetEntryPoint(kernelName, orgParams.layerID, params, options); + auto jit = CreateJit(kernelName, cldnn_jit, entry_point); + + kd.update_dispatch_data_func = [this](const Params& params, KernelData& kd) { + const auto& prim_params = static_cast(params); + auto dispatchData = SetDefault(prim_params); + OPENVINO_ASSERT(kd.kernels.size() == 1, "[GPU] Invalid kernels size for update dispatch data func"); + kd.kernels[0].params.workGroups.global = dispatchData.gws; + kd.kernels[0].params.workGroups.local = dispatchData.lws; + kd.kernels[0].skip_execution = KernelData::SkipKernelExecution(prim_params); + }; + + auto& kernel = kd.kernels[0]; + FillCLKernelData(kernel, + dispatchData, + params.engineInfo, + kernelName, + jit, + entry_point, + EXE_MODE_DEFAULT, + false, + false, + 2, + GetFusedPrimitiveInputsCount(params), + 1, + orgParams.outputs[0].is_dynamic()); + + return {kd}; +} + +Datatype RMSKernelBase::GetAccumulatorType(const rms_params& params) const { + const auto& input_dt = params.inputs[0].GetDType(); + + switch (input_dt) { + case Datatype::F32: + case Datatype::F16: + return Datatype::F32; + case Datatype::INT8: return Datatype::INT32; + case Datatype::UINT8: return Datatype::INT32; + default: return Datatype::F32; + } +} +} // namespace kernel_selector diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_base.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_base.h new file mode 100644 index 00000000000000..546c209bf03d77 --- /dev/null +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_base.h @@ -0,0 +1,50 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "kernel_base_opencl.h" + +namespace kernel_selector { +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// rms_params +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +struct rms_params : public base_params { + rms_params() : base_params(KernelType::RMS) {} + float epsilon = 0.0f; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// rms_optional_params +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +struct rms_optional_params : optional_params { + rms_optional_params() : optional_params(KernelType::RMS) {} +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// RMSKernelBase +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +class RMSKernelBase : public KernelBaseOpenCL { +public: + using KernelBaseOpenCL::KernelBaseOpenCL; + virtual ~RMSKernelBase() {} + + struct DispatchData : public CommonDispatchData { + size_t dataSize; + size_t dataCount; + size_t slmSize; + size_t maxSlmSize; + size_t leftovers; + + DispatchData() : dataSize(0), dataCount(0), slmSize(0), maxSlmSize(0), leftovers(0) {} + }; + +protected: + bool Validate(const Params&, const optional_params&) const override; + virtual JitConstants GetJitConstants(const rms_params& params, DispatchData dispatchData) const; + virtual DispatchData SetDefault(const rms_params& params) const; + KernelsData GetCommonKernelsData(const Params& params, const optional_params&) const; + Datatype GetAccumulatorType(const rms_params& params) const; +}; +} // namespace kernel_selector diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_bfyx_opt.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_bfyx_opt.cpp new file mode 100644 index 00000000000000..ad49fd86370e0a --- /dev/null +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_bfyx_opt.cpp @@ -0,0 +1,120 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "rms_kernel_bfyx_opt.h" +#include "kernel_selector_utils.h" +#include + +namespace kernel_selector { +ParamsKey RMSKernelBfyxOpt::GetSupportedKey() const { + ParamsKey k; + k.EnableInputDataType(Datatype::F16); + k.EnableInputDataType(Datatype::F32); + k.EnableOutputDataType(Datatype::F16); + k.EnableOutputDataType(Datatype::F32); + k.EnableInputLayout(DataLayout::bfyx); + k.EnableInputLayout(DataLayout::bfzyx); + k.EnableOutputLayout(DataLayout::bfyx); + k.EnableOutputLayout(DataLayout::bfzyx); + k.EnableTensorOffset(); + k.EnableTensorPitches(); + k.EnableBatching(); + k.EnableDifferentTypes(); + k.EnableDynamicShapesSupport(); + return k; +} + +JitConstants RMSKernelBfyxOpt::GetJitConstants(const rms_params& params, DispatchData dispatchData) const { + auto jit = Parent::GetJitConstants(params, dispatchData); + + if (params.has_dynamic_tensors()) { + const auto& input = params.inputs[0]; + DimensionAccessHelper dims(input); + const std::string data_size = toVectorMulString({dims.x(), dims.y(), dims.z()}); + const std::string lws_0 = "get_local_size(0)"; + jit.AddConstants({ + MakeJitConstant("DATA_SIZE", data_size), + MakeJitConstant("LWS", lws_0), + MakeJitConstant("SLM_SIZE", dispatchData.maxSlmSize) + }); + } else { + jit.AddConstants({ + MakeJitConstant("DATA_SIZE", dispatchData.dataSize), + MakeJitConstant("LWS", dispatchData.slmSize), + MakeJitConstant("SLM_SIZE", dispatchData.slmSize), + MakeJitConstant("LEFTOVERS", dispatchData.leftovers) + }); + } + jit.AddConstants({ + MakeJitConstant("VEC_SIZE", 8), + MakeJitConstant("VLOAD", "CAT(vload, VEC_SIZE)"), + MakeJitConstant("VSTORE", "CAT(vstore, VEC_SIZE)"), + MakeJitConstant("INPUT_VEC_TYPE", "MAKE_VECTOR_TYPE(INPUT0_TYPE, VEC_SIZE)"), + MakeJitConstant("ACCUMULATOR_VEC_TYPE", "MAKE_VECTOR_TYPE(ACCUMULATOR_TYPE, VEC_SIZE)"), + MakeJitConstant("OUTPUT_VEC_TYPE", "MAKE_VECTOR_TYPE(OUTPUT_TYPE, VEC_SIZE)"), + MakeJitConstant("AS_INPUT_VEC_TYPE", "CAT(as_, INPUT_VEC_TYPE)"), + MakeJitConstant("AS_ACCUMULATOR_VEC_TYPE", "CAT(as_, ACCUMULATOR_VEC_TYPE)"), + MakeJitConstant("TO_ACCUMULATOR_VEC_TYPE", "CAT(convert_, ACCUMULATOR_VEC_TYPE)"), + MakeJitConstant("TO_OUTPUT_VEC_TYPE", "CAT(convert_, OUTPUT_VEC_TYPE)"), + }); + + return jit; +} + +RMSKernelBase::DispatchData RMSKernelBfyxOpt::SetDefault(const rms_params& params) const { + DispatchData dispatchData; + const auto& input = params.inputs[0]; + + auto local_mem_per_wi = 2 * BytesPerElement(params.inputs[0].GetDType()); + auto max_lws = std::min(params.engineInfo.maxWorkGroupSize, params.engineInfo.maxLocalMemSize / local_mem_per_wi); + dispatchData.maxSlmSize = max_lws; + + if (!params.has_dynamic_tensors()) { + dispatchData.dataSize = input.X().v * input.Y().v * input.Z().v; + dispatchData.dataCount = input.Batch().v * input.Feature().v; + dispatchData.slmSize = dispatchData.dataSize / 8; + dispatchData.leftovers = dispatchData.dataSize % 8; + + dispatchData.gws[0] = dispatchData.slmSize; + dispatchData.gws[1] = dispatchData.dataCount; + dispatchData.gws[2] = 1; + + dispatchData.lws[0] = dispatchData.slmSize; + dispatchData.lws[1] = 1; + dispatchData.lws[2] = 1; + } + return dispatchData; +} + +bool RMSKernelBfyxOpt::Validate(const Params& p, const optional_params& o) const { + if (!Parent::Validate(p, o)) + return false; + + const rms_params& params = static_cast(p); + const auto& gamma = params.inputs[1]; + + if (!gamma.is_dynamic()) { + size_t data_size = gamma.LogicalSize(); + if (data_size < 8) { + return false; + } + auto local_mem_per_wi = 2 * BytesPerElement(params.inputs[0].GetDType()); + auto max_lws = std::min(params.engineInfo.maxWorkGroupSize, params.engineInfo.maxLocalMemSize / local_mem_per_wi); + auto slm_size = data_size / 8; + if (slm_size > max_lws) { + return false; + } + } + + return true; +} + +KernelsData RMSKernelBfyxOpt::GetKernelsData(const Params& params, const optional_params& options) const { + return GetCommonKernelsData(params, options); +} + +KernelsPriority RMSKernelBfyxOpt::GetKernelsPriority(const Params& /*params*/, const optional_params& /*options*/) const { + return FORCE_PRIORITY_7; +} +} // namespace kernel_selector diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_bfyx_opt.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_bfyx_opt.h new file mode 100644 index 00000000000000..a9b49c4c1cc654 --- /dev/null +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_bfyx_opt.h @@ -0,0 +1,25 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "rms_kernel_base.h" + +namespace kernel_selector { +class RMSKernelBfyxOpt : public RMSKernelBase { +public: + using Parent = RMSKernelBase; + RMSKernelBfyxOpt() : RMSKernelBase("rms_gpu_bfyx_opt") {} + virtual ~RMSKernelBfyxOpt() {} + + KernelsData GetKernelsData(const Params& params, const optional_params& options) const override; + KernelsPriority GetKernelsPriority(const Params& params, const optional_params& options) const override; + ParamsKey GetSupportedKey() const override; + +protected: + bool Validate(const Params&, const optional_params&) const override; + DispatchData SetDefault(const rms_params& params) const override; + JitConstants GetJitConstants(const rms_params& params, DispatchData dispatchData) const override; +}; +} // namespace kernel_selector diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_ref.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_ref.cpp new file mode 100644 index 00000000000000..9dbdf30154aea9 --- /dev/null +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_ref.cpp @@ -0,0 +1,35 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "rms_kernel_ref.h" +#include "kernel_selector_utils.h" +#include + +namespace kernel_selector { +ParamsKey RMSKernelRef::GetSupportedKey() const { + ParamsKey k; + k.EnableInputDataType(Datatype::F16); + k.EnableInputDataType(Datatype::F32); + k.EnableOutputDataType(Datatype::F16); + k.EnableOutputDataType(Datatype::F32); + k.EnableInputLayout(DataLayout::bfyx); + k.EnableInputLayout(DataLayout::bfzyx); + k.EnableOutputLayout(DataLayout::bfyx); + k.EnableOutputLayout(DataLayout::bfzyx); + k.EnableTensorOffset(); + k.EnableTensorPitches(); + k.EnableBatching(); + k.EnableDifferentTypes(); + k.EnableDynamicShapesSupport(); + return k; +} + +KernelsData RMSKernelRef::GetKernelsData(const Params& params, const optional_params& options) const { + return GetCommonKernelsData(params, options); +} + +KernelsPriority RMSKernelRef::GetKernelsPriority(const Params& /*params*/, const optional_params& /*options*/) const { + return FORCE_PRIORITY_9; +} +} // namespace kernel_selector diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_ref.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_ref.h new file mode 100644 index 00000000000000..7c2e3dd512e8f7 --- /dev/null +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_ref.h @@ -0,0 +1,20 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "rms_kernel_base.h" + +namespace kernel_selector { +class RMSKernelRef : public RMSKernelBase { +public: + using Parent = RMSKernelBase; + RMSKernelRef() : RMSKernelBase("rms_gpu_ref") {} + virtual ~RMSKernelRef() {} + + KernelsData GetKernelsData(const Params& params, const optional_params& options) const override; + KernelsPriority GetKernelsPriority(const Params& params, const optional_params& options) const override; + ParamsKey GetSupportedKey() const override; +}; +} // namespace kernel_selector diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_selector.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_selector.cpp new file mode 100644 index 00000000000000..13cabf77011d48 --- /dev/null +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_selector.cpp @@ -0,0 +1,18 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "rms_kernel_selector.h" +#include "rms_kernel_ref.h" +#include "rms_kernel_bfyx_opt.h" + +namespace kernel_selector { +rms_kernel_selector::rms_kernel_selector() { + Attach(); + Attach(); +} + +KernelsData rms_kernel_selector::GetBestKernels(const Params& params, const optional_params& options) const { + return GetNaiveBestKernel(params, options, KernelType::RMS); +} +} // namespace kernel_selector diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_selector.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_selector.h new file mode 100644 index 00000000000000..f951264c7f5c6b --- /dev/null +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/rms/rms_kernel_selector.h @@ -0,0 +1,23 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "kernel_selector.h" + +namespace kernel_selector { +class rms_kernel_selector : public kernel_selector_base { +public: + static rms_kernel_selector& Instance() { + static rms_kernel_selector instance_; + return instance_; + } + + rms_kernel_selector(); + + virtual ~rms_kernel_selector() {} + + KernelsData GetBestKernels(const Params& params, const optional_params& options) const override; +}; +} // namespace kernel_selector diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/scatter_update/scatter_nd_update_kernel_ref.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/scatter_update/scatter_nd_update_kernel_ref.cpp index 9fbe45f3da02a4..1680d39ca27bb6 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernels/scatter_update/scatter_nd_update_kernel_ref.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/scatter_update/scatter_nd_update_kernel_ref.cpp @@ -170,6 +170,10 @@ KernelsData ScatterNDUpdateKernelRef::GetKernelsData(const Params& params, const kd.kernels[i].params.workGroups.global = dispatchData.gws; kd.kernels[i].params.workGroups.local = dispatchData.lws; kd.kernels[i].skip_execution = KernelData::SkipKernelExecution(prim_params); + + // Do not skip copy stage if output buffer is not empty or requires modification + if (i == 0 && prim_params.outputs[0].LogicalSize() != 0 && prim_params.outputs[0] != prim_params.inputs[0]) + kd.kernels[i].skip_execution = false; } }; @@ -178,6 +182,7 @@ KernelsData ScatterNDUpdateKernelRef::GetKernelsData(const Params& params, const for (int i = 0; i < 2; i++) { auto dispatchData = SetDefault(newParams, (i == 1)); auto entry_point = GetEntryPoint(kernelName, newParams.layerID, params, options, i); + auto inputs_number = i == 0 ? 1 : 3; if (i == 1) { size_t input0_rank = newParams.inputs[0].LogicalDims().size(); @@ -213,7 +218,7 @@ KernelsData ScatterNDUpdateKernelRef::GetKernelsData(const Params& params, const clKernelData& kernel = kd.kernels[i]; FillCLKernelData(kernel, dispatchData, params.engineInfo, kernelName, jit, entry_point, - "", false, false, 3, GetFusedPrimitiveInputsCount(params), 1, newParams.has_dynamic_tensors()); + "", false, false, inputs_number, GetFusedPrimitiveInputsCount(params), 1, newParams.has_dynamic_tensors()); } return {kd}; diff --git a/src/plugins/intel_gpu/src/kernel_selector/tensor_type.cpp b/src/plugins/intel_gpu/src/kernel_selector/tensor_type.cpp index 545f01c6f3801e..3fcd03bdece0db 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/tensor_type.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/tensor_type.cpp @@ -27,16 +27,20 @@ DataTensor::DataChannelArray DataTensor::dataChannelArray {{ { DataLayout::fyxb, { 1, 2, -1, -1, -1, -1, 3, 0 } }, { DataLayout::b_fs_yx_fsv2, { 0, 1, -1, -1, -1, -1, 2, 3 } }, { DataLayout::b_fs_yx_fsv4, { 0, 1, -1, -1, -1, -1, 2, 3 } }, + { DataLayout::b_fs_yx_fsv8, { 0, 1, -1, -1, -1, -1, 2, 3 } }, { DataLayout::b_fs_yx_fsv16, { 0, 1, -1, -1, -1, -1, 2, 3 } }, { DataLayout::b_fs_yx_fsv32, { 0, 1, -1, -1, -1, -1, 2, 3 } }, { DataLayout::b_fs_zyx_fsv2, { 0, 1, 2, -1, -1, -1, 3, 4 } }, { DataLayout::b_fs_zyx_fsv4, { 0, 1, 2, -1, -1, -1, 3, 4 } }, + { DataLayout::b_fs_zyx_fsv8, { 0, 1, 2, -1, -1, -1, 3, 4 } }, { DataLayout::b_fs_zyx_fsv16, { 0, 1, 2, -1, -1, -1, 3, 4 } }, { DataLayout::b_fs_zyx_fsv32, { 0, 1, 2, -1, -1, -1, 3, 4 } }, { DataLayout::bs_fs_yx_bsv16_fsv32, { 0, 1, -1, -1, -1, -1, 2, 3 } }, { DataLayout::bs_fs_zyx_bsv16_fsv32, { 0, 1, 2, -1, -1, -1, 3, 4 } }, { DataLayout::bs_fs_zyx_bsv16_fsv16, { 0, 1, 2, -1, -1, -1, 3, 4 } }, { DataLayout::bs_fs_yx_bsv16_fsv16, { 0, 1, -1, -1, -1, -1, 2, 3 } }, + { DataLayout::bs_fs_zyx_bsv16_fsv8, { 0, 1, 2, -1, -1, -1, 3, 4 } }, + { DataLayout::bs_fs_yx_bsv16_fsv8, { 0, 1, -1, -1, -1, -1, 2, 3 } }, { DataLayout::bs_fs_yx_bsv4_fsv4, { 0, 1, -1, -1, -1, -1, 2, 3 } }, { DataLayout::bs_fs_yx_bsv8_fsv4, { 0, 1, -1, -1, -1, -1, 2, 3 } }, { DataLayout::bs_fs_zyx_bsv8_fsv4, { 0, 1, 2, -1, -1, -1, 3, 4 } }, @@ -82,7 +86,10 @@ WeightsTensor::WeightsChannelArray WeightsTensor::weightsChannelArray {{ { WeightsLayout::os_iyx_osv32__ai32, { 0, 1, -1, 2, 3, -1 } }, { WeightsLayout::os_iyx_osv64, { 0, 1, -1, 2, 3, -1 } }, { WeightsLayout::os_iyx_osv16_rotate_180, { 0, 1, -1, 2, 3, -1 } }, + { WeightsLayout::o_is_yx_isv2, { 0, 1, -1, 2, 3, -1 } }, + { WeightsLayout::o_is_yx_isv4, { 0, 1, -1, 2, 3, -1 } }, { WeightsLayout::o_is_yx_isv16, { 0, 1, -1, 2, 3, -1 } }, + { WeightsLayout::o_is_zyx_isv16, { 0, 1, 2, 3, 4, -1 } }, { WeightsLayout::os_yxi_osv16, { 1, 2, -1, 0, 3, -1 } }, { WeightsLayout::os_i_osv8__ai8, { -1, -1, -1, 0, 1, -1 } }, { WeightsLayout::os_i_osv16__ai8, { -1, -1, -1, 0, 1, -1 } }, @@ -132,6 +139,8 @@ WeightsTensor::WeightsChannelArray WeightsTensor::weightsChannelArray {{ { WeightsLayout::is_o32_yx_isv32_swizzled_by_4, { 1, 2, -1, 0, 3, -1 } }, { WeightsLayout::os_is_y_x8_osv8_isv4, { 0, 1, -1, 2, 3, -1 } }, { WeightsLayout::os_is_y_x8_osv8_isv4_swizzled_by_4, { 0, 1, -1, 2, 3, -1 } }, + { WeightsLayout::os_is_yx_osv2_isv16, { 0, 1, -1, 2, 3, -1 } }, + { WeightsLayout::os_is_yx_osv4_isv16, { 0, 1, -1, 2, 3, -1 } }, { WeightsLayout::os_is_yx_osv8_isv4, { 0, 1, -1, 2, 3, -1 } }, { WeightsLayout::os_is_zyx_osv8_isv4, { 0, 1, 2, 3, 4, -1 } }, { WeightsLayout::os_is_yx_osv8_isv2, { 0, 1, -1, 2, 3, -1 } }, @@ -145,6 +154,7 @@ WeightsTensor::WeightsChannelArray WeightsTensor::weightsChannelArray {{ { WeightsLayout::os_is_yx_osv32_isv32p, { 0, 1, -1, 2, 3, -1 } }, { WeightsLayout::os_is_zyx_isv16_osv16, { 0, 1, 2, 3, 4, -1 } }, { WeightsLayout::os_is_yx_isv16_osv16, { 0, 1, -1, 2, 3, -1 } }, + { WeightsLayout::is_os_yx_osv8_isv4, { 0, 1, -1, 3, 2, -1 } }, { WeightsLayout::is_os_zyx_isv16_osv16, { 0, 1, 2, 4, 3, -1 } }, { WeightsLayout::is_os_yx_isv16_osv16, { 0, 1, -1, 3, 2, -1 } }, { WeightsLayout::is_os_yx_isv16_osv8, { 0, 1, -1, 3, 2, -1 } }, @@ -180,6 +190,8 @@ WeightsTensor::WeightsChannelArray WeightsTensor::weightsChannelArray {{ { WeightsLayout::g_os_iyx_osv8, { 0, 1, -1, 2, 3, 4 } }, { WeightsLayout::g_os_iyx_osv16, { 0, 1, -1, 2, 3, 4 } }, { WeightsLayout::g_os_iyx_osv32, { 0, 1, -1, 2, 3, 4 } }, + { WeightsLayout::gs_oiyx_gsv8, { 0, 1, -1, 2, 3, 4 } }, + { WeightsLayout::gs_oizyx_gsv8, { 0, 1, 2, 3, 4, 5 } }, { WeightsLayout::gs_oiyx_gsv16, { 0, 1, -1, 2, 3, 4 } }, { WeightsLayout::gs_oizyx_gsv16, { 0, 1, 2, 3, 4, 5 } }, { WeightsLayout::gs_oiyx_gsv32, { 0, 1, -1, 2, 3, 4 } }, @@ -233,6 +245,10 @@ NDims DataTensor::GetSimpleDims(const std::vector& d, DataLayout l) { newDims[0] = RoundUp(newDims[0], 8); newDims[1] = RoundUp(newDims[1], 16); break; + case b_fs_yx_fsv8: + assert(newDims.size() == 4); + newDims[2] = RoundUp(newDims[2], 8); + break; case b_fs_yx_fsv16: assert(newDims.size() == 4); newDims[2] = RoundUp(newDims[2], 16); @@ -253,10 +269,19 @@ NDims DataTensor::GetSimpleDims(const std::vector& d, DataLayout l) { assert(newDims.size() == 4); newDims[3] = RoundUp(newDims[3], 32); break; + case b_fs_zyx_fsv8: + assert(newDims.size() == 5); + newDims[3] = RoundUp(newDims[3], 8); + break; case b_fs_zyx_fsv16: assert(newDims.size() == 5); newDims[3] = RoundUp(newDims[3], 16); break; + case bs_fs_yx_bsv16_fsv8: + assert(newDims.size() == 4); + newDims[2] = RoundUp(newDims[2], 8); + newDims[3] = RoundUp(newDims[3], 16); + break; case bs_fs_yx_bsv16_fsv16: assert(newDims.size() == 4); newDims[2] = RoundUp(newDims[2], 16); @@ -277,6 +302,11 @@ NDims DataTensor::GetSimpleDims(const std::vector& d, DataLayout l) { newDims[3] = RoundUp(newDims[3], 16); newDims[4] = RoundUp(newDims[4], 16); break; + case bs_fs_zyx_bsv16_fsv8: + assert(newDims.size() == 5); + newDims[3] = RoundUp(newDims[3], 8); + newDims[4] = RoundUp(newDims[4], 16); + break; case bs_fs_yx_bsv4_fsv4: assert(newDims.size() == 4); newDims[2] = RoundUp(newDims[2], 4); @@ -588,10 +618,22 @@ NDims WeightsTensor::GetSimpleDims(const std::vector& d, WeightsLayout l // TODO: It's not the right pitches. it's here in order to calculate physical size switch (l) { + case o_is_yx_isv2: + assert(newDims.size() == 4); + newDims[2] = RoundUp(newDims[2], 2); + break; + case o_is_yx_isv4: + assert(newDims.size() == 4); + newDims[2] = RoundUp(newDims[2], 4); + break; case o_is_yx_isv16: assert(newDims.size() == 4); newDims[2] = RoundUp(newDims[2], 16); break; + case o_is_zyx_isv16: + assert(newDims.size() == 5); + newDims[2] = RoundUp(newDims[3], 16); + break; case os_iyx_osv16: case os_yxi_osv16: case os_iyx_osv16_rotate_180: @@ -772,6 +814,11 @@ NDims WeightsTensor::GetSimpleDims(const std::vector& d, WeightsLayout l newDims[3] = RoundUp(newDims[3], 16); newDims[4] = RoundUp(newDims[4], 16); break; + case is_os_yx_osv8_isv4: + assert(newDims.size() == 4); + newDims[2] = RoundUp(newDims[2], 8); + newDims[3] = RoundUp(newDims[3], 4); + break; case is_os_yx_isv16_osv16: assert(newDims.size() == 4); newDims[2] = RoundUp(newDims[2], 16); @@ -806,6 +853,16 @@ NDims WeightsTensor::GetSimpleDims(const std::vector& d, WeightsLayout l assert(newDims.size() == 5); newDims[3] = RoundUp(newDims[0], 16); break; + case os_is_yx_osv2_isv16: + assert(newDims.size() == 4); + newDims[2] = RoundUp(newDims[2], 16); + newDims[3] = RoundUp(newDims[3], 2); + break; + case os_is_yx_osv4_isv16: + assert(newDims.size() == 4); + newDims[2] = RoundUp(newDims[2], 16); + newDims[3] = RoundUp(newDims[3], 4); + break; case os_is_yx_osv8_isv4: assert(newDims.size() == 4); newDims[2] = RoundUp(newDims[2], 4); @@ -827,6 +884,14 @@ NDims WeightsTensor::GetSimpleDims(const std::vector& d, WeightsLayout l assert(newDims.size() == 5); newDims[3] = RoundUp(newDims[3], 32); break; + case gs_oiyx_gsv8: + assert(newDims.size() == 5); + newDims[4] = RoundUp(newDims[4], 8); + break; + case gs_oizyx_gsv8: + assert(newDims.size() == 6); + newDims[5] = RoundUp(newDims[5], 8); + break; case gs_oiyx_gsv16: assert(newDims.size() == 5); newDims[4] = RoundUp(newDims[4], 16); diff --git a/src/plugins/intel_gpu/src/kernel_selector/tensor_type.h b/src/plugins/intel_gpu/src/kernel_selector/tensor_type.h index 85cec1fe17cf42..205b3198a7a103 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/tensor_type.h +++ b/src/plugins/intel_gpu/src/kernel_selector/tensor_type.h @@ -40,6 +40,8 @@ enum DataLayout { b_fs_zyx_fsv2, b_fs_yx_fsv4, // reordering format for swizzled input for convolution using IMAD b_fs_zyx_fsv4, + b_fs_yx_fsv8, + b_fs_zyx_fsv8, b_fs_yx_fsv16, // 3D+batch b_fs_zyx_fsv16, // batch, feature, 3D spatial. Blocks of 16 input channels b_fs_yx_fsv32, // 3D+batch @@ -53,6 +55,8 @@ enum DataLayout { bs_fs_yx_bsv8_fsv2, // batch, feature, 2D spatial. Blocks of 8 batch and 2 channels bs_fs_zyx_bsv8_fsv4, // batch, feature, 3D spatial. Blocks of 8 batch and 4 channels bs_fs_zyx_bsv8_fsv2, // batch, feature, 3D spatial. Blocks of 8 batch and 2 channels + bs_fs_yx_bsv16_fsv8, // batch, feature, 2D spatial. Blocks of 16 batch and 8 channels + bs_fs_zyx_bsv16_fsv8, // batch, feature, 3D spatial. Blocks of 16 batch and 8 channels bs_fs_yx_bsv16_fsv4, // batch, feature, 2D spatial. Blocks of 16 batch and 4 channels bs_fs_zyx_bsv16_fsv4, // batch, feature, 3D spatial. Blocks of 16 batch and 4 channels bs_fs_yx_bsv16_fsv2, // batch, feature, 2D spatial. Blocks of 16 batch and 2 channels @@ -90,7 +94,10 @@ enum WeightsLayout { oxiy, iyxo, yxio, + o_is_yx_isv2, + o_is_yx_isv4, o_is_yx_isv16, + o_is_zyx_isv16, os_yxi_osv16, os_iyx_osv16, os_iyx_osv32, @@ -156,6 +163,7 @@ enum WeightsLayout { os_is_yx_isa8_osv8_isv2, is_os_yx_isa8_osv8_isv2, is_os_yx_isa8_osv8_isv4, + is_os_yx_osv8_isv4, is_os_yx_osa8_isv16_osv4, is_os_yx_isa2_osa8_isv8_osv2, g_os_is_yx_osa2_isa8_osv16_isv4, @@ -179,6 +187,8 @@ enum WeightsLayout { os_is_yx_osv32_isv4_swizzled_by_2, // weights for bfyx -> b_fs_yx_fsv32 convolution using IMAD with swizzled ofm (0, 2, 4..), (1, 3, 5...) os_is_yx_osv32_isv4, // weights for bfyx -> b_fs_yx_fsv{32,16} convolution using IMAD os_is_zyx_osv32_isv4, // weights for bfzyx -> b_fs_zyx_fsv16 convolution using IMAD + os_is_yx_osv2_isv16, + os_is_yx_osv4_isv16, oizyx, iozyx, os_is_yx_osv32_isv32p, // 2 blocks: 32 packed binary in channels and 32 output channels @@ -200,6 +210,8 @@ enum WeightsLayout { g_os_iyx_osv8, g_os_iyx_osv16, g_os_iyx_osv32, + gs_oiyx_gsv8, + gs_oizyx_gsv8, gs_oiyx_gsv16, gs_oizyx_gsv16, gs_oiyx_gsv32, @@ -610,6 +622,10 @@ struct TensorBaseT : public TensorBase { return same; } + bool operator!=(const TensorBaseT& t) const { + return !(*this == t); + } + bool SameDims(const TensorBaseT& t) const { bool same = dtype == t.dtype && layout == t.layout && dims.size() == t.dims.size(); if (same) { diff --git a/src/plugins/intel_gpu/src/plugin/compiled_model.cpp b/src/plugins/intel_gpu/src/plugin/compiled_model.cpp index 3b8581a1e2e34e..fc04e35748fe6c 100644 --- a/src/plugins/intel_gpu/src/plugin/compiled_model.cpp +++ b/src/plugins/intel_gpu/src/plugin/compiled_model.cpp @@ -35,6 +35,20 @@ std::shared_ptr create_task_executor(const std::sh if (config.get_property(ov::internal::exclusive_async_requests)) { //exclusive_async_requests essentially disables the streams (and hence should be checked first) => aligned with the CPU behavior return plugin->get_executor_manager()->get_executor("GPU"); + } else if (config.get_property(ov::hint::enable_cpu_pinning)) { + auto executor_config = + ov::threading::IStreamsExecutor::Config{"Intel GPU plugin executor", + 0, + 0, + ov::threading::IStreamsExecutor::ThreadBindingType::CORES, + 1, + 0, + 0, + ov::threading::IStreamsExecutor::Config::PreferredCoreType::BIG, + {{config.get_property(ov::num_streams), MAIN_CORE_PROC, 1, 0, 0}}, + true}; + auto post_config = ov::threading::IStreamsExecutor::Config::reserve_cpu_threads(executor_config); + return std::make_shared(post_config); } else { return std::make_shared( ov::threading::IStreamsExecutor::Config{"Intel GPU plugin executor", config.get_property(ov::num_streams)}); @@ -250,6 +264,7 @@ ov::Any CompiledModel::get_property(const std::string& name) const { // Configs ov::PropertyName{ov::enable_profiling.name(), PropertyMutability::RO}, + ov::PropertyName{ov::hint::enable_cpu_pinning.name(), PropertyMutability::RO}, ov::PropertyName{ov::hint::model_priority.name(), PropertyMutability::RO}, ov::PropertyName{ov::intel_gpu::hint::host_task_priority.name(), PropertyMutability::RO}, ov::PropertyName{ov::intel_gpu::hint::queue_priority.name(), PropertyMutability::RO}, diff --git a/src/plugins/intel_gpu/src/plugin/ops/condition.cpp b/src/plugins/intel_gpu/src/plugin/ops/condition.cpp index d9b4e77314e600..c25726f673a2f8 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/condition.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/condition.cpp @@ -22,6 +22,12 @@ static cldnn::condition::branch gen_branch(ProgramBuilder& p, const std::shared_ << ", num inputs: " << op->get_input_size() << std::endl; auto config = p.get_config(); + { + auto custom_outputs = config.get_property(ov::intel_gpu::custom_outputs); + if (!custom_outputs.empty()) { + config.set_property(ov::intel_gpu::custom_outputs(std::vector({}))); + } + } config.set_property(ov::intel_gpu::max_dynamic_batch(1)); config.set_property(ov::intel_gpu::allow_new_shape_infer(op->is_dynamic())); @@ -61,10 +67,13 @@ static void CreateIfOp(ProgramBuilder& p, const std::shared_ptr& auto branch_true = gen_branch(p, op, idx_true); auto branch_false = gen_branch(p, op, idx_false); + const size_t num_outputs = op->get_output_size(); + const cldnn::condition conditionPrimitive(layerName, inputs, branch_true, - branch_false); + branch_false, + num_outputs); p.add_primitive(*op, conditionPrimitive); } diff --git a/src/plugins/intel_gpu/src/plugin/ops/constant.cpp b/src/plugins/intel_gpu/src/plugin/ops/constant.cpp index b74d05e4f9aca6..b12536b10ccb9a 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/constant.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/constant.cpp @@ -19,6 +19,8 @@ #include "openvino/op/roi_align.hpp" #include "openvino/op/variadic_split.hpp" #include "openvino/op/util/op_types.hpp" +#include "openvino/op/loop.hpp" +#include "openvino/op/tensor_iterator.hpp" #include "intel_gpu/primitives/data.hpp" #include "intel_gpu/runtime/debug_configuration.hpp" @@ -206,6 +208,13 @@ static void CreateConstantOp(ProgramBuilder& p, const std::shared_ptr(outOp) || ov::is_type(outOp)) { consts[op].needsBatchInterpretation = constDims.size() == 1; + } else if ((ov::is_type(outOp) || ov::is_type(outOp))) { + // when inner network has 1d parameter which is connected to outer loop's constant 1d data, + // outer constant 1d data and inner 1d parameter has same bytes_count but layout is different + // (outer constant is [1, N, 1, 1] but inner parameter is [N, 1, 1, 1]). + // To pass check_memory_to_set in input_layout::set_data for this case, Set constDims to [N, 1, 1, 1] + // when constDims is one dim and user op is Loop or TensorIterator. + consts[op].needsBatchInterpretation = constDims.size() == 1; } } diff --git a/src/plugins/intel_gpu/src/plugin/ops/gather.cpp b/src/plugins/intel_gpu/src/plugin/ops/gather.cpp index 883ebaba1a6dc2..7d941375d5ae14 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/gather.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/gather.cpp @@ -119,6 +119,7 @@ void CreateGatherOpBase(ProgramBuilder& p, const std::shared_ptr& op, const i reordered_inputs[0], reordered_inputs[1], axis, + input_rank, out_shape, batch_dim, support_neg_ind); diff --git a/src/plugins/intel_gpu/src/plugin/ops/group_normalization.cpp b/src/plugins/intel_gpu/src/plugin/ops/group_normalization.cpp new file mode 100644 index 00000000000000..8c17d111331a67 --- /dev/null +++ b/src/plugins/intel_gpu/src/plugin/ops/group_normalization.cpp @@ -0,0 +1,30 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/op/group_normalization.hpp" +#include "intel_gpu/plugin/program_builder.hpp" +#include "intel_gpu/primitives/group_normalization.hpp" + +namespace ov { +namespace intel_gpu { + +static void CreateGroupNormalizationOp(ProgramBuilder& p, const std::shared_ptr& op) { + validate_inputs_count(op, {3}); + auto inputs = p.GetInputInfo(op); + auto layerName = layer_type_name_ID(op); + cldnn::group_normalization groupNormalizationPrimitive { + layerName, + inputs[0], + inputs[1], + inputs[2], + op->get_num_groups(), + op->get_epsilon() + }; + p.add_primitive(*op, groupNormalizationPrimitive); +} + +REGISTER_FACTORY_IMPL(v12, GroupNormalization); + +} // namespace intel_gpu +} // namespace ov diff --git a/src/plugins/intel_gpu/src/plugin/ops/loop.cpp b/src/plugins/intel_gpu/src/plugin/ops/loop.cpp index f44dddb26ba0e6..628b0d7c37d9aa 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/loop.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/loop.cpp @@ -5,6 +5,7 @@ #include "intel_gpu/plugin/common_utils.hpp" #include "intel_gpu/plugin/plugin.hpp" +#include "openvino/op/tensor_iterator.hpp" #include "openvino/op/loop.hpp" #include "openvino/op/constant.hpp" #include "openvino/op/util/sub_graph_base.hpp" @@ -20,13 +21,14 @@ #include using Loop = ov::op::v5::Loop; +using TensorIterator = ov::op::v0::TensorIterator; namespace ov { namespace intel_gpu { template -static DATA_TYPE CreateScalarData(ProgramBuilder &p, const cldnn::primitive_id& id, int64_t num) { - auto mem = p.get_engine().allocate_memory({ cldnn::data_types::i64, cldnn::format::bfyx, { 1, 1, 1, 1 } }); +static DATA_TYPE CreateScalarData(ProgramBuilder &p, const cldnn::primitive_id& id, ov::Shape& shape, cldnn::data_types dtype, int64_t num) { + auto mem = p.get_engine().allocate_memory({ shape, dtype, cldnn::format::bfyx }); cldnn::mem_lock ptr{mem, p.get_engine().get_service_stream()}; *ptr.begin() = num; return {id, mem}; @@ -40,52 +42,37 @@ static cldnn::mutable_data CreateAdditionalOutputData(ProgramBuilder &p, const s const auto tensor = tensor_from_dims(op->get_output_shape(output_idx)); cldnn::layout output_layout = cldnn::layout(precision, format, tensor); auto mem = p.get_engine().allocate_memory(output_layout); - auto md = cldnn::mutable_data(id, {cldnn::input_info(input)}, mem); // cldnn::data cannot set dependency + auto md = cldnn::mutable_data(id, {cldnn::input_info(input)}, std::move(mem)); // cldnn::data cannot set dependency return md; } -static void CreateLoopOp(ProgramBuilder& p, const std::shared_ptr& op) { +static void SetLoopInputOutputMap(ProgramBuilder& p, + const std::shared_ptr& op, + cldnn::primitive::input_info_arr& inputs, + std::vector& input_primitive_maps, + std::vector& output_primitive_maps, + std::vector& back_edges_maps) { const std::string layerName = layer_type_name_ID(op); - auto inputs = p.GetInputInfo(op); const auto& loop_input_descs = op->get_input_descriptions(); const auto& loop_output_descs = op->get_output_descriptions(); const auto& body_inputs = op->get_function()->get_parameters(); const auto& body_outputs = op->get_function()->get_results(); - // Set special body ports: current_iteration input , execution condition output - auto special_body_ports = op->get_special_body_ports(); - - std::string body_current_iteration_id; - if (special_body_ports.current_iteration_input_idx >= 0) { - auto current_iteration_input = body_inputs.at(special_body_ports.current_iteration_input_idx); - body_current_iteration_id = layer_type_name_ID(current_iteration_input); - std::string input_name = ov::op::util::create_ie_output_name(current_iteration_input); - } - - cldnn::primitive_id body_execution_condition_id; - if (special_body_ports.body_condition_output_idx >= 0) { - auto body_condition_output = body_outputs.at(special_body_ports.body_condition_output_idx)->get_input_node_shared_ptr(0); - body_execution_condition_id = layer_type_name_ID(body_condition_output); - } - - // get body topology from ov::Model - ProgramBuilder body_program(op->get_function(), p.get_engine(), p.get_config(), true); - auto body_topology = *body_program.get_topology(); - - // setup input_primitive_maps/ output_primitive_maps and back_edges - std::vector input_primitive_maps; - std::vector output_primitive_maps; - std::vector back_edges; + bool use_new_shape_infer = p.use_new_shape_infer(); // set input mapping & back edges for (const auto& loop_input_desc : loop_input_descs) { - const cldnn::primitive_id& external_id = inputs.at(loop_input_desc->m_input_index).pid; + auto external_id = inputs.at(loop_input_desc->m_input_index); auto& body_input = body_inputs.at(loop_input_desc->m_body_parameter_index); cldnn::primitive_id internal_id = layer_type_name_ID(body_input); + GPU_DEBUG_LOG << "loop_input_descs[" << layerName << "] = {m_input_index:" << loop_input_desc->m_input_index << "(external_id: " + << external_id << "), m_body_parameter_index:" << loop_input_desc->m_body_parameter_index + << "(internal_id: " << internal_id << ")}" << std::endl; + // set input mapping if (const auto& sliceInfo = - std::dynamic_pointer_cast(loop_input_desc)) { + std::dynamic_pointer_cast(loop_input_desc)) { // sliced input input_primitive_maps.emplace_back(external_id, internal_id, sliceInfo->m_axis, sliceInfo->m_start, sliceInfo->m_end, sliceInfo->m_stride); @@ -96,7 +83,7 @@ static void CreateLoopOp(ProgramBuilder& p, const std::shared_ptr& op) { // set back edges if (const auto& mergedInput = - std::dynamic_pointer_cast(loop_input_desc)) { + std::dynamic_pointer_cast(loop_input_desc)) { // backedge const auto& to = body_inputs.at(mergedInput->m_body_parameter_index); const auto& from = body_outputs.at(mergedInput->m_body_value_index); @@ -104,81 +91,234 @@ static void CreateLoopOp(ProgramBuilder& p, const std::shared_ptr& op) { cldnn::primitive_id to_id = layer_type_name_ID(to); cldnn::primitive_id from_id = layer_type_name_ID(from); - // reset output data type because the data types of the outputs of the - // body topology are always FP32 regardless of element type - { - const auto from_prim = body_topology.at(from_id); - const auto to_cldnn_type = cldnn::element_type_to_data_type(to->get_element_type()); - from_prim->output_data_types = {to_cldnn_type}; - } - back_edges.emplace_back(from_id, to_id); + back_edges_maps.emplace_back(from_id, to_id); } } - // set trip count, initial execution condition, num iteration primitives - // they should be mutable_data to prevent from being optimized out - const cldnn::primitive_id trip_count_id = layer_type_name_ID(op->get_input_node_shared_ptr(0)); - const cldnn::primitive_id execution_condition_id = layer_type_name_ID(op->get_input_node_shared_ptr(1)); - const int64_t num_iterations = op->get_num_iterations(); - if (num_iterations < 0) { - OPENVINO_THROW("loop's num_iteration cannot be negative"); + // set output mapping + if (use_new_shape_infer) { + for (const auto& loop_output_desc : loop_output_descs) { + cldnn::input_info external_input_info(layerName, loop_output_desc->m_output_index); + p.primitive_ids[layerName] = layerName; + + const auto& body_output = body_outputs.at(loop_output_desc->m_body_value_index); + cldnn::primitive_id internal_id = layer_type_name_ID(body_output); + + // update primitive_map + if (const auto& concatOutput = + std::dynamic_pointer_cast(loop_output_desc)) { + // output which requires concatenation + output_primitive_maps.emplace_back(external_input_info, internal_id, concatOutput->m_axis, + concatOutput->m_start, concatOutput->m_end, concatOutput->m_stride); + GPU_DEBUG_LOG << "loop_output_descs[" << layerName << "][ConcatOutputDescription] external:" + << external_input_info << ", internal:" + << internal_id << "(axis, start, end, stride)={" + << concatOutput->m_axis << "," << concatOutput->m_start << "," + << concatOutput->m_end << "," << concatOutput->m_stride << "}" << std::endl; + } + if (std::dynamic_pointer_cast(loop_output_desc)) { + // output which requires no concatenation + output_primitive_maps.emplace_back(external_input_info, internal_id); + GPU_DEBUG_LOG << "loop_output_descs[" << layerName << "][BodyOutputDescription] external:" + << external_input_info << ", internal:" << internal_id << std::endl; + } + } + } else { + for (const auto& loop_output_desc : loop_output_descs) { + const uint64_t output_idx = loop_output_desc->m_output_index; + + // Add additional mutable_data for multiple outputs + // primitive ID should be . if output_idx > 0 + // otherwise primitive ID should be equals to TI primitive ID + const std::string layerNameWithIndex = layerName + ".out" + std::to_string(output_idx); + std::string external_id; + if (output_idx > 0) { + cldnn::mutable_data output_data = CreateAdditionalOutputData(p, op, layerNameWithIndex, layerName, output_idx); + p.add_primitive(*op, std::move(output_data)); + external_id = layerNameWithIndex; + } else { + p.primitive_ids[layerNameWithIndex] = layerName; + p.primitive_ids[layerName] = layerName; + external_id = layerName; + } + const auto& body_output = body_outputs.at(loop_output_desc->m_body_value_index); + cldnn::primitive_id internal_id = layer_type_name_ID(body_output); + + // update primitive_map + if (const auto& concatOutput = + std::dynamic_pointer_cast(loop_output_desc)) { + // output which requires concatenation + output_primitive_maps.emplace_back(external_id, internal_id, concatOutput->m_axis, + concatOutput->m_start, concatOutput->m_end, concatOutput->m_stride); + GPU_DEBUG_LOG << "loop_output_descs[" << layerName << "][ConcatOutputDescription] external:" + << external_id << ", internal:" + << internal_id << "(axis, start, end, stride)={" + << concatOutput->m_axis << "," << concatOutput->m_start << "," + << concatOutput->m_end << "," << concatOutput->m_stride << "}" << std::endl; + } + if (std::dynamic_pointer_cast(loop_output_desc)) { + // output which requires no concatenation + output_primitive_maps.emplace_back(external_id, internal_id); + GPU_DEBUG_LOG << "loop_output_descs[" << layerName << "][BodyOutputDescription] external:" + << external_id << ", internal:" << internal_id << std::endl; + } + } } - const cldnn::primitive_id num_iteration_id = layerName + "_numIteration"; - { - cldnn::mutable_data num_iteration = CreateScalarData(p, num_iteration_id, 0); - p.add_primitive(*op, std::move(num_iteration)); +} + +static std::vector GetOutputNames(const cldnn::primitive_id id, + const cldnn::primitive_id body_execution_condition_id, + const std::vector& output_primitive_maps, + const std::vector& back_edges) { + std::vector output_names; + OPENVINO_ASSERT(!output_primitive_maps.empty(), "[GPU] Output primitive map should have at least 1 mapping in primitive ", id); + for (auto out_map : output_primitive_maps) { + output_names.push_back(out_map.internal_id.pid); } - // set output mapping - for (const auto& loop_output_desc : loop_output_descs) { - const uint64_t output_idx = loop_output_desc->m_output_index; - - // Add additional mutable_data for multiple outputs - // primitive ID should be . if output_idx > 0 - // otherwise primitive ID should be equals to TI primitive ID - const std::string layerNameWithIndex = layerName + ".out" + std::to_string(output_idx); - std::string external_id; - if (output_idx > 0) { - cldnn::mutable_data output_data = CreateAdditionalOutputData(p, op, layerNameWithIndex, layerName, output_idx); - p.add_primitive(*op, std::move(output_data)); - external_id = layerNameWithIndex; - } else { - external_id = layerName; + // setup outputs for backedges + for (auto& back_edge : back_edges) { + auto iter = std::find(output_names.begin(), output_names.end(), back_edge.from); + // Do not add duplicated output name + if (iter == output_names.end()) { + output_names.push_back(back_edge.from); } - const auto& body_output = body_outputs.at(loop_output_desc->m_body_value_index); - cldnn::primitive_id internal_id = layer_type_name_ID(body_output); - - // update primitive_map - if (const auto& concatOutput = - std::dynamic_pointer_cast(loop_output_desc)) { - // output which requires concatenation - output_primitive_maps.emplace_back(external_id, internal_id, concatOutput->m_axis, - concatOutput->m_start, concatOutput->m_end, concatOutput->m_stride); + } + + // if execution_condition_id is specified, we need to add the id in build_option::outputs + if (!body_execution_condition_id.empty()) { + output_names.push_back(body_execution_condition_id); + } + + return output_names; +} + +static void CreateCommonLoopOp(ProgramBuilder& p, const std::shared_ptr& op, bool is_loop_op) { + const std::string layerName = layer_type_name_ID(op); + auto inputs = p.GetInputInfo(op); + bool is_dynamic = p.use_new_shape_infer() || op->is_dynamic(); + + int64_t num_iterations = op->get_num_iterations(); + OPENVINO_ASSERT((is_dynamic || num_iterations > 0), "loop's num_iteration should be positive on static shape model"); + + auto num_outputs = is_dynamic? op->get_output_size() : 1; + auto ov_model = op->get_function(); + + // Set special body ports: current_iteration input , execution condition output + cldnn::primitive_id body_current_iteration_id; + cldnn::primitive_id body_execution_condition_id; + cldnn::primitive_id trip_count_id; + cldnn::primitive_id first_execution_condition_id; + cldnn::primitive_id updated_current_iteration_id; + + std::shared_ptr current_iteration_input_op; + if (is_loop_op) { + auto loop_op = std::dynamic_pointer_cast(op); + auto special_body_ports = loop_op->get_special_body_ports(); + if (special_body_ports.current_iteration_input_idx >= 0) { + const auto& body_inputs = loop_op->get_function()->get_parameters(); + current_iteration_input_op = body_inputs.at(special_body_ports.current_iteration_input_idx); + body_current_iteration_id = layer_type_name_ID(current_iteration_input_op); } - if (std::dynamic_pointer_cast(loop_output_desc)) { - // output which requires no concatenation - output_primitive_maps.emplace_back(external_id, internal_id); + + if (special_body_ports.body_condition_output_idx >= 0) { + const auto& body_outputs = loop_op->get_function()->get_results(); + auto body_condition_output = body_outputs.at(special_body_ports.body_condition_output_idx)->get_input_node_shared_ptr(0); + body_execution_condition_id = layer_type_name_ID(body_condition_output); } + + trip_count_id = layer_type_name_ID(loop_op->get_input_node_shared_ptr(0)); + first_execution_condition_id = layer_type_name_ID(loop_op->get_input_node_shared_ptr(1)); + } + + // setup input_primitive_maps/ output_primitive_maps and back_edges + std::vector input_primitive_maps; + std::vector output_primitive_maps; + std::vector back_edges; + + SetLoopInputOutputMap(p, op, inputs, input_primitive_maps, output_primitive_maps, back_edges); + + auto shape = is_dynamic? ngraph::Shape{1} : ngraph::Shape{1, 1, 1, 1}; + auto prec = ngraph::element::i64; + if (current_iteration_input_op) { + current_iteration_input_op->set_output_type(0, prec, shape); + current_iteration_input_op->set_partial_shape(shape); + current_iteration_input_op->set_element_type(prec); + + auto increment_value_id = current_iteration_input_op->get_friendly_name() + "_inc"; + auto increment_value_op = std::make_shared(prec, shape, 1); + increment_value_op->set_friendly_name(increment_value_id); + + auto update_current_iter_op_id = current_iteration_input_op->get_friendly_name() + "_update"; + auto update_current_iter_op = std::make_shared(current_iteration_input_op, increment_value_op); + update_current_iter_op->set_friendly_name(update_current_iter_op_id); + updated_current_iteration_id = layer_type_name_ID(update_current_iter_op); + + auto result = std::make_shared(update_current_iter_op); + ov_model->add_results({result}); + } + + // set trip count, num iteration primitives + // they should be mutable_data to prevent from being optimized out + const cldnn::primitive_id num_iteration_id = layerName + "_numIteration"; + cldnn::mutable_data num_iteration_data = CreateScalarData(p, num_iteration_id, shape, prec, 0); + + p.add_primitive(*op, std::move(num_iteration_data)); + inputs.insert(inputs.begin(), cldnn::input_info(num_iteration_id, 0)); + + if (!body_current_iteration_id.empty()) { + // update input_primitive_maps and back_edges for current_iteration nodes + input_primitive_maps.emplace_back(cldnn::input_info(num_iteration_id), cldnn::input_info(body_current_iteration_id)); + back_edges.emplace_back(updated_current_iteration_id, body_current_iteration_id); } + auto output_names_vec = GetOutputNames(layerName, body_execution_condition_id, output_primitive_maps, back_edges); + + auto config = p.get_config(); + config.set_property(ov::intel_gpu::custom_outputs(output_names_vec)); + config.set_property(ov::intel_gpu::max_dynamic_batch(1)); + config.set_property(ov::intel_gpu::allow_new_shape_infer(is_dynamic)); + + // get body program from ov::Model + ProgramBuilder prog(ov_model, p.get_engine(), config, false, false, p.get_task_executor(), true); + auto body_program = prog.get_compiled_program(); + + GPU_DEBUG_LOG << "* trip_count_id : " << trip_count_id << std::endl; + GPU_DEBUG_LOG << "* num_iteration_id : " << num_iteration_id << std::endl; + GPU_DEBUG_LOG << "* body_current_iteration_id : " << body_current_iteration_id << std::endl; + GPU_DEBUG_LOG << "* first_execution_condition_id : " << first_execution_condition_id << std::endl; + GPU_DEBUG_LOG << "* body_execution_condition_id : " << body_execution_condition_id << std::endl; + const cldnn::loop loopPrimitive( - layerName, /* layer name of this primitive (output id) */ - inputs, /* inputs of this layer */ - body_topology, /* body network */ - trip_count_id, /* trip_count data in outer network, always same as num_iterations in TI */ - execution_condition_id, /* initial_execution_condition data in outer network, always true in TI */ - num_iteration_id, /* actual number of iteration data in body network */ - input_primitive_maps, /* input mappings connecting outer network and inner network */ - output_primitive_maps, /* output mappings connecting outer network and inner network */ - back_edges, /* back edge mapping */ - num_iterations, /* max iteration, i.e. length of iteration axis */ + layerName, /* layer name of this primitive (output id) */ + inputs, /* inputs of this layer */ + body_program, /* body network */ + trip_count_id, /* trip_count data in outer network, always same as num_iterations in TI */ + first_execution_condition_id, /* initial_execution_condition data in outer network, always true in TI */ + num_iteration_id, /* actual number of iteration data in body network */ + input_primitive_maps, /* input mappings connecting outer network and inner network */ + output_primitive_maps, /* output mappings connecting outer network and inner network */ + back_edges, /* back edge mapping */ + num_iterations, /* max iteration, i.e. length of iteration axis */ body_current_iteration_id, - body_execution_condition_id); + body_execution_condition_id, + num_outputs); p.add_primitive(*op, loopPrimitive); } +static void CreateLoopOp(ProgramBuilder& p, const std::shared_ptr& op) { + CreateCommonLoopOp(p, op, true); +} + +/* The above code is a comment in C++ programming language. It is not doing anything in terms of code +execution. It is simply providing information or documentation about the code. */ +static void CreateTensorIteratorOp(ProgramBuilder& p, const std::shared_ptr& op) { + CreateCommonLoopOp(p, op, false); +} + REGISTER_FACTORY_IMPL(v5, Loop); +REGISTER_FACTORY_IMPL(v0, TensorIterator); } // namespace intel_gpu } // namespace ov diff --git a/src/plugins/intel_gpu/src/plugin/ops/rms.cpp b/src/plugins/intel_gpu/src/plugin/ops/rms.cpp new file mode 100644 index 00000000000000..01289bd5022d6d --- /dev/null +++ b/src/plugins/intel_gpu/src/plugin/ops/rms.cpp @@ -0,0 +1,43 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "intel_gpu/op/rms.hpp" +#include "intel_gpu/plugin/program_builder.hpp" +#include "intel_gpu/plugin/common_utils.hpp" +#include "intel_gpu/primitives/rms.hpp" + +namespace ov { +namespace op { +namespace internal { +using RMS = ov::intel_gpu::op::RMS; +} // namespace internal +} // namespace op +} // namespace ov + +namespace ov { +namespace intel_gpu { + +static void CreateRMSOp(ProgramBuilder& p, const std::shared_ptr& op) { + validate_inputs_count(op, {2}); + auto inputs = p.GetInputInfo(op); + std::string primitive_name = layer_type_name_ID(op); + + auto get_output_data_types = [&]() { + std::vector output_data_types; + auto type = op->get_output_element_type(0); + output_data_types.push_back(cldnn::element_type_to_data_type(type)); + return output_data_types; + }; + auto rms = cldnn::rms(primitive_name, + inputs[0], + inputs[1], + op->get_epsilon()); + rms.output_data_types = get_output_data_types(); + p.add_primitive(*op, rms); +} + +REGISTER_FACTORY_IMPL(internal, RMS); + +} // namespace intel_gpu +} // namespace ov diff --git a/src/plugins/intel_gpu/src/plugin/ops/tensor_iterator.cpp b/src/plugins/intel_gpu/src/plugin/ops/tensor_iterator.cpp deleted file mode 100644 index 21c7d3a8167a91..00000000000000 --- a/src/plugins/intel_gpu/src/plugin/ops/tensor_iterator.cpp +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "intel_gpu/plugin/program_builder.hpp" -#include "intel_gpu/plugin/common_utils.hpp" -#include "intel_gpu/plugin/plugin.hpp" - -#include - -#include "openvino/op/tensor_iterator.hpp" -#include "openvino/op/constant.hpp" -#include "openvino/op/util/sub_graph_base.hpp" - -#include "intel_gpu/primitives/loop.hpp" -#include "intel_gpu/primitives/mutable_data.hpp" -#include "intel_gpu/primitives/data.hpp" -#include "intel_gpu/primitives/reorder.hpp" -#include "intel_gpu/graph/topology.hpp" - -#include -#include - -using TensorIterator = ov::op::v0::TensorIterator; - -namespace ov { -namespace intel_gpu { - -template -static DATA_TYPE CreateScalarData(ProgramBuilder &p, const cldnn::primitive_id& id, int64_t num) { - auto mem = p.get_engine().allocate_memory({ cldnn::data_types::i64, cldnn::format::bfyx, { 1, 1, 1, 1 } }); - cldnn::mem_lock ptr{mem, p.get_engine().get_service_stream()}; - *ptr.begin() = num; - return {id, mem}; -} - -static cldnn::mutable_data CreateAdditionalOutputData(ProgramBuilder &p, const std::shared_ptr& op, - const cldnn::primitive_id& id, const cldnn::primitive_id& input, - const int32_t output_idx) { - const auto precision = cldnn::element_type_to_data_type(op->get_output_element_type(output_idx)); - const auto format = cldnn::format::get_default_format(op->get_output_shape(output_idx).size()); - const auto tensor = tensor_from_dims(op->get_output_shape(output_idx)); - cldnn::layout output_layout = cldnn::layout(precision, format, tensor); - auto mem = p.get_engine().allocate_memory(output_layout); - auto md = cldnn::mutable_data(id, {cldnn::input_info(input)}, std::move(mem)); // cldnn::data cannot set dependency - return md; -} - -static void CreateTensorIteratorOp(ProgramBuilder &p, const std::shared_ptr &op) { - auto inputs = p.GetInputInfo(op); - - ProgramBuilder body_program(op->get_body(), p.get_engine(), p.get_config(), true); - auto body_topology = *body_program.get_topology(); - - // setup input_primitive_maps/ output_primitive_maps and back_edges - const auto& loop_input_descs = op->get_input_descriptions(); - const auto& loop_output_descs = op->get_output_descriptions(); - const auto& body_inputs = op->get_body()->get_parameters(); - const auto& body_outputs = op->get_body()->get_results(); - - std::vector input_primitive_maps; - std::vector output_primitive_maps; - std::vector back_edges; - std::map reordered_output_ids; - - // set input mapping & back edges - for (const auto& loop_input_desc : loop_input_descs) { - const cldnn::primitive_id& external_id = inputs.at(loop_input_desc->m_input_index).pid; - auto& body_input = body_inputs.at(loop_input_desc->m_body_parameter_index); - cldnn::primitive_id internal_id = layer_type_name_ID(body_input); - - // set input mapping - if (const auto& sliceInfo = - std::dynamic_pointer_cast(loop_input_desc)) { - // sliced input - input_primitive_maps.emplace_back(external_id, internal_id, sliceInfo->m_axis, - sliceInfo->m_start, sliceInfo->m_end, sliceInfo->m_stride); - } else { - // input without slicing - input_primitive_maps.emplace_back(external_id, internal_id); - } - - // set back edges - if (const auto& mergedInput = - std::dynamic_pointer_cast(loop_input_desc)) { - // backedge - const auto& to = body_inputs.at(mergedInput->m_body_parameter_index); - const auto& from = body_outputs.at(mergedInput->m_body_value_index); - - cldnn::primitive_id to_id = layer_type_name_ID(to); - cldnn::primitive_id from_id = layer_type_name_ID(from); - - // reset output data type because the data types of the outputs of the - // body topology are always FP32 regardless of element type - { - const auto from_prim = body_topology.at(from_id); - const auto to_cldnn_type = cldnn::element_type_to_data_type(to->get_element_type()); - from_prim->output_data_types = {to_cldnn_type}; - } - back_edges.emplace_back(from_id, to_id); - } - } - - // set trip count, initial execution condition, num iteration primitives - // they should be mutable_data to prevent from being optimized out - std::string layerName = layer_type_name_ID(op); - const cldnn::primitive_id trip_count_id = layerName + "_tripCount"; - const int64_t num_iterations = op->get_num_iterations(); - if (num_iterations < 0) { - throw std::runtime_error("tensor iterator's num_iteration cannot be negative"); - } - { - cldnn::data trip_count = CreateScalarData(p, trip_count_id, num_iterations); - p.add_primitive(*op, trip_count); - } - const cldnn::primitive_id execution_condition_id = layerName + "_initialExecutionCondition"; - { - cldnn::mutable_data execution_condition = CreateScalarData(p, execution_condition_id, 1); - p.add_primitive(*op, std::move(execution_condition)); - } - const cldnn::primitive_id num_iteration_id = layerName + "_numIteration"; - { - cldnn::mutable_data num_iteration = CreateScalarData(p, num_iteration_id, 0); - p.add_primitive(*op, num_iteration); - } - - // set output mapping - for (const auto& loop_output_desc : loop_output_descs) { - const uint64_t output_idx = loop_output_desc->m_output_index; - - // Add additional mutable_data for multiple outputs - // primitive ID should be . if output_idx > 0 - // otherwise primitive ID should be equals to TI primitive ID - const std::string layerNameWithIndex = layerName + ".out" + std::to_string(output_idx); - std::string external_id; - if (output_idx > 0) { - cldnn::mutable_data output_data = CreateAdditionalOutputData(p, op, layerNameWithIndex, layerName, output_idx); - p.add_primitive(*op, std::move(output_data)); - external_id = layerNameWithIndex; - } else { - p.primitive_ids[layerNameWithIndex] = layerName; - p.primitive_ids[layerName] = layerName; - external_id = layerName; - } - const auto& body_output = body_outputs.at(loop_output_desc->m_body_value_index); - cldnn::primitive_id internal_id = layer_type_name_ID(body_output); - - // update primitive_map - if (const auto& concatOutput = - std::dynamic_pointer_cast(loop_output_desc)) { - // output which requires concatenation - output_primitive_maps.emplace_back(external_id, internal_id, concatOutput->m_axis, - concatOutput->m_start, concatOutput->m_end, concatOutput->m_stride); - } - if (std::dynamic_pointer_cast(loop_output_desc)) { - // output which requires no concatenation - output_primitive_maps.emplace_back(external_id, internal_id); - } - } - - const cldnn::loop loopPrimitive( - layerName, /* layer name of this primitive (output id) */ - inputs, /* inputs of this layer */ - body_topology, /* body network */ - trip_count_id, /* trip_count data in outer network, always same as num_iterations in TI */ - execution_condition_id, /* initial_execution_condition data in outer network, always true in TI */ - num_iteration_id, /* actual number of iteration data in body network */ - input_primitive_maps, /* input mappings connecting outer network and inner network */ - output_primitive_maps, /* output mappings connecting outer network and inner network */ - back_edges, /* back edge mapping */ - num_iterations, /* max iteration, i.e. length of iteration axis */ - "", - ""); - - p.add_primitive(*op, loopPrimitive); -} - -REGISTER_FACTORY_IMPL(v0, TensorIterator); - -} // namespace intel_gpu -} // namespace ov diff --git a/src/plugins/intel_gpu/src/plugin/plugin.cpp b/src/plugins/intel_gpu/src/plugin/plugin.cpp index 55f4f5e7a42065..388269ddbb424d 100644 --- a/src/plugins/intel_gpu/src/plugin/plugin.cpp +++ b/src/plugins/intel_gpu/src/plugin/plugin.cpp @@ -593,6 +593,7 @@ std::vector Plugin::get_supported_properties() const { ov::PropertyName{ov::num_streams.name(), PropertyMutability::RW}, ov::PropertyName{ov::hint::num_requests.name(), PropertyMutability::RW}, ov::PropertyName{ov::hint::inference_precision.name(), PropertyMutability::RW}, + ov::PropertyName{ov::hint::enable_cpu_pinning.name(), PropertyMutability::RW}, ov::PropertyName{ov::device::id.name(), PropertyMutability::RW}, }; diff --git a/src/plugins/intel_gpu/src/plugin/program_builder.cpp b/src/plugins/intel_gpu/src/plugin/program_builder.cpp index 404818ce92ce8c..a97b7e87a9e4b3 100644 --- a/src/plugins/intel_gpu/src/plugin/program_builder.cpp +++ b/src/plugins/intel_gpu/src/plugin/program_builder.cpp @@ -158,7 +158,7 @@ std::shared_ptr ProgramBuilder::build(const std::vector - -namespace ov { -namespace intel_gpu { - -void* USMHostAllocator::allocate(const size_t bytes, const size_t /* alignment */) noexcept { - try { - ov::AnyMap params = { ov::intel_gpu::shared_mem_type(ov::intel_gpu::SharedMemType::USM_HOST_BUFFER) }; - _usm_host_tensor = _context->create_tensor(ov::element::u8, {bytes}, params); - if (auto casted = std::dynamic_pointer_cast(_usm_host_tensor._ptr)) { - return casted->get_original_memory()->get_internal_params().mem; - } - return nullptr; - } catch (std::exception&) { - return nullptr; - } -} - -bool USMHostAllocator::deallocate(void* /* handle */, const size_t /* bytes */, size_t /* alignment */) noexcept { - try { - _usm_host_tensor = {nullptr, nullptr}; - } catch (std::exception&) { } - return true; -} - -bool USMHostAllocator::is_equal(const USMHostAllocator& other) const { - return other._usm_host_tensor != nullptr && _usm_host_tensor != nullptr && other._usm_host_tensor._ptr == _usm_host_tensor._ptr; -} -} // namespace intel_gpu -} // namespace ov diff --git a/src/plugins/intel_gpu/src/plugin/remote_context.cpp b/src/plugins/intel_gpu/src/plugin/remote_context.cpp index 1b932226881db3..e4aefa00bb0f0f 100644 --- a/src/plugins/intel_gpu/src/plugin/remote_context.cpp +++ b/src/plugins/intel_gpu/src/plugin/remote_context.cpp @@ -6,7 +6,7 @@ #include "openvino/runtime/make_tensor.hpp" #include "intel_gpu/plugin/remote_context.hpp" #include "intel_gpu/plugin/remote_tensor.hpp" -#include "intel_gpu/plugin/remote_allocators.hpp" +#include "intel_gpu/plugin/usm_host_tensor.hpp" #include "intel_gpu/runtime/itt.hpp" #include "intel_gpu/runtime/device_query.hpp" #include @@ -111,8 +111,7 @@ std::shared_ptr RemoteContextImpl::get_this_shared_ptr() { ov::SoPtr RemoteContextImpl::create_host_tensor(const ov::element::Type type, const ov::Shape& shape) { if (m_engine->use_unified_shared_memory()) { - USMHostAllocator allocator(get_this_shared_ptr()); - return { ov::make_tensor(type, shape, allocator), nullptr }; + return { std::make_shared(get_this_shared_ptr(), type, shape), nullptr }; } else { return { ov::make_tensor(type, shape), nullptr }; } diff --git a/src/plugins/intel_gpu/src/plugin/remote_tensor.cpp b/src/plugins/intel_gpu/src/plugin/remote_tensor.cpp index cd164940027be7..cd1011ea153bfe 100644 --- a/src/plugins/intel_gpu/src/plugin/remote_tensor.cpp +++ b/src/plugins/intel_gpu/src/plugin/remote_tensor.cpp @@ -2,17 +2,29 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "intel_gpu/plugin/common_utils.hpp" #include "intel_gpu/plugin/remote_context.hpp" #include "intel_gpu/plugin/remote_tensor.hpp" -#include "intel_gpu/plugin/remote_allocators.hpp" #include "intel_gpu/plugin/plugin.hpp" #include "intel_gpu/runtime/itt.hpp" +#include "intel_gpu/runtime/memory_caps.hpp" #include namespace ov { namespace intel_gpu { +TensorType RemoteTensorImpl::allocation_type_to_tensor_type(cldnn::allocation_type t) { + switch (t) { + case cldnn::allocation_type::cl_mem: return TensorType::BT_BUF_INTERNAL; + case cldnn::allocation_type::usm_host: return TensorType::BT_USM_HOST_INTERNAL; + case cldnn::allocation_type::usm_device: return TensorType::BT_USM_DEVICE_INTERNAL; + default: return TensorType::BT_EMPTY; + } + + return TensorType::BT_EMPTY; +} + RemoteTensorImpl::RemoteTensorImpl(RemoteContextImpl::Ptr context, const ov::Shape& shape, const ov::element::Type& element_type, @@ -28,20 +40,8 @@ RemoteTensorImpl::RemoteTensorImpl(RemoteContextImpl::Ptr context, , m_mem(mem) , m_surf(surf) , m_plane(plane) { - if (supports_caching()) { - m_hash = cldnn::hash_combine(0, m_mem); - m_hash = cldnn::hash_combine(m_hash, m_surf); - m_hash = cldnn::hash_combine(m_hash, plane); - m_hash = cldnn::hash_combine(m_hash, m_shape.size()); - m_hash = cldnn::hash_combine(m_hash, element_type.hash()); - for (const auto& d : m_shape) { - m_hash = cldnn::hash_combine(m_hash, d); - } - } - - update_strides(); + update_hash(); allocate(); - init_properties(); } RemoteTensorImpl::~RemoteTensorImpl() { @@ -82,12 +82,15 @@ const AnyMap& RemoteTensorImpl::get_properties() const { m_shape = shape; if (ov::shape_size(shape) > m_memory_object->count()) { - OPENVINO_ASSERT(!is_shared(), "Cannot call setShape for Tensor created on top of preallocated memory if shape was increased."); + GPU_DEBUG_TRACE_DETAIL << "Remote realloc" << std::endl; + OPENVINO_ASSERT(!is_shared(), "Cannot call set_shape for Tensor created on top of preallocated memory if shape was increased."); if (!deallocate()) { - OPENVINO_THROW("Cannot deallocate tensor while an attempt to enlarge tensor area in setShape."); + OPENVINO_THROW("Cannot deallocate tensor while an attempt to enlarge tensor area in set_shape."); } allocate(); + } else { + update_strides(); } } @@ -108,23 +111,39 @@ void RemoteTensorImpl::allocate() { if (enable_caching) { m_memory_object = context->try_get_cached_memory(m_hash); - if (m_memory_object) + if (m_memory_object) { + update_properties(); + update_strides(); return; + } } auto& engine = context->get_engine(); + // Currently, clDeviceMemAllocINTEL returns memory address allocated to other input blob if the current blob is empty + // W/A for this issue: + // Allocate with non-empty shape and then reinterprete with original shape + auto shape_copy = m_shape; + for (auto &i : shape_copy) { + if (i == 0) + i = 1; + } + + m_layout.set_partial_shape(shape_copy); + + const bool reset = false; + switch (m_mem_type) { case TensorType::BT_BUF_INTERNAL: { - m_memory_object = engine.allocate_memory(m_layout, cldnn::allocation_type::cl_mem); + m_memory_object = engine.allocate_memory(m_layout, cldnn::allocation_type::cl_mem, reset); break; } case TensorType::BT_USM_HOST_INTERNAL: { - m_memory_object = engine.allocate_memory(m_layout, cldnn::allocation_type::usm_host); + m_memory_object = engine.allocate_memory(m_layout, cldnn::allocation_type::usm_host, reset); break; } case TensorType::BT_USM_DEVICE_INTERNAL: { - m_memory_object = engine.allocate_memory(m_layout, cldnn::allocation_type::usm_device); + m_memory_object = engine.allocate_memory(m_layout, cldnn::allocation_type::usm_device, reset); break; } case TensorType::BT_BUF_SHARED: { @@ -161,6 +180,9 @@ void RemoteTensorImpl::allocate() { m_memory_object.reset(); } + update_properties(); + update_strides(); + if (enable_caching) context->add_to_cache(m_hash, m_memory_object); } @@ -169,7 +191,7 @@ const std::string& RemoteTensorImpl::get_device_name() const { return m_context->get_device_name(); } -bool RemoteTensorImpl::is_shared() const { +bool RemoteTensorImpl::is_shared() const noexcept { return m_mem_type == TensorType::BT_BUF_SHARED || m_mem_type == TensorType::BT_USM_SHARED || m_mem_type == TensorType::BT_IMG_SHARED || @@ -181,6 +203,19 @@ bool RemoteTensorImpl::supports_caching() const { return is_shared(); } +void RemoteTensorImpl::update_hash() { + if (supports_caching()) { + m_hash = cldnn::hash_combine(0, m_mem); + m_hash = cldnn::hash_combine(m_hash, m_surf); + m_hash = cldnn::hash_combine(m_hash, m_plane); + m_hash = cldnn::hash_combine(m_hash, m_shape.size()); + m_hash = cldnn::hash_combine(m_hash, m_element_type.hash()); + for (const auto& d : m_shape) { + m_hash = cldnn::hash_combine(m_hash, d); + } + } +} + bool RemoteTensorImpl::is_surface() const noexcept { return m_mem_type == TensorType::BT_SURF_SHARED || m_mem_type == TensorType::BT_IMG_SHARED || @@ -196,11 +231,24 @@ cldnn::memory::ptr RemoteTensorImpl::get_original_memory() const { return m_memory_object; } +void RemoteTensorImpl::set_memory(cldnn::memory::ptr memory, size_t actual_size) { + auto engine = m_memory_object->get_engine(); + m_layout = memory->get_layout(); + m_shape = m_layout.get_shape(); + + auto actual_layout = m_layout; + actual_layout.set_partial_shape({ov::Dimension(actual_size)}); + m_memory_object = engine->reinterpret_buffer(*memory, actual_layout); + + update_properties(); + update_strides(); +} + std::shared_ptr RemoteTensorImpl::get_context() const { return m_context; } -void RemoteTensorImpl::init_properties() { +void RemoteTensorImpl::update_properties() { OPENVINO_ASSERT(is_allocated(), "[GPU] Can't initialize RemoteTensorImpl parameters as memory was not allocated"); auto params = m_memory_object->get_internal_params(); diff --git a/src/plugins/intel_gpu/src/plugin/sync_infer_request.cpp b/src/plugins/intel_gpu/src/plugin/sync_infer_request.cpp index 5e564f3b9a3ec5..9c097d222fdc1b 100644 --- a/src/plugins/intel_gpu/src/plugin/sync_infer_request.cpp +++ b/src/plugins/intel_gpu/src/plugin/sync_infer_request.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "intel_gpu/plugin/usm_host_tensor.hpp" #include "openvino/runtime/make_tensor.hpp" #include "openvino/core/preprocess/input_tensor_info.hpp" #include "openvino/core/parallel.hpp" @@ -10,7 +11,6 @@ #include "intel_gpu/plugin/sync_infer_request.hpp" #include "intel_gpu/plugin/remote_context.hpp" -#include "intel_gpu/plugin/remote_allocators.hpp" #include "intel_gpu/plugin/remote_tensor.hpp" #include "intel_gpu/plugin/compiled_model.hpp" #include "intel_gpu/plugin/variable_state.hpp" @@ -41,6 +41,15 @@ inline bool can_use_usm_host(const cldnn::engine& engine) { return can_use_usm; } +inline ov::Shape get_tensor_shape(const ov::PartialShape& pshape) { + ov::Shape res(pshape.size()); + for (size_t i = 0; i < pshape.size(); i++) { + res[i] = pshape[i].is_dynamic() ? 0 : pshape[i].get_length(); + } + + return res; +} + inline std::string get_port_name(const ov::Output& port, const bool is_legacy_api) { std::string name; // TODO: Should use tensor name as the port name, but many legacy tests still use legacy name @@ -72,7 +81,7 @@ void convert_and_copy(const void* src_ptr, ov::element::Type src_et, void* dst_p return; if (src_et == dst_et) { - std::memcpy(dst_ptr, src_ptr, size); + std::memcpy(dst_ptr, src_ptr, size * src_et.size()); return; } @@ -167,11 +176,10 @@ bool same_host_mem(cldnn::memory::cptr memory, const uint8_t* host_ptr) { } ov::Shape predict_shape(const std::string& name, const ov::Shape current_shape, ov::element::Type element_type, cldnn::ShapePredictor& shape_predictor) { - auto et_size = cldnn::ceil_div(element_type.bitwidth(), 8); - auto prealloc_info = shape_predictor.predict_preallocation_shape(name, current_shape, et_size, false); + auto prealloc_info = shape_predictor.predict_preallocation_shape(name, current_shape, element_type.bitwidth(), false); const auto& preallocation_shape = prealloc_info.second; auto can_preallocate_buffer = prealloc_info.first && - shape_predictor.can_preallocate(ov::shape_size(preallocation_shape) * et_size); + shape_predictor.can_preallocate(cldnn::ceil_div(ov::shape_size(preallocation_shape) * element_type.bitwidth(), 8)); if (can_preallocate_buffer) { return preallocation_shape; } @@ -270,10 +278,31 @@ void SyncInferRequest::set_tensor(const ov::Output& port, const bool is_input = ov::op::util::is_parameter(port.get_node()); + auto update_tensors_maps = [](const std::string& name, + std::unordered_map& user_tensors, + std::unordered_map& plugin_tensors, + const ov::SoPtr& tensor) { + auto current_tensor_owner = user_tensors[name].owner; + auto is_same_tensor = user_tensors[name].ptr == tensor._ptr; + + // Keep PLUGIN as a tensor owner if current user's tensor owner is PLUGIN and underlying tensor pointer is not changed + auto new_tensor_owner = current_tensor_owner == TensorOwner::PLUGIN && is_same_tensor ? TensorOwner::PLUGIN + : TensorOwner::USER; + + user_tensors[name] = { tensor._ptr, new_tensor_owner }; + + // We need to properly handle PLUGIN -> USER ownership change to prevent invalid PLUGIN's ush_host buffer sharing, + // so remove plugin's tensor to reallocate it in prepare_input() mehtod + if (current_tensor_owner == TensorOwner::PLUGIN && new_tensor_owner == TensorOwner::USER) { + if (plugin_tensors.count(name) && std::dynamic_pointer_cast(plugin_tensors[name].ptr)->is_shared()) + plugin_tensors.erase(plugin_tensors.find(name)); + } + }; + if (is_input) { - m_user_inputs[name] = { tensor._ptr, TensorOwner::USER }; + update_tensors_maps(name, m_user_inputs, m_plugin_inputs, tensor); } else { - m_user_outputs[name] = { tensor._ptr, TensorOwner::USER }; + update_tensors_maps(name, m_user_outputs, m_plugin_outputs, tensor); } ov::ISyncInferRequest::set_tensor(port, tensor); @@ -405,6 +434,7 @@ void SyncInferRequest::wait() { OV_ITT_SCOPED_TASK(itt::domains::intel_gpu_plugin, "SyncInferRequest::wait::reinterpret_memory"); OPENVINO_ASSERT(!output_memory->get_layout().data_padding, "[GPU] Unexpected padding in output buffer"); output_memory = m_graph->get_engine().reinterpret_buffer(*output_memory, output_layout); + GPU_DEBUG_TRACE_DETAIL << name << " model output: " << output_memory->buffer_ptr() << std::endl; } OPENVINO_ASSERT(m_user_outputs.count(name) > 0, "[GPU] Output ", name, " is not found in output tensors map"); @@ -413,6 +443,12 @@ void SyncInferRequest::wait() { auto remote_ptr = std::dynamic_pointer_cast(output_tensor); bool is_remote = remote_ptr != nullptr; + if (is_remote) { + GPU_DEBUG_TRACE_DETAIL << name << " handle output tensor (remote): " << remote_ptr->get_original_memory()->buffer_ptr() << std::endl; + } else { + GPU_DEBUG_TRACE_DETAIL << name << " handle output tensor (host): " << output_tensor->data() << std::endl; + } + bool need_output_update = output_layout.bytes_count() == 0 || (output_memory && output_tensor->get_byte_size() != output_memory->size()); if (need_output_update) { OV_ITT_SCOPED_TASK(itt::domains::intel_gpu_plugin, "SyncInferRequest::wait::update_output"); @@ -424,6 +460,19 @@ void SyncInferRequest::wait() { OPENVINO_ASSERT(ov::shape_size(port.get_shape()) == ov::shape_size(mem_shape), "[GPU] Unexpected elements count for output tensor"); mem_shape = port.get_shape(); } + if (port.get_partial_shape().is_dynamic()) { + bool need_reallocate = true; + auto usm_host_tensor = std::dynamic_pointer_cast(output_tensor); + if (usm_host_tensor && output_memory) + need_reallocate = usm_host_tensor->get_impl()->get_original_memory()->size() < output_memory->size(); + + if (need_reallocate) { + auto& shape_predictor = m_graph->get_network()->get_shape_predictor(); + auto actual_memory_shape = predict_shape(name, mem_shape, output_tensor->get_element_type(), shape_predictor); + output_tensor->set_shape(actual_memory_shape); + } + } + output_tensor->set_shape(mem_shape); } @@ -433,6 +482,8 @@ void SyncInferRequest::wait() { auto dst_ptr = static_cast(output_tensor->data()); bool same_mem = same_host_mem(output_memory, dst_ptr); if (!same_mem && output_memory->size()) { + GPU_DEBUG_TRACE_DETAIL << name << " copy from: " << output_memory->buffer_ptr() << " to " + << (!is_remote ? output_tensor->data() : remote_ptr->get_original_memory()->buffer_ptr()) << std::endl; if (auto ev = copy_output_data(output_memory, *output_tensor)) { copy_events.push_back(ev); } @@ -472,22 +523,13 @@ void SyncInferRequest::setup_stream_graph() { std::shared_ptr SyncInferRequest::create_host_tensor(const ov::PartialShape& port_shape, const ov::element::Type& port_element_type) const { OV_ITT_SCOPED_TASK(itt::domains::intel_gpu_plugin, "SyncInferRequest::create_host_tensor"); - // Disable USM usage as USMHostAllocator may fail for attempt to allocate 0 bytes - // If we add WA for such case to avoid driver call, then deallocate method will return false and Blob::setShape call will throw an exception - bool use_usm = m_graph->get_engine().use_unified_shared_memory() && !port_shape.is_dynamic(); - - auto shape = port_shape.is_static() ? port_shape.to_shape() : ov::Shape(port_shape.size(), 0); - auto usm_allocator = USMHostAllocator(m_context); - return use_usm ? ov::make_tensor(port_element_type, shape, usm_allocator) - : ov::make_tensor(port_element_type, shape); + return m_context->create_host_tensor(port_element_type, get_tensor_shape(port_shape))._ptr; } -std::shared_ptr SyncInferRequest::create_device_tensor(const ov::Shape& shape, ov::element::Type element_type, - bool need_lockable_memory, void* mem_ptr) const { +std::shared_ptr SyncInferRequest::create_device_tensor(const ov::PartialShape& port_shape, ov::element::Type element_type, + bool need_lockable_memory) const { TensorType tensor_type = TensorType::BT_EMPTY; - if (mem_ptr) { - tensor_type = TensorType::BT_USM_SHARED; - } else if (m_graph->get_engine().use_unified_shared_memory()) { + if (m_graph->get_engine().use_unified_shared_memory()) { tensor_type = need_lockable_memory ? TensorType::BT_USM_HOST_INTERNAL : TensorType::BT_USM_DEVICE_INTERNAL; } else { tensor_type = TensorType::BT_BUF_INTERNAL; @@ -497,24 +539,10 @@ std::shared_ptr SyncInferRequest::create_device_tensor(const ov::Sh if (!can_use_usm_host(m_graph->get_engine()) && need_lockable_memory) tensor_type = TensorType::BT_BUF_INTERNAL; - // Currently, clDeviceMemAllocINTEL returns memory address allocated to other input blob if the current blob is empty - // W/A for this issue: - // Allocate with non-empty shape and then reinterprete with original shape - auto shape_copy = shape; - for (auto &i : shape_copy) { - if (i == 0) - i = 1; - } - return std::make_shared(m_context, - shape_copy, + get_tensor_shape(port_shape), element_type, - tensor_type, - mem_ptr); -} - -std::shared_ptr SyncInferRequest::create_shared_device_tensor(const ov::Shape& shape, ov::element::Type element_type, void* usm_host_mem) const { - return create_device_tensor(shape, element_type, false, usm_host_mem); + tensor_type); } TensorWrapper SyncInferRequest::create_or_share_device_tensor(const TensorWrapper& user_tensor_wrapper, @@ -526,17 +554,12 @@ TensorWrapper SyncInferRequest::create_or_share_device_tensor(const TensorWrappe auto tensor_shape = user_tensor->get_shape(); bool is_dynamic = port_pshape.is_dynamic(); OPENVINO_ASSERT(std::dynamic_pointer_cast(user_tensor) == nullptr, "[GPU] Unexpected remote tensor"); - auto input_ptr = user_tensor->data(); - const auto alloc_type = m_graph->get_engine().detect_usm_allocation_type(input_ptr); - const auto is_usm_host = alloc_type == cldnn::allocation_type::usm_host; - bool can_share = is_usm_host && - !is_convert_required(user_tensor->get_element_type(), element_type) && + auto usm_host_tensor = std::dynamic_pointer_cast(user_tensor); + bool can_share = usm_host_tensor != nullptr && !is_convert_required(user_tensor->get_element_type(), element_type) && can_use_usm_host(m_graph->get_engine()); if (can_share) { - // For USM case we create host blob using custom USM host allocator - // and then create shared device blob on top of this buffer - return { create_shared_device_tensor(tensor_shape, element_type, input_ptr), user_tensor_wrapper.owner }; + return { usm_host_tensor->get_impl(), user_tensor_wrapper.owner }; } auto actual_memory_shape = tensor_shape; @@ -669,13 +692,17 @@ std::vector SyncInferRequest::prepare_batched_input(const std std::vector SyncInferRequest::prepare_input(const std::string& name, const ov::Output& port, const TensorWrapper& user_tensor_wrapper) { - OV_ITT_SCOPED_TASK(itt::domains::intel_gpu_plugin, "SyncInferRequest::prepare_input"); + OV_ITT_SCOPED_TASK(itt::domains::intel_gpu_plugin, openvino::itt::handle("SyncInferRequest::prepare_input: " + name)); auto pshape = port.get_partial_shape(); auto is_dynamic = pshape.is_dynamic(); auto user_tensor = user_tensor_wrapper.ptr; auto element_type = user_tensor->get_element_type(); + auto remote_ptr = std::dynamic_pointer_cast(user_tensor); + auto usm_host_ptr = std::dynamic_pointer_cast(user_tensor); bool is_remote = remote_ptr != nullptr; + bool is_usm_host_tensor = usm_host_ptr != nullptr; + GPU_DEBUG_TRACE_DETAIL << "Prepare input for " << name << " ( is_remote ? " << is_remote << ")" << std::endl; GPU_DEBUG_TRACE_DETAIL << " port shape : " << pshape.to_string() << std::endl; GPU_DEBUG_TRACE_DETAIL << " user_tensor shape: " << user_tensor->get_shape().to_string() << std::endl; @@ -693,12 +720,16 @@ std::vector SyncInferRequest::prepare_input(const std::string user_tensor->get_shape(), ") are incompatible"); + auto device_tensor_et = convert_to_supported_device_type(element_type); + bool convert_needed = is_convert_required(element_type, device_tensor_et); + if (is_remote) { m_plugin_inputs[name] = user_tensor_wrapper; + } else if (is_usm_host_tensor && !convert_needed) { + m_plugin_inputs[name] = {usm_host_ptr->get_impl(), user_tensor_wrapper.owner}; + is_remote = true; } - auto device_tensor_et = convert_to_supported_device_type(element_type); - bool convert_needed = is_convert_required(element_type, device_tensor_et); bool update_device_tensor = m_plugin_inputs.count(name) == 0 || (m_plugin_inputs[name].owner == TensorOwner::USER && !is_remote); if (update_device_tensor) { @@ -760,6 +791,7 @@ std::vector SyncInferRequest::prepare_input(const std::string } } + GPU_DEBUG_TRACE_DETAIL << name << " prepare input: " << memory->buffer_ptr() << std::endl; const cldnn::primitive_id internal_name = "parameter:" + name; network->set_input_data(internal_name, memory); @@ -819,6 +851,7 @@ std::vector SyncInferRequest::prepare_output(const std::strin auto output_tensor = std::dynamic_pointer_cast(m_plugin_outputs.at(name).ptr); auto output_memory = output_tensor->get_memory(); + GPU_DEBUG_TRACE_DETAIL << name << " prepare output: " << output_memory->buffer_ptr() << std::endl; return network->set_output_memory(internal_name, output_memory); } diff --git a/src/plugins/intel_gpu/src/plugin/transformations/convert_fc_to_compressed.cpp b/src/plugins/intel_gpu/src/plugin/transformations/convert_fc_to_compressed.cpp index a1c4d60b81977c..0ff0e1fd0bf258 100644 --- a/src/plugins/intel_gpu/src/plugin/transformations/convert_fc_to_compressed.cpp +++ b/src/plugins/intel_gpu/src/plugin/transformations/convert_fc_to_compressed.cpp @@ -3,16 +3,19 @@ // #include "convert_fc_to_compressed.hpp" +#include #include "intel_gpu/op/fully_connected.hpp" #include "intel_gpu/op/fully_connected_compressed.hpp" +#include "openvino/op/constant.hpp" #include "openvino/op/subtract.hpp" #include "openvino/op/matmul.hpp" #include "openvino/op/convert.hpp" #include "openvino/op/transpose.hpp" #include "openvino/op/reshape.hpp" #include "openvino/core/rt_info.hpp" +#include "openvino/pass/pattern/op/pattern.hpp" #include "openvino/pass/pattern/op/wrap_type.hpp" #include "openvino/pass/pattern/op/or.hpp" #include "transformations/utils/utils.hpp" @@ -23,7 +26,19 @@ namespace intel_gpu { ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyConnectedCompressed() { using namespace ov::pass::pattern; - auto weights_m = wrap_type(consumers_count(1)); + auto compressed_constant = [](const ov::Output& output) { + return (output.get_element_type() == ov::element::u8 || + output.get_element_type() == ov::element::i8) && + output.get_target_inputs().size() == 1; + }; + + auto reshape_3d_to_2d = [](const ov::Output& output) { + auto in_ps = output.get_node()->get_input_partial_shape(0); + auto out_ps = output.get_node()->get_output_partial_shape(0); + return in_ps.rank().is_static() && out_ps.rank().is_static() && in_ps.size() == 3 && out_ps.size() == 2; + }; + + auto weights_m = wrap_type(compressed_constant); auto convert_m = wrap_type({weights_m}); auto sub_const_m = wrap_type(consumers_count(1)); @@ -34,11 +49,15 @@ ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyCon auto mul_no_sub_m = wrap_type({convert_m, mul_const_m}); auto mul_m = std::make_shared(OutputVector{mul_with_sub_m, mul_no_sub_m}); + auto reshape_const_m = wrap_type(); + auto reshape_m = wrap_type({mul_m, reshape_const_m}, reshape_3d_to_2d); + + auto transpose_input = std::make_shared(OutputVector{reshape_m, mul_m}); auto transpose_const_m = wrap_type(); - auto transpose_m = wrap_type({mul_m, transpose_const_m}); - auto weights_input_m = std::make_shared(ov::OutputVector{mul_m, transpose_m}); + auto transpose_m = wrap_type({transpose_input, transpose_const_m}); auto data_m = any_input(); + auto weights_input_m = std::make_shared(ov::OutputVector{reshape_m, transpose_m, mul_m}); auto fully_connected_m = wrap_type({data_m, weights_input_m}); ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) { @@ -52,53 +71,73 @@ ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyCon return false; } + bool has_transpose = pattern_map.count(transpose_m); + auto scale_shape = pattern_map.at(mul_const_m).get_shape(); + bool grouped = std::count_if(scale_shape.begin(), scale_shape.end(), [](size_t d) { return d > 1; }) > 1; + + auto reshape_const_to_2d = [has_transpose, grouped](std::shared_ptr node) { + auto constant = std::dynamic_pointer_cast(node); + OPENVINO_ASSERT(constant != nullptr); + ov::Shape current_shape = constant->get_shape(); + if (current_shape.size() == 2) + return constant; + OPENVINO_ASSERT(current_shape.size() == 3); + + auto new_shape = (has_transpose || !grouped) ? ov::Shape{current_shape[0] * current_shape[1], current_shape[2]} + : ov::Shape{current_shape[0], current_shape[1] * current_shape[2]}; + + return std::make_shared(*constant, new_shape); + }; + const auto& fc_input_a = fc->get_input_node_shared_ptr(0); - const auto& scale = pattern_map.at(mul_const_m).get_node_shared_ptr(); + const auto& scale = reshape_const_to_2d(pattern_map.at(mul_const_m).get_node_shared_ptr()); std::shared_ptr optional_zero_point = nullptr; - ov::NodeVector nodes_to_copy_info{pattern_map.at(fully_connected_m).get_node_shared_ptr(), - pattern_map.at(convert_m).get_node_shared_ptr()}; - if (pattern_map.count(mul_no_sub_m)) { - nodes_to_copy_info.push_back(pattern_map.at(mul_no_sub_m).get_node_shared_ptr()); - } - if (pattern_map.count(mul_with_sub_m)) { - nodes_to_copy_info.push_back(pattern_map.at(mul_with_sub_m).get_node_shared_ptr()); - } - const bool with_zero_point = pattern_map.count(subtract_m) > 0; if (with_zero_point) { - optional_zero_point = pattern_map.at(sub_const_m).get_node_shared_ptr(); - nodes_to_copy_info.push_back(subtract_m); + optional_zero_point = reshape_const_to_2d(pattern_map.at(sub_const_m).get_node_shared_ptr()); } - std::shared_ptr fc_input_b = pattern_map.at(weights_m).get_node_shared_ptr(); - if (pattern_map.count(transpose_m)) { + std::shared_ptr fc_input_b = reshape_const_to_2d(pattern_map.at(weights_m).get_node_shared_ptr()); + std::shared_ptr fc_input_scale = scale; + std::shared_ptr fc_input_zp = optional_zero_point; + if (has_transpose) { const auto& transpose = pattern_map.at(transpose_m).get_node_shared_ptr(); - const auto& transpose_const = pattern_map.at(transpose_const_m).get_node_shared_ptr(); + std::shared_ptr transpose_const = pattern_map.at(transpose_const_m).get_node_shared_ptr(); + if (ov::shape_size(transpose_const->get_shape()) != fc_input_b->get_output_partial_shape(0).size()) { + std::vector new_order(fc_input_b->get_output_partial_shape(0).size()); + std::iota(new_order.begin(), new_order.end(), 0); + std::swap(new_order[new_order.size() - 1], new_order[new_order.size() - 2]); + transpose_const = std::make_shared(ov::element::i32, ov::Shape{new_order.size()}, new_order); + } + fc_input_b = transpose->clone_with_new_inputs({ fc_input_b->output(0), transpose_const }); + fc_input_scale = transpose->clone_with_new_inputs({ scale->output(0), transpose_const }); + if (with_zero_point) + fc_input_zp = transpose->clone_with_new_inputs({ optional_zero_point->output(0), transpose_const }); } std::shared_ptr new_fc = nullptr; if (with_zero_point) { new_fc = std::make_shared(fc_input_a, fc_input_b, - scale, - optional_zero_point, + fc_input_scale, + fc_input_zp, fc->get_output_type()); } else { new_fc = std::make_shared(fc_input_a, fc_input_b, - scale, + fc_input_scale, fc->get_output_type()); } new_fc->set_friendly_name(fc->get_friendly_name()); - ov::copy_runtime_info(nodes_to_copy_info, new_fc); + ov::copy_runtime_info(m.get_matched_nodes(), new_fc); ov::replace_node(fc, new_fc); return true; }; - auto m = std::make_shared(fully_connected_m); + auto m = std::make_shared(fully_connected_m, "ConvertFullyConnectedToFullyConnectedCompressed"); this->register_matcher(m, callback); } diff --git a/src/plugins/intel_gpu/src/plugin/transformations/convert_matmul_to_fc.cpp b/src/plugins/intel_gpu/src/plugin/transformations/convert_matmul_to_fc.cpp index a30c88e7d1492d..2caf3cd4d69850 100644 --- a/src/plugins/intel_gpu/src/plugin/transformations/convert_matmul_to_fc.cpp +++ b/src/plugins/intel_gpu/src/plugin/transformations/convert_matmul_to_fc.cpp @@ -160,7 +160,7 @@ ConvertMatMulToFullyConnected::ConvertMatMulToFullyConnected() { return true; }; - auto m = std::make_shared(matmul_m); + auto m = std::make_shared(matmul_m, "ConvertMatMulToFullyConnected"); this->register_matcher(m, callback); } diff --git a/src/plugins/intel_gpu/src/plugin/transformations/op/rms.cpp b/src/plugins/intel_gpu/src/plugin/transformations/op/rms.cpp new file mode 100644 index 00000000000000..5dcd12071d1712 --- /dev/null +++ b/src/plugins/intel_gpu/src/plugin/transformations/op/rms.cpp @@ -0,0 +1,39 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "intel_gpu/op/rms.hpp" + +namespace ov { +namespace intel_gpu { +namespace op { + +RMS::RMS(const Output& data, + const Output& gamma, + double epsilson, + const ov::element::Type output_type) + : Op({data, gamma}), m_epsilon(epsilson), m_output_type(output_type) { + validate_and_infer_types(); +} + +bool RMS::visit_attributes(ov::AttributeVisitor& visitor) { + visitor.on_attribute("epsilon", m_epsilon); + visitor.on_attribute("output_type", m_output_type); + return true; +} + +void RMS::validate_and_infer_types() { + auto output_type = m_output_type == ov::element::undefined ? get_input_element_type(0) : m_output_type; + set_output_type(0, output_type, get_input_partial_shape(0)); +} + +std::shared_ptr RMS::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), + m_epsilon); +} + +} // namespace op +} // namespace intel_gpu +} // namespace ov diff --git a/src/plugins/intel_gpu/src/plugin/transformations/rms_fusion.cpp b/src/plugins/intel_gpu/src/plugin/transformations/rms_fusion.cpp new file mode 100644 index 00000000000000..bcd192454f3d3a --- /dev/null +++ b/src/plugins/intel_gpu/src/plugin/transformations/rms_fusion.cpp @@ -0,0 +1,103 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "rms_fusion.hpp" + +#include "intel_gpu/op/rms.hpp" + +#include "openvino/core/rt_info.hpp" +#include "openvino/op/add.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/divide.hpp" +#include "openvino/op/multiply.hpp" +#include "openvino/op/power.hpp" +#include "openvino/op/reduce_mean.hpp" +#include "openvino/op/sqrt.hpp" +#include "openvino/pass/pattern/op/wrap_type.hpp" +#include "transformations/utils/utils.hpp" + +namespace ov { +namespace intel_gpu { + +static std::function)> constant_value(const float target_value) { + return [=](const ov::Output& output) -> bool { + 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 == target_value; + }; +} + +RMSFusion::RMSFusion() { + using namespace ov::pass::pattern; + + // Detect RMS decomposition pattern + // x * 1/Sqrt(ReduceMean(x^2,axes)+eps) * gamma + auto x = any_input(); + + // x^2 + auto const_power = wrap_type(constant_value(2)); + auto power = wrap_type({x, const_power}); + + // ReduceMean(x^2,axes) + auto mean_axes = wrap_type(constant_value(-1)); + auto mean = wrap_type({power, mean_axes}); + + // ReduceMean(x^2,axes)+eps + auto eps = wrap_type(); + auto add_eps = wrap_type({mean, eps}); + + // Sqrt(ReduceMean(x^2,axes)+eps) + auto sqrt = wrap_type({add_eps}); + + // 1/Sqrt(ReduceMean(x^2,axes)+eps) + auto const_div = wrap_type(constant_value(-1)); + auto div = wrap_type({sqrt, const_div}); + + // x * 1/Sqrt(ReduceMean(x^2,axes)+eps) + auto mul1 = wrap_type({x, div}); + + // x * 1/Sqrt(ReduceMean(x^2,axes)+eps) * gamma + auto gamma = wrap_type(type_matches(element::f32)); + auto mul2 = wrap_type({gamma, mul1}); + + // compress RMS result + auto comp = wrap_type({mul2}); + + ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) { + const auto& pattern_map = m.get_pattern_value_map(); + auto x_output = pattern_map.at(x); + + auto const_eps_node = + std::dynamic_pointer_cast(pattern_map.at(eps).get_node_shared_ptr()); + float eps_value; + if (!ov::op::util::get_single_value(const_eps_node, eps_value)) { + return false; + } + + const auto& gamma_node = pattern_map.at(gamma).get_node_shared_ptr(); + auto output_type = m.get_match_root()->get_output_element_type(0); + + auto rms = std::make_shared(x_output, + gamma_node, + eps_value, + output_type); + rms->set_friendly_name(m.get_match_root()->get_friendly_name()); + ov::copy_runtime_info(m.get_matched_nodes(), rms); + ov::replace_node(m.get_match_root(), rms); + + return true; + }; + + auto m = std::make_shared(comp, "RMSFusion"); + this->register_matcher(m, callback); +} + +} // namespace intel_gpu +} // namespace ov diff --git a/src/plugins/intel_gpu/src/plugin/transformations/rms_fusion.hpp b/src/plugins/intel_gpu/src/plugin/transformations/rms_fusion.hpp new file mode 100644 index 00000000000000..66f236f3f26c38 --- /dev/null +++ b/src/plugins/intel_gpu/src/plugin/transformations/rms_fusion.hpp @@ -0,0 +1,19 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/pass/graph_rewrite.hpp" + +namespace ov { +namespace intel_gpu { + +class RMSFusion : public ov::pass::MatcherPass { +public: + OPENVINO_RTTI("RMSFusion", "0"); + RMSFusion(); +}; + +} // namespace intel_gpu +} // namespace ov diff --git a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp index 14122656fc5145..dfc24774fcd26b 100644 --- a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp +++ b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp @@ -102,6 +102,7 @@ #include "transformations/op_conversions/convert_prior_box_v8_to_v0.hpp" #include "transformations/op_conversions/convert_shapeof3.hpp" #include "transformations/op_conversions/convert_topk11_downgrade.hpp" +#include "transformations/op_conversions/group_normalization_decomposition.hpp" #include "transformations/op_conversions/eye_decomposition.hpp" #include "transformations/op_conversions/convert_pad12_downgrade.hpp" #include "transformations/convert_precision.hpp" @@ -112,6 +113,7 @@ #include "plugin/transformations/convert_matmul_to_fc.hpp" #include "plugin/transformations/move_fc_reshape_to_weights.hpp" #include "plugin/transformations/convert_fc_to_compressed.hpp" +#include "plugin/transformations/rms_fusion.hpp" #include "transformations/low_precision/mark_dequantization_subgraph.hpp" #include "low_precision/pull_reshape_through_dequantization.hpp" @@ -488,6 +490,7 @@ void TransformationsPipeline::apply(std::shared_ptr func) { pass_config->disable(); pass_config->disable(); pass_config->disable(); + pass_config->disable(); pass_config->enable(); @@ -640,6 +643,7 @@ void TransformationsPipeline::apply(std::shared_ptr func) { manager.register_pass(); manager.register_pass(); manager.register_pass(); + manager.register_pass(); manager.run_passes(func); } diff --git a/src/plugins/intel_gpu/src/plugin/usm_host_tensor.cpp b/src/plugins/intel_gpu/src/plugin/usm_host_tensor.cpp new file mode 100644 index 00000000000000..bcb0877b521f20 --- /dev/null +++ b/src/plugins/intel_gpu/src/plugin/usm_host_tensor.cpp @@ -0,0 +1,50 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "intel_gpu/plugin/usm_host_tensor.hpp" +#include "intel_gpu/plugin/remote_tensor.hpp" +#include "intel_gpu/plugin/remote_context.hpp" +#include "openvino/runtime/make_tensor.hpp" +#include + +namespace ov { +namespace intel_gpu { + +USMHostTensor::USMHostTensor(std::shared_ptr context, const element::Type element_type, const Shape& shape) + : m_impl(std::make_shared(context, shape, element_type, TensorType::BT_USM_HOST_INTERNAL)) {} + +USMHostTensor::USMHostTensor(std::shared_ptr tensor) + : m_impl(tensor) {} + +void* USMHostTensor::data(const element::Type& element_type) const { + return m_impl->get_original_memory()->buffer_ptr(); +} + +const element::Type& USMHostTensor::get_element_type() const { + return m_impl->get_element_type(); +} + +const Shape& USMHostTensor::get_shape() const { + return m_impl->get_shape(); +} + +const Strides& USMHostTensor::get_strides() const { + return m_impl->get_strides(); +} + +void USMHostTensor::set_shape(ov::Shape new_shape) { + m_impl->set_shape(new_shape); +} + +void USMHostTensor::set_memory(std::shared_ptr tensor) { + OPENVINO_ASSERT(tensor->get_original_memory()->get_allocation_type() == cldnn::allocation_type::usm_host, "[GPU] Unexpected allocation type"); + m_impl = tensor; +} + +std::shared_ptr USMHostTensor::get_impl() const { + return m_impl; +} + +} // namespace intel_gpu +} // namespace ov diff --git a/src/plugins/intel_gpu/src/runtime/execution_config.cpp b/src/plugins/intel_gpu/src/runtime/execution_config.cpp index e1375ef14ddb47..8bcb853a4c3090 100644 --- a/src/plugins/intel_gpu/src/runtime/execution_config.cpp +++ b/src/plugins/intel_gpu/src/runtime/execution_config.cpp @@ -48,6 +48,7 @@ void ExecutionConfig::set_default() { std::make_tuple(ov::hint::performance_mode, ov::hint::PerformanceMode::LATENCY, PerformanceModeValidator()), std::make_tuple(ov::hint::execution_mode, ov::hint::ExecutionMode::PERFORMANCE), std::make_tuple(ov::hint::num_requests, 0), + std::make_tuple(ov::hint::enable_cpu_pinning, false), std::make_tuple(ov::intel_gpu::hint::host_task_priority, ov::hint::Priority::MEDIUM), std::make_tuple(ov::intel_gpu::hint::queue_throttle, ov::intel_gpu::hint::ThrottleLevel::MEDIUM), @@ -86,7 +87,7 @@ void ExecutionConfig::set_property(const AnyMap& config) { for (auto& kv : config) { auto& name = kv.first; auto& val = kv.second; - OPENVINO_ASSERT(is_supported(kv.first), "[GPU] Attepmpt to set property ", name, " (", val.as(), ") which was not registered!\n"); + OPENVINO_ASSERT(is_supported(kv.first), "[GPU] Attempt to set property ", name, " (", val.as(), ") which was not registered!\n"); OPENVINO_ASSERT(property_validators.at(name)->is_valid(val), "[GPU] Invalid value for property ", name, ": ", val.as()); internal_properties[name] = val; } @@ -108,7 +109,7 @@ void ExecutionConfig::set_user_property(const AnyMap& config) { auto& name = kv.first; auto& val = kv.second; bool supported = is_supported(name) && supported_properties.at(name) == PropertyVisibility::PUBLIC; - OPENVINO_ASSERT(supported, "[GPU] Attepmpt to set user property ", name, " (", val.as(), ") which was not registered or internal!\n"); + OPENVINO_ASSERT(supported, "[GPU] Attempt to set user property ", name, " (", val.as(), ") which was not registered or internal!\n"); OPENVINO_ASSERT(property_validators.at(name)->is_valid(val), "[GPU] Invalid value for property ", name, ": `", val.as(), "`"); user_properties[kv.first] = kv.second; diff --git a/src/plugins/intel_gpu/src/runtime/format.cpp b/src/plugins/intel_gpu/src/runtime/format.cpp index af268e94daae76..095bda14bbf97d 100644 --- a/src/plugins/intel_gpu/src/runtime/format.cpp +++ b/src/plugins/intel_gpu/src/runtime/format.cpp @@ -31,10 +31,12 @@ static const std::map format_traits_map { FMT_TRAITS(bxfy, 1, 1, 2, 0, {0, 3, 1, 2}, "bxfy", "bfxy", {}), FMT_TRAITS(b_fs_yx_fsv2, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy", {{1, 2}}), FMT_TRAITS(b_fs_yx_fsv4, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy", {{1, 4}}), + FMT_TRAITS(b_fs_yx_fsv8, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy", {{1, 8}}), FMT_TRAITS(b_fs_yx_fsv16, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy", {{1, 16}}), FMT_TRAITS(b_fs_yx_fsv32, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy", {{1, 32}}), FMT_TRAITS(b_fs_zyx_fsv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{1, 2}}), FMT_TRAITS(b_fs_zyx_fsv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{1, 4}}), + FMT_TRAITS(b_fs_zyx_fsv8, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{1, 8}}), FMT_TRAITS(b_fs_zyx_fsv32, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{1, 32}}), FMT_TRAITS(bs_fs_fsv8_bsv8, 1, 1, 0, 0, {0, 1}, "bf", "bf", {{0, 8}, {1, 8}}), FMT_TRAITS(bs_fs_fsv8_bsv16, 1, 1, 0, 0, {0, 1}, "bf", "bf", {{0, 16}, {1, 8}}), @@ -55,6 +57,8 @@ static const std::map format_traits_map { FMT_TRAITS(bs_fs_yx_bsv4_fsv4, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy", {{0, 4 }, {1, 4}}), FMT_TRAITS(bs_fs_yx_bsv8_fsv4, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy", {{0, 8 }, {1, 4}}), FMT_TRAITS(bs_fs_zyx_bsv8_fsv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 8 }, {1, 4}}), + FMT_TRAITS(bs_fs_yx_bsv16_fsv8, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy", {{0, 16 }, {1, 8}}), + FMT_TRAITS(bs_fs_zyx_bsv16_fsv8, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 16 }, {1, 8}}), FMT_TRAITS(bs_fs_yx_bsv16_fsv4, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy", {{0, 16 }, {1, 4}}), FMT_TRAITS(bs_fs_zyx_bsv16_fsv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 16 }, {1, 4}}), FMT_TRAITS(bs_fs_yx_bsv16_fsv2, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy", {{0, 16 }, {1, 2}}), @@ -81,7 +85,10 @@ static const std::map format_traits_map { FMT_TRAITS(oizyx, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {}), FMT_TRAITS(iozyx, 1, 1, 3, 0, {1, 0, 2, 3, 4}, "iozyx", "oixyz", {}), FMT_TRAITS(os_is_yx_isv16_osv16, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 16}, {0, 16}}), + FMT_TRAITS(o_is_yx_isv2, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 2}}), + FMT_TRAITS(o_is_yx_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 4}}), FMT_TRAITS(o_is_yx_isv16, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 16}}), + FMT_TRAITS(o_is_zyx_isv16, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{1, 16}}), FMT_TRAITS(os_yxi_osv16, 1, 1, 2, 0, {0, 2, 3, 1}, "oyxi", "oixy", {{0, 16}}), FMT_TRAITS(os_iyx_osv16, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 16}}), FMT_TRAITS(os_iyx_osv32, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 32}}), @@ -114,6 +121,8 @@ static const std::map format_traits_map { FMT_TRAITS(is_o32_yx_isv32_swizzled_by_4, 1, 1, 2, 0, {0, 1, 2, 3}, "oyxi", "oixy", {{0, 32}, {1, 32}}), FMT_TRAITS(os_is_y_x8_osv8_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oyxi", "oixy", {{0, 8}, {1, 4}, {2, 8}}), FMT_TRAITS(os_is_y_x8_osv8_isv4_swizzled_by_4, 1, 1, 2, 0, {0, 1, 2, 3}, "oyxi", "oixy", {{0, 8}, {1, 4}, {2, 8}}), + FMT_TRAITS(os_is_yx_osv2_isv16, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 2}, {1, 16}}), + FMT_TRAITS(os_is_yx_osv4_isv16, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 4}, {1, 16}}), FMT_TRAITS(os_is_yx_osv16_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 16}, {1, 4}}), FMT_TRAITS(os_is_yx_osv8_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 8}, {1, 4}}), FMT_TRAITS(os_is_zyx_osv8_isv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 8}, {1, 4}}), @@ -126,6 +135,7 @@ static const std::map format_traits_map { FMT_TRAITS(os_is_yx_osv32_isv32p, 1, 1, 1, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 32}, {1, 32}}), FMT_TRAITS(os_is_zyx_isv16_osv16, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{1, 16}, {0, 16}}), FMT_TRAITS(is_os_zyx_isv16_osv16, 1, 1, 3, 0, {1, 0, 2, 3, 4}, "iozyx", "oixyz", {{1, 16}, {0, 16}}), + FMT_TRAITS(is_os_yx_osv8_isv4, 1, 1, 2, 0, {1, 0, 2, 3}, "ioyx", "oixy", {{0, 8}, {1, 4}}), FMT_TRAITS(is_os_yx_isv16_osv16, 1, 1, 2, 0, {1, 0, 2, 3}, "ioyx", "oixy", {{1, 16}, {0, 16}}), FMT_TRAITS(is_os_yx_isv16_osv8, 1, 1, 2, 0, {1, 0, 2, 3}, "ioyx", "oixy", {{1, 16}, {0, 8}}), FMT_TRAITS(is_os_yx_isv16_osv4, 1, 1, 2, 0, {1, 0, 2, 3}, "ioyx", "oixy", {{1, 16}, {0, 4}}), @@ -174,6 +184,8 @@ static const std::map format_traits_map { FMT_TRAITS(g_os_iyx_osv8, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy????g", {{0, 8}}), FMT_TRAITS(g_os_iyx_osv16, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy????g", {{0, 16}}), FMT_TRAITS(g_os_iyx_osv32, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy????g", {{0, 32}}), + FMT_TRAITS(gs_oiyx_gsv8, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy????g", {{8, 8}}), + FMT_TRAITS(gs_oizyx_gsv8, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz???g", {{8, 8}}), FMT_TRAITS(gs_oiyx_gsv16, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy????g", {{8, 16}}), FMT_TRAITS(gs_oizyx_gsv16, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz???g", {{8, 16}}), FMT_TRAITS(gs_oiyx_gsv32, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy????g", {{8, 32}}), diff --git a/src/plugins/intel_gpu/src/runtime/layout.cpp b/src/plugins/intel_gpu/src/runtime/layout.cpp index 99fdadb24cc6bb..a18c5bd73210f1 100644 --- a/src/plugins/intel_gpu/src/runtime/layout.cpp +++ b/src/plugins/intel_gpu/src/runtime/layout.cpp @@ -145,6 +145,8 @@ static format to_weights_format(format f, bool is_grouped) { throw std::runtime_error("Invalid conversion of data format to weights format. bfwzyx can't be non-grouped as 4D spatials are not supported"); return format::goizyx; } + case format::b_fs_yx_fsv4: + return format::o_is_yx_isv4; case format::b_fs_yx_fsv16: return format::o_is_yx_isv16; case format::bs_fs_fsv8_bsv8: diff --git a/src/plugins/intel_gpu/src/runtime/shape_predictor.cpp b/src/plugins/intel_gpu/src/runtime/shape_predictor.cpp index 2d398ee89ff1de..1ff00c905bd073 100644 --- a/src/plugins/intel_gpu/src/runtime/shape_predictor.cpp +++ b/src/plugins/intel_gpu/src/runtime/shape_predictor.cpp @@ -58,7 +58,7 @@ bool ShapePredictor::can_preallocate(size_t desired_buffer_size) { std::pair ShapePredictor::predict_preallocation_shape(const std::string& id, const ov::Shape& current_shape, - size_t dt_size, + size_t dt_bitwidth, bool can_reuse_buffer) { add_shape(id, current_shape); @@ -110,7 +110,7 @@ std::pair ShapePredictor::predict_preallocation_shape(const std for (size_t i = 0; i < current_shape.size(); ++i) single_iter_shape.push_back(diffs[0][i] == 0 ? current_shape[i] : 1); - if (ov::shape_size(single_iter_shape) * dt_size > _max_per_iter_size) + if (ceil_div(ov::shape_size(single_iter_shape) * dt_bitwidth, 8) > _max_per_iter_size) can_use_iterations_preallocation = false; } diff --git a/src/plugins/intel_gpu/tests/common/subgraphs_builders.hpp b/src/plugins/intel_gpu/tests/common/subgraphs_builders.hpp new file mode 100644 index 00000000000000..dea703cf7104b2 --- /dev/null +++ b/src/plugins/intel_gpu/tests/common/subgraphs_builders.hpp @@ -0,0 +1,50 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include "openvino/core/dimension.hpp" +#include "openvino/core/model.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/transpose.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/matmul.hpp" +#include "openvino/op/convert.hpp" +#include "openvino/op/concat.hpp" + +namespace tests { + +inline std::shared_ptr make_llm_kv_cache_pattern(ov::Dimension batch = ov::Dimension::dynamic(), + ov::Dimension n_heads = ov::Dimension::dynamic(), + ov::Dimension n_features = ov::Dimension::dynamic(), + ov::element::Type_t element_type = ov::element::f32) { + ov::PartialShape kv_cache_size = {batch, n_heads, -1, n_features}; + ov::PartialShape new_token_size = {batch, -1, n_heads, n_features}; + ov::PartialShape matmul_in_size = {batch, n_heads, -1, -1}; + + auto in_kv_prev = std::make_shared(element_type, kv_cache_size); + in_kv_prev->set_friendly_name("past_key_values"); + auto in_new_token = std::make_shared(element_type, new_token_size); + in_new_token->set_friendly_name("new_token_input"); + auto in_matmul = std::make_shared(element_type, matmul_in_size); + in_matmul->set_friendly_name("in_matmul"); + + auto transpose_const = ov::op::v0::Constant::create(ov::element::i32, {new_token_size.size()}, {0, 2, 1, 3}); + auto transpose = std::make_shared(in_new_token, transpose_const); + auto concat = std::make_shared(ov::OutputVector{in_kv_prev, transpose}, 2); + auto convert = std::make_shared(concat, element_type); + auto kv_present = std::make_shared(convert); + kv_present->set_friendly_name("present_key_values"); + auto matmul = std::make_shared(in_matmul, concat, false, false); + auto matmul_out = std::make_shared(matmul); + matmul_out->set_friendly_name("matmul_out"); + + ov::ParameterVector params{in_kv_prev, in_new_token, in_matmul}; + ov::ResultVector results{kv_present, matmul_out}; + return std::make_shared(results, params, "LLM-KV-Cache"); +} + +} // namespace tests diff --git a/src/plugins/intel_gpu/tests/functional/behavior/infer_request.cpp b/src/plugins/intel_gpu/tests/functional/behavior/infer_request.cpp index 1d64aa74232d7c..af0229d5e81d8b 100644 --- a/src/plugins/intel_gpu/tests/functional/behavior/infer_request.cpp +++ b/src/plugins/intel_gpu/tests/functional/behavior/infer_request.cpp @@ -199,3 +199,26 @@ TEST(TensorTest, smoke_canSetTensorForDynamicInput) { ASSERT_NO_THROW(inf_req.set_input_tensor(t2)); ASSERT_NO_THROW(inf_req.infer()); } + +TEST(TensorTest, smoke_canReallocateDeviceInputForHostTensor) { + auto ov = ov::Core(); + using namespace ov::preprocess; + auto p = PrePostProcessor(ngraph::builder::subgraph::makeSplitMultiConvConcat()); + p.input().tensor().set_element_type(ov::element::i8); + p.input().preprocess().convert_element_type(ov::element::f32); + auto function = p.build(); + + auto compiled_model = ov.compile_model(function, ov::test::utils::DEVICE_GPU); + auto inf_req = compiled_model.create_infer_request(); + + auto input = function->input(); + ov::Tensor host_tensor(input.get_element_type(), input.get_shape()); + + // Infer with pre-allocated input tensor + ASSERT_NO_THROW(inf_req.infer()); + + // Infer with host_tensor + ASSERT_NO_THROW(inf_req.set_input_tensor(host_tensor)); + ASSERT_NO_THROW(inf_req.infer()); +} + diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/behavior/ov_infer_request/iteration_chaining.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/behavior/ov_infer_request/iteration_chaining.cpp new file mode 100644 index 00000000000000..4bcef9a7bedbe0 --- /dev/null +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/behavior/ov_infer_request/iteration_chaining.cpp @@ -0,0 +1,23 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#include +#include "behavior/ov_infer_request/iteration_chaining.hpp" +#include "common_test_utils/test_constants.hpp" +#include "openvino/runtime/properties.hpp" + +using namespace ov::test::behavior; + +namespace { + +const std::vector configs = { + { ov::hint::inference_precision(ov::element::f32) } +}; + +INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, OVIterationChaining, + ::testing::Combine( + ::testing::Values(ov::test::utils::DEVICE_GPU), + ::testing::ValuesIn(configs)), + OVIterationChaining::getTestCaseName); + +} // namespace diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/behavior/ov_plugin/properties_tests.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/behavior/ov_plugin/properties_tests.cpp index 31c4d4884f05d1..39711f74105596 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/behavior/ov_plugin/properties_tests.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/behavior/ov_plugin/properties_tests.cpp @@ -42,6 +42,7 @@ const std::vector gpu_setcore_properties = { const std::vector gpu_compileModel_properties = { {ov::hint::performance_mode(ov::hint::PerformanceMode::LATENCY), ov::hint::num_requests(10), + ov::hint::enable_cpu_pinning(true), ov::enable_profiling(true)}}; INSTANTIATE_TEST_SUITE_P(smoke_gpuCompileModelBehaviorTests, diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/adaptive_pooling.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/adaptive_pooling.cpp index 86e13507e63e14..e6026e85469871 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/adaptive_pooling.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/adaptive_pooling.cpp @@ -5,24 +5,21 @@ #include #include -#include "single_layer_tests/adaptive_pooling.hpp" +#include "single_op_tests/adaptive_pooling.hpp" #include "common_test_utils/test_constants.hpp" -using namespace ngraph::helpers; -using namespace LayerTestsDefinitions; -using namespace ngraph::element; - namespace { +using ov::test::AdaPoolLayerTest; const std::vector poolingModes = {"max", "avg"}; -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, +const std::vector types = { + ov::element::f16, + ov::element::f32 }; -const std::vector> inputShapes1D = { - {1, 3, 5}, - {1, 1, 17}, +const std::vector> inputShapes1D = { + {{1, 3, 5}}, + {{1, 1, 17}}, }; const std::vector> outputShapes1D = { {2}, @@ -31,16 +28,16 @@ const std::vector> outputShapes1D = { INSTANTIATE_TEST_SUITE_P(smoke_AdaptivePooling1D, AdaPoolLayerTest, ::testing::Combine( - ::testing::ValuesIn(inputShapes1D), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(inputShapes1D)), ::testing::ValuesIn(outputShapes1D), ::testing::ValuesIn(poolingModes), - ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(types), ::testing::Values(ov::test::utils::DEVICE_GPU)), AdaPoolLayerTest::getTestCaseName); -const std::vector> inputShapes2D = { - {1, 3, 4, 6}, - {1, 1, 17, 5}, +const std::vector> inputShapes2D = { + {{1, 3, 4, 6}}, + {{1, 1, 17, 5}}, }; const std::vector> outputShapes2D = { {2, 4}, @@ -49,16 +46,16 @@ const std::vector> outputShapes2D = { INSTANTIATE_TEST_SUITE_P(smoke_AdaptivePooling2D, AdaPoolLayerTest, ::testing::Combine( - ::testing::ValuesIn(inputShapes2D), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(inputShapes2D)), ::testing::ValuesIn(outputShapes2D), ::testing::ValuesIn(poolingModes), - ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(types), ::testing::Values(ov::test::utils::DEVICE_GPU)), AdaPoolLayerTest::getTestCaseName); -const std::vector> inputShapes3D = { - {1, 1, 3, 3, 3}, - {1, 3, 5, 7, 11}, +const std::vector> inputShapes3D = { + {{1, 1, 3, 3, 3}}, + {{1, 3, 5, 7, 11}}, }; const std::vector> outputShapes3D = { {2, 2, 2}, @@ -67,10 +64,10 @@ const std::vector> outputShapes3D = { INSTANTIATE_TEST_SUITE_P(smoke_AdaptivePooling3D, AdaPoolLayerTest, ::testing::Combine( - ::testing::ValuesIn(inputShapes3D), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(inputShapes3D)), ::testing::ValuesIn(outputShapes3D), ::testing::ValuesIn(poolingModes), - ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(types), ::testing::Values(ov::test::utils::DEVICE_GPU)), AdaPoolLayerTest::getTestCaseName); diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/batch_norm.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/batch_norm.cpp index 0ef10601c3f1b8..da3cbe708b0628 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/batch_norm.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/batch_norm.cpp @@ -4,14 +4,13 @@ #include -#include "single_layer_tests/batch_norm.hpp" - -using namespace LayerTestsDefinitions; +#include "single_op_tests/batch_norm.hpp" namespace { -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16 +using ov::test::BatchNormLayerTest; +const std::vector types = { + ov::element::f16, + ov::element::f32 }; const std::vector epsilon = { @@ -19,23 +18,19 @@ const std::vector epsilon = { 1e-5, 1e-4 }; -const std::vector> inputShapes = { - {1, 3}, - {2, 5}, - {1, 3, 10}, - {1, 3, 1, 1}, - {2, 5, 4, 4}, -}; +const std::vector> inputShapes = { + {{1, 3}}, + {{2, 5}}, + {{1, 3, 10}}, + {{1, 3, 1, 1}}, + {{2, 5, 4, 4}}, +}; const auto batchNormParams = testing::Combine( testing::ValuesIn(epsilon), - 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::ValuesIn(types), + testing::ValuesIn(ov::test::static_shapes_to_test_representation(inputShapes)), testing::Values(ov::test::utils::DEVICE_GPU) ); diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/batch_to_space.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/batch_to_space.cpp index b35117443cf47f..e79d3b55551797 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/batch_to_space.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/batch_to_space.cpp @@ -4,172 +4,125 @@ #include -#include "single_layer_tests/batch_to_space.hpp" +#include "single_op_tests/batch_to_space.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { +using ov::test::BatchToSpaceLayerTest; +using ov::test::batchToSpaceParamsTuple; + auto bts_only_test_cases = []() { return std::vector{batchToSpaceParamsTuple({1, 2, 2}, {0, 0, 0}, {0, 0, 0}, - {4, 1, 1}, - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Layout::ANY, - InferenceEngine::Layout::ANY, + ov::test::static_shapes_to_test_representation(std::vector({ + {4, 1, 1}})), + ov::element::f32, ov::test::utils::DEVICE_GPU), batchToSpaceParamsTuple({1, 1, 2, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, - {4, 1, 1, 1}, - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Layout::ANY, - InferenceEngine::Layout::ANY, + ov::test::static_shapes_to_test_representation(std::vector({ + {4, 1, 1, 1}})), + ov::element::f32, ov::test::utils::DEVICE_GPU), batchToSpaceParamsTuple({1, 1, 2, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, - {4, 3, 1, 1}, - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Layout::ANY, - InferenceEngine::Layout::ANY, + ov::test::static_shapes_to_test_representation(std::vector({ + {4, 3, 1, 1}})), + ov::element::f32, ov::test::utils::DEVICE_GPU), batchToSpaceParamsTuple({1, 1, 2, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, - {4, 1, 2, 2}, - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Layout::ANY, - InferenceEngine::Layout::ANY, + ov::test::static_shapes_to_test_representation(std::vector({ + {4, 1, 2, 2}})), + ov::element::f32, ov::test::utils::DEVICE_GPU), batchToSpaceParamsTuple({1, 1, 2, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, - {8, 1, 1, 2}, - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Layout::ANY, - InferenceEngine::Layout::ANY, + ov::test::static_shapes_to_test_representation(std::vector({ + {8, 1, 1, 2}})), + ov::element::f32, ov::test::utils::DEVICE_GPU), batchToSpaceParamsTuple({1, 1, 3, 2, 2}, {0, 0, 1, 0, 3}, {0, 0, 2, 0, 0}, - {24, 1, 2, 1, 2}, - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Layout::ANY, - InferenceEngine::Layout::ANY, + ov::test::static_shapes_to_test_representation(std::vector({ + {24, 1, 2, 1, 2}})), + ov::element::f32, ov::test::utils::DEVICE_GPU), batchToSpaceParamsTuple({1, 1, 2, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, - {4, 1, 1, 1}, - InferenceEngine::Precision::I8, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Layout::ANY, - InferenceEngine::Layout::ANY, + ov::test::static_shapes_to_test_representation(std::vector({ + {4, 1, 1, 1}})), + ov::element::i8, ov::test::utils::DEVICE_GPU), batchToSpaceParamsTuple({1, 1, 2, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, - {4, 3, 1, 1}, - InferenceEngine::Precision::I8, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Layout::ANY, - InferenceEngine::Layout::ANY, + ov::test::static_shapes_to_test_representation(std::vector({ + {4, 3, 1, 1}})), + ov::element::i8, ov::test::utils::DEVICE_GPU), batchToSpaceParamsTuple({1, 1, 2, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, - {4, 1, 2, 2}, - InferenceEngine::Precision::I8, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Layout::ANY, - InferenceEngine::Layout::ANY, + ov::test::static_shapes_to_test_representation(std::vector({ + {4, 1, 2, 2}})), + ov::element::i8, ov::test::utils::DEVICE_GPU), batchToSpaceParamsTuple({1, 1, 2, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, - {8, 1, 1, 2}, - InferenceEngine::Precision::I8, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Layout::ANY, - InferenceEngine::Layout::ANY, + ov::test::static_shapes_to_test_representation(std::vector({ + {8, 1, 1, 2}})), + ov::element::i8, ov::test::utils::DEVICE_GPU), batchToSpaceParamsTuple({1, 1, 3, 2, 2}, {0, 0, 1, 0, 3}, {0, 0, 2, 0, 0}, - {24, 1, 2, 1, 2}, - InferenceEngine::Precision::I8, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Layout::ANY, - InferenceEngine::Layout::ANY, + ov::test::static_shapes_to_test_representation(std::vector({ + {24, 1, 2, 1, 2}})), + ov::element::i8, ov::test::utils::DEVICE_GPU), batchToSpaceParamsTuple({1, 1, 2, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, - {4, 1, 1, 1}, - InferenceEngine::Precision::U8, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Layout::ANY, - InferenceEngine::Layout::ANY, + ov::test::static_shapes_to_test_representation(std::vector({ + {4, 1, 1, 1}})), + ov::element::u8, ov::test::utils::DEVICE_GPU), batchToSpaceParamsTuple({1, 1, 2, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, - {4, 3, 1, 1}, - InferenceEngine::Precision::U8, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Layout::ANY, - InferenceEngine::Layout::ANY, + ov::test::static_shapes_to_test_representation(std::vector({ + {4, 3, 1, 1}})), + ov::element::u8, ov::test::utils::DEVICE_GPU), batchToSpaceParamsTuple({1, 1, 2, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, - {4, 1, 2, 2}, - InferenceEngine::Precision::U8, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Layout::ANY, - InferenceEngine::Layout::ANY, + ov::test::static_shapes_to_test_representation(std::vector({ + {4, 1, 2, 2}})), + ov::element::u8, ov::test::utils::DEVICE_GPU), batchToSpaceParamsTuple({1, 1, 2, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, - {8, 1, 1, 2}, - InferenceEngine::Precision::U8, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Layout::ANY, - InferenceEngine::Layout::ANY, + ov::test::static_shapes_to_test_representation(std::vector({ + {8, 1, 1, 2}})), + ov::element::u8, ov::test::utils::DEVICE_GPU), batchToSpaceParamsTuple({1, 1, 3, 2, 2}, {0, 0, 1, 0, 3}, {0, 0, 2, 0, 0}, - {24, 1, 2, 1, 2}, - InferenceEngine::Precision::U8, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Precision::UNSPECIFIED, - InferenceEngine::Layout::ANY, - InferenceEngine::Layout::ANY, + ov::test::static_shapes_to_test_representation(std::vector({ + {24, 1, 2, 1, 2}})), + ov::element::u8, ov::test::utils::DEVICE_GPU)}; }; diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/broadcast.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/broadcast.cpp index 84234e94bbd347..3387375a0c07c1 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/broadcast.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/broadcast.cpp @@ -4,25 +4,24 @@ #include -#include "single_layer_tests/broadcast.hpp" +#include "single_op_tests/broadcast.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { - -const std::vector inputPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::I32, - InferenceEngine::Precision::I8, - InferenceEngine::Precision::U8 +using ov::test::BroadcastLayerTest; +using ov::test::BroadcastParamsTuple; +const std::vector inputPrecisions = { + ov::element::f32, + ov::element::f16, + ov::element::i32, + ov::element::i8, + ov::element::u8 }; -const std::vector inputTPrecisions = { - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::I16, - InferenceEngine::Precision::BOOL +const std::vector inputTPrecisions = { + ov::element::f16, + ov::element::i16, + ov::element::boolean }; // NUMPY MODE ////////////////////////////////////////// @@ -31,12 +30,16 @@ std::vector> targetShapesNumpy0D = { {}, }; +std::vector> input_shapes_0d_static = { + {{}} +}; + INSTANTIATE_TEST_CASE_P(smoke_TestNumpyBroadcast0D, BroadcastLayerTest, ::testing::Combine(::testing::ValuesIn(targetShapesNumpy0D), - ::testing::Values(ngraph::AxisSet{}), // not used in numpy mode - ::testing::Values(ngraph::op::BroadcastType::NUMPY), - ::testing::Values(std::vector{}), + ::testing::Values(ov::AxisSet{}), // not used in numpy mode + ::testing::Values(ov::op::BroadcastType::NUMPY), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_0d_static)), ::testing::ValuesIn(inputPrecisions), ::testing::Values(ov::test::utils::DEVICE_GPU)), BroadcastLayerTest::getTestCaseName); @@ -53,12 +56,16 @@ std::vector> targetShapesNumpy1D = { {1, 4, 4}, }; +std::vector> input_shapes_1d_static = { + {{1}} +}; + INSTANTIATE_TEST_CASE_P(smoke_TestNumpyBroadcast1D, BroadcastLayerTest, ::testing::Combine(::testing::ValuesIn(targetShapesNumpy1D), - ::testing::Values(ngraph::AxisSet{}), // not used in numpy mode - ::testing::Values(ngraph::op::BroadcastType::NUMPY), - ::testing::Values(std::vector{1}), + ::testing::Values(ov::AxisSet{}), // not used in numpy mode + ::testing::Values(ov::op::BroadcastType::NUMPY), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_1d_static)), ::testing::ValuesIn(inputPrecisions), ::testing::Values(ov::test::utils::DEVICE_GPU)), BroadcastLayerTest::getTestCaseName); @@ -66,9 +73,9 @@ INSTANTIATE_TEST_CASE_P(smoke_TestNumpyBroadcast1D, INSTANTIATE_TEST_CASE_P(smoke_PrecTransformation, BroadcastLayerTest, ::testing::Combine( ::testing::Values(targetShapesNumpy1D[0]), - ::testing::Values(ngraph::AxisSet{}), //not used in numpy mode - ::testing::Values(ngraph::op::BroadcastType::NUMPY), - ::testing::Values(std::vector{1}), + ::testing::Values(ov::AxisSet{}), //not used in numpy mode + ::testing::Values(ov::op::BroadcastType::NUMPY), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_1d_static)), ::testing::ValuesIn(inputTPrecisions), ::testing::Values(ov::test::utils::DEVICE_GPU)), BroadcastLayerTest::getTestCaseName); @@ -81,12 +88,16 @@ std::vector> targetShapesNumpy2D = { {2, 2, 3, 6}, }; +std::vector> input_shapes_2d_static = { + {{3, 1}} +}; + INSTANTIATE_TEST_CASE_P(smoke_TestNumpyBroadcast2D, BroadcastLayerTest, ::testing::Combine(::testing::ValuesIn(targetShapesNumpy2D), ::testing::Values(ngraph::AxisSet{}), // not used in numpy mode ::testing::Values(ngraph::op::BroadcastType::NUMPY), - ::testing::Values(std::vector{3, 1}), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_2d_static)), ::testing::ValuesIn(inputPrecisions), ::testing::Values(ov::test::utils::DEVICE_GPU)), BroadcastLayerTest::getTestCaseName); @@ -99,42 +110,63 @@ std::vector> targetShapesNumpy3D = { {2, 1, 1, 4, 4}, }; +std::vector> input_shapes_3d_static = { + {{1, 4, 1}} +}; + + INSTANTIATE_TEST_CASE_P(smoke_TestNumpyBroadcast3D, BroadcastLayerTest, ::testing::Combine(::testing::ValuesIn(targetShapesNumpy3D), - ::testing::Values(ngraph::AxisSet{}), // not used in numpy mode - ::testing::Values(ngraph::op::BroadcastType::NUMPY), - ::testing::Values(std::vector{1, 4, 1}), + ::testing::Values(ov::AxisSet{}), // not used in numpy mode + ::testing::Values(ov::op::BroadcastType::NUMPY), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_3d_static)), ::testing::ValuesIn(inputPrecisions), ::testing::Values(ov::test::utils::DEVICE_GPU)), BroadcastLayerTest::getTestCaseName); +std::vector> targetShapesNumpy6D = { + {1, 2, 3, 4, 5, 6}, +}; + +std::vector> input_shapes_6d_static = { + {{1, 2, 1, 4, 1, 6}} +}; + INSTANTIATE_TEST_CASE_P(smoke_TestNumpyBroadcast6D, BroadcastLayerTest, - ::testing::Combine(::testing::Values(std::vector{1, 2, 3, 4, 5, 6}), - ::testing::Values(ngraph::AxisSet{}), // not used in numpy mode - ::testing::Values(ngraph::op::BroadcastType::NUMPY), - ::testing::Values(std::vector{1, 2, 1, 4, 1, 6}), + ::testing::Combine(::testing::ValuesIn(targetShapesNumpy6D), + ::testing::Values(ov::AxisSet{}), // not used in numpy mode + ::testing::Values(ov::op::BroadcastType::NUMPY), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_6d_static)), ::testing::ValuesIn(inputPrecisions), ::testing::Values(ov::test::utils::DEVICE_GPU)), BroadcastLayerTest::getTestCaseName); +std::vector> targetShapesNumpy5D = { + {1, 2, 3, 4, 5}, +}; + +std::vector> input_shapes_5d_static = { + {{1, 2, 1, 4, 1}} +}; + INSTANTIATE_TEST_CASE_P(smoke_TestNumpyBroadcast5D, BroadcastLayerTest, - ::testing::Combine(::testing::Values(std::vector{1, 2, 3, 4, 5}), - ::testing::Values(ngraph::AxisSet{}), // not used in numpy mode - ::testing::Values(ngraph::op::BroadcastType::NUMPY), - ::testing::Values(std::vector{1, 2, 1, 4, 1}), + ::testing::Combine(::testing::ValuesIn(targetShapesNumpy5D), + ::testing::Values(ov::AxisSet{}), // not used in numpy mode + ::testing::Values(ov::op::BroadcastType::NUMPY), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_5d_static)), ::testing::ValuesIn(inputPrecisions), ::testing::Values(ov::test::utils::DEVICE_GPU)), BroadcastLayerTest::getTestCaseName); // END NUMPY MODE ////////////////////////////////////// // BIDIRECTIONAL MODE ////////////////////////////////// -std::vector> inShapesBidi = { - {4, 1}, - {1, 4, 1}, - {4, 1, 1} +std::vector> inShapesBidi = { + {{4, 1}}, + {{1, 4, 1}}, + {{4, 1, 1}} }; std::vector> targetShapesBidi = { @@ -146,25 +178,25 @@ std::vector> targetShapesBidi = { INSTANTIATE_TEST_CASE_P(smoke_TestBidirectionalBroadcast, BroadcastLayerTest, ::testing::Combine(::testing::ValuesIn(targetShapesBidi), - ::testing::Values(ngraph::AxisSet{}), // not used in bidirectional mode - ::testing::Values(ngraph::op::BroadcastType::BIDIRECTIONAL), - ::testing::ValuesIn(inShapesBidi), + ::testing::Values(ov::AxisSet{}), // not used in bidirectional mode + ::testing::Values(ov::op::BroadcastType::BIDIRECTIONAL), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(inShapesBidi)), ::testing::ValuesIn(inputPrecisions), ::testing::Values(ov::test::utils::DEVICE_GPU)), BroadcastLayerTest::getTestCaseName); // EXPLICIT MODE /////////////////////////////////////// // 1D -std::vector> inShapesExplicit1D = { {4} }; +std::vector> inShapesExplicit1D = { {{4}} }; std::vector> targetShapesExplicit1D = { {4, 2, 4}, {4, 2, 4, 1} }; -std::vector axes1D = { {0}, {2} }; +std::vector axes1D = { {0}, {2} }; INSTANTIATE_TEST_CASE_P(smoke_TestExplicitBroadcast1D, BroadcastLayerTest, ::testing::Combine(::testing::ValuesIn(targetShapesExplicit1D), ::testing::ValuesIn(axes1D), - ::testing::Values(ngraph::op::BroadcastType::EXPLICIT), - ::testing::ValuesIn(inShapesExplicit1D), + ::testing::Values(ov::op::BroadcastType::EXPLICIT), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(inShapesExplicit1D)), ::testing::ValuesIn(inputPrecisions), ::testing::Values(ov::test::utils::DEVICE_GPU)), BroadcastLayerTest::getTestCaseName); @@ -172,18 +204,18 @@ INSTANTIATE_TEST_CASE_P(smoke_TestExplicitBroadcast1D, INSTANTIATE_TEST_SUITE_P(smoke_TestBidirectionalBroadcast3, BroadcastLayerTest, ::testing::Combine(::testing::Values(targetShapesBidi[2]), - ::testing::Values(ngraph::AxisSet{}), // not used in bidirectional mode - ::testing::Values(ngraph::op::BroadcastType::BIDIRECTIONAL), - ::testing::Values(inShapesBidi[2]), + ::testing::Values(ov::AxisSet{}), // not used in bidirectional mode + ::testing::Values(ov::op::BroadcastType::BIDIRECTIONAL), + ::testing::Values(ov::test::static_shapes_to_test_representation(inShapesBidi[2])), ::testing::ValuesIn(inputPrecisions), ::testing::Values(ov::test::utils::DEVICE_GPU)), BroadcastLayerTest::getTestCaseName); // EXPLICIT MODE -std::vector> inShapesExplicit = { - {3, 1}, - {2, 4} +std::vector> inShapesExplicit = { + {{3, 1}}, + {{2, 4}} }; std::vector> targetShapesExplicit = { @@ -192,34 +224,33 @@ std::vector> targetShapesExplicit = { }; // 2D -std::vector> inShapesExplicit2D = { {2, 4} }; +std::vector> inShapesExplicit2D = { {{2, 4}} }; std::vector> targetShapesExplicit2D = { {2, 2, 4}, {2, 2, 4, 1}}; -std::vector axes2D = { {1, 2}, {0, 2} }; +std::vector axes2D = { {1, 2}, {0, 2} }; INSTANTIATE_TEST_CASE_P(smoke_TestExplicitBroadcast2D, BroadcastLayerTest, ::testing::Combine(::testing::ValuesIn(targetShapesExplicit2D), ::testing::ValuesIn(axes2D), - ::testing::Values(ngraph::op::BroadcastType::EXPLICIT), - ::testing::ValuesIn(inShapesExplicit2D), + ::testing::Values(ov::op::BroadcastType::EXPLICIT), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(inShapesExplicit2D)), ::testing::ValuesIn(inputPrecisions), ::testing::Values(ov::test::utils::DEVICE_GPU)), BroadcastLayerTest::getTestCaseName); // 3D -std::vector> inShapesExplicit3D = { {2, 2, 2} }; +std::vector> inShapesExplicit3D = { {{2, 2, 2}} }; std::vector> targetShapesExplicit3D = { {2, 2, 2, 2} }; -std::vector axes3D = { {0, 1, 2}, {0, 1, 3}, {0, 2, 3}, {1, 2, 3} }; +std::vector axes3D = { {0, 1, 2}, {0, 1, 3}, {0, 2, 3}, {1, 2, 3} }; INSTANTIATE_TEST_CASE_P(smoke_TestExplicitBroadcast3D, BroadcastLayerTest, ::testing::Combine(::testing::ValuesIn(targetShapesExplicit3D), ::testing::ValuesIn(axes3D), - ::testing::Values(ngraph::op::BroadcastType::EXPLICIT), - ::testing::ValuesIn(inShapesExplicit3D), + ::testing::Values(ov::op::BroadcastType::EXPLICIT), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(inShapesExplicit3D)), ::testing::ValuesIn(inputPrecisions), ::testing::Values(ov::test::utils::DEVICE_GPU)), BroadcastLayerTest::getTestCaseName); // END EXPLICIT MODE /////////////////////////////////// - } // namespace diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/bucketize.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/bucketize.cpp index b658cfc840fe06..89da385392745f 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/bucketize.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/bucketize.cpp @@ -2,31 +2,37 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "single_layer_tests/bucketize.hpp" +#include "single_op_tests/bucketize.hpp" #include -using namespace LayerTestsDefinitions; +using ov::test::BucketizeLayerTest; namespace { -const std::vector> data_shapes = { - // No reason to test other ranks as logic is the same - {40, 22, 13, 9}, // 4D - {6, 7, 3, 2, 8}, // 5D - {6, 7, 3, 2, 8, 5}, // 6D -}; - -const std::vector> buckets_shapes = { - {5}, - {100}, +const std::vector> input_shapes_static = { + {{40, 22, 13, 9}, {5}}, + {{6, 7, 3, 2, 8}, {5}}, + {{6, 7, 3, 2, 8, 5}, {5}}, + {{40, 22, 13, 9}, {100}}, + {{6, 7, 3, 2, 8}, {100}}, + {{6, 7, 3, 2, 8, 5}, {100}}, }; const std::vector with_right_bound = {true, false}; -const std::vector out_precision = { - InferenceEngine::Precision::I32, - InferenceEngine::Precision::I64, +const std::vector out_precision = { + ov::element::i32, + ov::element::i64 +}; + +const std::vector in_buckets_precision = { + ov::element::f16, + ov::element::f32, + ov::element::i32, + ov::element::i64, + ov::element::i8, + ov::element::u8 }; // We won't test FP32 and FP16 together as it won't make sense for now @@ -34,94 +40,68 @@ const std::vector out_precision = { INSTANTIATE_TEST_SUITE_P(smoke_Bucketize_input_fp16, BucketizeLayerTest, - testing::Combine(testing::ValuesIn(data_shapes), - testing::ValuesIn(buckets_shapes), + testing::Combine(testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), testing::ValuesIn(with_right_bound), - testing::Values(InferenceEngine::Precision::FP16), - testing::Values(InferenceEngine::Precision::FP16, - InferenceEngine::Precision::I32, - InferenceEngine::Precision::I64, - InferenceEngine::Precision::I8, - InferenceEngine::Precision::U8), + testing::Values(ov::element::f16), + testing::Values(ov::element::f16, + ov::element::i32, + ov::element::i64, + ov::element::i8, + ov::element::u8), testing::ValuesIn(out_precision), testing::Values(ov::test::utils::DEVICE_GPU)), BucketizeLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_Bucketize_input_fp32, BucketizeLayerTest, - testing::Combine(testing::ValuesIn(data_shapes), - testing::ValuesIn(buckets_shapes), + testing::Combine(testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), testing::ValuesIn(with_right_bound), - testing::Values(InferenceEngine::Precision::FP32), - testing::Values(InferenceEngine::Precision::FP32, - InferenceEngine::Precision::I32, - InferenceEngine::Precision::I64, - InferenceEngine::Precision::I8, - InferenceEngine::Precision::U8), + testing::Values(ov::element::f32), + testing::Values(ov::element::f32, + ov::element::i32, + ov::element::i64, + ov::element::i8, + ov::element::u8), testing::ValuesIn(out_precision), testing::Values(ov::test::utils::DEVICE_GPU)), BucketizeLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_Bucketize_input_i32, BucketizeLayerTest, - testing::Combine(testing::ValuesIn(data_shapes), - testing::ValuesIn(buckets_shapes), + testing::Combine(testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), testing::ValuesIn(with_right_bound), - testing::Values(InferenceEngine::Precision::I32), - testing::Values(InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::I32, - InferenceEngine::Precision::I64, - InferenceEngine::Precision::I8, - InferenceEngine::Precision::U8), + testing::Values(ov::element::i32), + testing::ValuesIn(in_buckets_precision), testing::ValuesIn(out_precision), testing::Values(ov::test::utils::DEVICE_GPU)), BucketizeLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_Bucketize_input_i64, BucketizeLayerTest, - testing::Combine(testing::ValuesIn(data_shapes), - testing::ValuesIn(buckets_shapes), + testing::Combine(testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), testing::ValuesIn(with_right_bound), - testing::Values(InferenceEngine::Precision::I64), - testing::Values(InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::I32, - InferenceEngine::Precision::I64, - InferenceEngine::Precision::I8, - InferenceEngine::Precision::U8), + testing::Values(ov::element::i64), + testing::ValuesIn(in_buckets_precision), testing::ValuesIn(out_precision), testing::Values(ov::test::utils::DEVICE_GPU)), BucketizeLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_Bucketize_input_i8, BucketizeLayerTest, - testing::Combine(testing::ValuesIn(data_shapes), - testing::ValuesIn(buckets_shapes), + testing::Combine(testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), testing::ValuesIn(with_right_bound), - testing::Values(InferenceEngine::Precision::I8), - testing::Values(InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::I32, - InferenceEngine::Precision::I64, - InferenceEngine::Precision::I8, - InferenceEngine::Precision::U8), + testing::Values(ov::element::i8), + testing::ValuesIn(in_buckets_precision), testing::ValuesIn(out_precision), testing::Values(ov::test::utils::DEVICE_GPU)), BucketizeLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_Bucketize_input_u8, BucketizeLayerTest, - testing::Combine(testing::ValuesIn(data_shapes), - testing::ValuesIn(buckets_shapes), + testing::Combine(testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), testing::ValuesIn(with_right_bound), - testing::Values(InferenceEngine::Precision::U8), - testing::Values(InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::I32, - InferenceEngine::Precision::I64, - InferenceEngine::Precision::I8, - InferenceEngine::Precision::U8), + testing::Values(ov::element::u8), + testing::ValuesIn(in_buckets_precision), testing::ValuesIn(out_precision), testing::Values(ov::test::utils::DEVICE_GPU)), BucketizeLayerTest::getTestCaseName); diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/concat.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/concat.cpp index 0d0aa1fe704b77..a6dfee6b36d641 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/concat.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/concat.cpp @@ -4,35 +4,30 @@ #include -#include "single_layer_tests/concat.hpp" +#include "single_op_tests/concat.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { +using ov::test::ConcatLayerTest; std::vector axes = {-3, -2, -1, 0, 1, 2, 3}; -std::vector>> inShapes = { +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}, {10, 10, 10, 10}} }; -std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::I64}; +std::vector netPrecisions = {ov::element::f32, + ov::element::f16, + ov::element::i64}; INSTANTIATE_TEST_SUITE_P(smoke_NoReshape, ConcatLayerTest, ::testing::Combine( ::testing::ValuesIn(axes), - ::testing::ValuesIn(inShapes), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(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_GPU)), ConcatLayerTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_greedy_decoder.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_greedy_decoder.cpp index 2206490567e7e2..b7c2807ce37086 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_greedy_decoder.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_greedy_decoder.cpp @@ -3,35 +3,33 @@ // #include -#include "single_layer_tests/ctc_greedy_decoder.hpp" +#include "single_op_tests/ctc_greedy_decoder.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; -using namespace ngraph::helpers; - namespace { +using ov::test::CTCGreedyDecoderLayerTest; + // Common params -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16 +const std::vector netPrecisions = { + ov::element::f32, + ov::element::f16 }; std::vector mergeRepeated{true, false}; +std::vector> input_shapes_static = { + {{ 50, 3, 3 }}, + {{ 50, 3, 7 }}, + {{ 50, 3, 8 }}, + {{ 50, 3, 16 }}, + {{ 50, 3, 128 }}, + {{ 50, 3, 49 }}, + {{ 50, 3, 55 }}, + {{ 1, 1, 16 }}}; + INSTANTIATE_TEST_SUITE_P(smoke_CtcGreedyDecoderBasic, CTCGreedyDecoderLayerTest, ::testing::Combine(::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({50, 3, 3}), - std::vector({50, 3, 7}), - std::vector({50, 3, 8}), - std::vector({50, 3, 16}), - std::vector({50, 3, 128}), - std::vector({50, 3, 49}), - std::vector({50, 3, 55}), - std::vector({1, 1, 16})), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), ::testing::ValuesIn(mergeRepeated), ::testing::Values(ov::test::utils::DEVICE_GPU)), CTCGreedyDecoderLayerTest::getTestCaseName); diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_greedy_decoder_seq_len.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_greedy_decoder_seq_len.cpp index c015258d41ed24..12d318d107d342 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_greedy_decoder_seq_len.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_greedy_decoder_seq_len.cpp @@ -3,30 +3,28 @@ // #include -#include "single_layer_tests/ctc_greedy_decoder_seq_len.hpp" +#include "single_op_tests/ctc_greedy_decoder_seq_len.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; -using namespace ngraph::helpers; - namespace { +using ov::test::CTCGreedyDecoderSeqLenLayerTest; -std::vector> inputShape{{1, 1, 1}, {1, 6, 10}, {3, 3, 16}, {5, 3, 55}}; +std::vector> inputShape{{{1, 1, 1}}, {{1, 6, 10}}, {{3, 3, 16}}, {{5, 3, 55}}}; -const std::vector probPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16 +const std::vector probPrecisions = { + ov::element::f32, + ov::element::f16 }; -const std::vector idxPrecisions = { - InferenceEngine::Precision::I32, - InferenceEngine::Precision::I64 +const std::vector idxPrecisions = { + ov::element::i32, + ov::element::i64 }; std::vector mergeRepeated{true, false}; INSTANTIATE_TEST_SUITE_P(smoke_set1, CTCGreedyDecoderSeqLenLayerTest, - ::testing::Combine(::testing::ValuesIn(inputShape), + ::testing::Combine(::testing::ValuesIn(ov::test::static_shapes_to_test_representation(inputShape)), ::testing::Values(10), ::testing::ValuesIn(probPrecisions), ::testing::ValuesIn(idxPrecisions), @@ -37,8 +35,8 @@ INSTANTIATE_TEST_SUITE_P(smoke_set1, INSTANTIATE_TEST_SUITE_P(smoke_set2, CTCGreedyDecoderSeqLenLayerTest, - ::testing::Combine(::testing::ValuesIn(std::vector>{{2, 8, 11}, - {4, 10, 55}}), + ::testing::Combine(::testing::ValuesIn(ov::test::static_shapes_to_test_representation(std::vector>{{{2, 8, 11}}, + {{4, 10, 55}}})), ::testing::ValuesIn(std::vector{5, 100}), ::testing::ValuesIn(probPrecisions), ::testing::ValuesIn(idxPrecisions), diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_loss.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_loss.cpp index 9e71f45de30034..742b4974e6fc88 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_loss.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/ctc_loss.cpp @@ -2,22 +2,21 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "single_layer_tests/ctc_loss.hpp" +#include "single_op_tests/ctc_loss.hpp" #include -using namespace LayerTestsDefinitions; - namespace { +using ov::test::CTCLossLayerTest; -const std::vector fPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, +const std::vector fPrecisions = { + ov::element::f32, + ov::element::f16, }; -const std::vector iPrecisions = { - InferenceEngine::Precision::I32, - InferenceEngine::Precision::I64, +const std::vector iPrecisions = { + ov::element::i32, + ov::element::i64, }; const std::vector preprocessCollapseRepeated = {true, false}; @@ -25,7 +24,6 @@ const std::vector ctcMergeRepeated = {true, false}; const std::vector unique = {true, false}; const auto ctcLossArgsSubset1 = testing::Combine( - testing::Values(std::vector({2, 3, 3})), // logits shape testing::ValuesIn(std::vector>({{2, 3}, {3, 3}})), // logits length testing::ValuesIn( std::vector>>({{{0, 1, 0}, {1, 0, 1}}, {{0, 1, 2}, {1, 1, 1}}})), // labels @@ -38,14 +36,14 @@ const auto ctcLossArgsSubset1 = testing::Combine( INSTANTIATE_TEST_SUITE_P(smoke_CTCLoss_Set1, CTCLossLayerTest, testing::Combine(ctcLossArgsSubset1, - testing::ValuesIn(fPrecisions), - testing::ValuesIn(iPrecisions), - testing::Values(ov::test::utils::DEVICE_GPU)), + testing::Values(ov::test::static_shapes_to_test_representation({{2, 3, 3}})), // logits shape + testing::ValuesIn(fPrecisions), + testing::ValuesIn(iPrecisions), + testing::Values(ov::test::utils::DEVICE_GPU)), CTCLossLayerTest::getTestCaseName); const auto ctcLossArgsSubset2 = - testing::Combine(testing::Values(std::vector({3, 6, 8})), // logits shape - testing::ValuesIn(std::vector>({{6, 5, 6}, {5, 5, 5}})), // logits length + testing::Combine(testing::ValuesIn(std::vector>({{6, 5, 6}, {5, 5, 5}})), // logits length testing::ValuesIn(std::vector>>( {{{4, 1, 2, 3, 4, 5}, {5, 4, 3, 0, 1, 0}, {2, 1, 3, 1, 3, 0}}, {{2, 1, 5, 3, 2, 6}, {3, 3, 3, 3, 3, 3}, {6, 5, 6, 5, 6, 5}}})), // labels @@ -58,8 +56,9 @@ const auto ctcLossArgsSubset2 = INSTANTIATE_TEST_SUITE_P(smoke_CTCLoss_Set2, CTCLossLayerTest, testing::Combine(ctcLossArgsSubset2, - testing::ValuesIn(fPrecisions), - testing::ValuesIn(iPrecisions), - testing::Values(ov::test::utils::DEVICE_GPU)), + testing::Values(ov::test::static_shapes_to_test_representation({{3, 6, 8}})), // logits shape + testing::ValuesIn(fPrecisions), + testing::ValuesIn(iPrecisions), + testing::Values(ov::test::utils::DEVICE_GPU)), CTCLossLayerTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/einsum.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/einsum.cpp index 94555588b727bb..7303e7a396a2b2 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/einsum.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/einsum.cpp @@ -4,35 +4,34 @@ #include -#include "single_layer_tests/einsum.hpp" - -using namespace ngraph::helpers; -using namespace LayerTestsDefinitions; +#include "single_op_tests/einsum.hpp" namespace { -const std::vector precisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16 +using ov::test::EinsumLayerTest; + +const std::vector model_types = { + ov::element::f32, + ov::element::f16 }; -const std::vector equationsWithInput = { - { "ij->ji", {{{1, 2}}} }, // transpose 2d - { "ijk->kij", { {1, 2, 3} } }, // transpose 3d - { "ij->i", { {2, 3} } }, // reduce - { "ab,cd->abcd", { { 1, 2}, {3, 4} } }, // no reduction - { "ab,bc->ac", { {2, 3}, {3, 2} } }, // matrix multiplication - { "ab,bcd,bc->ca", { {2, 4}, {4, 3, 1}, {4, 3} } }, // multiple multiplications - { "kii->ki", { {1, 3, 3} } }, // diagonal - { "abbac,bad->ad", { {2, 3, 3, 2, 4}, {3, 2, 1} } }, // diagonal and multiplication with repeated labels - { "a...->...a", { {2, 2, 3} } }, // transpose with ellipsis - { "a...->...", { {2, 2, 3} } }, // reduce with ellipsis - { "ab...,...->ab...", { {2, 2, 3}, {1} } }, // multiply by scalar - { "a...j,j...->a...", { {1, 1, 4, 3}, {3, 4, 2, 1} } } // complex multiplication +const std::vector equationsWithInput = { + { "ij->ji", ov::test::static_shapes_to_test_representation({ {1, 2} }) }, // transpose 2d + { "ijk->kij", ov::test::static_shapes_to_test_representation({ {1, 2, 3} }) }, // transpose 3d + { "ij->i", ov::test::static_shapes_to_test_representation({ {2, 3} }) }, // reduce + { "ab,cd->abcd", ov::test::static_shapes_to_test_representation({ { 1, 2}, {3, 4} }) }, // no reduction + { "ab,bc->ac", ov::test::static_shapes_to_test_representation({ {2, 3}, {3, 2} }) }, // matrix multiplication + { "ab,bcd,bc->ca", ov::test::static_shapes_to_test_representation({ {2, 4}, {4, 3, 1}, {4, 3} }) }, // multiple multiplications + { "kii->ki", ov::test::static_shapes_to_test_representation({ {1, 3, 3} }) }, // diagonal + { "abbac,bad->ad", ov::test::static_shapes_to_test_representation({ {2, 3, 3, 2, 4}, {3, 2, 1} }) }, // diagonal and multiplication with repeated labels + { "a...->...a", ov::test::static_shapes_to_test_representation({ {2, 2, 3} }) }, // transpose with ellipsis + { "a...->...", ov::test::static_shapes_to_test_representation({ {2, 2, 3} }) }, // reduce with ellipsis + { "ab...,...->ab...", ov::test::static_shapes_to_test_representation({ {2, 2, 3}, {1} }) }, // multiply by scalar + { "a...j,j...->a...", ov::test::static_shapes_to_test_representation({ {1, 1, 4, 3}, {3, 4, 2, 1} }) } // complex multiplication }; INSTANTIATE_TEST_SUITE_P(smoke_Einsum, EinsumLayerTest, - ::testing::Combine(::testing::ValuesIn(precisions), + ::testing::Combine(::testing::ValuesIn(model_types), ::testing::ValuesIn(equationsWithInput), ::testing::Values(ov::test::utils::DEVICE_GPU)), EinsumLayerTest::getTestCaseName); diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/eye.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/eye.cpp similarity index 88% rename from src/plugins/intel_gpu/tests/functional/single_layer_tests/eye.cpp rename to src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/eye.cpp index a347ab6877b16d..d610fc923d8e72 100644 --- a/src/plugins/intel_gpu/tests/functional/single_layer_tests/eye.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/eye.cpp @@ -2,19 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "shared_test_classes/single_layer/eye.hpp" - -using namespace LayerTestsDefinitions; +#include "single_op_tests/eye.hpp" namespace { +using ov::test::EyeLayerTest; -TEST_P(EyeLayerTest, CompareWithRefs) { - SKIP_IF_CURRENT_TEST_IS_DISABLED() - Run(); -} - -const std::vector netPrecisions = - {ElementType::f32, ElementType::f16, ElementType::i32, ElementType::i8, ElementType::u8, ElementType::i64}; +const std::vector model_types = { + ov::element::f32, + ov::element::f16, + ov::element::i32, + ov::element::i8, + ov::element::u8, + ov::element::i64}; const std::vector> eyePars = { // rows, cols, diag_shift @@ -40,7 +39,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_Eye2D_WithNonScalar_Test, ::testing::Combine(::testing::ValuesIn(std::vector>{{{1}, {1}, {1}}}), ::testing::ValuesIn(emptyBatchShape), ::testing::ValuesIn(eyePars), - ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_GPU)), EyeLayerTest::getTestCaseName); @@ -50,7 +49,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_Eye_1DBatch_Test, {{1}, {1}, {1}, {1}}}), ::testing::ValuesIn(batchShapes1D), ::testing::ValuesIn(eyePars), - ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_GPU)), EyeLayerTest::getTestCaseName); @@ -60,7 +59,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_Eye_2DBatch_Test, {{1}, {1}, {1}, {2}}}), ::testing::ValuesIn(batchShapes2D), ::testing::ValuesIn(eyePars), - ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_GPU)), EyeLayerTest::getTestCaseName); @@ -70,7 +69,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_Eye_3DBatch_Test, {{1}, {1}, {1}, {3}}}), ::testing::ValuesIn(batchShapes3D), ::testing::ValuesIn(eyePars), - ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(model_types), ::testing::Values(ov::test::utils::DEVICE_GPU)), EyeLayerTest::getTestCaseName); diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/gather.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/gather.cpp index 4ab3baadfabdad..04b501af6d6a51 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/gather.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/gather.cpp @@ -578,4 +578,32 @@ INSTANTIATE_TEST_SUITE_P( Gather8IndiceScalarLayerTest::getTestCaseName ); +gather7ParamsTuple dummyParams = { + std::vector{2, 3}, + std::vector{2, 2}, + std::tuple{1, 1}, + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::UNSPECIFIED, + InferenceEngine::Precision::UNSPECIFIED, + InferenceEngine::Layout::ANY, + InferenceEngine::Layout::ANY, + ov::test::utils::DEVICE_GPU, +}; + +std::vector> indicesData = { + {0, 1, 2, 0}, // positive in bound + {-1, -2, -3, -1}, // negative in bound + {-1, 0, 1, 2}, // positive and negative in bound + {0, 1, 2, 3}, // positive out of bound + {-1, -2, -3, -4}, // negative out of bound + {0, 4, -4, 0}, // positive and negative out of bound +}; + +const auto gatherWithIndicesParams = testing::Combine( + testing::Values(dummyParams), + testing::ValuesIn(indicesData) +); + +INSTANTIATE_TEST_CASE_P(smoke, Gather8withIndicesDataLayerTest, gatherWithIndicesParams, Gather8withIndicesDataLayerTest::getTestCaseName); + } // namespace diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/group_normalization.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/group_normalization.cpp new file mode 100644 index 00000000000000..72bb27eba05c54 --- /dev/null +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/group_normalization.cpp @@ -0,0 +1,41 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#include "single_layer_tests/group_normalization.hpp" + +using namespace ov::test::subgraph; + +namespace { + +const std::vector netPrecisions = { + ov::element::f16, + ov::element::f32, +}; + +const std::vector inputShapes = { + {3, 8, 32, 64}, + {3, 8, 28, 32, 12}, +}; + +const std::vector numGroups = { + 2, 4, +}; + +const std::vector epsilon = { + 0.0025 +}; + +INSTANTIATE_TEST_SUITE_P( + smoke_GroupNormalization, + GroupNormalizationTest, + testing::Combine(testing::ValuesIn(netPrecisions), + ::testing::Values(ov::element::undefined), + ::testing::Values(ov::element::undefined), + testing::ValuesIn(ov::test::static_shapes_to_test_representation(inputShapes)), + testing::ValuesIn(numGroups), + testing::ValuesIn(epsilon), + testing::Values(ov::test::utils::DEVICE_GPU), + testing::Values(ov::AnyMap())), + GroupNormalizationTest::getTestCaseName); + +} // anonymous namespace diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/power.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/power.cpp index d3af6893b3e2f5..951df90937f729 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/power.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/power.cpp @@ -2,47 +2,42 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include "single_layer_tests/power.hpp" +#include "single_op_tests/power.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { +using ov::test::PowerLayerTest; - std::vector>> inShapes = { - {{1, 8}}, - {{2, 16}}, - {{3, 32}}, - {{4, 64}}, - {{5, 128}}, - {{6, 256}}, - {{7, 512}}, - {{8, 1024}} - }; +std::vector> input_shape_static = { + {{1, 8}}, + {{2, 16}}, + {{3, 32}}, + {{4, 64}}, + {{5, 128}}, + {{6, 256}}, + {{7, 512}}, + {{8, 1024}} +}; - std::vector> Power = { - {0.0f}, - {0.5f}, - {1.0f}, - {1.1f}, - {1.5f}, - {2.0f}, - }; +std::vector> powers = { + {0.0f}, + {0.5f}, + {1.0f}, + {1.1f}, + {1.5f}, + {2.0f}, +}; - std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, - }; +std::vector model_types = { + ov::element::f32, + ov::element::f16, +}; - 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_GPU), - ::testing::ValuesIn(Power)), - PowerLayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_power, PowerLayerTest, + ::testing::Combine( + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shape_static)), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(powers), + ::testing::Values(ov::test::utils::DEVICE_GPU)), + PowerLayerTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/get_output_before_activation.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/get_output_before_activation.cpp index 1f3ae389ce87ef..f96f89f19124e8 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/get_output_before_activation.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/get_output_before_activation.cpp @@ -3,32 +3,26 @@ // #include + #include "common_test_utils/test_constants.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { namespace { - std::vector input_sizes = { - 80, - 32, - 64, - 100 - }; +std::vector input_sizes = {80, 32, 64, 100}; - std::vector midLayerTypes { - midOutputType::Mul, - midOutputType::Sub, - midOutputType::Sum - }; +std::vector midLayerTypes{midOutputType::Mul, midOutputType::Sub, midOutputType::Sum}; - std::map additional_config = {}; -} // namespace +ov::AnyMap additional_config = {}; +} // namespace -INSTANTIATE_TEST_SUITE_P(OutputBeforeActivation, OutputBeforeActivation, - ::testing::Combine( - ::testing::Values(ov::test::utils::DEVICE_GPU), - ::testing::Values(InferenceEngine::Precision::FP32), - ::testing::ValuesIn(input_sizes), - ::testing::ValuesIn(midLayerTypes), - ::testing::Values(additional_config)), - OutputBeforeActivation::getTestCaseName); -} // namespace SubgraphTestsDefinitions +INSTANTIATE_TEST_SUITE_P(OutputBeforeActivation, + OutputBeforeActivation, + ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GPU), + ::testing::Values(ov::element::f32), + ::testing::ValuesIn(input_sizes), + ::testing::ValuesIn(midLayerTypes), + ::testing::Values(additional_config)), + OutputBeforeActivation::getTestCaseName); +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/matmul_squeeze_add.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/matmul_squeeze_add.cpp index 04a19a95a61ba7..bfeed0cab84a30 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/matmul_squeeze_add.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/matmul_squeeze_add.cpp @@ -2,46 +2,27 @@ // SPDX-License-Identifier: Apache-2.0 // -#include - -#include "common_test_utils/test_constants.hpp" #include "subgraph_tests/matmul_squeeze_add.hpp" -using namespace SubgraphTestsDefinitions; +#include + +using namespace ov::test; namespace { -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16 -}; - -const std::vector> configs = { - { } -}; - -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(MatmulSqueezeAdd, MatmulSqueezeAddTest, - ::testing::Combine( - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GPU), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(input_shapes), - ::testing::ValuesIn(output_sizes)), - MatmulSqueezeAddTest::getTestCaseName); +const std::vector netPrecisions = {ov::element::f32, ov::element::f16}; + +const std::vector configs = {{}}; + +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(MatmulSqueezeAdd, + MatmulSqueezeAddTest, + ::testing::Combine(::testing::ValuesIn(netPrecisions), + ::testing::Values(ov::test::utils::DEVICE_GPU), + ::testing::ValuesIn(configs), + ::testing::ValuesIn(input_shapes), + ::testing::ValuesIn(output_sizes)), + MatmulSqueezeAddTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/multiply_add.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/multiply_add.cpp index d60cbeb5875472..056a85a926aaa3 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/multiply_add.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/multiply_add.cpp @@ -2,32 +2,29 @@ // SPDX-License-Identifier: Apache-2.0 // -#include - #include "subgraph_tests/multiply_add.hpp" -using namespace SubgraphTestsDefinitions; +#include + +using namespace ov::test; namespace { -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16 -}; +const std::vector input_type = {ov::element::f32, ov::element::f16}; -const std::vector> inputShapes = { - {1, 3}, - {1, 3, 2}, - {1, 3, 2, 5}, - {1, 3, 2, 5, 4}, - {1, 3, 2, 2, 4, 5}, +const std::vector inputShapes = { + {1, 3}, + {1, 3, 2}, + {1, 3, 2, 5}, + {1, 3, 2, 5, 4}, + {1, 3, 2, 2, 4, 5}, }; -INSTANTIATE_TEST_SUITE_P(smoke_MultipleAdd_Nd, MultiplyAddLayerTest, - ::testing::Combine( - ::testing::ValuesIn(inputShapes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GPU)), - MultiplyAddLayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_MultipleAdd_Nd, + MultiplyAddLayerTest, + ::testing::Combine(::testing::ValuesIn(inputShapes), + ::testing::ValuesIn(input_type), + ::testing::Values(ov::test::utils::DEVICE_GPU)), + MultiplyAddLayerTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/perm_conv_perm_concat.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/perm_conv_perm_concat.cpp index 105a37a30f2c37..5eda8a003d8971 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/perm_conv_perm_concat.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/perm_conv_perm_concat.cpp @@ -2,42 +2,41 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include "subgraph_tests/perm_conv_perm_concat.hpp" -#include "common_test_utils/test_constants.hpp" + +#include + namespace { -std::vector> input_shapes { +std::vector input_shapes{ {1, 1, 7, 32}, {1, 1, 8, 16}, }; -std::vector> kernel_shapes { +std::vector kernel_shapes{ {1, 3}, {1, 5}, }; -std::vector output_channels { +std::vector output_channels{ 32, 64, }; -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, -// InferenceEngine::Precision::FP16, -}; +std::vector netPrecisions = {ov::element::f32}; -std::map additional_config = { -}; -} // namespace - -namespace SubgraphTestsDefinitions { - INSTANTIATE_TEST_SUITE_P(smoke_basic, PermConvPermConcat, - ::testing::Combine( - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GPU), - ::testing::ValuesIn(input_shapes), - ::testing::ValuesIn(kernel_shapes), - ::testing::ValuesIn(output_channels), - ::testing::Values(additional_config)), - PermConvPermConcat::getTestCaseName); -} // namespace SubgraphTestsDefinitions +ov::AnyMap additional_config = {}; +} // namespace + +namespace ov { +namespace test { +INSTANTIATE_TEST_SUITE_P(smoke_basic, + PermConvPermConcat, + ::testing::Combine(::testing::ValuesIn(netPrecisions), + ::testing::Values(ov::test::utils::DEVICE_GPU), + ::testing::ValuesIn(input_shapes), + ::testing::ValuesIn(kernel_shapes), + ::testing::ValuesIn(output_channels), + ::testing::Values(additional_config)), + PermConvPermConcat::getTestCaseName); +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/reshape_squeeze_reshape_relu.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/reshape_squeeze_reshape_relu.cpp index 872140ceea815f..78cef86f3b0c09 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/reshape_squeeze_reshape_relu.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/reshape_squeeze_reshape_relu.cpp @@ -2,48 +2,48 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include "subgraph_tests/reshape_squeeze_reshape_relu.hpp" + +#include + #include "common_test_utils/test_constants.hpp" -using namespace SubgraphTestsDefinitions; +using namespace ov::test; namespace { - std::vector inputs_squeeze { - {{1, 1, 3}, {0, 1}}, - {{1, 1, 3}, {1}}, - {{1, 3, 1}, {0, 2}}, - {{3, 1, 1}, {1}}, - {{1, 4, 1, 3}, {0, 2}}, - {{3, 1, 2, 4, 4, 3}, {1}}, - {{1, 1, 1, 1, 1, 3}, {0, 1, 2, 3, 4}}, - {{1}, {0}}, - }; - - std::vector inputs_unsqueeze{ - {{1}, {0}}, - {{1}, {0, 1}}, - {{1}, {0, 1, 2}}, - {{1, 2, 3}, {0}}, - {{1, 1, 3}, {1, 2}}, - {{1, 4, 1, 3}, {0, 2}}, - }; - - std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, - }; - - - const std::vector opTypes = { - ngraph::helpers::SqueezeOpType::SQUEEZE, - ngraph::helpers::SqueezeOpType::UNSQUEEZE - }; - - INSTANTIATE_TEST_SUITE_P(smoke_reshape_squeeze_reshape_relu, ReshapeSqueezeReshapeRelu, - ::testing::Combine( - ::testing::ValuesIn(inputs_squeeze), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GPU), - ::testing::ValuesIn(opTypes)), - ReshapeSqueezeReshapeRelu::getTestCaseName); +std::vector inputs_squeeze{ + {{1, 1, 3}, {0, 1}}, + {{1, 1, 3}, {1}}, + {{1, 3, 1}, {0, 2}}, + {{3, 1, 1}, {1}}, + {{1, 4, 1, 3}, {0, 2}}, + {{3, 1, 2, 4, 4, 3}, {1}}, + {{1, 1, 1, 1, 1, 3}, {0, 1, 2, 3, 4}}, + {{1}, {0}}, +}; + +std::vector inputs_unsqueeze{ + {{1}, {0}}, + {{1}, {0, 1}}, + {{1}, {0, 1, 2}}, + {{1, 2, 3}, {0}}, + {{1, 1, 3}, {1, 2}}, + {{1, 4, 1, 3}, {0, 2}}, +}; + +std::vector input_types = { + ov::element::f32, + ov::element::f16, +}; + +const std::vector opTypes = {ov::test::utils::SqueezeOpType::SQUEEZE, + ov::test::utils::SqueezeOpType::UNSQUEEZE}; + +INSTANTIATE_TEST_SUITE_P(smoke_reshape_squeeze_reshape_relu, + ReshapeSqueezeReshapeRelu, + ::testing::Combine(::testing::ValuesIn(inputs_squeeze), + ::testing::ValuesIn(input_types), + ::testing::Values(ov::test::utils::DEVICE_GPU), + ::testing::ValuesIn(opTypes)), + ReshapeSqueezeReshapeRelu::getTestCaseName); } // namespace diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/split_conv_concat.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/split_conv_concat.cpp index 3d5a1af905130e..5857c2188cfdb2 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/split_conv_concat.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/split_conv_concat.cpp @@ -2,26 +2,21 @@ // SPDX-License-Identifier: Apache-2.0 // -#include - #include "subgraph_tests/split_conv_concat.hpp" -#include "common_test_utils/test_constants.hpp" -using namespace SubgraphTestsDefinitions; +#include + +using namespace ov::test; namespace { -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16 -}; +const std::vector input_types = {ov::element::f32, ov::element::f16}; -INSTANTIATE_TEST_SUITE_P(smoke_NoReshape, SplitConvConcat, - ::testing::Combine( - ::testing::ValuesIn(netPrecisions), - ::testing::Values(std::vector({1, 6, 40, 40})), - ::testing::Values(ov::test::utils::DEVICE_GPU)), - SplitConvConcat::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_NoReshape, + SplitConvConcat, + ::testing::Combine(::testing::ValuesIn(input_types), + ::testing::Values(ov::Shape{1, 6, 40, 40}), + ::testing::Values(ov::test::utils::DEVICE_GPU)), + SplitConvConcat::getTestCaseName); } // namespace - diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/roi_pooling.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/roi_pooling.cpp index eee9451c206413..34ac60f2752c08 100644 --- a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/roi_pooling.cpp +++ b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/roi_pooling.cpp @@ -148,12 +148,9 @@ class ROIPoolingLayerGPUTest : public testing::WithParamInterface(tensor, feat_map_shape[0] - 1, height, width, 1.f, is_roi_max_mode); - break; - } - case ngraph::element::bf16: { - ov::test::utils::fill_data_roi(tensor, feat_map_shape[0] - 1, height, width, 1.f, is_roi_max_mode); + case ov::element::f32: + case ov::element::bf16: { + ov::test::utils::fill_data_roi(tensor, feat_map_shape[0] - 1, height, width, 1.f, is_roi_max_mode); break; } default: diff --git a/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/kv_cache.cpp b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/kv_cache.cpp new file mode 100644 index 00000000000000..a32e97d8e8e0fc --- /dev/null +++ b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/kv_cache.cpp @@ -0,0 +1,217 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "openvino/core/node_vector.hpp" +#include "openvino/core/partial_shape.hpp" +#include "openvino/core/preprocess/pre_post_process.hpp" +#include "openvino/op/concat.hpp" +#include "openvino/op/matmul.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/transpose.hpp" +#include "shared_test_classes/base/layer_test_utils.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "shared_test_classes/base/utils/compare_results.hpp" +#include "transformations/rt_info/decompression.hpp" +#include "subgraphs_builders.hpp" + +using namespace ov::test; + +namespace SubgraphTestsDefinitions { + +using KVCacheTestParams = std::tuple, // input shapes + ov::element::Type, // in/out precision + std::map>; // additional config + +class KVCacheTest : public testing::WithParamInterface, public SubgraphBaseTest { +public: + static std::string get_test_case_name(testing::TestParamInfo obj) { + std::vector input_shapes; + ov::element::Type element_type; + std::map additional_config; + + std::tie(input_shapes, element_type, additional_config) = obj.param; + + std::ostringstream result; + for (const auto& shape : input_shapes) { + result << ov::test::utils::partialShape2str({shape.first}) << "_"; + } + result << "TS="; + for (const auto& shape : input_shapes) { + result << "("; + if (!shape.second.empty()) { + auto itr = shape.second.begin(); + do { + result << ov::test::utils::vec2str(*itr); + } while (++itr != shape.second.end() && result << "_"); + } + result << ")_"; + } + result << "precision=" << element_type << "_"; + result << "config=("; + for (const auto& configEntry : additional_config) { + result << configEntry.first << ", " << configEntry.second << ":"; + } + result << ")"; + + return result.str(); + } + +protected: + void SetUp() override { + targetDevice = ov::test::utils::DEVICE_GPU; + + std::vector input_shapes; + ov::element::Type element_type; + std::map additional_config; + + std::tie(input_shapes, element_type, additional_config) = GetParam(); + + configuration.insert(additional_config.begin(), additional_config.end()); + init_input_shapes(input_shapes); + + inType = outType = element_type; + + function = tests::make_llm_kv_cache_pattern(inputDynamicShapes[0][0], inputDynamicShapes[0][1], inputDynamicShapes[0][3], element_type); + } +}; + +TEST_P(KVCacheTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + run(); +} + +namespace { + +const std::vector precisions = {ov::element::f32, ov::element::f16}; + +const std::vector> input_shapes_basic = { + { + {{-1, 32, -1, 80}, { {1, 32, 0, 80}, {1, 32, 20, 80} }}, + {{-1, -1, 32, 80}, { {1, 20, 32, 80}, {1, 1, 32, 80} }}, + {{-1, 32, -1, -1}, { {1, 32, 1, 20}, {1, 32, 1, 21} }} + }, +}; + +INSTANTIATE_TEST_SUITE_P(smoke_GPU_Dynamic, + KVCacheTest, + ::testing::Combine(::testing::ValuesIn(input_shapes_basic), + ::testing::ValuesIn(precisions), + ::testing::Values(std::map())), + KVCacheTest::get_test_case_name); +} // namespace + +TEST(KVCacheTest, smoke_multipleIterations) { +#if defined(ANDROID) + GTEST_SKIP(); +#endif + auto core = ov::Core(); + + const size_t batch = 1; + const size_t n_heads = 32; + const size_t n_features = 80; + const size_t context_size = 20; + size_t cache_size = 0; + + ov::element::Type element_type = ov::element::f16; + + auto model = tests::make_llm_kv_cache_pattern(batch, n_heads, n_features, element_type); + auto compiled_model = core.compile_model(model, ov::test::utils::DEVICE_GPU, ov::hint::inference_precision(ov::element::f16)); + + auto input0 = model->get_parameters().at(0); + auto input1 = model->get_parameters().at(1); + auto input2 = model->get_parameters().at(2); + auto output0 = model->get_results().at(0); + auto output1 = model->get_results().at(1); + + auto infer_request = compiled_model.create_infer_request(); + auto input0_tensor_remote_io = infer_request.get_tensor(input0); + auto input1_tensor_remote_io = infer_request.get_tensor(input1); + auto input2_tensor_remote_io = infer_request.get_tensor(input2); + auto output0_tensor_remote_io = infer_request.get_tensor(output0); + auto output1_tensor_remote_io = infer_request.get_tensor(output1); + + auto compare_tensors = [&model](const std::vector expected, const std::vector& actual) { + ASSERT_EQ(expected.size(), actual.size()); + ASSERT_EQ(expected.size(), model->get_results().size()); + auto compareMap = ov::test::utils::getCompareMap(); + const auto& results = model->get_results(); + for (size_t j = 0; j < results.size(); j++) { + const auto result = results[j]; + for (size_t i = 0; i < result->get_input_size(); ++i) { + std::shared_ptr inputNode = result->get_input_node_shared_ptr(i); + if (std::dynamic_pointer_cast(inputNode)) { + std::shared_ptr nextNodePtr = inputNode->get_input_node_shared_ptr(0); + if (!ngraph::is_type(nextNodePtr)) { + inputNode = nextNodePtr; + } + } + auto it = compareMap.find(inputNode->get_type_info()); + ASSERT_NE(it, compareMap.end()); + it->second(inputNode, i, expected[j], actual[j], 1e-4f, 1e-4f); + } + } + }; + + { + const ov::Shape kv_cache_size_initial = {batch, n_heads, cache_size, n_features}; + const ov::Shape new_token_size_initial = {batch, context_size, n_heads, n_features}; + const ov::Shape matmul_in_size_initial = {batch, n_heads, context_size, context_size}; + + auto new_token_data = ov::test::utils::create_and_fill_tensor(element_type, new_token_size_initial); + auto matmul_data = ov::test::utils::create_and_fill_tensor(element_type, matmul_in_size_initial); + + auto kv_cache_input = infer_request.get_tensor(input0); + kv_cache_input.set_shape(kv_cache_size_initial); + + auto ref_model = model->clone(); + ngraph::helpers::resize_function(ref_model, {kv_cache_input.get_shape(), new_token_data.get_shape(), matmul_data.get_shape()}); + auto results = ngraph::helpers::interpretFunction(ref_model, {{input0, kv_cache_input}, {input1, new_token_data}, {input2, matmul_data}}); + + infer_request.set_tensor(input0, kv_cache_input); + infer_request.set_tensor(input1, new_token_data); + infer_request.set_tensor(input2, matmul_data); + + infer_request.infer(); + + compare_tensors(results, {infer_request.get_tensor(output0), infer_request.get_tensor(output1)}); + + cache_size += context_size; + } + + const size_t input_tokens = 1; + const size_t niters = 10; + const ov::Shape new_token_size = {batch, input_tokens, n_heads, n_features}; + size_t context_length = cache_size + input_tokens; + for (size_t i = 0; i < niters; i++, context_length += input_tokens) { + ov::Shape matmul_in_size_loop = {batch, n_heads, input_tokens, context_length}; + auto new_token_data = ov::test::utils::create_and_fill_tensor(element_type, new_token_size); + auto matmul_data = ov::test::utils::create_and_fill_tensor(element_type, matmul_in_size_loop); + + auto kv_cache_input = infer_request.get_tensor(output0); + auto kv_shape = kv_cache_input.get_shape(); + + auto ref_model = model->clone(); + ngraph::helpers::resize_function(ref_model, {kv_shape, new_token_data.get_shape(), matmul_data.get_shape()}); + auto results = ngraph::helpers::interpretFunction(ref_model, {{input0, kv_cache_input}, {input1, new_token_data}, {input2, matmul_data}}); + + auto new_token_input = infer_request.get_tensor(input1); + new_token_input.set_shape(new_token_data.get_shape()); + auto matmul_input = infer_request.get_tensor(input2); + matmul_input.set_shape(matmul_data.get_shape()); + + new_token_data.copy_to(new_token_input); + matmul_data.copy_to(matmul_input); + + infer_request.set_tensor(input0, kv_cache_input); + infer_request.set_tensor(input1, new_token_input); + infer_request.set_tensor(input2, matmul_input); + + infer_request.infer(); + + compare_tensors(results, {infer_request.get_tensor(output0), infer_request.get_tensor(output1)}); + } +} + +} // namespace SubgraphTestsDefinitions diff --git a/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/matmul_weights_decompression.cpp b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/matmul_weights_decompression.cpp index 313015da3406ba..75bdb9f0ec71a7 100644 --- a/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/matmul_weights_decompression.cpp +++ b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/matmul_weights_decompression.cpp @@ -2,19 +2,21 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ov_models/builders.hpp" +#include "common_test_utils/ov_tensor_utils.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/matmul.hpp" #include "shared_test_classes/base/layer_test_utils.hpp" #include "shared_test_classes/base/ov_subgraph.hpp" #include "transformations/rt_info/decompression.hpp" -using namespace ngraph; +using namespace ov; using namespace ov::test; namespace SubgraphTestsDefinitions { /* - * Subtract_const(U8) + * Subtract_const(U8/NF4/U4) * / - * Weights(U8) Convert(F32) + * Weights(U8/NF4/U4) Convert(F32) * | / * Convert(F32) Reshape(optional) * \ / Multiply_const(F32) @@ -29,7 +31,20 @@ namespace SubgraphTestsDefinitions { * | * Bias */ -using MatmulWeightsDecompressionParams = std::tuple, // input shapes + +struct ShapeParams { + ShapeParams() = default; + ShapeParams(InputShape data_shape, ov::Shape weights_shape, int weights_group_size = -1) + : data_shape(std::move(data_shape)), + weights_shape(std::move(weights_shape)), + weights_group_size(weights_group_size) {} + + InputShape data_shape; + ov::Shape weights_shape; + // Decompression group size. If the value is equal to -1, ordinary decompression is used + int weights_group_size; +}; +using MatmulWeightsDecompressionParams = std::tuple, // class MatmulWeightsDecompression : public testing::WithParamInterface, public SubgraphBaseTest { public: static std::string get_test_case_name(testing::TestParamInfo obj) { - std::vector inputShapes; + ShapeParams shape_params; ov::test::ElementType weights_precision; ov::test::ElementType activations_precision; bool transpose; @@ -48,7 +63,7 @@ class MatmulWeightsDecompression : public testing::WithParamInterface additional_config; - std::tie(inputShapes, + std::tie(shape_params, weights_precision, activations_precision, transpose, @@ -57,20 +72,9 @@ class MatmulWeightsDecompression : public testing::WithParamInterface init_subgraph(std::vector& inputShapes, - const ov::element::Type data_precision, - const ov::element::Type weights_precision, - const bool transpose_weights, - const bool add_subtract, - const bool reshape_on_decompression) { - ov::ParameterVector params{std::make_shared(data_precision, inputShapes[0])}; + std::shared_ptr init_subgraph(const ov::PartialShape& data_shape, + const ov::Shape& weights_shape, + const int group_size, + const ov::element::Type data_precision, + const ov::element::Type weights_precision, + const bool transpose_weights, + const bool add_subtract, + const bool reshape_on_decompression) { + ov::ParameterVector params{std::make_shared(data_precision, data_shape)}; + const auto weights_subgraph = init_compressed_weights_subgraph(weights_shape, + group_size, + data_precision, + weights_precision, + transpose_weights, + add_subtract, + reshape_on_decompression); + + auto mat_mul = std::make_shared(params[0], weights_subgraph); + return std::make_shared(NodeVector{mat_mul}, params, "MatmulWeightsDecompression"); + } + + std::shared_ptr init_compressed_weights_subgraph(const ov::Shape& weights_shape, + const int group_size, + const ov::element::Type data_precision, + const ov::element::Type weights_precision, + const bool transpose_weights, + const bool add_subtract, + const bool reshape_on_decompression_constant) { auto transpose_if_necessary = [&](const ov::Shape& shape) { - if (!transpose_weights) - return shape; - auto transposed_shape = shape; - std::swap(*transposed_shape.rbegin(), *(transposed_shape.rbegin() + 1)); - return transposed_shape; + auto result_shape = shape; + if (transpose_weights) + std::swap(*result_shape.rbegin(), *(result_shape.rbegin() + 1)); + return result_shape; }; - auto weights_shape = transpose_if_necessary(inputShapes[1].to_shape()); - auto weights = ngraph::builder::makeConstant(weights_precision, weights_shape, {}, true); + const bool group_decompression = group_size != -1; + // Weights has shape [I, O], where + // I - input channels + // O - output channels + // In case of group decompression, input channels dimension is split into 2: I -> [N, G], where + // N - number of groups + // G - group size + auto transformed_weights_shape = transpose_if_necessary(weights_shape); + if (group_decompression) { + OPENVINO_ASSERT(weights_shape[0] % group_size == 0, + "Weights output channels count (", + weights_shape[0], + ") must be divisible by decompression group size (", + group_size, + ")."); + auto in_channel_idx = transpose_weights ? transformed_weights_shape.size() - 1 : transformed_weights_shape.size() - 2; + transformed_weights_shape[in_channel_idx] = weights_shape[0] / group_size; + transformed_weights_shape.insert(transformed_weights_shape.begin() + in_channel_idx + 1, group_size); + } + auto weights_tensor = ov::test::utils::create_and_fill_tensor(weights_precision, transformed_weights_shape); + auto weights = std::make_shared(weights_tensor); weights->set_friendly_name("Compressed_weights"); auto weights_convert = std::make_shared(weights, data_precision); std::shared_ptr mul_parent = weights_convert; - auto output_channels = transpose_weights ? *(weights_shape.rbegin() + 1) : *weights_shape.rbegin(); - auto scaleshift_target_shape = transpose_if_necessary(ov::Shape{1, output_channels}); - auto scaleshift_const_shape = reshape_on_decompression ? ov::Shape{output_channels} : scaleshift_target_shape; + auto output_channels = *weights_shape.rbegin(); + + // Decompression constants shape: + // Ordinary decompression: [O, 1] + // Group decompression: [O, N, 1] + ov::Shape scaleshift_target_shape{output_channels}; + scaleshift_target_shape.insert(scaleshift_target_shape.begin(), group_decompression ? weights_shape[0] / group_size : 1); + scaleshift_target_shape = transpose_if_necessary(scaleshift_target_shape); + if (group_decompression) { + auto in_channel_idx = transpose_weights ? scaleshift_target_shape.size() - 1 : scaleshift_target_shape.size() - 2; + scaleshift_target_shape.insert(scaleshift_target_shape.begin() + in_channel_idx + 1, 1); + } + + auto scaleshift_const_shape = scaleshift_target_shape; + if (reshape_on_decompression_constant) + scaleshift_const_shape.erase(std::remove(scaleshift_const_shape.begin(), scaleshift_const_shape.end(), 1), scaleshift_const_shape.end()); if (add_subtract) { - auto shift_const = ngraph::builder::makeConstant(weights_precision, scaleshift_const_shape, {}, true); + auto shift_tensor = ov::test::utils::create_and_fill_tensor(weights_precision, scaleshift_const_shape); + auto shift_const = std::make_shared(shift_tensor); std::shared_ptr shift_convert = std::make_shared(shift_const, data_precision); - if (reshape_on_decompression) { + if (reshape_on_decompression_constant) { auto shift_reshape_const = ov::opset10::Constant::create(ov::element::i32, {scaleshift_target_shape.size()}, scaleshift_target_shape); auto shift_reshape = std::make_shared(shift_convert, shift_reshape_const, false); shift_convert = shift_reshape; @@ -122,32 +179,36 @@ class MatmulWeightsDecompression : public testing::WithParamInterface(weights_convert, shift_convert); } - std::shared_ptr scale_const = ngraph::builder::makeConstant(data_precision, scaleshift_const_shape, {}, true); - if (reshape_on_decompression) { + auto scale_tensor = ov::test::utils::create_and_fill_tensor(data_precision, scaleshift_const_shape, 1, -0.5, 10000); + std::shared_ptr scale_const = std::make_shared(scale_tensor); + if (reshape_on_decompression_constant) { auto scale_reshape_const = ov::opset10::Constant::create(ov::element::i32, {scaleshift_target_shape.size()}, scaleshift_target_shape); auto scale_reshape = std::make_shared(scale_const, scale_reshape_const, false); scale_const = scale_reshape; } - auto multiply = std::make_shared(mul_parent, scale_const); + std::shared_ptr last_node = std::make_shared(mul_parent, scale_const); - std::shared_ptr matmul_weights = multiply; + if (group_decompression) { + auto reshape_target_shape = transpose_weights ? std::vector{-1, static_cast(weights_shape[0])} + : std::vector{static_cast(weights_shape[0]), -1}; + auto target_shape_node = ov::opset10::Constant::create(ov::element::i32, {reshape_target_shape.size()}, reshape_target_shape); + last_node = std::make_shared(last_node, target_shape_node, false); + } if (transpose_weights) { - const size_t rank = matmul_weights->get_output_partial_shape(0).size(); + const size_t rank = last_node->get_output_partial_shape(0).size(); std::vector order(rank); std::iota(order.begin(), order.end(), 0); std::swap(*order.rbegin(), *(order.rbegin() + 1)); auto transpose_constant = ov::opset10::Constant::create(ov::element::i32, {rank}, order); - auto transpose = std::make_shared(matmul_weights, transpose_constant); - matmul_weights = transpose; + last_node = std::make_shared(last_node, transpose_constant); } - auto matMul = builder::makeMatMul(params[0], matmul_weights); - return std::make_shared(NodeVector{matMul}, params, "MatmulWeightsDecompression"); + return last_node; } void SetUp() override { targetDevice = ov::test::utils::DEVICE_GPU; - std::vector inputShapes; + ShapeParams shape_params; ov::test::ElementType weights_precision; ov::test::ElementType activations_precision; bool transpose_weights; @@ -155,7 +216,7 @@ class MatmulWeightsDecompression : public testing::WithParamInterface additional_config; - std::tie(inputShapes, + std::tie(shape_params, weights_precision, activations_precision, transpose_weights, @@ -164,14 +225,47 @@ class MatmulWeightsDecompression : public testing::WithParamInterface 200) so fp16 representation & math error is larger than default threshold + if (weights_input_channels > 2048) { + abs_threshold = 4.0f; + } else { + abs_threshold = 1.0f; + } + } + } + + void generate_inputs(const std::vector& target_input_static_shapes) override { + inputs.clear(); + const auto& model_inputs = function->inputs(); + for (size_t i = 0; i < model_inputs.size(); ++i) { + const auto& model_input = model_inputs[i]; + ov::Tensor tensor = ov::test::utils::create_and_fill_tensor(model_input.get_element_type(), + target_input_static_shapes[i], + 2, + -1, + 10000); + inputs.insert({model_input.get_node_shared_ptr(), tensor}); + } } - void checkResults() { + void check_results() { const auto& test_param = GetParam(); ov::test::ElementType weights_precision = std::get<1>(test_param); for (const auto& n : compiledModel.get_runtime_model()->get_ordered_ops()) { @@ -185,24 +279,20 @@ class MatmulWeightsDecompression : public testing::WithParamInterface activations_precisions = {ov::element::f32, ov::element::f16}; const std::vector weights_precisions = {ov::element::u8}; -const std::vector> input_shapes_basic = { - {{{-1, -1, -1}, {{1, 4, 16}, {10, 16, 16}}}, {{}, {{16, 32}}}}, - {{{}, {{10, 40, 496}}}, {{}, {{1, 496, 240}}}}, - {{{}, {{1, 4, 48}}}, {{}, {{48, 256}}}}, - {{{}, {{11, 339, 377}}}, {{}, {{377, 335}}}}, - {{{}, {{1, 4, 32}}}, {{}, {{32, 256}}}}, - {{{}, {{1, 4, 512}}}, {{}, {{512, 256}}}}, - {{{}, {{1, 16, 32}}}, {{}, {{32, 64}}}}, - {{{}, {{2, 4, 32}}}, {{}, {{32, 65}}}}, - {{{}, {{3, 12, 768}}}, {{}, {{768, 1024}}}}, - {{{}, {{11, 339, 577}}}, {{}, {{577, 335}}}}, +const std::vector input_shapes_basic = { + {{{-1, -1, -1}, {{1, 4, 16}, {10, 16, 16}}}, {16, 32}}, + {{{}, {{1, 4, 16}}}, {16, 32}, 2ul}, + {{{}, {{1, 4, 16}}}, {1, 16, 32}}, + {{{}, {{10, 40, 496}}}, {1, 496, 240}}, + {{{}, {{1, 4, 48}}}, {48, 256}}, + {{{}, {{11, 339, 377}}}, {377, 335}} }; INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_basic, @@ -216,15 +306,16 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_basic, ::testing::Values(std::map())), MatmulWeightsDecompression::get_test_case_name); -const std::vector> input_shapes_corner_cases_basic = { - {{{-1, -1, -1}, {{1, 4, 16}}}, {{}, {{1, 16, 32}}}}, - {{{}, {{1, 4, 16}}}, {{}, {{1, 16, 32}}}}, - {{{-1, -1, -1}, {{1, 4, 16}}}, {{}, {{16, 32}}}}, - {{{-1, -1, -1, -1}, {{1, 1, 4, 16}}}, {{}, {{1, 1, 16, 32}}}}, - {{{}, {{1, 1, 4, 16}}}, {{}, {{1, 1, 16, 32}}}}, +const std::vector input_shapes_corner_cases_basic = { + {{{-1, -1, -1}, {{1, 4, 16}}}, {1, 16, 32}}, + {{{-1, -1, -1}, {{1, 4, 16}}}, {16, 32}}, + {{{-1, -1, 16}, {{1, 4, 16}}}, {16, 32}, 4}, }; -const std::vector> input_shapes_corner_cases_big = { - {{{-1, -1, -1}, {{10, 40, 480}, {11, 40, 480}}}, {{}, {{1, 480, 256}}}}, +const std::vector input_shapes_corner_cases_big = { + {{{-1, -1, -1}, {{10, 40, 480}, {11, 40, 480}}}, {1, 480, 256}}, + {{{-1, -1, -1}, {{1, 1, 4096}}}, {4096, 4096}, 128}, + {{{-1, -1, -1}, {{1, 1, 4096}}}, {4096, 4096}}, + {{{-1, 4096}, {{1, 4096}}}, {4096, 4096}, 128}, }; const std::vector transpose_weights = {true, false}; @@ -242,7 +333,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_corner_cases_basic, ::testing::Values(std::map{})), MatmulWeightsDecompression::get_test_case_name); -INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_corner_cases_big, +INSTANTIATE_TEST_SUITE_P(MatMulCompressedWeights_corner_cases_big, MatmulWeightsDecompression, ::testing::Combine(::testing::ValuesIn(input_shapes_corner_cases_big), ::testing::ValuesIn(weights_precisions), diff --git a/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/rms_norm_decomposition.cpp b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/rms_norm_decomposition.cpp new file mode 100644 index 00000000000000..2ea4fc415b52f0 --- /dev/null +++ b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/rms_norm_decomposition.cpp @@ -0,0 +1,153 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ov_models/builders.hpp" +#include "shared_test_classes/base/layer_test_utils.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" + +using namespace ngraph; +using namespace ov::test; + +namespace SubgraphTestsDefinitions { +/* + * Input(F32) Const(F32) + * | \ / + * | Power(F32) Const(I64) + * | \ / + * | ReduceMean(F32) + * | | Const(F32) + * | | / + * | Add(F32) + * | | + * | Sqrt(F32) Const(F32) + * | | / + * | Divide(F32) + * | / + * Const(F32) Multiply(F32) + * \ | + * Multiply(F32) + * | + * Convert(F16) + */ +using RMSNormDecompositionParams = std::tuple, // input shapes + ov::test::ElementType, // input precision + std::map>; // additional config + +class RMSNormDecomposition : public testing::WithParamInterface, public SubgraphBaseTest { +public: + static std::string getTestCaseName(testing::TestParamInfo obj) { + std::vector input_shapes; + ElementType input_precision; + std::map additional_config; + + std::tie(input_shapes, input_precision, additional_config) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (const auto& shape : input_shapes) { + result << ov::test::utils::partialShape2str({shape.first}) << "_"; + } + result << ")_TS="; + for (const auto& shape : input_shapes) { + result << "("; + if (!shape.second.empty()) { + auto itr = shape.second.begin(); + do { + result << ov::test::utils::vec2str(*itr); + } while (++itr != shape.second.end() && result << "_"); + } + result << ")_"; + } + result << "input_precision=" << input_precision << "_"; + + result << "config=("; + for (const auto& configEntry : additional_config) { + result << configEntry.first << ", " << configEntry.second << ":"; + } + result << ")"; + + return result.str(); + } + +protected: + std::shared_ptr init_subgraph(std::vector& input_shapes, + const ov::Shape& target_shape, + const ov::element::Type input_precision) { + ov::ParameterVector params{std::make_shared(input_precision, input_shapes[0])}; + + // x^2 + auto power_const = ov::opset10::Constant::create(input_precision, {}, {2.f}); + auto power = std::make_shared(params[0], power_const); + + // ReduceMean(x^2,axes) + auto mean_axes = ov::opset10::Constant::create(ov::element::i64, ov::Shape{1}, {-1}); + auto mean = std::make_shared(power, mean_axes, true); + + // ReduceMean(x^2,axes)+eps + auto eps = ov::opset10::Constant::create(input_precision, {}, {1e-5f}); + auto add_eps = std::make_shared(mean, eps); + + // Sqrt(ReduceMean(x^2,axes)+eps) + auto sqrt = std::make_shared(add_eps); + + // 1/Sqrt(ReduceMean(x^2,axes)+eps) + auto div_const = ov::opset10::Constant::create(input_precision, {}, {1}); + auto div = std::make_shared(div_const, sqrt); + + // x * 1/Sqrt(ReduceMean(x^2,axes)+eps) + auto mul1 = std::make_shared(params[0], div); + + // x * 1/Sqrt(ReduceMean(x^2,axes)+eps) * gamma + auto dim = *target_shape.rbegin(); + auto gamma = ngraph::builder::makeConstant(input_precision, ov::Shape{dim}, std::vector{}, true); + auto mul2 = std::make_shared(gamma, mul1); + + auto comp = std::make_shared(mul2, ov::element::f16); + + return std::make_shared(NodeVector{comp}, params, "RMSNormDecomposition"); + } + + void SetUp() override { + targetDevice = ov::test::utils::DEVICE_GPU; + + std::vector input_shapes; + ElementType input_precision; + std::map additional_config; + + std::tie(input_shapes, input_precision, additional_config) = GetParam(); + + configuration.insert(additional_config.begin(), additional_config.end()); + init_input_shapes(input_shapes); + + inType = outType = input_precision; + + function = init_subgraph(inputDynamicShapes, targetStaticShapes.front().front(), input_precision); + } +}; + +TEST_P(RMSNormDecomposition, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + run(); +} + +namespace { + +const std::vector input_precisions = {ov::element::f32, ov::element::f16}; + +const std::vector> input_shapes_basic = { + {{{-1, -1, 96}, {{1, 4, 96}}}}, + {{{-1, -1, -1}, {{1, 2, 16}}}}, + {{{}, {{1, 2, 6}}}}, + {{{}, {{1, 2, 18}}}}, +}; + +INSTANTIATE_TEST_SUITE_P(smoke_RMSNormDecomposition_basic, + RMSNormDecomposition, + ::testing::Combine(::testing::ValuesIn(input_shapes_basic), + ::testing::ValuesIn(input_precisions), + ::testing::Values(std::map())), + RMSNormDecomposition::getTestCaseName); +} // namespace + +} // namespace SubgraphTestsDefinitions diff --git a/src/plugins/intel_gpu/tests/functional/subgraph_tests/loop.cpp b/src/plugins/intel_gpu/tests/functional/subgraph_tests/loop.cpp new file mode 100644 index 00000000000000..8c7de510531348 --- /dev/null +++ b/src/plugins/intel_gpu/tests/functional/subgraph_tests/loop.cpp @@ -0,0 +1,316 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include +#include +#include +#include "ov_models/utils/ov_helpers.hpp" +#include "shared_test_classes/base/layer_test_utils.hpp" +#include "ov_models/builders.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "common_test_utils/test_constants.hpp" +#include "shared_test_classes/base/utils/ranges.hpp" +#include +#include "shared_test_classes/base/utils/compare_results.hpp" +#include "openvino/pass/constant_folding.hpp" +#include + +using namespace InferenceEngine; +using namespace ov::test; + +namespace GPULayerTestsDefinitions { + +using DynamicShapeLoopParams = typename std::tuple< + bool, + std::tuple< + bool, + int64_t, + int64_t, + int64_t + >, + int64_t, + InputShape, + InferenceEngine::Precision, + std::string, + ov::AnyMap + >; + +/** + * Test case with Dynamic SHAPE version of loop operation. + * Total iteration count is dynamic. + */ +class DynamicShapeLoopTest : public testing::WithParamInterface, + virtual public SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj) { + bool static_iter_num; + bool static_continue_cond; + int64_t max_iter_num; + int64_t dynamic_exit; + int64_t axis; + int64_t start_value; + InputShape data_shapes; + InferenceEngine::Precision data_prc; + std::string targetDevice; + auto args_pack = std::tie(static_iter_num, max_iter_num, dynamic_exit, axis); + ov::Any configuration; + std::tie( + static_continue_cond, + args_pack, + start_value, + data_shapes, + data_prc, + targetDevice, + configuration) = obj.param; + + std::ostringstream result; + result << "static_iter_num=" << std::to_string(static_iter_num) << "_"; + result << "static_continue_cond=" << std::to_string(static_continue_cond) << "_"; + result << "max_iter_num=" << std::to_string(max_iter_num) << "_"; + result << "dynamic_exit=" << std::to_string(dynamic_exit) << "_"; + result << "axis=" << std::to_string(axis) << "_"; + result << "start_value=" << std::to_string(start_value) << "_"; + result << "max_iter_num=" << std::to_string(max_iter_num) << "_"; + result << "IS=("; + result << ov::test::utils::partialShape2str({data_shapes.first}) << "_"; + for (size_t i = 0lu; i < data_shapes.second.size(); i++) { + result << "{"; + result << ov::test::utils::vec2str(data_shapes.second[i]) << "_"; + result << "}_"; + } + result << ")_"; + result << "netPRC=" << data_prc << "_"; + result << "targetDevice=" << targetDevice << "_"; + + auto res_str = result.str(); + std::replace(res_str.begin(), res_str.end(), '-', '_'); + return res_str; + } + +private: + bool static_iter_num; // trip count provided by constant node + bool static_continue_cond; // initial_cond provided by constant node + int64_t max_iter_num; // -1 means infinity loop (expected dynamic exit condition in body) + int64_t dynamic_exit; // -1 means always true + int64_t axis; // -1 means no auto concatenation + int64_t start_value; + InputShape data_shapes; + InferenceEngine::Precision data_prc; + +protected: + void SetUp() override { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + auto args_pack = std::tie(static_iter_num, max_iter_num, dynamic_exit, axis); + std::tie( + static_continue_cond, + args_pack, + start_value, + data_shapes, + data_prc, + targetDevice, + configuration) = GetParam(); + + const auto prc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(data_prc); + const auto inputShape = data_shapes.first; + const auto scalarShape = ngraph::Shape{}; + init_input_shapes({data_shapes}); + + ngraph::ParameterVector params{}; + auto cond_input_create = [¶ms] (ngraph::element::Type prc, const ov::PartialShape &shape, int value = 0, bool is_static = false) + -> std::shared_ptr { + if (is_static) + return std::make_shared(prc, shape.to_shape(), value); + + auto input = std::make_shared(prc, shape); + params.push_back(input); + return input; + }; + + auto start = cond_input_create(prc, inputShape); + start->set_friendly_name("start"); + auto count = cond_input_create(ngraph::element::i64, scalarShape, max_iter_num, static_iter_num); + count->set_friendly_name("count"); + auto skip = cond_input_create(ngraph::element::boolean, scalarShape, true, static_continue_cond); + skip->set_friendly_name("skip"); + + // + // count skip start count skip start + // / / + // ___*___*____ __________*___*____ | idx | data | out | + // | idx in | | ex_val idx in | | 0 | 7 | 7 | + // | | / | | | / | / | | 1 | 7 | 8 | + // | add | | less add | | 2 | 8 | 10 | + // | | true | | | | | | 3 | 10 | 13 | + // | | | | | | | | ~~~~~ * * * ~~~~~ + // | out cnd | | cnd out | + // |___*____*___| |____*_____*________| + // Full loop Dynamic exit loop + // n_iter = count n_iter = ex_val + // + auto b_indx = std::make_shared(ngraph::element::i64, ngraph::Shape{}); + b_indx->set_friendly_name("body_index"); + auto b_data = std::make_shared(prc, inputShape); + b_data->set_friendly_name("body_data"); + auto b_indx_cast = std::make_shared(b_indx, prc); + b_indx_cast->set_friendly_name("body_index_cast"); + auto b_add = std::make_shared(b_data, b_indx_cast); + b_add->set_friendly_name("body_addition"); + + std::shared_ptr b_cond; + if (dynamic_exit == -1) { + b_cond = std::make_shared(ngraph::element::boolean, ngraph::Shape{}, true); + b_cond->set_friendly_name("body_condition"); + } else { + auto b_exit_value = std::make_shared(ngraph::element::i64, scalarShape, dynamic_exit); + b_exit_value->set_friendly_name("body_exit_value"); + b_cond = std::make_shared(b_indx, b_exit_value); + b_cond->set_friendly_name("body_condition_with_exit_value"); + } + + auto body = std::make_shared( + ngraph::OutputVector {b_cond, b_add}, // TODO: check with reverse + ngraph::ParameterVector {b_indx, b_data}); // TODO: check with reverse + body->set_friendly_name("body_network"); + + auto loop = std::make_shared(count, skip); + loop->set_friendly_name("loop"); + loop->set_function(body); + loop->set_special_body_ports({0, 0}); + loop->set_merged_input(b_data, start, b_add); + if (axis == -1) + loop->get_iter_value(b_add, -1); + else + loop->get_concatenated_slices(b_add, 0, 1, 1, -1, axis); + + function = std::make_shared( + ngraph::OutputVector {loop}, + params); + function->set_friendly_name("outer_body_network"); + } +}; + + +TEST_P(DynamicShapeLoopTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + run(); +} + +std::vector netPrecisions = { + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::I32 +}; + +ov::AnyMap netConfigurations = { + {GPUConfigParams::KEY_GPU_ENABLE_LOOP_UNROLLING, PluginConfigParams::NO} +}; + +static const std::vector> dynamic_loop_types_axis_0 { + // GCC4.8 limitation: have to specify type of each element in list + // static_trip_count | max | dynamic_exit | axis + std::tuple{ true , 10, -1, 0 }, // n_iter 10, no dynamic exit +}; + +std::vector inputs_0 = { + InputShape(ov::PartialShape({1, -1, 2}), {{1, 4, 2}, {1, 5, 2}, {1, 10, 2}}), +}; + +INSTANTIATE_TEST_SUITE_P(smoke_DynamicShapeLoop_axis_0, DynamicShapeLoopTest, + testing::Combine( + /* static_continue_cond */ testing::Values(true), + /* args_pack */ testing::ValuesIn(dynamic_loop_types_axis_0), + /* start_value */ testing::Values(0), + /* data_shape */ testing::ValuesIn(inputs_0), + /* data_prc */ testing::ValuesIn(netPrecisions), + /* device */ testing::Values(ov::test::utils::DEVICE_GPU), + /* configuration */ testing::Values(netConfigurations)), + DynamicShapeLoopTest::getTestCaseName); + +static const std::vector> dynamic_loop_types_1 { + // GCC4.8 limitation: have to specify type of each element in list + // static_trip_count | max | dynamic_exit | axis + std::tuple{ true , 5, -1, 1 }, // n_iter 5, no dynamic exit +}; + +std::vector inputs_1 = { + InputShape(ov::PartialShape({-1, 1, 4, -1}), {{2, 1, 4, 10}, {3, 1, 4, 14}, {6, 1, 4, 16}}), +}; + +INSTANTIATE_TEST_SUITE_P(smoke_DynamicShapeLoop_axis_1, DynamicShapeLoopTest, + testing::Combine( + /* static_continue_cond */ testing::Values(true), + /* args_pack */ testing::ValuesIn(dynamic_loop_types_1), + /* start_value */ testing::Values(0), + /* data_shape */ testing::ValuesIn(inputs_1), + /* data_prc */ testing::ValuesIn(netPrecisions), + /* device */ testing::Values(ov::test::utils::DEVICE_GPU), + /* configuration */ testing::Values(netConfigurations)), + DynamicShapeLoopTest::getTestCaseName); + +static const std::vector> dynamic_loop_types_2 { + // GCC4.8 limitation: have to specify type of each element in list + // static_trip_count | max | dynamic_exit | axis + std::tuple{ true , 10, -1, 2 }, // n_iter 10, no dynamic exit +}; + +std::vector inputs_2 = { + InputShape(ov::PartialShape({-1, -1, 1, 6}), {{2, 4, 1, 6}, {10, 40, 1, 6}, {12, 16, 1, 6}}), +}; + +INSTANTIATE_TEST_SUITE_P(smoke_DynamicShapeLoop_axis_2, DynamicShapeLoopTest, + testing::Combine( + /* static_continue_cond */ testing::Values(true), + /* args_pack */ testing::ValuesIn(dynamic_loop_types_2), + /* start_value */ testing::Values(0), + /* data_shape */ testing::ValuesIn(inputs_2), + /* data_prc */ testing::ValuesIn(netPrecisions), + /* device */ testing::Values(ov::test::utils::DEVICE_GPU), + /* configuration */ testing::Values(netConfigurations)), + DynamicShapeLoopTest::getTestCaseName); + +static const std::vector> dynamic_loop_types_no_auto_concat { + // GCC4.8 limitation: have to specify type of each element in list + // static_trip_count | max | dynamic_exit | axis + std::tuple{ true , 10, -1, -1 }, // n_iter 5, no dynamic exit +}; + +std::vector inputs_no_auto_concat = { + InputShape(ov::PartialShape({-1, 1, 6}), {{2, 1, 6}, {10, 1, 6}, {12, 1, 6}}), +}; + +INSTANTIATE_TEST_SUITE_P(smoke_DynamicShapeLoop_no_auto_concat, DynamicShapeLoopTest, + testing::Combine( + /* static_continue_cond */ testing::Values(true), + /* args_pack */ testing::ValuesIn(dynamic_loop_types_no_auto_concat), + /* start_value */ testing::Values(0), + /* data_shape */ testing::ValuesIn(inputs_no_auto_concat), + /* data_prc */ testing::ValuesIn(netPrecisions), + /* device */ testing::Values(ov::test::utils::DEVICE_GPU), + /* configuration */ testing::Values(netConfigurations)), + DynamicShapeLoopTest::getTestCaseName); + +static const std::vector> dynamic_loop_types_dynamic_exit { + // GCC4.8 limitation: have to specify type of each element in list + // static_trip_count | max | dynamic_exit | axis + std::tuple{ true , 5, 3, -1 }, // n_iter 3, dynamic exit on 3 + std::tuple{ true , 5, 7, 1 }, // n_iter 5, dynamic exit not reached + std::tuple{ true , -1, 5, -1 }, // n_iter 5, inf loop with dynamic exit on 5 +}; + +std::vector inputs_dynamic_exit = { + InputShape(ov::PartialShape({-1, 1, 2}), {{4, 1, 2}, {10, 1, 2}, {12, 1, 2}}), +}; + +INSTANTIATE_TEST_SUITE_P(smoke_DynamicShapeLoop_dynamic_exit, DynamicShapeLoopTest, + testing::Combine( + /* static_continue_cond */ testing::Values(true), + /* args_pack */ testing::ValuesIn(dynamic_loop_types_dynamic_exit), + /* start_value */ testing::Values(0), + /* data_shape */ testing::ValuesIn(inputs_dynamic_exit), + /* data_prc */ testing::ValuesIn(netPrecisions), + /* device */ testing::Values(ov::test::utils::DEVICE_GPU), + /* configuration */ testing::Values(netConfigurations)), + DynamicShapeLoopTest::getTestCaseName); + +} // namespace GPULayerTestsDefinitions \ No newline at end of file diff --git a/src/plugins/intel_gpu/tests/unit/CMakeLists.txt b/src/plugins/intel_gpu/tests/unit/CMakeLists.txt index bf9858d1575e6b..1230e57effbd74 100644 --- a/src/plugins/intel_gpu/tests/unit/CMakeLists.txt +++ b/src/plugins/intel_gpu/tests/unit/CMakeLists.txt @@ -23,14 +23,12 @@ file(GLOB_RECURSE SOURCES_MAIN ) if (NOT ENABLE_ONEDNN_FOR_GPU) - set(EXCLUDE_DIR "/onednn/") - foreach (SOURCE_FILE ${SOURCES_MAIN}) - string (FIND ${SOURCE_FILE} ${EXCLUDE_DIR} EXCLUDE_DIR_FOUND) - if (NOT ${EXCLUDE_DIR_FOUND} EQUAL -1) - message (Exclude : ${SOURCE_FILE}) + set(EXCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/onednn/") + foreach (SOURCE_FILE IN LISTS SOURCES_MAIN) + if (SOURCE_FILE MATCHES "${EXCLUDE_DIR}.*") list (REMOVE_ITEM SOURCES_MAIN ${SOURCE_FILE}) endif () - endforeach(SOURCE_FILE) + endforeach() endif() if (MSVC) @@ -82,7 +80,7 @@ elseif((NOT ANDROID) AND (UNIX)) endif() if(ENABLE_SSE42) - ie_sse42_optimization_flags(sse4_2_flags) + ov_sse42_optimization_flags(sse4_2_flags) set_source_files_properties(${SOURCES_ALL} PROPERTIES COMPILE_FLAGS "${sse4_2_flags}") endif() diff --git a/src/plugins/intel_gpu/tests/unit/fusions/convolution_fusion_test.cpp b/src/plugins/intel_gpu/tests/unit/fusions/convolution_fusion_test.cpp index aa5934a710f196..df20a50e33b9b2 100644 --- a/src/plugins/intel_gpu/tests/unit/fusions/convolution_fusion_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/fusions/convolution_fusion_test.cpp @@ -625,6 +625,12 @@ TEST_P(conv_fp32_activation, basic) { reorder("reorder_bfyx", input_info("activation"), p.default_format, data_types::f32) ); + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16 && + p.weights_format == format::gs_oiyx_gsv16) { + GTEST_SKIP(); // Issue: 94154 + } + tolerance = default_tolerance(p.default_type); execute(p); } @@ -635,9 +641,9 @@ INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_fp32_activation, ::testing::ValuesIn( convolution_test_params{ CASE_CONV_FP32_3, 2, 2, 3 }, convolution_test_params{ CASE_CONV_FP32_4, 2, 2, 3 }, - convolution_test_params{ CASE_CONV_FP16_4, 2, 2, 3 }, - convolution_test_params{ CASE_CONV_FP16_4, 2, 2, 3 }, - convolution_test_params{ CASE_CONV_FP16_4, 2, 2, 3 }, + convolution_test_params{ CASE_CONV_FP16_1, 2, 2, 3 }, + convolution_test_params{ CASE_CONV_FP16_2, 2, 2, 3 }, + convolution_test_params{ CASE_CONV_FP16_3, 2, 2, 3 }, convolution_test_params{ CASE_CONV_FP16_4, 2, 2, 3 }, })); @@ -655,6 +661,12 @@ TEST_P(conv_fp32_scale, basic) { reorder("reorder_bfyx", input_info("scale"), p.default_format, data_types::f32) ); + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16 && + p.weights_format == format::gs_oiyx_gsv16) { + GTEST_SKIP(); // Issue: 94154 + } + tolerance = default_tolerance(p.default_type); execute(p); } @@ -685,6 +697,12 @@ TEST_P(conv_fp32_bias, basic) { reorder("reorder_bfyx", input_info("add_bias"), p.default_format, data_types::f32) ); + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16 && + p.weights_format == format::gs_oiyx_gsv16) { + GTEST_SKIP(); // Issue: 94154 + } + tolerance = default_tolerance(p.default_type); execute(p); } @@ -700,7 +718,7 @@ INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_fp32_bias, ::testing::ValuesIn(std::v convolution_test_params{ CASE_CONV_FP16_2, 2, 2, 3 }, convolution_test_params{ CASE_CONV_FP16_3, 2, 2, 3 }, convolution_test_params{ CASE_CONV_FP16_4, 2, 2, 3 }, - convolution_test_params{ CASE_CONV_FP16_10, 2, 2, 3 }, + // convolution_test_params{ CASE_CONV_FP16_10, 2, 2, 3 }, // Issue: 94154 })); class conv_fp32_double_bias : public ConvFusingTest {}; @@ -800,6 +818,12 @@ TEST_P(conv_fp32_prelu_eltwise, basic_sum) { ); tolerance = default_tolerance(p.data_type); + if (engine.get_device_info().supports_immad && p.default_type == data_types::f16) { + tolerance *= 2; + if (p.weights_format == format::gs_oiyx_gsv16) { + GTEST_SKIP(); // Issue: 94154 + } + } execute(p); } @@ -818,6 +842,12 @@ TEST_P(conv_fp32_prelu_eltwise, basic_sum_slope_2) { ); tolerance = default_tolerance(p.data_type); + if (engine.get_device_info().supports_immad && p.default_type == data_types::f16) { + tolerance *= 2; + if (p.weights_format == format::gs_oiyx_gsv16) { + GTEST_SKIP(); // Issue: 94154 + } + } execute(p); } @@ -835,6 +865,12 @@ TEST_P(conv_fp32_prelu_eltwise, basic_prod) { reorder("reorder_bfyx", input_info("eltwise"), p.default_format, data_types::f32) ); + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16 && + p.weights_format == format::gs_oiyx_gsv16) { + GTEST_SKIP(); // Issue: 94154 + } + tolerance = default_tolerance(p.data_type); execute(p); } @@ -854,6 +890,12 @@ TEST_P(conv_fp32_prelu_eltwise, basic_prod_slope_2) { ); tolerance = default_tolerance(p.data_type); + if (engine.get_device_info().supports_immad && p.default_type == data_types::f16) { + tolerance *= 4; + if (p.weights_format == format::gs_oiyx_gsv16) { + GTEST_SKIP(); // Issue: 94154 + } + } execute(p); } @@ -873,6 +915,12 @@ TEST_P(conv_fp32_prelu_eltwise, eltw_broadcast_sum) { ); tolerance = default_tolerance(p.data_type); + if (engine.get_device_info().supports_immad && p.default_type == data_types::f16) { + tolerance *= 2; + if (p.weights_format == format::gs_oiyx_gsv16) { + GTEST_SKIP(); // Issue: 94154 + } + } execute(p); } @@ -891,6 +939,12 @@ TEST_P(conv_fp32_prelu_eltwise, eltw_broadcast_sum_slope_2) { reorder("reorder_bfyx", input_info("eltwise"), p.default_format, data_types::f32) ); + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16 && + p.weights_format == format::gs_oiyx_gsv16) { + GTEST_SKIP(); // Issue: 94154 + } + tolerance = default_tolerance(p.data_type); execute(p); } @@ -911,6 +965,12 @@ TEST_P(conv_fp32_prelu_eltwise, eltw_broadcast_prod) { ); tolerance = default_tolerance(p.data_type); + if (engine.get_device_info().supports_immad && p.default_type == data_types::f16) { + tolerance *= 4; + if (p.weights_format == format::gs_oiyx_gsv16) { + GTEST_SKIP(); // Issue: 94154 + } + } execute(p); } @@ -929,6 +989,12 @@ TEST_P(conv_fp32_prelu_eltwise, eltw_broadcast_prod_slope_2) { reorder("reorder_bfyx", input_info("eltwise"), p.default_format, data_types::f32) ); + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16 && + p.weights_format == format::gs_oiyx_gsv16) { + GTEST_SKIP(); // Issue: 94154 + } + tolerance = default_tolerance(p.data_type); execute(p); } @@ -1129,6 +1195,9 @@ TEST_P(conv_fp32_multi_eltwise_4_clamp, basic) { cfg_fused.set_property(ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ { "conv_prim", conv_impl } })); tolerance = default_tolerance(p.default_type); + if (p.default_type == data_types::f16) { + tolerance *= 4.f; // Issue: 94154 + } execute(p); } @@ -1168,6 +1237,9 @@ TEST_P(conv_fp32_eltwise_fusing_extend_ops, pattern01_simple_sub) { cfg_fused.set_property(ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ { "conv_prim", conv_impl } })); tolerance = default_tolerance(p.default_type); + if (p.default_type == data_types::f16) { + tolerance *= 8.f; // Issue: 94154 + } execute(p); } @@ -1335,7 +1407,16 @@ TEST_P(conv_fp32_multi_eltwise_quantization, basic) { reorder("reorder_bfyx", input_info("eltwise2"), p.default_format, data_types::f32) ); + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16 && + p.weights_format == format::gs_oiyx_gsv16) { + GTEST_SKIP(); // Issue: 94154 + } + tolerance = 1.f; + if (p.default_type == data_types::f16) { + tolerance *= 8.f; // Issue: 94154 + } execute(p); } @@ -1420,7 +1501,15 @@ TEST_P(conv_fp32_swish, basic) { reorder("reorder_bfyx", input_info("mul"), p.default_format, data_types::f32) ); + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16) { + GTEST_SKIP(); // Issue: 94154 + } + tolerance = default_tolerance(p.default_type); + if (p.default_type == data_types::f16) { + tolerance *= 3.f; // Issue: 94154 + } execute(p); } @@ -1784,6 +1873,11 @@ TEST_P(conv_swap_xy_with_eltwise_diff_sizes, basic) { reorder("reorder_bfyx", input_info("sum"), p.default_format, data_types::f16) ); + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16) { + GTEST_SKIP(); // Issue: 94154 + } + tolerance = default_tolerance(p.default_type); execute(p); } @@ -3329,6 +3423,10 @@ TEST_P(conv_gen9_common_conv_fwd_data_1stconv, basic) { ); tolerance = default_tolerance(p.default_type); + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16) { + tolerance *= 2; // Issue: 94154 + } execute(p); } @@ -3438,6 +3536,12 @@ TEST_P(conv_fp32_activation_abs_onednn, basic) { reorder("reorder_bfyx", input_info("activation"), p.default_format, data_types::f32) ); + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16 && + p.weights_format == format::gs_oiyx_gsv16) { + GTEST_SKIP(); // Issue: 94154 + } + tolerance = default_tolerance(p.default_type); execute(p); } @@ -3462,6 +3566,12 @@ TEST_P(conv_fp32_activation_mish_onednn, basic) { ); tolerance = default_tolerance(p.default_type); + if (engine.get_device_info().supports_immad && p.default_type == data_types::f16) { + tolerance *= 4; + if (p.weights_format == format::gs_oiyx_gsv16) { + GTEST_SKIP(); // Issue: 94154 + } + } execute(p); } @@ -3484,6 +3594,12 @@ TEST_P(conv_fp32_activation_swish_onednn, basic) { reorder("reorder_bfyx", input_info("activation"), p.default_format, data_types::f32) ); + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16 && + p.weights_format == format::gs_oiyx_gsv16) { + GTEST_SKIP(); // Issue: 94154 + } + tolerance = default_tolerance(p.default_type); execute(p); } @@ -3508,6 +3624,12 @@ TEST_P(conv_fp32_activation_hswish_onednn, basic) { ); tolerance = default_tolerance(p.default_type); + if (engine.get_device_info().supports_immad && p.default_type == data_types::f16) { + tolerance *= 8; + if (p.weights_format == format::gs_oiyx_gsv16) { + GTEST_SKIP(); // Issue: 94154 + } + } execute(p); } @@ -3530,6 +3652,11 @@ TEST_P(conv_fp32_activation_exp_onednn, basic) { reorder("reorder_bfyx", input_info("activation"), p.default_format, data_types::f32) ); + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16) { + GTEST_SKIP(); // Issue: 94154 + } + tolerance = default_tolerance(p.default_type); execute(p); } @@ -4440,6 +4567,8 @@ TEST_P(conv_after_permute_not_optimizing, basic) { if (!engine.get_device_info().supports_immad) return; + GTEST_SKIP(); // Issue: 94154 + auto p = GetParam(); create_topologies( diff --git a/src/plugins/intel_gpu/tests/unit/fusions/deconvolution_fusion_test.cpp b/src/plugins/intel_gpu/tests/unit/fusions/deconvolution_fusion_test.cpp index 5702b695d359a0..7dba6f2ca7e266 100644 --- a/src/plugins/intel_gpu/tests/unit/fusions/deconvolution_fusion_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/fusions/deconvolution_fusion_test.cpp @@ -240,6 +240,13 @@ TEST_P(deconv_actv, basic) { activation("act", input_info("deconv"), activation_func::relu), reorder("out", input_info("act"), p.default_format, data_types::f32) ); + + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16 && + p.weights_format == format::is_os_yx_isv16_osv16) { + GTEST_SKIP(); // Issue: 94154 + } + // Need much higher tolerance because of deconvolution -> convolution optimization tolerance = 1.f; execute(p); @@ -335,6 +342,12 @@ TEST_P(deconv_bias, basic) { reorder("out", input_info("bias_add"), p.default_format, data_types::f32) ); + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16 && + p.weights_format == format::is_os_yx_isv16_osv16) { + GTEST_SKIP(); // Issue: 94154 + } + // Need much higher tolerance because of deconvolution -> convolution optimization tolerance = 1.f; execute(p); @@ -457,6 +470,13 @@ class deconv_actv_eltw_actv : public DeconvolutionFusingTest { activation("act2", input_info("eltw"), activation_func::relu), reorder("out", input_info("act2"), p.default_format, data_types::f32) ); + + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16 && + p.weights_format == format::is_os_yx_isv16_osv16) { + GTEST_SKIP(); // Issue: 94154 + } + // Need much higher tolerance because of deconvolution -> convolution optimization tolerance = 1.f; execute(p, is_caching_test); @@ -570,6 +590,12 @@ TEST_P(deconv_scale_actv_quant_i8, basic) { if (engine.get_device_info().supports_immad) p.expected_fused_primitives++; + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16 && + p.weights_format == format::is_os_yx_isv16_osv16) { + GTEST_SKIP(); // Issue: 94154 + } + tolerance = 1.f; execute(p); } @@ -681,6 +707,14 @@ TEST_P(deconv_scale_actv_quant_u8_eltw_scale_actv_quant_i8, basic) { input_info("out2_lo"), input_info("out2_hi"), 255, data_types::i8), reorder("out", input_info("quant2"), p.default_format, data_types::f32) ); + + if (engine.get_device_info().supports_immad && + p.default_type == data_types::f16 && + (p.weights_format == format::is_os_yx_isv16_osv16 || + p.weights_format == format::is_os_zyx_isv16_osv16)) { + GTEST_SKIP(); // Issue: 94154 + } + tolerance = 2.1f; execute(p); } diff --git a/src/plugins/intel_gpu/tests/unit/fusions/eltwise_fusion_test.cpp b/src/plugins/intel_gpu/tests/unit/fusions/eltwise_fusion_test.cpp index 50ddb9870e51e2..bf72af9c91837f 100644 --- a/src/plugins/intel_gpu/tests/unit/fusions/eltwise_fusion_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/fusions/eltwise_fusion_test.cpp @@ -124,6 +124,9 @@ TEST_P(eltwise_quantize, u8) { ); tolerance = default_tolerance(data_types::i8); + if (p.default_type == data_types::f16 && p.default_format == format::b_fs_yx_fsv4) { + tolerance *= 2.f; // Issue: 94154 + } execute(p); } @@ -143,6 +146,9 @@ TEST_P(eltwise_quantize, i8_per_channel) { ); tolerance = default_tolerance(data_types::i8); + if (p.default_type == data_types::f16 && p.default_format == format::b_fs_yx_fsv4) { + tolerance *= 11.f; // Issue: 94154 + } execute(p); } diff --git a/src/plugins/intel_gpu/tests/unit/fusions/fusion_test_common.hpp b/src/plugins/intel_gpu/tests/unit/fusions/fusion_test_common.hpp index 0eaf6cbee32543..58694f91d4c3ab 100644 --- a/src/plugins/intel_gpu/tests/unit/fusions/fusion_test_common.hpp +++ b/src/plugins/intel_gpu/tests/unit/fusions/fusion_test_common.hpp @@ -121,7 +121,7 @@ class BaseFusingTest : public ::testing::TestWithParam { VF rnd_vec = rg.generate_random_1d(s.count(), min_random, max_random); set_values(prim, rnd_vec); } else if (l.data_type == data_types::f16) { - VF rnd_vec = rg.generate_random_1d(s.count(), -1, 1); + VF rnd_vec = rg.generate_random_1d(s.count(), -1, 1); set_values(prim, rnd_vec); } else { VF rnd_vec = rg.generate_random_1d(s.count(), -1, 1); diff --git a/src/plugins/intel_gpu/tests/unit/fusions/gather_fusion_test.cpp b/src/plugins/intel_gpu/tests/unit/fusions/gather_fusion_test.cpp index 39022f9f7b870d..c1af88852dde09 100644 --- a/src/plugins/intel_gpu/tests/unit/fusions/gather_fusion_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/fusions/gather_fusion_test.cpp @@ -129,7 +129,7 @@ TEST_P(gather_quantize, basic) { data("in_hi", get_mem(get_per_channel_layout(p), 1, max_random)), data("out_lo", get_mem(get_single_element_layout(p), -127)), data("out_hi", get_mem(get_single_element_layout(p), 127)), - gather("gather_prim", input_info("input"), input_info("gather_indices"), p.axis, p.out_shape), + gather("gather_prim", input_info("input"), input_info("gather_indices"), p.axis, p.dictionary_shape.size(), p.out_shape), quantize("quantize", input_info("gather_prim"), input_info("in_lo"), input_info("in_hi"), input_info("out_lo"), input_info("out_hi"), 255, data_types::i8), reorder("reorder_bfyx", input_info("quantize"), p.default_format, data_types::f32) @@ -172,7 +172,7 @@ TEST_P(gather_eltwise_activation, basic) { input_layout("input", get_input_layout(p)), data("gather_indices", get_mem(get_indices_layout(p), 0, static_cast(get_axis_dim(p) - 1))), data("eltwise_data", get_mem(get_per_channel_layout(p), -10, 10)), - gather("gather_prim", input_info("input"), input_info("gather_indices"), p.axis, p.out_shape), + gather("gather_prim", input_info("input"), input_info("gather_indices"), p.axis, p.dictionary_shape.size(), p.out_shape), activation("activation", input_info("gather_prim"), activation_func::abs), eltwise("eltwise", { input_info("activation"), input_info("eltwise_data") }, eltwise_mode::prod), reorder("reorder_bfyx", input_info("eltwise"), p.default_format, data_types::f32) @@ -220,7 +220,7 @@ TEST_P(gather_eltwise_activation_dynamic, basic) { input_layout("input", get_input_layout(p, true)), input_layout("gather_indices", layout{ ov::PartialShape::dynamic(p.indices_shape.size()), p.data_type, format::bfyx }), input_layout("eltwise_data", get_per_channel_layout(p, true)), - gather("gather_prim", input_info("input"), input_info("gather_indices"), p.axis, p.out_shape), + gather("gather_prim", input_info("input"), input_info("gather_indices"), p.axis, p.dictionary_shape.size(), p.out_shape), activation("activation", input_info("gather_prim"), activation_func::abs), eltwise("eltwise", { input_info("activation"), input_info("eltwise_data") }, eltwise_mode::prod), reorder("reorder_bfyx", input_info("eltwise"), p.default_format, data_types::f32) diff --git a/src/plugins/intel_gpu/tests/unit/fusions/gemm_fusion_test.cpp b/src/plugins/intel_gpu/tests/unit/fusions/gemm_fusion_test.cpp index 19a9deccfc3e33..68d444094f331b 100644 --- a/src/plugins/intel_gpu/tests/unit/fusions/gemm_fusion_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/fusions/gemm_fusion_test.cpp @@ -493,6 +493,9 @@ TEST_P(gemm_2in_act_scale_eltwise, basic) { ); tolerance = default_tolerance(p.default_type); + if (p.default_type == data_types::f16 && p.kernel_name == "gemm_tiled_opt") { + tolerance *= 2.1f; // Issue: 94154 + } execute(p, false); } @@ -511,6 +514,9 @@ TEST_P(gemm_2in_act_scale_eltwise, broadcast_eltwise) { ); tolerance = default_tolerance(p.default_type); + if (p.default_type == data_types::f16 && p.kernel_name == "gemm_tiled_opt") { + tolerance *= 2.1f; // Issue: 94154 + } execute(p, false); } diff --git a/src/plugins/intel_gpu/tests/unit/fusions/loop_fusion_test.cpp b/src/plugins/intel_gpu/tests/unit/fusions/loop_fusion_test.cpp index 6e980ac7d25d8b..a3635bb320f47f 100644 --- a/src/plugins/intel_gpu/tests/unit/fusions/loop_fusion_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/fusions/loop_fusion_test.cpp @@ -31,6 +31,35 @@ struct loop_params { size_t expected_not_fused_primitives; }; + +program::ptr build_program(engine& engine, + topology& body_topology, + primitive_id initial_condition_id, + std::vector output_primitive_maps, + std::vector back_edges) { + std::vector output_names_vec; + for (auto out_map : output_primitive_maps) { + output_names_vec.push_back(out_map.internal_id.pid); + } + + // setup outputs for backedges + for (auto& back_edge : back_edges) { + output_names_vec.push_back(back_edge.from); + } + + // if execution_condition_id is specified, we need to add the id in build_option::outputs + if (!initial_condition_id.empty()) { + output_names_vec.push_back(initial_condition_id); + } + + ExecutionConfig config = get_test_default_config(engine); + config.set_property(ov::intel_gpu::optimize_data(true)); + config.set_property(ov::intel_gpu::custom_outputs(output_names_vec)); + config.set_property(ov::intel_gpu::max_dynamic_batch(1)); + + return program::build_program(engine, body_topology, config, false, false, true); +} + class LoopFusingTest : public ::BaseFusingTest { public: @@ -71,6 +100,8 @@ TEST_P(permute_eltwise_loop, basic) { std::vector output_primitive_maps {loop::io_primitive_map("loop", "body_eltwise", 2)}; std::vector back_edges {loop::backedge_mapping("body_eltwise", "body_eltwise_operand")}; + auto body_program = build_program(engine, body, "", output_primitive_maps, back_edges); + create_topologies( input_layout("input", get_input_layout(p)), data("eltwise_data", get_mem(layout{p.data_type, p.default_format, p.loop_input_shape})), @@ -80,7 +111,7 @@ TEST_P(permute_eltwise_loop, basic) { data("trip_count", trip_count_mem), data("initial_condition", initial_condition_mem), mutable_data("num_iteration", num_iteration_mem), - loop("loop", { input_info("eltwise"), input_info("loop_eltwise_init_values") }, body, + loop("loop", { input_info("num_iteration"), input_info("eltwise"), input_info("loop_eltwise_init_values") }, body_program, "trip_count", "initial_condition", "num_iteration", input_primitive_maps, output_primitive_maps, back_edges, p.loop_trip_count), reorder("output", input_info("loop"), format::bfyx, p.default_type) diff --git a/src/plugins/intel_gpu/tests/unit/module_tests/primitive_comparison_test.cpp b/src/plugins/intel_gpu/tests/unit/module_tests/primitive_comparison_test.cpp index 11d769f322be93..7fafb55beeccb8 100644 --- a/src/plugins/intel_gpu/tests/unit/module_tests/primitive_comparison_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/module_tests/primitive_comparison_test.cpp @@ -89,11 +89,11 @@ TEST(primitive_comparison, fully_connected) { } TEST(primitive_comparison, gather) { - auto gather_prim = gather("gather", input_info("input0"), input_info("input1"), 2, {1, 3, 224, 224}, 1, true); - auto gather_prim_eq = gather("gather_eq", input_info("input0_eq"), input_info("input1_eq"), 2, {1, 3, 224, 224}, 1, true); - auto gather_prim_axis = gather("gather", input_info("input0"), input_info("input1"), 3, {1, 3, 224, 224}, 1, true); - auto gather_prim_batch_dim = gather("gather", input_info("input0"), input_info("input1"), 2, {1, 3, 224, 224}, 2, true); - auto gather_prim_support_neg_ind = gather("gather", input_info("input0"), input_info("input1"), 2, {1, 3, 224, 224}, 1, false); + auto gather_prim = gather("gather", input_info("input0"), input_info("input1"), 2, {}, {1, 3, 224, 224}, 1, true); + auto gather_prim_eq = gather("gather_eq", input_info("input0_eq"), input_info("input1_eq"), 2, {}, {1, 3, 224, 224}, 1, true); + auto gather_prim_axis = gather("gather", input_info("input0"), input_info("input1"), 3, {}, {1, 3, 224, 224}, 1, true); + auto gather_prim_batch_dim = gather("gather", input_info("input0"), input_info("input1"), 2, {}, {1, 3, 224, 224}, 2, true); + auto gather_prim_support_neg_ind = gather("gather", input_info("input0"), input_info("input1"), 2, {}, {1, 3, 224, 224}, 1, false); ASSERT_EQ(gather_prim, gather_prim_eq); ASSERT_NE(gather_prim, gather_prim_axis); diff --git a/src/plugins/intel_gpu/tests/unit/module_tests/shape_predictor_test.cpp b/src/plugins/intel_gpu/tests/unit/module_tests/shape_predictor_test.cpp index e6c78b4fd8513e..5e5caa91cd7d3f 100644 --- a/src/plugins/intel_gpu/tests/unit/module_tests/shape_predictor_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/module_tests/shape_predictor_test.cpp @@ -25,10 +25,10 @@ TEST_P(shape_predictor_tests, prediction) { ShapePredictor sp(&engine, p.buffers_preallocation_ratio); std::pair result; - const auto dt_size = 4; + const auto dt_bitwidth = ov::element::f32.bitwidth(); for (auto& shape : in_shapes) - result = sp.predict_preallocation_shape("dummy_name", shape, dt_size, p.can_reuse_buffer); + result = sp.predict_preallocation_shape("dummy_name", shape, dt_bitwidth, p.can_reuse_buffer); ASSERT_TRUE(result.first == !expected_predicted_shape.empty()); ASSERT_EQ(result.second, expected_predicted_shape); diff --git a/src/plugins/intel_gpu/tests/unit/passes/add_required_reorders_test.cpp b/src/plugins/intel_gpu/tests/unit/passes/add_required_reorders_test.cpp index 4ac5f414c70664..629769d086d9d1 100644 --- a/src/plugins/intel_gpu/tests/unit/passes/add_required_reorders_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/passes/add_required_reorders_test.cpp @@ -41,11 +41,11 @@ TEST(add_required_reorders, input_reorder_inside_shape_of_subgraph) { topology.add(data("data_0", data_0)); topology.add(data("data_1", data_1)); topology.add(shape_of("shape_of", input_info("input"), 4, data_types::i32)); - topology.add(gather("gather0", input_info("shape_of"), input_info("data_0"), 0, {}, 0, true)); + topology.add(gather("gather0", input_info("shape_of"), input_info("data_0"), 0, {}, {}, 0, true)); topology.add(eltwise("eltwise0", {input_info("gather0"), input_info("data_1")}, eltwise_mode::prod, data_types::f32)); topology.add(reshape("reshape0", input_info("eltwise0"), false, {}, ov::PartialShape{1}, reshape::reshape_mode::unsqueeze)); - topology.add(gather("gather1", input_info("shape_of"), input_info("data_0"), 0, {}, 0, true)); + topology.add(gather("gather1", input_info("shape_of"), input_info("data_0"), 0, {}, {}, 0, true)); topology.add(eltwise("eltwise1", {input_info("gather1"), input_info("data_1")}, eltwise_mode::prod, data_types::f32)); topology.add(reshape("reshape1", input_info("eltwise1"), false, {}, ov::PartialShape{1}, reshape::reshape_mode::unsqueeze)); diff --git a/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp b/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp index 4fe7598e8af3d8..6b66075c6db26d 100644 --- a/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp @@ -62,7 +62,7 @@ TEST(mark_shape_of_subgraphs, simple_chain) { topology.add(data("data_0", data_0)); topology.add(data("data_1", data_1)); topology.add(shape_of("shape_of", input_info("input"), data_types::i64)); - topology.add(gather("gather", input_info("shape_of"), input_info("data_0"), 0, {})); + topology.add(gather("gather", input_info("shape_of"), input_info("data_0"), 0, 0, {})); topology.add(eltwise("eltwise", input_info("gather"), input_info("data_1"), eltwise_mode::sum)); topology.add(concatenation("concat", {input_info("eltwise"), input_info("data_1")}, 0)); topology.add(broadcast("broadcast", input_info("input"), input_info("concat"), {}, ov::op::BroadcastType::BIDIRECTIONAL)); @@ -103,7 +103,7 @@ TEST(mark_shape_of_subgraphs, simple_chain_w_reshape_inside_subgraph) { topology.add(data("data_0", data_0)); topology.add(data("data_1", data_1)); topology.add(shape_of("shape_of", input_info("input"), data_types::i64)); - topology.add(gather("gather", input_info("shape_of"), input_info("data_0"), 0, {1})); + topology.add(gather("gather", input_info("shape_of"), input_info("data_0"), 0, 1, {1})); topology.add(reshape("reshape", input_info("gather"), input_info("data_1"), false, ov::PartialShape{2})); topology.add(broadcast("broadcast", input_info("input"), input_info("reshape"), {}, ov::op::BroadcastType::BIDIRECTIONAL)); @@ -129,8 +129,8 @@ TEST(mark_shape_of_subgraphs, parallel_shape_of_subgraphs) { topology.add(data("data_0", data_0)); topology.add(shape_of("shape_of_0", input_info("input"), data_types::i64)); topology.add(shape_of("shape_of_1", input_info("input"), data_types::i64)); - topology.add(gather("gather_0", input_info("shape_of_0"), input_info("data_0"), 0, {})); - topology.add(gather("gather_1", input_info("shape_of_1"), input_info("data_0"), 0, {})); + topology.add(gather("gather_0", input_info("shape_of_0"), input_info("data_0"), 0, 0, {})); + topology.add(gather("gather_1", input_info("shape_of_1"), input_info("data_0"), 0, 0, {})); topology.add(eltwise("eltwise", input_info("gather_0"), input_info("gather_1"), eltwise_mode::sum)); topology.add(reshape("reshape", input_info("input"), input_info("eltwise"), false, ov::PartialShape())); @@ -160,9 +160,9 @@ TEST(mark_shape_of_subgraphs, parallel_shape_of_subgraphs_cascade) { topology.add(data("data_1", data_1)); topology.add(data("data_2", data_2)); topology.add(shape_of("shape_of_0", input_info("input"), data_types::i64)); - topology.add(gather("gather_0", input_info("shape_of_0"), input_info("data_0"), 0, {1})); + topology.add(gather("gather_0", input_info("shape_of_0"), input_info("data_0"), 0, 1, {1})); topology.add(shape_of("shape_of_1", input_info("input"), data_types::i64)); - topology.add(gather("gather_1", input_info("shape_of_1"), input_info("data_0"), 0, {1})); + topology.add(gather("gather_1", input_info("shape_of_1"), input_info("data_0"), 0, 1, {1})); topology.add(scatter_update("scatter_update_0", input_info("gather_0"), input_info("data_0"), input_info("data_0"), 0)); topology.add(scatter_update("scatter_update_1", input_info("gather_1"), input_info("data_0"), input_info("data_0"), 0)); topology.add(strided_slice("strided_slice_1", @@ -171,7 +171,7 @@ TEST(mark_shape_of_subgraphs, parallel_shape_of_subgraphs_cascade) { input_info("scatter_update_1"), input_info("data_0"), {}, {}, {}, {}, {}, {})); topology.add(shape_of("shape_of_2", input_info("input"), data_types::i64)); - topology.add(gather("gather_2", input_info("shape_of_2"), input_info("data_0"), 0, {})); + topology.add(gather("gather_2", input_info("shape_of_2"), input_info("data_0"), 0, 0, {})); topology.add(scatter_update("scatter_update_2", input_info("gather_2"), input_info("data_0"), input_info("data_0"), 0)); topology.add(strided_slice("strided_slice_2", input_info("data_1"), @@ -207,7 +207,7 @@ TEST(mark_shape_of_subgraphs, simple_chain_w_inserted_reorder) { topology.add(input_layout("input", input_layout_dynamic)); topology.add(data("data_0", data_0)); topology.add(shape_of("shape_of", input_info("input"), data_types::i64)); - topology.add(gather("gather", input_info("shape_of"), input_info("data_0"), 0, {1})); + topology.add(gather("gather", input_info("shape_of"), input_info("data_0"), 0, 1, {1})); topology.add(reshape("reshape", input_info("gather"), true, {}, {})); topology.add(reorder("reorder", input_info("reshape"), format::bfyx, data_types::f16)); topology.add(eltwise("eltwise", input_info("reorder"), input_info("data_0"), eltwise_mode::prod)); @@ -237,7 +237,7 @@ TEST(mark_shape_of_subgraphs, concat_with_empty_tensor_inputs) { topology.add(input_layout("input_empty", input_layout_empty)); topology.add(data("data_0", data_0)); topology.add(shape_of("shape_of_01", input_info("input"), data_types::i64)); - topology.add(gather("gather01", input_info("shape_of_01"), input_info("data_0"), 0, {1})); + topology.add(gather("gather01", input_info("shape_of_01"), input_info("data_0"), 0, 1, {1})); topology.add(shape_of("shape_of_02", input_info("input_empty"), data_types::i64)); topology.add(shape_of("shape_of_03", input_info("input_empty"), data_types::i64)); topology.add(concatenation("concat", {input_info("gather01"), input_info("shape_of_02"), input_info("shape_of_03")}, 0)); diff --git a/src/plugins/intel_gpu/tests/unit/passes/prepare_buffer_fusing_test.cpp b/src/plugins/intel_gpu/tests/unit/passes/prepare_buffer_fusing_test.cpp index 1866ddb6c19870..9d7aef3e2b68bf 100644 --- a/src/plugins/intel_gpu/tests/unit/passes/prepare_buffer_fusing_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/passes/prepare_buffer_fusing_test.cpp @@ -633,13 +633,13 @@ TEST(prepare_buffer_fusing, skip_in_place_concat_inside_shape_of_subgraph) { topology.add(data("data_1", data_1)); topology.add(data("data_2", data_2)); topology.add(shape_of("shape_of", input_info("input"), 4, data_types::i32)); - topology.add(gather("gather0", input_info("shape_of"), input_info("data_0"), 0, {}, 0, true)); + topology.add(gather("gather0", input_info("shape_of"), input_info("data_0"), 0, 0, {}, 0, true)); topology.add(reorder("reorder0", input_info("gather0"), format::any, data_types::f32, std::vector(), reorder_mean_mode::subtract, padding(), true)); topology.add(eltwise("eltwise0", input_info("reorder0"), input_info("data_1"), eltwise_mode::prod, broadcast_spec)); topology.add(reshape("reshape0", input_info("eltwise0"), false, {}, ov::PartialShape{1}, reshape::reshape_mode::unsqueeze)); - topology.add(gather("gather1", input_info("shape_of"), input_info("data_0"), 0, {}, 0, true)); + topology.add(gather("gather1", input_info("shape_of"), input_info("data_0"), 0, 0, {}, 0, true)); topology.add(reorder("reorder1", input_info("gather1"), format::any, data_types::f32, std::vector(), reorder_mean_mode::subtract, padding(), true)); topology.add(eltwise("eltwise1", input_info("reorder1"), input_info("data_1"), eltwise_mode::prod, broadcast_spec)); @@ -693,7 +693,7 @@ TEST(prepare_buffer_fusing, test_implicit_crop_and_outerpadding) { topology.add(input_layout("Input", in_input->get_layout())); topology.add(input_layout("Input_idx_1", input_idx1->get_layout())); topology.add(reorder("reorder_input", input_info("Input"), format::bfzyx, data_types::f32)); - topology.add(gather("gather1", input_info("reorder_input"), input_info("Input_idx_1"), axis, ov::Shape{1, 6, 2, 2, 2})); + topology.add(gather("gather1", input_info("reorder_input"), input_info("Input_idx_1"), axis, 5, ov::Shape{1, 6, 2, 2, 2})); topology.add(reorder("gather1_reorder", input_info("gather1"), reorder_layout)); topology.add(reshape("reshape1", input_info("gather1_reorder"), tensor(6, 2, 2, 2))); topology.add(crop("crop", input_info("reorder_input"), tensor{1, 6, 2, 2, 2}, tensor(1, 0, 0, 0, 0))); diff --git a/src/plugins/intel_gpu/tests/unit/passes/prepare_primitive_fusing_test.cpp b/src/plugins/intel_gpu/tests/unit/passes/prepare_primitive_fusing_test.cpp index f19140d24593ff..a5f1d9e4706b36 100644 --- a/src/plugins/intel_gpu/tests/unit/passes/prepare_primitive_fusing_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/passes/prepare_primitive_fusing_test.cpp @@ -528,7 +528,7 @@ TEST(prepare_primitive_fusing, fuse_constant_transposes_removal_check) { input_layout("input", input->get_layout()), data("weights", weights), permute("permute", input_info("weights"), {1, 0}), - reorder("reorder_dt", input_info("permute"), format::bfyx, data_types::f16), + reorder("reorder_dt", input_info("permute"), format::fbyx, data_types::f16), fully_connected("fc", input_info("input"), { "reorder_dt" }, "", data_types::f16) ); @@ -536,13 +536,24 @@ TEST(prepare_primitive_fusing, fuse_constant_transposes_removal_check) { config.set_property(ov::intel_gpu::optimize_data(true)); config.set_property(ov::intel_gpu::allow_new_shape_infer(true)); + if (engine.get_device_info().supports_immad) { + ov::intel_gpu::ImplementationDesc fc_impl = { format::bfyx, "", impl_types::onednn }; + config.set_property(ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ {"fc", fc_impl} })); + } + auto prog = program::build_program(engine, topology, config, false, true); layout_optimizer lo(true); + lo.set_implementation_forcing(config.get_property(ov::intel_gpu::force_implementations)); program_wrapper::apply_opt_pass(*prog, lo); ASSERT_TRUE(!has_node(*prog, "permute")); ASSERT_EQ(prog->get_node("weights").get_output_layout().format, format::fbyx); + + if (engine.get_device_info().supports_immad) { + ASSERT_TRUE(has_node(*prog, "reorder_dt")); + ASSERT_EQ(prog->get_node("reorder_dt").get_output_layout().format, format::bfyx); + } } TEST(prepare_primitive_fusing, fuse_constant_transposes_accuracy_test) { diff --git a/src/plugins/intel_gpu/tests/unit/passes/remove_redundant_reorders_tests.cpp b/src/plugins/intel_gpu/tests/unit/passes/remove_redundant_reorders_tests.cpp index 1d5bdd88209668..ee454a74e96635 100644 --- a/src/plugins/intel_gpu/tests/unit/passes/remove_redundant_reorders_tests.cpp +++ b/src/plugins/intel_gpu/tests/unit/passes/remove_redundant_reorders_tests.cpp @@ -346,13 +346,13 @@ TEST(remove_redundant_reorders, not_to_fuse_concat_with_reorder_inside_shape_of_ topology.add(data("data_1", data_1)); topology.add(data("data_2", data_2)); topology.add(shape_of("shape_of", input_info("input"), 4, data_types::i32)); - topology.add(gather("gather0", input_info("shape_of"), input_info("data_0"), 0, {}, 0, true)); + topology.add(gather("gather0", input_info("shape_of"), input_info("data_0"), 0, {}, {}, 0, true)); topology.add(reorder("reorder0", input_info("gather0"), format::any, data_types::f32, std::vector(), reorder_mean_mode::subtract, padding(), true)); topology.add(eltwise("eltwise0", input_info("reorder0"), input_info("data_1"), eltwise_mode::prod, broadcast_spec)); topology.add(reshape("reshape0", input_info("eltwise0"), false, {}, ov::PartialShape{1}, reshape::reshape_mode::unsqueeze)); - topology.add(gather("gather1", input_info("shape_of"), input_info("data_0"), 0, {}, 0, true)); + topology.add(gather("gather1", input_info("shape_of"), input_info("data_0"), 0, {}, {}, 0, true)); topology.add(reorder("reorder1", input_info("gather1"), format::any, data_types::f32, std::vector(), reorder_mean_mode::subtract, padding(), true)); topology.add(eltwise("eltwise1", input_info("reorder1"), input_info("data_1"), eltwise_mode::prod, broadcast_spec)); diff --git a/src/plugins/intel_gpu/tests/unit/passes/reorder_inputs_test.cpp b/src/plugins/intel_gpu/tests/unit/passes/reorder_inputs_test.cpp index a6efbbc98a5de3..4406605784a22f 100644 --- a/src/plugins/intel_gpu/tests/unit/passes/reorder_inputs_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/passes/reorder_inputs_test.cpp @@ -136,8 +136,8 @@ TEST(reorder_inputs, mixed_ranks_gather) { ov::CoordinateDiff{0, 0}, false)); topology.add(border("pad", { input_info("conv") }, 0, ov::CoordinateDiff{0, 0, 1, 1}, ov::CoordinateDiff{0, 0, 1, 1})); - topology.add(gather("gather1", input_info("pad"), input_info("data1"), 2, { 1, 2, 3, 128, 57 }, 0, false)); - topology.add(gather("gather2", input_info("gather1"), input_info("data2"), 4, { 1, 2, 3, 128, 3, 55 }, 0, false)); + topology.add(gather("gather1", input_info("pad"), input_info("data1"), 2, 4, { 1, 2, 3, 128, 57 }, 0, false)); + topology.add(gather("gather2", input_info("gather1"), input_info("data2"), 4, 5, { 1, 2, 3, 128, 3, 55 }, 0, false)); topology.add(permute("permute", input_info("gather2"), {0, 1, 2, 4, 3, 5})); ExecutionConfig config = get_test_default_config(engine); @@ -155,10 +155,10 @@ TEST(reorder_inputs, mixed_ranks_gather) { auto& gather1_node = prog_impl->get_node("gather1"); auto& gather2_node = prog_impl->get_node("gather2"); - ASSERT_EQ(gather1_node.get_input_layouts()[0].format, format::bfzyx); + ASSERT_EQ(gather1_node.get_input_layouts()[0].format, format::bfyx); ASSERT_EQ(gather1_node.get_output_layout().format, format::bfzyx); - ASSERT_EQ(gather2_node.get_input_layouts()[0].format, format::bfwzyx); + ASSERT_EQ(gather2_node.get_input_layouts()[0].format, format::bfzyx); ASSERT_EQ(gather2_node.get_output_layout().format, format::bfwzyx); } diff --git a/src/plugins/intel_gpu/tests/unit/shape_infer/gather_si_test.cpp b/src/plugins/intel_gpu/tests/unit/shape_infer/gather_si_test.cpp index aedcfb9d4dce5c..a1852c0c4561a5 100644 --- a/src/plugins/intel_gpu/tests/unit/shape_infer/gather_si_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/shape_infer/gather_si_test.cpp @@ -37,7 +37,7 @@ TEST_P(gather_test, shape_infer) { auto input0_layout_prim = std::make_shared("input0", p.in0_layout); auto input1_layout_prim = std::make_shared("input1", p.in1_layout); - auto gather_prim = std::make_shared("output", input_info("input0"), input_info("input1"), p.axis, ov::Shape{}, p.batch_dim); + auto gather_prim = std::make_shared("output", input_info("input0"), input_info("input1"), p.axis, 0, ov::Shape{}, p.batch_dim); cldnn::program prog(engine); diff --git a/src/plugins/intel_gpu/tests/unit/shape_infer/random_uniform_si_test.cpp b/src/plugins/intel_gpu/tests/unit/shape_infer/random_uniform_si_test.cpp index 6597351a0c728c..f41cafc9e2d4f9 100644 --- a/src/plugins/intel_gpu/tests/unit/shape_infer/random_uniform_si_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/shape_infer/random_uniform_si_test.cpp @@ -67,19 +67,19 @@ TEST_P(random_uniform_si_test, shape_infer) { set_values(allocated_mem, {ov::float16(val).to_bits()}); break; case data_types::f32: - set_values(allocated_mem, {static_cast::type>(val)}); + set_values(allocated_mem, {static_cast::value_type>(val)}); break; case data_types::i32: - set_values(allocated_mem, {static_cast::type>(val)}); + set_values(allocated_mem, {static_cast::value_type>(val)}); break; case data_types::i64: - set_values(allocated_mem, {static_cast::type>(val)}); + set_values(allocated_mem, {static_cast::value_type>(val)}); break; case data_types::i8: - set_values(allocated_mem, {static_cast::type>(val)}); + set_values(allocated_mem, {static_cast::value_type>(val)}); break; case data_types::u8: - set_values(allocated_mem, {static_cast::type>(val)}); + set_values(allocated_mem, {static_cast::value_type>(val)}); break; default: break; diff --git a/src/plugins/intel_gpu/tests/unit/shape_infer/range_si_test.cpp b/src/plugins/intel_gpu/tests/unit/shape_infer/range_si_test.cpp index 2430d628aa2c42..b079017d5c12e0 100644 --- a/src/plugins/intel_gpu/tests/unit/shape_infer/range_si_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/shape_infer/range_si_test.cpp @@ -66,19 +66,19 @@ TEST_P(range_si_test, shape_infer) { set_values(prim_mem, {ov::float16(p.vals[idx]).to_bits()}); break; case data_types::f32: - set_values(prim_mem, {static_cast::type>(p.vals[idx])}); + set_values(prim_mem, {static_cast::value_type>(p.vals[idx])}); break; case data_types::i32: - set_values(prim_mem, {static_cast::type>(p.vals[idx])}); + set_values(prim_mem, {static_cast::value_type>(p.vals[idx])}); break; case data_types::i64: - set_values(prim_mem, {static_cast::type>(p.vals[idx])}); + set_values(prim_mem, {static_cast::value_type>(p.vals[idx])}); break; case data_types::i8: - set_values(prim_mem, {static_cast::type>(p.vals[idx])}); + set_values(prim_mem, {static_cast::value_type>(p.vals[idx])}); break; case data_types::u8: - set_values(prim_mem, {static_cast::type>(p.vals[idx])}); + set_values(prim_mem, {static_cast::value_type>(p.vals[idx])}); break; default: break; diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/canonicalization_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/canonicalization_gpu_test.cpp index 400152887e6ce9..933161185c78a8 100644 --- a/src/plugins/intel_gpu/tests/unit/test_cases/canonicalization_gpu_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/test_cases/canonicalization_gpu_test.cpp @@ -220,7 +220,7 @@ TEST(canonicalization, gather) { topology.add(input_layout("data", data_layout)); topology.add(input_layout("indices", indices_layout)); topology.add(gather("gather", input_info("data"), input_info("indices"), params.second.axis, - ov::Shape{}, params.second.batch_dim, params.second.support_neg_ind)); + 0, ov::Shape{}, params.second.batch_dim, params.second.support_neg_ind)); canonicalization_test(topology, "gather", std::get<1>(params.first), std::get<2>(params.first)); } @@ -254,9 +254,9 @@ TEST(canonicalization, fusing_gather_eltwise) { topology.add(input_layout("indices_second", indices_layout_second)); topology.add(input_layout("data", input_mul_layout)); topology.add(gather("gather_first", input_info("input"), input_info("indices_first"), shapes.second.axis, - shapes.second.out_shape, shapes.second.batch_dim, shapes.second.support_neg_ind)); + shapes.second.data_shape.rank().get_length(), shapes.second.out_shape, shapes.second.batch_dim, shapes.second.support_neg_ind)); topology.add(gather("gather_second", input_info("input"), input_info("indices_second"), shapes.second.axis, - shapes.second.out_shape, shapes.second.batch_dim, shapes.second.support_neg_ind)); + shapes.second.data_shape.rank().get_length(), shapes.second.out_shape, shapes.second.batch_dim, shapes.second.support_neg_ind)); topology.add(eltwise("mul", {input_info("gather_first"), input_info("data")}, eltwise_mode::prod)); topology.add(eltwise("add", {input_info("gather_second"), input_info("mul")}, eltwise_mode::sum)); topology.add(reorder("out_reorder", input_info("add"), format::bfyx, data_types::f32)); diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/condition_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/condition_gpu_test.cpp index b42241b23f1e99..fda7c1c41e5c12 100644 --- a/src/plugins/intel_gpu/tests/unit/test_cases/condition_gpu_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/test_cases/condition_gpu_test.cpp @@ -28,6 +28,7 @@ bool is_output_equal(const cldnn::memory::ptr mem, const std::vector& ref) return true; } + topology generate_simple_branch (bool branch_true_false, const primitive_id& id, const primitive_id& input_id, const data_types dt = data_types::f32) { topology branch; @@ -86,14 +87,14 @@ class condition_gpu_basic_test : public ::testing::Test { condition::branch branch_true; { cldnn::topology branch_true_topology = generate_simple_branch(true, cond_id, branch_input_id, dat_dt); - branch_true.inner_program = program::build_program(engine, branch_true_topology, config, true); + branch_true.inner_program = program::build_program(engine, branch_true_topology, config, false, false, true); branch_true.input_map.insert({input_id, branch_input_id}); branch_true.output_map.insert({0, "condi_when_true"}); } condition::branch branch_false; { cldnn::topology branch_false_topology = generate_simple_branch(false, cond_id, branch_input_id, dat_dt); - branch_false.inner_program = program::build_program(engine, branch_false_topology, config, true); + branch_false.inner_program = program::build_program(engine, branch_false_topology, config, false, false, true); branch_false.input_map.insert({input_id, branch_input_id}); branch_false.output_map.insert({0, "condi_when_false"}); } @@ -178,14 +179,14 @@ TEST(condition_gpu, basic_range_equal_comp) { condition::branch branch_true; { cldnn::topology branch_true_topology = generate_simple_branch(true, condi_id, branch_input_id); - branch_true.inner_program = program::build_program(engine, branch_true_topology, config, true); + branch_true.inner_program = program::build_program(engine, branch_true_topology, config, false, false, true); branch_true.input_map.insert({concat_id, branch_input_id}); branch_true.output_map.insert({0, "condi_when_true"}); } condition::branch branch_false; { cldnn::topology branch_false_topology = generate_simple_branch(false, condi_id, branch_input_id); - branch_false.inner_program = program::build_program(engine, branch_false_topology, config, true); + branch_false.inner_program = program::build_program(engine, branch_false_topology, config, false, false, true); branch_false.input_map.insert({concat_id, branch_input_id}); branch_false.output_map.insert({0, "condi_when_false"}); } @@ -258,8 +259,8 @@ TEST(condition_gpu, basic_stacked_ifs) { auto predicate2 = engine.allocate_memory({ data_types::f32, format::bfyx,{ 1, 1, 1, 1 } }); primitive_id input_id = "input"; - primitive_id pred_id = "predicate"; - primitive_id predicate2_id = "predicate2"; + primitive_id pred_id = "predicate"; + primitive_id predicate2_id = "predicate2"; primitive_id branch_input_id = "branch_input"; primitive_id cond_id = "condi"; primitive_id cond2_id = "condi2"; @@ -280,22 +281,22 @@ TEST(condition_gpu, basic_stacked_ifs) { ); condition::branch branch_condi_1_true; - branch_condi_1_true.inner_program = program::build_program(engine, condi_1_true, config, true); + branch_condi_1_true.inner_program = program::build_program(engine, condi_1_true, config, false, false, true); branch_condi_1_true.input_map.insert({input_id, branch_input_id}); branch_condi_1_true.output_map.insert({0, "condi_when_true"}); condition::branch branch_condi_1_false; - branch_condi_1_false.inner_program = program::build_program(engine, condi_1_false, config, true); + branch_condi_1_false.inner_program = program::build_program(engine, condi_1_false, config, false, false, true); branch_condi_1_false.input_map.insert({input_id, branch_input_id}); branch_condi_1_false.output_map.insert({0, "condi_when_false"}); condition::branch branch_condi_2_true; - branch_condi_2_true.inner_program = program::build_program(engine, condi_2_true, config, true); + branch_condi_2_true.inner_program = program::build_program(engine, condi_2_true, config, false, false, true); branch_condi_2_true.input_map.insert({cond_id, branch_input_id}); branch_condi_2_true.output_map.insert({0, "activ_when_true"}); condition::branch branch_condi_2_false; - branch_condi_2_false.inner_program = program::build_program(engine, condi_2_false, config, true); + branch_condi_2_false.inner_program = program::build_program(engine, condi_2_false, config, false, false, true); branch_condi_2_false.input_map.insert({cond_id, branch_input_id}); branch_condi_2_false.output_map.insert({0, "activ_when_false"}); @@ -373,7 +374,7 @@ TEST(condition_gpu, basic_nested_ifs) { data("scale_5_data", scale_5_mem), eltwise("scale_5", { input_info("branch_input1"), input_info("scale_5_data") }, eltwise_mode::prod) ); - nested_true.inner_program = program::build_program(engine, nested_true_topology, config, true); + nested_true.inner_program = program::build_program(engine, nested_true_topology, config, false, false, true); nested_true.input_map.insert({"pooling_when_true", "branch_input1"}); nested_true.output_map.insert({0, "scale_5"}); } @@ -385,7 +386,7 @@ TEST(condition_gpu, basic_nested_ifs) { data("scale_10_data", scale_10_mem), eltwise("scale_10", { input_info("branch_input2"), input_info("scale_10_data") }, eltwise_mode::prod) ); - nested_false.inner_program = program::build_program(engine, nested_false_topology, config, true); + nested_false.inner_program = program::build_program(engine, nested_false_topology, config, false, false, true); nested_false.input_map.insert({"pooling_when_true", "branch_input2"}); nested_false.output_map.insert({0, "scale_10"}); } @@ -399,7 +400,7 @@ TEST(condition_gpu, basic_nested_ifs) { input_layout("predicate2", predicate2->get_layout()), condition( "condi_nested", {input_info("predicate2"), input_info("pooling_when_true")}, nested_true, nested_false) ); - branch_true.inner_program = program::build_program(engine, branch_true_topology, config, true); + branch_true.inner_program = program::build_program(engine, branch_true_topology, config, false, false, true); branch_true.input_map.insert({"input", "branch_input3"}); branch_true.output_map.insert({0, "condi_nested"}); } @@ -411,7 +412,7 @@ TEST(condition_gpu, basic_nested_ifs) { input_layout("branch_input4", { data_types::f32, format::bfyx,{ 1, 1, 4, 1 } }), pooling("pooling_when_false", input_info("branch_input4"), cldnn::pooling_mode::average, { 1, 2 }, { 1, 2 }) ); - branch_false.inner_program = program::build_program(engine, branch_false_topology, config, true); + branch_false.inner_program = program::build_program(engine, branch_false_topology, config, false, false, true); branch_false.input_map.insert({"input", "branch_input4"}); branch_false.output_map.insert({0, "pooling_when_false"}); } @@ -460,21 +461,21 @@ TEST(condition_gpu, negative_predicate_wrong_layout) { auto predicate = engine.allocate_memory({ data_types::f32, format::bfyx,{ 1, 1, 5, 1 } }); primitive_id input_id = "input"; - primitive_id pred_id = "predicate"; + primitive_id pred_id = "predicate"; primitive_id branch_input_id = "branch_input"; primitive_id cond_id = "condi"; condition::branch branch_true; { cldnn::topology branch_true_topology = generate_simple_branch(true, cond_id, branch_input_id, data_types::f32); - branch_true.inner_program = program::build_program(engine, branch_true_topology, config, true); + branch_true.inner_program = program::build_program(engine, branch_true_topology, config, false, false, true); branch_true.input_map.insert({input_id, branch_input_id}); branch_true.output_map.insert({0, "condi_when_true"}); } condition::branch branch_false; { cldnn::topology branch_false_topology = generate_simple_branch(false, cond_id, branch_input_id, data_types::f32); - branch_false.inner_program = program::build_program(engine, branch_false_topology, config, true); + branch_false.inner_program = program::build_program(engine, branch_false_topology, config, false, false, true); branch_false.input_map.insert({input_id, branch_input_id}); branch_false.output_map.insert({0, "condi_when_false"}); } @@ -501,7 +502,7 @@ TEST(condition_gpu, negative_not_same_layouts) { auto predicate = engine.allocate_memory({ data_types::u8, format::bfyx,{ 1, 1, 1, 1 } }); primitive_id input_id = "input"; - primitive_id pred_id = "predicate"; + primitive_id pred_id = "predicate"; primitive_id branch_input_id = "branch_input"; primitive_id cond_id = "condi"; @@ -513,7 +514,7 @@ TEST(condition_gpu, negative_not_same_layouts) { input_layout(branch_input_id, { data_types::f32, format::bfyx,{ 1, 1, 4, 1 } }), pooling(pool_id, input_info(branch_input_id), cldnn::pooling_mode::max, { 1, 2 }, { 1, 2 }) ); - branch_true.inner_program = program::build_program(engine, branch_true_topology, config, true); + branch_true.inner_program = program::build_program(engine, branch_true_topology, config, false, false, true); branch_true.input_map.insert({input_id, branch_input_id}); branch_true.output_map.insert({0, pool_id}); } @@ -526,7 +527,7 @@ TEST(condition_gpu, negative_not_same_layouts) { input_layout(branch_input_id, { data_types::f32, format::bfyx,{ 1, 1, 4, 1 } }), pooling(pool_id, input_info(branch_input_id), cldnn::pooling_mode::max, { 1, 4 }, { 1, 4 }) ); - branch_false.inner_program = program::build_program(engine, branch_false_topology, config, true); + branch_false.inner_program = program::build_program(engine, branch_false_topology, config, false, false, true); branch_false.input_map.insert({input_id, branch_input_id}); branch_false.output_map.insert({0, pool_id}); } @@ -566,7 +567,7 @@ TEST(condition_gpu, negative_same_names_within_different_networks) { input_layout(branch_input_id, { data_types::f32, format::bfyx,{ 1, 1, 4, 1 } }), pooling(duplicated_id, input_info(branch_input_id), cldnn::pooling_mode::max, { 2, 1 }, { 2, 1 }) ); - branch_true.inner_program = program::build_program(engine, branch_true_topology, config, true); + branch_true.inner_program = program::build_program(engine, branch_true_topology, config, false, false, true); branch_true.input_map.insert({input_id, branch_input_id}); branch_true.output_map.insert({0, duplicated_id}); } @@ -578,7 +579,7 @@ TEST(condition_gpu, negative_same_names_within_different_networks) { input_layout(branch_input_id, { data_types::f32, format::bfyx,{ 1, 1, 4, 1 } }), pooling("pooling_when_false", input_info(branch_input_id), cldnn::pooling_mode::max, { 2, 1 }, { 2, 1 }) ); - branch_false.inner_program = program::build_program(engine, branch_false_topology, config, true); + branch_false.inner_program = program::build_program(engine, branch_false_topology, config, false, false, true); branch_false.input_map.insert({input_id, branch_input_id}); branch_false.output_map.insert({0, "pooling_when_false"}); } diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/eltwise_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/eltwise_gpu_test.cpp index c1309b720daf16..5da00e8fb739f3 100644 --- a/src/plugins/intel_gpu/tests/unit/test_cases/eltwise_gpu_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/test_cases/eltwise_gpu_test.cpp @@ -2482,7 +2482,7 @@ TEST(eltwise_gpu_int, div_gather_fusing) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add(input_layout("Input3", input3->get_layout())); - topology.add(gather("gather", input_info("InputDictionary"), input_info("InputText"), 0, ov::Shape{2, 2, 2, 2})); + topology.add(gather("gather", input_info("InputDictionary"), input_info("InputText"), 0, 4, ov::Shape{2, 2, 2, 2})); topology.add(reorder("gather_reorder", input_info("gather"), { data_types::i32, format::bfyx, { 2, 2, 2, 2 } })); topology.add(eltwise("eltwise", { input_info("gather_reorder"), input_info("Input3") }, diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp index 71301447bb28b9..dc23440c48af67 100644 --- a/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp @@ -663,21 +663,22 @@ TEST(fully_connected_gpu, compressed_scale_zp_bias) { auto& engine = get_test_engine(); auto input_mem = engine.allocate_memory({ {1, 2, 4}, data_types::f32, format::bfyx }); - auto weights_mem = engine.allocate_memory({ {8, 4}, data_types::f32, format::bfyx }); + auto weights_mem = engine.allocate_memory({ {8, 4}, data_types::u8, format::bfyx }); auto bias_mem = engine.allocate_memory({ {1, 1, 8}, data_types::f32, format::bfyx }); - auto scale_mem = engine.allocate_memory({ {1, 1, 8}, data_types::f32, format::bfyx }); - auto zp_mem = engine.allocate_memory({ {1, 1, 8}, data_types::f32, format::bfyx }); + auto scale_mem = engine.allocate_memory({ {8, 1}, data_types::f32, format::bfyx }); + auto zp_mem = engine.allocate_memory({ {8, 1}, data_types::f32, format::bfyx }); set_values(input_mem, { -0.5f, 2.0f, 0.5f, 1.0f, 0.5f, -2.0f, -0.5f, -1.0f }); - set_values(weights_mem, { 1.5f, 1.0f, 0.5f, -1.0f, - 0.0f, 0.5f, 0.5f, -0.5f, - -2.0f, -0.5f, 1.0f, 1.5f, - -2.0f, -0.5f, 1.0f, 1.5f, - 2.0f, 0.5f, -1.0f, -1.5f, - 2.0f, 0.5f, -1.0f, -1.5f, - -1.5f, -1.0f, -0.5f, 1.0f, - 0.0f, -0.5f, 0.5f, 0.5f }); + set_values(weights_mem, { 1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12, + 13, 14, 15, 0, + 15, 14, 13, 12, + 11, 10, 9, 8, + 7, 6, 5, 4, + 3, 2, 1, 0}); + set_values(bias_mem, { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, 2.0f }); set_values(scale_mem, { 2.0f, 4.0f, -2.0f, -4.0f, 0.5f, -0.5f, 2.0f, 2.0f }); @@ -709,8 +710,7 @@ TEST(fully_connected_gpu, compressed_scale_zp_bias) { ov::PartialShape expected_shape{1, 2, 8}; ASSERT_EQ(expected_shape, output_mem->get_layout().get_partial_shape()); - std::vector expected_result = {-4.0f, -23.0f, 11.0f, 0.0f, -2.0f, -3.5f, -30.0f, -10.5f, - 6.0f, 19.0f, -5.0f, -8.0f, 12.0f, -8.5f, 44.0f, 14.5f}; + std::vector expected_result = {13.f, 58.f, -51.f, -108.f, 18.5f, -18.f, 1.f, -4.f, -11.f, -62.f, 57.f, 100.f, -8.5f, 6.f, 13.f, 8.f, }; for (size_t i = 0; i < expected_result.size(); i++) { ASSERT_EQ(expected_result[i], output_ptr[i]) << "i = " << i; @@ -721,20 +721,20 @@ TEST(fully_connected_gpu, compressed_scale_bias) { auto& engine = get_test_engine(); auto input_mem = engine.allocate_memory({ {1, 2, 4}, data_types::f32, format::bfyx }); - auto weights_mem = engine.allocate_memory({ {8, 4}, data_types::f32, format::bfyx }); + auto weights_mem = engine.allocate_memory({ {8, 4}, data_types::u8, format::bfyx }); auto bias_mem = engine.allocate_memory({ {1, 1, 8}, data_types::f32, format::bfyx }); auto scale_mem = engine.allocate_memory({ {1, 1, 8}, data_types::f32, format::bfyx }); set_values(input_mem, { -0.5f, 2.0f, 0.5f, 1.0f, 0.5f, -2.0f, -0.5f, -1.0f }); - set_values(weights_mem, { 1.5f, 1.0f, 0.5f, -1.0f, - 0.0f, 0.5f, 0.5f, -0.5f, - -2.0f, -0.5f, 1.0f, 1.5f, - -2.0f, -0.5f, 1.0f, 1.5f, - 2.0f, 0.5f, -1.0f, -1.5f, - 2.0f, 0.5f, -1.0f, -1.5f, - -1.5f, -1.0f, -0.5f, 1.0f, - 0.0f, -0.5f, 0.5f, 0.5f }); + set_values(weights_mem, { 1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12, + 13, 14, 15, 0, + 15, 14, 13, 12, + 11, 10, 9, 8, + 7, 6, 5, 4, + 3, 2, 1, 0}); set_values(bias_mem, { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }); set_values(scale_mem, { 2.0f, 4.0f, -2.0f, -4.0f, 0.5f, -0.5f, 2.0f, 1.0f }); @@ -764,8 +764,7 @@ TEST(fully_connected_gpu, compressed_scale_bias) { ov::PartialShape expected_shape{1, 2, 8}; ASSERT_EQ(expected_shape, output_mem->get_layout().get_partial_shape()); - std::vector expected_result = {2.0f, 1.0f, -1.0f, -12.0f, 4.0f, -5.0f, 6.0f, -8.25f, - 0.0f, -5.0f, 7.0f, 4.0f, 6.0f, -7.0f, 8.0f, -7.75f}; + std::vector expected_result = {19.f, 40.f, 69.f, 54.f, 83.f, 48.f, 37.f, -2.f, -17.f, -44.f, -63.f, -62.f, -73.f, -60.f, -23.f, -14.f }; for (size_t i = 0; i < expected_result.size(); i++) { ASSERT_EQ(expected_result[i], output_ptr[i]) << "i = " << i; @@ -776,19 +775,19 @@ TEST(fully_connected_gpu, compressed_scale_fp16) { auto& engine = get_test_engine(); auto input_mem = engine.allocate_memory({ { 2, 4}, data_types::f16, format::bfyx }); - auto weights_mem = engine.allocate_memory({ {8, 4}, data_types::f16, format::bfyx }); - auto scale_mem = engine.allocate_memory({ {1, 8}, data_types::f16, format::bfyx }); + auto weights_mem = engine.allocate_memory({ {8, 4}, data_types::u8, format::bfyx }); + auto scale_mem = engine.allocate_memory({ {8, 1}, data_types::f16, format::bfyx }); set_values(input_mem, { ov::float16(-0.5f), ov::float16(2.0f), ov::float16(0.5f), ov::float16(1.0f), ov::float16(0.5f), ov::float16(-2.0f), ov::float16(-0.5f), ov::float16(-1.0f) }); - set_values(weights_mem, {ov::float16( 1.5f), ov::float16( 1.0f), ov::float16( 0.5f), ov::float16(-1.0f), - ov::float16( 0.0f), ov::float16( 0.5f), ov::float16( 0.5f), ov::float16(-0.5f), - ov::float16(-2.0f), ov::float16(-0.5f), ov::float16( 1.0f), ov::float16( 1.5f), - ov::float16(-2.0f), ov::float16(-0.5f), ov::float16( 1.0f), ov::float16( 1.5f), - ov::float16( 2.0f), ov::float16( 0.5f), ov::float16(-1.0f), ov::float16(-1.5f), - ov::float16( 2.0f), ov::float16( 0.5f), ov::float16(-1.0f), ov::float16(-1.5f), - ov::float16(-1.5f), ov::float16(-1.0f), ov::float16(-0.5f), ov::float16( 1.0f), - ov::float16( 0.0f), ov::float16(-0.5f), ov::float16(0.5f), ov::float16( 0.5f) }); + set_values(weights_mem, { 1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12, + 13, 14, 15, 0, + 15, 14, 13, 12, + 11, 10, 9, 8, + 7, 6, 5, 4, + 3, 2, 1, 0}); set_values(scale_mem, {ov::float16(2.0f), ov::float16(4.0f), ov::float16(-2.0f), ov::float16(-4.0f), ov::float16(0.5f), ov::float16(-0.5f), ov::float16(2.0f), ov::float16(2.0f)}); @@ -817,8 +816,8 @@ TEST(fully_connected_gpu, compressed_scale_fp16) { ASSERT_EQ(expected_shape, output_mem->get_layout().get_partial_shape()); std::vector expected_result = { - ov::float16(1.0f), ov::float16( 3.0f), ov::float16(-4.0f), ov::float16(-8.0f), ov::float16(-1.0f), ov::float16( 1.0f), ov::float16(-1.0f), ov::float16(-0.5f), - ov::float16(-1.0f), ov::float16(-3.0f), ov::float16( 4.0f), ov::float16( 8.0f), ov::float16( 1.0f), ov::float16(-1.0f), ov::float16( 1.0f), ov::float16( 0.5f)}; + ov::float16(18), ov::float16(84), ov::float16(-66), ov::float16(-116), ov::float16(19.5), ov::float16(-13.5), ov::float16(30), ov::float16(6), + ov::float16(-18), ov::float16(-84), ov::float16(66), ov::float16(116), ov::float16(-19.5), ov::float16(13.5), ov::float16(-30), ov::float16(-6) }; for (size_t i = 0; i < expected_result.size(); i++) { ASSERT_FLOAT_EQ(expected_result[i], output_ptr[i]) << "i = " << i; diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/gather_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/gather_gpu_test.cpp index bbef9e78912d5b..75465b89ae51ff 100644 --- a/src/plugins/intel_gpu/tests/unit/test_cases/gather_gpu_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/test_cases/gather_gpu_test.cpp @@ -88,6 +88,7 @@ class gather8_test : public ::testing::TestWithParam { input_info("reorder0"), input_info("reorder1"), axis, + shape_in[0].size(), ov::Shape(shape_out.begin(), shape_out.end()), batch_dim, true)); @@ -108,7 +109,7 @@ class gather8_test : public ::testing::TestWithParam { planar_topo.add(input_layout("input0", input0->get_layout())); planar_topo.add(input_layout("input1", input1->get_layout())); planar_topo.add( - gather("gather", input_info("input0"), input_info("input1"), axis, ov::Shape(shape_out.begin(), shape_out.end()), batch_dim, true)); + gather("gather", input_info("input0"), input_info("input1"), axis, shape_in[0].size(), ov::Shape(shape_out.begin(), shape_out.end()), batch_dim, true)); network planar_network(engine, planar_topo, get_test_default_config(engine)); planar_network.set_input_data("input0", input0); planar_network.set_input_data("input1", input1); @@ -408,7 +409,7 @@ TEST(gather8_gpu_fp16, d323_axisY_bdim_m1) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{3, 2, 3, 3, 2}, batch_dim, negative_indexes) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 5, ov::Shape{3, 2, 3, 3, 2}, batch_dim, negative_indexes) ); network network(engine, topology, get_test_default_config(engine)); @@ -515,7 +516,7 @@ TEST(gather7_gpu_fp16, d222_axisX_bdim_m1) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{2, 2, 2, 2, 2, 2}, batch_dim) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 6, ov::Shape{2, 2, 2, 2, 2, 2}, batch_dim) ); network network(engine, topology, get_test_default_config(engine)); @@ -626,7 +627,7 @@ TEST(gather7_gpu_fp16, d323_axisY_bdim_m1) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{3, 2, 3, 3, 2}, batch_dim) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 5, ov::Shape{3, 2, 3, 3, 2}, batch_dim) ); network network(engine, topology, get_test_default_config(engine)); @@ -730,7 +731,7 @@ TEST(gather7_gpu_fp16, d44_axisY_bdim1) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{4, 3, 4, 1, 1, 1}, batch_dim) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{4, 3, 4, 1, 1, 1}, batch_dim) ); network network(engine, topology, get_test_default_config(engine)); @@ -805,7 +806,7 @@ TEST(gather7_gpu_fp16, d32_axisF_bdim_m1) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{3, 2, 1, 1}, batch_dim) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{3, 2, 1, 1}, batch_dim) ); network network(engine, topology, get_test_default_config(engine)); @@ -868,7 +869,7 @@ TEST(gather7_gpu_fp16, d32_axisF_bdim1) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{3, 2, 1, 1}, batch_dim) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{3, 2, 1, 1}, batch_dim) ); network network(engine, topology, get_test_default_config(engine)); @@ -930,7 +931,7 @@ TEST(gather7_gpu_fp16, d32_axisF_bdim0) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{3, 3, 2, 1}, batch_dim) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{3, 3, 2, 1}, batch_dim) ); network network(engine, topology, get_test_default_config(engine)); @@ -998,7 +999,7 @@ TEST(gather_gpu_fp16, d14_axisB) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{1, 4, 2, 1}) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{1, 4, 2, 1}) ); network network(engine, topology, get_test_default_config(engine)); @@ -1060,7 +1061,7 @@ TEST(gather_gpu_fp16, d222_axisB) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{2, 2, 2, 2}) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{2, 2, 2, 2}) ); network network(engine, topology, get_test_default_config(engine)); @@ -1121,7 +1122,7 @@ TEST(gather_gpu_fp16, d22_axisY) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{2, 2, 2, 2}) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{2, 2, 2, 2}) ); network network(engine, topology, get_test_default_config(engine)); @@ -1182,7 +1183,7 @@ TEST(gather_gpu_fp16, d22_axisF) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{2, 2, 2, 2}) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{2, 2, 2, 2}) ); network network(engine, topology, get_test_default_config(engine)); @@ -1240,7 +1241,7 @@ TEST(gather_gpu_fp32, d14_axisB) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{1, 4, 2, 1}) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{1, 4, 2, 1}) ); network network(engine, topology, get_test_default_config(engine)); @@ -1301,7 +1302,7 @@ TEST(gather_gpu_fp32, d222_axisB) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{2, 2, 2, 2}) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{2, 2, 2, 2}) ); network network(engine, topology, get_test_default_config(engine)); @@ -1362,7 +1363,7 @@ TEST(gather_gpu_fp32, d22_axisY) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{2, 2, 2, 2}) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{2, 2, 2, 2}) ); network network(engine, topology, get_test_default_config(engine)); @@ -1423,7 +1424,7 @@ TEST(gather_gpu_fp32, d22_axisF) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{2, 2, 2, 2}) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{2, 2, 2, 2}) ); network network(engine, topology, get_test_default_config(engine)); @@ -1484,7 +1485,7 @@ TEST(gather_gpu_int32, d22_axisF) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{2, 2, 2, 2}) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{2, 2, 2, 2}) ); network network(engine, topology, get_test_default_config(engine)); @@ -1542,7 +1543,7 @@ TEST(gather_gpu_int32, d14_axisB) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{1, 4, 2, 1}) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{1, 4, 2, 1}) ); network network(engine, topology, get_test_default_config(engine)); @@ -1603,7 +1604,7 @@ TEST(gather_gpu_int32, d222_axisB) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{2, 2, 2, 2}) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{2, 2, 2, 2}) ); network network(engine, topology, get_test_default_config(engine)); @@ -1664,7 +1665,7 @@ TEST(gather_gpu_int32, d22_axisY) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{2, 2, 2, 2}) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{2, 2, 2, 2}) ); network network(engine, topology, get_test_default_config(engine)); @@ -1728,7 +1729,7 @@ TEST(gather_gpu_fp32, d41_axisB) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{4, 1, 2, 3}) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{4, 1, 2, 3}) ); network network(engine, topology, get_test_default_config(engine)); @@ -1791,7 +1792,7 @@ TEST(gather_gpu_fp32, d41_axisF) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{2, 4, 1, 2}) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{2, 4, 1, 2}) ); network network(engine, topology, get_test_default_config(engine)); @@ -1850,7 +1851,7 @@ TEST(gather_gpu_fp32, d2_axisX) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{2, 2, 1, 2}) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{2, 2, 1, 2}) ); network network(engine, topology, get_test_default_config(engine)); @@ -1900,7 +1901,7 @@ TEST(gather_gpu_fp32, 322_axisF) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{3, 2, 2, 1}) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{3, 2, 2, 1}) ); network network(engine, topology, get_test_default_config(engine)); @@ -1940,7 +1941,7 @@ TEST(gather_gpu_fp32, dynamic_322_axisF) { topology topology; topology.add(input_layout("input1", in1_layout)); topology.add(input_layout("input2", in2_layout)); - topology.add(gather("gather", input_info("input1"), input_info("input2"), axis, ov::Shape{})); + topology.add(gather("gather", input_info("input1"), input_info("input2"), axis, 0, ov::Shape{})); ExecutionConfig config = get_test_default_config(engine); config.set_property(ov::intel_gpu::allow_new_shape_infer(true)); @@ -1983,7 +1984,7 @@ TEST(gather_gpu_fp32, indice_out_of_bound) { topology topology; topology.add(input_layout("input1", in1_layout)); topology.add(input_layout("input2", in2_layout)); - topology.add(gather("gather", input_info("input1"), input_info("input2"), axis, ov::Shape{}, 0, true)); + topology.add(gather("gather", input_info("input1"), input_info("input2"), axis, 0, ov::Shape{}, 0, true)); ExecutionConfig config = get_test_default_config(engine); config.set_property(ov::intel_gpu::allow_new_shape_infer(true)); @@ -2021,7 +2022,7 @@ TEST(gather_cpu_impl_fp32, dynamic_322_axisF) { topology topology; topology.add(input_layout("input1", in1_layout)); topology.add(input_layout("input2", in2_layout)); - topology.add(gather("gather", input_info("input1"), input_info("input2"), axis, ov::Shape{})); + topology.add(gather("gather", input_info("input1"), input_info("input2"), axis, 0, ov::Shape{})); auto config = get_test_default_config(engine); config.set_property(ov::intel_gpu::allow_new_shape_infer(true)); @@ -2071,7 +2072,7 @@ void test_gather_gpu_u8_322_axisF(bool is_caching_test) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{3, 2, 2, 1})); + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{3, 2, 2, 1})); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -2121,7 +2122,7 @@ TEST(gather_single_axis, simple_Baxis) { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{1, 2, 2, 1}) + gather("gather", input_info("InputDictionary"), input_info("InputText"), axis, 4, ov::Shape{1, 2, 2, 1}) ); topology.add(reorder("reorder", input_info("gather"), format::bfyx, data_types::i8)); diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/group_normalization_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/group_normalization_gpu_test.cpp new file mode 100644 index 00000000000000..a13c1d1550882f --- /dev/null +++ b/src/plugins/intel_gpu/tests/unit/test_cases/group_normalization_gpu_test.cpp @@ -0,0 +1,146 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "test_utils.h" +#include "random_generator.hpp" +#include +#include +#include "openvino/reference/group_normalization.hpp" +#include "compilation_context.hpp" + + +using namespace cldnn; +using namespace ::tests; + +namespace { + +typedef std::tuple< +std::vector, // Input shape +std::size_t, // Number of groups +double, // Epsilon +format // First input layout +> +GroupNormalizationParams; + +class GroupNormalizationGPUTest : public ::testing::TestWithParam { +public: + GroupNormalizationGPUTest() = default; + + void SetUp() override { + std::vector input_shape; + const auto& params = GetParam(); + std::tie(input_shape, num_groups_, epsilon_, format_) = params; + std::copy(std::begin(input_shape), std::end(input_shape), std::back_inserter(data_shape_)); + tests::random_generator rg{"GroupNormalizationGPUTest"}; + data_ = rg.generate_random_1d(ov::shape_size(input_shape), -1, 1); + scale_ = rg.generate_random_1d(input_shape[1], -1, 1); + bias_ = rg.generate_random_1d(input_shape[1], -1, 1); + const auto planar_format = format::dimension(format_) == 4 ? format::bfyx : format::bfzyx; + + topology tp; + auto &engine = get_test_engine(); + data_layout_ = layout{data_types::f32, planar_format, tensor{input_shape}}; + scale_bias_layout_ = layout{data_types::f32, planar_format, tensor{1, + static_cast(scale_.size()), 1, 1}}; + + primitive_id reordered_data_primitive = data_primitive_ + "_reordered"; + tp.add(input_layout{data_primitive_, data_layout_}); + tp.add(input_layout{scale_primitive_, scale_bias_layout_}); + tp.add(input_layout{bias_primitive_, scale_bias_layout_}); + tp.add(reorder{reordered_data_primitive, data_primitive_, format_, data_types::f32}); + + auto g = group_normalization{ + "group_normalization_output", + input_info{reordered_data_primitive}, + input_info{scale_primitive_}, + input_info{bias_primitive_}, + static_cast(num_groups_), + epsilon_ + }; + tp.add(g); + tp.add(reorder{"output", input_info("group_normalization_output"), planar_format, data_types::f32}); + + network_ = std::make_shared(engine, tp, get_test_default_config(engine)); + } + + void Test() { + auto &engine = get_test_engine(); + auto data_gpu_mem = engine.allocate_memory(data_layout_); + auto scale_gpu_mem = engine.allocate_memory(scale_bias_layout_); + auto bias_gpu_mem = engine.allocate_memory(scale_bias_layout_); + set_values(data_gpu_mem, data_); + set_values(scale_gpu_mem, scale_); + set_values(bias_gpu_mem, bias_); + network_->set_input_data(data_primitive_, data_gpu_mem); + network_->set_input_data(scale_primitive_, scale_gpu_mem); + network_->set_input_data(bias_primitive_, bias_gpu_mem); + auto outputs = network_->execute(); + auto output = outputs.at("output").get_memory(); + cldnn::mem_lock output_gpu_mem(output, get_test_stream()); + + std::vector reference_output(data_.size()); + ov::reference::group_normalization(data_.data(), scale_.data(), bias_.data(), reference_output.data(), + ov::Shape{data_shape_}, num_groups_, epsilon_); + + ASSERT_EQ(output_gpu_mem.size(), reference_output.size()); + for (std::size_t i = 0; i < reference_output.size(); i++) { + ASSERT_NEAR(output_gpu_mem[i], reference_output[i], 0.0001); + } + } + +private: + std::vector data_{}; + std::vector scale_{}; + std::vector bias_{}; + std::size_t num_groups_{}; + double epsilon_{}; + format format_{format::any}; + network::ptr network_{}; + layout data_layout_{}; + layout scale_bias_layout_{}; + std::vector data_shape_; + static const primitive_id data_primitive_; + static const primitive_id scale_primitive_; + static const primitive_id bias_primitive_; +}; + +const primitive_id GroupNormalizationGPUTest::data_primitive_{"data"}; +const primitive_id GroupNormalizationGPUTest::scale_primitive_{"scale"}; +const primitive_id GroupNormalizationGPUTest::bias_primitive_{"bias"}; + +TEST_P(GroupNormalizationGPUTest, blocked_layouts_support) { + Test(); +} + +const std::vector f_blocked_4d_formats { + format::b_fs_yx_fsv2, + format::b_fs_yx_fsv4, + format::b_fs_yx_fsv16, + format::b_fs_yx_fsv32, +}; + +const std::vector f_blocked_5d_formats { + format::b_fs_zyx_fsv2, + format::b_fs_zyx_fsv4, + format::b_fs_zyx_fsv16, + format::b_fs_zyx_fsv32, +}; + +INSTANTIATE_TEST_SUITE_P( + GroupNormalizationGPUTest_blocked_layouts_support_4d, GroupNormalizationGPUTest, + ::testing::Combine( + ::testing::Values(std::vector{3, 64, 32, 64}), + ::testing::Values(4), + ::testing::Values(0.0025), + ::testing::ValuesIn(f_blocked_4d_formats))); + +INSTANTIATE_TEST_SUITE_P( + GroupNormalizationGPUTest_blocked_layouts_support_5d, GroupNormalizationGPUTest, + ::testing::Combine( + ::testing::Values(std::vector{3, 64, 28, 32, 12}), + ::testing::Values(4), + ::testing::Values(0.0025), + ::testing::ValuesIn(f_blocked_5d_formats))); + +} // anonymous namespace diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/hash_key_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/hash_key_gpu_test.cpp index b76e45428f9850..68cfc54237737b 100644 --- a/src/plugins/intel_gpu/tests/unit/test_cases/hash_key_gpu_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/test_cases/hash_key_gpu_test.cpp @@ -94,7 +94,7 @@ class check_hash_value: public ::testing::Test { topology.add(input_layout("InputDictionary", input1->get_layout())); topology.add(input_layout("InputText", input2->get_layout())); topology.add( - gather(key_prim_id, input_info("InputDictionary"), input_info("InputText"), axis, ov::Shape{3, 2, 3, 3, 2}, batch_dim, negative_indexes) + gather(key_prim_id, input_info("InputDictionary"), input_info("InputText"), axis, 5, ov::Shape{3, 2, 3, 3, 2}, batch_dim, negative_indexes) ); cldnn::network::ptr net = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -176,7 +176,7 @@ class check_hash_value: public ::testing::Test { const auto params_hash = prim_inst->get_impl_params()->hash(); ASSERT_EQ(primitive_hash, 16293979194373117693UL); - ASSERT_EQ(params_hash, 14231564068060955575UL); + ASSERT_EQ(params_hash, 15950979219660866859UL); } void test_reshape_basic(bool is_caching_test) { diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/loop_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/loop_gpu_test.cpp index 94fb17104275e0..240f0df9980e97 100644 --- a/src/plugins/intel_gpu/tests/unit/test_cases/loop_gpu_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/test_cases/loop_gpu_test.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -23,6 +24,34 @@ using namespace cldnn; using namespace tests; using namespace testing; +static program::ptr build_program(engine& engine, + topology& body_topology, + primitive_id execution_condition_id, + std::vector output_primitive_maps, + std::vector back_edges) { + std::vector output_names_vec; + for (auto out_map : output_primitive_maps) { + output_names_vec.push_back(out_map.internal_id.pid); + } + + // setup outputs for backedges + for (auto& back_edge : back_edges) { + output_names_vec.push_back(back_edge.from); + } + + // if execution_condition_id is specified, we need to add the id in build_option::outputs + if (!execution_condition_id.empty()) { + output_names_vec.push_back(execution_condition_id); + } + + ExecutionConfig config = get_test_default_config(engine); + config.set_property(ov::intel_gpu::optimize_data(true)); + config.set_property(ov::intel_gpu::custom_outputs(output_names_vec)); + config.set_property(ov::intel_gpu::max_dynamic_batch(1)); + + return program::build_program(engine, body_topology, config, false, false, true); +} + template void test_loop_gpu_basic_no_concat(bool is_caching_test) { @@ -52,23 +81,23 @@ void test_loop_gpu_basic_no_concat(bool is_caching_test) set_values(initial_condition_mem, {initial_condition}); topology body( + input_layout("input", input_mem->get_layout()), data("eltwise_operand", operand_mem), eltwise("eltwise", input_info("input"), input_info("eltwise_operand"), eltwise_mode::sum) ); std::vector input_primitive_maps { loop::io_primitive_map("input", "input") }; std::vector output_primitive_maps { loop::io_primitive_map("loop", "eltwise") }; + std::vector back_edges { loop::backedge_mapping("eltwise", "input") }; - std::vector back_edges { - loop::backedge_mapping("eltwise", "input") - }; + auto body_program = build_program(engine, body, "", output_primitive_maps, back_edges); topology topology( input_layout("input", input_mem->get_layout()), input_layout("trip_count", trip_count_mem->get_layout()), input_layout("initial_condition", initial_condition_mem->get_layout()), mutable_data("num_iteration", num_iteration_mem), - loop("loop", { input_info("input") }, body, + loop("loop", { input_info("num_iteration"), input_info("input") }, body_program, "trip_count", "initial_condition", "num_iteration", input_primitive_maps, output_primitive_maps, back_edges, 8) ); @@ -161,15 +190,16 @@ void test_loop_gpu_basic_concat(bool is_caching_test) std::vector input_primitive_maps { loop::io_primitive_map("input", "input", 2) }; std::vector output_primitive_maps { loop::io_primitive_map("loop", "eltwise", 2) }; - std::vector back_edges {}; + auto body_program = build_program(engine, body, "", output_primitive_maps, back_edges); + topology topology( input_layout("input", input_mem->get_layout()), input_layout("trip_count", trip_count_mem->get_layout()), input_layout("initial_condition", initial_condition_mem->get_layout()), mutable_data("num_iteration", num_iteration_mem), - loop("loop", { input_info("input") }, body, + loop("loop", { input_info("num_iteration"), input_info("input") }, body_program, "trip_count", "initial_condition", "num_iteration", input_primitive_maps, output_primitive_maps, back_edges, trip_count) ); @@ -274,6 +304,8 @@ void test_loop_gpu_basic_concat_nested(bool is_caching_test) std::vector inner_output_primitive_maps { loop::io_primitive_map("inner_loop", "inner_eltwise", 2) }; std::vector inner_back_edges {}; + auto inner_body_program = build_program(engine, inner_loop_body, "", inner_output_primitive_maps, inner_back_edges); + ///////////////////////////////// // set outer loop body ///////////////////////////////// @@ -282,8 +314,8 @@ void test_loop_gpu_basic_concat_nested(bool is_caching_test) input_layout("trip_count", inner_trip_count_mem->get_layout()), input_layout("initial_condition", inner_initial_condition_mem->get_layout()), mutable_data("inner_num_iteration", inner_num_iteration_mem), - loop("inner_loop", { input_info("inner_input"), input_info("trip_count"), input_info("initial_condition") }, - inner_loop_body, "trip_count", "initial_condition", "inner_num_iteration", + loop("inner_loop", { input_info("inner_num_iteration"), input_info("inner_input"), input_info("trip_count"), input_info("initial_condition") }, + inner_body_program, "trip_count", "initial_condition", "inner_num_iteration", inner_input_primitive_maps, inner_output_primitive_maps, inner_back_edges, inner_trip_count) ); std::vector outer_input_primitive_maps { @@ -296,6 +328,8 @@ void test_loop_gpu_basic_concat_nested(bool is_caching_test) }; std::vector outer_back_edges { {"inner_loop", "inner_input"} }; + auto outer_body_program = build_program(engine, outer_loop_body, "", outer_output_primitive_maps, outer_back_edges); + ///////////////////////////////// // set main topology ///////////////////////////////// @@ -306,8 +340,8 @@ void test_loop_gpu_basic_concat_nested(bool is_caching_test) mutable_data("num_iteration", num_iteration_mem), input_layout("inner_trip_count", inner_trip_count_mem->get_layout()), input_layout("inner_initial_condition", inner_initial_condition_mem->get_layout()), - loop("loop", { input_info("input"), input_info("inner_trip_count"), input_info("inner_initial_condition") }, - outer_loop_body, "trip_count", "initial_condition", "num_iteration", + loop("loop", { input_info("num_iteration"), input_info("input"), input_info("inner_trip_count"), input_info("inner_initial_condition") }, + outer_body_program, "trip_count", "initial_condition", "num_iteration", outer_input_primitive_maps, outer_output_primitive_maps, outer_back_edges, outer_trip_count) ); diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/permute_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/permute_gpu_test.cpp index 7be1609c64a9c9..ac22cc773f885a 100644 --- a/src/plugins/intel_gpu/tests/unit/test_cases/permute_gpu_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/test_cases/permute_gpu_test.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/core/type/element_type_traits.hpp" #include "test_utils.h" #include "random_generator.hpp" @@ -1924,7 +1925,7 @@ void TiledPermuteTest::run_test(const std::vector& si const std::string & permute_opt, std::vector permute_order, bool is_caching_test) { // convert ov::float16 to ov::float16 - using type_ = typename data_type_to_type::type; + using type_ = typename ov::element_type_traits::value_type; using type = typename std::conditional::value, ov::float16, type_>::type; std::vector internal_sizes(sizes); @@ -2318,7 +2319,7 @@ struct TiledPerformancePermuteTest : TiledPermuteTest { auto& engine = get_test_engine(); // convert ov::float16 to ov::float16 - using type_ = typename data_type_to_type::type; + using type_ = typename ov::element_type_traits::value_type; using type = typename std::conditional::value, ov::float16, type_>::type; std::vector internal_sizes(sizes); diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/rms_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/rms_gpu_test.cpp new file mode 100644 index 00000000000000..deee8418e23fae --- /dev/null +++ b/src/plugins/intel_gpu/tests/unit/test_cases/rms_gpu_test.cpp @@ -0,0 +1,184 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "test_utils.h" + +#include +#include +#include "rms_inst.h" + +using namespace cldnn; +using namespace ::tests; + +class rms_gpu_test : public ::testing::TestWithParam {}; + +template +void rms_ref(const memory::ptr input, const memory::ptr gamma, memory::ptr output, float epsilon) { + auto input_layout = input->get_layout(); + auto gamma_layout = gamma->get_layout(); + + uint32_t batch_size = input_layout.batch(); + uint32_t feature_size = input_layout.feature(); + uint32_t y_size = input_layout.spatial(1); + uint32_t x_size = input_layout.spatial(0); + + cldnn::mem_lock src(input, get_test_stream()); + cldnn::mem_lock weight(gamma, get_test_stream()); + cldnn::mem_lock dst(output, get_test_stream()); + + for (uint32_t b = 0; b < batch_size; ++b) { + for (uint32_t f = 0; f < feature_size; ++f) { + float rms = 0.f; + for (uint32_t y = 0; y < y_size; ++y) { + for (uint32_t x = 0; x < x_size; ++x) { + auto tensor_src = tensor(batch(b), feature(f), spatial(x, y, 0, 0)); + size_t src_offset = input_layout.get_linear_offset(tensor_src); + rms += std::pow(static_cast(src[src_offset]), 2); + } + } + rms /= y_size * x_size; + rms += epsilon; + rms = std::pow(std::sqrt(rms), -1); + + for (uint32_t y = 0; y < y_size; ++y) { + for (uint32_t x = 0; x < x_size; ++x) { + auto tensor_src = tensor(batch(b), feature(f), spatial(x, y, 0, 0)); + auto tensor_weight = tensor(batch(b), feature(0), spatial(x, y, 0, 0)); + auto tensor_dst = tensor(batch(b), feature(f), spatial(x, y, 0, 0)); + size_t src_offset = input_layout.get_linear_offset(tensor_src); + size_t weight_offset = input_layout.get_linear_offset(tensor_weight); + size_t dst_offset = input_layout.get_linear_offset(tensor_dst); + float result = rms * static_cast(src[src_offset]) * static_cast(weight[weight_offset]); + dst[dst_offset] = static_cast(result); + } + } + } + } +} + +TEST(rms_gpu_test, rms_test_bfyx_ref) { + auto& engine = get_test_engine(); + + auto input = engine.allocate_memory({ov::PartialShape{1, 2, 6}, data_types::f32, format::bfyx}); + auto gamma = engine.allocate_memory({ov::PartialShape{1, 6}, data_types::f32, format::bfyx}); + auto output_ref = engine.allocate_memory({ov::PartialShape{1, 2, 6}, data_types::f32, format::bfyx}); + + set_values(input, { + 0.001839f, -0.003815f, 0.000961f, 0.002930f, -0.003998f, -0.008057f, + 0.006744f, -0.000004f, 0.004303f, -0.002380f, 0.000072f, 0.001404f + }); + set_values(gamma, { + 0.029785f, 0.014038f, 0.003098f, 0.013123f, 0.015137f, 0.009399f + }); + + rms_ref(input, gamma, output_ref, 1e-5f); + + topology topology; + topology.add(input_layout("input", input->get_layout())); + topology.add(input_layout("gamma", gamma->get_layout())); + topology.add(rms("rms", input_info("input"), input_info("gamma"), 1e-5f)); + + network network(engine, topology, get_test_default_config(engine)); + + network.set_input_data("input", input); + network.set_input_data("gamma", gamma); + + auto outputs = network.execute(); + ASSERT_EQ(outputs.size(), size_t(1)); + ASSERT_EQ(outputs.begin()->first, "rms"); + + auto output = outputs.begin()->second.get_memory(); + cldnn::mem_lock output_ptr(output, get_test_stream()); + cldnn::mem_lock output_ref_ptr(output_ref, get_test_stream()); + + for (unsigned int i = 0; i < output_ref->count(); ++i) { + EXPECT_NEAR(output_ptr[i], output_ref_ptr[i], 1e-3); + } +} + +TEST(rms_gpu_test, rms_test_bfyx_opt) { + auto& engine = get_test_engine(); + + auto input = engine.allocate_memory({ov::PartialShape{1, 2, 16}, data_types::f32, format::bfyx}); + auto gamma = engine.allocate_memory({ov::PartialShape{1, 16}, data_types::f32, format::bfyx}); + auto output_ref = engine.allocate_memory({ov::PartialShape{1, 2, 16}, data_types::f32, format::bfyx}); + + set_values(input, { + 0.001839f, -0.003815f, 0.000961f, 0.002930f, -0.003998f, -0.008057f, -0.005402f, -0.002945f, + 0.006744f, -0.000004f, 0.004303f, -0.002380f, 0.000072f, 0.001404f, 0.000568f, 0.002579f, + 0.003098f, -0.006989f, -0.000244f, 0.010193f, 0.002899f, -0.005798f, -0.026978f, 0.008789f, + 0.002258f, 0.006500f, 0.003159f, -0.012329f, 0.026245f, -0.001839f, 0.000259f, 0.002670f + }); + set_values(gamma, { + 0.029785f, 0.014038f, 0.003098f, 0.013123f, 0.015137f, 0.009399f, 0.008362f, 0.008179f, + 0.018188f, 0.021973f, 0.005249f, 0.004639f, 0.004272f, 0.020264f, 0.013489f, 0.008789f + }); + + rms_ref(input, gamma, output_ref, 1e-5f); + + topology topology; + topology.add(input_layout("input", input->get_layout())); + topology.add(input_layout("gamma", gamma->get_layout())); + topology.add(rms("rms", input_info("input"), input_info("gamma"), 1e-5f)); + + network network(engine, topology, get_test_default_config(engine)); + + network.set_input_data("input", input); + network.set_input_data("gamma", gamma); + + auto outputs = network.execute(); + ASSERT_EQ(outputs.size(), size_t(1)); + ASSERT_EQ(outputs.begin()->first, "rms"); + + auto output = outputs.begin()->second.get_memory(); + cldnn::mem_lock output_ptr(output, get_test_stream()); + cldnn::mem_lock output_ref_ptr(output_ref, get_test_stream()); + + for (unsigned int i = 0; i < output_ref->count(); ++i) { + EXPECT_NEAR(output_ptr[i], output_ref_ptr[i], 1e-3); + } +} + +TEST(rms_gpu_test, rms_test_bfyx_opt_leftovers) { + auto& engine = get_test_engine(); + + auto input = engine.allocate_memory({ov::PartialShape{1, 2, 18}, data_types::f32, format::bfyx}); + auto gamma = engine.allocate_memory({ov::PartialShape{1, 18}, data_types::f32, format::bfyx}); + auto output_ref = engine.allocate_memory({ov::PartialShape{1, 2, 18}, data_types::f32, format::bfyx}); + + set_values(input, { + 0.001839f, -0.003815f, 0.000961f, 0.002930f, -0.003998f, -0.008057f, -0.005402f, -0.002945f, 0.006744f, + -0.000004f, 0.004303f, -0.002380f, 0.000072f, 0.001404f, 0.000568f, 0.002579f, 0.003098f, -0.006989f, + -0.000244f, 0.010193f, 0.002899f, -0.005798f, -0.026978f, 0.008789f, 0.002258f, 0.006500f, 0.003159f, + -0.012329f, 0.026245f, -0.001839f, 0.000259f, 0.002670f, 0.001419f, 0.001617f,-0.006622f, 0.010864f + }); + set_values(gamma, { + 0.029785f, 0.014038f, 0.003098f, 0.013123f, 0.015137f, 0.009399f, 0.008362f, 0.008179f, 0.018188f, + 0.021973f, 0.005249f, 0.004639f, 0.004272f, 0.020264f, 0.013489f, 0.008789f, 0.006653f, 0.010315f + }); + + rms_ref(input, gamma, output_ref, 1e-5f); + + topology topology; + topology.add(input_layout("input", input->get_layout())); + topology.add(input_layout("gamma", gamma->get_layout())); + topology.add(rms("rms", input_info("input"), input_info("gamma"), 1e-5f)); + + network network(engine, topology, get_test_default_config(engine)); + + network.set_input_data("input", input); + network.set_input_data("gamma", gamma); + + auto outputs = network.execute(); + ASSERT_EQ(outputs.size(), size_t(1)); + ASSERT_EQ(outputs.begin()->first, "rms"); + + auto output = outputs.begin()->second.get_memory(); + cldnn::mem_lock output_ptr(output, get_test_stream()); + cldnn::mem_lock output_ref_ptr(output_ref, get_test_stream()); + + for (unsigned int i = 0; i < output_ref->count(); ++i) { + EXPECT_NEAR(output_ptr[i], output_ref_ptr[i], 1e-3); + } +} diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/scatter_nd_update_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/scatter_nd_update_gpu_test.cpp index d905755e789a71..b3f68e0f00b349 100644 --- a/src/plugins/intel_gpu/tests/unit/test_cases/scatter_nd_update_gpu_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/test_cases/scatter_nd_update_gpu_test.cpp @@ -4458,6 +4458,67 @@ TEST(scatter_nd_update_gpu, dynamic) { } } + +TEST(scatter_nd_update_gpu, dynamic_padded_output) { + // Dictionary : 2x1x2x8 + // Indexes : 0x3 + // Updates : 0x8 + // Output : 2x1x2x8 + // Input values in fp32 + // + auto& engine = get_test_engine(); + + auto input1_layout = layout{ ov::PartialShape::dynamic(4), data_types::f32, format::bfyx }; + auto input2_layout = layout{ ov::PartialShape::dynamic(2), data_types::f32, format::bfyx }; + auto input3_layout = layout{ ov::PartialShape::dynamic(2), data_types::f32, format::bfyx }; + + auto input1 = engine.allocate_memory({ { 1, 1, 2, 8 }, data_types::f32, format::bfyx }); // Dictionary + auto input2 = engine.allocate_memory({ { 0, 3 }, data_types::f32, format::bfyx }); // Indexes + auto input3 = engine.allocate_memory({ { 0, 8 }, data_types::f32, format::bfyx }); // Updates + + set_values(input1, { + 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, + 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f, + }); + + topology topology; + topology.add(input_layout("InputData", input1_layout)); + topology.add(input_layout("InputIndices", input2_layout)); + topology.add(input_layout("InputUpdates", input3_layout)); + topology.add( + scatter_nd_update("scatter_nd_update", input_info("InputData"), input_info("InputIndices"), input_info("InputUpdates"), 2, padding({0, 0, 1, 1})) + ); + + ExecutionConfig config = get_test_default_config(engine); + config.set_property(ov::intel_gpu::allow_new_shape_infer(true)); + network network(engine, topology, config); + + network.set_input_data("InputData", input1); + network.set_input_data("InputIndices", input2); + network.set_input_data("InputUpdates", input3); + + auto inst = network.get_primitive("scatter_nd_update"); + auto impl = inst->get_impl(); + ASSERT_TRUE(impl != nullptr); + ASSERT_TRUE(impl->is_dynamic()); + + auto outputs = network.execute(); + + auto output = outputs.at("scatter_nd_update").get_memory(); + cldnn::mem_lock output_ptr(output, get_test_stream()); + + std::vector expected_results = { + 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, + 0.f, 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 0.f, + 0.f, 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f, 0.f, + 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, + }; + + for (size_t i = 0; i < expected_results.size(); ++i) { + ASSERT_EQ(expected_results[i], output_ptr[i]); + } +} + TEST(scatter_nd_update_gpu, dynamic_5d) { tests::random_generator rg(std::string(::testing::UnitTest::GetInstance()->current_test_info()->test_suite_name()) + std::string(::testing::UnitTest::GetInstance()->current_test_info()->name())); diff --git a/src/plugins/intel_gpu/tests/unit/transformations/rms_norm_decomposition_test.cpp b/src/plugins/intel_gpu/tests/unit/transformations/rms_norm_decomposition_test.cpp new file mode 100644 index 00000000000000..26d8638d2b904e --- /dev/null +++ b/src/plugins/intel_gpu/tests/unit/transformations/rms_norm_decomposition_test.cpp @@ -0,0 +1,144 @@ +// Copyright (C) 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; +using namespace ov::intel_gpu; + +TEST_F(TransformationTestsF, RMSNormFusionTest1) { + { + auto input = std::make_shared(ov::element::f32, ov::Shape{1, 2, 6}); + auto power_const = ov::opset10::Constant::create(ov::element::f32, {}, {2.f}); + auto power = std::make_shared(input, power_const); + auto mean_axes = ov::opset10::Constant::create(ov::element::i64, ov::Shape{1}, {-1}); + auto mean = std::make_shared(power, mean_axes, true); + auto eps = ov::opset10::Constant::create(ov::element::f32, {}, {1e-5f}); + auto add_eps = std::make_shared(mean, eps); + auto sqrt = std::make_shared(add_eps); + auto div_const = ov::opset10::Constant::create(ov::element::f32, {}, {-1}); + auto div = std::make_shared(sqrt, div_const); + auto mul1 = std::make_shared(input, div); + auto gamma = ov::opset10::Constant::create(ov::element::f32, ov::Shape{6}, {0.029f, 0.014f, 0.003f, 0.013f, 0.015f, 0.009f}); + auto mul2 = std::make_shared(gamma, mul1); + auto comp = std::make_shared(mul2, ov::element::f16); + + model = std::make_shared(ov::NodeVector{comp}, ov::ParameterVector{input}); + manager.register_pass(); + } + { + auto input = std::make_shared(ov::element::f32, ov::Shape{1, 2, 6}); + auto rms_const = ov::opset10::Constant::create(ov::element::f32, ov::Shape{6}, {0.029f, 0.014f, 0.003f, 0.013f, 0.015f, 0.009f}); + auto rms = std::make_shared(input, rms_const, 1e-5f, ov::element::f16); + + model_ref = std::make_shared(ov::NodeVector{rms}, ov::ParameterVector{input}); + } +} + +TEST_F(TransformationTestsF, RMSNormFusionTest2) { + { + auto input = std::make_shared(ov::element::f32, ov::Shape{1, 2, 6}); + auto power_const = ov::opset10::Constant::create(ov::element::f32, {}, {2.f}); + auto power = std::make_shared(input, power_const); + auto mean_axes = ov::opset10::Constant::create(ov::element::i64, ov::Shape{1}, {-1}); + auto mean = std::make_shared(power, mean_axes, true); + auto eps = ov::opset10::Constant::create(ov::element::f32, {}, {1e-5f}); + auto add_eps = std::make_shared(mean, eps); + auto sqrt = std::make_shared(add_eps); + auto div_const = ov::opset10::Constant::create(ov::element::f32, {}, {1}); + auto div = std::make_shared(div_const, sqrt); + auto mul1 = std::make_shared(input, div); + auto gamma = ov::opset10::Constant::create(ov::element::f32, ov::Shape{6}, {0.029f, 0.014f, 0.003f, 0.013f, 0.015f, 0.009f}); + auto mul2 = std::make_shared(gamma, mul1); + auto comp = std::make_shared(mul2, ov::element::f16); + + model = std::make_shared(ov::NodeVector{comp}, ov::ParameterVector{input}); + manager.register_pass(); + } +} + +TEST_F(TransformationTestsF, RMSNormFusionTest3) { + { + auto input = std::make_shared(ov::element::f32, ov::Shape{1, 2, 6}); + auto power_const = ov::opset10::Constant::create(ov::element::f32, {}, {2.f}); + auto power = std::make_shared(input, power_const); + auto mean_axes = ov::opset10::Constant::create(ov::element::i64, ov::Shape{1}, {-1}); + auto mean = std::make_shared(power, mean_axes, true); + auto eps = ov::opset10::Constant::create(ov::element::f32, {}, {1e-5f}); + auto add_eps = std::make_shared(mean, eps); + auto sqrt = std::make_shared(add_eps); + auto div_const = ov::opset10::Constant::create(ov::element::f32, {}, {1}); + auto div = std::make_shared(sqrt, div_const); + auto mul1 = std::make_shared(input, div); + auto gamma = ov::opset10::Constant::create(ov::element::f32, ov::Shape{6}, {0.029f, 0.014f, 0.003f, 0.013f, 0.015f, 0.009f}); + auto mul2 = std::make_shared(gamma, mul1); + auto comp = std::make_shared(mul2, ov::element::f16); + + model = std::make_shared(ov::NodeVector{comp}, ov::ParameterVector{input}); + manager.register_pass(); + } +} + +TEST_F(TransformationTestsF, RMSNormFusionTest4) { + { + auto input = std::make_shared(ov::element::f32, ov::PartialShape{-1, -1, 6}); + auto power_const = ov::opset10::Constant::create(ov::element::f32, {}, {2.f}); + auto power = std::make_shared(input, power_const); + auto mean_axes = ov::opset10::Constant::create(ov::element::i64, ov::Shape{1}, {-1}); + auto mean = std::make_shared(power, mean_axes, true); + auto eps = ov::opset10::Constant::create(ov::element::f32, {}, {1e-5f}); + auto add_eps = std::make_shared(mean, eps); + auto sqrt = std::make_shared(add_eps); + auto div_const = ov::opset10::Constant::create(ov::element::f32, {}, {1}); + auto div = std::make_shared(div_const, sqrt); + auto mul1 = std::make_shared(input, div); + auto gamma = ov::opset10::Constant::create(ov::element::f32, ov::Shape{6}, {0.029f, 0.014f, 0.003f, 0.013f, 0.015f, 0.009f}); + auto mul2 = std::make_shared(gamma, mul1); + auto comp = std::make_shared(mul2, ov::element::f16); + + model = std::make_shared(ov::NodeVector{comp}, ov::ParameterVector{input}); + manager.register_pass(); + } +} + +TEST_F(TransformationTestsF, RMSNormFusionTest5) { + { + auto input = std::make_shared(ov::element::f32, ov::PartialShape{-1, -1, 6}); + auto power_const = ov::opset10::Constant::create(ov::element::f32, {}, {2.f}); + auto power = std::make_shared(input, power_const); + auto mean_axes = ov::opset10::Constant::create(ov::element::i64, ov::Shape{1}, {-1}); + auto mean = std::make_shared(power, mean_axes, true); + auto eps = ov::opset10::Constant::create(ov::element::f32, {}, {1e-5f}); + auto add_eps = std::make_shared(mean, eps); + auto sqrt = std::make_shared(add_eps); + auto div_const = ov::opset10::Constant::create(ov::element::f32, {}, {-1}); + auto div = std::make_shared(sqrt, div_const); + auto mul1 = std::make_shared(input, div); + auto gamma = ov::opset10::Constant::create(ov::element::f32, ov::Shape{6}, {0.029f, 0.014f, 0.003f, 0.013f, 0.015f, 0.009f}); + auto mul2 = std::make_shared(gamma, mul1); + auto comp = std::make_shared(mul2, ov::element::f16); + + model = std::make_shared(ov::NodeVector{comp}, ov::ParameterVector{input}); + manager.register_pass(); + } + { + auto input = std::make_shared(ov::element::f32, ov::PartialShape{-1, -1, 6}); + auto rms_const = ov::opset10::Constant::create(ov::element::f32, ov::Shape{6}, {0.029f, 0.014f, 0.003f, 0.013f, 0.015f, 0.009f}); + auto rms = std::make_shared(input, rms_const, 1e-5f, ov::element::f16); + + model_ref = std::make_shared(ov::NodeVector{rms}, ov::ParameterVector{input}); + } +} diff --git a/src/plugins/intel_gpu/thirdparty/onednn_gpu b/src/plugins/intel_gpu/thirdparty/onednn_gpu index 4b82a66ed38eca..284ad4574939fa 160000 --- a/src/plugins/intel_gpu/thirdparty/onednn_gpu +++ b/src/plugins/intel_gpu/thirdparty/onednn_gpu @@ -1 +1 @@ -Subproject commit 4b82a66ed38ecaa993352e5cc6ed7753656b8a26 +Subproject commit 284ad4574939fa784e4ddaa1f4aa577b8eb7a017 diff --git a/src/plugins/proxy/tests/proxy_tests.cpp b/src/plugins/proxy/tests/proxy_tests.cpp index 10d944ba3fe2f2..0343e40ee240e2 100644 --- a/src/plugins/proxy/tests/proxy_tests.cpp +++ b/src/plugins/proxy/tests/proxy_tests.cpp @@ -28,7 +28,7 @@ namespace { std::string get_mock_engine_path() { std::string mockEngineName("mock_engine"); return ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - mockEngineName + IE_BUILD_POSTFIX); + mockEngineName + OV_BUILD_POSTFIX); } template @@ -492,7 +492,7 @@ void ov::proxy::tests::ProxyTests::reg_plugin(ov::Core& core, injectProxyEngine(plugin.get()); core.register_plugin(ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("mock_engine") + IE_BUILD_POSTFIX), + std::string("mock_engine") + OV_BUILD_POSTFIX), device_name, properties); m_mock_plugins.emplace_back(plugin); diff --git a/src/plugins/template/CMakeLists.txt b/src/plugins/template/CMakeLists.txt index 02633f09abee92..47cbb954d63dbd 100644 --- a/src/plugins/template/CMakeLists.txt +++ b/src/plugins/template/CMakeLists.txt @@ -7,8 +7,6 @@ cmake_minimum_required(VERSION 3.13) project(OpenVINOTemplatePlugin) -set(TEMPLATE_PLUGIN_SOURCE_DIR ${OpenVINOTemplatePlugin_SOURCE_DIR}) - find_package(OpenVINODeveloperPackage REQUIRED) ov_option(ENABLE_TEMPLATE_REGISTRATION "Enables registration of TEMPLATE plugin" OFF) @@ -31,6 +29,6 @@ endif() # install if(OpenVINODeveloperPackage_FOUND) - ie_cpack(template) + ov_cpack(template) endif() # [cmake:main] diff --git a/src/plugins/template/backend/CMakeLists.txt b/src/plugins/template/backend/CMakeLists.txt index 74e10c01863dfe..0dc03242b554af 100644 --- a/src/plugins/template/backend/CMakeLists.txt +++ b/src/plugins/template/backend/CMakeLists.txt @@ -2,12 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 # +set(TARGET_NAME openvino_interpreter_backend) + add_definitions(-DIN_OV_COMPONENT) -ov_deprecated_no_errors() -file(GLOB OPS_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/ops/*.cpp" - ) +file(GLOB OPS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/ops/*.cpp") set (SRC backend.cpp @@ -24,31 +23,38 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") ov_add_compiler_flags(/wd4018) endif() -add_library(interpreter_backend STATIC EXCLUDE_FROM_ALL ${OPS_SRC} ${SRC}) -add_library(openvino::interpreter_backend ALIAS interpreter_backend) +add_library(${TARGET_NAME} STATIC EXCLUDE_FROM_ALL ${OPS_SRC} ${SRC}) + +add_library(openvino::interpreter_backend ALIAS ${TARGET_NAME}) +set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME interpreter_backend) if(CMAKE_COMPILER_IS_GNUCXX) ov_add_compiler_flags(-Wno-missing-declarations) endif() -ov_build_target_faster(interpreter_backend UNITY) +ov_build_target_faster(${TARGET_NAME} UNITY) -target_compile_definitions(interpreter_backend +target_compile_definitions(${TARGET_NAME} PRIVATE SHARED_LIB_PREFIX="${CMAKE_SHARED_LIBRARY_PREFIX}" - SHARED_LIB_SUFFIX="${IE_BUILD_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}" + SHARED_LIB_SUFFIX="${OV_BUILD_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}" ) -target_link_libraries(interpreter_backend PRIVATE openvino::builders openvino::reference openvino::util openvino::runtime::dev openvino::shape_inference) +target_link_libraries(${TARGET_NAME} PRIVATE openvino::builders openvino::reference openvino::util openvino::runtime::dev openvino::shape_inference) -target_include_directories(interpreter_backend PUBLIC $ $) +target_include_directories(${TARGET_NAME} PUBLIC $ + $ + $) file(GLOB_RECURSE all_backends_src "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp") -ov_add_clang_format_target(interpreter_backend_clang FOR_SOURCES ${all_backends_src}) +ov_add_clang_format_target(${TARGET_NAME}_clang FOR_SOURCES ${all_backends_src}) -# developer package +# install & export -openvino_developer_export_targets(COMPONENT core TARGETS interpreter_backend) +ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE}) -# install +ov_developer_package_export_targets(TARGET openvino::interpreter_backend) -ov_install_static_lib(interpreter_backend ${OV_CPACK_COMP_CORE}) +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/" + DESTINATION developer_package/include/${TARGET_NAME} + COMPONENT developer_package EXCLUDE_FROM_ALL + FILES_MATCHING PATTERN "*.hpp") diff --git a/src/plugins/template/src/CMakeLists.txt b/src/plugins/template/src/CMakeLists.txt index f382f90d11b450..effc4831f18947 100644 --- a/src/plugins/template/src/CMakeLists.txt +++ b/src/plugins/template/src/CMakeLists.txt @@ -26,7 +26,7 @@ ov_mark_target_as_cc(${TARGET_NAME}) target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" - "${TEMPLATE_PLUGIN_SOURCE_DIR}/include") + "${OpenVINOTemplatePlugin_SOURCE_DIR}/include") # link common OpenVINO Runtime libraries target_link_libraries(${TARGET_NAME} PRIVATE diff --git a/src/plugins/template/src/itt.hpp b/src/plugins/template/src/itt.hpp index d8153bcff90ab6..a48f85ef747165 100644 --- a/src/plugins/template/src/itt.hpp +++ b/src/plugins/template/src/itt.hpp @@ -9,7 +9,7 @@ #pragma once -#include +#include "openvino/itt.hpp" namespace ov { namespace template_plugin { diff --git a/src/plugins/template/tests/functional/CMakeLists.txt b/src/plugins/template/tests/functional/CMakeLists.txt index eb634d4f91f955..18296710d64a28 100644 --- a/src/plugins/template/tests/functional/CMakeLists.txt +++ b/src/plugins/template/tests/functional/CMakeLists.txt @@ -18,7 +18,7 @@ ov_add_test_target( openvino::funcSharedTests openvino::runtime::dev INCLUDES - "${TEMPLATE_PLUGIN_SOURCE_DIR}/include" + "${OpenVINOTemplatePlugin_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/op_reference" ADD_CLANG_FORMAT LABELS diff --git a/src/plugins/template/tests/functional/op_reference/batch_to_space.cpp b/src/plugins/template/tests/functional/op_reference/batch_to_space.cpp index 10583280efd619..96ac6fd261717f 100644 --- a/src/plugins/template/tests/functional/op_reference/batch_to_space.cpp +++ b/src/plugins/template/tests/functional/op_reference/batch_to_space.cpp @@ -2,11 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/batch_to_space.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" -#include "openvino/opsets/opset2.hpp" +#include "openvino/op/parameter.hpp" using namespace reference_tests; using namespace ov; @@ -47,7 +48,7 @@ class ReferenceBatchToSpaceLayerTest : public testing::TestWithParam& obj) { - auto param = obj.param; + const auto& param = obj.param; std::ostringstream result; result << "dType=" << param.dataTensor.type; result << "_dShape=" << param.dataTensor.shape; @@ -69,11 +70,11 @@ class ReferenceBatchToSpaceLayerTest : public testing::TestWithParam CreateFunction(const BatchToSpaceParams& params) { - const auto data = std::make_shared(params.dataTensor.type, params.dataTensor.shape); - const auto blockShape = std::make_shared(element::i64, params.blockShapeTensor.shape); - const auto cropsBegin = std::make_shared(element::i64, params.cropsBeginTensor.shape); - const auto cropsEnd = std::make_shared(element::i64, params.cropsEndTensor.shape); - const auto batchToSpace = std::make_shared(data, blockShape, cropsBegin, cropsEnd); + const auto data = std::make_shared(params.dataTensor.type, params.dataTensor.shape); + const auto blockShape = std::make_shared(element::i64, params.blockShapeTensor.shape); + const auto cropsBegin = std::make_shared(element::i64, params.cropsBeginTensor.shape); + const auto cropsEnd = std::make_shared(element::i64, params.cropsEndTensor.shape); + const auto batchToSpace = std::make_shared(data, blockShape, cropsBegin, cropsEnd); return std::make_shared(NodeVector{batchToSpace}, ParameterVector{data, blockShape, cropsBegin, cropsEnd}); } diff --git a/src/plugins/template/tests/functional/op_reference/binary_convolution.cpp b/src/plugins/template/tests/functional/op_reference/binary_convolution.cpp index 1917163d832f4e..6b6089911a197c 100644 --- a/src/plugins/template/tests/functional/op_reference/binary_convolution.cpp +++ b/src/plugins/template/tests/functional/op_reference/binary_convolution.cpp @@ -7,7 +7,7 @@ #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset8.hpp" +#include "openvino/op/constant.hpp" using namespace reference_tests; using namespace ov; @@ -95,7 +95,7 @@ class ReferenceBinaryConvolutionLayerTest : public testing::TestWithParam& filterData) { const op::PadType auto_pad{op::PadType::EXPLICIT}; const auto in = std::make_shared(params.inType, params.inputShape); - auto filter = std::make_shared(ov::element::u1, params.filterShape, &filterData[0]); + auto filter = std::make_shared(ov::element::u1, params.filterShape, &filterData[0]); const auto BinaryConvolution = std::make_shared(in, filter, params.strides, diff --git a/src/plugins/template/tests/functional/op_reference/broadcast.cpp b/src/plugins/template/tests/functional/op_reference/broadcast.cpp index 5cb9712c8b2b2d..415116a39af6cf 100644 --- a/src/plugins/template/tests/functional/op_reference/broadcast.cpp +++ b/src/plugins/template/tests/functional/op_reference/broadcast.cpp @@ -2,11 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/broadcast.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" -#include "openvino/opsets/opset3.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/reverse.hpp" using namespace reference_tests; using namespace ov; @@ -56,10 +59,10 @@ class ReferenceBroadcastTest : public testing::TestWithParam, p private: static std::shared_ptr CreateFunction(const BroadcastParams& params) { - const auto A = std::make_shared(params.dataTensor.type, params.dataTensor.shape); + const auto A = std::make_shared(params.dataTensor.type, params.dataTensor.shape); const auto f = std::make_shared( - std::make_shared(A, - opset1::Constant::create(params.targetShapeTensor.type, + std::make_shared(A, + op::v0::Constant::create(params.targetShapeTensor.type, params.targetShapeTensor.shape, params.targetShapeTensor.data.data())), ParameterVector{A}); @@ -74,10 +77,10 @@ TEST_P(ReferenceBroadcastTest, CompareWithRefs) { class ReferenceBroadcastTestV3 : public ReferenceBroadcastTest { private: static std::shared_ptr CreateFunction(const BroadcastParams& params) { - const auto A = std::make_shared(params.dataTensor.type, params.dataTensor.shape); + const auto A = std::make_shared(params.dataTensor.type, params.dataTensor.shape); const auto f = std::make_shared( - std::make_shared(A, - opset1::Constant::create(params.targetShapeTensor.type, + std::make_shared(A, + op::v0::Constant::create(params.targetShapeTensor.type, params.targetShapeTensor.shape, params.targetShapeTensor.data.data())), ParameterVector{A}); @@ -132,13 +135,13 @@ class ReferenceBroadcastTestExplicitAxis : public testing::TestWithParam CreateFunction(const BroadcastParamsExplicitAxis& params) { - const auto A = std::make_shared(params.dataTensor.type, params.dataTensor.shape); + const auto A = std::make_shared(params.dataTensor.type, params.dataTensor.shape); const auto f = std::make_shared( - std::make_shared(A, - opset1::Constant::create(params.targetShapeTensor.type, + std::make_shared(A, + op::v0::Constant::create(params.targetShapeTensor.type, params.targetShapeTensor.shape, params.targetShapeTensor.data.data()), - opset1::Constant::create(params.axesMappingTensor.type, + op::v0::Constant::create(params.axesMappingTensor.type, params.axesMappingTensor.shape, params.axesMappingTensor.data.data())), ParameterVector{A}); @@ -203,15 +206,15 @@ class ReferenceBroadcastTestTestHelper : public testing::TestWithParam CreateFunction(const BroadcastParamsTestHelper& params) { - const auto A = std::make_shared(element::f32, params.shapeA); - const auto shape_const = opset1::Constant::create(element::u64, Shape{params.shapeR.size()}, params.shapeR); + const auto A = std::make_shared(element::f32, params.shapeA); + const auto shape_const = op::v0::Constant::create(element::u64, Shape{params.shapeR.size()}, params.shapeR); std::shared_ptr broadcast; if (params.axes.size() > 0) { auto axes_const = - opset1::Constant::create(element::i64, Shape{params.axes.size()}, params.axes.to_vector()); - broadcast = std::make_shared(A, shape_const, axes_const); + op::v0::Constant::create(element::i64, Shape{params.axes.size()}, params.axes.to_vector()); + broadcast = std::make_shared(A, shape_const, axes_const); } else { - broadcast = std::make_shared(A, shape_const); + broadcast = std::make_shared(A, shape_const); } auto f = std::make_shared(broadcast, ParameterVector{A}); return f; @@ -239,18 +242,18 @@ TEST_P(ReferenceBroadcastTestTestHelper, CompareWithRefs) { class ReferenceBroadcastTestExplicitAxisReversed : public ReferenceBroadcastTestExplicitAxis { private: static std::shared_ptr CreateFunction(const BroadcastParamsExplicitAxis& params) { - const auto A = std::make_shared(params.dataTensor.type, params.dataTensor.shape); + const auto A = std::make_shared(params.dataTensor.type, params.dataTensor.shape); auto broadcast = - std::make_shared(A, - opset1::Constant::create(params.targetShapeTensor.type, + std::make_shared(A, + op::v0::Constant::create(params.targetShapeTensor.type, params.targetShapeTensor.shape, params.targetShapeTensor.data.data()), - opset1::Constant::create(params.axesMappingTensor.type, + op::v0::Constant::create(params.axesMappingTensor.type, params.axesMappingTensor.shape, params.axesMappingTensor.data.data())); - auto reverse = std::make_shared(broadcast, - opset1::Constant::create(element::i64, {1}, {1}), - opset1::Reverse::Mode::INDEX); + auto reverse = std::make_shared(broadcast, + op::v0::Constant::create(element::i64, {1}, {1}), + op::v1::Reverse::Mode::INDEX); auto f = std::make_shared(NodeVector{reverse}, ParameterVector{A}); return f; } diff --git a/src/plugins/template/tests/functional/op_reference/concat.cpp b/src/plugins/template/tests/functional/op_reference/concat.cpp index b11a3d1e4a4658..da3a141b160a18 100644 --- a/src/plugins/template/tests/functional/op_reference/concat.cpp +++ b/src/plugins/template/tests/functional/op_reference/concat.cpp @@ -2,10 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/concat.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" +#include "openvino/op/add.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/subtract.hpp" using namespace reference_tests; using namespace ov; @@ -68,17 +73,17 @@ class ReferenceConcatTest : public testing::TestWithParam, public private: static std::shared_ptr CreateFunction(const ConcatParams& params) { - std::shared_ptr A, B, C; + std::shared_ptr A, B, C; if (params.dynamicShape.is_dynamic()) { - A = std::make_shared(params.A.type, params.dynamicShape); - B = std::make_shared(params.B.type, params.dynamicShape); - C = std::make_shared(params.C.type, params.dynamicShape); + A = std::make_shared(params.A.type, params.dynamicShape); + B = std::make_shared(params.B.type, params.dynamicShape); + C = std::make_shared(params.C.type, params.dynamicShape); } else { - A = std::make_shared(params.A.type, params.A.shape); - B = std::make_shared(params.B.type, params.B.shape); - C = std::make_shared(params.C.type, params.C.shape); + A = std::make_shared(params.A.type, params.A.shape); + B = std::make_shared(params.B.type, params.B.shape); + C = std::make_shared(params.C.type, params.C.shape); } - auto f = std::make_shared(std::make_shared(NodeVector{A, B, C}, params.axis), + auto f = std::make_shared(std::make_shared(NodeVector{A, B, C}, params.axis), ParameterVector{A, B, C}); return f; } @@ -190,11 +195,11 @@ class ReferenceConcatTestVectorLarge : public testing::TestWithParam(element::f32, shape_a); + auto A = std::make_shared(element::f32, shape_a); inputs_param.push_back(A); inputs.push_back(A); } - function = std::make_shared(std::make_shared(inputs, 0), inputs_param); + function = std::make_shared(std::make_shared(inputs, 0), inputs_param); std::vector ref_result; for (uint32_t i = 0; i < params.numInputs; i++) { @@ -309,15 +314,15 @@ class ReferenceConcatTestInPlace2dTensor : public testing::TestWithParam CreateFunction(const ConcatParamsInPlace2dTensor& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto B = std::make_shared(params.B.type, params.B.shape); - const auto add1 = std::make_shared(A, B); - const auto C = std::make_shared(params.C.type, params.C.shape); - const auto D = std::make_shared(params.D.type, params.D.shape); - const auto add2 = std::make_shared(C, D); - const auto subtract = std::make_shared(C, A); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto B = std::make_shared(params.B.type, params.B.shape); + const auto add1 = std::make_shared(A, B); + const auto C = std::make_shared(params.C.type, params.C.shape); + const auto D = std::make_shared(params.D.type, params.D.shape); + const auto add2 = std::make_shared(C, D); + const auto subtract = std::make_shared(C, A); const auto f = - std::make_shared(std::make_shared(NodeVector{add1, add2, subtract}, params.axis), + std::make_shared(std::make_shared(NodeVector{add1, add2, subtract}, params.axis), ParameterVector{A, B, C, D}); return f; } @@ -426,16 +431,16 @@ class ReferenceConcatTestInPlacePropagate2dTensor : public testing::TestWithPara private: static std::shared_ptr CreateFunction(const ConcatParamsInPlacePropagate2dTensor& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto B = std::make_shared(params.B.type, params.B.shape); - const auto add1 = std::make_shared(A, B); - const auto C = std::make_shared(params.C.type, params.C.shape); - const auto D = std::make_shared(params.D.type, params.D.shape); - const auto add2 = std::make_shared(C, D); - const auto concat1 = std::make_shared(NodeVector{add1, add2}, params.axis); - const auto subtract = std::make_shared(C, A); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto B = std::make_shared(params.B.type, params.B.shape); + const auto add1 = std::make_shared(A, B); + const auto C = std::make_shared(params.C.type, params.C.shape); + const auto D = std::make_shared(params.D.type, params.D.shape); + const auto add2 = std::make_shared(C, D); + const auto concat1 = std::make_shared(NodeVector{add1, add2}, params.axis); + const auto subtract = std::make_shared(C, A); const auto f = - std::make_shared(std::make_shared(NodeVector{concat1, subtract}, params.axis), + std::make_shared(std::make_shared(NodeVector{concat1, subtract}, params.axis), ParameterVector{A, B, C, D}); return f; } @@ -534,12 +539,12 @@ class ReferenceConcatTestInPlaceTree1 : public testing::TestWithParam CreateFunction(const ConcatParamsInPlaceTree1& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto B = std::make_shared(params.B.type, params.B.shape); - const auto add1 = std::make_shared(A, B); - const auto add2 = std::make_shared(A, B); - const auto concat = std::make_shared(NodeVector{add1, add2}, params.axis); - const auto f = std::make_shared(std::make_shared(concat, concat), ParameterVector{A, B}); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto B = std::make_shared(params.B.type, params.B.shape); + const auto add1 = std::make_shared(A, B); + const auto add2 = std::make_shared(A, B); + const auto concat = std::make_shared(NodeVector{add1, add2}, params.axis); + const auto f = std::make_shared(std::make_shared(concat, concat), ParameterVector{A, B}); return f; } }; @@ -635,15 +640,15 @@ class ReferenceConcatTestInPlaceTree2 : public testing::TestWithParam CreateFunction(const ConcatParamsInPlaceTree2& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto B = std::make_shared(params.B.type, params.B.shape); - const auto add1 = std::make_shared(A, B); - const auto add2 = std::make_shared(A, B); - const auto concat1 = std::make_shared(NodeVector{add1, add2}, params.axis); - const auto concat2 = std::make_shared(NodeVector{add1, add2}, params.axis); - const auto concat12 = std::make_shared(NodeVector{concat1, concat2}, params.axis); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto B = std::make_shared(params.B.type, params.B.shape); + const auto add1 = std::make_shared(A, B); + const auto add2 = std::make_shared(A, B); + const auto concat1 = std::make_shared(NodeVector{add1, add2}, params.axis); + const auto concat2 = std::make_shared(NodeVector{add1, add2}, params.axis); + const auto concat12 = std::make_shared(NodeVector{concat1, concat2}, params.axis); const auto f = - std::make_shared(std::make_shared(concat12, concat12), ParameterVector{A, B}); + std::make_shared(std::make_shared(concat12, concat12), ParameterVector{A, B}); return f; } }; @@ -740,17 +745,17 @@ class ReferenceConcatTestInPlaceTree3 : public testing::TestWithParam CreateFunction(const ConcatParamsInPlaceTree3& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto B = std::make_shared(params.B.type, params.B.shape); - const auto concat1 = std::make_shared(NodeVector{A, B}, params.axis); - const auto concat2 = std::make_shared(NodeVector{A, B}, params.axis); - const auto concat3 = std::make_shared(NodeVector{A, B}, params.axis); - const auto concat4 = std::make_shared(NodeVector{A, B}, params.axis); - const auto concat12 = std::make_shared(NodeVector{concat1, concat2}, params.axis); - const auto concat34 = std::make_shared(NodeVector{concat3, concat4}, params.axis); - const auto concat14 = std::make_shared(NodeVector{concat12, concat34}, params.axis); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto B = std::make_shared(params.B.type, params.B.shape); + const auto concat1 = std::make_shared(NodeVector{A, B}, params.axis); + const auto concat2 = std::make_shared(NodeVector{A, B}, params.axis); + const auto concat3 = std::make_shared(NodeVector{A, B}, params.axis); + const auto concat4 = std::make_shared(NodeVector{A, B}, params.axis); + const auto concat12 = std::make_shared(NodeVector{concat1, concat2}, params.axis); + const auto concat34 = std::make_shared(NodeVector{concat3, concat4}, params.axis); + const auto concat14 = std::make_shared(NodeVector{concat12, concat34}, params.axis); const auto f = - std::make_shared(std::make_shared(concat14, concat14), ParameterVector{A, B}); + std::make_shared(std::make_shared(concat14, concat14), ParameterVector{A, B}); return f; } }; @@ -848,12 +853,12 @@ class ReferenceConcatTestInPlaceAddConcat : public testing::TestWithParam CreateFunction(const ConcatParamsInPlaceAddConcat& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto B = std::make_shared(params.B.type, params.B.shape); - const auto add1 = std::make_shared(A, B); - const auto add2 = std::make_shared(add1, add1); - const auto concat = std::make_shared(NodeVector{add1, add2}, params.axis); - const auto add3 = std::make_shared(concat, concat); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto B = std::make_shared(params.B.type, params.B.shape); + const auto add1 = std::make_shared(A, B); + const auto add2 = std::make_shared(add1, add1); + const auto concat = std::make_shared(NodeVector{add1, add2}, params.axis); + const auto add3 = std::make_shared(concat, concat); const auto f = std::make_shared(add3, ParameterVector{A, B}); return f; } @@ -950,16 +955,16 @@ class ReferenceConcatTestInPlaceAddConcat2 : public testing::TestWithParam CreateFunction(const ConcatParamsInPlaceAddConcat2& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto B = std::make_shared(params.B.type, params.B.shape); - const auto add1 = std::make_shared(A, B); - const auto add2 = std::make_shared(A, B); - const auto add3 = std::make_shared(A, B); - const auto add4 = std::make_shared(A, B); - const auto add5 = std::make_shared(A, B); - const auto concat1 = std::make_shared(NodeVector{add1, add2, add3}, params.axis); - const auto concat2 = std::make_shared(NodeVector{add4, add2, add5}, params.axis); - const auto add6 = std::make_shared(concat1, concat2); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto B = std::make_shared(params.B.type, params.B.shape); + const auto add1 = std::make_shared(A, B); + const auto add2 = std::make_shared(A, B); + const auto add3 = std::make_shared(A, B); + const auto add4 = std::make_shared(A, B); + const auto add5 = std::make_shared(A, B); + const auto concat1 = std::make_shared(NodeVector{add1, add2, add3}, params.axis); + const auto concat2 = std::make_shared(NodeVector{add4, add2, add5}, params.axis); + const auto add6 = std::make_shared(concat1, concat2); const auto f = std::make_shared(add6, ParameterVector{A, B}); return f; } @@ -1061,10 +1066,10 @@ class ReferenceConcatTest5d : public testing::TestWithParam, pub private: static std::shared_ptr CreateFunction(const ConcatParams5d& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto B = std::make_shared(params.B.type, params.B.shape); - const auto C = std::make_shared(params.C.type, params.C.shape); - const auto concat = std::make_shared(NodeVector{A, B, C}, params.axis); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto B = std::make_shared(params.B.type, params.B.shape); + const auto C = std::make_shared(params.C.type, params.C.shape); + const auto concat = std::make_shared(NodeVector{A, B, C}, params.axis); const auto f = std::make_shared(concat, ParameterVector{A, B, C}); return f; } @@ -1210,9 +1215,9 @@ class ReferenceConcatTestZeroLength1dLast : public testing::TestWithParam CreateFunction(const ConcatParamsZeroLength1dLast& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto B = std::make_shared(params.B.type, params.B.shape); - const auto concat = std::make_shared(NodeVector{A, B}, params.axis); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto B = std::make_shared(params.B.type, params.B.shape); + const auto concat = std::make_shared(NodeVector{A, B}, params.axis); const auto f = std::make_shared(concat, ParameterVector{A, B}); return f; } @@ -1314,10 +1319,10 @@ class ReferenceConcatTestZeroLength1dMiddle : public testing::TestWithParam CreateFunction(const ConcatParamsZeroLength1dMiddle& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto B = std::make_shared(params.B.type, params.B.shape); - const auto C = std::make_shared(params.C.type, params.C.shape); - const auto concat = std::make_shared(NodeVector{A, B, C}, params.axis); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto B = std::make_shared(params.B.type, params.B.shape); + const auto C = std::make_shared(params.C.type, params.C.shape); + const auto concat = std::make_shared(NodeVector{A, B, C}, params.axis); const auto f = std::make_shared(concat, ParameterVector{A, B, C}); return f; } @@ -1409,8 +1414,8 @@ class ReferenceConcatTestZeroZero : public testing::TestWithParam CreateFunction(const ConcatParamsZeroZero& params) { - const auto constant_1 = std::make_shared(params.A.type, params.A.shape, params.A.data.data()); - const auto concat_1 = std::make_shared(NodeVector{constant_1, constant_1}, params.axis); + const auto constant_1 = std::make_shared(params.A.type, params.A.shape, params.A.data.data()); + const auto concat_1 = std::make_shared(NodeVector{constant_1, constant_1}, params.axis); const auto f = std::make_shared(concat_1, ParameterVector{}); return f; } @@ -1511,10 +1516,10 @@ class ReferenceConcatTestZeroLength4dMiddle : public testing::TestWithParam CreateFunction(const ConcatParamsZeroLength4dMiddle& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto B = std::make_shared(params.B.type, params.B.shape); - const auto C = std::make_shared(params.C.type, params.C.shape); - const auto concat = std::make_shared(NodeVector{A, B, C}, params.axis); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto B = std::make_shared(params.B.type, params.B.shape); + const auto C = std::make_shared(params.C.type, params.C.shape); + const auto concat = std::make_shared(NodeVector{A, B, C}, params.axis); const auto f = std::make_shared(concat, ParameterVector{A, B, C}); return f; } diff --git a/src/plugins/template/tests/functional/op_reference/convert.cpp b/src/plugins/template/tests/functional/op_reference/convert.cpp index 0f3e47148790be..b6195744c9c6f3 100644 --- a/src/plugins/template/tests/functional/op_reference/convert.cpp +++ b/src/plugins/template/tests/functional/op_reference/convert.cpp @@ -103,7 +103,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{2, 2}, ov::element::u4, ov::element::f32, - std::vector{0xFB, 0x0A}, + std::vector{0xBF, 0xA0}, std::vector{15.0f, 11.0f, 0.0f, 10.0f}, 4), ConvertParams(ConversionTypes::CONVERT, @@ -134,7 +134,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{2, 2}, ov::element::i4, ov::element::f32, - std::vector{0xFE, 0xF2}, + std::vector{0xEF, 0x2F}, std::vector{-1.0f, -2.0f, -1.0f, 2.0f}, 4), ConvertParams(ConversionTypes::CONVERT, @@ -245,7 +245,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u1, ov::element::i4, std::vector{0xA0}, - std::vector{0x10, 0x10}, + std::vector{0x01, 0x01}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -261,7 +261,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u8, ov::element::i4, std::vector{1, 2, 0, 3}, - std::vector{0x12, 0x03}, + std::vector{0x21, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -269,7 +269,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u16, ov::element::i4, std::vector{1, 2, 0, 3}, - std::vector{0x12, 0x03}, + std::vector{0x21, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -277,7 +277,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u32, ov::element::i4, std::vector{1, 2, 0, 3}, - std::vector{0x12, 0x03}, + std::vector{0x21, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -285,7 +285,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u64, ov::element::i4, std::vector{1, 2, 0, 3}, - std::vector{0x12, 0x03}, + std::vector{0x21, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -301,7 +301,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::i8, ov::element::i4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -309,7 +309,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::i16, ov::element::i4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -317,7 +317,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::i32, ov::element::i4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -325,7 +325,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::i64, ov::element::i4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -333,7 +333,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::f16, ov::element::i4, std::vector{-1, -2, 0, 3}, - std::vector{0xFE, 0x03}, + std::vector{0xEF, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -341,7 +341,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::bf16, ov::element::i4, std::vector{-1, -2, 0, 3}, - std::vector{0xFE, 0x03}, + std::vector{0xEF, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -349,7 +349,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::f32, ov::element::i4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), // destination i8 @@ -364,7 +364,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::u4, ov::element::i8, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT, @@ -395,7 +395,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::i4, ov::element::i8, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT, @@ -452,7 +452,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::u4, ov::element::i16, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT, @@ -483,7 +483,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::i4, ov::element::i16, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT, @@ -540,7 +540,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::u4, ov::element::i32, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT, @@ -571,7 +571,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::i4, ov::element::i32, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT, @@ -628,7 +628,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::u4, ov::element::i64, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT, @@ -659,7 +659,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::i4, ov::element::i64, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT, @@ -718,7 +718,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{8}, ov::element::u4, ov::element::u1, - std::vector{0x10, 0x01, 0x00, 0x00}, + std::vector{0x01, 0x10, 0x00, 0x00}, std::vector{0x90}, 8, 8), @@ -758,7 +758,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{8}, ov::element::i4, ov::element::u1, - std::vector{0x10, 0x01, 0x00, 0x00}, + std::vector{0x01, 0x10, 0x00, 0x00}, std::vector{0x90}, 8, 8), @@ -825,7 +825,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u1, ov::element::u4, std::vector{0xA0}, - std::vector{0x10, 0x10}, + std::vector{0x01, 0x01}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -841,7 +841,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u8, ov::element::u4, std::vector{1, 2, 0, 3}, - std::vector{0x12, 0x03}, + std::vector{0x21, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -849,7 +849,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u16, ov::element::u4, std::vector{1, 2, 0, 3}, - std::vector{0x12, 0x03}, + std::vector{0x21, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -857,7 +857,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u32, ov::element::u4, std::vector{1, 2, 0, 3}, - std::vector{0x12, 0x03}, + std::vector{0x21, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -865,7 +865,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u64, ov::element::u4, std::vector{1, 2, 0, 3}, - std::vector{0x12, 0x03}, + std::vector{0x21, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -881,7 +881,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::i8, ov::element::u4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -889,7 +889,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::i16, ov::element::u4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -897,7 +897,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::i32, ov::element::u4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -905,7 +905,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::i64, ov::element::u4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -913,7 +913,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::f16, ov::element::u4, std::vector{-1, -2, 0, 3}, - std::vector{0xFE, 0x03}, + std::vector{0xEF, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -921,7 +921,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::bf16, ov::element::u4, std::vector{-1, -2, 0, 3}, - std::vector{0xFE, 0x03}, + std::vector{0xEF, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT, @@ -929,7 +929,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::f32, ov::element::u4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), @@ -945,7 +945,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::u4, ov::element::u8, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT, @@ -976,7 +976,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::i4, ov::element::u8, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT, @@ -1034,7 +1034,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::u4, ov::element::u16, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT, @@ -1065,7 +1065,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::i4, ov::element::u16, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT, @@ -1123,7 +1123,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::u4, ov::element::u32, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT, @@ -1154,7 +1154,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::i4, ov::element::u32, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT, @@ -1211,7 +1211,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::u4, ov::element::u64, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT, @@ -1242,7 +1242,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::i4, ov::element::u64, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT, diff --git a/src/plugins/template/tests/functional/op_reference/convert_color_i420.cpp b/src/plugins/template/tests/functional/op_reference/convert_color_i420.cpp index 844fdeb116344c..2e9747596965b6 100644 --- a/src/plugins/template/tests/functional/op_reference/convert_color_i420.cpp +++ b/src/plugins/template/tests/functional/op_reference/convert_color_i420.cpp @@ -4,13 +4,13 @@ #include -#include -#include -#include #include #include "base_reference_test.hpp" #include "functional_test_utils/skip_tests_config.hpp" +#include "openvino/core/model.hpp" +#include "openvino/op/i420_to_bgr.hpp" +#include "openvino/op/i420_to_rgb.hpp" using namespace ov; using namespace InferenceEngine; diff --git a/src/plugins/template/tests/functional/op_reference/convert_color_nv12.cpp b/src/plugins/template/tests/functional/op_reference/convert_color_nv12.cpp index 26d9c31bae3f1e..77781766478765 100644 --- a/src/plugins/template/tests/functional/op_reference/convert_color_nv12.cpp +++ b/src/plugins/template/tests/functional/op_reference/convert_color_nv12.cpp @@ -4,13 +4,13 @@ #include -#include -#include -#include #include #include "base_reference_test.hpp" #include "functional_test_utils/skip_tests_config.hpp" +#include "openvino/core/model.hpp" +#include "openvino/op/nv12_to_bgr.hpp" +#include "openvino/op/nv12_to_rgb.hpp" using namespace ov; using namespace InferenceEngine; diff --git a/src/plugins/template/tests/functional/op_reference/convert_like.cpp b/src/plugins/template/tests/functional/op_reference/convert_like.cpp index b46fe98af030c2..4ddf3dda276b92 100644 --- a/src/plugins/template/tests/functional/op_reference/convert_like.cpp +++ b/src/plugins/template/tests/functional/op_reference/convert_like.cpp @@ -6,6 +6,8 @@ #include +#include + #include "conversion.hpp" using namespace ov; @@ -101,7 +103,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{2, 2}, ov::element::u4, ov::element::f32, - std::vector{0xFB, 0x0A}, + std::vector{0xBF, 0xA0}, std::vector{15.0f, 11.0f, 0.0f, 10.0f}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -132,7 +134,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{2, 2}, ov::element::i4, ov::element::f32, - std::vector{0xFE, 0xF2}, + std::vector{0xEF, 0x2F}, std::vector{-1.0f, -2.0f, -1.0f, 2.0f}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -243,7 +245,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u1, ov::element::i4, std::vector{0xA0}, - std::vector{0x10, 0x10}, + std::vector{0x01, 0x01}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -259,7 +261,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u8, ov::element::i4, std::vector{1, 2, 0, 3}, - std::vector{0x12, 0x03}, + std::vector{0x21, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -267,7 +269,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u16, ov::element::i4, std::vector{1, 2, 0, 3}, - std::vector{0x12, 0x03}, + std::vector{0x21, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -275,7 +277,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u32, ov::element::i4, std::vector{1, 2, 0, 3}, - std::vector{0x12, 0x03}, + std::vector{0x21, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -283,7 +285,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u64, ov::element::i4, std::vector{1, 2, 0, 3}, - std::vector{0x12, 0x03}, + std::vector{0x21, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -299,7 +301,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::i8, ov::element::i4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -307,7 +309,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::i16, ov::element::i4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -315,7 +317,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::i32, ov::element::i4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -323,7 +325,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::i64, ov::element::i4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -331,7 +333,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::f16, ov::element::i4, std::vector{-1, -2, 0, 3}, - std::vector{0xFE, 0x03}, + std::vector{0xEF, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -339,7 +341,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::bf16, ov::element::i4, std::vector{-1, -2, 0, 3}, - std::vector{0xFE, 0x03}, + std::vector{0xEF, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -347,7 +349,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::f32, ov::element::i4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), // destination i8 @@ -362,7 +364,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::u4, ov::element::i8, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -393,7 +395,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::i4, ov::element::i8, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -436,7 +438,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::f32, ov::element::i8, - std::vector{-1, -2, 2, 3}, + std::vector{-1, -2, 2.2, 3.8}, std::vector{-1, -2, 2, 3}), // destination i16 ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -450,7 +452,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::u4, ov::element::i16, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -481,7 +483,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::i4, ov::element::i16, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -524,7 +526,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::f32, ov::element::i16, - std::vector{-1, -2, 2, 3}, + std::vector{-1, -2, 2.2, 3.8}, std::vector{-1, -2, 2, 3}), // destination i32 ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -538,7 +540,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::u4, ov::element::i32, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -569,7 +571,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::i4, ov::element::i32, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -612,7 +614,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::f32, ov::element::i32, - std::vector{-1, -2, 2, 3}, + std::vector{-1, -2, 2.2, 3.8}, std::vector{-1, -2, 2, 3}), // destination i64 ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -626,7 +628,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::u4, ov::element::i64, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -657,7 +659,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::i4, ov::element::i64, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -700,7 +702,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::f32, ov::element::i64, - std::vector{-1, -2, 2, 3}, + std::vector{-1, -2, 2.2, 3.8}, std::vector{-1, -2, 2, 3}), // destination u1 @@ -716,7 +718,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{8}, ov::element::u4, ov::element::u1, - std::vector{0x10, 0x01, 0x00, 0x00}, + std::vector{0x01, 0x10, 0x00, 0x00}, std::vector{0x90}, 8, 8), @@ -756,7 +758,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{8}, ov::element::i4, ov::element::u1, - std::vector{0x10, 0x01, 0x00, 0x00}, + std::vector{0x01, 0x10, 0x00, 0x00}, std::vector{0x90}, 8, 8), @@ -823,7 +825,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u1, ov::element::u4, std::vector{0xA0}, - std::vector{0x10, 0x10}, + std::vector{0x01, 0x01}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -839,7 +841,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u8, ov::element::u4, std::vector{1, 2, 0, 3}, - std::vector{0x12, 0x03}, + std::vector{0x21, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -847,7 +849,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u16, ov::element::u4, std::vector{1, 2, 0, 3}, - std::vector{0x12, 0x03}, + std::vector{0x21, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -855,7 +857,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u32, ov::element::u4, std::vector{1, 2, 0, 3}, - std::vector{0x12, 0x03}, + std::vector{0x21, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -863,7 +865,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::u64, ov::element::u4, std::vector{1, 2, 0, 3}, - std::vector{0x12, 0x03}, + std::vector{0x21, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -879,7 +881,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::i8, ov::element::u4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -887,7 +889,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::i16, ov::element::u4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -895,7 +897,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::i32, ov::element::u4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -903,7 +905,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::i64, ov::element::u4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -911,7 +913,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::f16, ov::element::u4, std::vector{-1, -2, 0, 3}, - std::vector{0xFE, 0x03}, + std::vector{0xEF, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -919,7 +921,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::bf16, ov::element::u4, std::vector{-1, -2, 0, 3}, - std::vector{0xFE, 0x03}, + std::vector{0xEF, 0x30}, 4, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -927,7 +929,7 @@ INSTANTIATE_TEST_SUITE_P( ov::element::f32, ov::element::u4, std::vector{-1, -2, 2, 3}, - std::vector{0xFE, 0x23}, + std::vector{0xEF, 0x32}, 4, 4), @@ -943,7 +945,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::u4, ov::element::u8, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -974,7 +976,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::i4, ov::element::u8, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -1017,7 +1019,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::f32, ov::element::u8, - std::vector{1, 2, 2, 3}, + std::vector{1, 2, 2.2, 3.8}, std::vector{1, 2, 2, 3}), // destination u16 @@ -1032,7 +1034,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::u4, ov::element::u16, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -1063,7 +1065,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::i4, ov::element::u16, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -1106,7 +1108,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::f32, ov::element::u16, - std::vector{1, 2, 2, 3}, + std::vector{1, 2, 2.2, 3.8}, std::vector{1, 2, 2, 3}), // destination u32 @@ -1121,7 +1123,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::u4, ov::element::u32, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -1152,7 +1154,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::i4, ov::element::u32, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -1195,7 +1197,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::f32, ov::element::u32, - std::vector{1, 2, 2, 3}, + std::vector{1, 2, 2.2, 3.8}, std::vector{1, 2, 2, 3}), // destination u64 ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -1209,7 +1211,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::u4, ov::element::u64, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -1240,7 +1242,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::i4, ov::element::u64, - std::vector{0x21, 0x43}, + std::vector{0x12, 0x34}, std::vector{2, 1, 4, 3}, 4), ConvertParams(ConversionTypes::CONVERT_LIKE, @@ -1283,7 +1285,7 @@ INSTANTIATE_TEST_SUITE_P( ov::PartialShape{4}, ov::element::f32, ov::element::u64, - std::vector{1, 2, 2, 3}, + std::vector{1, 2, 2.2, 3.8}, std::vector{1, 2, 2, 3})), ReferenceConversionLayerTest::getTestCaseName); } // namespace diff --git a/src/plugins/template/tests/functional/op_reference/deformable_psroi_pooling.cpp b/src/plugins/template/tests/functional/op_reference/deformable_psroi_pooling.cpp index 858c5d287f4206..36f3e46b8d38ad 100644 --- a/src/plugins/template/tests/functional/op_reference/deformable_psroi_pooling.cpp +++ b/src/plugins/template/tests/functional/op_reference/deformable_psroi_pooling.cpp @@ -2,13 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/deformable_psroi_pooling.hpp" + #include #include #include "base_reference_test.hpp" #include "openvino/op/psroi_pooling.hpp" -#include "openvino/opsets/opset1.hpp" using namespace reference_tests; using namespace ov; @@ -186,7 +187,7 @@ class ReferenceDeformablePSROIPoolingLayerTest : public testing::TestWithParam(params.roisType, params.roisShape); if (params.offsetsShape.size() != 0) { const auto offsets = std::make_shared(params.offsetsType, params.offsetsShape); - const auto DeformablePSROIPooling = std::make_shared(input, + const auto DeformablePSROIPooling = std::make_shared(input, rois, offsets, params.outputDim, @@ -200,7 +201,7 @@ class ReferenceDeformablePSROIPoolingLayerTest : public testing::TestWithParam(NodeVector{DeformablePSROIPooling}, ParameterVector{input, rois, offsets}); } else { - const auto DeformablePSROIPooling = std::make_shared(input, + const auto DeformablePSROIPooling = std::make_shared(input, rois, params.outputDim, params.spatialScale, diff --git a/src/plugins/template/tests/functional/op_reference/depth_to_space.cpp b/src/plugins/template/tests/functional/op_reference/depth_to_space.cpp index 6f683ed5452765..83c91f93f92a11 100644 --- a/src/plugins/template/tests/functional/op_reference/depth_to_space.cpp +++ b/src/plugins/template/tests/functional/op_reference/depth_to_space.cpp @@ -2,10 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/depth_to_space.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" +#include "openvino/op/parameter.hpp" using namespace reference_tests; using namespace ov; @@ -56,11 +58,10 @@ class ReferenceDepthToSpaceLayerTest : public testing::TestWithParam CreateFunction(const DepthToSpaceParams& params) { - opset1::DepthToSpace::DepthToSpaceMode mode = params.mode == "DEPTH_FIRST" - ? opset1::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST - : opset1::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST; - const auto data = std::make_shared(params.dataTensor.type, params.dataTensor.shape); - const auto depthToSpace = std::make_shared(data, mode, params.blockSize); + const auto mode = params.mode == "DEPTH_FIRST" ? op::v0::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST + : op::v0::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST; + const auto data = std::make_shared(params.dataTensor.type, params.dataTensor.shape); + const auto depthToSpace = std::make_shared(data, mode, params.blockSize); return std::make_shared(NodeVector{depthToSpace}, ParameterVector{data}); } }; diff --git a/src/plugins/template/tests/functional/op_reference/einsum.cpp b/src/plugins/template/tests/functional/op_reference/einsum.cpp index 400fdc445c5387..e01dc16293e17e 100644 --- a/src/plugins/template/tests/functional/op_reference/einsum.cpp +++ b/src/plugins/template/tests/functional/op_reference/einsum.cpp @@ -2,11 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/einsum.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" -#include "openvino/opsets/opset7.hpp" +#include "openvino/op/parameter.hpp" using namespace reference_tests; using namespace ov; @@ -56,11 +57,11 @@ class ReferenceEinsumTest : public testing::TestWithParam, public OutputVector output_vector; ParameterVector param_vector; for (const auto& input_tensor : params.inputs) { - auto param = std::make_shared(input_tensor.type, input_tensor.shape); + auto param = std::make_shared(input_tensor.type, input_tensor.shape); output_vector.push_back(param); param_vector.push_back(param); } - const auto einsum = std::make_shared(output_vector, params.equation); + const auto einsum = std::make_shared(output_vector, params.equation); const auto f = std::make_shared(OutputVector{einsum}, param_vector); return f; } diff --git a/src/plugins/template/tests/functional/op_reference/embedding_segments_sum.cpp b/src/plugins/template/tests/functional/op_reference/embedding_segments_sum.cpp index d308d2c2a5d69f..4726ccdffd6a51 100644 --- a/src/plugins/template/tests/functional/op_reference/embedding_segments_sum.cpp +++ b/src/plugins/template/tests/functional/op_reference/embedding_segments_sum.cpp @@ -4,9 +4,8 @@ #include -#include - #include "base_reference_test.hpp" +#include "shared_test_classes/base/layer_test_utils.hpp" using namespace reference_tests; using namespace ov; diff --git a/src/plugins/template/tests/functional/op_reference/embeddingbag_offsetssum.cpp b/src/plugins/template/tests/functional/op_reference/embeddingbag_offsetssum.cpp index f7e7bdcafaa7f0..9967e99b8e2317 100644 --- a/src/plugins/template/tests/functional/op_reference/embeddingbag_offsetssum.cpp +++ b/src/plugins/template/tests/functional/op_reference/embeddingbag_offsetssum.cpp @@ -4,9 +4,8 @@ #include -#include - #include "base_reference_test.hpp" +#include "shared_test_classes/base/layer_test_utils.hpp" using namespace reference_tests; using namespace ov; diff --git a/src/plugins/template/tests/functional/op_reference/embeddingbag_packedsum.cpp b/src/plugins/template/tests/functional/op_reference/embeddingbag_packedsum.cpp index 80af12d4053c8f..ea9dfe34decb22 100644 --- a/src/plugins/template/tests/functional/op_reference/embeddingbag_packedsum.cpp +++ b/src/plugins/template/tests/functional/op_reference/embeddingbag_packedsum.cpp @@ -4,9 +4,8 @@ #include -#include - #include "base_reference_test.hpp" +#include "shared_test_classes/base/layer_test_utils.hpp" using namespace reference_tests; using namespace ov; diff --git a/src/plugins/template/tests/functional/op_reference/extract_image_patches.cpp b/src/plugins/template/tests/functional/op_reference/extract_image_patches.cpp index 62fc41dbea9b2c..af82d7e3c74872 100644 --- a/src/plugins/template/tests/functional/op_reference/extract_image_patches.cpp +++ b/src/plugins/template/tests/functional/op_reference/extract_image_patches.cpp @@ -5,8 +5,8 @@ #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" -#include "openvino/opsets/opset3.hpp" +#include "openvino/op/extractimagepatches.hpp" +#include "openvino/op/parameter.hpp" using namespace reference_tests; using namespace ov; @@ -61,8 +61,8 @@ class ReferenceExtractImagePatchesTest : public testing::TestWithParam CreateModel(const ExtractImagePatchesParams& params) { - const auto data = std::make_shared(params.data.type, params.data.shape); - const auto extrace_image_patches = std::make_shared(data, + const auto data = std::make_shared(params.data.type, params.data.shape); + const auto extrace_image_patches = std::make_shared(data, params.sizes, params.strides, params.rates, diff --git a/src/plugins/template/tests/functional/op_reference/fake_quantize.cpp b/src/plugins/template/tests/functional/op_reference/fake_quantize.cpp index 418d02c23c5d08..d2ea203ff8e942 100644 --- a/src/plugins/template/tests/functional/op_reference/fake_quantize.cpp +++ b/src/plugins/template/tests/functional/op_reference/fake_quantize.cpp @@ -253,6 +253,22 @@ std::vector generateParamsForFakeQuantize() { }), 16, op::AutoBroadcastSpec(op::AutoBroadcastType::NUMPY)), + FakeQuantizeParams( + ov::Shape{1, 2, 4, 4}, + ov::Shape{1, 2, 4, 4}, + IN_ET, + IN_ET, + iota_vector(shape_size(Shape{1, 2, 4, 4})), + std::vector{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 8.75, 8.75, 8.75, 8.75, 8.75, 8.75, 17.5, + 23.75, 23.75, 27.5, 27.5, 27.5, 27.5, 27.5, 31.25, 31.25, 31.25, 31.25, 31.25, 35, 35, 35, 35, + }, + op::v0::Constant::create(IN_ET, Shape{1, 2, 1, 1}, {5.f, 10.f}), + op::v0::Constant::create(IN_ET, Shape{1, 1}, {30.f}), + op::v0::Constant::create(IN_ET, Shape{2, 1, 1}, {0.f, 20.f}), + op::v0::Constant::create(IN_ET, Shape{1}, {35.f}), + 5), + }; return params; } diff --git a/src/plugins/template/tests/functional/op_reference/gather.cpp b/src/plugins/template/tests/functional/op_reference/gather.cpp index 916cee50407836..99b1c82a8d91d8 100644 --- a/src/plugins/template/tests/functional/op_reference/gather.cpp +++ b/src/plugins/template/tests/functional/op_reference/gather.cpp @@ -2,12 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/gather.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" -#include "openvino/opsets/opset7.hpp" -#include "openvino/opsets/opset8.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/parameter.hpp" using namespace reference_tests; using namespace ov; @@ -62,11 +63,11 @@ class ReferenceGatherTest : public testing::TestWithParam, public private: static std::shared_ptr CreateFunction(const GatherParams& params) { - const auto P = std::make_shared(params.dataTensor.type, params.dataTensor.shape); - const auto I = std::make_shared(params.indicesTensor.type, params.indicesTensor.shape); + const auto P = std::make_shared(params.dataTensor.type, params.dataTensor.shape); + const auto I = std::make_shared(params.indicesTensor.type, params.indicesTensor.shape); const auto A = - opset1::Constant::create(params.axisTensor.type, params.axisTensor.shape, params.axisTensor.data.data()); - const auto G = std::make_shared(P, I, A); + op::v0::Constant::create(params.axisTensor.type, params.axisTensor.shape, params.axisTensor.data.data()); + const auto G = std::make_shared(P, I, A); const auto f = std::make_shared(G, ParameterVector{P, I}); return f; } @@ -129,11 +130,11 @@ class ReferenceGatherTestV7 : public testing::TestWithParam, pub private: static std::shared_ptr CreateFunction(const GatherParamsV7& params) { - const auto P = std::make_shared(params.dataTensor.type, params.dataTensor.shape); - const auto I = std::make_shared(params.indicesTensor.type, params.indicesTensor.shape); + const auto P = std::make_shared(params.dataTensor.type, params.dataTensor.shape); + const auto I = std::make_shared(params.indicesTensor.type, params.indicesTensor.shape); const auto A = - opset1::Constant::create(params.axisTensor.type, params.axisTensor.shape, params.axisTensor.data.data()); - const auto G = std::make_shared(P, I, A, params.batchDims); + op::v0::Constant::create(params.axisTensor.type, params.axisTensor.shape, params.axisTensor.data.data()); + const auto G = std::make_shared(P, I, A, params.batchDims); const auto f = std::make_shared(G, ParameterVector{P, I}); return f; } @@ -146,11 +147,11 @@ TEST_P(ReferenceGatherTestV7, CompareWithRefs) { class ReferenceGatherTestV8 : public ReferenceGatherTestV7 { private: static std::shared_ptr CreateFunction(const GatherParamsV7& params) { - const auto P = std::make_shared(params.dataTensor.type, params.dataTensor.shape); - const auto I = std::make_shared(params.indicesTensor.type, params.indicesTensor.shape); + const auto P = std::make_shared(params.dataTensor.type, params.dataTensor.shape); + const auto I = std::make_shared(params.indicesTensor.type, params.indicesTensor.shape); const auto A = - opset1::Constant::create(params.axisTensor.type, params.axisTensor.shape, params.axisTensor.data.data()); - const auto G = std::make_shared(P, I, A, params.batchDims); + op::v0::Constant::create(params.axisTensor.type, params.axisTensor.shape, params.axisTensor.data.data()); + const auto G = std::make_shared(P, I, A, params.batchDims); const auto f = std::make_shared(G, ParameterVector{P, I}); return f; } diff --git a/src/plugins/template/tests/functional/op_reference/gather_tree.cpp b/src/plugins/template/tests/functional/op_reference/gather_tree.cpp index 696820760e8fea..57a8b796431fc2 100644 --- a/src/plugins/template/tests/functional/op_reference/gather_tree.cpp +++ b/src/plugins/template/tests/functional/op_reference/gather_tree.cpp @@ -2,10 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/gather_tree.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" +#include "openvino/op/parameter.hpp" using namespace reference_tests; using namespace ov; @@ -59,11 +61,11 @@ class ReferenceGatherTreeTest : public testing::TestWithParam, private: static std::shared_ptr CreateFunction(const GatherTreeParams& params) { - const auto step_ids = std::make_shared(params.stepIds.type, params.stepIds.shape); - const auto parent_idx = std::make_shared(params.parentIdx.type, params.parentIdx.shape); - const auto max_seq_len = std::make_shared(params.maxSeqLen.type, params.maxSeqLen.shape); - const auto end_token = std::make_shared(params.endToken.type, params.endToken.shape); - const auto gather_tree = std::make_shared(step_ids, parent_idx, max_seq_len, end_token); + const auto step_ids = std::make_shared(params.stepIds.type, params.stepIds.shape); + const auto parent_idx = std::make_shared(params.parentIdx.type, params.parentIdx.shape); + const auto max_seq_len = std::make_shared(params.maxSeqLen.type, params.maxSeqLen.shape); + const auto end_token = std::make_shared(params.endToken.type, params.endToken.shape); + const auto gather_tree = std::make_shared(step_ids, parent_idx, max_seq_len, end_token); const auto f = std::make_shared(gather_tree, ParameterVector{step_ids, parent_idx, max_seq_len, end_token}); return f; diff --git a/src/plugins/template/tests/functional/op_reference/group_convolution_backprop.cpp b/src/plugins/template/tests/functional/op_reference/group_convolution_backprop.cpp index 6cc21eb9cb4f04..b378fe18cc27cf 100644 --- a/src/plugins/template/tests/functional/op_reference/group_convolution_backprop.cpp +++ b/src/plugins/template/tests/functional/op_reference/group_convolution_backprop.cpp @@ -5,8 +5,8 @@ #include #include "base_reference_test.hpp" +#include "openvino/op/constant.hpp" #include "openvino/op/group_conv.hpp" -#include "openvino/opsets/opset8.hpp" using namespace reference_tests; using namespace ov; @@ -187,7 +187,7 @@ class ReferenceGroupConvolutionBackpropDataLayerOutShapeTest const auto in = std::make_shared(params.inType, params.inputShape); const auto filter = std::make_shared(params.inType, params.filterShape); - auto output_shape = std::make_shared(element::i64, + auto output_shape = std::make_shared(element::i64, params.constantOutputShape, params.constantOutputShapeData); const auto GroupConvolutionBackpropData = diff --git a/src/plugins/template/tests/functional/op_reference/if.cpp b/src/plugins/template/tests/functional/op_reference/if.cpp index 81b454c01484cf..eef66bb3e5ad61 100644 --- a/src/plugins/template/tests/functional/op_reference/if.cpp +++ b/src/plugins/template/tests/functional/op_reference/if.cpp @@ -5,11 +5,11 @@ #include #include -#include #include -#include #include "base_reference_test.hpp" +#include "ie_core.hpp" +#include "shared_test_classes/base/layer_test_utils.hpp" using namespace reference_tests; using namespace ov; diff --git a/src/plugins/template/tests/functional/op_reference/loop.cpp b/src/plugins/template/tests/functional/op_reference/loop.cpp index 7ff49b7173f9ab..ffdbc0b8dc6ee2 100644 --- a/src/plugins/template/tests/functional/op_reference/loop.cpp +++ b/src/plugins/template/tests/functional/op_reference/loop.cpp @@ -2,14 +2,19 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include "openvino/op/loop.hpp" -#include -#include +#include #include "base_reference_test.hpp" #include "common_test_utils/common_utils.hpp" #include "functional_test_utils/skip_tests_config.hpp" +#include "openvino/core/model.hpp" +#include "openvino/op/add.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/multiply.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/result.hpp" namespace { enum LOOP_IN_TYPE { INVARIANT, MERGED }; @@ -30,36 +35,36 @@ struct LoopDynamicInputs : public LoopFunctionalBase { const int64_t& trip_count_value, const std::vector& loop_in_type, const ov::element::Type& net_type) override { - auto X = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); - auto Y = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); - auto M = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); + auto X = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); + auto Y = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); + auto M = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); // Set up the cell body, a function from (Xi, Yi) -> (Zo) // Body parameters - auto Xi = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); - auto Yi = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); - auto M_body = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); - auto body_condition = std::make_shared(ov::element::boolean, ov::Shape{1}, true); + auto Xi = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); + auto Yi = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); + auto M_body = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); + auto body_condition = std::make_shared(ov::element::boolean, ov::Shape{1}, true); - auto trip_count = std::make_shared(ov::element::i64, ov::Shape{1}, 3); - auto exec_condition = std::make_shared(ov::element::boolean, ov::Shape{1}, true); + auto trip_count = std::make_shared(ov::element::i64, ov::Shape{1}, 3); + auto exec_condition = std::make_shared(ov::element::boolean, ov::Shape{1}, true); // Body - auto sum = std::make_shared(Xi, Yi); - auto Zo = std::make_shared(sum, M_body); + auto sum = std::make_shared(Xi, Yi); + auto Zo = std::make_shared(sum, M_body); auto body = std::make_shared(ov::OutputVector{body_condition, Zo}, ov::ParameterVector{Xi, Yi, M_body}); - auto loop = std::make_shared(trip_count, exec_condition); + auto loop = std::make_shared(trip_count, exec_condition); loop->set_function(body); loop->set_invariant_input(Xi, X); loop->set_invariant_input(Yi, Y); loop->set_merged_input(M_body, M, Zo); - loop->set_special_body_ports(ov::opset8::Loop::SpecialBodyPorts{-1, 0}); + loop->set_special_body_ports(ov::op::v5::Loop::SpecialBodyPorts{-1, 0}); // Output is last Zo - auto result = std::make_shared(loop->get_iter_value(Zo, -1)); + auto result = std::make_shared(loop->get_iter_value(Zo, -1)); return std::make_shared(ov::ResultVector{result}, ov::ParameterVector{X, Y, M}); } }; @@ -131,7 +136,7 @@ struct LoopStaticInputs : public LoopFunctionalBase { const ov::element::Type& net_type) override { ov::ParameterVector loop_params; for (auto&& input : loop_inputs) { - loop_params.emplace_back(std::make_shared(input.type, input.shape)); + loop_params.emplace_back(std::make_shared(input.type, input.shape)); } // Set up the cell body, a function from (Xi, Yi) -> (Zo) @@ -139,26 +144,26 @@ struct LoopStaticInputs : public LoopFunctionalBase { const std::vector body_params_shapes(loop_inputs.size(), ov::PartialShape::dynamic()); ov::ParameterVector body_params; for (const auto& pshape : body_params_shapes) { - body_params.emplace_back(std::make_shared(net_type, pshape)); + body_params.emplace_back(std::make_shared(net_type, pshape)); } const auto body_condition_const = - std::make_shared(ov::element::boolean, ov::Shape{1}, true); - const auto exec_condition = std::make_shared(ov::element::boolean, ov::Shape{1}, true); + std::make_shared(ov::element::boolean, ov::Shape{1}, true); + const auto exec_condition = std::make_shared(ov::element::boolean, ov::Shape{1}, true); std::shared_ptr trip_count_input; - trip_count_input = std::make_shared(ov::element::i64, ov::Shape{1}, trip_count); + trip_count_input = std::make_shared(ov::element::i64, ov::Shape{1}, trip_count); // Body std::shared_ptr Zo = body_params[0]; for (size_t i = 1; i < body_params.size(); ++i) { - Zo = std::make_shared(body_params[i], Zo); + Zo = std::make_shared(body_params[i], Zo); } const auto body = std::make_shared(ov::OutputVector{body_condition_const, Zo}, body_params); - const auto loop = std::make_shared(trip_count_input, exec_condition); + const auto loop = std::make_shared(trip_count_input, exec_condition); loop->set_function(body); - loop->set_special_body_ports(ov::opset8::Loop::SpecialBodyPorts{-1, 0}); + loop->set_special_body_ports(ov::op::v5::Loop::SpecialBodyPorts{-1, 0}); for (size_t i = 0; i < body_params.size(); ++i) { if (loop_in_type[i] == LOOP_IN_TYPE::INVARIANT) { @@ -177,9 +182,9 @@ struct LoopStaticInputs : public LoopFunctionalBase { // start=0, stride=1, part_size=1, end=-1, axis=1 const auto out2 = loop->get_concatenated_slices(Zo, 0, 1, 1, -1, 1); - const auto result0 = std::make_shared(out0); - const auto result1 = std::make_shared(out1); - const auto result2 = std::make_shared(out2); + const auto result0 = std::make_shared(out0); + const auto result1 = std::make_shared(out1); + const auto result2 = std::make_shared(out2); const auto function = std::make_shared(ov::ResultVector{result0, result1, result2}, loop_params, "loop"); return function; diff --git a/src/plugins/template/tests/functional/op_reference/lstm_cell.cpp b/src/plugins/template/tests/functional/op_reference/lstm_cell.cpp index 8df731e9f6f459..7b8686dcaf8c4b 100644 --- a/src/plugins/template/tests/functional/op_reference/lstm_cell.cpp +++ b/src/plugins/template/tests/functional/op_reference/lstm_cell.cpp @@ -2,11 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/lstm_cell.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" -#include "openvino/opsets/opset4.hpp" +#include "openvino/op/parameter.hpp" using namespace reference_tests; using namespace ov; @@ -84,15 +85,15 @@ class ReferenceLSTMCellTest : public testing::TestWithParam, pub private: static std::shared_ptr CreateFunction(const LSTMCellParams& params) { - const auto X = std::make_shared(params.X.type, params.X.shape); - const auto W = std::make_shared(params.W.type, params.W.shape); - const auto R = std::make_shared(params.R.type, params.R.shape); - const auto H_t = std::make_shared(params.H_t.type, params.H_t.shape); - const auto C_t = std::make_shared(params.C_t.type, params.C_t.shape); - const auto B = std::make_shared(params.B.type, params.B.shape); + const auto X = std::make_shared(params.X.type, params.X.shape); + const auto W = std::make_shared(params.W.type, params.W.shape); + const auto R = std::make_shared(params.R.type, params.R.shape); + const auto H_t = std::make_shared(params.H_t.type, params.H_t.shape); + const auto C_t = std::make_shared(params.C_t.type, params.C_t.shape); + const auto B = std::make_shared(params.B.type, params.B.shape); const auto lstm_cell = - std::make_shared(X, + std::make_shared(X, H_t, C_t, op::util::convert_lstm_node_format(W, op::util::LSTMWeightsFormat::IOFC), @@ -117,15 +118,15 @@ class ReferenceLSTMCellTestBiasDefaultAttrs : public ReferenceLSTMCellTest { private: static std::shared_ptr CreateFunction(const LSTMCellParams& params) { - const auto X = std::make_shared(params.X.type, params.X.shape); - const auto W = std::make_shared(params.W.type, params.W.shape); - const auto R = std::make_shared(params.R.type, params.R.shape); - const auto H_t = std::make_shared(params.H_t.type, params.H_t.shape); - const auto C_t = std::make_shared(params.C_t.type, params.C_t.shape); - const auto B = std::make_shared(params.B.type, params.B.shape); + const auto X = std::make_shared(params.X.type, params.X.shape); + const auto W = std::make_shared(params.W.type, params.W.shape); + const auto R = std::make_shared(params.R.type, params.R.shape); + const auto H_t = std::make_shared(params.H_t.type, params.H_t.shape); + const auto C_t = std::make_shared(params.C_t.type, params.C_t.shape); + const auto B = std::make_shared(params.B.type, params.B.shape); const auto lstm_cell = - std::make_shared(X, + std::make_shared(X, H_t, C_t, op::util::convert_lstm_node_format(W, op::util::LSTMWeightsFormat::IOFC), @@ -152,14 +153,14 @@ class ReferenceLSTMCellTestBiasClip : public ReferenceLSTMCellTest { static std::shared_ptr CreateFunction(const LSTMCellParams& params) { const float clip_threshold = 3.5f; - const auto X = std::make_shared(params.X.type, params.X.shape); - const auto W = std::make_shared(params.W.type, params.W.shape); - const auto R = std::make_shared(params.R.type, params.R.shape); - const auto H_t = std::make_shared(params.H_t.type, params.H_t.shape); - const auto C_t = std::make_shared(params.C_t.type, params.C_t.shape); - const auto B = std::make_shared(params.B.type, params.B.shape); + const auto X = std::make_shared(params.X.type, params.X.shape); + const auto W = std::make_shared(params.W.type, params.W.shape); + const auto R = std::make_shared(params.R.type, params.R.shape); + const auto H_t = std::make_shared(params.H_t.type, params.H_t.shape); + const auto C_t = std::make_shared(params.C_t.type, params.C_t.shape); + const auto B = std::make_shared(params.B.type, params.B.shape); - const auto lstm_cell = std::make_shared(X, + const auto lstm_cell = std::make_shared(X, H_t, C_t, W, @@ -191,15 +192,15 @@ TEST_P(ReferenceLSTMCellTestBiasClip, CompareWithRefs) { class ReferenceLSTMCellV1Test : public ReferenceLSTMCellTest { private: static std::shared_ptr CreateFunction(const LSTMCellParams& params) { - const auto X = std::make_shared(params.X.type, params.X.shape); - const auto W = std::make_shared(params.W.type, params.W.shape); - const auto R = std::make_shared(params.R.type, params.R.shape); - const auto H_t = std::make_shared(params.H_t.type, params.H_t.shape); - const auto C_t = std::make_shared(params.C_t.type, params.C_t.shape); - const auto B = std::make_shared(params.B.type, params.B.shape); + const auto X = std::make_shared(params.X.type, params.X.shape); + const auto W = std::make_shared(params.W.type, params.W.shape); + const auto R = std::make_shared(params.R.type, params.R.shape); + const auto H_t = std::make_shared(params.H_t.type, params.H_t.shape); + const auto C_t = std::make_shared(params.C_t.type, params.C_t.shape); + const auto B = std::make_shared(params.B.type, params.B.shape); const auto lstm_cell = - std::make_shared(X, + std::make_shared(X, H_t, C_t, op::util::convert_lstm_node_format(W, op::util::LSTMWeightsFormat::IOFC), @@ -215,15 +216,15 @@ class ReferenceLSTMCellV1Test : public ReferenceLSTMCellTest { class ReferenceLSTMCellV1TestBiasDefaultAttrs : public ReferenceLSTMCellTestBiasDefaultAttrs { private: static std::shared_ptr CreateFunction(const LSTMCellParams& params) { - const auto X = std::make_shared(params.X.type, params.X.shape); - const auto W = std::make_shared(params.W.type, params.W.shape); - const auto R = std::make_shared(params.R.type, params.R.shape); - const auto H_t = std::make_shared(params.H_t.type, params.H_t.shape); - const auto C_t = std::make_shared(params.C_t.type, params.C_t.shape); - const auto B = std::make_shared(params.B.type, params.B.shape); + const auto X = std::make_shared(params.X.type, params.X.shape); + const auto W = std::make_shared(params.W.type, params.W.shape); + const auto R = std::make_shared(params.R.type, params.R.shape); + const auto H_t = std::make_shared(params.H_t.type, params.H_t.shape); + const auto C_t = std::make_shared(params.C_t.type, params.C_t.shape); + const auto B = std::make_shared(params.B.type, params.B.shape); const auto lstm_cell = - std::make_shared(X, + std::make_shared(X, H_t, C_t, op::util::convert_lstm_node_format(W, op::util::LSTMWeightsFormat::IOFC), @@ -256,15 +257,15 @@ class ReferenceLSTMCellV1TestBiasClip : public ReferenceLSTMCellTestBiasClip { static std::shared_ptr CreateFunction(const LSTMCellParams& params) { const float clip_threshold = 3.5f; - const auto X = std::make_shared(params.X.type, params.X.shape); - const auto W = std::make_shared(params.W.type, params.W.shape); - const auto R = std::make_shared(params.R.type, params.R.shape); - const auto H_t = std::make_shared(params.H_t.type, params.H_t.shape); - const auto C_t = std::make_shared(params.C_t.type, params.C_t.shape); - const auto B = std::make_shared(params.B.type, params.B.shape); - const auto P = std::make_shared(params.P.type, params.P.shape); + const auto X = std::make_shared(params.X.type, params.X.shape); + const auto W = std::make_shared(params.W.type, params.W.shape); + const auto R = std::make_shared(params.R.type, params.R.shape); + const auto H_t = std::make_shared(params.H_t.type, params.H_t.shape); + const auto C_t = std::make_shared(params.C_t.type, params.C_t.shape); + const auto B = std::make_shared(params.B.type, params.B.shape); + const auto P = std::make_shared(params.P.type, params.P.shape); - const auto lstm_cell = std::make_shared(X, + const auto lstm_cell = std::make_shared(X, H_t, C_t, W, diff --git a/src/plugins/template/tests/functional/op_reference/matrix_nms.cpp b/src/plugins/template/tests/functional/op_reference/matrix_nms.cpp index 4c2fd3ee50755c..f0adb506f6fa21 100644 --- a/src/plugins/template/tests/functional/op_reference/matrix_nms.cpp +++ b/src/plugins/template/tests/functional/op_reference/matrix_nms.cpp @@ -2,18 +2,19 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/matrix_nms.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" -#include "openvino/opsets/opset8.hpp" +#include "openvino/op/parameter.hpp" using namespace reference_tests; using namespace ov; namespace { struct MatrixNmsParams { - MatrixNmsParams(const opset8::MatrixNms::Attributes& attrs, + MatrixNmsParams(const op::v8::MatrixNms::Attributes& attrs, const reference_tests::Tensor& boxes, const reference_tests::Tensor& scores, const reference_tests::Tensor& expectedSelectedScores, @@ -28,7 +29,7 @@ struct MatrixNmsParams { expectedValidOutputs(expectedValidOutputs), testcaseName(testcaseName) {} - opset8::MatrixNms::Attributes attrs; + op::v8::MatrixNms::Attributes attrs; reference_tests::Tensor boxes; reference_tests::Tensor scores; reference_tests::Tensor expectedSelectedScores; @@ -71,9 +72,9 @@ class ReferenceMatrixNmsTest : public testing::TestWithParam, p private: static std::shared_ptr CreateFunction(const MatrixNmsParams& params) { - const auto boxes = std::make_shared(params.boxes.type, PartialShape::dynamic()); - const auto scores = std::make_shared(params.scores.type, PartialShape::dynamic()); - const auto nms = std::make_shared(boxes, scores, params.attrs); + const auto boxes = std::make_shared(params.boxes.type, PartialShape::dynamic()); + const auto scores = std::make_shared(params.scores.type, PartialShape::dynamic()); + const auto nms = std::make_shared(boxes, scores, params.attrs); const auto f = std::make_shared(nms->outputs(), ParameterVector{boxes, scores}); return f; } @@ -91,14 +92,14 @@ std::vector generateParams() { std::vector params{ MatrixNmsParams( { - opset8::MatrixNms::SortResultType::SCORE, // sort_result_type + op::v8::MatrixNms::SortResultType::SCORE, // sort_result_type false, // sort_result_across_batch ET_IND, // output_type 0.0f, // score_threshold 3, // nms_top_k -1, // keep_top_k 0, // background_class - opset8::MatrixNms::DecayFunction::LINEAR, // decay_function + op::v8::MatrixNms::DecayFunction::LINEAR, // decay_function 2.0f, // gaussian_sigma 0.0f, // post_threshold true, // normalized @@ -135,14 +136,14 @@ std::vector generateParams() { "matrix_nms_output_type_i64"), MatrixNmsParams( { - opset8::MatrixNms::SortResultType::SCORE, // sort_result_type + op::v8::MatrixNms::SortResultType::SCORE, // sort_result_type false, // sort_result_across_batch ET_IND, // output_type 0.0f, // score_threshold 3, // nms_top_k -1, // keep_top_k 0, // background_class - opset8::MatrixNms::DecayFunction::LINEAR, // decay_function + op::v8::MatrixNms::DecayFunction::LINEAR, // decay_function 2.0f, // gaussian_sigma 0.0f, // post_threshold true, // normalized @@ -179,14 +180,14 @@ std::vector generateParams() { "matrix_nms_output_type_i32"), MatrixNmsParams( { - opset8::MatrixNms::SortResultType::SCORE, // sort_result_type + op::v8::MatrixNms::SortResultType::SCORE, // sort_result_type false, // sort_result_across_batch ET_IND, // output_type 0.0f, // score_threshold 3, // nms_top_k -1, // keep_top_k 0, // background_class - opset8::MatrixNms::DecayFunction::GAUSSIAN, // decay_function + op::v8::MatrixNms::DecayFunction::GAUSSIAN, // decay_function 2.0f, // gaussian_sigma 0.0f, // post_threshold true, // normalized @@ -223,14 +224,14 @@ std::vector generateParams() { "matrix_nms_gaussian"), MatrixNmsParams( { - opset8::MatrixNms::SortResultType::SCORE, // sort_result_type + op::v8::MatrixNms::SortResultType::SCORE, // sort_result_type false, // sort_result_across_batch ET_IND, // output_type 0.0f, // score_threshold 3, // nms_top_k -1, // keep_top_k 0, // background_class - opset8::MatrixNms::DecayFunction::LINEAR, // decay_function + op::v8::MatrixNms::DecayFunction::LINEAR, // decay_function 2.0f, // gaussian_sigma 0.0f, // post_threshold true, // normalized @@ -258,14 +259,14 @@ std::vector generateParams() { "matrix_nms_two_batches_two_classes"), MatrixNmsParams( { - opset8::MatrixNms::SortResultType::SCORE, // sort_result_type + op::v8::MatrixNms::SortResultType::SCORE, // sort_result_type true, // sort_result_across_batch ET_IND, // output_type 0.0f, // score_threshold 3, // nms_top_k -1, // keep_top_k -1, // background_class - opset8::MatrixNms::DecayFunction::LINEAR, // decay_function + op::v8::MatrixNms::DecayFunction::LINEAR, // decay_function 2.0f, // gaussian_sigma 0.5f, // post_threshold true, // normalized @@ -296,14 +297,14 @@ std::vector generateParams() { "matrix_nms_two_batches_two_classes_by_score_cross_batch"), MatrixNmsParams( { - opset8::MatrixNms::SortResultType::CLASSID, // sort_result_type + op::v8::MatrixNms::SortResultType::CLASSID, // sort_result_type true, // sort_result_across_batch ET_IND, // output_type 0.0f, // score_threshold 3, // nms_top_k -1, // keep_top_k -1, // background_class - opset8::MatrixNms::DecayFunction::LINEAR, // decay_function + op::v8::MatrixNms::DecayFunction::LINEAR, // decay_function 2.0f, // gaussian_sigma 0.5f, // post_threshold true, // normalized @@ -334,14 +335,14 @@ std::vector generateParams() { "matrix_nms_two_batches_two_classes_by_classid_cross_batch"), MatrixNmsParams( { - opset8::MatrixNms::SortResultType::CLASSID, // sort_result_type + op::v8::MatrixNms::SortResultType::CLASSID, // sort_result_type false, // sort_result_across_batch ET_IND, // output_type 0.0f, // score_threshold 3, // nms_top_k 3, // keep_top_k 0, // background_class - opset8::MatrixNms::DecayFunction::LINEAR, // decay_function + op::v8::MatrixNms::DecayFunction::LINEAR, // decay_function 2.0f, // gaussian_sigma 0.0f, // post_threshold true, // normalized @@ -369,14 +370,14 @@ std::vector generateParams() { "matrix_nms_by_keep_top_k"), MatrixNmsParams( { - opset8::MatrixNms::SortResultType::SCORE, // sort_result_type + op::v8::MatrixNms::SortResultType::SCORE, // sort_result_type false, // sort_result_across_batch ET_IND, // output_type 0.0f, // score_threshold 3, // nms_top_k -1, // keep_top_k -1, // background_class - opset8::MatrixNms::DecayFunction::LINEAR, // decay_function + op::v8::MatrixNms::DecayFunction::LINEAR, // decay_function 2.0f, // gaussian_sigma 0.0f, // post_threshold true, // normalized @@ -400,14 +401,14 @@ std::vector generateParams() { "matrix_nms_background"), MatrixNmsParams( { - opset8::MatrixNms::SortResultType::SCORE, // sort_result_type + op::v8::MatrixNms::SortResultType::SCORE, // sort_result_type false, // sort_result_across_batch ET_IND, // output_type 0.0f, // score_threshold 3, // nms_top_k -1, // keep_top_k -1, // background_class - opset8::MatrixNms::DecayFunction::LINEAR, // decay_function + op::v8::MatrixNms::DecayFunction::LINEAR, // decay_function 2.0f, // gaussian_sigma 0.0f, // post_threshold true, // normalized @@ -442,14 +443,14 @@ std::vector generateParams() { "matrix_nms_flipped_coordinates"), MatrixNmsParams( { - opset8::MatrixNms::SortResultType::SCORE, // sort_result_type + op::v8::MatrixNms::SortResultType::SCORE, // sort_result_type false, // sort_result_across_batch ET_IND, // output_type 0.0f, // score_threshold 3, // nms_top_k -1, // keep_top_k -1, // background_class - opset8::MatrixNms::DecayFunction::LINEAR, // decay_function + op::v8::MatrixNms::DecayFunction::LINEAR, // decay_function 2.0f, // gaussian_sigma 0.8f, // post_threshold true, // normalized @@ -468,14 +469,14 @@ std::vector generateParams() { "matrix_nms_post_threshold"), MatrixNmsParams( { - opset8::MatrixNms::SortResultType::SCORE, // sort_result_type + op::v8::MatrixNms::SortResultType::SCORE, // sort_result_type false, // sort_result_across_batch ET_IND, // output_type 0.0f, // score_threshold 3, // nms_top_k -1, // keep_top_k -1, // background_class - opset8::MatrixNms::DecayFunction::LINEAR, // decay_function + op::v8::MatrixNms::DecayFunction::LINEAR, // decay_function 2.0f, // gaussian_sigma 0.3f, // post_threshold true, // normalized @@ -497,14 +498,14 @@ std::vector generateParams() { "matrix_nms_identical_boxes"), MatrixNmsParams( { - opset8::MatrixNms::SortResultType::SCORE, // sort_result_type + op::v8::MatrixNms::SortResultType::SCORE, // sort_result_type false, // sort_result_across_batch ET_IND, // output_type 0.0f, // score_threshold 2, // nms_top_k -1, // keep_top_k -1, // background_class - opset8::MatrixNms::DecayFunction::LINEAR, // decay_function + op::v8::MatrixNms::DecayFunction::LINEAR, // decay_function 2.0f, // gaussian_sigma 0.0f, // post_threshold true, // normalized @@ -523,14 +524,14 @@ std::vector generateParams() { "matrix_nms_nms_top_k"), MatrixNmsParams( { - opset8::MatrixNms::SortResultType::SCORE, // sort_result_type + op::v8::MatrixNms::SortResultType::SCORE, // sort_result_type false, // sort_result_across_batch ET_IND, // output_type 0.0f, // score_threshold 3, // nms_top_k -1, // keep_top_k -1, // background_class - opset8::MatrixNms::DecayFunction::LINEAR, // decay_function + op::v8::MatrixNms::DecayFunction::LINEAR, // decay_function 2.0f, // gaussian_sigma 0.0f, // post_threshold true, // normalized @@ -545,14 +546,14 @@ std::vector generateParams() { "matrix_nms_single_box"), MatrixNmsParams( { - opset8::MatrixNms::SortResultType::SCORE, // sort_result_type + op::v8::MatrixNms::SortResultType::SCORE, // sort_result_type false, // sort_result_across_batch ET_IND, // output_type 2.0f, // score_threshold 3, // nms_top_k -1, // keep_top_k -1, // background_class - opset8::MatrixNms::DecayFunction::LINEAR, // decay_function + op::v8::MatrixNms::DecayFunction::LINEAR, // decay_function 2.0f, // gaussian_sigma 0.0f, // post_threshold true, // normalized diff --git a/src/plugins/template/tests/functional/op_reference/multinomial.cpp b/src/plugins/template/tests/functional/op_reference/multinomial.cpp index d2edf5bedd9d60..25159ae3ee2a22 100644 --- a/src/plugins/template/tests/functional/op_reference/multinomial.cpp +++ b/src/plugins/template/tests/functional/op_reference/multinomial.cpp @@ -86,8 +86,11 @@ std::vector generateMultinomialParams() { const ov::Shape prob_2d_shape{2, 4}; const ov::Shape prob_1d_shape{4}; const ov::Shape num_samples_shape{1}; + const ov::Shape prob_1d_shape_expand_small{2}; + const ov::Shape out_1d_shape_expand_big{16}; reference_tests::Tensor num_samples(num_samples_shape, ov::element::Type_t::i32, std::vector{4}); + reference_tests::Tensor num_samples_big(num_samples_shape, ov::element::Type_t::i32, std::vector{16}); reference_tests::Tensor probabilities_2d_no_log(prob_2d_shape, et, @@ -95,50 +98,61 @@ std::vector generateMultinomialParams() { reference_tests::Tensor probabilities_2d_log(prob_2d_shape, et, std::vector{1, 2, 3, 4, 2, 4, 6, 8}); reference_tests::Tensor probabilities_1d_no_log(prob_1d_shape, et, std::vector{0.001, 0.01, 0.1, 0.899}); reference_tests::Tensor probabilities_1d_log(prob_1d_shape, et, std::vector{1, 10, 7, 3}); + reference_tests::Tensor probabilities_1d_expand(prob_1d_shape_expand_small, et, std::vector{0.00001, 0.99999}); - reference_tests::Tensor output_2d_no_log_no_replacement(prob_2d_shape, - ov::element::Type_t::i32, - std::vector{3, 3, 3, 3, 0, 0, 0, 0}); - reference_tests::Tensor output_2d_log_no_replacement(prob_2d_shape, + reference_tests::Tensor output_2d_no_log_replacement(prob_2d_shape, ov::element::Type_t::i32, - std::vector{3, 3, 2, 3, 3, 3, 3, 3}); - reference_tests::Tensor output_1d_no_log_replacement(prob_1d_shape, + std::vector{3, 3, 3, 3, 0, 0, 0, 0}); + reference_tests::Tensor output_2d_log_replacement(prob_2d_shape, + ov::element::Type_t::i32, + std::vector{3, 3, 2, 3, 3, 3, 3, 3}); + reference_tests::Tensor output_1d_no_log_no_replacement(prob_1d_shape, + ov::element::Type_t::i64, + std::vector{3, 2, 1, 0}); + reference_tests::Tensor output_1d_log_no_replacement(prob_1d_shape, ov::element::Type_t::i64, - std::vector{3, 2, 1, 0}); - reference_tests::Tensor output_1d_log_replacement(prob_1d_shape, - ov::element::Type_t::i64, - std::vector{1, 2, 3, 0}); + std::vector{1, 2, 3, 0}); + reference_tests::Tensor output_1d_expand(out_1d_shape_expand_big, + ov::element::Type_t::i64, + std::vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); std::vector params; // probabilities, num_samples, output, convert_type, log_probs, with_replacement, name params.emplace_back(probabilities_2d_no_log, num_samples, - output_2d_no_log_no_replacement, + output_2d_no_log_replacement, ov::element::Type_t::i32, false, - false, + true, "input_2d"); params.emplace_back(probabilities_2d_log, num_samples, - output_2d_log_no_replacement, + output_2d_log_replacement, ov::element::Type_t::i32, true, - false, + true, "input_2d"); params.emplace_back(probabilities_1d_no_log, num_samples, - output_1d_no_log_replacement, + output_1d_no_log_no_replacement, ov::element::Type_t::i64, false, - true, + false, "input_1d"); params.emplace_back(probabilities_1d_log, num_samples, - output_1d_log_replacement, + output_1d_log_no_replacement, ov::element::Type_t::i64, true, - true, + false, "input_1d"); + params.emplace_back(probabilities_1d_expand, + num_samples_big, + output_1d_expand, + ov::element::Type_t::i64, + false, + true, + "input_1d_expand"); return params; } diff --git a/src/plugins/template/tests/functional/op_reference/nms_rotated.cpp b/src/plugins/template/tests/functional/op_reference/nms_rotated.cpp index d22aa82911830d..34f0bc074ec2f1 100644 --- a/src/plugins/template/tests/functional/op_reference/nms_rotated.cpp +++ b/src/plugins/template/tests/functional/op_reference/nms_rotated.cpp @@ -2,11 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/nms_rotated.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" -#include "openvino/opsets/opset13.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/parameter.hpp" using namespace reference_tests; using namespace ov; @@ -72,19 +74,19 @@ class ReferenceNMSRotatedTest : public testing::TestWithParam, private: static std::shared_ptr CreateModel(const NMSRotatedParams& params) { - const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); - const auto scores = std::make_shared(params.scores.type, params.scores.shape); + const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); + const auto scores = std::make_shared(params.scores.type, params.scores.shape); const auto max_output_boxes_per_class = - std::make_shared(params.maxOutputBoxesPerClass.type, + std::make_shared(params.maxOutputBoxesPerClass.type, params.maxOutputBoxesPerClass.shape, params.maxOutputBoxesPerClass.data.data()); - const auto iou_threshold = std::make_shared(params.iouThreshold.type, + const auto iou_threshold = std::make_shared(params.iouThreshold.type, params.iouThreshold.shape, params.iouThreshold.data.data()); - const auto score_threshold = std::make_shared(params.scoreThreshold.type, + const auto score_threshold = std::make_shared(params.scoreThreshold.type, params.scoreThreshold.shape, params.scoreThreshold.data.data()); - const auto nms = std::make_shared(boxes, + const auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, iou_threshold, @@ -113,16 +115,16 @@ class ReferenceNMSRotatedTestWithoutConstants : public ReferenceNMSRotatedTest { private: static std::shared_ptr CreateModel(const NMSRotatedParams& params) { - const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); - const auto scores = std::make_shared(params.scores.type, params.scores.shape); + const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); + const auto scores = std::make_shared(params.scores.type, params.scores.shape); const auto max_output_boxes_per_class = - std::make_shared(params.maxOutputBoxesPerClass.type, + std::make_shared(params.maxOutputBoxesPerClass.type, params.maxOutputBoxesPerClass.shape); const auto iou_threshold = - std::make_shared(params.iouThreshold.type, params.iouThreshold.shape); + std::make_shared(params.iouThreshold.type, params.iouThreshold.shape); const auto score_threshold = - std::make_shared(params.scoreThreshold.type, params.scoreThreshold.shape); - const auto nms = std::make_shared(boxes, + std::make_shared(params.scoreThreshold.type, params.scoreThreshold.shape); + const auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, iou_threshold, diff --git a/src/plugins/template/tests/functional/op_reference/non_max_suppression.cpp b/src/plugins/template/tests/functional/op_reference/non_max_suppression.cpp index 333ea4cf0d2845..7a3e8f28b03550 100644 --- a/src/plugins/template/tests/functional/op_reference/non_max_suppression.cpp +++ b/src/plugins/template/tests/functional/op_reference/non_max_suppression.cpp @@ -2,13 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/non_max_suppression.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" -#include "openvino/opsets/opset3.hpp" -#include "openvino/opsets/opset4.hpp" -#include "openvino/opsets/opset5.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/parameter.hpp" using namespace reference_tests; using namespace ov; @@ -21,7 +21,7 @@ struct NonMaxSuppressionParams { reference_tests::Tensor iouThreshold; reference_tests::Tensor scoreThreshold; reference_tests::Tensor softNmsSigma; - opset5::NonMaxSuppression::BoxEncodingType boxEncoding; + op::v5::NonMaxSuppression::BoxEncodingType boxEncoding; reference_tests::Tensor expectedSelectedIndices; reference_tests::Tensor expectedSelectedScores; reference_tests::Tensor expectedValidOutputs; @@ -75,22 +75,22 @@ class ReferenceNonMaxSuppressionTest : public testing::TestWithParam CreateFunction(const NonMaxSuppressionParams& params) { - const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); - const auto scores = std::make_shared(params.scores.type, params.scores.shape); + const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); + const auto scores = std::make_shared(params.scores.type, params.scores.shape); const auto max_output_boxes_per_class = - std::make_shared(params.maxOutputBoxesPerClass.type, + std::make_shared(params.maxOutputBoxesPerClass.type, params.maxOutputBoxesPerClass.shape, params.maxOutputBoxesPerClass.data.data()); - const auto iou_threshold = std::make_shared(params.iouThreshold.type, + const auto iou_threshold = std::make_shared(params.iouThreshold.type, params.iouThreshold.shape, params.iouThreshold.data.data()); - const auto score_threshold = std::make_shared(params.scoreThreshold.type, + const auto score_threshold = std::make_shared(params.scoreThreshold.type, params.scoreThreshold.shape, params.scoreThreshold.data.data()); - const auto soft_nms_sigma = std::make_shared(params.softNmsSigma.type, + const auto soft_nms_sigma = std::make_shared(params.softNmsSigma.type, params.softNmsSigma.shape, params.softNmsSigma.data.data()); - const auto nms = std::make_shared(boxes, + const auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, iou_threshold, @@ -122,18 +122,18 @@ class ReferenceNonMaxSuppressionTestWithoutConstants : public ReferenceNonMaxSup private: static std::shared_ptr CreateFunction(const NonMaxSuppressionParams& params) { - const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); - const auto scores = std::make_shared(params.scores.type, params.scores.shape); + const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); + const auto scores = std::make_shared(params.scores.type, params.scores.shape); const auto max_output_boxes_per_class = - std::make_shared(params.maxOutputBoxesPerClass.type, + std::make_shared(params.maxOutputBoxesPerClass.type, params.maxOutputBoxesPerClass.shape); const auto iou_threshold = - std::make_shared(params.iouThreshold.type, params.iouThreshold.shape); + std::make_shared(params.iouThreshold.type, params.iouThreshold.shape); const auto score_threshold = - std::make_shared(params.scoreThreshold.type, params.scoreThreshold.shape); + std::make_shared(params.scoreThreshold.type, params.scoreThreshold.shape); const auto soft_nms_sigma = - std::make_shared(params.softNmsSigma.type, params.softNmsSigma.shape); - const auto nms = std::make_shared(boxes, + std::make_shared(params.softNmsSigma.type, params.softNmsSigma.shape); + const auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, iou_threshold, @@ -173,7 +173,7 @@ std::vector generateParams() { .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) .softNmsSigma(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset5::NonMaxSuppression::BoxEncodingType::CENTER) + .boxEncoding(op::v5::NonMaxSuppression::BoxEncodingType::CENTER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {3, 3}, std::vector{0, 0, 3, 0, 0, 0, 0, 0, 5})) .expectedSelectedScores( @@ -190,7 +190,7 @@ std::vector generateParams() { .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) .softNmsSigma(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset5::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v5::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {3, 3}, std::vector{0, 0, 3, 0, 0, 0, 0, 0, 5})) .expectedSelectedScores( @@ -211,7 +211,7 @@ std::vector generateParams() { .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) .softNmsSigma(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset5::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v5::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {1, 3}, std::vector{0, 0, 0})) .expectedSelectedScores(reference_tests::Tensor(ET_TH, {1, 3}, std::vector{0.0, 0.0, 0.9})) .expectedValidOutputs(reference_tests::Tensor(ET_IND, {1}, std::vector{1})) @@ -226,7 +226,7 @@ std::vector generateParams() { .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) .softNmsSigma(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset5::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v5::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {2, 3}, std::vector{0, 0, 3, 0, 0, 0})) .expectedSelectedScores( reference_tests::Tensor(ET_TH, {2, 3}, std::vector{0.0, 0.0, 0.95, 0.0, 0.0, 0.9})) @@ -240,7 +240,7 @@ std::vector generateParams() { .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) .softNmsSigma(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset5::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v5::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {1, 3}, std::vector{0, 0, 0})) .expectedSelectedScores(reference_tests::Tensor(ET_TH, {1, 3}, std::vector{0.0, 0.0, 0.9})) .expectedValidOutputs(reference_tests::Tensor(ET_IND, {1}, std::vector{1})) @@ -255,7 +255,7 @@ std::vector generateParams() { .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) .softNmsSigma(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset5::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v5::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {3, 3}, std::vector{0, 0, 3, 0, 0, 0, 0, 0, 5})) .expectedSelectedScores( @@ -272,7 +272,7 @@ std::vector generateParams() { .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.4f})) .softNmsSigma(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset5::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v5::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {2, 3}, std::vector{0, 0, 3, 0, 0, 0})) .expectedSelectedScores( reference_tests::Tensor(ET_TH, {2, 3}, std::vector{0.0, 0.0, 0.95, 0.0, 0.0, 0.9})) @@ -294,7 +294,7 @@ std::vector generateParams() { .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) .softNmsSigma(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset5::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v5::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {4, 3}, std::vector{0, 0, 3, 0, 0, 0, 1, 0, 3, 1, 0, 0})) .expectedSelectedScores(reference_tests::Tensor( @@ -316,7 +316,7 @@ std::vector generateParams() { .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) .softNmsSigma(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset5::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v5::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {4, 3}, std::vector{0, 0, 3, 0, 0, 0, 0, 1, 3, 0, 1, 0})) .expectedSelectedScores(reference_tests::Tensor( @@ -363,7 +363,7 @@ std::vector generateParamsWithoutConstants() { .iouThreshold(reference_tests::Tensor(ET_TH, {1}, std::vector{0.4f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {1}, std::vector{0.2f})) .softNmsSigma(reference_tests::Tensor(ET_TH, {1}, std::vector{0.0f})) - .boxEncoding(opset5::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v5::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {1, 3}, std::vector{0, 0, 3})) .expectedSelectedScores(reference_tests::Tensor(ET_TH, {1, 3}, std::vector{0.0f, 0.0f, 0.95f})) .expectedValidOutputs(reference_tests::Tensor(ET_IND, {1}, std::vector{1})) @@ -422,7 +422,7 @@ struct NonMaxSuppression4Params { reference_tests::Tensor maxOutputBoxesPerClass; reference_tests::Tensor iouThreshold; reference_tests::Tensor scoreThreshold; - opset4::NonMaxSuppression::BoxEncodingType boxEncoding; + op::v4::NonMaxSuppression::BoxEncodingType boxEncoding; reference_tests::Tensor expectedSelectedIndices; std::string testcaseName; }; @@ -465,19 +465,19 @@ class ReferenceNonMaxSuppression4Test : public testing::TestWithParam CreateFunction(const NonMaxSuppression4Params& params) { - const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); - const auto scores = std::make_shared(params.scores.type, params.scores.shape); + const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); + const auto scores = std::make_shared(params.scores.type, params.scores.shape); const auto max_output_boxes_per_class = - std::make_shared(params.maxOutputBoxesPerClass.type, + std::make_shared(params.maxOutputBoxesPerClass.type, params.maxOutputBoxesPerClass.shape, params.maxOutputBoxesPerClass.data.data()); - const auto iou_threshold = std::make_shared(params.iouThreshold.type, + const auto iou_threshold = std::make_shared(params.iouThreshold.type, params.iouThreshold.shape, params.iouThreshold.data.data()); - const auto score_threshold = std::make_shared(params.scoreThreshold.type, + const auto score_threshold = std::make_shared(params.scoreThreshold.type, params.scoreThreshold.shape, params.scoreThreshold.data.data()); - const auto nms = std::make_shared(boxes, + const auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, iou_threshold, @@ -505,16 +505,16 @@ class ReferenceNonMaxSuppression4TestWithoutConstants : public ReferenceNonMaxSu private: static std::shared_ptr CreateFunction(const NonMaxSuppression4Params& params) { - const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); - const auto scores = std::make_shared(params.scores.type, params.scores.shape); + const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); + const auto scores = std::make_shared(params.scores.type, params.scores.shape); const auto max_output_boxes_per_class = - std::make_shared(params.maxOutputBoxesPerClass.type, + std::make_shared(params.maxOutputBoxesPerClass.type, params.maxOutputBoxesPerClass.shape); const auto iou_threshold = - std::make_shared(params.iouThreshold.type, params.iouThreshold.shape); + std::make_shared(params.iouThreshold.type, params.iouThreshold.shape); const auto score_threshold = - std::make_shared(params.scoreThreshold.type, params.scoreThreshold.shape); - const auto nms = std::make_shared(boxes, + std::make_shared(params.scoreThreshold.type, params.scoreThreshold.shape); + const auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, iou_threshold, @@ -552,7 +552,7 @@ std::vector generateParams4() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{3})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset4::NonMaxSuppression::BoxEncodingType::CENTER) + .boxEncoding(op::v4::NonMaxSuppression::BoxEncodingType::CENTER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {3, 3}, std::vector{0, 0, 3, 0, 0, 0, 0, 0, 5})) .testcaseName("nonmaxsuppression_center_point_box_format"), @@ -565,7 +565,7 @@ std::vector generateParams4() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{3})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset4::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v4::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {3, 3}, std::vector{0, 0, 3, 0, 0, 0, 0, 0, 5})) .testcaseName("nonmaxsuppression_flipped_coordinates"), @@ -582,7 +582,7 @@ std::vector generateParams4() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{1})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset4::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v4::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {1, 3}, std::vector{0, 0, 0})) .testcaseName("nonmaxsuppression_identical_boxes"), @@ -594,7 +594,7 @@ std::vector generateParams4() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{2})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset4::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v4::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {2, 3}, std::vector{0, 0, 3, 0, 0, 0})) .testcaseName("nonmaxsuppression_limit_output_size"), @@ -604,7 +604,7 @@ std::vector generateParams4() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{3})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset4::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v4::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {1, 3}, std::vector{0, 0, 0})) .testcaseName("nonmaxsuppression_single_box"), @@ -616,7 +616,7 @@ std::vector generateParams4() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{3})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset4::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v4::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {3, 3}, std::vector{0, 0, 3, 0, 0, 0, 0, 0, 5})) .testcaseName("nonmaxsuppression_suppress_by_IOU"), @@ -629,7 +629,7 @@ std::vector generateParams4() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{2})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.4f})) - .boxEncoding(opset4::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v4::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {2, 3}, std::vector{0, 0, 3, 0, 0, 0})) .testcaseName("nonmaxsuppression_suppress_by_IOU_and_scores"), @@ -647,7 +647,7 @@ std::vector generateParams4() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{2})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset4::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v4::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {4, 3}, std::vector{0, 0, 3, 0, 0, 0, 1, 0, 3, 1, 0, 0})) .testcaseName("nonmaxsuppression_two_batches"), @@ -663,7 +663,7 @@ std::vector generateParams4() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{2})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset4::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v4::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {4, 3}, std::vector{0, 0, 3, 0, 0, 0, 0, 1, 3, 0, 1, 0})) .testcaseName("nonmaxsuppression_two_classes"), @@ -704,7 +704,7 @@ std::vector generateParams4WithoutConstants() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{1})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.4f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.2f})) - .boxEncoding(opset4::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v4::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {1, 3}, std::vector{0, 0, 3})) .testcaseName("nonmaxsuppression_suppress_by_IOU_and_scores_without_constants"), }; @@ -761,7 +761,7 @@ struct NonMaxSuppression3Params { reference_tests::Tensor maxOutputBoxesPerClass; reference_tests::Tensor iouThreshold; reference_tests::Tensor scoreThreshold; - opset3::NonMaxSuppression::BoxEncodingType boxEncoding; + op::v3::NonMaxSuppression::BoxEncodingType boxEncoding; reference_tests::Tensor expectedSelectedIndices; std::string testcaseName; }; @@ -804,19 +804,19 @@ class ReferenceNonMaxSuppression3Test : public testing::TestWithParam CreateFunction(const NonMaxSuppression3Params& params) { - const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); - const auto scores = std::make_shared(params.scores.type, params.scores.shape); + const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); + const auto scores = std::make_shared(params.scores.type, params.scores.shape); const auto max_output_boxes_per_class = - std::make_shared(params.maxOutputBoxesPerClass.type, + std::make_shared(params.maxOutputBoxesPerClass.type, params.maxOutputBoxesPerClass.shape, params.maxOutputBoxesPerClass.data.data()); - const auto iou_threshold = std::make_shared(params.iouThreshold.type, + const auto iou_threshold = std::make_shared(params.iouThreshold.type, params.iouThreshold.shape, params.iouThreshold.data.data()); - const auto score_threshold = std::make_shared(params.scoreThreshold.type, + const auto score_threshold = std::make_shared(params.scoreThreshold.type, params.scoreThreshold.shape, params.scoreThreshold.data.data()); - const auto nms = std::make_shared(boxes, + const auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, iou_threshold, @@ -844,16 +844,16 @@ class ReferenceNonMaxSuppression3TestWithoutConstants : public ReferenceNonMaxSu private: static std::shared_ptr CreateFunction(const NonMaxSuppression3Params& params) { - const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); - const auto scores = std::make_shared(params.scores.type, params.scores.shape); + const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); + const auto scores = std::make_shared(params.scores.type, params.scores.shape); const auto max_output_boxes_per_class = - std::make_shared(params.maxOutputBoxesPerClass.type, + std::make_shared(params.maxOutputBoxesPerClass.type, params.maxOutputBoxesPerClass.shape); const auto iou_threshold = - std::make_shared(params.iouThreshold.type, params.iouThreshold.shape); + std::make_shared(params.iouThreshold.type, params.iouThreshold.shape); const auto score_threshold = - std::make_shared(params.scoreThreshold.type, params.scoreThreshold.shape); - const auto nms = std::make_shared(boxes, + std::make_shared(params.scoreThreshold.type, params.scoreThreshold.shape); + const auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, iou_threshold, @@ -891,7 +891,7 @@ std::vector generateParams3() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{3})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset3::NonMaxSuppression::BoxEncodingType::CENTER) + .boxEncoding(op::v3::NonMaxSuppression::BoxEncodingType::CENTER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {3, 3}, std::vector{0, 0, 3, 0, 0, 0, 0, 0, 5})) .testcaseName("nonmaxsuppression_center_point_box_format"), @@ -904,7 +904,7 @@ std::vector generateParams3() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{3})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset3::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v3::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {3, 3}, std::vector{0, 0, 3, 0, 0, 0, 0, 0, 5})) .testcaseName("nonmaxsuppression_flipped_coordinates"), @@ -921,7 +921,7 @@ std::vector generateParams3() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{1})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset3::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v3::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {1, 3}, std::vector{0, 0, 0})) .testcaseName("nonmaxsuppression_identical_boxes"), @@ -933,7 +933,7 @@ std::vector generateParams3() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{2})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset3::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v3::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {2, 3}, std::vector{0, 0, 3, 0, 0, 0})) .testcaseName("nonmaxsuppression_limit_output_size"), @@ -943,7 +943,7 @@ std::vector generateParams3() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{3})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset3::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v3::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {1, 3}, std::vector{0, 0, 0})) .testcaseName("nonmaxsuppression_single_box"), @@ -955,7 +955,7 @@ std::vector generateParams3() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{3})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset3::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v3::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {3, 3}, std::vector{0, 0, 3, 0, 0, 0, 0, 0, 5})) .testcaseName("nonmaxsuppression_suppress_by_IOU"), @@ -968,7 +968,7 @@ std::vector generateParams3() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{2})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.4f})) - .boxEncoding(opset3::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v3::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {2, 3}, std::vector{0, 0, 3, 0, 0, 0})) .testcaseName("nonmaxsuppression_suppress_by_IOU_and_scores"), @@ -983,7 +983,7 @@ std::vector generateParams3() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{2})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset3::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v3::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {4, 3}, std::vector{0, 0, 3, 0, 0, 0, 0, 1, 3, 0, 1, 0})) .testcaseName("nonmaxsuppression_two_classes"), @@ -1024,7 +1024,7 @@ std::vector generateParams3WithoutConstants() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{1})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.4f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.2f})) - .boxEncoding(opset3::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v3::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {1, 3}, std::vector{0, 0, 3})) .testcaseName("nonmaxsuppression_suppress_by_IOU_and_scores_without_constants"), }; @@ -1081,7 +1081,7 @@ struct NonMaxSuppression1Params { reference_tests::Tensor maxOutputBoxesPerClass; reference_tests::Tensor iouThreshold; reference_tests::Tensor scoreThreshold; - opset1::NonMaxSuppression::BoxEncodingType boxEncoding; + op::v1::NonMaxSuppression::BoxEncodingType boxEncoding; reference_tests::Tensor expectedSelectedIndices; std::string testcaseName; }; @@ -1124,19 +1124,19 @@ class ReferenceNonMaxSuppression1Test : public testing::TestWithParam CreateFunction(const NonMaxSuppression1Params& params) { - const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); - const auto scores = std::make_shared(params.scores.type, params.scores.shape); + const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); + const auto scores = std::make_shared(params.scores.type, params.scores.shape); const auto max_output_boxes_per_class = - std::make_shared(params.maxOutputBoxesPerClass.type, + std::make_shared(params.maxOutputBoxesPerClass.type, params.maxOutputBoxesPerClass.shape, params.maxOutputBoxesPerClass.data.data()); - const auto iou_threshold = std::make_shared(params.iouThreshold.type, + const auto iou_threshold = std::make_shared(params.iouThreshold.type, params.iouThreshold.shape, params.iouThreshold.data.data()); - const auto score_threshold = std::make_shared(params.scoreThreshold.type, + const auto score_threshold = std::make_shared(params.scoreThreshold.type, params.scoreThreshold.shape, params.scoreThreshold.data.data()); - const auto nms = std::make_shared(boxes, + const auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, iou_threshold, @@ -1163,16 +1163,16 @@ class ReferenceNonMaxSuppression1TestWithoutConstants : public ReferenceNonMaxSu private: static std::shared_ptr CreateFunction(const NonMaxSuppression1Params& params) { - const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); - const auto scores = std::make_shared(params.scores.type, params.scores.shape); + const auto boxes = std::make_shared(params.boxes.type, params.boxes.shape); + const auto scores = std::make_shared(params.scores.type, params.scores.shape); const auto max_output_boxes_per_class = - std::make_shared(params.maxOutputBoxesPerClass.type, + std::make_shared(params.maxOutputBoxesPerClass.type, params.maxOutputBoxesPerClass.shape); const auto iou_threshold = - std::make_shared(params.iouThreshold.type, params.iouThreshold.shape); + std::make_shared(params.iouThreshold.type, params.iouThreshold.shape); const auto score_threshold = - std::make_shared(params.scoreThreshold.type, params.scoreThreshold.shape); - const auto nms = std::make_shared(boxes, + std::make_shared(params.scoreThreshold.type, params.scoreThreshold.shape); + const auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, iou_threshold, @@ -1209,7 +1209,7 @@ std::vector generateParams1() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{3})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset1::NonMaxSuppression::BoxEncodingType::CENTER) + .boxEncoding(op::v1::NonMaxSuppression::BoxEncodingType::CENTER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {3, 3}, std::vector{0, 0, 3, 0, 0, 0, 0, 0, 5})) .testcaseName("nonmaxsuppression_center_point_box_format"), @@ -1222,7 +1222,7 @@ std::vector generateParams1() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{3})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset1::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v1::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {3, 3}, std::vector{0, 0, 3, 0, 0, 0, 0, 0, 5})) .testcaseName("nonmaxsuppression_flipped_coordinates"), @@ -1239,7 +1239,7 @@ std::vector generateParams1() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{1})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset1::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v1::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {1, 3}, std::vector{0, 0, 0})) .testcaseName("nonmaxsuppression_identical_boxes"), @@ -1251,7 +1251,7 @@ std::vector generateParams1() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{2})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset1::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v1::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {2, 3}, std::vector{0, 0, 3, 0, 0, 0})) .testcaseName("nonmaxsuppression_limit_output_size"), @@ -1261,7 +1261,7 @@ std::vector generateParams1() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{3})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset1::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v1::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {1, 3}, std::vector{0, 0, 0})) .testcaseName("nonmaxsuppression_single_box"), @@ -1273,7 +1273,7 @@ std::vector generateParams1() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{3})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset1::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v1::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {3, 3}, std::vector{0, 0, 3, 0, 0, 0, 0, 0, 5})) .testcaseName("nonmaxsuppression_suppress_by_IOU"), @@ -1286,7 +1286,7 @@ std::vector generateParams1() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{2})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.4f})) - .boxEncoding(opset1::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v1::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {2, 3}, std::vector{0, 0, 3, 0, 0, 0})) .testcaseName("nonmaxsuppression_suppress_by_IOU_and_scores"), @@ -1301,7 +1301,7 @@ std::vector generateParams1() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{2})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.5f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.0f})) - .boxEncoding(opset1::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v1::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices( reference_tests::Tensor(ET_IND, {4, 3}, std::vector{0, 0, 3, 0, 0, 0, 0, 1, 3, 0, 1, 0})) .testcaseName("nonmaxsuppression_two_classes"), @@ -1339,7 +1339,7 @@ std::vector generateParams1WithoutConstants() { .maxOutputBoxesPerClass(reference_tests::Tensor(ET_BOX, {}, std::vector{1})) .iouThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.4f})) .scoreThreshold(reference_tests::Tensor(ET_TH, {}, std::vector{0.2f})) - .boxEncoding(opset1::NonMaxSuppression::BoxEncodingType::CORNER) + .boxEncoding(op::v1::NonMaxSuppression::BoxEncodingType::CORNER) .expectedSelectedIndices(reference_tests::Tensor(ET_IND, {1, 3}, std::vector{0, 0, 3})) .testcaseName("nonmaxsuppression_suppress_by_IOU_and_scores_without_constants"), }; diff --git a/src/plugins/template/tests/functional/op_reference/pad.cpp b/src/plugins/template/tests/functional/op_reference/pad.cpp index eca5f7dbd074a7..4396aadf415661 100644 --- a/src/plugins/template/tests/functional/op_reference/pad.cpp +++ b/src/plugins/template/tests/functional/op_reference/pad.cpp @@ -6,9 +6,8 @@ #include -#include - #include "base_reference_test.hpp" +#include "functional_test_utils/skip_tests_config.hpp" #include "openvino/op/constant.hpp" using namespace reference_tests; diff --git a/src/plugins/template/tests/functional/op_reference/prior_box_clustered.cpp b/src/plugins/template/tests/functional/op_reference/prior_box_clustered.cpp index 9097c3a2019f8b..358477ee9ed40a 100644 --- a/src/plugins/template/tests/functional/op_reference/prior_box_clustered.cpp +++ b/src/plugins/template/tests/functional/op_reference/prior_box_clustered.cpp @@ -2,11 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/prior_box_clustered.hpp" + #include #include "base_reference_test.hpp" +#include "openvino/op/constant.hpp" #include "openvino/op/prior_box.hpp" -#include "openvino/opsets/opset1.hpp" using namespace reference_tests; using namespace ov; @@ -76,9 +78,9 @@ class ReferencePriorBoxClusteredLayerTest : public testing::TestWithParam CreateFunction(const PriorBoxClusteredParams& params) { auto LS = - std::make_shared(params.inType, params.layerShapeShape, params.layerShapeData.data()); + std::make_shared(params.inType, params.layerShapeShape, params.layerShapeData.data()); auto IS = - std::make_shared(params.inType, params.imageShapeShape, params.imageShapeData.data()); + std::make_shared(params.inType, params.imageShapeShape, params.imageShapeData.data()); const auto PriorBoxClustered = std::make_shared(LS, IS, params.attrs); return std::make_shared(NodeVector{PriorBoxClustered}, ParameterVector{}); } diff --git a/src/plugins/template/tests/functional/op_reference/random_uniform.cpp b/src/plugins/template/tests/functional/op_reference/random_uniform.cpp index 9da97ef7c0b426..706a7217c1dbae 100644 --- a/src/plugins/template/tests/functional/op_reference/random_uniform.cpp +++ b/src/plugins/template/tests/functional/op_reference/random_uniform.cpp @@ -2,10 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/random_uniform.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset8.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/parameter.hpp" using namespace ov; @@ -64,11 +67,11 @@ class ReferenceRandomUniformLayerTest : public testing::TestWithParam(min_val.type, min_val.shape); - const auto max_val_param = std::make_shared(max_val.type, max_val.shape); - auto out_shape_ = std::make_shared(element::i64, Shape{out_shape.size()}, out_shape); + const auto min_val_param = std::make_shared(min_val.type, min_val.shape); + const auto max_val_param = std::make_shared(max_val.type, max_val.shape); + auto out_shape_ = std::make_shared(element::i64, Shape{out_shape.size()}, out_shape); - return std::make_shared(NodeVector{std::make_shared(out_shape_, + return std::make_shared(NodeVector{std::make_shared(out_shape_, min_val_param, max_val_param, out_type, diff --git a/src/plugins/template/tests/functional/op_reference/roi_align.cpp b/src/plugins/template/tests/functional/op_reference/roi_align.cpp index ede8f75ace3c04..3bad155201bc2e 100644 --- a/src/plugins/template/tests/functional/op_reference/roi_align.cpp +++ b/src/plugins/template/tests/functional/op_reference/roi_align.cpp @@ -2,14 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/roi_align.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" -#include "openvino/opsets/opset3.hpp" -#include "openvino/opsets/opset4.hpp" -#include "openvino/opsets/opset5.hpp" -#include "openvino/opsets/opset9.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/parameter.hpp" using namespace reference_tests; using namespace ov; @@ -133,12 +132,12 @@ class ReferenceROIAlignTest : public testing::TestWithParam, pub private: static std::shared_ptr CreateFunction(const ROIAlignParams& params) { - const auto featureMap = std::make_shared(params.iType, params.pShape); + const auto featureMap = std::make_shared(params.iType, params.pShape); const auto coords = - std::make_shared(params.coords.type, params.coords.shape, params.coords.data.data()); + std::make_shared(params.coords.type, params.coords.shape, params.coords.data.data()); const auto roisIdx = - std::make_shared(params.roiIdx.type, params.roiIdx.shape, params.roiIdx.data.data()); - const auto roi_align = std::make_shared(featureMap, + std::make_shared(params.roiIdx.type, params.roiIdx.shape, params.roiIdx.data.data()); + const auto roi_align = std::make_shared(featureMap, coords, roisIdx, params.pooledH, @@ -185,14 +184,14 @@ class ReferenceROIAlignV9Test : public testing::TestWithParam, private: static std::shared_ptr CreateFunction(const ROIAlignV9Params& params) { - const auto featureMap = std::make_shared(params.iType, params.pShape); + const auto featureMap = std::make_shared(params.iType, params.pShape); const auto coords = - std::make_shared(params.coords.type, params.coords.shape, params.coords.data.data()); + std::make_shared(params.coords.type, params.coords.shape, params.coords.data.data()); const auto roisIdx = - std::make_shared(params.roiIdx.type, params.roiIdx.shape, params.roiIdx.data.data()); - const auto pooling_mode = EnumNames::as_enum(params.poolingMode); - const auto aligned_mode = EnumNames::as_enum(params.alignedMode); - const auto roi_align = std::make_shared(featureMap, + std::make_shared(params.roiIdx.type, params.roiIdx.shape, params.roiIdx.data.data()); + const auto pooling_mode = EnumNames::as_enum(params.poolingMode); + const auto aligned_mode = EnumNames::as_enum(params.alignedMode); + const auto roi_align = std::make_shared(featureMap, coords, roisIdx, params.pooledH, diff --git a/src/plugins/template/tests/functional/op_reference/roll.cpp b/src/plugins/template/tests/functional/op_reference/roll.cpp index b9d2b54f5debb0..63293f1c323347 100644 --- a/src/plugins/template/tests/functional/op_reference/roll.cpp +++ b/src/plugins/template/tests/functional/op_reference/roll.cpp @@ -2,11 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/roll.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" -#include "openvino/opsets/opset7.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/parameter.hpp" using namespace reference_tests; using namespace ov; @@ -61,14 +63,14 @@ class ReferenceRollLayerTest : public testing::TestWithParam, public private: static std::shared_ptr CreateFunction(const RollParams& params) { - const auto data = std::make_shared(params.dataTensor.type, params.dataTensor.shape); - const auto shift = std::make_shared(params.shiftTensor.type, + const auto data = std::make_shared(params.dataTensor.type, params.dataTensor.shape); + const auto shift = std::make_shared(params.shiftTensor.type, params.shiftTensor.shape, params.shiftTensor.data.data()); - const auto axes = std::make_shared(params.axesTensor.type, + const auto axes = std::make_shared(params.axesTensor.type, params.axesTensor.shape, params.axesTensor.data.data()); - const auto roll = std::make_shared(data, shift, axes); + const auto roll = std::make_shared(data, shift, axes); return std::make_shared(NodeVector{roll}, ParameterVector{data}); } }; diff --git a/src/plugins/template/tests/functional/op_reference/shuffle_channels.cpp b/src/plugins/template/tests/functional/op_reference/shuffle_channels.cpp index 7b605e62680c73..f3cd395bf4aadc 100644 --- a/src/plugins/template/tests/functional/op_reference/shuffle_channels.cpp +++ b/src/plugins/template/tests/functional/op_reference/shuffle_channels.cpp @@ -2,10 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/shuffle_channels.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" +#include "openvino/op/parameter.hpp" using namespace reference_tests; using namespace ov; @@ -59,8 +61,8 @@ class ReferenceShuffleChannelsLayerTest : public testing::TestWithParam CreateFunction(const ShuffleChannelsParams& params) { - const auto data = std::make_shared(params.dataTensor.type, params.dataTensor.shape); - const auto function = std::make_shared(data, params.axis, params.group); + const auto data = std::make_shared(params.dataTensor.type, params.dataTensor.shape); + const auto function = std::make_shared(data, params.axis, params.group); return std::make_shared(NodeVector{function}, ParameterVector{data}); } }; diff --git a/src/plugins/template/tests/functional/op_reference/slice.cpp b/src/plugins/template/tests/functional/op_reference/slice.cpp index 2fa64b2dd458d6..21455df6786460 100644 --- a/src/plugins/template/tests/functional/op_reference/slice.cpp +++ b/src/plugins/template/tests/functional/op_reference/slice.cpp @@ -2,12 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/slice.hpp" + #include #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset8.hpp" +#include "openvino/op/parameter.hpp" using namespace ov; @@ -102,13 +104,13 @@ class ReferenceSliceLayerTest : public testing::TestWithParam, publ const reference_tests::Tensor& stop, const reference_tests::Tensor& step, const reference_tests::Tensor& axes) { - const auto data_param = std::make_shared(data.type, data.shape); - const auto start_param = std::make_shared(start.type, start.shape); - const auto stop_param = std::make_shared(stop.type, stop.shape); - const auto step_param = std::make_shared(step.type, step.shape); - const auto axes_param = std::make_shared(axes.type, axes.shape); + const auto data_param = std::make_shared(data.type, data.shape); + const auto start_param = std::make_shared(start.type, start.shape); + const auto stop_param = std::make_shared(stop.type, stop.shape); + const auto step_param = std::make_shared(step.type, step.shape); + const auto axes_param = std::make_shared(axes.type, axes.shape); - const auto slice = std::make_shared(data_param, start_param, stop_param, step_param, axes_param); + const auto slice = std::make_shared(data_param, start_param, stop_param, step_param, axes_param); return std::make_shared(NodeVector{slice}, ParameterVector{data_param, start_param, stop_param, step_param, axes_param}); } @@ -118,12 +120,12 @@ class ReferenceSliceLayerTest : public testing::TestWithParam, publ const reference_tests::Tensor& start, const reference_tests::Tensor& stop, const reference_tests::Tensor& step) { - const auto data_param = std::make_shared(data.type, data.shape); - const auto start_param = std::make_shared(start.type, start.shape); - const auto stop_param = std::make_shared(stop.type, stop.shape); - const auto step_param = std::make_shared(step.type, step.shape); + const auto data_param = std::make_shared(data.type, data.shape); + const auto start_param = std::make_shared(start.type, start.shape); + const auto stop_param = std::make_shared(stop.type, stop.shape); + const auto step_param = std::make_shared(step.type, step.shape); - const auto slice = std::make_shared(data_param, start_param, stop_param, step_param); + const auto slice = std::make_shared(data_param, start_param, stop_param, step_param); return std::make_shared(NodeVector{slice}, ParameterVector{data_param, start_param, stop_param, step_param}); } diff --git a/src/plugins/template/tests/functional/op_reference/space_to_batch.cpp b/src/plugins/template/tests/functional/op_reference/space_to_batch.cpp index 39cadfe89560df..32bcf21cab7f3b 100644 --- a/src/plugins/template/tests/functional/op_reference/space_to_batch.cpp +++ b/src/plugins/template/tests/functional/op_reference/space_to_batch.cpp @@ -2,12 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/space_to_batch.hpp" + #include #include "base_reference_test.hpp" #include "openvino/op/constant.hpp" -#include "openvino/opsets/opset1.hpp" -#include "openvino/opsets/opset2.hpp" +#include "openvino/op/parameter.hpp" using namespace reference_tests; using namespace ov; @@ -70,11 +71,11 @@ class ReferenceSpaceToBatchLayerTest : public testing::TestWithParam CreateFunction(const SpaceToBatchParams& params) { - const auto data = std::make_shared(params.dataTensor.type, params.dataTensor.shape); - const auto blockShape = std::make_shared(element::i64, params.blockShapeTensor.shape); - const auto padsBegin = std::make_shared(element::i64, params.padsBeginTensor.shape); - const auto padsEnd = std::make_shared(element::i64, params.padsEndTensor.shape); - const auto batchToSpace = std::make_shared(data, blockShape, padsBegin, padsEnd); + const auto data = std::make_shared(params.dataTensor.type, params.dataTensor.shape); + const auto blockShape = std::make_shared(element::i64, params.blockShapeTensor.shape); + const auto padsBegin = std::make_shared(element::i64, params.padsBeginTensor.shape); + const auto padsEnd = std::make_shared(element::i64, params.padsEndTensor.shape); + const auto batchToSpace = std::make_shared(data, blockShape, padsBegin, padsEnd); return std::make_shared(NodeVector{batchToSpace}, ParameterVector{data, blockShape, padsBegin, padsEnd}); } diff --git a/src/plugins/template/tests/functional/op_reference/space_to_depth.cpp b/src/plugins/template/tests/functional/op_reference/space_to_depth.cpp index 7420376f802af7..19a6b71c03463c 100644 --- a/src/plugins/template/tests/functional/op_reference/space_to_depth.cpp +++ b/src/plugins/template/tests/functional/op_reference/space_to_depth.cpp @@ -2,10 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/space_to_depth.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" +#include "openvino/op/parameter.hpp" using namespace reference_tests; using namespace ov; @@ -56,11 +58,10 @@ class ReferenceSpaceToDepthLayerTest : public testing::TestWithParam CreateFunction(const SpaceToDepthParams& params) { - opset1::SpaceToDepth::SpaceToDepthMode mode = params.mode == "DEPTH_FIRST" - ? opset1::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST - : opset1::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST; - const auto data = std::make_shared(params.dataTensor.type, params.dataTensor.shape); - const auto SpaceToDepth = std::make_shared(data, mode, params.blockSize); + const auto mode = params.mode == "DEPTH_FIRST" ? op::v0::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST + : op::v0::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST; + const auto data = std::make_shared(params.dataTensor.type, params.dataTensor.shape); + const auto SpaceToDepth = std::make_shared(data, mode, params.blockSize); return std::make_shared(NodeVector{SpaceToDepth}, ParameterVector{data}); } }; diff --git a/src/plugins/template/tests/functional/op_reference/tensor_iterator.cpp b/src/plugins/template/tests/functional/op_reference/tensor_iterator.cpp index 5c53422b0dad64..477585ce5a7319 100644 --- a/src/plugins/template/tests/functional/op_reference/tensor_iterator.cpp +++ b/src/plugins/template/tests/functional/op_reference/tensor_iterator.cpp @@ -2,13 +2,23 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include "openvino/op/tensor_iterator.hpp" -#include -#include +#include #include "base_reference_test.hpp" #include "functional_test_utils/skip_tests_config.hpp" +#include "openvino/core/model.hpp" +#include "openvino/op/add.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/gru_cell.hpp" +#include "openvino/op/lstm_cell.hpp" +#include "openvino/op/multiply.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/rnn_cell.hpp" +#include "openvino/op/squeeze.hpp" +#include "openvino/op/unsqueeze.hpp" namespace { struct TIFunctionalBase { @@ -23,26 +33,26 @@ struct TIFunctionalBase { struct TIDynamicInputs : public TIFunctionalBase { std::shared_ptr create_function(const std::vector& ti_inputs, const std::vector& results) override { - auto X = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); - auto Y = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); - auto M = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); + auto X = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); + auto Y = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); + auto M = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); // Set up the cell body, a function from (Xi, Yi) -> (Zo) // Body parameters - auto Xi = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); - auto Yi = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); - auto M_body = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); - auto body_condition = std::make_shared(ov::element::boolean, ov::Shape{1}, true); + auto Xi = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); + auto Yi = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); + auto M_body = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); + auto body_condition = std::make_shared(ov::element::boolean, ov::Shape{1}, true); - auto trip_count = std::make_shared(ov::element::i64, ov::Shape{1}, 3); - auto exec_condition = std::make_shared(ov::element::boolean, ov::Shape{1}, true); + auto trip_count = std::make_shared(ov::element::i64, ov::Shape{1}, 3); + auto exec_condition = std::make_shared(ov::element::boolean, ov::Shape{1}, true); // Body - auto sum = std::make_shared(Xi, Yi); - auto Zo = std::make_shared(sum, M_body); + auto sum = std::make_shared(Xi, Yi); + auto Zo = std::make_shared(sum, M_body); auto body = std::make_shared(ov::OutputVector{body_condition, Zo}, ov::ParameterVector{Xi, Yi, M_body}); - auto tensor_iterator = std::make_shared(); + auto tensor_iterator = std::make_shared(); tensor_iterator->set_function(body); tensor_iterator->set_sliced_input(Xi, X, 0, 1, 1, -1, 1); @@ -257,14 +267,14 @@ struct TIStaticInputs : public TIStaticFunctionalBase { std::shared_ptr create_function(const TensorIteratorStaticParams& params) override { std::vector inputShapes; std::shared_ptr function; - auto tensor_iterator = std::make_shared(); + auto tensor_iterator = std::make_shared(); // Each case consist of 3 steps: // 1. Create TensorIterator body. // 2. Set PortMap // 3. Create outer function auto axis = - std::make_shared(ov::element::i64, + std::make_shared(ov::element::i64, ov::Shape{1}, std::vector{static_cast(params.sequenceAxis)}); switch (params.body_type) { @@ -290,13 +300,13 @@ struct TIStaticInputs : public TIStaticFunctionalBase { ov::ParameterVector body_params{std::make_shared(params.iType, inputShapes[0]), std::make_shared(params.iType, inputShapes[1]), std::make_shared(params.iType, inputShapes[2])}; - auto squeeze = std::make_shared(body_params[0], axis); + auto squeeze = std::make_shared(body_params[0], axis); ov::OutputVector out_vector = {squeeze, body_params[1], body_params[2]}; - auto W = std::make_shared(params.W.type, params.W.shape, params.W.data.data()); - auto R = std::make_shared(params.R.type, params.R.shape, params.R.data.data()); - auto B = std::make_shared(params.B.type, params.B.shape, params.B.data.data()); - auto lstm_cell = std::make_shared(out_vector[0], + auto W = std::make_shared(params.W.type, params.W.shape, params.W.data.data()); + auto R = std::make_shared(params.R.type, params.R.shape, params.R.data.data()); + auto B = std::make_shared(params.B.type, params.B.shape, params.B.data.data()); + auto lstm_cell = std::make_shared(out_vector[0], out_vector[1], out_vector[2], W, @@ -308,10 +318,10 @@ struct TIStaticInputs : public TIStaticFunctionalBase { std::vector{}, params.clip); - auto unsqueeze = std::make_shared(lstm_cell->output(0), axis); - ov::ResultVector results{std::make_shared(unsqueeze), - std::make_shared(lstm_cell->output(0)), - std::make_shared(lstm_cell->output(1))}; + auto unsqueeze = std::make_shared(lstm_cell->output(0), axis); + ov::ResultVector results{std::make_shared(unsqueeze), + std::make_shared(lstm_cell->output(0)), + std::make_shared(lstm_cell->output(1))}; auto body = std::make_shared(results, body_params, "lstm_cell"); tensor_iterator->set_function(body); @@ -357,13 +367,13 @@ struct TIStaticInputs : public TIStaticFunctionalBase { ov::ParameterVector body_params{std::make_shared(params.iType, inputShapes[0]), std::make_shared(params.iType, inputShapes[1])}; - auto squeeze = std::make_shared(body_params[0], axis); + auto squeeze = std::make_shared(body_params[0], axis); ov::OutputVector out_vector = {squeeze, body_params[1]}; - auto W = std::make_shared(params.W.type, params.W.shape, params.W.data.data()); - auto R = std::make_shared(params.R.type, params.R.shape, params.R.data.data()); - auto B = std::make_shared(params.B.type, params.B.shape, params.B.data.data()); - auto gru_cell = std::make_shared(out_vector[0], + auto W = std::make_shared(params.W.type, params.W.shape, params.W.data.data()); + auto R = std::make_shared(params.R.type, params.R.shape, params.R.data.data()); + auto B = std::make_shared(params.B.type, params.B.shape, params.B.data.data()); + auto gru_cell = std::make_shared(out_vector[0], out_vector[1], W, R, @@ -375,9 +385,9 @@ struct TIStaticInputs : public TIStaticFunctionalBase { params.clip, false); - auto unsqueeze = std::make_shared(gru_cell->output(0), axis); - ov::ResultVector results{std::make_shared(gru_cell->output(0)), - std::make_shared(unsqueeze)}; + auto unsqueeze = std::make_shared(gru_cell->output(0), axis); + ov::ResultVector results{std::make_shared(gru_cell->output(0)), + std::make_shared(unsqueeze)}; auto body = std::make_shared(results, body_params, "gru_cell"); tensor_iterator->set_function(body); @@ -420,13 +430,13 @@ struct TIStaticInputs : public TIStaticFunctionalBase { inputShapes[0][params.sequenceAxis] = 1; // sliced dimension ov::ParameterVector body_params{std::make_shared(params.iType, inputShapes[0]), std::make_shared(params.iType, inputShapes[1])}; - auto squeeze = std::make_shared(body_params[0], axis); + auto squeeze = std::make_shared(body_params[0], axis); ov::OutputVector out_vector = {squeeze, body_params[1]}; - auto W = std::make_shared(params.W.type, params.W.shape, params.W.data.data()); - auto R = std::make_shared(params.R.type, params.R.shape, params.R.data.data()); - auto B = std::make_shared(params.B.type, params.B.shape, params.B.data.data()); - auto rnn_cell = std::make_shared(out_vector[0], + auto W = std::make_shared(params.W.type, params.W.shape, params.W.data.data()); + auto R = std::make_shared(params.R.type, params.R.shape, params.R.data.data()); + auto B = std::make_shared(params.B.type, params.B.shape, params.B.data.data()); + auto rnn_cell = std::make_shared(out_vector[0], out_vector[1], W, R, @@ -437,9 +447,9 @@ struct TIStaticInputs : public TIStaticFunctionalBase { std::vector{}, params.clip); - auto unsqueeze = std::make_shared(rnn_cell->output(0), axis); - ov::ResultVector results{std::make_shared(rnn_cell), - std::make_shared(unsqueeze)}; + auto unsqueeze = std::make_shared(rnn_cell->output(0), axis); + ov::ResultVector results{std::make_shared(rnn_cell), + std::make_shared(unsqueeze)}; auto body = std::make_shared(results, body_params, "rnn_cell"); tensor_iterator->set_function(body); diff --git a/src/plugins/template/tests/functional/op_reference/tile.cpp b/src/plugins/template/tests/functional/op_reference/tile.cpp index 2a99ee45b11cb4..6caa3d64154e95 100644 --- a/src/plugins/template/tests/functional/op_reference/tile.cpp +++ b/src/plugins/template/tests/functional/op_reference/tile.cpp @@ -2,10 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/tile.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/parameter.hpp" using namespace reference_tests; using namespace ov; @@ -55,10 +58,10 @@ class ReferenceTileTest : public testing::TestWithParam, public Comm private: static std::shared_ptr CreateFunction(const TileParams& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); + const auto A = std::make_shared(params.A.type, params.A.shape); const auto repeats = - std::make_shared(params.repeats.type, params.repeats.shape, params.repeats.data.data()); - const auto tile = std::make_shared(A, repeats); + std::make_shared(params.repeats.type, params.repeats.shape, params.repeats.data.data()); + const auto tile = std::make_shared(A, repeats); const auto f = std::make_shared(NodeVector{tile}, ParameterVector{A}); return f; } diff --git a/src/plugins/template/tests/functional/op_reference/topk.cpp b/src/plugins/template/tests/functional/op_reference/topk.cpp index f3fac57bd2acf1..b702a97519d1db 100644 --- a/src/plugins/template/tests/functional/op_reference/topk.cpp +++ b/src/plugins/template/tests/functional/op_reference/topk.cpp @@ -2,12 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/topk.hpp" + #include #include "base_reference_test.hpp" -#include "openvino/opsets/opset1.hpp" -#include "openvino/opsets/opset11.hpp" -#include "openvino/opsets/opset3.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/parameter.hpp" using namespace reference_tests; using namespace ov; @@ -17,8 +18,8 @@ struct TopKParams { TopKParams(const reference_tests::Tensor& A, const reference_tests::Tensor& k, const int64_t axis, - const opset1::TopK::Mode mode, - const opset1::TopK::SortType sort, + const op::v1::TopK::Mode mode, + const op::v1::TopK::SortType sort, const reference_tests::Tensor& result0, const reference_tests::Tensor& result1, const size_t outIdx, @@ -36,8 +37,8 @@ struct TopKParams { reference_tests::Tensor A; reference_tests::Tensor k; int64_t axis; - opset1::TopK::Mode mode; - opset1::TopK::SortType sort; + op::v1::TopK::Mode mode; + op::v1::TopK::SortType sort; reference_tests::Tensor result0; reference_tests::Tensor result1; size_t outIdx; @@ -116,17 +117,17 @@ class ReferenceTopKTestResnet50 : public testing::TestWithParam CreateFunction(const TopKParamsResnet50& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto B = std::make_shared(A, - opset1::Constant::create(element::i64, {}, {5}), + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto B = std::make_shared(A, + op::v0::Constant::create(element::i64, {}, {5}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES); - const auto C = std::make_shared(A, - opset1::Constant::create(element::i64, {}, {1}), + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES); + const auto C = std::make_shared(A, + op::v0::Constant::create(element::i64, {}, {1}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES); + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES); const auto out5_value = B->output(0); const auto out5_index = B->output(1); @@ -247,9 +248,9 @@ class ReferenceTopKTestMaxMinSort : public ReferenceTopKTest { private: static std::shared_ptr CreateFunction(const TopKParams& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto k = opset1::Constant::create(params.k.type, params.k.shape, params.k.data.data()); - const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto k = op::v0::Constant::create(params.k.type, params.k.shape, params.k.data.data()); + const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort); const auto f = std::make_shared(B->outputs(), ParameterVector{A}); return f; } @@ -279,8 +280,8 @@ std::vector generateParamsMaxMinSort() { }({128, 1000})), reference_tests::Tensor(ET2, {}, std::vector{5}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::NONE, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::NONE, reference_tests::Tensor(ET, {128, 5}, [](std::vector rshape, std::vector shape) -> std::vector { @@ -323,8 +324,8 @@ std::vector generateParamsMaxMinSort() { }({128, 1000})), reference_tests::Tensor(ET2, {}, std::vector{5}), 1, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::NONE, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::NONE, reference_tests::Tensor(ET, {128, 5}, [](std::vector rshape) -> std::vector { @@ -368,8 +369,8 @@ std::vector generateParamsMaxMinSort() { }({128, 1000})), reference_tests::Tensor(ET2, {}, std::vector{5}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {128, 5}, [](std::vector rshape, std::vector shape) -> std::vector { @@ -408,8 +409,8 @@ std::vector generateParamsMaxMinSort() { }({128, 1000})), reference_tests::Tensor(ET2, {}, std::vector{5}), 1, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {128, 5}, [](std::vector rshape) -> std::vector { @@ -449,8 +450,8 @@ std::vector generateParamsMaxMinSort() { }({128, 1000})), reference_tests::Tensor(ET2, {}, std::vector{5}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_INDICES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_INDICES, reference_tests::Tensor(ET, {128, 5}, [](std::vector rshape, std::vector shape) -> std::vector { @@ -493,8 +494,8 @@ std::vector generateParamsMaxMinSort() { }({128, 1000})), reference_tests::Tensor(ET2, {}, std::vector{5}), 1, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_INDICES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_INDICES, reference_tests::Tensor(ET, {128, 5}, [](std::vector rshape) -> std::vector { @@ -523,8 +524,8 @@ std::vector generateParamsMaxMinSort() { TopKParams(reference_tests::Tensor(ET, {5}, std::vector{3, 1, 2, 5, 4}), reference_tests::Tensor(ET2, {}, std::vector{3}), 0, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {3}, std::vector{5, 4, 3}), reference_tests::Tensor(ET_OUT, {3}, std::vector{3, 4, 0}), 0, @@ -533,8 +534,8 @@ std::vector generateParamsMaxMinSort() { TopKParams(reference_tests::Tensor(ET, {5}, std::vector{3, 1, 2, 5, 4}), reference_tests::Tensor(ET2, {}, std::vector{3}), 0, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_INDICES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_INDICES, reference_tests::Tensor(ET, {3}, std::vector{3, 5, 4}), reference_tests::Tensor(ET_OUT, {3}, std::vector{0, 3, 4}), 0, @@ -543,8 +544,8 @@ std::vector generateParamsMaxMinSort() { TopKParams(reference_tests::Tensor(ET, {5}, std::vector{3, 1, 2, 5, 4}), reference_tests::Tensor(ET2, {}, std::vector{3}), 0, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {3}, std::vector{1, 2, 3}), reference_tests::Tensor(ET_OUT, {3}, std::vector{1, 2, 0}), 0, @@ -553,8 +554,8 @@ std::vector generateParamsMaxMinSort() { TopKParams(reference_tests::Tensor(ET, {5}, std::vector{3, 1, 2, 5, 4}), reference_tests::Tensor(ET2, {}, std::vector{3}), 0, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_INDICES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_INDICES, reference_tests::Tensor(ET, {3}, std::vector{3, 1, 2}), reference_tests::Tensor(ET_OUT, {3}, std::vector{0, 1, 2}), 0, @@ -602,9 +603,9 @@ class ReferenceTopKTestBackend : public ReferenceTopKTest { private: static std::shared_ptr CreateFunction(const TopKParams& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto k = opset1::Constant::create(params.k.type, params.k.shape, params.k.data.data()); - const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto k = op::v0::Constant::create(params.k.type, params.k.shape, params.k.data.data()); + const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort); const auto f = std::make_shared(B->outputs(), ParameterVector{A}); return f; } @@ -674,9 +675,9 @@ class ReferenceTopKTest1dMaxMin : public ReferenceTopKTest { private: static std::shared_ptr CreateFunction(const TopKParams& params, size_t out_idx) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto k = opset1::Constant::create(params.k.type, params.k.shape, params.k.data.data()); - const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto k = op::v0::Constant::create(params.k.type, params.k.shape, params.k.data.data()); + const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort); const auto f = std::make_shared(OutputVector{B->output(out_idx)}, ParameterVector{A}); return f; } @@ -695,8 +696,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {6}, std::vector{1, 2, 3, 4, 5, 6}), reference_tests::Tensor(ET2, {}, std::vector{6}), 0, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {6}, std::vector{6, 5, 4, 3, 2, 1}), reference_tests::Tensor(ET_OUT, {6}, std::vector{5, 4, 3, 2, 1, 0}), 0, @@ -705,8 +706,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {6}, std::vector{1, 2, 3, 4, 5, 6}), reference_tests::Tensor(ET2, {}, std::vector{6}), 0, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {6}, std::vector{6, 5, 4, 3, 2, 1}), reference_tests::Tensor(ET_OUT, {6}, std::vector{5, 4, 3, 2, 1, 0}), 1, @@ -715,8 +716,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {6}, std::vector{1, 2, 3, 4, 5, 6}), reference_tests::Tensor(ET2, {}, std::vector{3}), 0, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {3}, std::vector{6, 5, 4}), reference_tests::Tensor(ET_OUT, {3}, std::vector{5, 4, 3}), 0, @@ -725,8 +726,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {6}, std::vector{1, 2, 3, 4, 5, 6}), reference_tests::Tensor(ET2, {}, std::vector{3}), 0, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {3}, std::vector{6, 5, 4}), reference_tests::Tensor(ET_OUT, {3}, std::vector{5, 4, 3}), 1, @@ -735,8 +736,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {6}, std::vector{1, 2, 3, 4, 5, 6}), reference_tests::Tensor(ET2, {}, std::vector{1}), 0, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {1}, std::vector{6}), reference_tests::Tensor(ET_OUT, {1}, std::vector{5}), 0, @@ -745,8 +746,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {6}, std::vector{1, 2, 3, 4, 5, 6}), reference_tests::Tensor(ET2, {}, std::vector{1}), 0, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {1}, std::vector{6}), reference_tests::Tensor(ET_OUT, {1}, std::vector{5}), 1, @@ -755,8 +756,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {6}, std::vector{6, 5, 4, 3, 2, 1}), reference_tests::Tensor(ET2, {}, std::vector{6}), 0, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {6}, std::vector{1, 2, 3, 4, 5, 6}), reference_tests::Tensor(ET_OUT, {6}, std::vector{5, 4, 3, 2, 1, 0}), 0, @@ -765,8 +766,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {6}, std::vector{6, 5, 4, 3, 2, 1}), reference_tests::Tensor(ET2, {}, std::vector{6}), 0, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {6}, std::vector{1, 2, 3, 4, 5, 6}), reference_tests::Tensor(ET_OUT, {6}, std::vector{5, 4, 3, 2, 1, 0}), 1, @@ -775,8 +776,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {6}, std::vector{6, 5, 4, 3, 2, 1}), reference_tests::Tensor(ET2, {}, std::vector{3}), 0, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {3}, std::vector{1, 2, 3}), reference_tests::Tensor(ET_OUT, {3}, std::vector{5, 4, 3}), 0, @@ -785,8 +786,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {6}, std::vector{6, 5, 4, 3, 2, 1}), reference_tests::Tensor(ET2, {}, std::vector{3}), 0, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {3}, std::vector{1, 2, 3}), reference_tests::Tensor(ET_OUT, {3}, std::vector{5, 4, 3}), 1, @@ -795,8 +796,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {6}, std::vector{6, 5, 4, 3, 2, 1}), reference_tests::Tensor(ET2, {}, std::vector{1}), 0, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {1}, std::vector{1}), reference_tests::Tensor(ET_OUT, {1}, std::vector{5}), 0, @@ -805,8 +806,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {6}, std::vector{6, 5, 4, 3, 2, 1}), reference_tests::Tensor(ET2, {}, std::vector{1}), 0, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {1}, std::vector{1}), reference_tests::Tensor(ET_OUT, {1}, std::vector{5}), 1, @@ -815,8 +816,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {2, 3, 2}, std::vector{9, 2, 10, 12, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{3}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 3, 2}, std::vector{10, 12, 9, 4, 8, 2, 11, 7, 6, 3, 5, 1}), reference_tests::Tensor(ET_OUT, {2, 3, 2}, std::vector{1, 1, 0, 2, 2, 0, 2, 2, 0, 1, 1, 0}), 0, @@ -825,8 +826,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {2, 3, 2}, std::vector{9, 2, 10, 12, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{3}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 3, 2}, std::vector{10, 12, 9, 4, 8, 2, 11, 7, 6, 3, 5, 1}), reference_tests::Tensor(ET_OUT, {2, 3, 2}, std::vector{1, 1, 0, 2, 2, 0, 2, 2, 0, 1, 1, 0}), 1, @@ -854,8 +855,8 @@ std::vector generateParams1dMaxMin() { 215, 287, 200, 272, 208, 280, 216, 288}), reference_tests::Tensor(ET2, {}, std::vector{2}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor( ET, {2, 2, 3, 2, 4}, @@ -897,8 +898,8 @@ std::vector generateParams1dMaxMin() { 215, 287, 200, 272, 208, 280, 216, 288}), reference_tests::Tensor(ET2, {}, std::vector{2}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor( ET, {2, 2, 3, 2, 4}, @@ -921,8 +922,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {2, 3, 2}, std::vector{9, 2, 10, 12, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{2}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 2, 2}, std::vector{10, 12, 9, 4, 11, 7, 6, 3}), reference_tests::Tensor(ET_OUT, {2, 2, 2}, std::vector{1, 1, 0, 2, 2, 2, 0, 1}), 0, @@ -931,8 +932,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {2, 3, 2}, std::vector{9, 2, 10, 12, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{2}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 2, 2}, std::vector{10, 12, 9, 4, 11, 7, 6, 3}), reference_tests::Tensor(ET_OUT, {2, 2, 2}, std::vector{1, 1, 0, 2, 2, 2, 0, 1}), 1, @@ -941,8 +942,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {2, 3, 2}, std::vector{9, 2, 10, 12, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{1}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 1, 2}, std::vector{10, 12, 11, 7}), reference_tests::Tensor(ET_OUT, {2, 1, 2}, std::vector{1, 1, 2, 2}), 0, @@ -951,8 +952,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {2, 3, 2}, std::vector{9, 2, 10, 12, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{1}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 1, 2}, std::vector{10, 12, 11, 7}), reference_tests::Tensor(ET_OUT, {2, 1, 2}, std::vector{1, 1, 2, 2}), 1, @@ -961,8 +962,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {2, 3, 2}, std::vector{12, 2, 10, 9, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{3}), 1, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 3, 2}, std::vector{8, 2, 10, 4, 12, 9, 5, 1, 6, 3, 11, 7}), reference_tests::Tensor(ET_OUT, {2, 3, 2}, std::vector{2, 0, 1, 2, 0, 1, 1, 0, 0, 1, 2, 2}), 0, @@ -971,8 +972,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {2, 3, 2}, std::vector{12, 2, 10, 9, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{3}), 1, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 3, 2}, std::vector{8, 2, 10, 4, 12, 9, 5, 1, 6, 3, 11, 7}), reference_tests::Tensor(ET_OUT, {2, 3, 2}, std::vector{2, 0, 1, 2, 0, 1, 1, 0, 0, 1, 2, 2}), 1, @@ -981,8 +982,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {2, 3, 2}, std::vector{12, 2, 10, 9, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{2}), 1, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 2, 2}, std::vector{8, 2, 10, 4, 5, 1, 6, 3}), reference_tests::Tensor(ET_OUT, {2, 2, 2}, std::vector{2, 0, 1, 2, 1, 0, 0, 1}), 0, @@ -991,8 +992,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {2, 3, 2}, std::vector{12, 2, 10, 9, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{2}), 1, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 2, 2}, std::vector{8, 2, 10, 4, 5, 1, 6, 3}), reference_tests::Tensor(ET_OUT, {2, 2, 2}, std::vector{2, 0, 1, 2, 1, 0, 0, 1}), 1, @@ -1001,8 +1002,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {2, 3, 2}, std::vector{12, 2, 10, 9, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{1}), 1, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 1, 2}, std::vector{8, 2, 5, 1}), reference_tests::Tensor(ET_OUT, {2, 1, 2}, std::vector{2, 0, 1, 0}), 0, @@ -1011,8 +1012,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {2, 3, 2}, std::vector{12, 2, 10, 9, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{1}), 1, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 1, 2}, std::vector{8, 2, 5, 1}), reference_tests::Tensor(ET_OUT, {2, 1, 2}, std::vector{2, 0, 1, 0}), 1, @@ -1021,8 +1022,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {4, 3}, std::vector{9, 2, 10, 12, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{4}), 0, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {4, 3}, std::vector{12, 11, 10, 9, 8, 7, 6, 2, 5, 3, 1, 4}), reference_tests::Tensor(ET_OUT, {4, 3}, std::vector{1, 3, 0, 0, 1, 3, 2, 0, 2, 3, 2, 1}), 0, @@ -1031,8 +1032,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {4, 3}, std::vector{9, 2, 10, 12, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{4}), 0, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {4, 3}, std::vector{12, 11, 10, 9, 8, 7, 6, 2, 5, 3, 1, 4}), reference_tests::Tensor(ET_OUT, {4, 3}, std::vector{1, 3, 0, 0, 1, 3, 2, 0, 2, 3, 2, 1}), 1, @@ -1041,8 +1042,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {4, 3}, std::vector{9, 2, 10, 12, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{2}), 0, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 3}, std::vector{12, 11, 10, 9, 8, 7}), reference_tests::Tensor(ET_OUT, {2, 3}, std::vector{1, 3, 0, 0, 1, 3}), 0, @@ -1051,8 +1052,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {4, 3}, std::vector{9, 2, 10, 12, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{2}), 0, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 3}, std::vector{12, 11, 10, 9, 8, 7}), reference_tests::Tensor(ET_OUT, {2, 3}, std::vector{1, 3, 0, 0, 1, 3}), 1, @@ -1061,8 +1062,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {4, 3}, std::vector{9, 2, 10, 12, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{1}), 0, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {1, 3}, std::vector{12, 11, 10}), reference_tests::Tensor(ET_OUT, {1, 3}, std::vector{1, 3, 0}), 0, @@ -1071,8 +1072,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {4, 3}, std::vector{9, 2, 10, 12, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{1}), 0, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {1, 3}, std::vector{12, 11, 10}), reference_tests::Tensor(ET_OUT, {1, 3}, std::vector{1, 3, 0}), 1, @@ -1081,8 +1082,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {2, 4}, std::vector{1, 3, 2, 4, 1, 3, 3, 2}), reference_tests::Tensor(ET2, {}, std::vector{1}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 1}, std::vector{4, 3}), reference_tests::Tensor(ET_OUT, {2, 1}, std::vector{3, 1}), 0, @@ -1091,8 +1092,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {2, 4}, std::vector{1, 3, 2, 4, 1, 3, 3, 2}), reference_tests::Tensor(ET2, {}, std::vector{1}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 1}, std::vector{4, 3}), reference_tests::Tensor(ET_OUT, {2, 1}, std::vector{3, 1}), 1, @@ -1101,8 +1102,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {4, 3}, std::vector{12, 2, 10, 9, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{4}), 0, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {4, 3}, std::vector{3, 1, 4, 6, 2, 5, 9, 8, 7, 12, 11, 10}), reference_tests::Tensor(ET_OUT, {4, 3}, std::vector{3, 2, 1, 2, 0, 2, 1, 1, 3, 0, 3, 0}), 0, @@ -1111,8 +1112,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {4, 3}, std::vector{12, 2, 10, 9, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{4}), 0, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {4, 3}, std::vector{3, 1, 4, 6, 2, 5, 9, 8, 7, 12, 11, 10}), reference_tests::Tensor(ET_OUT, {4, 3}, std::vector{3, 2, 1, 2, 0, 2, 1, 1, 3, 0, 3, 0}), 1, @@ -1121,8 +1122,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {4, 3}, std::vector{12, 2, 10, 9, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{2}), 0, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 3}, std::vector{3, 1, 4, 6, 2, 5}), reference_tests::Tensor(ET_OUT, {2, 3}, std::vector{3, 2, 1, 2, 0, 2}), 0, @@ -1131,8 +1132,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {4, 3}, std::vector{12, 2, 10, 9, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{2}), 0, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 3}, std::vector{3, 1, 4, 6, 2, 5}), reference_tests::Tensor(ET_OUT, {2, 3}, std::vector{3, 2, 1, 2, 0, 2}), 1, @@ -1141,8 +1142,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {4, 3}, std::vector{12, 2, 10, 9, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{1}), 0, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::NONE, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::NONE, reference_tests::Tensor(ET, {1, 3}, std::vector{3, 1, 4}), reference_tests::Tensor(ET_OUT, {1, 3}, std::vector{3, 2, 1}), 0, @@ -1151,8 +1152,8 @@ std::vector generateParams1dMaxMin() { TopKParams(reference_tests::Tensor(ET, {4, 3}, std::vector{12, 2, 10, 9, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{1}), 0, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::NONE, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::NONE, reference_tests::Tensor(ET, {1, 3}, std::vector{3, 1, 4}), reference_tests::Tensor(ET_OUT, {1, 3}, std::vector{3, 2, 1}), 1, @@ -1190,9 +1191,9 @@ INSTANTIATE_TEST_SUITE_P(smoke_TopK_With_Hardcoded_Refs, class ReferenceTopKTestInt64 : public ReferenceTopKTest1dMaxMin { private: static std::shared_ptr CreateFunction(const TopKParams& params, size_t out_idx) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto k = opset1::Constant::create(params.k.type, params.k.shape, params.k.data.data()); - const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort, element::i64); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto k = op::v0::Constant::create(params.k.type, params.k.shape, params.k.data.data()); + const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort, element::i64); const auto f = std::make_shared(OutputVector{B->output(out_idx)}, ParameterVector{A}); return f; } @@ -1211,8 +1212,8 @@ std::vector generateParamsInt64() { TopKParams(reference_tests::Tensor(ET, {2, 3, 2}, std::vector{9, 2, 10, 12, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{3}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 3, 2}, std::vector{10, 12, 9, 4, 8, 2, 11, 7, 6, 3, 5, 1}), reference_tests::Tensor(ET_OUT, {2, 3, 2}, std::vector{1, 1, 0, 2, 2, 0, 2, 2, 0, 1, 1, 0}), 0, @@ -1220,8 +1221,8 @@ std::vector generateParamsInt64() { TopKParams(reference_tests::Tensor(ET, {2, 3, 2}, std::vector{9, 2, 10, 12, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{3}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 3, 2}, std::vector{10, 12, 9, 4, 8, 2, 11, 7, 6, 3, 5, 1}), reference_tests::Tensor(ET_OUT, {2, 3, 2}, std::vector{1, 1, 0, 2, 2, 0, 2, 2, 0, 1, 1, 0}), 1, @@ -1258,9 +1259,9 @@ class ReferenceTopKTestSingleOutput : public ReferenceTopKTest { private: static std::shared_ptr CreateFunction(const TopKParams& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto k = opset1::Constant::create(params.k.type, params.k.shape, params.k.data.data()); - const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto k = op::v0::Constant::create(params.k.type, params.k.shape, params.k.data.data()); + const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort); const auto f = std::make_shared(OutputVector{B->output(1)}, ParameterVector{A}); return f; } @@ -1279,8 +1280,8 @@ std::vector generateParamsSingleOutput() { TopKParams(reference_tests::Tensor(ET, {2, 3, 2}, std::vector{12, 2, 10, 9, 8, 4, 6, 1, 5, 3, 11, 7}), reference_tests::Tensor(ET2, {}, std::vector{2}), 1, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 2, 2}, std::vector{}), reference_tests::Tensor(ET_OUT, {2, 2, 2}, std::vector{2, 0, 1, 2, 1, 0, 0, 1}), 0, @@ -1318,36 +1319,36 @@ INSTANTIATE_TEST_SUITE_P(smoke_TopK_With_Hardcoded_Refs, ReferenceTopKTest::getTestCaseName); TEST(ReferenceTopKTestInvalid, topk_v1_invalid_strings) { - const auto data = std::make_shared(element::f32, Shape{1, 2, 3}); - const auto k = opset1::Constant::create(element::i64, Shape{}, {1}); - EXPECT_THROW(opset1::TopK(data, k, 0, "max", "invalid_mode"), ov::AssertFailure); - EXPECT_THROW(opset1::TopK(data, k, 0, "invalid_sort", "index"), ov::AssertFailure); + const auto data = std::make_shared(element::f32, Shape{1, 2, 3}); + const auto k = op::v0::Constant::create(element::i64, Shape{}, {1}); + EXPECT_THROW(op::v1::TopK(data, k, 0, "max", "invalid_mode"), ov::AssertFailure); + EXPECT_THROW(op::v1::TopK(data, k, 0, "invalid_sort", "index"), ov::AssertFailure); } TEST(ReferenceTopKTestInvalid, topk_v1_invalid_k) { - const auto data = std::make_shared(element::f32, Shape{1, 2, 3}); - const auto k_non_scalar = opset1::Constant::create(element::i64, Shape{2}, {1, 2}); - EXPECT_THROW(opset1::TopK(data, k_non_scalar, 0, "max", "index"), ov::NodeValidationFailure); - const auto k_float = opset1::Constant::create(element::f32, Shape{}, {1.0f}); - EXPECT_THROW(opset1::TopK(data, k_float, 0, "max", "index"), ov::NodeValidationFailure); - const auto k_negative = opset1::Constant::create(element::i8, Shape{}, {-1}); - EXPECT_THROW(opset1::TopK(data, k_negative, 0, "max", "index"), ov::NodeValidationFailure); + const auto data = std::make_shared(element::f32, Shape{1, 2, 3}); + const auto k_non_scalar = op::v0::Constant::create(element::i64, Shape{2}, {1, 2}); + EXPECT_THROW(op::v1::TopK(data, k_non_scalar, 0, "max", "index"), ov::NodeValidationFailure); + const auto k_float = op::v0::Constant::create(element::f32, Shape{}, {1.0f}); + EXPECT_THROW(op::v1::TopK(data, k_float, 0, "max", "index"), ov::NodeValidationFailure); + const auto k_negative = op::v0::Constant::create(element::i8, Shape{}, {-1}); + EXPECT_THROW(op::v1::TopK(data, k_negative, 0, "max", "index"), ov::NodeValidationFailure); } class ReferenceTopKTestResnet50V3 : public ReferenceTopKTestResnet50 { private: static std::shared_ptr CreateFunction(const TopKParamsResnet50& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto B = std::make_shared(A, - opset1::Constant::create(element::i64, {}, {5}), + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto B = std::make_shared(A, + op::v0::Constant::create(element::i64, {}, {5}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES); - const auto C = std::make_shared(A, - opset1::Constant::create(element::i64, {}, {1}), + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES); + const auto C = std::make_shared(A, + op::v0::Constant::create(element::i64, {}, {1}), 1, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES); + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES); const auto out5_value = B->output(0); const auto out5_index = B->output(1); @@ -1371,9 +1372,9 @@ INSTANTIATE_TEST_SUITE_P(smoke_TopK_With_Hardcoded_Refs, class ReferenceTopKTestMaxMinSortV3 : public ReferenceTopKTestMaxMinSort { private: static std::shared_ptr CreateFunction(const TopKParams& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto k = opset1::Constant::create(params.k.type, params.k.shape, params.k.data.data()); - const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto k = op::v0::Constant::create(params.k.type, params.k.shape, params.k.data.data()); + const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort); const auto f = std::make_shared(B->outputs(), ParameterVector{A}); return f; } @@ -1391,9 +1392,9 @@ INSTANTIATE_TEST_SUITE_P(smoke_TopK_With_Hardcoded_Refs, class ReferenceTopKTestBackendV3 : public ReferenceTopKTestBackend { private: static std::shared_ptr CreateFunction(const TopKParams& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto k = opset1::Constant::create(params.k.type, params.k.shape, params.k.data.data()); - const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto k = op::v0::Constant::create(params.k.type, params.k.shape, params.k.data.data()); + const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort); const auto f = std::make_shared(B->outputs(), ParameterVector{A}); return f; } @@ -1411,9 +1412,9 @@ INSTANTIATE_TEST_SUITE_P(smoke_TopK_With_Hardcoded_Refs, class ReferenceTopKTest1dMaxMinV3 : public ReferenceTopKTest1dMaxMin { private: static std::shared_ptr CreateFunction(const TopKParams& params, size_t out_idx) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto k = opset1::Constant::create(params.k.type, params.k.shape, params.k.data.data()); - const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto k = op::v0::Constant::create(params.k.type, params.k.shape, params.k.data.data()); + const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort); const auto f = std::make_shared(OutputVector{B->output(out_idx)}, ParameterVector{A}); return f; } @@ -1431,9 +1432,9 @@ INSTANTIATE_TEST_SUITE_P(smoke_TopK_With_Hardcoded_Refs, class ReferenceTopKTestInt64V3 : public ReferenceTopKTestInt64 { private: static std::shared_ptr CreateFunction(const TopKParams& params, size_t out_idx) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto k = opset1::Constant::create(params.k.type, params.k.shape, params.k.data.data()); - const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort, element::i64); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto k = op::v0::Constant::create(params.k.type, params.k.shape, params.k.data.data()); + const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort, element::i64); const auto f = std::make_shared(OutputVector{B->output(out_idx)}, ParameterVector{A}); return f; } @@ -1451,9 +1452,9 @@ INSTANTIATE_TEST_SUITE_P(smoke_TopK_With_Hardcoded_Refs, class ReferenceTopKTestSingleOutputV3 : public ReferenceTopKTestSingleOutput { private: static std::shared_ptr CreateFunction(const TopKParams& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto k = opset1::Constant::create(params.k.type, params.k.shape, params.k.data.data()); - const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto k = op::v0::Constant::create(params.k.type, params.k.shape, params.k.data.data()); + const auto B = std::make_shared(A, k, params.axis, params.mode, params.sort); const auto f = std::make_shared(OutputVector{B->output(1)}, ParameterVector{A}); return f; } @@ -1469,20 +1470,20 @@ INSTANTIATE_TEST_SUITE_P(smoke_TopK_With_Hardcoded_Refs, ReferenceTopKTestSingleOutputV3::getTestCaseName); TEST(ReferenceTopKTestInvalidV3, topk_v3_invalid_strings) { - const auto data = std::make_shared(element::f32, Shape{1, 2, 3}); - const auto k = opset1::Constant::create(element::i64, Shape{}, {1}); - EXPECT_THROW(opset3::TopK(data, k, 0, "max", "invalid_mode"), ov::AssertFailure); - EXPECT_THROW(opset3::TopK(data, k, 0, "invalid_sort", "index"), ov::AssertFailure); + const auto data = std::make_shared(element::f32, Shape{1, 2, 3}); + const auto k = op::v0::Constant::create(element::i64, Shape{}, {1}); + EXPECT_THROW(op::v3::TopK(data, k, 0, "max", "invalid_mode"), ov::AssertFailure); + EXPECT_THROW(op::v3::TopK(data, k, 0, "invalid_sort", "index"), ov::AssertFailure); } TEST(ReferenceTopKTestInvalidV3, topk_v3_invalid_k) { - const auto data = std::make_shared(element::f32, Shape{1, 2, 3}); - const auto k_non_scalar = opset1::Constant::create(element::i64, Shape{2}, {1, 2}); - EXPECT_THROW(opset3::TopK(data, k_non_scalar, 0, "max", "index"), ov::NodeValidationFailure); - const auto k_float = opset1::Constant::create(element::f32, Shape{}, {1.0f}); - EXPECT_THROW(opset3::TopK(data, k_float, 0, "max", "index"), ov::NodeValidationFailure); - const auto k_negative = opset1::Constant::create(element::i8, Shape{}, {-1}); - EXPECT_THROW(opset3::TopK(data, k_negative, 0, "max", "index"), ov::NodeValidationFailure); + const auto data = std::make_shared(element::f32, Shape{1, 2, 3}); + const auto k_non_scalar = op::v0::Constant::create(element::i64, Shape{2}, {1, 2}); + EXPECT_THROW(op::v3::TopK(data, k_non_scalar, 0, "max", "index"), ov::NodeValidationFailure); + const auto k_float = op::v0::Constant::create(element::f32, Shape{}, {1.0f}); + EXPECT_THROW(op::v3::TopK(data, k_float, 0, "max", "index"), ov::NodeValidationFailure); + const auto k_negative = op::v0::Constant::create(element::i8, Shape{}, {-1}); + EXPECT_THROW(op::v3::TopK(data, k_negative, 0, "max", "index"), ov::NodeValidationFailure); } class ReferenceTopKv11StableTest : public ReferenceTopKTest { @@ -1502,12 +1503,12 @@ class ReferenceTopKv11StableTest : public ReferenceTopKTest { private: static std::shared_ptr CreateFunction(const TopKParams& params) { - const auto A = std::make_shared(params.A.type, params.A.shape); - const auto k = opset11::Constant::create(params.k.type, params.k.shape, params.k.data.data()); + const auto A = std::make_shared(params.A.type, params.A.shape); + const auto k = op::v0::Constant::create(params.k.type, params.k.shape, params.k.data.data()); const auto topk_stable = - std::make_shared(A, k, params.axis, params.mode, params.sort, params.result1.type, true); + std::make_shared(A, k, params.axis, params.mode, params.sort, params.result1.type, true); const auto topk_unstable = - std::make_shared(A, k, params.axis, params.mode, params.sort, params.result1.type, false); + std::make_shared(A, k, params.axis, params.mode, params.sort, params.result1.type, false); return std::make_shared( OutputVector{topk_stable->output(0), topk_stable->output(1), topk_unstable->output(0)}, @@ -1528,8 +1529,8 @@ std::vector generateParamsForStableTest() { TopKParams(reference_tests::Tensor(ET, {2, 7}, std::vector{5, 4, 3, 1, 7, 1, 3, 2, 1, 2, 5, 1, 7, 3}), reference_tests::Tensor(ET2, {}, std::vector{3}), 1, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 3}, std::vector{1, 1, 3, 1, 1, 2}), reference_tests::Tensor(ET_OUT, {2, 3}, std::vector{3, 5, 2, 1, 4, 0}), 0, @@ -1541,8 +1542,8 @@ std::vector generateParamsForStableTest() { }), reference_tests::Tensor(ET2, {}, std::vector{4}), 0, - opset1::TopK::Mode::MAX, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MAX, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {4, 3}, std::vector{8, 9, 5, 7, 8, 4, 7, 7, 3, 5, 7, 2}), reference_tests::Tensor(ET_OUT, {4, 3}, std::vector{5, 1, 4, 1, 3, 5, 4, 0, 6, 0, 2, 2}), 0, @@ -1552,8 +1553,8 @@ std::vector generateParamsForStableTest() { std::vector{1, 3, 3, 1, 2, 4, 2, 2, 3, 7, 7, 1, 7, 9, 7, 5, 7, 7}), reference_tests::Tensor(ET2, {}, std::vector{2}), 1, - opset1::TopK::Mode::MIN, - opset1::TopK::SortType::SORT_VALUES, + op::v1::TopK::Mode::MIN, + op::v1::TopK::SortType::SORT_VALUES, reference_tests::Tensor(ET, {2, 2, 3}, std::vector{1, 2, 3, 1, 2, 3, 5, 7, 1, 7, 7, 7}), reference_tests::Tensor(ET_OUT, {2, 2, 3}, std::vector{0, 1, 0, 1, 2, 2, 2, 0, 0, 0, 2, 1}), 0, diff --git a/src/plugins/template/tests/functional/shared_tests_instances/behavior/ov_executable_network/ov_exec_net_import_export.cpp b/src/plugins/template/tests/functional/shared_tests_instances/behavior/ov_executable_network/ov_exec_net_import_export.cpp index 391c2919c26e74..388150d628600b 100644 --- a/src/plugins/template/tests/functional/shared_tests_instances/behavior/ov_executable_network/ov_exec_net_import_export.cpp +++ b/src/plugins/template/tests/functional/shared_tests_instances/behavior/ov_executable_network/ov_exec_net_import_export.cpp @@ -1,9 +1,8 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // -#include - #include "behavior/compiled_model/import_export.hpp" +#include "common_test_utils/test_constants.hpp" #include "ie_plugin_config.hpp" using namespace ov::test::behavior; diff --git a/src/plugins/template/tests/functional/subgraph_reference/preprocess_opencv.cpp b/src/plugins/template/tests/functional/subgraph_reference/preprocess_opencv.cpp index 32b4097eb58550..a19631713ad3c1 100644 --- a/src/plugins/template/tests/functional/subgraph_reference/preprocess_opencv.cpp +++ b/src/plugins/template/tests/functional/subgraph_reference/preprocess_opencv.cpp @@ -8,13 +8,13 @@ # include # include -# include -# include -# include -# include # include "base_reference_test.hpp" +# include "openvino/core/preprocess/pre_post_process.hpp" # include "ov_models/builders.hpp" +# include "shared_test_classes/base/layer_test_utils.hpp" +# include "shared_test_classes/single_layer/convert_color_i420.hpp" +# include "shared_test_classes/single_layer/convert_color_nv12.hpp" using namespace ov; using namespace ov::preprocess; diff --git a/src/plugins/template/tests/functional/transformations/disable_transformations_test.cpp b/src/plugins/template/tests/functional/transformations/disable_transformations_test.cpp index 6ad9c5c024f18a..7d5f878869f4ec 100644 --- a/src/plugins/template/tests/functional/transformations/disable_transformations_test.cpp +++ b/src/plugins/template/tests/functional/transformations/disable_transformations_test.cpp @@ -11,21 +11,24 @@ #include "common_test_utils/graph_comparator.hpp" #include "common_test_utils/ov_test_utils.hpp" #include "functional_test_utils/ov_plugin_cache.hpp" -#include "openvino/opsets/opset11.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/convert.hpp" +#include "openvino/op/convert_like.hpp" +#include "openvino/op/parameter.hpp" #include "template/properties.hpp" TEST(DisableTransformationsTests, TestTemplatePluginProperty) { std::shared_ptr m(nullptr), m_ref(nullptr); { - auto data = std::make_shared(ov::element::f32, ov::Shape{3, 1, 2}); - auto like = ov::opset11::Constant::create(ov::element::i32, ov::Shape{1}, {1}); - auto cvtlike = std::make_shared(data, like); + auto data = std::make_shared(ov::element::f32, ov::Shape{3, 1, 2}); + auto like = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1}); + auto cvtlike = std::make_shared(data, like); m = std::make_shared(ov::NodeVector{cvtlike}, ov::ParameterVector{data}); } { - auto data = std::make_shared(ov::element::f32, ov::Shape{3, 1, 2}); - auto cvt = std::make_shared(data, ov::element::i32); + auto data = std::make_shared(ov::element::f32, ov::Shape{3, 1, 2}); + auto cvt = std::make_shared(data, ov::element::i32); m_ref = std::make_shared(ov::NodeVector{cvt}, ov::ParameterVector{data}); } diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 944fc8d0d52054..d0a302ad12bec4 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -2,11 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 # -set(IE_TESTS_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) +set(OV_TESTS_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) enable_testing() -ie_option(ENABLE_CONFORMANCE_PGQL "Enables support of PostgreSQL-based reporting from test tools" OFF) +ov_option(ENABLE_CONFORMANCE_PGQL "Enables support of PostgreSQL-based reporting from test tools" OFF) mark_as_advanced(FORCE ENABLE_CONFORMANCE_PGQL) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/CMakeLists.txt b/src/tests/functional/plugin/conformance/subgraphs_dumper/CMakeLists.txt index 6f981d0702c96d..027af903cff097 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/CMakeLists.txt +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/CMakeLists.txt @@ -12,13 +12,13 @@ list(APPEND LIBRARIES ) # add subgraphs_dumpers tool -ov_add_target( +ov_add_test_target( NAME ${TARGET_NAME} TYPE EXECUTABLE ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src INCLUDES PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/include + "$" LINK_LIBRARIES PRIVATE ${LIBRARIES} @@ -34,7 +34,7 @@ ov_add_target( ROOT "${CMAKE_CURRENT_SOURCE_DIR}/src" INCLUDES PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/include + "$" LINK_LIBRARIES PUBLIC ${LIBRARIES} @@ -46,4 +46,4 @@ ov_add_target( ADD_CPPLINT ) -ov_build_target_faster(${TARGET_NAME} UNITY) \ No newline at end of file +ov_build_target_faster(${TARGET_NAME} UNITY) diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/cache/graph_cache.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/cache/graph_cache.hpp index 130847a58ea8da..6bcedde7f9a114 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/cache/graph_cache.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/cache/graph_cache.hpp @@ -6,6 +6,7 @@ #include "cache/cache.hpp" #include "cache/meta/input_info.hpp" +#include "utils/model_comparator.hpp" #include "matchers/subgraph/manager.hpp" #include "matchers/subgraph/subgraph.hpp" #include "matchers/subgraph/fused_names.hpp" @@ -42,10 +43,12 @@ class GraphCache : public ICache { protected: std::map, MetaInfo> m_graph_cache; - ExtractorsManager m_manager = ExtractorsManager(); - static std::shared_ptr m_cache_instance; // cache byte size uint64_t m_graph_cache_bytesize = 0; + ExtractorsManager m_manager; + ModelComparator::Ptr m_model_comparator = ModelComparator::get(); + std::shared_ptr model_to_update = nullptr; + static std::shared_ptr m_cache_instance; GraphCache(const std::string& device = "") { ExtractorsManager::ExtractorsMap matchers = { @@ -59,7 +62,7 @@ class GraphCache : public ICache { void update_cache(const std::shared_ptr& model, const std::string& model_path, - std::map& input_info, + const std::map& input_info, const std::string& extractor_name, size_t model_op_cnt); }; diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/cache/meta/input_info.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/cache/meta/input_info.hpp index 43e2b2a6356ed1..50f92af4f280f8 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/cache/meta/input_info.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/cache/meta/input_info.hpp @@ -59,6 +59,9 @@ struct InputInfo { } InputInfo operator=(const InputInfo& input_info) { + if (this->is_const != input_info.is_const) { + throw std::runtime_error("Cast Const to Parameter! Impossible to update Input Info!"); + } this->ranges = input_info.ranges; if (ov::shape_size(this->max_shape.get_max_shape()) < ov::shape_size(input_info.max_shape.get_max_shape())) { this->max_shape = input_info.max_shape; diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/cache/meta/meta_info.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/cache/meta/meta_info.hpp index 54625bfac52b39..971e101584cf66 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/cache/meta/meta_info.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/cache/meta/meta_info.hpp @@ -33,7 +33,10 @@ class MetaInfo { const std::string& extractor = "", const std::vector& ignored_inputs = {}); std::map get_input_info() const; - void set_input_info(const std::map& new_in_info) { input_info = new_in_info; }; + void set_input_info(const std::map& new_in_info) { + input_info.clear(); + input_info = new_in_info; + }; std::map get_model_info() const; std::string get_any_extractor() const { return *extractors.begin(); } diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/single_op/manager.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/single_op/manager.hpp index 8d8143d86250ba..f8b3540fa64302 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/single_op/manager.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/single_op/manager.hpp @@ -20,6 +20,8 @@ class MatchersManager { const std::shared_ptr &ref) const; void set_matchers(const MatchersMap& matchers = {}) { m_matchers = matchers; } + void set_shape_strict_match(bool shape_strict_match); + const MatchersMap& get_matchers() { return m_matchers; } iMatcherConfig::Ptr get_config(const std::shared_ptr &node) const; diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/single_op/single_op.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/single_op/single_op.hpp index d6ef95ad99864c..b86edfe06fa25d 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/single_op/single_op.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/single_op/single_op.hpp @@ -21,6 +21,7 @@ class SingleOpMatcher { const std::shared_ptr &ref) const; iMatcherConfig::Ptr get_config(const std::shared_ptr &node) const; + void set_strict_shape_match(bool strict_shape_match); protected: virtual void configure(const pugi::xml_document &cfg) {}; @@ -35,6 +36,8 @@ class SingleOpMatcher { const std::shared_ptr &ref) const; std::vector default_configs; + // match only shape ranks by default; + bool is_strict_shape_match = false; }; } // namespace subgraph_dumper diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/fused_names.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/fused_names.hpp index 5df31c77baaa0c..d9a78fe51220ce 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/fused_names.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/fused_names.hpp @@ -17,9 +17,7 @@ class FusedNamesExtractor final : public SubgraphExtractor { FusedNamesExtractor(const std::string& device = ""); ~FusedNamesExtractor(); - std::list extract(const std::shared_ptr &model, - bool is_extract_body = true, - bool is_copy_constants = true) override; + std::vector extract(const std::shared_ptr &modele) override; protected: std::unordered_set extract_compiled_model_names(const std::shared_ptr& model); diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/manager.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/manager.hpp index 8634585cf1a2ce..5e960e2d3197aa 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/manager.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/manager.hpp @@ -12,38 +12,19 @@ namespace subgraph_dumper { class ExtractorsManager { public: - // { model, subgraph, model_in_info, subgraph_in_info } - using ExtractedSubgraphTuple = std::tuple, std::shared_ptr, std::map, std::map>; using ExtractorsMap = std::map; explicit ExtractorsManager(const ExtractorsMap& extractors = {}) : m_extractors(extractors) {} - bool match(const std::shared_ptr &model, - const std::shared_ptr &ref_model, - std::map &in_info, - const std::map &in_info_ref); - ExtractedSubgraphTuple is_subgraph(const std::shared_ptr &model, - const std::shared_ptr &ref_model, - const std::map &in_info = {}, - const std::map &in_info_ref = {}); - std::list extract(const std::shared_ptr &model, - bool is_extract_body = true, - bool is_copy_constants = true); + std::vector extract(const std::shared_ptr &model, + bool is_extract_body = true, + bool is_copy_constants = true); void set_extractors(const ExtractorsMap& extractors = {}) { m_extractors = extractors; } ExtractorsMap get_extractors() { return m_extractors; } - std::map align_input_info(const std::shared_ptr& model, - const std::shared_ptr& model_ref, - const std::map &in_info, - const std::map &in_info_ref, - const std::map &matched_op = {}); - protected: ExtractorsMap m_extractors = {}; - - bool match(const std::shared_ptr &model, - const std::shared_ptr &ref); }; } // namespace subgraph_dumper diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/repeat_pattern.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/repeat_pattern.hpp index 874ed35be83662..f38ebfe507f5b7 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/repeat_pattern.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/repeat_pattern.hpp @@ -5,31 +5,45 @@ #pragma once #include + #include "matchers/subgraph/subgraph.hpp" -#include "matchers/single_op/single_op.hpp" -#include "matchers/single_op/convolutions.hpp" -#include "matchers/single_op/manager.hpp" namespace ov { namespace tools { namespace subgraph_dumper { class RepeatPatternExtractor final : public SubgraphExtractor { +private: + using InputVector = std::vector>; + using OutputVector = std::vector>; + public: - RepeatPatternExtractor() { - MatchersManager::MatchersMap matchers = { - { "generic_single_op", SingleOpMatcher::Ptr(new SingleOpMatcher) }, - { "convolutions", ConvolutionsMatcher::Ptr(new ConvolutionsMatcher) }, - }; - manager.set_matchers(matchers); - } - - std::list extract(const std::shared_ptr &model, - bool is_extract_body = true, - bool is_copy_constants = true) override; + using PatternBorders = std::pair; + ModelComparator::Ptr model_comparator = ModelComparator::get(); + + std::vector> + get_repeat_pattern_borders(const std::shared_ptr &model); + std::vector> + get_repeat_node_vectors(const std::shared_ptr &model); + + void set_recursive_extraction(bool _is_recursive_extraction); + std::vector extract(const std::shared_ptr &model) override; + +protected: + // {subgraph, node_vector, input_info} + using ExtractedRepeatPattern = std::tuple, ov::NodeVector, std::map>; + bool is_recursive_extraction = true; + + std::list> + find_repeat_patterns(const std::shared_ptr &model, + bool is_save_borders_only = false); + void update_extractor_cache(std::list>& extracted_patterns, + std::list>& secondary_extracted_patterns); + void update_extractor_cache(std::list>& extracted_patterns, + const std::shared_ptr& pattern, + const ov::NodeVector& pattern_node_vector, + const std::map& in_info); -private: - MatchersManager manager; }; } // namespace subgraph_dumper diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/subgraph.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/subgraph.hpp index 5f7dd9d8204b25..04e3b08ee9885f 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/subgraph.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/subgraph.hpp @@ -7,12 +7,8 @@ #include #include "openvino/op/util/op_types.hpp" -#include "common_test_utils/graph_comparator.hpp" -#include "cache/meta/input_info.hpp" -#include "matchers/single_op/single_op.hpp" -#include "matchers/single_op/convolutions.hpp" -#include "matchers/single_op/manager.hpp" +#include "utils/model_comparator.hpp" namespace ov { namespace tools { @@ -20,44 +16,19 @@ namespace subgraph_dumper { class SubgraphExtractor { public: - // { is_subgraph, model, subgraph, matched_ops{ model_op_name, graph_op_name }} - using IsSubgraphTuple = std::tuple, std::shared_ptr, std::map>; using Ptr = std::shared_ptr; - SubgraphExtractor() { - MatchersManager::MatchersMap matchers = { - { "generic_single_op", SingleOpMatcher::Ptr(new SingleOpMatcher) }, - { "convolutions", ConvolutionsMatcher::Ptr(new ConvolutionsMatcher) }, - }; - m_manager.set_matchers(matchers); + virtual std::vector extract(const std::shared_ptr &model) { + return std::vector{}; } - bool match(const std::shared_ptr &model, - const std::shared_ptr &ref_model) const; - IsSubgraphTuple is_subgraph(const std::shared_ptr &model, - const std::shared_ptr &ref_model) const; - - virtual std::list extract(const std::shared_ptr &model, - bool is_extract_body = true, - bool is_copy_constants = true) { - return std::list{}; - }; - void set_extractor_name(const std::string& _extractor_name) { extractor_name = _extractor_name; } + void set_extract_body(bool _is_extract_body) { is_extract_body = _is_extract_body; } + void set_save_const(bool _is_save_const) { is_save_const = _is_save_const; } protected: std::string extractor_name = ""; - FunctionsComparator comparator = FunctionsComparator::no_default() - .enable(FunctionsComparator::ATTRIBUTES) - .enable(FunctionsComparator::NODES) - .enable(FunctionsComparator::PRECISIONS); - MatchersManager m_manager = MatchersManager(); - - inline bool is_node_to_skip(const std::shared_ptr& node) const { - return ov::op::util::is_parameter(node) || - ov::op::util::is_constant(node) || - ov::op::util::is_output(node); - } + bool is_extract_body = true, is_save_const = true; }; } // namespace subgraph_dumper diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/utils/model.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/utils/model.hpp index 61ce8ce8d7a637..8b48b2074df711 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/utils/model.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/utils/model.hpp @@ -33,7 +33,7 @@ static std::vector FROTEND_REGEXP = { std::regex(R"(.*__model__)"), #endif #ifdef ENABLE_OV_TF_FRONTEND - std::regex(R"(.*\.pb)"), + std::regex(R"(.*\model.pb)"), #endif #ifdef ENABLE_OV_IR_FRONTEND std::regex(R"(.*\.xml)"), @@ -74,32 +74,24 @@ std::map> cache_models( void save_model_status_to_file(const std::map>& caching_status, const std::string& output_dir); -inline bool is_dynamic_model(const std::shared_ptr& model) { - for (const auto& parameter : model->get_parameters()) { - if (is_dynamic_node(parameter)) { - return true; - } - } - for (const auto& result : model->get_results()) { - if (is_dynamic_node(result)) { - return true; - } - } - return false; -} +bool is_dynamic_model(const std::shared_ptr& model); +std::string get_model_type(const std::shared_ptr& model); -inline std::string get_model_type(const std::shared_ptr& model) { - if (is_dynamic_model(model)) { - return "dynamic"; - } - return "static"; -} +std::map +get_input_info_by_model(const std::shared_ptr& model); -inline ExtractedPattern -generate_model(const std::set>& nodes, +std::map +align_input_info(const std::shared_ptr& model, + const std::shared_ptr& model_ref, + const std::map &in_info, + const std::map &in_info_ref, + const std::map &matched_op = {}); + +inline std::pair, std::map> +generate_model(ov::NodeVector& nodes, std::unordered_set& checked_ops, - const std::string& extractor_name, - bool is_copy_constants = true) { + bool is_copy_constants = true, + bool is_save_only_borders = false) { // map to recover graph using cloned nodes and original connections // { original_node_name, cloned_node } std::unordered_map> cloned_node_map; @@ -214,27 +206,51 @@ generate_model(const std::set>& nodes, // prepare unique model name based on operations from model std::string string_to_hash; for (const auto& op : model->get_ordered_ops()) { + bool is_erase_node = !is_save_only_borders; std::ostringstream result; result << op->get_type_info(); - for (const auto& in : op->inputs()) { + for (size_t i = 0; i < op->inputs().size(); ++i) { + const auto& in = op->input(i); + if (!is_node_to_skip(op->get_input_node_shared_ptr(i))) { + is_erase_node |= true; + } result << in.get_element_type(); result << in.get_partial_shape().rank(); result << in.get_partial_shape().is_static(); } for (const auto& out : op->outputs()) { + for (const auto& target_input : out.get_target_inputs()) { + if (!is_node_to_skip(target_input.get_node()->shared_from_this())) { + is_erase_node |= true; + break; + } + } result << out.get_element_type(); result << out.get_partial_shape().rank(); result << out.get_partial_shape().is_static(); } string_to_hash += result.str(); + if (is_erase_node) { + cloned_node_map.erase(op->get_friendly_name()); + } } for (const auto& in : model_input_info) { string_to_hash += (in.second.is_const ? "1" : "0"); } auto h1 = std::hash{}(string_to_hash); model->set_friendly_name(std::to_string(h1)); - - return { model, model_input_info, extractor_name }; + { + auto it = nodes.begin(); + while (it != nodes.end()) { + if (cloned_node_map.count((*it)->get_friendly_name())) { + nodes.erase(it); + } else { + ++it; + } + } + } + + return { model, model_input_info }; } } // namespace subgraph_dumper diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/utils/model_comparator.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/utils/model_comparator.hpp new file mode 100644 index 00000000000000..e3388fe9438ada --- /dev/null +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/utils/model_comparator.hpp @@ -0,0 +1,68 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "matchers/single_op/single_op.hpp" +#include "matchers/single_op/convolutions.hpp" +#include "matchers/single_op/manager.hpp" + +namespace ov { +namespace tools { +namespace subgraph_dumper { + +class ModelComparator { +public: + using Ptr = std::shared_ptr; + // { is_match, subgraph, graph, matched_nodes -> {subgraph_op_name, graph_op_name}} + using IsSubgraphTuple = std::tuple, std::shared_ptr, std::map>; + // { model, subgraph, graph, subgraph_in_info, model_in_info, } + using ExtractedSubgraphTuple = std::tuple, std::shared_ptr, std::map, std::map>; + + static std::shared_ptr get(bool in_is_match_shapes = false) { + if (m_instance == nullptr) { + m_instance = std::shared_ptr(new ModelComparator); + } + return m_instance; + } + + IsSubgraphTuple is_subgraph(const std::shared_ptr &model, + const std::shared_ptr &ref_model) const; + + bool match(const std::shared_ptr &node, + const std::shared_ptr &ref_node) const; + bool match(const std::shared_ptr &model, + const std::shared_ptr &ref_model) const; + + std::pair> + match(const std::shared_ptr &model, + const std::shared_ptr &ref_model, + const std::map &in_info, + const std::map &in_info_ref); + ExtractedSubgraphTuple + is_subgraph(const std::shared_ptr &model, + const std::shared_ptr &ref_model, + const std::map &in_info, + const std::map &in_info_ref); + + void set_match_coefficient(float _match_coefficient); + void set_shape_strict_match(bool is_shape_strict_match); + +protected: + MatchersManager m_manager = MatchersManager(); + float match_coefficient = 0.9f; + static std::shared_ptr m_instance; + + ModelComparator() { + MatchersManager::MatchersMap matchers = { + { "generic_single_op", SingleOpMatcher::Ptr(new SingleOpMatcher) }, + { "convolutions", ConvolutionsMatcher::Ptr(new ConvolutionsMatcher) }, + }; + m_manager.set_matchers(matchers); + } +}; + +} // namespace subgraph_dumper +} // namespace tools +} // namespace ov diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/utils/node.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/utils/node.hpp index c679707bf5b3ae..928ebd36935345 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/utils/node.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/utils/node.hpp @@ -26,6 +26,9 @@ inline InputInfo::Range get_const_ranges(const std::shared_ptr(min), static_cast(max)); } +InputInfo::Range get_const_ranges(const std::shared_ptr& const_node, + ov::element::Type elem_type); + std::map get_input_info_by_node(const std::shared_ptr& node); // replace all input node by parameters and constants instead of non input mode types @@ -111,6 +114,12 @@ inline size_t get_node_priority_by_version(const std::shared_ptr& node return priority; } + +inline bool is_node_to_skip(const std::shared_ptr& node) { + return ov::op::util::is_parameter(node) || + ov::op::util::is_constant(node) || + ov::op::util::is_output(node); +} } // namespace subgraph_dumper } // namespace tools diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/cache/cache.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/cache/cache.cpp index 38df8575dd730b..0938de3383667b 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/cache/cache.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/cache/cache.cpp @@ -42,8 +42,8 @@ bool ICache::serialize_model(const std::pair, MetaInf meta.serialize(meta_path); return true; } catch (std::exception &e) { - // std::cout << "[ ERROR ] Failed to serialize model: " << model_name - // << ". Exception: " << e.what() << std::endl; + std::cout << "[ ERROR ] Failed to serialize model: " << model_name + << ". Exception: " << e.what() << std::endl; ov::test::utils::removeFile(xml_path); ov::test::utils::removeFile(bin_path); ov::test::utils::removeFile(meta_path); diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/cache/graph_cache.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/cache/graph_cache.cpp index 1273f5cc342d1b..51ee4835419c15 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/cache/graph_cache.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/cache/graph_cache.cpp @@ -56,77 +56,92 @@ void GraphCache::update_cache(const std::shared_ptr& model, return; } while (!extracted_patterns.empty()) { - auto it = *extracted_patterns.begin(); + auto it = *extracted_patterns.rbegin(); update_cache(std::get<0>(it), model_meta_data, std::get<1>(it), std::get<2>(it), model_total_op); - extracted_patterns.pop_front(); + extracted_patterns.pop_back(); } } } void GraphCache::update_cache(const std::shared_ptr& extracted_model, const std::string& model_path, - std::map& input_info, + const std::map& input_info, const std::string& extractor_name, size_t model_op_cnt) { auto graph_name = extracted_model->get_friendly_name(); auto this_op_cnt = extracted_model->get_ops().size() - extracted_model->get_parameters().size() - extracted_model->get_results().size(); - std::string serialized_model_path = ""; - for (const auto& extractor : m_manager.get_extractors()) { - auto tmp_serialized_model_path = ov::util::path_join({ m_serialization_dir, m_cache_subdir, extractor.first, graph_name + ".xml" }); - if (ov::util::file_exists(serialized_model_path)) { - serialized_model_path = tmp_serialized_model_path; - break; + std::map updated_input_info; + if (!m_graph_cache.empty() && model_to_update != nullptr) { + auto comparator_res = m_model_comparator->match(extracted_model, model_to_update, + input_info, m_graph_cache.at(model_to_update).get_input_info()); + if (comparator_res.first) { + updated_input_info = comparator_res.second; + } else { + model_to_update = nullptr; } } - std::shared_ptr model_to_update = nullptr; - // if cached model was serialized - if (!serialized_model_path.empty()) { - // std::cout << "[ GRAPH CACHE ][ INFO ] Reading cached model: " << serialized_model_path << std::endl; - auto bin_path = ov::test::utils::replaceExt(serialized_model_path, ".bin"); - auto meta_path = ov::test::utils::replaceExt(serialized_model_path, ".meta"); - auto cached_model = ov::test::utils::PluginCache::get().core()->read_model(serialized_model_path); - auto cached_meta = MetaInfo::read_meta_from_file(meta_path); + if (model_to_update == nullptr) { + std::string serialized_model_path = ""; + for (const auto& extractor : m_manager.get_extractors()) { + auto tmp_serialized_model_path = ov::util::path_join({ m_serialization_dir, m_cache_subdir, extractor.first, graph_name + ".xml" }); + if (ov::util::file_exists(serialized_model_path)) { + serialized_model_path = tmp_serialized_model_path; + break; + } + } + // if cached model was serialized + if (!serialized_model_path.empty()) { + // std::cout << "[ GRAPH CACHE ][ INFO ] Reading cached model: " << serialized_model_path << std::endl; + auto bin_path = ov::test::utils::replaceExt(serialized_model_path, ".bin"); + auto meta_path = ov::test::utils::replaceExt(serialized_model_path, ".meta"); + auto cached_model = ov::test::utils::PluginCache::get().core()->read_model(serialized_model_path); + auto cached_meta = MetaInfo::read_meta_from_file(meta_path); - ov::test::utils::removeFile(serialized_model_path); - ov::test::utils::removeFile(bin_path); - ov::test::utils::removeFile(meta_path); + ov::test::utils::removeFile(serialized_model_path); + ov::test::utils::removeFile(bin_path); + ov::test::utils::removeFile(meta_path); - m_graph_cache.insert({ cached_model, cached_meta }); - m_graph_cache_bytesize += cached_model->get_graph_size(); + m_graph_cache.insert({ cached_model, cached_meta }); + m_graph_cache_bytesize += cached_model->get_graph_size(); - if (m_manager.match(extracted_model, cached_model, - input_info, cached_meta.get_input_info())) { - model_to_update = cached_model; - } - } else { - for (const auto& cached_model : m_graph_cache) { - if (m_manager.match(extracted_model, cached_model.first, - input_info, cached_model.second.get_input_info())) { - model_to_update = cached_model.first; - break; - } else { - auto is_subgraph = m_manager.is_subgraph(extracted_model, cached_model.first, - input_info, cached_model.second.get_input_info()); - // in case if one model is subgraph of other to update model meta info and remove subgraph from cache - if (std::get<0>(is_subgraph)) { - std::shared_ptr graph, subgraph; - std::map graph_in_info, subgraph_in_info; - std::tie(std::ignore, graph, subgraph, graph_in_info, subgraph_in_info) = is_subgraph; - if (subgraph == cached_model.first) { - auto meta = m_graph_cache[subgraph]; - meta.set_input_info(graph_in_info); - m_graph_cache.erase(subgraph); - m_graph_cache.insert({graph, meta}); - m_graph_cache_bytesize += (graph->get_graph_size() - subgraph->get_graph_size()); + auto comparator_res = m_model_comparator->match(extracted_model, cached_model, + input_info, cached_meta.get_input_info()); + if (comparator_res.first) { + model_to_update = cached_model; + updated_input_info = comparator_res.second; + } + } else { + for (const auto& cached_model : m_graph_cache) { + auto comparator_res = m_model_comparator->match(extracted_model, cached_model.first, + input_info, cached_model.second.get_input_info()); + if (comparator_res.first) { + model_to_update = cached_model.first; + updated_input_info = comparator_res.second; + break; + } else { + auto is_subgraph = m_model_comparator->is_subgraph(extracted_model, cached_model.first, + input_info, cached_model.second.get_input_info()); + // in case if one model is subgraph of other to update model meta info and remove subgraph from cache + if (std::get<0>(is_subgraph)) { + std::shared_ptr graph, subgraph; + std::map graph_in_info, subgraph_in_info; + std::tie(std::ignore, subgraph, graph, subgraph_in_info, graph_in_info) = is_subgraph; + if (subgraph == cached_model.first) { + auto meta = m_graph_cache[subgraph]; + meta.set_input_info(graph_in_info); + m_graph_cache.erase(subgraph); + m_graph_cache.insert({graph, meta}); + m_graph_cache_bytesize += (graph->get_graph_size() - subgraph->get_graph_size()); + } + m_graph_cache[cached_model.first].update(model_path, + subgraph_in_info, + model_op_cnt, + this_op_cnt, + extractor_name); + return; } - m_graph_cache[cached_model.first].update(model_path, - subgraph_in_info, - model_op_cnt, - this_op_cnt, - extractor_name); - return; } } } @@ -134,18 +149,22 @@ void GraphCache::update_cache(const std::shared_ptr& extracted_model, if (model_to_update == nullptr) { MetaInfo meta = MetaInfo(model_path, input_info, model_op_cnt, this_op_cnt, extractor_name); - m_graph_cache.insert({ extracted_model, meta }); + model_to_update = extracted_model; + m_graph_cache.insert({ model_to_update, meta }); m_graph_cache_bytesize += extracted_model->get_graph_size(); return; } - m_graph_cache[model_to_update].update(model_path, input_info, model_op_cnt, this_op_cnt, extractor_name); + m_graph_cache[model_to_update].update(model_path, updated_input_info, model_op_cnt, this_op_cnt, extractor_name); auto cached_model_size = model_to_update->get_graph_size(); auto pattern_model_size = extracted_model->get_graph_size(); if (pattern_model_size < cached_model_size) { m_graph_cache_bytesize -= (cached_model_size - pattern_model_size); auto meta = m_graph_cache[model_to_update]; + auto new_in_info = align_input_info(model_to_update, extracted_model, m_graph_cache.at(model_to_update).get_input_info(), input_info); + meta.set_input_info(new_in_info); m_graph_cache.erase(model_to_update); - m_graph_cache.insert({extracted_model, meta}); + model_to_update = extracted_model; + m_graph_cache.insert({model_to_update, meta}); } } diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/cache/meta/meta_info.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/cache/meta/meta_info.cpp index 68213db323c7a2..ab8cc56c92e4de 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/cache/meta/meta_info.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/cache/meta/meta_info.cpp @@ -169,7 +169,6 @@ void MetaInfo::update(const std::string& _model_path, size_t _this_op_cnt, const std::string& extractor, const std::vector& ignored_inputs) { - bool is_update_in_info = true; if (input_info.size() != _input_info.size()) { throw std::runtime_error("Incompatible input info!"); } @@ -193,9 +192,6 @@ void MetaInfo::update(const std::string& _model_path, if (!extractor.empty()) { extractors.insert(extractor); } - if (!is_update_in_info) { - return; - } for (const auto& in : _input_info) { if (std::find(ignored_inputs.begin(), ignored_inputs.end(), in.first) != ignored_inputs.begin()) { continue; diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/single_op/convolutions.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/single_op/convolutions.cpp index 30b99c580df314..3913f98fe5e9cd 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/single_op/convolutions.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/single_op/convolutions.cpp @@ -50,8 +50,11 @@ bool ConvolutionsMatcher::match_inputs(const std::shared_ptr &node, bool has_groups = std::dynamic_pointer_cast(node) || std::dynamic_pointer_cast(node); size_t kernel_size_offset = has_groups ? 3 : 2; - auto ref_weights_shape = ref->get_input_tensor(1).get_shape(); - auto cur_weights_shape = node->get_input_tensor(1).get_shape(); + auto ref_weights_shape = ref->get_input_partial_shape(1).get_shape(); + auto cur_weights_shape = node->get_input_partial_shape(1).get_shape(); + if (is_strict_shape_match && ref_weights_shape != cur_weights_shape) { + return false; + } const auto ref_kernel_size = std::vector(ref_weights_shape.begin() + kernel_size_offset, ref_weights_shape.end()); const auto cur_kernel_size = std::vector(cur_weights_shape.begin() + kernel_size_offset, diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/single_op/manager.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/single_op/manager.cpp index 675d808d92b42c..334128e65426ac 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/single_op/manager.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/single_op/manager.cpp @@ -17,9 +17,15 @@ iMatcherConfig::Ptr MatchersManager::get_config(const std::shared_ptr return nullptr; } +void MatchersManager::set_shape_strict_match(bool shape_strict_match) { + for (const auto& matcher : m_matchers) { + matcher.second->set_strict_shape_match(shape_strict_match); + } +} + bool MatchersManager::match(const std::shared_ptr &node, const std::shared_ptr &ref) const { - for (const auto &it : m_matchers) { + for (const auto& it : m_matchers) { if (it.second->match(node, ref)) { return true; } diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/single_op/single_op.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/single_op/single_op.cpp index 3e0abda2a936e9..dc81db171f8b99 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/single_op/single_op.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/single_op/single_op.cpp @@ -7,6 +7,7 @@ #include "openvino/op/util/op_types.hpp" #include "common_test_utils/graph_comparator.hpp" #include "matchers/single_op/single_op.hpp" +#include "utils/node.hpp" using namespace ov::tools::subgraph_dumper; @@ -24,6 +25,10 @@ iMatcherConfig::Ptr SingleOpMatcher::get_config(const std::shared_ptr return std::make_shared>(); } +void SingleOpMatcher::set_strict_shape_match(bool strict_shape_match) { + is_strict_shape_match = strict_shape_match; +} + bool SingleOpMatcher::match_inputs(const std::shared_ptr &node, const std::shared_ptr &ref) const { if (node->get_input_size() != ref->get_input_size()) { @@ -35,21 +40,17 @@ bool SingleOpMatcher::match_inputs(const std::shared_ptr &node, if (std::find(ignored_ports.begin(), ignored_ports.end(), port_id) != ignored_ports.end()) { continue; } - if (!ov::op::util::is_parameter(node) && !ov::op::util::is_parameter(ref) && - !ov::op::util::is_constant(node) && !ov::op::util::is_constant(ref)) { - const auto &cur_node_input_type = node->input_value(port_id).get_node_shared_ptr()->get_type_info(); - const auto &ref_node_input_type = ref->input_value(port_id).get_node_shared_ptr()->get_type_info(); - if (cur_node_input_type != ref_node_input_type) { - return false; - } - } - if (node->get_input_tensor(port_id).get_partial_shape().rank() != ref->get_input_tensor(port_id).get_partial_shape().rank()) { + if (node->get_input_element_type(port_id) != ref->get_input_element_type(port_id)) { return false; } - if (node->get_input_tensor(port_id).get_element_type() != ref->get_input_tensor(port_id).get_element_type()) { + const auto& partial_shape = node->get_input_partial_shape(port_id); + const auto& ref_partial_shape = ref->get_input_partial_shape(port_id); + if (is_strict_shape_match && partial_shape != ref_partial_shape) { + return false; + } else if (partial_shape.rank() != ref_partial_shape.rank()) { return false; } - if (node->get_input_partial_shape(port_id).is_dynamic() != ref->get_input_partial_shape(port_id).is_dynamic()) { + if (partial_shape.is_dynamic() != ref_partial_shape.is_dynamic()) { return false; } } @@ -63,20 +64,18 @@ SingleOpMatcher::match_outputs(const std::shared_ptr &node, return false; } for (size_t port_id = 0; port_id < node->get_output_size(); ++port_id) { - if (!ov::op::util::is_output(node) && !ov::op::util::is_output(ref)) { - const auto &cur_node_out_type = node->output(port_id).get_node_shared_ptr()->get_type_info(); - const auto &ref_node_out_type = ref->output(port_id).get_node_shared_ptr()->get_type_info(); - if (cur_node_out_type != ref_node_out_type) { - return false; - } - } - if (node->get_output_tensor(port_id).get_element_type() != ref->get_output_tensor(port_id).get_element_type()) { + if (node->get_output_element_type(port_id) != ref->get_output_element_type(port_id)) { return false; } - if (node->get_output_tensor(port_id).get_partial_shape().is_dynamic() != ref->get_output_tensor(port_id).get_partial_shape().is_dynamic()) { + + const auto& partial_shape = node->get_output_partial_shape(port_id); + const auto& ref_partial_shape = ref->get_output_partial_shape(port_id); + if (partial_shape.is_dynamic() != ref_partial_shape.is_dynamic()) { return false; } - if (node->get_output_tensor(port_id).get_partial_shape().rank()!= ref->get_output_tensor(port_id).get_partial_shape().rank()) { + if (is_strict_shape_match && partial_shape != ref_partial_shape) { + return false; + } else if (partial_shape.rank() != ref_partial_shape.rank()) { return false; } } @@ -98,17 +97,16 @@ bool SingleOpMatcher::match(const std::shared_ptr &node, if (cfg->ignore_matching) { return false; } - if (!same_op_type(node, ref)) { return false; } if (!match_inputs(node, ref)) { return false; } - if (!match_attrs(node, ref) && !ov::op::util::is_parameter(node) && !ov::op::util::is_parameter(ref)) { + if (!match_outputs(node, ref)) { return false; } - if (!match_outputs(node, ref)) { + if (!match_attrs(node, ref) && !is_node_to_skip(node)) { return false; } return true; @@ -121,9 +119,6 @@ bool SingleOpMatcher::same_op_type(const std::shared_ptr &node, SingleOpMatcher::SingleOpMatcher() { default_configs = { - // std::make_shared>(std::vector{}, std::vector{0}), - // std::make_shared>(std::vector{}, - // std::vector{0, 1, 2, 3, 4}), std::make_shared -FusedNamesExtractor::extract(const std::shared_ptr &model, - bool is_extract_body, - bool is_copy_constants) { +std::vector +FusedNamesExtractor::extract(const std::shared_ptr &model) { auto compiled_op_name = extract_compiled_model_names(model); - std::list matched_patterns; + std::vector matched_patterns; std::unordered_set checked_ops; - std::set> nodes; + ov::NodeVector nodes; for (const auto& op : model->get_ordered_ops()) { auto op_name = op->get_friendly_name(); if (is_node_to_skip(op) || checked_ops.count(op_name)) { @@ -71,7 +70,8 @@ FusedNamesExtractor::extract(const std::shared_ptr &model, } if (compiled_op_name.count(op_name)) { try { - matched_patterns.push_back(generate_model(nodes, checked_ops, extractor_name, is_copy_constants)); + auto extracted_pattern = generate_model(nodes, checked_ops, is_save_const); + matched_patterns.push_back({ extracted_pattern.first, extracted_pattern.second, extractor_name }); } catch(std::exception& e) { if (std::string(e.what()).find("Incorrect node number to create model") == std::string::npos) { // std::cout << "[ WARNING ] Impossible to generate network and add to GraphCache: " < &model, } nodes.clear(); } else { - nodes.insert(op); + nodes.push_back(op); } if (is_extract_body) { if (std::dynamic_pointer_cast(op)) { @@ -104,7 +104,8 @@ FusedNamesExtractor::extract(const std::shared_ptr &model, } } try { - matched_patterns.push_back(generate_model(nodes, checked_ops, extractor_name, is_copy_constants)); + auto extracted_pattern = generate_model(nodes, checked_ops, is_save_const); + matched_patterns.push_back({ extracted_pattern.first, extracted_pattern.second, extractor_name }); } catch(std::exception& e) { if (std::string(e.what()).find("Incorrect node number to create model") == std::string::npos) { // std::cout << "[ WARNING ] Impossible to generate network and add to GraphCache: " < &model, - const std::shared_ptr &ref) { - // `match` is not virtual method in base `SubgraphExtractor` class - // we can use function from any `extractor` to avoid of cycle - if (!m_extractors.empty()) { - if (m_extractors.begin()->second->match(model, ref)) { - return true; - } - } - return false; -} - -ExtractorsManager::ExtractedSubgraphTuple -ExtractorsManager::is_subgraph(const std::shared_ptr &model, - const std::shared_ptr &ref_model, - const std::map &in_info, - const std::map &in_info_ref) { - if (!m_extractors.empty()) { - // `is_subgraph` is not virtual method in base `SubgraphExtractor` class - // we can use function from any `extractor` to avoid of cycle - auto extractor_res = m_extractors.begin()->second->is_subgraph(model, ref_model); - if (std::get<0>(extractor_res)) { - std::map graph_in_info, subgraph_in_info; - if (std::get<1>(extractor_res) == model && std::get<2>(extractor_res) == ref_model) { - graph_in_info = in_info; - subgraph_in_info = in_info_ref; - } else if (std::get<1>(extractor_res) == ref_model && std::get<2>(extractor_res) == model) { - graph_in_info = in_info_ref; - subgraph_in_info = in_info; - } else { - throw std::runtime_error("Generated models are incompatible with original ones!"); - } - try { - subgraph_in_info = align_input_info(std::get<2>(extractor_res), std::get<1>(extractor_res), subgraph_in_info, graph_in_info); - } catch(std::exception) { - return { false, nullptr, nullptr, {}, {} }; - } - return { true, std::get<1>(extractor_res), std::get<2>(extractor_res), graph_in_info, subgraph_in_info }; - } - } - return { false, nullptr, nullptr, {}, {} }; -} - -bool ExtractorsManager::match(const std::shared_ptr &model, - const std::shared_ptr &ref, - std::map &in_info, - const std::map &in_info_ref) { - if (match(model, ref)) { - try { - in_info = align_input_info(model, ref, in_info, in_info_ref); - return true; - } catch (std::exception) { - return false; - } - } - return false; -} - -std::map -ExtractorsManager::align_input_info(const std::shared_ptr& model, - const std::shared_ptr& model_ref, - const std::map& in_info, - const std::map& in_info_ref, - const std::map &matched_op) { - std::map new_input_info = in_info; - bool is_update_required = false; - for (const auto& in_info_item : in_info_ref) { - if (!in_info.count(in_info_item.first)) { - is_update_required = true; - break; - } else if (in_info.at(in_info_item.first).is_const != in_info_item.second.is_const) { - throw std::runtime_error("Impossible to update input info!!!"); - } - } - if (is_update_required) { - // align matched model names - auto ref_model_ops = model_ref->get_ordered_ops(); - auto model_ops = model->get_ordered_ops(); - size_t ref_ordered_ops_size = ref_model_ops.size(); - size_t ordered_ops_size = model_ops.size(); - if (ref_ordered_ops_size != ordered_ops_size && matched_op.empty()) { - throw std::runtime_error("Matched models can not be compared according different op numbers!"); - } - for (size_t i = 0; i < ref_ordered_ops_size; ++i) { - auto model_op_name = i < ordered_ops_size ? model_ops[i]->get_friendly_name() : ""; - auto model_ref_op_name = ref_model_ops[i]->get_friendly_name(); - if (!in_info_ref.count(model_ref_op_name) && !in_info.count(model_op_name)) { - continue; - } - auto input_info = matched_op.empty() ? new_input_info[model_op_name] : in_info_ref.at(model_ref_op_name); - std::string input_name = matched_op.count(model_ref_op_name) ? matched_op.at(model_ref_op_name) : model_op_name; - if (new_input_info.count(input_name)) { - if (input_info.is_const != in_info_ref.at(model_ref_op_name).is_const) { - throw std::runtime_error("Impossible to update input info!!!"); - } - if (!matched_op.empty()) { - input_info = new_input_info.at(input_name); - } - new_input_info.erase(input_name); - } - new_input_info.insert({ model_ref_op_name, input_info }); - } - } - return new_input_info; -} - -std::list +std::vector ExtractorsManager::extract(const std::shared_ptr &model, bool is_extract_body, bool is_copy_constants) { - std::list result; + std::vector result; for (const auto &it : m_extractors) { // extract patterns from original models auto start = std::chrono::high_resolution_clock::now(); it.second->set_extractor_name(it.first); - auto extracted_patterns = it.second->extract(model, is_extract_body, is_copy_constants); + it.second->set_extract_body(is_extract_body); + it.second->set_save_const(is_copy_constants); + auto extracted_patterns = it.second->extract(model); result.insert(result.end(), extracted_patterns.begin(), extracted_patterns.end()); auto end = std::chrono::high_resolution_clock::now(); auto delta = std::chrono::duration_cast(end - start).count(); diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/subgraph/repeat_pattern.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/subgraph/repeat_pattern.cpp index 4331b178a7b037..006714774cc2a0 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/subgraph/repeat_pattern.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/subgraph/repeat_pattern.cpp @@ -8,18 +8,118 @@ #include "openvino/op/lstm_cell.hpp" #include "openvino/op/tensor_iterator.hpp" #include "openvino/op/if.hpp" +#include "openvino/op/loop.hpp" #include "matchers/subgraph/repeat_pattern.hpp" #include "utils/model.hpp" +#include "utils/model_comparator.hpp" using namespace ov::tools::subgraph_dumper; -std::list -RepeatPatternExtractor::extract(const std::shared_ptr &model, - bool is_extract_body, - bool is_copy_constants) { +void RepeatPatternExtractor::set_recursive_extraction(bool _is_recursive_extraction) { + is_recursive_extraction = _is_recursive_extraction; +} + +std::vector +RepeatPatternExtractor::extract(const std::shared_ptr &model) { + std::vector extracted_patterns; + for (const auto& pattern : find_repeat_patterns(model)) { + for (const auto& pattern_structure : pattern) { + extracted_patterns.push_back({std::get<0>(pattern_structure), std::get<2>(pattern_structure), extractor_name}); + } + } + return extracted_patterns; +} + +std::vector> +RepeatPatternExtractor::get_repeat_pattern_borders(const std::shared_ptr &model) { + std::vector> extracted_patterns; + for (auto& pattern : find_repeat_patterns(model, true)) { + std::vector same_pattern_borders; + for (const auto& pattern_structure : pattern) { + std::set output_names; + for (const auto& result : std::get<0>(pattern_structure)->get_results()) { + output_names.insert(result->get_input_node_shared_ptr(0)->get_friendly_name()); + } + + RepeatPatternExtractor::InputVector in_vec; + RepeatPatternExtractor::OutputVector out_vec; + for (const auto& node : std::get<1>(pattern_structure)) { + if (output_names.count(node->get_friendly_name())) { + OutputVector node_outputs = node->outputs(); + out_vec.insert(out_vec.end(), node_outputs.begin(), node_outputs.end()); + } else { + for (const auto& input : node->inputs()) { + in_vec.push_back(input); + } + } + } + same_pattern_borders.push_back({in_vec, out_vec}); + } + extracted_patterns.push_back(same_pattern_borders); + } + return extracted_patterns; +} + +std::vector> +RepeatPatternExtractor::get_repeat_node_vectors(const std::shared_ptr &model) { + std::vector> extracted_patterns; + for (const auto& pattern : find_repeat_patterns(model)) { + std::vector same_pattern_nodes; + for (const auto& pattern_structure : pattern) { + same_pattern_nodes.push_back(std::get<1>(pattern_structure)); + } + extracted_patterns.push_back(same_pattern_nodes); + } + return extracted_patterns; +} + +void +RepeatPatternExtractor::update_extractor_cache( + std::list>& extracted_patterns, + const std::shared_ptr& pattern, + const ov::NodeVector& pattern_node_vector, + const std::map& pattern_in_info) { + for (auto& extracted_pattern : extracted_patterns) { + auto& pattern_structure = extracted_pattern.front(); + const auto& cached_pattern = std::get<0>(pattern_structure); + if (model_comparator->match(pattern, cached_pattern)) { + try { + const auto& cached_in_info = std::get<2>(pattern_structure); + align_input_info(pattern, cached_pattern, pattern_in_info, cached_in_info); + extracted_pattern.push_back({ pattern, pattern_node_vector, pattern_in_info }); + return; + } catch(std::exception) {} + } + } + extracted_patterns.push_back({{ pattern, pattern_node_vector, pattern_in_info }}); +} + +void +RepeatPatternExtractor::update_extractor_cache( + std::list>& extracted_patterns, + std::list>& secondary_extracted_patterns) { + auto extern_it = secondary_extracted_patterns.begin(); + while (!secondary_extracted_patterns.empty()) { + auto it = extern_it->rbegin(); + while (!extern_it->empty()) { + auto& pattern_structure = *it; + const auto& pattern = std::get<0>(pattern_structure); + const auto& pattern_node_vector = std::get<1>(pattern_structure); + const auto& pattern_in_info = std::get<2>(pattern_structure); + update_extractor_cache(extracted_patterns, pattern, pattern_node_vector, pattern_in_info); + extern_it->pop_back(); + it = extern_it->rbegin(); + } + secondary_extracted_patterns.pop_front(); + } +} + +std::list> +RepeatPatternExtractor::find_repeat_patterns(const std::shared_ptr &model, + bool is_save_borders_only) { + std::list> extracted_patterns; std::unordered_set checked_ops; - std::list to_cache; auto ordered_ops = model->get_ordered_ops(); auto op_cnt = ordered_ops.size(); @@ -31,9 +131,10 @@ RepeatPatternExtractor::extract(const std::shared_ptr &model, continue; } + // find the same nodes std::vector start_node_idx{idx}; for (size_t i = idx + 1; i < op_cnt; ++i) { - if (manager.match(op, ordered_ops[i])) { + if (model_comparator->match(op, ordered_ops[i])) { start_node_idx.push_back(i); } } @@ -57,9 +158,9 @@ RepeatPatternExtractor::extract(const std::shared_ptr &model, if (node_idx == start_node_idx[i] && ref_node_idx == start_node_idx[j]) { nodes[i].insert(node); nodes[j].insert(ref_node); - } else if (manager.match(node, ref_node)) { + } else if (model_comparator->match(node, ref_node)) { // check if we met the same node - if (manager.match(node, op)) { + if (model_comparator->match(node, op)) { break; } if (checked_ops.count(node->get_friendly_name()) || @@ -94,16 +195,26 @@ RepeatPatternExtractor::extract(const std::shared_ptr &model, for (size_t i = 0; i < start_node_idx.size(); ++i) { try { std::unordered_set tmp_checked_ops; - auto extracted_pattern = generate_model(nodes[i], tmp_checked_ops, extractor_name, is_copy_constants); - auto extracted_model = std::get<0>(extracted_pattern); - std::list secondary_patterns; - if (nodes[i].size() > 20) { - secondary_patterns = extract(std::get<0>(extracted_pattern), is_extract_body, is_copy_constants); - } - if (secondary_patterns.size() > 1) { - to_cache.insert(to_cache.end(), secondary_patterns.begin(), secondary_patterns.end()); + // model, in_info, extractor_name + ov::NodeVector nodes_vector(nodes[i].begin(), nodes[i].end()); + auto extracted_pattern = generate_model(nodes_vector, tmp_checked_ops, is_save_const, is_save_borders_only); + auto extracted_model = extracted_pattern.first; + if (is_recursive_extraction && nodes_vector.size() > 20) { + auto secondary_patterns = find_repeat_patterns(extracted_model, is_save_borders_only); + if (!secondary_patterns.empty()) { + tmp_checked_ops.clear(); + update_extractor_cache(extracted_patterns, secondary_patterns); + } else { + update_extractor_cache(extracted_patterns, + extracted_model, + nodes_vector, + extracted_pattern.second); + } } else { - to_cache.push_back(extracted_pattern); + update_extractor_cache(extracted_patterns, + extracted_model, + nodes_vector, + extracted_pattern.second); } nodes[i].clear(); checked_ops.insert(tmp_checked_ops.begin(), tmp_checked_ops.end()); @@ -117,23 +228,39 @@ RepeatPatternExtractor::extract(const std::shared_ptr &model, if (std::dynamic_pointer_cast(op)) { auto ti = ov::as_type_ptr(op); auto ti_body = ti->get_function(); - auto tmp_res = extract(ti_body); - to_cache.insert(to_cache.end(), tmp_res.begin(), tmp_res.end()); + auto secondary_patterns = find_repeat_patterns(ti_body, is_save_borders_only); + update_extractor_cache(extracted_patterns, secondary_patterns); } else if (std::dynamic_pointer_cast(op)) { auto loop = ov::as_type_ptr(op); auto loop_body = loop->get_function(); - auto tmp_res = extract(loop_body); - to_cache.insert(to_cache.end(), tmp_res.begin(), tmp_res.end()); + auto secondary_patterns = find_repeat_patterns(loop_body, is_save_borders_only); + update_extractor_cache(extracted_patterns, secondary_patterns); } else if (std::dynamic_pointer_cast(op)) { auto if_op = ov::as_type_ptr(op); std::vector> bodies; for (size_t i = 0; i < if_op->get_internal_subgraphs_size(); i++) { auto if_body = if_op->get_function(i); - auto tmp_res = extract(if_body); - to_cache.insert(to_cache.end(), tmp_res.begin(), tmp_res.end()); + auto secondary_patterns = find_repeat_patterns(if_body, is_save_borders_only); + update_extractor_cache(extracted_patterns, secondary_patterns); } } } } - return to_cache; + + // clean up patterns + { + auto it = extracted_patterns.begin(); + size_t elem_cnt = 0; + while (it != extracted_patterns.end()) { + if (it->size() > 1) { + ++it; + ++elem_cnt; + } else { + extracted_patterns.erase(it); + it = extracted_patterns.begin(); + std::advance(it, elem_cnt); + } + } + } + return extracted_patterns; } diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/subgraph/subgraph.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/subgraph/subgraph.cpp deleted file mode 100644 index 5b0bddc2e183e9..00000000000000 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/subgraph/subgraph.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include "matchers/subgraph/subgraph.hpp" - -using namespace ov::tools::subgraph_dumper; - -bool -SubgraphExtractor::match(const std::shared_ptr &model, - const std::shared_ptr &ref_model) const { - bool res = comparator.compare(model, ref_model).valid; - if (res) { - return res; - } - std::vector> ordered_ops = model->get_ordered_ops(), - ref_ordered_ops = ref_model->get_ordered_ops(); - if (ordered_ops.size() != ref_ordered_ops.size()) { - return false; - } - size_t matched_op_cnt = 0, total_op_cnt = ordered_ops.size(); - size_t matched_op_cnt_required = round(0.9 * total_op_cnt); - for (size_t i = 0; i < total_op_cnt; ++i) { - if (is_node_to_skip(ordered_ops[i]) && - is_node_to_skip(ref_ordered_ops[i]) || - m_manager.match(ordered_ops[i], ref_ordered_ops[i])) { - ++matched_op_cnt; - } - if (matched_op_cnt >= matched_op_cnt_required) { - return true; - } - } - return false; -} - -inline SubgraphExtractor::IsSubgraphTuple prepare_is_subgraph_result(bool is_subgraph, - const std::shared_ptr& graph, - const std::shared_ptr& subgraph, - const std::map& matched_ops) { - return is_subgraph ? - std::make_tuple(is_subgraph, graph, subgraph, matched_ops) : - std::make_tuple(is_subgraph, nullptr, nullptr, std::map()); -} - -SubgraphExtractor::IsSubgraphTuple -SubgraphExtractor::is_subgraph(const std::shared_ptr &model, - const std::shared_ptr &ref_model) const { - std::vector> ordered_ops = model->get_ordered_ops(), - ref_ordered_ops = ref_model->get_ordered_ops(); - bool is_model = ordered_ops.size() > ref_ordered_ops.size(); - ov::NodeVector graph_to_check_ops, subgraph_to_check_ops; - std::shared_ptr graph = nullptr, subgraph = nullptr; - if (is_model) { - graph_to_check_ops = ordered_ops; - subgraph_to_check_ops = ref_ordered_ops; - graph = model; - subgraph = ref_model; - } else { - graph_to_check_ops = ref_ordered_ops; - subgraph_to_check_ops = ordered_ops; - graph = ref_model; - subgraph = model; - } - std::map matched_op_names; - - auto graph_it = graph_to_check_ops.begin(), subgraph_it = subgraph_to_check_ops.begin(); - while (graph_it != graph_to_check_ops.end() && subgraph_it != subgraph_to_check_ops.end()) { - if (m_manager.match(*graph_it, *subgraph_it)) { - matched_op_names.insert({ (*graph_it)->get_friendly_name(), (*subgraph_it)->get_friendly_name()}); - ++subgraph_it; - } - ++graph_it; - } - return prepare_is_subgraph_result(subgraph_it == subgraph_to_check_ops.end(), graph, subgraph, matched_op_names); -} diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/utils/model.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/utils/model.cpp index 6717961ea1b837..b84a11b0b458c2 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/utils/model.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/utils/model.cpp @@ -70,6 +70,27 @@ find_models(const std::vector &dirs, const std::string& regexp) { return { models, { ModelCacheStatus::NOT_READ, not_read_model } }; } +bool is_dynamic_model(const std::shared_ptr& model) { + for (const auto& parameter : model->get_parameters()) { + if (is_dynamic_node(parameter)) { + return true; + } + } + for (const auto& result : model->get_results()) { + if (is_dynamic_node(result)) { + return true; + } + } + return false; +} + +std::string get_model_type(const std::shared_ptr& model) { + if (is_dynamic_model(model)) { + return "dynamic"; + } + return "static"; +} + std::map> cache_models( std::shared_ptr& cache, const std::vector& models, @@ -115,6 +136,78 @@ std::map> cache_models( return cache_status; } +std::map +get_input_info_by_model(const std::shared_ptr& model) { + std::map in_info; + for (const auto& node : model->get_ordered_ops()) { + InputInfo::Range ranges(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE); + bool is_const = false; + if (ov::op::util::is_constant(node)) { + std::shared_ptr constant = std::dynamic_pointer_cast(node); + auto const_ranges = get_const_ranges(constant, + constant->get_default_output().get_element_type()); + ranges = const_ranges; + } else if (!ov::op::util::is_parameter(node)) { + continue; + } + auto partial_shape = node->get_default_output().get_partial_shape(); + in_info.insert({node->get_friendly_name(), + InputInfo(partial_shape, ranges.min, ranges.max, is_const)}); + } + return in_info; +} + +std::map +align_input_info(const std::shared_ptr& model, + const std::shared_ptr& model_ref, + const std::map& in_info, + const std::map& in_info_ref, + const std::map &matched_op) { + bool is_update_required = !matched_op.empty(); + if (!is_update_required) { + for (const auto& ref_item : in_info_ref) { + if (!in_info.count(ref_item.first)) { + is_update_required = true; + break; + } else if (in_info.at(ref_item.first).is_const != ref_item.second.is_const) { + throw std::runtime_error("Impossible to update input info!!!"); + } + } + } + + std::map updated_input_info = in_info_ref; + if (is_update_required) { + // align matched model names + const auto& ref_model_ops = model_ref->get_ordered_ops(); + const auto& model_ops = model->get_ordered_ops(); + size_t ref_ordered_ops_size = ref_model_ops.size(); + size_t ordered_ops_size = model_ops.size(); + if (ref_ordered_ops_size != ordered_ops_size && matched_op.empty()) { + throw std::runtime_error("Matched models can not be compared according different op numbers!"); + } + for (size_t i = 0; i < ordered_ops_size; ++i) { + auto model_op_name = model_ops[i]->get_friendly_name(); + if (!in_info.count(model_op_name)) { + continue; + } + if (!matched_op.empty()) { + if (!matched_op.count(model_op_name)) { + continue; + } + } + auto model_ref_op_name = matched_op.empty() ? ref_model_ops[i]->get_friendly_name() : matched_op.at(model_op_name); + + const auto& in_info_item = in_info.at(model_op_name); + const auto& ref_in_info_item = in_info_ref.at(model_ref_op_name); + if (in_info_item.is_const != ref_in_info_item.is_const) { + throw std::runtime_error("Impossible to update input info!!!"); + } + updated_input_info[model_ref_op_name] = in_info_item; + } + } + return updated_input_info; +} + } // namespace subgraph_dumper } // namespace tools } // namespace ov \ No newline at end of file diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/utils/model_comparator.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/utils/model_comparator.cpp new file mode 100644 index 00000000000000..027dc61be8e4db --- /dev/null +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/utils/model_comparator.cpp @@ -0,0 +1,136 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "utils/model_comparator.hpp" +#include "utils/model.hpp" + +using namespace ov::tools::subgraph_dumper; + +std::shared_ptr ModelComparator::m_instance = nullptr; + +void ModelComparator::set_match_coefficient(float _match_coefficient) { + if (_match_coefficient < 0 || _match_coefficient > 1) { + throw std::runtime_error("[ ERROR ] Match coefficient should be from 0 to 1!"); + } + match_coefficient = _match_coefficient; +} + +void ModelComparator::set_shape_strict_match(bool in_is_shape_strict_match) { + m_manager.set_shape_strict_match(in_is_shape_strict_match); +} + +inline ModelComparator::IsSubgraphTuple +prepare_is_subgraph_result(bool is_subgraph, + const std::shared_ptr& subgraph, + const std::shared_ptr& graph, + const std::map& matched_ops) { + return is_subgraph ? + std::make_tuple(is_subgraph, subgraph, graph, matched_ops) : + std::make_tuple(is_subgraph, nullptr, nullptr, std::map()); +} + +ModelComparator::IsSubgraphTuple +ModelComparator::is_subgraph(const std::shared_ptr &model, + const std::shared_ptr &ref_model) const { + std::vector> ordered_ops = model->get_ordered_ops(), + ref_ordered_ops = ref_model->get_ordered_ops(); + bool is_model = ordered_ops.size() > ref_ordered_ops.size(); + ov::NodeVector graph_to_check_ops, subgraph_to_check_ops; + std::shared_ptr graph = nullptr, subgraph = nullptr; + if (is_model) { + graph_to_check_ops = ordered_ops; + subgraph_to_check_ops = ref_ordered_ops; + graph = model; + subgraph = ref_model; + } else { + graph_to_check_ops = ref_ordered_ops; + subgraph_to_check_ops = ordered_ops; + graph = ref_model; + subgraph = model; + } + std::map matched_op_names; + + auto graph_it = graph_to_check_ops.begin(), subgraph_it = subgraph_to_check_ops.begin(); + while (graph_it != graph_to_check_ops.end() && subgraph_it != subgraph_to_check_ops.end()) { + if (m_manager.match(*graph_it, *subgraph_it)) { + matched_op_names.insert({ (*subgraph_it)->get_friendly_name(), (*graph_it)->get_friendly_name()}); + ++subgraph_it; + } + ++graph_it; + } + return prepare_is_subgraph_result(subgraph_it == subgraph_to_check_ops.end(), subgraph, graph, matched_op_names); +} + +bool +ModelComparator::match(const std::shared_ptr &node, + const std::shared_ptr &ref_node) const { + return m_manager.match(node, ref_node); +} + +bool +ModelComparator::match(const std::shared_ptr &model, + const std::shared_ptr &ref_model) const { + std::vector> ordered_ops = model->get_ordered_ops(), + ref_ordered_ops = ref_model->get_ordered_ops(); + if (ordered_ops.size() != ref_ordered_ops.size()) { + return false; + } + size_t matched_op_cnt = 0, total_op_cnt = ordered_ops.size(); + size_t matched_op_cnt_required = round(match_coefficient * total_op_cnt); + for (size_t i = 0; i < total_op_cnt; ++i) { + if (m_manager.match(ordered_ops[i], ref_ordered_ops[i])) { + ++matched_op_cnt; + } + if (matched_op_cnt >= matched_op_cnt_required) { + return true; + } + } + return false; +} + +ModelComparator::ExtractedSubgraphTuple +ModelComparator::is_subgraph(const std::shared_ptr &model, + const std::shared_ptr &ref_model, + const std::map &in_info, + const std::map &in_info_ref) { + auto extractor_res = is_subgraph(model, ref_model); + if (std::get<0>(extractor_res)) { + std::map graph_in_info, subgraph_in_info; + std::shared_ptr subgraph = nullptr, graph = nullptr; + // if (model == subgraph && ref_model == graph) + if (std::get<1>(extractor_res) == model && std::get<2>(extractor_res) == ref_model) { + subgraph = model; + subgraph_in_info = in_info; + graph = ref_model; + graph_in_info = in_info_ref; + // else if (subgraph == ref_model && graph = model) + } else if (std::get<1>(extractor_res) == ref_model && std::get<2>(extractor_res) == model) { + subgraph = ref_model; + subgraph_in_info = in_info_ref; + graph = model; + graph_in_info = in_info; + } else { + throw std::runtime_error("Generated models are incompatible with original ones!"); + } + try { + subgraph_in_info = align_input_info(subgraph, graph, subgraph_in_info, graph_in_info); + return { true, subgraph, graph, subgraph_in_info, graph_in_info }; + } catch(std::exception) {} + } + return { false, nullptr, nullptr, {}, {} }; +} + +std::pair> +ModelComparator::match(const std::shared_ptr &model, + const std::shared_ptr &model_ref, + const std::map &in_info, + const std::map &in_info_ref) { + try { + if (match(model, model_ref)) { + auto new_input_info = align_input_info(model, model_ref, in_info, in_info_ref); + return {true, new_input_info}; + } + } catch (std::exception) {} + return {false, {}}; +} \ No newline at end of file diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/utils/node.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/utils/node.cpp index 9df7ea3dc178fb..5c371174b26ef4 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/utils/node.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/utils/node.cpp @@ -7,6 +7,73 @@ namespace ov { namespace tools { namespace subgraph_dumper { +InputInfo::Range get_const_ranges(const std::shared_ptr& const_node, + ov::element::Type elem_type) { + InputInfo::Range ranges(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE); + switch (elem_type) { + case ov::element::Type_t::boolean: { + ranges = get_const_ranges(const_node); + break; + } + case ov::element::Type_t::bf16: { + ranges = get_const_ranges(const_node); + break; + } + case ov::element::Type_t::f16: { + ranges = get_const_ranges(const_node); + break; + } + case ov::element::Type_t::f32: { + ranges = get_const_ranges(const_node); + break; + } + case ov::element::Type_t::f64: { + ranges = get_const_ranges(const_node); + break; + } + case ov::element::Type_t::i8: { + ranges = get_const_ranges(const_node); + break; + } + case ov::element::Type_t::i16: { + ranges = get_const_ranges(const_node); + break; + } + case ov::element::Type_t::i32: { + ranges = get_const_ranges(const_node); + break; + } + case ov::element::Type_t::i64: { + ranges = get_const_ranges(const_node); + break; + } + // TODO cast_vector doesn't support u1 now + // case ov::element::Type_t::u1: + // return get_const_ranges(const_node); + case ov::element::Type_t::u8: { + ranges = get_const_ranges(const_node); + break; + } + case ov::element::Type_t::u16: { + ranges = get_const_ranges(const_node); + break; + } + case ov::element::Type_t::u32: { + ranges = get_const_ranges(const_node); + break; + } + case ov::element::Type_t::u64: { + ranges = get_const_ranges(const_node); + break; + } + default: { + std::cout << "Can't get ranges.. Unsupported data type" << std::endl; + break; + } + } + return ranges; +} + std::map get_input_info_by_node(const std::shared_ptr& node) { std::map input_info; for (size_t port_id = 0; port_id < node->get_input_size(); ++port_id) { @@ -19,71 +86,12 @@ std::map get_input_info_by_node(const std::shared_ptr(input_node)) { if (ov::shape_size(input_node->get_output_shape(0)) == 0) continue; - auto const_node = - std::dynamic_pointer_cast(input_node); + auto const_node = ov::as_type_ptr(input_node); in_info.is_const = true; - switch (node->get_output_element_type(0)) { - case ov::element::Type_t::boolean: { - in_info.ranges = get_const_ranges(const_node); - break; - } - case ov::element::Type_t::bf16: { - in_info.ranges = get_const_ranges(const_node); - break; - } - case ov::element::Type_t::f16: { - in_info.ranges = get_const_ranges(const_node); - break; - } - case ov::element::Type_t::f32: { - in_info.ranges = get_const_ranges(const_node); - break; - } - case ov::element::Type_t::f64: { - in_info.ranges = get_const_ranges(const_node); - break; - } - case ov::element::Type_t::i8: { - in_info.ranges = get_const_ranges(const_node); - break; - } - case ov::element::Type_t::i16: { - in_info.ranges = get_const_ranges(const_node); - break; - } - case ov::element::Type_t::i32: { - in_info.ranges = get_const_ranges(const_node); - break; - } - case ov::element::Type_t::i64: { - in_info.ranges = get_const_ranges(const_node); - break; - } - // TODO cast_vector doesn't support u1 now - // case ov::element::Type_t::u1: - // return get_const_ranges(const_node); - case ov::element::Type_t::u8: { - in_info.ranges = get_const_ranges(const_node); - break; - } - case ov::element::Type_t::u16: { - in_info.ranges = get_const_ranges(const_node); - break; - } - case ov::element::Type_t::u32: { - in_info.ranges = get_const_ranges(const_node); - break; - } - case ov::element::Type_t::u64: { - in_info.ranges = get_const_ranges(const_node); - break; - } - default: { - std::cout << "Can't get ranges.. Unsupported data type" << std::endl; - break; - }} + in_info.ranges = get_const_ranges(const_node, + const_node->get_default_output().get_element_type()); } - input_info.insert({ input_name, in_info }); + input_info.insert({input_name, in_info}); } return input_info; } @@ -128,9 +136,10 @@ std::shared_ptr clone_node(std::shared_ptr node, std::shared_ptr cloned_node = nullptr; if (!has_parameters && !is_copy_const_node && !inputs.empty()) { cloned_node = clone_node(node, true, true, node_name); - // std::cout << "The operation: " + node->get_friendly_name() + " does not have parameters! Replace first input to parameter!" << std::endl; - auto param = - std::make_shared(cloned_node->get_input_element_type(0), cloned_node->get_input_partial_shape(0)); + // std::cout << "The operation: " + node->get_friendly_name() + " does not have parameters! Replace first input + // to parameter!" << std::endl; + auto param = std::make_shared(cloned_node->get_input_element_type(0), + cloned_node->get_input_partial_shape(0)); std::string param_name = node_name + "_0"; param->set_friendly_name(param_name); auto node_to_replace = cloned_node->get_input_node_shared_ptr(0); @@ -142,10 +151,11 @@ std::shared_ptr clone_node(std::shared_ptr node, return cloned_node; } -std::shared_ptr convert_const_to_param(const std::shared_ptr& op_to_replace) { +std::shared_ptr convert_const_to_param( + const std::shared_ptr& op_to_replace) { if (op_to_replace->get_byte_size() > 1024) { - auto param = std::make_shared( - op_to_replace->get_output_element_type(0), op_to_replace->get_output_partial_shape(0)); + auto param = std::make_shared(op_to_replace->get_output_element_type(0), + op_to_replace->get_output_partial_shape(0)); param->set_friendly_name(op_to_replace->get_friendly_name()); if (param != nullptr) { ov::replace_node(op_to_replace, param); diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/cache/cache.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/cache/cache.cpp index a0d46c733809d7..0450d05ab1c054 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/cache/cache.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/cache/cache.cpp @@ -93,4 +93,22 @@ TEST_F(ICacheUnitTest, serialize_model) { } } +TEST_F(ICacheUnitTest, is_model_large_to_read) { + this->mem_size = 0; + ASSERT_NO_THROW(this->is_model_large_to_read(test_model, test_model_path)); + ASSERT_TRUE(this->is_model_large_to_read(test_model, test_model_path)); + this->mem_size = 1 << 30; + ASSERT_NO_THROW(this->is_model_large_to_read(test_model, test_model_path)); + ASSERT_FALSE(this->is_model_large_to_read(test_model, test_model_path)); +} + +TEST_F(ICacheUnitTest, is_model_large_to_store_const) { + this->mem_size = 0; + ASSERT_NO_THROW(this->is_model_large_to_store_const(test_model)); + ASSERT_TRUE(this->is_model_large_to_store_const(test_model)); + this->mem_size = 1 << 30; + ASSERT_NO_THROW(this->is_model_large_to_store_const(test_model)); + ASSERT_FALSE(this->is_model_large_to_store_const(test_model)); +} + } // namespace \ No newline at end of file diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/cache/op_cache.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/cache/op_cache.cpp index 67a57298da3d95..0ec25023f3801c 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/cache/op_cache.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/cache/op_cache.cpp @@ -132,7 +132,7 @@ TEST_F(OpCacheUnitTest, update_cache_by_model) { ASSERT_EQ(meta.get_model_info().begin()->second.model_priority, 3); // check input_info ASSERT_EQ(meta.get_input_info().size(), 1); - ASSERT_EQ(meta.get_input_info().begin()->first, "Convert-1_0"); + ASSERT_EQ(meta.get_input_info().begin()->first, "Convert-0_0"); ASSERT_EQ(meta.get_input_info().begin()->second.ranges.max, DEFAULT_MAX_VALUE); ASSERT_EQ(meta.get_input_info().begin()->second.ranges.min, DEFAULT_MIN_VALUE); ASSERT_EQ(meta.get_input_info().begin()->second.is_const, false); @@ -149,7 +149,7 @@ TEST_F(OpCacheUnitTest, update_cache_by_model) { ASSERT_EQ(meta.get_model_info().begin()->second.model_priority, 1); // check input_info ASSERT_EQ(meta.get_input_info().size(), 1); - ASSERT_EQ(meta.get_input_info().begin()->first, "ShapeOf-1_0"); + ASSERT_EQ(meta.get_input_info().begin()->first, "ShapeOf-0_0"); ASSERT_EQ(meta.get_input_info().begin()->second.ranges.max, DEFAULT_MAX_VALUE); ASSERT_EQ(meta.get_input_info().begin()->second.ranges.min, DEFAULT_MIN_VALUE); ASSERT_EQ(meta.get_input_info().begin()->second.is_const, false); @@ -162,7 +162,7 @@ TEST_F(OpCacheUnitTest, serialize_op) { ASSERT_TRUE(this->serialize_op({convert_node, test_meta})); ASSERT_TRUE(ov::util::directory_exists(test_artifacts_dir)); auto serialized_model_path = ov::util::path_join({test_artifacts_dir, - "operation", "static", "Convert-1", "f16", "Convert-1_0.xml"}); + "operation", "static", "Convert-0", "f16", "Convert-0_0.xml"}); ASSERT_TRUE(ov::util::file_exists(serialized_model_path)); auto core = ov::Core(); auto serialized_model = core.read_model(serialized_model_path); @@ -171,7 +171,7 @@ TEST_F(OpCacheUnitTest, serialize_op) { } TEST_F(OpCacheUnitTest, get_rel_serilization_dir) { - auto ref_path = ov::util::path_join({"operation", "static", "Convert-1", "f16"}); + auto ref_path = ov::util::path_join({"operation", "static", "Convert-0", "f16"}); auto original_path = this->get_rel_serilization_dir(convert_node); ASSERT_EQ(ref_path, original_path); } diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/fused_names.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/fused_names.cpp index f83c34bbe9ce43..6a287a8e364c64 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/fused_names.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/fused_names.cpp @@ -8,6 +8,7 @@ #include "matchers/subgraph/fused_names.hpp" #include "utils/model.hpp" +#include "utils/model_comparator.hpp" #include "test_models/model_0.hpp" #include "test_models/model_1.hpp" @@ -32,7 +33,7 @@ class FusedNamesExtractorTest : public SubgraphsDumperBaseTest { auto it_model_2 = models_2.begin(); while (it_model_1 != models_1.end() || it_model_2 != models_2.end()) { SubgraphExtractor extractor; - ASSERT_TRUE(extractor.match(std::get<0>(*it_model_1), std::get<0>(*it_model_2))); + ASSERT_TRUE(ModelComparator::get()->match(std::get<0>(*it_model_1), std::get<0>(*it_model_2))); auto in_info_1 = std::get<1>(*it_model_1); auto in_info_2 = std::get<1>(*it_model_2); for (const auto& in_info : in_info_1) { diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/manager.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/manager.cpp index 76bbeb4769bc08..fe25e581e71608 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/manager.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/manager.cpp @@ -35,31 +35,10 @@ class ExtractorsManagerTest : public ExtractorsManager, test_model_0_0 = std::make_shared(ov::ResultVector{test_res}, ov::ParameterVector{test_parameter}); } - { - std::shared_ptr test_parameter = - std::make_shared(ov::element::f32, ov::Shape{2, 5}); - test_parameter->set_friendly_name("test_parameter_1"); - std::shared_ptr test_abs = - std::make_shared(test_parameter); - std::shared_ptr test_res = - std::make_shared(test_abs); - test_model_0_1 = std::make_shared(ov::ResultVector{test_res}, - ov::ParameterVector{test_parameter}); - } - { - std::shared_ptr test_parameter = - std::make_shared(ov::element::f32, ov::Shape{2, 5}); - std::shared_ptr test_abs = - std::make_shared(test_parameter); - std::shared_ptr test_res = - std::make_shared(test_abs); - test_model_1 = std::make_shared(ov::ResultVector{test_res}, - ov::ParameterVector{test_parameter}); - } } ExtractorsManager::ExtractorsMap test_map; - std::shared_ptr test_model_0_0, test_model_0_1, test_model_1; + std::shared_ptr test_model_0_0; }; TEST_F(ExtractorsManagerTest, constructor) { @@ -78,57 +57,9 @@ TEST_F(ExtractorsManagerTest, get_extractors) { ASSERT_EQ(this->m_extractors, this->get_extractors()); } -TEST_F(ExtractorsManagerTest, match) { - this->set_extractors(test_map); - ASSERT_NO_THROW(this->match(test_model_0_0, test_model_0_1)); - ASSERT_TRUE(this->match(test_model_0_0, test_model_0_1)); - ASSERT_NO_THROW(this->match(test_model_0_0, test_model_1)); - ASSERT_FALSE(this->match(test_model_0_0, test_model_1)); - ASSERT_NO_THROW(this->match(test_model_0_1, test_model_1)); - ASSERT_FALSE(this->match(test_model_0_1, test_model_1)); -} - -TEST_F(ExtractorsManagerTest, is_subgraph) { - this->set_extractors(test_map); - ASSERT_NO_THROW(this->is_subgraph(test_model_0_0, test_model_0_1)); - auto is_subgraph = this->is_subgraph(test_model_0_0, test_model_0_1); - ASSERT_TRUE(std::get<0>(is_subgraph)); - ASSERT_NO_THROW(this->is_subgraph(test_model_0_0, test_model_1)); - ASSERT_FALSE(std::get<0>(this->is_subgraph(test_model_0_0, test_model_1))); - ASSERT_NO_THROW(this->is_subgraph(test_model_0_1, test_model_1)); - ASSERT_FALSE(std::get<0>(this->is_subgraph(test_model_0_1, test_model_1))); -} - -TEST_F(ExtractorsManagerTest, match_with_in_info) { - this->set_extractors(test_map); - std::map test_in_info({{"test_parameter_0", InputInfo()}}), test_in_info_1({{"test_parameter_1", InputInfo({}, 1, 2, true)}}); - ASSERT_NO_THROW(this->match(test_model_0_0, test_model_0_1, test_in_info, test_in_info)); - ASSERT_TRUE(this->match(test_model_0_0, test_model_0_1, test_in_info, test_in_info)); - ASSERT_NO_THROW(this->match(test_model_0_0, test_model_0_1, test_in_info, test_in_info_1)); - ASSERT_FALSE(this->match(test_model_0_0, test_model_0_1, test_in_info, test_in_info_1)); - ASSERT_NO_THROW(this->match(test_model_0_1, test_model_1, test_in_info, test_in_info)); - ASSERT_FALSE(this->match(test_model_0_1, test_model_1, test_in_info, test_in_info)); -} - TEST_F(ExtractorsManagerTest, extract) { this->set_extractors(test_map); ASSERT_NO_THROW(this->extract(test_model_0_0)); } -TEST_F(ExtractorsManagerTest, align_input_info) { - std::map test_in_info({{"test_parameter_0", InputInfo()}}), test_in_info_ref({{"test_parameter_1", InputInfo()}}); - ASSERT_NE(test_in_info, test_in_info_ref); - ASSERT_NO_THROW(this->align_input_info(test_model_0_0, test_model_0_1, test_in_info, test_in_info_ref)); - auto c = this->align_input_info(test_model_0_0, test_model_0_1, test_in_info, test_in_info_ref); - ASSERT_EQ(c, test_in_info_ref); -} - -TEST_F(ExtractorsManagerTest, align_input_info_for_subgraphs) { - std::map test_in_info({{"test_parameter_0", InputInfo()}}), test_in_info_ref({{"test_parameter_1", InputInfo()}}); - ASSERT_NE(test_in_info, test_in_info_ref); - ASSERT_NO_THROW(this->align_input_info(test_model_0_0, test_model_0_1, test_in_info, test_in_info_ref, {{"test_parameter_0", "test_parameter_1"}})); - auto c = this->align_input_info(test_model_0_0, test_model_0_1, test_in_info, test_in_info_ref); - ASSERT_EQ(c, test_in_info_ref); -} - } // namespace diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/repeat_pattern.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/repeat_pattern.cpp index 7bb49decaeaab7..e583bca1eef155 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/repeat_pattern.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/repeat_pattern.cpp @@ -6,6 +6,7 @@ #include "matchers/subgraph/repeat_pattern.hpp" #include "utils/model.hpp" +#include "utils/model_comparator.hpp" #include "base_test.hpp" #include "test_models/model_0.hpp" @@ -22,13 +23,13 @@ class RepeatPatternExtractorTest : public SubgraphsDumperBaseTest { protected: RepeatPatternExtractor extractor; - bool is_match(const std::list& models, + bool is_match(const std::vector& models, const std::vector>& ref_models) { size_t match_numbers = 0; for (const auto& model : models) { bool is_match = false; for (const auto& ref_model : ref_models) { - if (extractor.match(std::get<0>(model), ref_model)) { + if (ModelComparator::get()->match(std::get<0>(model), ref_model)) { is_match = true; ++match_numbers; break; @@ -40,6 +41,28 @@ class RepeatPatternExtractorTest : public SubgraphsDumperBaseTest { } return match_numbers == models.size(); } + + void sort_node_vec(std::vector>& pattern_vec) { + for (auto& pattern : pattern_vec) { + for (auto& node_vec : pattern) { + std::sort(node_vec.begin(), node_vec.end()); + } + std::sort(pattern.begin(), pattern.end()); + } + std::sort(pattern_vec.begin(), pattern_vec.end()); + } + + // not allowed to sort inputs/outputs according there are not copy constructor + // void sort_borders(std::vector>& pattern_vec) { + // for (auto& pattern : pattern_vec) { + // for (auto& node_vec : pattern) { + // std::sort(node_vec.first.begin(), node_vec.first.end()); + // std::sort(node_vec.second.begin(), node_vec.second.end()); + // } + // std::sort(pattern.begin(), pattern.end()); + // } + // std::sort(pattern_vec.begin(), pattern_vec.end()); + // } }; TEST_F(RepeatPatternExtractorTest, extract_0) { @@ -63,4 +86,59 @@ TEST_F(RepeatPatternExtractorTest, extract_2) { ASSERT_TRUE(is_match(models, ref)); } +TEST_F(RepeatPatternExtractorTest, get_repeat_node_vectors_model_0) { + auto test_model = Model_0(); + auto node_vector = extractor.get_repeat_node_vectors(test_model.get()); + auto ref = test_model.get_ref_node_vector(); + sort_node_vec(node_vector); + sort_node_vec(ref); + ASSERT_EQ(node_vector, ref); +} + +TEST_F(RepeatPatternExtractorTest, get_repeat_node_vectors_model_1) { + auto test_model = Model_1(); + auto node_vector = extractor.get_repeat_node_vectors(test_model.get()); + auto ref = test_model.get_ref_node_vector(); + sort_node_vec(node_vector); + sort_node_vec(ref); + ASSERT_EQ(node_vector, ref); +} + +TEST_F(RepeatPatternExtractorTest, get_repeat_node_vectors_model_2) { + auto test_model = Model_2(); + auto node_vector = extractor.get_repeat_node_vectors(test_model.get()); + auto ref = test_model.get_ref_node_vector(); + sort_node_vec(node_vector); + sort_node_vec(ref); + ASSERT_EQ(node_vector, ref); +} + +TEST_F(RepeatPatternExtractorTest, get_repeat_pattern_borders_model_0) { + auto test_model = Model_0(); + auto extracted_borders = extractor.get_repeat_pattern_borders(test_model.get()); + auto ref_borders = test_model.get_ref_node_borders(); + // sort_borders(extracted_borders); + // sort_borders(ref_borders); + ASSERT_EQ(extracted_borders, ref_borders); +} + +TEST_F(RepeatPatternExtractorTest, get_repeat_pattern_borders_model_1) { + auto test_model = Model_1(); + auto extracted_borders = extractor.get_repeat_pattern_borders(test_model.get()); + auto ref_borders = test_model.get_ref_node_borders(); + // sort_borders(extracted_borders); + // sort_borders(ref_borders); + ASSERT_EQ(extracted_borders, ref_borders); +} + +TEST_F(RepeatPatternExtractorTest, get_repeat_pattern_borders_model_2) { + auto test_model = Model_2(); + auto extracted_borders = extractor.get_repeat_pattern_borders(test_model.get()); + auto ref_borders = test_model.get_ref_node_borders(); + // sort_borders(extracted_borders); + // sort_borders(ref_borders); + ASSERT_EQ(extracted_borders, ref_borders); +} + + } // namespace diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/subgraph.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/subgraph.cpp index 7de5706b9e9a06..8819456bdcf2e5 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/subgraph.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/subgraph.cpp @@ -1,209 +1,209 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// +// // Copyright (C) 2018-2023 Intel Corporation +// // SPDX-License-Identifier: Apache-2.0 +// // -#include "matchers/subgraph/subgraph.hpp" -#include "base_test.hpp" +// #include "matchers/subgraph/subgraph.hpp" +// #include "base_test.hpp" -#include "openvino/op/abs.hpp" -#include "openvino/op/relu.hpp" -#include "openvino/op/parameter.hpp" -#include "openvino/op/result.hpp" +// #include "openvino/op/abs.hpp" +// #include "openvino/op/relu.hpp" +// #include "openvino/op/parameter.hpp" +// #include "openvino/op/result.hpp" -namespace { +// namespace { -using namespace ov::tools::subgraph_dumper; +// using namespace ov::tools::subgraph_dumper; -// ======================= ExtractorsManagerTest Unit tests ======================= -class SubgraphExtractorTest : public SubgraphExtractor, - public SubgraphsDumperBaseTest { -protected: - void SetUp() override { - SubgraphsDumperBaseTest::SetUp(); - { - std::shared_ptr test_parameter = - std::make_shared(ov::element::f32, ov::Shape{1, 2}); - std::shared_ptr test_abs = - std::make_shared(test_parameter); - std::shared_ptr test_res = - std::make_shared(test_abs); - test_model_0_0 = std::make_shared(ov::ResultVector{test_res}, - ov::ParameterVector{test_parameter}); - } - { - std::shared_ptr test_parameter = - std::make_shared(ov::element::f32, ov::Shape{2, 5}); - std::shared_ptr test_abs = - std::make_shared(test_parameter); - std::shared_ptr test_res = - std::make_shared(test_abs); - test_model_0_1 = std::make_shared(ov::ResultVector{test_res}, - ov::ParameterVector{test_parameter}); - } - { - std::shared_ptr test_parameter = - std::make_shared(ov::element::f32, ov::Shape{2, 5}); - std::shared_ptr test_abs = - std::make_shared(test_parameter); - std::shared_ptr test_res = - std::make_shared(test_abs); - test_model_1 = std::make_shared(ov::ResultVector{test_res}, - ov::ParameterVector{test_parameter}); - } - } +// // ======================= ExtractorsManagerTest Unit tests ======================= +// class SubgraphExtractorTest : public SubgraphExtractor, +// public SubgraphsDumperBaseTest { +// protected: +// void SetUp() override { +// SubgraphsDumperBaseTest::SetUp(); +// { +// std::shared_ptr test_parameter = +// std::make_shared(ov::element::f32, ov::Shape{1, 2}); +// std::shared_ptr test_abs = +// std::make_shared(test_parameter); +// std::shared_ptr test_res = +// std::make_shared(test_abs); +// test_model_0_0 = std::make_shared(ov::ResultVector{test_res}, +// ov::ParameterVector{test_parameter}); +// } +// { +// std::shared_ptr test_parameter = +// std::make_shared(ov::element::f32, ov::Shape{2, 5}); +// std::shared_ptr test_abs = +// std::make_shared(test_parameter); +// std::shared_ptr test_res = +// std::make_shared(test_abs); +// test_model_0_1 = std::make_shared(ov::ResultVector{test_res}, +// ov::ParameterVector{test_parameter}); +// } +// { +// std::shared_ptr test_parameter = +// std::make_shared(ov::element::f32, ov::Shape{2, 5}); +// std::shared_ptr test_abs = +// std::make_shared(test_parameter); +// std::shared_ptr test_res = +// std::make_shared(test_abs); +// test_model_1 = std::make_shared(ov::ResultVector{test_res}, +// ov::ParameterVector{test_parameter}); +// } +// } - std::shared_ptr test_model_0_0, test_model_0_1, test_model_1; -}; +// std::shared_ptr test_model_0_0, test_model_0_1, test_model_1; +// }; -TEST_F(SubgraphExtractorTest, match) { - ASSERT_NO_THROW(this->match(test_model_0_0, test_model_0_1)); - ASSERT_TRUE(this->match(test_model_0_0, test_model_0_1)); - ASSERT_NO_THROW(this->match(test_model_0_0, test_model_1)); - ASSERT_FALSE(this->match(test_model_0_0, test_model_1)); - ASSERT_NO_THROW(this->match(test_model_0_1, test_model_1)); - ASSERT_FALSE(this->match(test_model_0_1, test_model_1)); -} +// TEST_F(SubgraphExtractorTest, match) { +// ASSERT_NO_THROW(this->match(test_model_0_0, test_model_0_1)); +// ASSERT_TRUE(this->match(test_model_0_0, test_model_0_1)); +// ASSERT_NO_THROW(this->match(test_model_0_0, test_model_1)); +// ASSERT_FALSE(this->match(test_model_0_0, test_model_1)); +// ASSERT_NO_THROW(this->match(test_model_0_1, test_model_1)); +// ASSERT_FALSE(this->match(test_model_0_1, test_model_1)); +// } -TEST_F(SubgraphExtractorTest, match_90_percent) { - { - std::shared_ptr test_parameter = - std::make_shared(ov::element::f32, ov::Shape{1, 2}); - std::shared_ptr test_abs_0 = - std::make_shared(test_parameter); - std::shared_ptr test_abs_1 = - std::make_shared(test_abs_0); - std::shared_ptr test_abs_2 = - std::make_shared(test_abs_1); - std::shared_ptr test_abs_3 = - std::make_shared(test_abs_2); - std::shared_ptr test_abs_4 = - std::make_shared(test_abs_3); - std::shared_ptr test_abs_5 = - std::make_shared(test_abs_4); - std::shared_ptr test_abs_6 = - std::make_shared(test_abs_5); - std::shared_ptr test_abs_7 = - std::make_shared(test_abs_6); - std::shared_ptr test_abs_8 = - std::make_shared(test_abs_7); - std::shared_ptr test_abs_9 = - std::make_shared(test_abs_8); - std::shared_ptr test_abs_10 = - std::make_shared(test_abs_9); - std::shared_ptr test_res = - std::make_shared(test_abs_10); - test_model_0_0 = std::make_shared(ov::ResultVector{test_res}, - ov::ParameterVector{test_parameter}); - } - { - std::shared_ptr test_parameter = - std::make_shared(ov::element::f32, ov::Shape{1, 2}); - std::shared_ptr test_abs_0 = - std::make_shared(test_parameter); - std::shared_ptr test_abs_1 = - std::make_shared(test_abs_0); - std::shared_ptr test_abs_2 = - std::make_shared(test_abs_1); - std::shared_ptr test_abs_3 = - std::make_shared(test_abs_2); - std::shared_ptr test_abs_4 = - std::make_shared(test_abs_3); - std::shared_ptr test_abs_5 = - std::make_shared(test_abs_4); - std::shared_ptr test_abs_6 = - std::make_shared(test_abs_5); - std::shared_ptr test_abs_7 = - std::make_shared(test_abs_6); - std::shared_ptr test_abs_8 = - std::make_shared(test_abs_7); - std::shared_ptr test_abs_9 = - std::make_shared(test_abs_8); - std::shared_ptr test_abs_10 = - std::make_shared(test_abs_9); - std::shared_ptr test_res = - std::make_shared(test_abs_10); - test_model_0_1 = std::make_shared(ov::ResultVector{test_res}, - ov::ParameterVector{test_parameter}); - } - { - std::shared_ptr test_parameter = - std::make_shared(ov::element::f32, ov::Shape{1, 2}); - std::shared_ptr test_abs_0 = - std::make_shared(test_parameter); - std::shared_ptr test_abs_1 = - std::make_shared(test_abs_0); - std::shared_ptr test_abs_2 = - std::make_shared(test_abs_1); - std::shared_ptr test_abs_3 = - std::make_shared(test_abs_2); - std::shared_ptr test_abs_4 = - std::make_shared(test_abs_3); - std::shared_ptr test_abs_5 = - std::make_shared(test_abs_4); - std::shared_ptr test_abs_6 = - std::make_shared(test_abs_5); - std::shared_ptr test_abs_7 = - std::make_shared(test_abs_6); - std::shared_ptr test_abs_8 = - std::make_shared(test_abs_7); - std::shared_ptr test_abs_9 = - std::make_shared(test_abs_8); - std::shared_ptr test_abs_10 = - std::make_shared(test_abs_9); - std::shared_ptr test_res = - std::make_shared(test_abs_10); - test_model_1 = std::make_shared(ov::ResultVector{test_res}, - ov::ParameterVector{test_parameter}); - } - ASSERT_NO_THROW(this->match(test_model_0_0, test_model_0_1)); - ASSERT_TRUE(this->match(test_model_0_0, test_model_0_1)); - ASSERT_NO_THROW(this->match(test_model_0_0, test_model_1)); - ASSERT_FALSE(this->match(test_model_0_0, test_model_1)); - ASSERT_NO_THROW(this->match(test_model_0_1, test_model_1)); - ASSERT_FALSE(this->match(test_model_0_1, test_model_1)); -} +// TEST_F(SubgraphExtractorTest, match_90_percent) { +// { +// std::shared_ptr test_parameter = +// std::make_shared(ov::element::f32, ov::Shape{1, 2}); +// std::shared_ptr test_abs_0 = +// std::make_shared(test_parameter); +// std::shared_ptr test_abs_1 = +// std::make_shared(test_abs_0); +// std::shared_ptr test_abs_2 = +// std::make_shared(test_abs_1); +// std::shared_ptr test_abs_3 = +// std::make_shared(test_abs_2); +// std::shared_ptr test_abs_4 = +// std::make_shared(test_abs_3); +// std::shared_ptr test_abs_5 = +// std::make_shared(test_abs_4); +// std::shared_ptr test_abs_6 = +// std::make_shared(test_abs_5); +// std::shared_ptr test_abs_7 = +// std::make_shared(test_abs_6); +// std::shared_ptr test_abs_8 = +// std::make_shared(test_abs_7); +// std::shared_ptr test_abs_9 = +// std::make_shared(test_abs_8); +// std::shared_ptr test_abs_10 = +// std::make_shared(test_abs_9); +// std::shared_ptr test_res = +// std::make_shared(test_abs_10); +// test_model_0_0 = std::make_shared(ov::ResultVector{test_res}, +// ov::ParameterVector{test_parameter}); +// } +// { +// std::shared_ptr test_parameter = +// std::make_shared(ov::element::f32, ov::Shape{1, 2}); +// std::shared_ptr test_abs_0 = +// std::make_shared(test_parameter); +// std::shared_ptr test_abs_1 = +// std::make_shared(test_abs_0); +// std::shared_ptr test_abs_2 = +// std::make_shared(test_abs_1); +// std::shared_ptr test_abs_3 = +// std::make_shared(test_abs_2); +// std::shared_ptr test_abs_4 = +// std::make_shared(test_abs_3); +// std::shared_ptr test_abs_5 = +// std::make_shared(test_abs_4); +// std::shared_ptr test_abs_6 = +// std::make_shared(test_abs_5); +// std::shared_ptr test_abs_7 = +// std::make_shared(test_abs_6); +// std::shared_ptr test_abs_8 = +// std::make_shared(test_abs_7); +// std::shared_ptr test_abs_9 = +// std::make_shared(test_abs_8); +// std::shared_ptr test_abs_10 = +// std::make_shared(test_abs_9); +// std::shared_ptr test_res = +// std::make_shared(test_abs_10); +// test_model_0_1 = std::make_shared(ov::ResultVector{test_res}, +// ov::ParameterVector{test_parameter}); +// } +// { +// std::shared_ptr test_parameter = +// std::make_shared(ov::element::f32, ov::Shape{1, 2}); +// std::shared_ptr test_abs_0 = +// std::make_shared(test_parameter); +// std::shared_ptr test_abs_1 = +// std::make_shared(test_abs_0); +// std::shared_ptr test_abs_2 = +// std::make_shared(test_abs_1); +// std::shared_ptr test_abs_3 = +// std::make_shared(test_abs_2); +// std::shared_ptr test_abs_4 = +// std::make_shared(test_abs_3); +// std::shared_ptr test_abs_5 = +// std::make_shared(test_abs_4); +// std::shared_ptr test_abs_6 = +// std::make_shared(test_abs_5); +// std::shared_ptr test_abs_7 = +// std::make_shared(test_abs_6); +// std::shared_ptr test_abs_8 = +// std::make_shared(test_abs_7); +// std::shared_ptr test_abs_9 = +// std::make_shared(test_abs_8); +// std::shared_ptr test_abs_10 = +// std::make_shared(test_abs_9); +// std::shared_ptr test_res = +// std::make_shared(test_abs_10); +// test_model_1 = std::make_shared(ov::ResultVector{test_res}, +// ov::ParameterVector{test_parameter}); +// } +// ASSERT_NO_THROW(this->match(test_model_0_0, test_model_0_1)); +// ASSERT_TRUE(this->match(test_model_0_0, test_model_0_1)); +// ASSERT_NO_THROW(this->match(test_model_0_0, test_model_1)); +// ASSERT_FALSE(this->match(test_model_0_0, test_model_1)); +// ASSERT_NO_THROW(this->match(test_model_0_1, test_model_1)); +// ASSERT_FALSE(this->match(test_model_0_1, test_model_1)); +// } -TEST_F(SubgraphExtractorTest, extract) { - ASSERT_NO_THROW(this->extract(test_model_0_0)); - ASSERT_NO_THROW(this->extract(test_model_0_1)); - ASSERT_NO_THROW(this->extract(test_model_1)); -} +// TEST_F(SubgraphExtractorTest, extract) { +// ASSERT_NO_THROW(this->extract(test_model_0_0)); +// ASSERT_NO_THROW(this->extract(test_model_0_1)); +// ASSERT_NO_THROW(this->extract(test_model_1)); +// } -TEST_F(SubgraphExtractorTest, is_subgraph) { - auto is_subgraph = this->is_subgraph(test_model_0_0, test_model_0_0); - ASSERT_NO_THROW(this->is_subgraph(test_model_0_0, test_model_0_0)); - ASSERT_TRUE(std::get<0>(is_subgraph)); - ASSERT_NO_THROW(this->is_subgraph(test_model_0_0, test_model_1)); - is_subgraph = this->is_subgraph(test_model_0_0, test_model_1); - ASSERT_FALSE(std::get<0>(is_subgraph)); - ASSERT_NO_THROW(this->is_subgraph(test_model_0_1, test_model_1)); - is_subgraph = this->is_subgraph(test_model_0_1, test_model_1); - ASSERT_FALSE(std::get<0>(is_subgraph)); - { - std::shared_ptr test_parameter = - std::make_shared(ov::element::f32, ov::Shape{1, 2}); - std::shared_ptr test_abs_0 = - std::make_shared(test_parameter); - std::shared_ptr test_abs_1 = - std::make_shared(test_abs_0); - std::shared_ptr test_res = - std::make_shared(test_abs_1); - auto big_model_0 = std::make_shared(ov::ResultVector{test_res}, - ov::ParameterVector{test_parameter}); - is_subgraph = this->is_subgraph(test_model_0_0, big_model_0); - ASSERT_NO_THROW(this->is_subgraph(test_model_0_0, big_model_0)); - ASSERT_TRUE(std::get<0>(is_subgraph)); - ASSERT_EQ(std::get<1>(is_subgraph), big_model_0); - ASSERT_EQ(std::get<2>(is_subgraph), test_model_0_0); +// TEST_F(SubgraphExtractorTest, is_subgraph) { +// auto is_subgraph = this->is_subgraph(test_model_0_0, test_model_0_0); +// ASSERT_NO_THROW(this->is_subgraph(test_model_0_0, test_model_0_0)); +// ASSERT_TRUE(std::get<0>(is_subgraph)); +// ASSERT_NO_THROW(this->is_subgraph(test_model_0_0, test_model_1)); +// is_subgraph = this->is_subgraph(test_model_0_0, test_model_1); +// ASSERT_FALSE(std::get<0>(is_subgraph)); +// ASSERT_NO_THROW(this->is_subgraph(test_model_0_1, test_model_1)); +// is_subgraph = this->is_subgraph(test_model_0_1, test_model_1); +// ASSERT_FALSE(std::get<0>(is_subgraph)); +// { +// std::shared_ptr test_parameter = +// std::make_shared(ov::element::f32, ov::Shape{1, 2}); +// std::shared_ptr test_abs_0 = +// std::make_shared(test_parameter); +// std::shared_ptr test_abs_1 = +// std::make_shared(test_abs_0); +// std::shared_ptr test_res = +// std::make_shared(test_abs_1); +// auto big_model_0 = std::make_shared(ov::ResultVector{test_res}, +// ov::ParameterVector{test_parameter}); +// is_subgraph = this->is_subgraph(test_model_0_0, big_model_0); +// ASSERT_NO_THROW(this->is_subgraph(test_model_0_0, big_model_0)); +// ASSERT_TRUE(std::get<0>(is_subgraph)); +// ASSERT_EQ(std::get<1>(is_subgraph), big_model_0); +// ASSERT_EQ(std::get<2>(is_subgraph), test_model_0_0); - is_subgraph = this->is_subgraph(test_model_0_1, big_model_0); - ASSERT_NO_THROW(this->is_subgraph(test_model_0_1, big_model_0)); - ASSERT_TRUE(std::get<0>(is_subgraph)); - ASSERT_EQ(std::get<1>(is_subgraph), big_model_0); - ASSERT_EQ(std::get<2>(is_subgraph), test_model_0_1); - ASSERT_NO_THROW(this->is_subgraph(test_model_1, big_model_0)); - ASSERT_FALSE(std::get<0>(this->is_subgraph(test_model_1, big_model_0))); - } -} +// is_subgraph = this->is_subgraph(test_model_0_1, big_model_0); +// ASSERT_NO_THROW(this->is_subgraph(test_model_0_1, big_model_0)); +// ASSERT_TRUE(std::get<0>(is_subgraph)); +// ASSERT_EQ(std::get<1>(is_subgraph), big_model_0); +// ASSERT_EQ(std::get<2>(is_subgraph), test_model_0_1); +// ASSERT_NO_THROW(this->is_subgraph(test_model_1, big_model_0)); +// ASSERT_FALSE(std::get<0>(this->is_subgraph(test_model_1, big_model_0))); +// } +// } -} // namespace +// } // namespace diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/test_models/model_0.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/test_models/model_0.hpp index 43f49506ee40c8..4a37a80bbfdb04 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/test_models/model_0.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/test_models/model_0.hpp @@ -11,8 +11,12 @@ #include "openvino/op/relu.hpp" #include "openvino/op/parameter.hpp" #include "openvino/op/result.hpp" +#include "matchers/subgraph/repeat_pattern.hpp" class Model_0 { +private: + using PatternBorders = ov::tools::subgraph_dumper::RepeatPatternExtractor::PatternBorders; + public: Model_0() { // param param @@ -48,6 +52,13 @@ class Model_0 { std::make_shared(test_add_0); model = std::make_shared(ov::ResultVector{test_res}, ov::ParameterVector{test_parameter_0, test_parameter_1}); + ref_nodes = {{{test_abs_0, test_relu_0}, {test_abs_1, test_relu_1}}}; + { + PatternBorders ref_pattern_0 = {test_abs_0->inputs(), test_relu_0->outputs()}, + ref_pattern_1 = {test_abs_1->inputs(), test_relu_1->outputs()}; + std::vector> ref_res = {{ref_pattern_0, ref_pattern_1}}; + ref_borders = std::move(ref_res); + } } std::shared_ptr get() { @@ -72,6 +83,14 @@ class Model_0 { return ref; } + std::vector> + get_ref_node_vector() { return ref_nodes; } + + std::vector> + get_ref_node_borders() { return ref_borders; } + protected: std::shared_ptr model; + std::vector> ref_nodes; + std::vector> ref_borders; }; diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/test_models/model_1.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/test_models/model_1.hpp index 5893fb949f774a..96a478abc09c56 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/test_models/model_1.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/test_models/model_1.hpp @@ -12,8 +12,12 @@ #include "openvino/op/parameter.hpp" #include "openvino/op/result.hpp" #include "openvino/op/subtract.hpp" +#include "matchers/subgraph/repeat_pattern.hpp" class Model_1 { +private: + using PatternBorders = ov::tools::subgraph_dumper::RepeatPatternExtractor::PatternBorders; + public: Model_1() { // param param param param @@ -119,6 +123,22 @@ class Model_1 { ov::ParameterVector{test_parameter_0, test_parameter_1, test_parameter_0_0, test_parameter_0_1, test_parameter_1_0, test_parameter_1_1}); + + ref_nodes = {{{test_abs_0, test_relu_0}, {test_abs_0_0, test_relu_0_0}}, + {{test_abs_1, test_clamp_1}, {test_abs_0_1, test_clamp_0_1}}, + {{test_multiply_0_1, test_relu_0_1}, {test_multiply_1_1, test_relu_1_1}}}; + { + PatternBorders ref_pattern_0 = {test_abs_0->inputs(), test_relu_0->outputs()}, + ref_pattern_0_0 = {test_abs_0_0->inputs(), test_relu_0_0->outputs()}, + ref_pattern_1 = {test_abs_1->inputs(), test_clamp_1->outputs()}, + ref_pattern_0_1_0 = {test_abs_0_1->inputs(), test_clamp_0_1->outputs()}, + test_pattern_0_1_1 = {test_multiply_0_1->inputs(), test_relu_0_1->outputs()}, + test_pattern_1_1 = {test_multiply_1_1->inputs(), test_relu_1_1->outputs()}; + std::vector> ref_res = {{ref_pattern_0, ref_pattern_0_0}, + {ref_pattern_1, ref_pattern_0_1_0}, + {test_pattern_0_1_1, test_pattern_1_1}}; + ref_borders = std::move(ref_res); + } } std::shared_ptr get() { @@ -166,10 +186,19 @@ class Model_1 { std::make_shared(test_relu_1); auto ref_model = std::make_shared(ov::ResultVector{res}, ov::ParameterVector{test_parameter_1_0, test_parameter_1_1}); + ref.push_back(ref_model); } return ref; } + std::vector> + get_ref_node_vector() { return ref_nodes; } + + std::vector> + get_ref_node_borders() { return ref_borders; } + protected: std::shared_ptr model; + std::vector> ref_nodes; + std::vector> ref_borders; }; diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/test_models/model_2.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/test_models/model_2.hpp index fd7a24cbe49e3d..94f11ee192b06f 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/test_models/model_2.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/test_models/model_2.hpp @@ -13,6 +13,9 @@ #include "openvino/op/result.hpp" class Model_2 { +private: + using PatternBorders = ov::tools::subgraph_dumper::RepeatPatternExtractor::PatternBorders; + public: Model_2() { // param @@ -55,9 +58,17 @@ class Model_2 { } std::vector> get_repeat_pattern_ref() { - return {}; + return std::vector>(); } + std::vector> + get_ref_node_vector() { return ref_nodes; } + + std::vector> + get_ref_node_borders() { return ref_borders; } + protected: std::shared_ptr model; + std::vector> ref_nodes; + std::vector> ref_borders; }; diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/utils/model.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/utils/model.cpp index a5bb560f486e1e..afb4f490b1d0dc 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/utils/model.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/utils/model.cpp @@ -4,6 +4,7 @@ #include "openvino/op/util/op_types.hpp" #include "utils/model.hpp" +#include "utils/model_comparator.hpp" #include "matchers/subgraph/subgraph.hpp" #include "test_models/model_0.hpp" #include "test_models/model_1.hpp" @@ -16,11 +17,11 @@ using namespace ov::tools::subgraph_dumper; using ModelUtilsTest = SubgraphsDumperBaseTest; -std::set> +ov::NodeVector get_functional_ops(const std::shared_ptr& model) { - std::set> nodes; + std::vector> nodes; for (const auto& op : model->get_ordered_ops()) { - nodes.insert(op); + nodes.push_back(op); } return nodes; } @@ -31,12 +32,11 @@ TEST_F(ModelUtilsTest, generate_0) { { std::unordered_set checked_ops; auto func_ops = get_functional_ops(test_model); - auto model_with_in_info = generate_model(func_ops, checked_ops, "test_extractor"); + auto model_with_in_info = generate_model(func_ops, checked_ops); recovered_model = std::get<0>(model_with_in_info); } { - SubgraphExtractor extractor; - ASSERT_TRUE(extractor.match(test_model, recovered_model)); + ASSERT_TRUE(ModelComparator::get()->match(test_model, recovered_model)); } } @@ -46,12 +46,11 @@ TEST_F(ModelUtilsTest, generate_1) { { std::unordered_set checked_ops; auto func_ops = get_functional_ops(test_model); - auto model_with_in_info = generate_model(func_ops, checked_ops, "test_extractor"); + auto model_with_in_info = generate_model(func_ops, checked_ops); recovered_model = std::get<0>(model_with_in_info); } { - SubgraphExtractor extractor; - ASSERT_TRUE(extractor.match(test_model, recovered_model)); + ASSERT_TRUE(ModelComparator::get()->match(test_model, recovered_model)); } } @@ -61,14 +60,59 @@ TEST_F(ModelUtilsTest, generate_2) { { std::unordered_set checked_ops; auto func_ops = get_functional_ops(test_model); - auto model_with_in_info = generate_model(func_ops, checked_ops, "extract_model"); + auto model_with_in_info = generate_model(func_ops, checked_ops); recovered_model = std::get<0>(model_with_in_info); auto in_info = std::get<1>(model_with_in_info); } { - SubgraphExtractor extractor; - ASSERT_TRUE(extractor.match(test_model, recovered_model)); + ASSERT_TRUE(ModelComparator::get()->match(test_model, recovered_model)); } } +TEST_F(ModelUtilsTest, align_input_info) { + Model_0 test_model_0, test_model_1; + auto in_info_0 = get_input_info_by_model(test_model_0.get()); + auto in_info_1 = get_input_info_by_model(test_model_1.get()); + ASSERT_NE(in_info_0, in_info_1); + ASSERT_NO_THROW(align_input_info(test_model_0.get(), test_model_1.get(), in_info_0, in_info_1)); + auto in_info_ref = align_input_info(test_model_0.get(), test_model_1.get(), in_info_0, in_info_1); + ASSERT_EQ(in_info_1, in_info_ref); +} + +TEST_F(ModelUtilsTest, align_input_info_for_subgraphs) { + Model_0 model_0, model_1; + auto test_model_0 = model_0.get(); + auto test_model_1 = model_1.get(); + auto in_info_0 = get_input_info_by_model(test_model_0); + auto in_info_1 = get_input_info_by_model(test_model_1); + ASSERT_NE(in_info_0, in_info_1); + std::map matched_ops; + auto params_0 = test_model_0->get_parameters(); + auto params_1 = test_model_1->get_parameters(); + size_t params_cnt = params_0.size(); + for (size_t param_id = 0; param_id < params_cnt; ++param_id) { + matched_ops.insert({params_0[param_id]->get_friendly_name(), + params_1[param_id]->get_friendly_name()}); + } + ASSERT_NO_THROW(align_input_info(test_model_0, test_model_1, + in_info_0, in_info_1, + matched_ops)); + auto ref = align_input_info(test_model_0, test_model_1, in_info_0, in_info_1, matched_ops); + ASSERT_EQ(in_info_1, ref); +} + +TEST_F(ModelUtilsTest, get_input_info_by_model) { + Model_1 model; + auto test_model = model.get(); + size_t param_idx = 0; + std::map ref; + for (auto& param : test_model->get_parameters()) { + std::string param_name = "parameter_" + std::to_string(param_idx++); + param->set_friendly_name(param_name); + ref.insert({param_name, InputInfo(param->get_default_output().get_partial_shape())}); + } + auto cur = get_input_info_by_model(test_model); + ASSERT_EQ(cur, ref); +} + } // namespace diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/utils/model_comparator.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/utils/model_comparator.cpp new file mode 100644 index 00000000000000..ca742c55d52046 --- /dev/null +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/utils/model_comparator.cpp @@ -0,0 +1,137 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "matchers/subgraph/subgraph.hpp" +#include "utils/model_comparator.hpp" +#include "base_test.hpp" + +#include "openvino/op/abs.hpp" +#include "openvino/op/relu.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/result.hpp" + +namespace { + +using namespace ov::tools::subgraph_dumper; + +// ======================= ExtractorsManagerTest Unit tests ======================= +class ModelComparatorTest : public SubgraphsDumperBaseTest { +protected: + void SetUp() override { + SubgraphsDumperBaseTest::SetUp(); + { + std::shared_ptr test_parameter = + std::make_shared(ov::element::f32, ov::Shape{1, 2}); + test_parameter->set_friendly_name("test_parameter_0"); + std::shared_ptr test_abs = + std::make_shared(test_parameter); + std::shared_ptr test_res = + std::make_shared(test_abs); + test_model_0_0 = std::make_shared(ov::ResultVector{test_res}, + ov::ParameterVector{test_parameter}); + } + { + std::shared_ptr test_parameter = + std::make_shared(ov::element::f32, ov::Shape{2, 5}); + test_parameter->set_friendly_name("test_parameter_1"); + std::shared_ptr test_abs = + std::make_shared(test_parameter); + std::shared_ptr test_res = + std::make_shared(test_abs); + test_model_0_1 = std::make_shared(ov::ResultVector{test_res}, + ov::ParameterVector{test_parameter}); + } + { + std::shared_ptr test_parameter = + std::make_shared(ov::element::f32, ov::Shape{2, 5}); + std::shared_ptr test_abs = + std::make_shared(test_parameter); + std::shared_ptr test_res = + std::make_shared(test_abs); + test_model_1 = std::make_shared(ov::ResultVector{test_res}, + ov::ParameterVector{test_parameter}); + } + } + + void TearDown() override { + ModelComparator::Ptr model_comparator = ModelComparator::get(); + model_comparator->set_shape_strict_match(false); + model_comparator->set_match_coefficient(0.9f); + } + + std::shared_ptr test_model_0_0, test_model_0_1, test_model_1; +}; + +TEST_F(ModelComparatorTest, get) { + ModelComparator::Ptr model_comparator = nullptr; + ASSERT_NO_THROW(model_comparator = ModelComparator::get()); + ASSERT_EQ(model_comparator, ModelComparator::get()); +} + +TEST_F(ModelComparatorTest, match) { + ModelComparator::Ptr model_comparator = ModelComparator::get(); + ASSERT_NO_THROW(model_comparator->match(test_model_0_0, test_model_0_1)); + ASSERT_TRUE(model_comparator->match(test_model_0_0, test_model_0_1)); + ASSERT_NO_THROW(model_comparator->match(test_model_0_0, test_model_1)); + ASSERT_FALSE(model_comparator->match(test_model_0_0, test_model_1)); + ASSERT_NO_THROW(model_comparator->match(test_model_0_1, test_model_1)); + ASSERT_FALSE(model_comparator->match(test_model_0_1, test_model_1)); +} + +TEST_F(ModelComparatorTest, match_strict_shape) { + ModelComparator::Ptr model_comparator = ModelComparator::get(); + ASSERT_NO_THROW(model_comparator->set_shape_strict_match(true)); + ASSERT_NO_THROW(model_comparator->match(test_model_0_0, test_model_0_1)); + ASSERT_FALSE(model_comparator->match(test_model_0_0, test_model_0_1)); + { + { + std::shared_ptr test_parameter = + std::make_shared(ov::element::f32, ov::Shape{1, 2}); + test_parameter->set_friendly_name("test_parameter_1"); + std::shared_ptr test_abs = + std::make_shared(test_parameter); + std::shared_ptr test_res = + std::make_shared(test_abs); + test_model_0_1 = std::make_shared(ov::ResultVector{test_res}, + ov::ParameterVector{test_parameter}); + } + ASSERT_TRUE(model_comparator->match(test_model_0_0, test_model_0_1)); + } +} + +TEST_F(ModelComparatorTest, match_with_low_coeff) { + ModelComparator::Ptr model_comparator = ModelComparator::get(); + model_comparator->set_match_coefficient(0.5f); + ASSERT_NO_THROW(model_comparator->match(test_model_0_0, test_model_0_1)); + ASSERT_TRUE(model_comparator->match(test_model_0_0, test_model_0_1)); + ASSERT_NO_THROW(model_comparator->match(test_model_0_0, test_model_1)); + ASSERT_TRUE(model_comparator->match(test_model_0_0, test_model_1)); + ASSERT_NO_THROW(model_comparator->match(test_model_0_1, test_model_1)); + ASSERT_TRUE(model_comparator->match(test_model_0_1, test_model_1)); +} + +TEST_F(ModelComparatorTest, match_with_in_info) { + ModelComparator::Ptr model_comparator = ModelComparator::get(); + std::map test_in_info({{"test_parameter_0", InputInfo()}}), + test_in_info_1({{"test_parameter_1", InputInfo({}, 1, 2, true)}}); + ASSERT_NO_THROW(model_comparator->match(test_model_0_0, test_model_0_1, test_in_info, test_in_info)); + ASSERT_TRUE(std::get<0>(model_comparator->match(test_model_0_0, test_model_0_1, test_in_info, test_in_info))); + ASSERT_NO_THROW(model_comparator->match(test_model_0_0, test_model_0_1, test_in_info, test_in_info_1)); + ASSERT_FALSE(std::get<0>(model_comparator->match(test_model_0_0, test_model_0_1, test_in_info, test_in_info_1))); + ASSERT_NO_THROW(model_comparator->match(test_model_0_1, test_model_1, test_in_info, test_in_info)); + ASSERT_FALSE(std::get<0>(model_comparator->match(test_model_0_1, test_model_1, test_in_info, test_in_info))); +} + +TEST_F(ModelComparatorTest, is_subgraph) { + ModelComparator::Ptr model_comparator = ModelComparator::get(); + ASSERT_NO_THROW(model_comparator->is_subgraph(test_model_0_0, test_model_0_1)); + auto is_subgraph = model_comparator->is_subgraph(test_model_0_0, test_model_0_1); + ASSERT_TRUE(std::get<0>(is_subgraph)); + ASSERT_NO_THROW(model_comparator->is_subgraph(test_model_0_0, test_model_1)); + ASSERT_FALSE(std::get<0>(model_comparator->is_subgraph(test_model_0_0, test_model_1))); + ASSERT_NO_THROW(model_comparator->is_subgraph(test_model_0_1, test_model_1)); + ASSERT_FALSE(std::get<0>(model_comparator->is_subgraph(test_model_0_1, test_model_1))); +} + +} // namespace diff --git a/src/tests/functional/plugin/conformance/test_runner/conformance_infra/CMakeLists.txt b/src/tests/functional/plugin/conformance/test_runner/conformance_infra/CMakeLists.txt index 0f25d3218e1b92..5f9dc01189a443 100644 --- a/src/tests/functional/plugin/conformance/test_runner/conformance_infra/CMakeLists.txt +++ b/src/tests/functional/plugin/conformance/test_runner/conformance_infra/CMakeLists.txt @@ -14,8 +14,8 @@ ov_add_target( ADD_CPPLINT INCLUDES PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${OpenVINO_SOURCE_DIR}/src/tests/functional/plugin/conformance/subgraphs_dumper_new/include/cache/meta/ + "$" + "$" LINK_LIBRARIES PUBLIC gflags diff --git a/src/tests/functional/plugin/shared/CMakeLists.txt b/src/tests/functional/plugin/shared/CMakeLists.txt index c75d2938d6badf..3715abb9bb059d 100644 --- a/src/tests/functional/plugin/shared/CMakeLists.txt +++ b/src/tests/functional/plugin/shared/CMakeLists.txt @@ -52,13 +52,11 @@ ov_add_target( ADDITIONAL_SOURCE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src ADD_CPPLINT - DEVELOPER_PACKAGE - tests EXCLUDED_SOURCE_PATHS ${EXCLUDED_SOURCE_PATHS} DEFINES ${DEFINES} INCLUDES PUBLIC - ${PUBLIC_HEADERS_DIR} + "$" LINK_LIBRARIES PUBLIC openvino::pugixml @@ -86,3 +84,8 @@ if (ENABLE_INTEL_CPU) "${CMAKE_CURRENT_SOURCE_DIR}/src/behavior/ov_executable_network/get_metric.cpp" PROPERTIES COMPILE_DEFINITIONS ENABLE_INTEL_CPU=1) endif() + +# install & export + +ov_developer_package_export_targets(TARGET ${TARGET_NAME} + INSTALL_INCLUDE_DIRECTORIES "${PUBLIC_HEADERS_DIR}/") diff --git a/src/tests/functional/plugin/shared/include/base/behavior_test_utils.hpp b/src/tests/functional/plugin/shared/include/base/behavior_test_utils.hpp index c3ac8e0f5c1a0a..6fb1ca5e3d0a55 100644 --- a/src/tests/functional/plugin/shared/include/base/behavior_test_utils.hpp +++ b/src/tests/functional/plugin/shared/include/base/behavior_test_utils.hpp @@ -87,7 +87,7 @@ inline InferenceEngine::Core createIECoreWithTemplate() { PluginCache::get().reset(); InferenceEngine::Core ie; #ifndef OPENVINO_STATIC_LIBRARY - std::string pluginName = "openvino_template_plugin" IE_BUILD_POSTFIX; + std::string pluginName = "openvino_template_plugin" OV_BUILD_POSTFIX; ie.RegisterPlugin(ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), pluginName), ov::test::utils::DEVICE_TEMPLATE); #endif // !OPENVINO_STATIC_LIBRARY diff --git a/src/tests/functional/plugin/shared/include/base/ov_behavior_test_utils.hpp b/src/tests/functional/plugin/shared/include/base/ov_behavior_test_utils.hpp index 347660d0aa3252..5e29386b9d6a69 100644 --- a/src/tests/functional/plugin/shared/include/base/ov_behavior_test_utils.hpp +++ b/src/tests/functional/plugin/shared/include/base/ov_behavior_test_utils.hpp @@ -161,7 +161,7 @@ inline ov::Core createCoreWithTemplate() { ov::Core core; #ifndef OPENVINO_STATIC_LIBRARY std::string pluginName = "openvino_template_plugin"; - pluginName += IE_BUILD_POSTFIX; + pluginName += OV_BUILD_POSTFIX; core.register_plugin(ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), pluginName), ov::test::utils::DEVICE_TEMPLATE); #endif // !OPENVINO_STATIC_LIBRARY diff --git a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_integration.hpp b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_integration.hpp index 3be422c23f4e2f..a6c0f73751bff7 100644 --- a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_integration.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_integration.hpp @@ -65,8 +65,8 @@ class OVClassBasicTestP : public OVPluginTestBase, std::tie(pluginName, target_device) = GetParam(); SKIP_IF_CURRENT_TEST_IS_DISABLED(); APIBaseTest::SetUp(); - pluginName += IE_BUILD_POSTFIX; - if (pluginName == (std::string("openvino_template_plugin") + IE_BUILD_POSTFIX)) { + pluginName += OV_BUILD_POSTFIX; + if (pluginName == (std::string("openvino_template_plugin") + OV_BUILD_POSTFIX)) { pluginName = ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), pluginName); } } @@ -197,7 +197,7 @@ inline std::string getPluginFile() { std::ostringstream stream; stream << ""; ov::test::utils::createFile(filename, stream.str()); return filename; diff --git a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/properties_tests.hpp b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/properties_tests.hpp index edfcc5920b07a0..cecd117f3529a7 100644 --- a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/properties_tests.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/properties_tests.hpp @@ -123,8 +123,8 @@ class OVBasicPropertiesTestsP : public OVPluginTestBase, std::tie(pluginName, target_device) = GetParam(); SKIP_IF_CURRENT_TEST_IS_DISABLED(); APIBaseTest::SetUp(); - pluginName += IE_BUILD_POSTFIX; - if (pluginName == (std::string("openvino_template_plugin") + IE_BUILD_POSTFIX)) { + pluginName += OV_BUILD_POSTFIX; + if (pluginName == (std::string("openvino_template_plugin") + OV_BUILD_POSTFIX)) { pluginName = ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), pluginName); } } diff --git a/src/tests/functional/plugin/shared/include/behavior/plugin/core_integration.hpp b/src/tests/functional/plugin/shared/include/behavior/plugin/core_integration.hpp index f0ae5358605656..d49e0dfd17c2bd 100644 --- a/src/tests/functional/plugin/shared/include/behavior/plugin/core_integration.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/plugin/core_integration.hpp @@ -55,8 +55,8 @@ class IEClassBasicTestP : public BehaviorTestsUtils::IEPluginTestBase, std::tie(pluginName, target_device) = GetParam(); SKIP_IF_CURRENT_TEST_IS_DISABLED(); ov::test::behavior::APIBaseTest::SetUp(); - pluginName += IE_BUILD_POSTFIX; - if (pluginName == (std::string("openvino_template_plugin") + IE_BUILD_POSTFIX)) { + pluginName += OV_BUILD_POSTFIX; + if (pluginName == (std::string("openvino_template_plugin") + OV_BUILD_POSTFIX)) { pluginName = ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), pluginName); } } @@ -149,7 +149,7 @@ inline std::string getPluginFile() { std::ostringstream stream; stream << ""; ov::test::utils::createFile(filename, stream.str()); return filename; diff --git a/src/tests/functional/plugin/shared/include/single_layer_tests/binary_convolution.hpp b/src/tests/functional/plugin/shared/include/single_layer_tests/binary_convolution.hpp index f6f2fbdbbc9e6f..6d76bf71a3ee66 100644 --- a/src/tests/functional/plugin/shared/include/single_layer_tests/binary_convolution.hpp +++ b/src/tests/functional/plugin/shared/include/single_layer_tests/binary_convolution.hpp @@ -7,7 +7,6 @@ #include "shared_test_classes/single_layer/binary_convolution.hpp" namespace LayerTestsDefinitions { - TEST_P(BinaryConvolutionLayerTest, CompareWithRefs) { Run(); } diff --git a/src/tests/functional/plugin/shared/include/single_layer_tests/gather.hpp b/src/tests/functional/plugin/shared/include/single_layer_tests/gather.hpp index f6b8f091bd8125..e909283ff31336 100644 --- a/src/tests/functional/plugin/shared/include/single_layer_tests/gather.hpp +++ b/src/tests/functional/plugin/shared/include/single_layer_tests/gather.hpp @@ -24,4 +24,8 @@ TEST_P(Gather8IndiceScalarLayerTest, CompareWithRefs) { Run(); }; +TEST_P(Gather8withIndicesDataLayerTest, CompareWithRefs) { + Run(); +}; + } // namespace LayerTestsDefinitions diff --git a/src/tests/functional/plugin/shared/include/single_layer_tests/group_normalization.hpp b/src/tests/functional/plugin/shared/include/single_layer_tests/group_normalization.hpp new file mode 100644 index 00000000000000..8f080764adbced --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_layer_tests/group_normalization.hpp @@ -0,0 +1,21 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#pragma once +#include "shared_test_classes/single_layer/group_normalization.hpp" + +namespace ov { +namespace test { +namespace subgraph { + +TEST_P(GroupNormalizationTest, CompareWithRefs) { + run(); +} + +TEST_P(GroupNormalizationTest, CompareQueryModel) { + query_model(); +} + +} // namespace subgraph +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/binary_convolution.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/binary_convolution.hpp new file mode 100644 index 00000000000000..4f1e93f4155ab8 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/binary_convolution.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/binary_convolution.hpp" + +namespace ov { +namespace test { +TEST_P(BinaryConvolutionLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/bucketize.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/bucketize.hpp new file mode 100644 index 00000000000000..3056be6c48d922 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/bucketize.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/bucketize.hpp" + +namespace ov { +namespace test { +TEST_P(BucketizeLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/cum_sum.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/cum_sum.hpp new file mode 100644 index 00000000000000..0d7c57a9341eef --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/cum_sum.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/cum_sum.hpp" + +namespace ov { +namespace test { +TEST_P(CumSumLayerTest, Inference) { + run(); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/deformable_psroi_pooling.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/deformable_psroi_pooling.hpp new file mode 100644 index 00000000000000..65063df0f5e545 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/deformable_psroi_pooling.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/deformable_psroi_pooling.hpp" + +namespace ov { +namespace test { +TEST_P(DeformablePSROIPoolingLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/depth_to_space.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/depth_to_space.hpp new file mode 100644 index 00000000000000..a7f0552d6028a6 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/depth_to_space.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/depth_to_space.hpp" + +namespace ov { +namespace test { +TEST_P(DepthToSpaceLayerTest, Inference) { + run(); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/einsum.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/einsum.hpp new file mode 100644 index 00000000000000..375a02f2ec65f4 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/einsum.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/einsum.hpp" + +namespace ov { +namespace test { +TEST_P(EinsumLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/eye.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/eye.hpp new file mode 100644 index 00000000000000..ebacbba67b4844 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/eye.hpp @@ -0,0 +1,14 @@ +// Copyright (C) 2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#pragma once + +#include "shared_test_classes/single_op/eye.hpp" + +namespace ov { +namespace test { +TEST_P(EyeLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/gather.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/gather.hpp index 6c27459fc18712..be9aa74077694e 100644 --- a/src/tests/functional/plugin/shared/include/single_op_tests/gather.hpp +++ b/src/tests/functional/plugin/shared/include/single_op_tests/gather.hpp @@ -23,5 +23,9 @@ TEST_P(Gather8LayerTest, Inference) { TEST_P(Gather8IndiceScalarLayerTest, Inference) { run(); }; + +TEST_P(Gather8withIndicesDataLayerTest, Inference) { + run(); +}; } // namespace test } // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/interpolate.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/interpolate.hpp new file mode 100644 index 00000000000000..4d7bee7599896b --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/interpolate.hpp @@ -0,0 +1,18 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/interpolate.hpp" + +namespace ov { +namespace test { +TEST_P(InterpolateLayerTest, Inference) { + run(); +} +TEST_P(Interpolate11LayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/is_inf.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/is_inf.hpp new file mode 100644 index 00000000000000..04b0aaa1f6a29e --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/is_inf.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/is_inf.hpp" + +namespace ov { +namespace test { +TEST_P(IsInfLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/log_softmax.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/log_softmax.hpp new file mode 100644 index 00000000000000..5d941a1d87f9e9 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/log_softmax.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/log_softmax.hpp" + +namespace ov { +namespace test { +TEST_P(LogSoftmaxLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/logical.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/logical.hpp new file mode 100644 index 00000000000000..f98027493e8cc7 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/logical.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/logical.hpp" + +namespace ov { +namespace test { +TEST_P(LogicalLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/loop.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/loop.hpp new file mode 100644 index 00000000000000..ada7e8b32b8e79 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/loop.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/loop.hpp" + +namespace ov { +namespace test { +TEST_P(LoopLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/lrn.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/lrn.hpp new file mode 100644 index 00000000000000..cbe1b3f5710f0e --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/lrn.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/lrn.hpp" + +namespace ov { +namespace test { +TEST_P(LrnLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/lstm_cell.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/lstm_cell.hpp new file mode 100644 index 00000000000000..8ce396ec36f279 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/lstm_cell.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/lstm_cell.hpp" + +namespace ov { +namespace test { +TEST_P(LSTMCellTest, Inference) { + run(); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/lstm_sequence.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/lstm_sequence.hpp new file mode 100644 index 00000000000000..c77ce06ece2c92 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/lstm_sequence.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/lstm_sequence.hpp" + +namespace ov { +namespace test { +TEST_P(LSTMSequenceTest, Inference) { + run(); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/mat_mul.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/mat_mul.hpp new file mode 100644 index 00000000000000..217b5825da9b7e --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/mat_mul.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/mat_mul.hpp" + +namespace ov { +namespace test { +TEST_P(MatMulLayerTest, Inference) { + run(); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/minimum_maximum.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/minimum_maximum.hpp new file mode 100644 index 00000000000000..ae367d97a07ec0 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/minimum_maximum.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/minimum_maximum.hpp" + +namespace ov { +namespace test { +TEST_P(MaxMinLayerTest, Inference){ + run(); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/mvn.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/mvn.hpp new file mode 100644 index 00000000000000..6ad139d046621e --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/mvn.hpp @@ -0,0 +1,19 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/mvn.hpp" + +namespace ov { +namespace test { +TEST_P(Mvn1LayerTest, Inference) { + run(); +}; + +TEST_P(Mvn6LayerTest, Inference) { + run(); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/nonzero.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/nonzero.hpp new file mode 100644 index 00000000000000..7afb5a97579bee --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/nonzero.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/nonzero.hpp" + +namespace ov { +namespace test { +TEST_P(NonZeroLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/normalize_l2.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/normalize_l2.hpp new file mode 100644 index 00000000000000..aabe69a20654b1 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/normalize_l2.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/normalize_l2.hpp" + +namespace ov { +namespace test { +TEST_P(NormalizeL2LayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/one_hot.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/one_hot.hpp new file mode 100644 index 00000000000000..91242249e8794b --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/one_hot.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/one_hot.hpp" + +namespace ov { +namespace test { +TEST_P(OneHotLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/pad.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/pad.hpp new file mode 100644 index 00000000000000..a1bc55e5208eb7 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/pad.hpp @@ -0,0 +1,19 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/pad.hpp" + +namespace ov { +namespace test { +TEST_P(PadLayerTest, Inference) { + run(); +} + +TEST_P(Pad12LayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/pooling.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/pooling.hpp new file mode 100644 index 00000000000000..495c551e9764eb --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/pooling.hpp @@ -0,0 +1,19 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/pooling.hpp" + +namespace ov { +namespace test { +TEST_P(PoolingLayerTest, Inference) { + run(); +} + +TEST_P(MaxPoolingV8LayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/power.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/power.hpp new file mode 100644 index 00000000000000..922ccbcbb345cc --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/power.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/power.hpp" + +namespace ov { +namespace test { +TEST_P(PowerLayerTest, Inference){ + run(); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/prior_box.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/prior_box.hpp new file mode 100644 index 00000000000000..707aadec0e8b29 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/prior_box.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/prior_box.hpp" + +namespace ov { +namespace test { +TEST_P(PriorBoxLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/prior_box_clustered.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/prior_box_clustered.hpp new file mode 100644 index 00000000000000..389bf2309b7831 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/prior_box_clustered.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/prior_box_clustered.hpp" + +namespace ov { +namespace test { +TEST_P(PriorBoxClusteredLayerTest, Inference) { + run(); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/roi_align.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/roi_align.hpp new file mode 100644 index 00000000000000..96e1bbeeeac639 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/roi_align.hpp @@ -0,0 +1,19 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/roi_align.hpp" + +namespace ov { +namespace test { +TEST_P(ROIAlignLayerTest, Inference) { + run(); +} + +TEST_P(ROIAlignV9LayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/roi_pooling.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/roi_pooling.hpp new file mode 100644 index 00000000000000..3b89b91aa15504 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/roi_pooling.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/roi_pooling.hpp" + +namespace ov { +namespace test { +TEST_P(ROIPoolingLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/conv_eltwise_fusion.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/conv_eltwise_fusion.hpp index f41991680ab4f6..088716c36ab130 100644 --- a/src/tests/functional/plugin/shared/include/subgraph_tests/conv_eltwise_fusion.hpp +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/conv_eltwise_fusion.hpp @@ -6,10 +6,12 @@ #include "shared_test_classes/subgraph/conv_eltwise_fusion.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { TEST_P(ConvEltwiseFusion, CompareWithRefs) { - Run(); + run(); } -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/conv_strides_opt.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/conv_strides_opt.hpp index 67ae6cda1320aa..9d46654ebd743e 100644 --- a/src/tests/functional/plugin/shared/include/subgraph_tests/conv_strides_opt.hpp +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/conv_strides_opt.hpp @@ -6,9 +6,12 @@ #include "shared_test_classes/subgraph/conv_strides_opt.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { TEST_P(ConvStridesOpt, CompareWithRefs) { - Run(); + run(); } -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/convert_pad_to_group_conv.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/convert_pad_to_group_conv.hpp index 4d9ce3770aba9a..8547d6b17436a4 100644 --- a/src/tests/functional/plugin/shared/include/subgraph_tests/convert_pad_to_group_conv.hpp +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/convert_pad_to_group_conv.hpp @@ -6,9 +6,12 @@ #include "shared_test_classes/subgraph/convert_pad_to_group_conv.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { TEST_P(ConvertPadToConvTests, CompareWithRefs) { - Run(); + run(); } -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/get_output_before_activation.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/get_output_before_activation.hpp index 996a42e26cd2b4..eca03aab8e56ca 100644 --- a/src/tests/functional/plugin/shared/include/subgraph_tests/get_output_before_activation.hpp +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/get_output_before_activation.hpp @@ -6,10 +6,12 @@ #include "shared_test_classes/subgraph/get_output_before_activation.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { TEST_P(OutputBeforeActivation, CompareWithRefs) { - Run(); + run(); }; -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/matmul_const_transposes_extraction.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/matmul_const_transposes_extraction.hpp index 48e0755fa65d3c..e16847f17105d5 100644 --- a/src/tests/functional/plugin/shared/include/subgraph_tests/matmul_const_transposes_extraction.hpp +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/matmul_const_transposes_extraction.hpp @@ -4,18 +4,21 @@ #pragma once +#include "functional_test_utils/skip_tests_config.hpp" #include "shared_test_classes/subgraph/matmul_const_transposes_extraction.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { TEST_P(MatMulConstTransposesExtractionTest, CompareWithRefs) { SKIP_IF_CURRENT_TEST_IS_DISABLED(); - Run(); + run(); } TEST_P(QuantizedMatMulConstTransposesExtractionTest, CompareWithRefs) { SKIP_IF_CURRENT_TEST_IS_DISABLED(); - Run(); + run(); } -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/matmul_multiply_fusion.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/matmul_multiply_fusion.hpp index e2db9bee578207..77ff3497cb2e03 100644 --- a/src/tests/functional/plugin/shared/include/subgraph_tests/matmul_multiply_fusion.hpp +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/matmul_multiply_fusion.hpp @@ -4,17 +4,21 @@ #pragma once +#include "functional_test_utils/skip_tests_config.hpp" #include "shared_test_classes/subgraph/matmul_multiply_fusion.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { TEST_P(MatMulMultiplyFusion, CompareWithRefs) { SKIP_IF_CURRENT_TEST_IS_DISABLED(); - Run(); + run(); } TEST_P(QuantizedMatMulMultiplyFusion, CompareWithRefs) { SKIP_IF_CURRENT_TEST_IS_DISABLED(); - Run(); + run(); } -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/matmul_squeeze_add.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/matmul_squeeze_add.hpp index b745f70da4e238..267053d695162e 100644 --- a/src/tests/functional/plugin/shared/include/subgraph_tests/matmul_squeeze_add.hpp +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/matmul_squeeze_add.hpp @@ -6,10 +6,12 @@ #include "shared_test_classes/subgraph/matmul_squeeze_add.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { TEST_P(MatmulSqueezeAddTest, CompareWithRefImpl) { - Run(); + run(); }; -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/mul_conv_fusion.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/mul_conv_fusion.hpp index 46d65560b9e1ab..529b22c56e401e 100644 --- a/src/tests/functional/plugin/shared/include/subgraph_tests/mul_conv_fusion.hpp +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/mul_conv_fusion.hpp @@ -6,9 +6,12 @@ #include "shared_test_classes/subgraph/mul_conv_fusion.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { TEST_P(MulConvFusion, CompareWithRefs) { - Run(); + run(); } -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/multiply_add.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/multiply_add.hpp index f3d65830592133..93f3600048a90d 100644 --- a/src/tests/functional/plugin/shared/include/subgraph_tests/multiply_add.hpp +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/multiply_add.hpp @@ -6,10 +6,12 @@ #include "shared_test_classes/subgraph/multiply_add.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { TEST_P(MultiplyAddLayerTest, CompareWithRefs) { - Run(); + run(); }; -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/mvn_multiply_add.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/mvn_multiply_add.hpp index 8b118b1295f140..174dffd25ca873 100644 --- a/src/tests/functional/plugin/shared/include/subgraph_tests/mvn_multiply_add.hpp +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/mvn_multiply_add.hpp @@ -6,10 +6,12 @@ #include "shared_test_classes/subgraph/mvn_multiply_add.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { -TEST_P(MVNMultiplyAdd, CompareWithRefs){ - Run(); +TEST_P(MVNMultiplyAdd, CompareWithRefs) { + run(); }; -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/perm_conv_perm_concat.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/perm_conv_perm_concat.hpp index b4ad568c56b462..41582d13ffd009 100644 --- a/src/tests/functional/plugin/shared/include/subgraph_tests/perm_conv_perm_concat.hpp +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/perm_conv_perm_concat.hpp @@ -6,10 +6,12 @@ #include "shared_test_classes/subgraph/perm_conv_perm_concat.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { TEST_P(PermConvPermConcat, CompareWithRefs) { - Run(); + run(); } -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/range_add.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/range_add.hpp index 197fe81621e5f8..ce16e5850744a5 100644 --- a/src/tests/functional/plugin/shared/include/subgraph_tests/range_add.hpp +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/range_add.hpp @@ -6,14 +6,16 @@ #include "shared_test_classes/subgraph/range_add.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { TEST_P(RangeAddSubgraphTest, CompareWithRefs) { - Run(); + run(); } TEST_P(RangeNumpyAddSubgraphTest, CompareWithRefs) { - Run(); + run(); } -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/relu_shape_of.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/relu_shape_of.hpp index b2391ef6c04dd8..e26e8837f80279 100644 --- a/src/tests/functional/plugin/shared/include/subgraph_tests/relu_shape_of.hpp +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/relu_shape_of.hpp @@ -6,10 +6,12 @@ #include "shared_test_classes/subgraph/relu_shape_of.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { TEST_P(ReluShapeOfSubgraphTest, CompareWithRefs) { - Run(); + run(); } -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/reshape_squeeze_reshape_relu.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/reshape_squeeze_reshape_relu.hpp index 331ee30f7e515d..7b1c841d7d17b7 100644 --- a/src/tests/functional/plugin/shared/include/subgraph_tests/reshape_squeeze_reshape_relu.hpp +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/reshape_squeeze_reshape_relu.hpp @@ -6,10 +6,12 @@ #include "shared_test_classes/subgraph/reshape_squeeze_reshape_relu.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { -TEST_P(ReshapeSqueezeReshapeRelu, CompareWithRefs){ - Run(); +TEST_P(ReshapeSqueezeReshapeRelu, CompareWithRefs) { + run(); }; -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/split_conv_concat.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/split_conv_concat.hpp index c121683977f898..5fd61dd48f738a 100644 --- a/src/tests/functional/plugin/shared/include/subgraph_tests/split_conv_concat.hpp +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/split_conv_concat.hpp @@ -6,14 +6,17 @@ #include "shared_test_classes/subgraph/split_conv_concat.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { TEST_P(SplitConvConcat, CompareWithRefImpl) { - Run(); + run(); }; -TEST_P(SplitConvConcat, QueryNetwork) { - QueryNetwork(); +TEST_P(SplitConvConcat, QueryModel) { + query_model(); } -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov + diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/variadic_split_pad.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/variadic_split_pad.hpp index 9b9d4fb77839ea..8f1eec6cbf6214 100644 --- a/src/tests/functional/plugin/shared/include/subgraph_tests/variadic_split_pad.hpp +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/variadic_split_pad.hpp @@ -6,10 +6,12 @@ #include "shared_test_classes/subgraph/variadic_split_pad.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { -TEST_P(VariadicSplitPad, CompareWithRefs){ - Run(); +TEST_P(VariadicSplitPad, CompareWithRefs) { + run(); }; -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/infer_request_dynamic.cpp b/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/infer_request_dynamic.cpp index 6540664e3f4b11..e431c4d6eead2b 100644 --- a/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/infer_request_dynamic.cpp +++ b/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/infer_request_dynamic.cpp @@ -76,6 +76,14 @@ bool OVInferRequestDynamicTests::checkOutput(const ov::runtime::Tensor& in, cons tensor.data()[i] = in.data()[i]; } req.infer(); + const auto reqShape = req.get_output_tensor(0).get_shape(); + const auto actualShape = actual.get_shape(); + if (reqShape.size() != actualShape.size()) { + return false; + } + if (!std::equal(reqShape.cbegin(), reqShape.cend(), actualShape.cbegin())) { + return false; + } for (int i = 0; i < actual.get_size(); i++) { if (fabs(req.get_output_tensor(0).data()[i] - actual.data()[i]) > std::numeric_limits::epsilon()) return false; diff --git a/src/tests/functional/plugin/shared/src/behavior/plugin/hetero_synthetic.cpp b/src/tests/functional/plugin/shared/src/behavior/plugin/hetero_synthetic.cpp index 005e71be01fc36..bd165465edc894 100644 --- a/src/tests/functional/plugin/shared/src/behavior/plugin/hetero_synthetic.cpp +++ b/src/tests/functional/plugin/shared/src/behavior/plugin/hetero_synthetic.cpp @@ -119,11 +119,11 @@ void HeteroSyntheticTest::SetUp() { try { if (pluginParameter._location == "openvino_template_plugin") { PluginCache::get().ie()->RegisterPlugin(ov::util::make_plugin_library_name( - ov::test::utils::getExecutableDirectory(), pluginParameter._location + IE_BUILD_POSTFIX), + ov::test::utils::getExecutableDirectory(), pluginParameter._location + OV_BUILD_POSTFIX), pluginParameter._name); } else { PluginCache::get().ie()->RegisterPlugin(pluginParameter._location - + IE_BUILD_POSTFIX, pluginParameter._name); + + OV_BUILD_POSTFIX, pluginParameter._name); } } catch (InferenceEngine::Exception& ex) { if (std::string{ex.what()}.find("Device with \"" + pluginParameter._name diff --git a/src/tests/functional/shared_test_classes/CMakeLists.txt b/src/tests/functional/shared_test_classes/CMakeLists.txt index 35d09840c09770..a4f46b241437b0 100644 --- a/src/tests/functional/shared_test_classes/CMakeLists.txt +++ b/src/tests/functional/shared_test_classes/CMakeLists.txt @@ -9,11 +9,9 @@ ov_add_target( TYPE STATIC ROOT "${CMAKE_CURRENT_SOURCE_DIR}/include" ADD_CPPLINT - DEVELOPER_PACKAGE - tests INCLUDES PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/include" + "$" ADDITIONAL_SOURCE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src LINK_LIBRARIES @@ -25,3 +23,8 @@ ov_add_target( ov_build_target_faster(${TARGET_NAME} PCH PRIVATE "src/precomp.hpp" ) + +# install & export + +ov_developer_package_export_targets(TARGET ${TARGET_NAME} + INSTALL_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include/") diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/ov_subgraph.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/ov_subgraph.hpp index 42d021072a49a2..5ca0b6531a39f3 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/ov_subgraph.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/ov_subgraph.hpp @@ -20,6 +20,12 @@ using ElementType = ov::element::Type_t; using Config = ov::AnyMap; using TargetDevice = std::string; +typedef std::tuple + BasicParams; + class SubgraphBaseTest : public ov::test::TestsCommon { public: virtual void run(); @@ -106,5 +112,16 @@ inline std::vector static_shapes_to_test_representation(const std::v } return result; } + +class SubgraphBaseStaticTest : public ov::test::SubgraphBaseTest { +public: + void run() override { + std::vector input_shapes; + for (const auto& param : function->get_parameters()) + input_shapes.emplace_back(param->get_shape()); + init_input_shapes(ov::test::static_shapes_to_test_representation(input_shapes)); + ov::test::SubgraphBaseTest::run(); + } +}; } // namespace test } // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/ranges.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/ranges.hpp index 17121e8a57aff3..4315fd9ef5d5a6 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/ranges.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/ranges.hpp @@ -22,6 +22,10 @@ #include "openvino/op/dft.hpp" #include "openvino/op/idft.hpp" +#include "openvino/op/logical_and.hpp" +#include "openvino/op/logical_or.hpp" +#include "openvino/op/logical_xor.hpp" +#include "openvino/op/logical_not.hpp" #include #include @@ -86,7 +90,10 @@ static std::map>> i { ov::op::v4::ReduceL1::get_type_info_static(), {{{0, 5}}, {{0, 5, 1000}}} }, { ov::op::v4::ReduceL2::get_type_info_static(), {{{0, 5}}, {{0, 5, 1000}}} }, { ov::op::v7::DFT::get_type_info_static(), {{{0, 1}}, {{0, 1, 1000000}}} }, - { ov::op::v7::IDFT::get_type_info_static(), {{{0, 1}}, {{0, 1, 1000000}}} }, + { ov::op::v1::LogicalAnd::get_type_info_static(), {{{0, 2}}, {{0, 2, 1}}} }, + { ov::op::v1::LogicalOr::get_type_info_static(), {{{0, 2}}, {{0, 2, 1}}} }, + { ov::op::v1::LogicalNot::get_type_info_static(), {{{0, 2}}, {{0, 2, 1}}} }, + { ov::op::v1::LogicalXor::get_type_info_static(), {{{0, 2}}, {{0, 2, 1}}} }, }; } // namespace utils diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/gather.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/gather.hpp index 5f9e9473708969..c2f354f39200a6 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/gather.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/gather.hpp @@ -83,4 +83,18 @@ class Gather8IndiceScalarLayerTest : public testing::WithParamInterface // indices data +> gather8withIndicesDataParamsTuple; + +class Gather8withIndicesDataLayerTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; + } // namespace LayerTestsDefinitions diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/group_normalization.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/group_normalization.hpp new file mode 100644 index 00000000000000..759f47786d98be --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/group_normalization.hpp @@ -0,0 +1,98 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#pragma once +#include "ov_models/builders.hpp" +#include "common_test_utils/common_utils.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +namespace subgraph { + +using GroupNormalizationTestParams = std::tuple; + +class GroupNormalizationTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj) { + ElementType netType, inType, outType; + InputShape shapes; + std::int64_t num_groups; + double epsilon; + TargetDevice targetDevice; + Config config; + std::tie(netType, inType, outType, shapes, num_groups, epsilon, targetDevice, config) = obj.param; + + std::ostringstream result; + result << "NetType=" << netType << "_"; + result << "InType=" << inType << "_"; + result << "OutType=" << outType << "_"; + result << "IS=" << ov::test::utils::partialShape2str({shapes.first}) << "_"; + result << "TS="; + for (const auto& item : shapes.second) { + result << ov::test::utils::vec2str(item) << "_"; + } + result << "NumGroups=" << num_groups << "_"; + result << "Epsilon=" << epsilon << "_"; + result << "Device=" << targetDevice; + + return result.str(); + } + +protected: + void SetUp() override { + InputShape shapes; + ElementType ngPrc; + std::int64_t num_groups; + double epsilon; + + std::tie(ngPrc, inType, outType, shapes, num_groups, epsilon, targetDevice, configuration) = this->GetParam(); + InputShape biasInputShape = ExtractBiasShape(shapes); + init_input_shapes({shapes, biasInputShape, biasInputShape}); + ov::ParameterVector params; + for (auto&& shape : inputDynamicShapes) { + params.push_back(std::make_shared(ngPrc, shape)); + } + const auto paramOuts = + ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(params)); + + const auto groupNormalization = std::make_shared( + paramOuts.at(0), + paramOuts.at(1), + paramOuts.at(2), + num_groups, + epsilon); + const ngraph::ResultVector results{std::make_shared(groupNormalization)}; + + // TODO: This workaround is needed as there is no full support for f16 type in the reference implementation + if (ngPrc == element::Type_t::f16) { + abs_threshold = 0.007; + } + + function = std::make_shared(results, params, "GroupNormalization"); + } + + InputShape ExtractBiasShape(const InputShape& shape) { + std::vector biasShape; + std::transform(shape.second.cbegin(), shape.second.cend(), std::back_inserter(biasShape), + [](const ov::Shape& s)->ov::Shape { return {s[1]}; }); + InputShape biasInputShape { + shape.first.is_dynamic() ? ov::PartialShape{shape.first[1]} : shape.first, + std::move(biasShape) + }; + return biasInputShape; + } +}; + +} // namespace subgraph +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/binary_convolution.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/binary_convolution.hpp new file mode 100644 index 00000000000000..14d388a8883266 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/binary_convolution.hpp @@ -0,0 +1,42 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { + +using binConvSpecificParams = std::tuple< + std::vector, // Kernel size + std::vector, // Strides + std::vector, // Pads begin + std::vector, // Pads end + std::vector, // Dilations + size_t, // Num Output channels + ov::op::PadType, // Padding type + float>; // Padding value + +using binaryConvolutionTestParamsSet = std::tuple< + binConvSpecificParams, // + ov::element::Type, // Model Type + std::vector, // Input shape + std::string>; // Device name + +class BinaryConvolutionLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); +protected: + void SetUp() override; +}; + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/bucketize.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/bucketize.hpp new file mode 100644 index 00000000000000..509a1405379fbd --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/bucketize.hpp @@ -0,0 +1,33 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { + +using bucketizeParamsTuple = std::tuple< + std::vector, // data shape, bucket shape + bool, // Right edge of interval + ov::element::Type, // Data input precision + ov::element::Type, // Buckets input precision + ov::element::Type, // Output precision + std::string>; // Device name + +class BucketizeLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); +protected: + void SetUp() override; +}; + + +} // namespace test +} // namespace ov \ No newline at end of file diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/cum_sum.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/cum_sum.hpp new file mode 100644 index 00000000000000..035bff4de8c67e --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/cum_sum.hpp @@ -0,0 +1,33 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { + +typedef std::tuple< + std::vector, // Input shapes + ov::element::Type, // Model type + int64_t, // Axis + bool, // Exclusive + bool, // Reverse + std::string> cumSumParams; // Device name + +class CumSumLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/deformable_psroi_pooling.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/deformable_psroi_pooling.hpp new file mode 100644 index 00000000000000..b3cc9ea739a779 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/deformable_psroi_pooling.hpp @@ -0,0 +1,39 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +using deformablePSROISpecificParams = std::tuple< + int64_t, // output_dim + int64_t, // group_size + float, // spatial_scale + std::vector, // spatial_bins_x_y + float, // trans_std + int64_t>; // part_size + +using deformablePSROILayerTestParams = std::tuple< + deformablePSROISpecificParams, + std::vector, // data input shape + ov::element::Type, // Net type + std::string>; // Device name + +class DeformablePSROIPoolingLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/depth_to_space.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/depth_to_space.hpp new file mode 100644 index 00000000000000..40a7632aaa5098 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/depth_to_space.hpp @@ -0,0 +1,33 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "openvino/op/depth_to_space.hpp" + +namespace ov { +namespace test { +using depthToSpaceParamsTuple = typename std::tuple< + std::vector, // Input shape + ov::element::Type, // Model type + ov::op::v0::DepthToSpace::DepthToSpaceMode, // Mode + std::size_t, // Block size + std::string>; // Device name> + +class DepthToSpaceLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj); + +protected: + void SetUp() override; +}; + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/einsum.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/einsum.hpp new file mode 100644 index 00000000000000..aeef17447e6a43 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/einsum.hpp @@ -0,0 +1,34 @@ +// Copyright (C) 2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + std::string, // Equation + std::vector // Input shapes +> EinsumEquationWithInput; + +typedef std::tuple< + ov::element::Type, // Model type + EinsumEquationWithInput, // Equation with corresponding input shapes + std::string // Device name +> EinsumLayerTestParamsSet; + +class EinsumLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/eye.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/eye.hpp new file mode 100644 index 00000000000000..1563a8a37f9cda --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/eye.hpp @@ -0,0 +1,24 @@ +// Copyright (C) 2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#pragma once + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +using EyeLayerTestParams = std::tuple< + std::vector, // eye shape + std::vector, // output batch shape + std::vector, // eye params (rows, cols, diag_shift) + ov::element::Type, // Model type + std::string>; // Device name + +class EyeLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(testing::TestParamInfo obj); + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/gather.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/gather.hpp index 36d6ba48dfd25a..a41a13ce962eb7 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/gather.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/gather.hpp @@ -63,5 +63,20 @@ class Gather8IndiceScalarLayerTest : public testing::WithParamInterface // indices data +> gather8withIndicesDataParamsTuple; + +class Gather8withIndicesDataLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; + } // namespace test } // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/interpolate.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/interpolate.hpp new file mode 100644 index 00000000000000..0623f5690fb100 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/interpolate.hpp @@ -0,0 +1,55 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + ov::op::util::InterpolateBase::InterpolateMode, // InterpolateMode + ov::op::util::InterpolateBase::ShapeCalcMode, // ShapeCalculationMode + ov::op::util::InterpolateBase::CoordinateTransformMode, // CoordinateTransformMode + ov::op::util::InterpolateBase::NearestMode, // NearestMode + bool, // AntiAlias + std::vector, // PadBegin + std::vector, // PadEnd + double, // Cube coef + std::vector, // Axes + std::vector // Scales +> InterpolateSpecificParams; + +typedef std::tuple< + InterpolateSpecificParams, + ov::element::Type, // Model type + std::vector, // Input shapes + ov::Shape, // Target shapes + std::string, // Device name + std::map // Additional network configuration +> InterpolateLayerTestParams; + +class InterpolateLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; + +class Interpolate11LayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/is_inf.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/is_inf.hpp new file mode 100644 index 00000000000000..7856a0036e7bbb --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/is_inf.hpp @@ -0,0 +1,31 @@ +// Copyright (C) 2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +using IsInfParams = std::tuple< + std::vector, // Data shape + bool, // Detect negative + bool, // Detect positive + ov::element::Type, // Model type + std::string, // Device name + std::map // Additional config +>; + +class IsInfLayerTest : public testing::WithParamInterface, + virtual public SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/log_softmax.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/log_softmax.hpp new file mode 100644 index 00000000000000..b803cd35a8abdb --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/log_softmax.hpp @@ -0,0 +1,32 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +using logSoftmaxLayerTestParams = std::tuple< + ov::element::Type, // Model type + std::vector, // Input shapes + int64_t, // Axis + std::string // Target device +>; + +class LogSoftmaxLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/logical.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/logical.hpp new file mode 100644 index 00000000000000..5dce73dc0552ab --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/logical.hpp @@ -0,0 +1,36 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + + +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +#include "common_test_utils/test_enums.hpp" + +namespace ov { +namespace test { +using InputShapesTuple = std::pair, std::vector>; + +typedef std::tuple< + std::vector, // Input shapes + ov::test::utils::LogicalTypes, // Logical op type + ov::test::utils::InputLayerType, // Second input type + ov::element::Type, // Model type + std::string, // Device name + std::map // Additional model configuration +> LogicalTestParams; + +class LogicalLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +protected: + void SetUp() override; + +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/loop.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/loop.hpp new file mode 100644 index 00000000000000..c9645d6a5b1c74 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/loop.hpp @@ -0,0 +1,39 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +enum LOOP_IN_TYPE { + INVARIANT, + MERGED +}; + +using LoopParams = typename std::tuple< + bool, // ExecuteFirstIteration + bool, // BodyCondition is a constant? + bool, // BodyCondition value, if it is a Const + int64_t, // TripCount, -1 means infinity + std::vector, // input shapes + std::vector, // input types. Vector size have to be equal to input shapes vector size + ov::element::Type, // Model type + std::string>; // Device name + +class LoopLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/lrn.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/lrn.hpp new file mode 100644 index 00000000000000..c7b887cb1fc631 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/lrn.hpp @@ -0,0 +1,35 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + double, // Alpha + double, // Beta + double, // Bias + size_t, // Size + std::vector, // Reduction axes + ov::element::Type, // Network precision + std::vector, // Input shapes + std::string // Device name +> lrnLayerTestParamsSet; + +class LrnLayerTest + : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/lstm_cell.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/lstm_cell.hpp new file mode 100644 index 00000000000000..d63b7553da1c55 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/lstm_cell.hpp @@ -0,0 +1,38 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "common_test_utils/test_enums.hpp" + +namespace ov { +namespace test { +using LSTMCellParams = typename std::tuple< + bool, // using decompose to sub-ops transformation + size_t, // batch + size_t, // hidden size + size_t, // input size + std::vector, // activations + float, // clip + ov::test::utils::InputLayerType, // W input type (Constant or Parameter) + ov::test::utils::InputLayerType, // R input type (Constant or Parameter) + ov::test::utils::InputLayerType, // B input type (Constant or Parameter) + ov::element::Type, // Network precision + std::string>; // Device name + +class LSTMCellTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj); +protected: + void SetUp() override; +}; + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/lstm_sequence.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/lstm_sequence.hpp new file mode 100644 index 00000000000000..c4996cb32c9d7d --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/lstm_sequence.hpp @@ -0,0 +1,38 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "common_test_utils/test_enums.hpp" + +namespace ov { +namespace test { +using LSTMSequenceParams = typename std::tuple< + ov::test::utils::SequenceTestsMode, // pure Sequence or TensorIterator + size_t, // seq_lengths + size_t, // batch + size_t, // hidden size + size_t, // input size + std::vector, // activations + float, // clip + ov::op::RecurrentSequenceDirection, // direction + ov::test::utils::InputLayerType, // WRB input type (Constant or Parameter) + ov::element::Type, // Network precision + std::string>; // Device name + + +class LSTMSequenceTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj); +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/mat_mul.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/mat_mul.hpp new file mode 100644 index 00000000000000..61fc57a100cd75 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/mat_mul.hpp @@ -0,0 +1,34 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "common_test_utils/test_enums.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + std::vector, // Input Shapes + std::pair, // Transpose inputs + ov::element::Type, // Model type + ov::test::utils::InputLayerType, // Secondary input type + std::string, // Device name + std::map // Additional network configuration +> MatMulLayerTestParamsSet; + +class MatMulLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/minimum_maximum.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/minimum_maximum.hpp new file mode 100644 index 00000000000000..d0af98986af336 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/minimum_maximum.hpp @@ -0,0 +1,32 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "common_test_utils/test_enums.hpp" + +namespace ov { +namespace test { +using MaxMinParamsTuple = typename std::tuple< + std::vector, // Input shapes + ov::test::utils::MinMaxOpType, // Operation type + ov::element::Type, // Model type + ov::test::utils::InputLayerType, // Secondary input type + std::string>; // Device name + +class MaxMinLayerTest: + public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/mvn.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/mvn.hpp new file mode 100644 index 00000000000000..da93a4706700ee --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/mvn.hpp @@ -0,0 +1,54 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + std::vector, // Input shapes + ov::element::Type, // Model type + ov::AxisSet, // Reduction axes + bool, // Across channels + bool, // Normalize variance + double, // Epsilon + std::string // Device name + > mvn1Params; + +class Mvn1LayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; + +typedef std::tuple< + std::vector, // Input shapes + ov::element::Type, // Model type + ov::element::Type, // Axes type + std::vector, // Axes + bool, // Normalize variance + float, // Epsilon + std::string, // Epsilon mode + std::string // Device name + > mvn6Params; + +class Mvn6LayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/nonzero.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/nonzero.hpp new file mode 100644 index 00000000000000..740259846b8150 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/nonzero.hpp @@ -0,0 +1,31 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +using NonZeroLayerTestParamsSet = typename std::tuple< + std::vector, // Input shapes + ov::element::Type, // Model shape + std::string, // Device name + std::map>; // Additional network configuration + +class NonZeroLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/normalize_l2.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/normalize_l2.hpp new file mode 100644 index 00000000000000..160bfc89035258 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/normalize_l2.hpp @@ -0,0 +1,33 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +using NormalizeL2LayerTestParams = std::tuple< + std::vector, // axes + float, // eps + ov::op::EpsMode, // eps mode + std::vector, // input shape + ov::element::Type, // model type + std::string // target device +>; + +class NormalizeL2LayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/one_hot.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/one_hot.hpp new file mode 100644 index 00000000000000..4714c8441603cc --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/one_hot.hpp @@ -0,0 +1,37 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + ov::element::Type, // depth type (any integer type) + int64_t, // depth value + ov::element::Type, // On & Off values type (any supported type) + float, // OnValue + float, // OffValue + int64_t, // axis + ov::element::Type, // Model type + std::vector, // Input shapes + std::string // Target device name +> oneHotLayerTestParamsSet; + +class OneHotLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/pad.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/pad.hpp new file mode 100644 index 00000000000000..1e8e2b7a50a144 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/pad.hpp @@ -0,0 +1,48 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "openvino/op/util/attr_types.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + std::vector, // padsBegin + std::vector, // padsEnd + float, // argPadValue + ov::op::PadMode, // padMode + ov::element::Type, // Net precision + std::vector, // Input shapes + std::string // Target device name +> padLayerTestParamsSet; + +class PadLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; + virtual std::shared_ptr create_pad_op(const std::shared_ptr&, + const std::shared_ptr&, + const std::shared_ptr&, + const std::shared_ptr&, + ov::op::PadMode) const; +}; + +class Pad12LayerTest : public PadLayerTest { + std::shared_ptr create_pad_op(const std::shared_ptr&, + const std::shared_ptr&, + const std::shared_ptr&, + const std::shared_ptr&, + ov::op::PadMode) const override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/pooling.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/pooling.hpp new file mode 100644 index 00000000000000..cfb57994b35b33 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/pooling.hpp @@ -0,0 +1,71 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "common_test_utils/test_enums.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + ov::test::utils::PoolingTypes, // Pooling type, max or avg + std::vector, // Kernel size + std::vector, // Stride + std::vector, // Pad begin + std::vector, // Pad end + ov::op::RoundingType, // Rounding type + ov::op::PadType, // Pad type + bool // Exclude pad +> poolSpecificParams; + +typedef std::tuple< + poolSpecificParams, + ov::element::Type, // Model type + std::vector, // Input shape + std::string // Device name +> poolLayerTestParamsSet; + +typedef std::tuple< + std::vector, // Kernel size + std::vector, // Stride + std::vector, // Dilation + std::vector, // Pad begin + std::vector, // Pad end + ov::element::Type, // Index element type + int64_t, // Axis + ov::op::RoundingType, // Rounding type + ov::op::PadType // Pad type +> maxPoolV8SpecificParams; + +typedef std::tuple< + maxPoolV8SpecificParams, + ov::element::Type, // Model type + std::vector, // Input shape + std::string // Device name +> maxPoolV8LayerTestParamsSet; + +class PoolingLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; + +class MaxPoolingV8LayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/power.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/power.hpp new file mode 100644 index 00000000000000..28634d34428819 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/power.hpp @@ -0,0 +1,30 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +using PowerParamsTuple = typename std::tuple< + std::vector, // Input shapes + ov::element::Type, // Model type + std::vector, // Power + std::string>; // Device name + +class PowerLayerTest: + public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest{ +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj); +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/prior_box.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/prior_box.hpp new file mode 100644 index 00000000000000..e48759fab47589 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/prior_box.hpp @@ -0,0 +1,46 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +using priorBoxSpecificParams = std::tuple< + std::vector, // min_size + std::vector, // max_size + std::vector, // aspect_ratio + std::vector, // density + std::vector, // fixed_ratio + std::vector, // fixed_size + bool, // clip + bool, // flip + float, // step + float, // offset + std::vector, // variance + bool, // scale_all_sizes + bool>; // min_max_aspect_ratios_order + +typedef std::tuple< + priorBoxSpecificParams, + ov::element::Type, // model type + std::vector, // input shape + std::string> priorBoxLayerParams; + +class PriorBoxLayerTest + : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseStaticTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); +protected: + void SetUp() override; +}; + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/prior_box_clustered.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/prior_box_clustered.hpp new file mode 100644 index 00000000000000..61af34ccccf9d2 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/prior_box_clustered.hpp @@ -0,0 +1,40 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + std::vector, // widths + std::vector, // heights + bool, // clip + float, // step_width + float, // step_height + float, // step + float, // offset + std::vector> priorBoxClusteredSpecificParams; + +typedef std::tuple< + priorBoxClusteredSpecificParams, + ov::element::Type, // Model type + std::vector, // Input shape + std::string> priorBoxClusteredLayerParams; + +class PriorBoxClusteredLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/roi_align.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/roi_align.hpp new file mode 100644 index 00000000000000..57257c7154a829 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/roi_align.hpp @@ -0,0 +1,54 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +using roialignParams = std::tuple< + std::vector, // Feature map shape + ov::Shape, // Proposal coords shape + int, // Bin's row count + int, // Bin's column count + float, // Spatial scale + int, // Pooling ratio + std::string, // Pooling mode + ov::element::Type, // Model type + ov::test::TargetDevice>; // Device name + +class ROIAlignLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + static void fillCoordTensor(std::vector& coords, int height, int width, + float spatialScale, int pooledRatio, int pooledH, int pooledW); + static void fillIdxTensor(std::vector& idx, int batchSize); + +protected: + void SetUp() override; +}; + +using roialignV9Params = std::tuple< + std::vector, // Feature map shape + ov::Shape, // Proposal coords shape + int, // Bin's row count + int, // Bin's column count + float, // Spatial scale + int, // Pooling ratio + std::string, // Pooling mode + std::string, // ROI aligned mode + ov::element::Type, // Model type + ov::test::TargetDevice>; // Device name +class ROIAlignV9LayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/roi_pooling.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/roi_pooling.hpp new file mode 100644 index 00000000000000..ecd714f6ef511a --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/roi_pooling.hpp @@ -0,0 +1,34 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "common_test_utils/test_enums.hpp" + +namespace ov { +namespace test { +using roiPoolingParamsTuple = std::tuple< + std::vector, // Input, coords shapes + ov::Shape, // Pooled shape {pooled_h, pooled_w} + float, // Spatial scale + ov::test::utils::ROIPoolingTypes, // ROIPooling method + ov::element::Type, // Model type + ov::test::TargetDevice>; // Device name + +class ROIPoolingLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/conv_eltwise_fusion.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/conv_eltwise_fusion.hpp index d3dea8eb01b080..c156ab395cfe29 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/conv_eltwise_fusion.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/conv_eltwise_fusion.hpp @@ -9,9 +9,10 @@ #include #include "ov_models/builders.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { typedef std::tuple, - virtual public LayerTestsUtils::LayerTestsCommon { + virtual public ov::test::SubgraphBaseStaticTest { public: static std::string getTestCaseName(const testing::TestParamInfo& obj); @@ -35,4 +36,5 @@ class ConvEltwiseFusion : public testing::WithParamInterface #include -#include -#include "shared_test_classes/base/layer_test_utils.hpp" +#include + #include "ov_models/builders.hpp" -#include -#include +#include "shared_test_classes/base/ov_subgraph.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { -typedef std::tuple< - ngraph::Shape, // input shape - ngraph::op::PadType, - std::string // Device name - > ConvStridesOptParams; +typedef std::tuple + ConvStridesOptParams; -class ConvStridesOpt - : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { +class ConvStridesOpt : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseStaticTest { public: - static std::string getTestCaseName(const testing::TestParamInfo &obj); + static std::string getTestCaseName(const testing::TestParamInfo& obj); protected: void SetUp() override; }; -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/convert_pad_to_group_conv.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/convert_pad_to_group_conv.hpp index 53bcd5d850e1c5..108c0086f04b07 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/convert_pad_to_group_conv.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/convert_pad_to_group_conv.hpp @@ -4,32 +4,32 @@ #pragma once -#include #include +#include #include -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "ov_models/builders.hpp" -#include -#include - -namespace SubgraphTestsDefinitions { - -typedef std::tuple< - ngraph::Shape, // input shape - std::vector, // pad_begin - std::vector, // pad_end - float, // pad_value - ngraph::op::PadMode, // pad_mode - std::string // Device name - > PadParams; - -class ConvertPadToConvTests - : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { + +typedef std::tuple, // pad_begin + std::vector, // pad_end + float, // pad_value + ov::op::PadMode, // pad_mode + std::string // Device name + > + PadParams; + +class ConvertPadToConvTests : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseStaticTest { public: - static std::string getTestCaseName(const testing::TestParamInfo &obj); + static std::string getTestCaseName(const testing::TestParamInfo& obj); protected: void SetUp() override; }; -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/get_output_before_activation.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/get_output_before_activation.hpp index b6241ee0a049b3..5aac351fe7d01c 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/get_output_before_activation.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/get_output_before_activation.hpp @@ -4,33 +4,34 @@ #pragma once -#include "common_test_utils/test_common.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" -#include - -namespace SubgraphTestsDefinitions { +#include "shared_test_classes/base/ov_subgraph.hpp" +namespace ov { +namespace test { enum class midOutputType { Sum, Sub, Mul, }; -typedef std::tuple< - std::string, // Target device name - InferenceEngine::Precision, // Network precision - size_t, // Input size - midOutputType, // Type of layer that will be an output - std::map // Configuration -> outputBeforeActivationParams; +typedef std::tuple + outputBeforeActivationParams; -std::ostream& operator<< (std::ostream& os, const midOutputType& oType); +std::ostream& operator<<(std::ostream& os, const midOutputType& oType); -class OutputBeforeActivation : virtual public LayerTestsUtils::LayerTestsCommon, - public testing::WithParamInterface { +class OutputBeforeActivation : virtual public ov::test::SubgraphBaseStaticTest, + public testing::WithParamInterface { protected: void SetUp() override; + public: - static std::string getTestCaseName(const testing::TestParamInfo &obj); - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo &info) const override; + static std::string getTestCaseName(const testing::TestParamInfo& obj); + // void generate_inputs(const std::vector& targetInputStaticShapes) override; }; -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/matmul_const_transposes_extraction.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/matmul_const_transposes_extraction.hpp index ab345a20167618..e67acee0208017 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/matmul_const_transposes_extraction.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/matmul_const_transposes_extraction.hpp @@ -4,44 +4,46 @@ #pragma once -#include #include -#include "shared_test_classes/base/layer_test_utils.hpp" -#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { struct MatMulConstTransposesExtractionTestShapeParams { - ngraph::Shape input_shape; - ngraph::Shape weights_shape; + ov::Shape input_shape; + ov::Shape weights_shape; bool trans_b; }; -typedef std::tuple< - MatMulConstTransposesExtractionTestShapeParams, - bool, // whether Mul can be fused to MatMul in this case - std::string // Device name - > MatMulConstTransposesExtractionTestParams; +typedef std::tuple + MatMulConstTransposesExtractionTestParams; class MatMulConstTransposesExtractionTest - : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { + : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseStaticTest { public: - static std::string getTestCaseName(const testing::TestParamInfo &obj); + static std::string getTestCaseName(const testing::TestParamInfo& obj); protected: void SetUp() override; }; class QuantizedMatMulConstTransposesExtractionTest - : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { + : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseStaticTest { public: - static std::string getTestCaseName(const testing::TestParamInfo &obj); + static std::string getTestCaseName(const testing::TestParamInfo& obj); protected: void SetUp() override; void TearDown() override; }; -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/matmul_multiply_fusion.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/matmul_multiply_fusion.hpp index ad65d51366276b..3dd24f50746bac 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/matmul_multiply_fusion.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/matmul_multiply_fusion.hpp @@ -4,45 +4,45 @@ #pragma once -#include #include -#include "shared_test_classes/base/layer_test_utils.hpp" -#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { struct MatMulMultiplyFusionShapeParams { - ngraph::Shape input_shape; - ngraph::Shape weights_shape; + ov::Shape input_shape; + ov::Shape weights_shape; bool trans_b; - ngraph::Shape const_shape; + ov::Shape const_shape; }; -typedef std::tuple< - MatMulMultiplyFusionShapeParams, - bool, // whether Mul can be fused to MatMul in this case - std::string // Device name - > MatMulMultiplyFusionParams; +typedef std::tuple + MatMulMultiplyFusionParams; -class MatMulMultiplyFusion - : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { +class MatMulMultiplyFusion : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseStaticTest { public: - static std::string getTestCaseName(const testing::TestParamInfo &obj); + static std::string getTestCaseName(const testing::TestParamInfo& obj); protected: void SetUp() override; }; -class QuantizedMatMulMultiplyFusion - : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { +class QuantizedMatMulMultiplyFusion : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseStaticTest { public: - static std::string getTestCaseName(const testing::TestParamInfo &obj); + static std::string getTestCaseName(const testing::TestParamInfo& obj); protected: void SetUp() override; void TearDown() override; }; -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/matmul_squeeze_add.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/matmul_squeeze_add.hpp index 2aa4039e0cd9a3..fc5270096f0d52 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/matmul_squeeze_add.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/matmul_squeeze_add.hpp @@ -9,22 +9,21 @@ #include #include -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/utils/ov_helpers.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { -typedef std::tuple< - InferenceEngine::Precision, // Network Precision - std::string, // Target Device - std::map, // Configuration - std::vector, // Input Shapes - size_t // Output Size -> matmulSqueezeAddParams; +typedef std::tuple + matmulSqueezeAddParams; class MatmulSqueezeAddTest : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { + virtual public ov::test::SubgraphBaseStaticTest { public: static std::string getTestCaseName(const testing::TestParamInfo& obj); @@ -32,4 +31,5 @@ class MatmulSqueezeAddTest : public testing::WithParamInterface #include +#include #include -#include "shared_test_classes/base/layer_test_utils.hpp" -#include -#include - -namespace SubgraphTestsDefinitions { - -typedef std::tuple< - ngraph::NodeTypeInfo, // Convolution type - ngraph::Shape, // Input shape - ngraph::Shape, // Weights shape - ngraph::Shape, // Const shape - ngraph::element::Type, // Network precision - bool, // True if test is negative - std::string // Device name - > MulConvFusionParams; - -class MulConvFusion - : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { + +typedef std::tuple + MulConvFusionParams; + +class MulConvFusion : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseStaticTest { public: - static std::string getTestCaseName(const testing::TestParamInfo &obj); + static std::string getTestCaseName(const testing::TestParamInfo& obj); protected: void SetUp() override; }; -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/multiply_add.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/multiply_add.hpp index 1e016857d4728f..fd93d5a01e3560 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/multiply_add.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/multiply_add.hpp @@ -4,30 +4,28 @@ #pragma once -#include +#include #include +#include #include -#include -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "common_test_utils/test_constants.hpp" -namespace SubgraphTestsDefinitions { +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { -using MultiplyAddParamsTuple = typename std::tuple< - std::vector, //input shapes - InferenceEngine::Precision, //Network precision - std::string>; //Device name +using MultiplyAddParamsTuple = typename std::tuple; // Device name -class MultiplyAddLayerTest: - public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon{ +class MultiplyAddLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseStaticTest { public: - std::shared_ptr fn; - static std::string getTestCaseName(const testing::TestParamInfo &obj); + static std::string getTestCaseName(const testing::TestParamInfo& obj); + protected: void SetUp() override; }; -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/mvn_multiply_add.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/mvn_multiply_add.hpp index 800fc2cbb0caa1..f8218c2f04238f 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/mvn_multiply_add.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/mvn_multiply_add.hpp @@ -4,31 +4,34 @@ #pragma once -#include #include +#include #include -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "ov_models/builders.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { -typedef std::tuple< - std::pair, // Input shape, Constant shape - InferenceEngine::Precision, // Data precision - InferenceEngine::Precision, // Axes precision - std::vector, // Axes - bool, // Normalize variance - float, // Epsilon - std::string, // Epsilon mode - std::string // Device name -> mvnMultiplyAddParams; +typedef std::tuple, // Input shape, Constant shape + ov::element::Type, // Data precision + ov::element::Type, // Axes precision + std::vector, // Axes + bool, // Normalize variance + float, // Epsilon + std::string, // Epsilon mode + std::string // Device name + > + mvnMultiplyAddParams; -class MVNMultiplyAdd: public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon{ +class MVNMultiplyAdd : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseStaticTest { public: - static std::string getTestCaseName(const testing::TestParamInfo &obj); + static std::string getTestCaseName(const testing::TestParamInfo& obj); + protected: void SetUp() override; }; -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/perm_conv_perm_concat.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/perm_conv_perm_concat.hpp index b8be31f93271e7..e9b47db5482dee 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/perm_conv_perm_concat.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/perm_conv_perm_concat.hpp @@ -5,32 +5,29 @@ #pragma once #include -#include -#include -#include -#include - -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "ov_models/builders.hpp" - -namespace SubgraphTestsDefinitions { -typedef std::tuple< - InferenceEngine::Precision, // Network Precision - std::string, // Target Device - std::array, // Input shape - std::array, // Kernel shape - size_t, // Output channels - std::map // Configuration -> PermConvPermConcatParams; + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { + +typedef std::tuple + PermConvPermConcatParams; class PermConvPermConcat : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { + virtual public ov::test::SubgraphBaseStaticTest { public: static std::string getTestCaseName(const testing::TestParamInfo& obj); protected: void SetUp() override; - void Run() override; }; -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/range_add.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/range_add.hpp index 18fe4775ebbea7..6139db3244fc83 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/range_add.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/range_add.hpp @@ -4,36 +4,45 @@ #pragma once -#include +#include #include +#include #include -#include -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "ov_models/builders.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" -#include "shared_test_classes/single_layer/range.hpp" +namespace ov { +namespace test { -namespace SubgraphTestsDefinitions { +typedef std::tuple + RangeParams; // ------------------------------ V0 ------------------------------ -class RangeAddSubgraphTest : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { +class RangeAddSubgraphTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseStaticTest { public: - static std::string getTestCaseName(const testing::TestParamInfo& obj); + static std::string getTestCaseName(const testing::TestParamInfo& obj); + protected: void SetUp() override; }; // ------------------------------ V4 ------------------------------ -class RangeNumpyAddSubgraphTest : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { +class RangeNumpyAddSubgraphTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseStaticTest { public: - static std::string getTestCaseName(const testing::TestParamInfo& obj); + static std::string getTestCaseName(const testing::TestParamInfo& obj); + protected: void SetUp() override; }; -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/relu_shape_of.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/relu_shape_of.hpp index c84f0e2d8292e5..6127de67d74ab1 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/relu_shape_of.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/relu_shape_of.hpp @@ -4,23 +4,26 @@ #pragma once -#include -#include -#include -#include +#include "shared_test_classes/base/ov_subgraph.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "shared_test_classes/single_layer/shape_of.hpp" +namespace ov { +namespace test { -#include "ov_models/builders.hpp" +typedef std::tuple + ShapeOfParams; -namespace SubgraphTestsDefinitions { - -class ReluShapeOfSubgraphTest : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { +class ReluShapeOfSubgraphTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseStaticTest { public: - static std::string getTestCaseName(const testing::TestParamInfo& obj); + static std::string getTestCaseName(const testing::TestParamInfo& obj); + protected: void SetUp() override; }; -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/reshape_squeeze_reshape_relu.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/reshape_squeeze_reshape_relu.hpp index eb4811e08cf353..b2c69f96d946c0 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/reshape_squeeze_reshape_relu.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/reshape_squeeze_reshape_relu.hpp @@ -4,30 +4,32 @@ #pragma once -#include #include +#include #include -#include -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/utils/ov_helpers.hpp" - -namespace SubgraphTestsDefinitions { -using ShapeAxesTuple = std::pair, std::vector>; - -using ReshapeSqueezeReshapeReluTuple = typename std::tuple< - ShapeAxesTuple, // Input shapes & squeeze_indices - InferenceEngine::Precision, // Network precision - std::string, // Device name - ngraph::helpers::SqueezeOpType // SqueezeOpType ->; - -class ReshapeSqueezeReshapeRelu - : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { + +#include "common_test_utils/test_enums.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { + +using ShapeAxesTuple = std::pair>; + +using ReshapeSqueezeReshapeReluTuple = typename std::tuple; + +class ReshapeSqueezeReshapeRelu : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseStaticTest { public: - static std::string getTestCaseName(const testing::TestParamInfo &obj); + static std::string getTestCaseName(const testing::TestParamInfo& obj); + protected: void SetUp() override; }; -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/split_conv_concat.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/split_conv_concat.hpp index a02822a50b9374..d74865a6bb0c6b 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/split_conv_concat.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/split_conv_concat.hpp @@ -4,19 +4,37 @@ #pragma once +#include +#include #include #include -#include -#include #include "shared_test_classes/base/layer_test_utils.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "ov_models/builders.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { + +class SplitConvConcatBase : public ov::test::SubgraphBaseStaticTest { +protected: + void configure_test(const ov::test::BasicParams& param); +}; + +class SplitConvConcat : public testing::WithParamInterface, virtual public SplitConvConcatBase { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; + +} // namespace test +} // namespace ov namespace SubgraphTestsDefinitions { class SplitConvConcat : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { + virtual public ov::test::SplitConvConcatBase { public: static std::string getTestCaseName(const testing::TestParamInfo& obj); diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/variadic_split_pad.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/variadic_split_pad.hpp index 6cfbf94286902d..d9744f8b2ab8cc 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/variadic_split_pad.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/variadic_split_pad.hpp @@ -4,33 +4,35 @@ #pragma once -#include #include +#include #include -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "ov_models/builders.hpp" - -namespace SubgraphTestsDefinitions { +#include "shared_test_classes/base/ov_subgraph.hpp" -typedef std::tuple< - InferenceEngine::SizeVector, // Input shapes - size_t, // Axis - std::vector, // Split number - std::vector, // Index connected layer - std::vector, // Pad begin - std::vector, // Pad end - ngraph::helpers::PadMode, // Pad mode - InferenceEngine::Precision, // Network precision - std::string // Device name -> SplitPadTuple; +namespace ov { +namespace test { +typedef std::tuple, // Split number + std::vector, // Index connected layer + std::vector, // Pad begin + std::vector, // Pad end + ov::op::PadMode, // Pad mode + ov::element::Type, // Input element type + std::string // Device name + > + SplitPadTuple; -class VariadicSplitPad: public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon{ +class VariadicSplitPad : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseStaticTest { public: - static std::string getTestCaseName(const testing::TestParamInfo &obj); + static std::string getTestCaseName(const testing::TestParamInfo& obj); + protected: void SetUp() override; }; -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp b/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp index 285dbebeaa8c49..0d8909c46581e0 100644 --- a/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp +++ b/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp @@ -9,7 +9,7 @@ #include "common_test_utils/ov_tensor_utils.hpp" -#include "shared_test_classes/single_layer/roi_align.hpp" +#include "shared_test_classes/single_op/roi_align.hpp" #include "shared_test_classes/single_layer/psroi_pooling.hpp" #include "shared_test_classes/base/utils/generate_inputs.hpp" #include "shared_test_classes/base/utils/ranges.hpp" @@ -537,13 +537,13 @@ ov::runtime::Tensor generate(const std::shared_ptr& node, if (node->get_sampling_ratio() != 0) { const auto &inputShape = node->get_input_shape(0); std::vector blobData(node->get_shape()[0] * 4); - LayerTestsDefinitions::ROIAlignLayerTest::fillCoordTensor(blobData, - inputShape[2], - inputShape[3], - node->get_spatial_scale(), - node->get_sampling_ratio(), - node->get_pooled_h(), - node->get_pooled_w()); + ov::test::ROIAlignLayerTest::fillCoordTensor(blobData, + inputShape[2], + inputShape[3], + node->get_spatial_scale(), + node->get_sampling_ratio(), + node->get_pooled_h(), + node->get_pooled_w()); return ov::test::utils::create_tensor(ov::element::f32, targetShape, blobData); } else { return generate(std::dynamic_pointer_cast(node), port, elemType, targetShape); @@ -551,7 +551,7 @@ ov::runtime::Tensor generate(const std::shared_ptr& node, } case 2: { std::vector roiIdxVector(node->get_shape()[0]); - LayerTestsDefinitions::ROIAlignLayerTest::fillIdxTensor(roiIdxVector, node->get_shape()[0]); + ov::test::ROIAlignLayerTest::fillIdxTensor(roiIdxVector, node->get_shape()[0]); return ov::test::utils::create_tensor(elemType, targetShape, roiIdxVector); } default: @@ -632,7 +632,7 @@ ov::runtime::Tensor generate(const std::shared_ptr& no return Activation::generate(elemType, targetShape); } -ov::runtime::Tensor generate(const std::shared_ptr& node, +ov::runtime::Tensor generate(const std::shared_ptr& node, size_t port, const ov::element::Type& elemType, const ov::Shape& targetShape) { @@ -640,6 +640,10 @@ ov::runtime::Tensor generate(const std::shared_ptr unsigned int m_max_seq_len = 10; return ov::test::utils::create_and_fill_tensor(elemType, targetShape, m_max_seq_len, 0); } + if (port == 3 && node->input(0).get_partial_shape().is_static()) { + auto seq_len = node->input(0).get_shape()[1]; + return ov::test::utils::create_and_fill_tensor(elemType, targetShape, seq_len); + } return generate(std::dynamic_pointer_cast(node), port, elemType, targetShape); } @@ -851,6 +855,28 @@ ov::runtime::Tensor generate(const std::shared_ptr& nod return generate(std::dynamic_pointer_cast(node), port, elemType, targetShape); } +ov::runtime::Tensor generate(const + std::shared_ptr& node, + size_t port, + const ov::element::Type& elemType, + const ov::Shape& targetShape) { + if (port == 1) { + ov::Tensor tensor(elemType, targetShape); + auto data_input_shape = node->input(0).get_shape(); + const auto batch_distrib = data_input_shape[0] - 1; + const auto height = data_input_shape[2] / node->get_spatial_scale(); + const auto width = data_input_shape[3] / node->get_spatial_scale(); + + ov::test::utils::fill_data_roi(tensor, batch_distrib, height, width, 1.0f, true); + return tensor; + } else if (port == 2) { + ov::Tensor tensor(elemType, targetShape); + ov::test::utils::fill_tensor_random(tensor, 1.8, -0.9); + return tensor; + } + return generate(std::static_pointer_cast(node), port, elemType, targetShape); +} + ov::runtime::Tensor generate(const std::shared_ptr& node, size_t port, @@ -1022,6 +1048,7 @@ ov::runtime::Tensor generate(const comparison::fill_tensor(tensor); return tensor; } + ov::runtime::Tensor generate(const std::shared_ptr& node, size_t port, @@ -1032,6 +1059,44 @@ ov::runtime::Tensor generate(const return tensor; } +namespace is_inf { +template +void fill_tensor(ov::Tensor& tensor) { + int range = ov::shape_size(tensor.get_shape()); + float startFrom = -static_cast(range) / 2.f; + + auto pointer = tensor.data(); + testing::internal::Random random(1); + for (size_t i = 0; i < range; i++) { + if (i % 7 == 0) { + pointer[i] = std::numeric_limits::infinity(); + } else if (i % 7 == 1) { + pointer[i] = std::numeric_limits::quiet_NaN(); + } else if (i % 7 == 3) { + pointer[i] = -std::numeric_limits::infinity(); + } else if (i % 7 == 5) { + pointer[i] = -std::numeric_limits::quiet_NaN(); + } else { + pointer[i] = static_cast(startFrom + random.Generate(range)); + } + } +} +} // namespace is_inf + +ov::runtime::Tensor generate(const + std::shared_ptr& node, + size_t port, + const ov::element::Type& elemType, + const ov::Shape& targetShape) { + auto tensor = ov::Tensor(elemType, targetShape); + if (elemType == ov::element::f16) { + is_inf::fill_tensor(tensor); + } else { + is_inf::fill_tensor(tensor); + } + return tensor; +} + namespace color_conversion { enum class ColorFormat { i420, @@ -1141,6 +1206,18 @@ ov::runtime::Tensor generate(const return tensor; } +ov::runtime::Tensor generate(const + std::shared_ptr& node, + size_t port, + const ov::element::Type& elemType, + const ov::Shape& targetShape) { + if (port == 0) { + InputGenerateData inGenData(-5, 10, 7, 222); + return ov::test::utils::create_and_fill_tensor(elemType, targetShape, inGenData.range, inGenData.start_from, inGenData.resolution, inGenData.seed); + } + return generate(std::dynamic_pointer_cast(node), port, elemType, targetShape); +} + template ov::runtime::Tensor generateInput(const std::shared_ptr& node, size_t port, diff --git a/src/tests/functional/shared_test_classes/src/single_layer/bucketize.cpp b/src/tests/functional/shared_test_classes/src/single_layer/bucketize.cpp index 30f162feeb242f..381a2c9f55fcf7 100644 --- a/src/tests/functional/shared_test_classes/src/single_layer/bucketize.cpp +++ b/src/tests/functional/shared_test_classes/src/single_layer/bucketize.cpp @@ -5,7 +5,6 @@ #include "shared_test_classes/single_layer/bucketize.hpp" namespace LayerTestsDefinitions { - std::string BucketizeLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { InferenceEngine::SizeVector dataShape; InferenceEngine::SizeVector bucketsShape; diff --git a/src/tests/functional/shared_test_classes/src/single_layer/gather.cpp b/src/tests/functional/shared_test_classes/src/single_layer/gather.cpp index a9b58ecea05e37..97538823dc52ae 100644 --- a/src/tests/functional/shared_test_classes/src/single_layer/gather.cpp +++ b/src/tests/functional/shared_test_classes/src/single_layer/gather.cpp @@ -178,4 +178,56 @@ void Gather8IndiceScalarLayerTest::SetUp() { function = std::make_shared(results, functionParams, "gather"); } +std::string Gather8withIndicesDataLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + gather7ParamsTuple basicParams; + std::vector indicesData; + std::tie(basicParams, indicesData) = obj.param; + + std::tuple axis_batchIdx; + std::vector indices; + std::vector indicesShape, inputShape; + InferenceEngine::Precision netPrecision; + InferenceEngine::Precision inPrc, outPrc; + InferenceEngine::Layout inLayout, outLayout; + std::string targetName; + std::tie(inputShape, indicesShape, axis_batchIdx, netPrecision, inPrc, outPrc, inLayout, outLayout, targetName) = basicParams; + std::ostringstream result; + result << "IS=" << ov::test::utils::vec2str(inputShape) << "_"; + result << "indicesShape=" << ov::test::utils::vec2str(indicesShape) << "_"; + result << "axis=" << std::get<0>(axis_batchIdx) << "_"; + result << "batchIdx=" << std::get<1>(axis_batchIdx) << "_"; + result << "netPRC=" << netPrecision.name() << "_"; + result << "inPRC=" << inPrc.name() << "_"; + result << "outPRC=" << outPrc.name() << "_"; + result << "inL=" << inLayout << "_"; + result << "outL=" << outLayout << "_"; + result << "trgDev=" << targetName << "_"; + + result << "indicesData=" << ov::test::utils::vec2str(indicesData) << "_"; + + return result.str(); +} + +void Gather8withIndicesDataLayerTest::SetUp() { + gather7ParamsTuple basicParams; + std::vector indicesData; + std::tie(basicParams, indicesData) = GetParam(); + + std::tuple axis_batchIdx; + std::vector indicesShape; + std::vector inputShape; + InferenceEngine::Precision netPrecision; + std::tie(inputShape, indicesShape, axis_batchIdx, netPrecision, inPrc, outPrc, inLayout, outLayout, targetDevice) = basicParams; + int axis = std::get<0>(axis_batchIdx); + int batchIdx = std::get<1>(axis_batchIdx); + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + ov::ParameterVector functionParams {std::make_shared(ngPrc, ov::Shape(inputShape))}; + auto paramOuts = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(functionParams)); + auto indicesNode = ngraph::builder::makeConstant(ngraph::element::i64, indicesShape, indicesData); + auto axisNode = ngraph::opset8::Constant::create(ngraph::element::i64, ngraph::Shape({}), { axis }); + auto gather = std::make_shared(paramOuts[0], indicesNode, axisNode, batchIdx); + ngraph::ResultVector results{ std::make_shared(gather) }; + function = std::make_shared(results, functionParams, "gather"); +} + } // namespace LayerTestsDefinitions diff --git a/src/tests/functional/shared_test_classes/src/single_op/binary_convolution.cpp b/src/tests/functional/shared_test_classes/src/single_op/binary_convolution.cpp new file mode 100644 index 00000000000000..b2f056457a852f --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/binary_convolution.cpp @@ -0,0 +1,79 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/binary_convolution.hpp" + +#include "ov_models/builders.hpp" +#include "common_test_utils/ov_tensor_utils.hpp" + +namespace ov { +namespace test { +std::string BinaryConvolutionLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + binConvSpecificParams bin_conv_params; + ov::element::Type model_type; + std::vector shapes; + std::string target_device; + + std::tie(bin_conv_params, model_type, shapes, target_device) = obj.param; + + ov::op::PadType pad_type; + std::vector kernel, stride, dilation; + std::vector pad_begin, padEnd; + size_t conv_out_channels; + float pad_value; + std::tie(kernel, stride, pad_begin, padEnd, dilation, conv_out_channels, pad_type, pad_value) = bin_conv_params; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "KS=" << ov::test::utils::vec2str(kernel) << "_"; + result << "S=" << ov::test::utils::vec2str(stride) << "_"; + result << "PB=" << ov::test::utils::vec2str(pad_begin) << "_"; + result << "PE=" << ov::test::utils::vec2str(padEnd) << "_"; + result << "D=" << ov::test::utils::vec2str(dilation) << "_"; + result << "O=" << conv_out_channels << "_"; + result << "AP=" << pad_type << "_"; + result << "PV=" << pad_value << "_"; + result << "netPRC=" << model_type.get_type_name() << "_"; + result << "trgDev=" << target_device; + return result.str(); +} + +void BinaryConvolutionLayerTest::SetUp() { + binConvSpecificParams bin_conv_params; + ov::element::Type model_type; + std::vector shapes; + + std::tie(bin_conv_params, model_type, shapes, targetDevice) = this->GetParam(); + init_input_shapes(shapes); + + ov::op::PadType pad_type; + std::vector kernel_size, strides, dilations; + std::vector pads_begin, pads_end; + size_t num_out_channels; + float pad_value; + std::tie(kernel_size, strides, pads_begin, pads_end, dilations, num_out_channels, pad_type, pad_value) = bin_conv_params; + + ov::ParameterVector params{std::make_shared(model_type, inputDynamicShapes.front())}; + params[0]->set_friendly_name("a_data_batch"); + + // TODO: refactor build BinaryConvolution op to accept filters input as Parameter + auto bin_conv = + ngraph::builder::makeBinaryConvolution(params[0], kernel_size, strides, pads_begin, pads_end, dilations, pad_type, num_out_channels, pad_value); + auto result = std::make_shared(bin_conv); + function = std::make_shared(ov::OutputVector{result}, params, "BinaryConvolution"); +} + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/bucketize.cpp b/src/tests/functional/shared_test_classes/src/single_op/bucketize.cpp new file mode 100644 index 00000000000000..bea6eaf18bfb22 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/bucketize.cpp @@ -0,0 +1,61 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/bucketize.hpp" + +#include "common_test_utils/ov_tensor_utils.hpp" + +namespace ov { +namespace test { + +std::string BucketizeLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector shapes; + bool with_right_bound; + ov::element::Type in_data_type, in_buckets_type, model_type; + std::string target_device; + + std::tie(shapes, with_right_bound, in_data_type, in_buckets_type, model_type, target_device) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + if (with_right_bound) + result << "rightIntervalEdge_"; + else + result << "leftIntervalEdge_"; + result << "in_data_type=" << in_data_type.get_type_name() << "_"; + result << "in_buckets_type=" << in_buckets_type.get_type_name() << "_"; + result << "model_type=" << model_type.get_type_name() << "_"; + result << "target_device=" << target_device; + return result.str(); +} + +void BucketizeLayerTest::SetUp() { + std::vector shapes; + bool with_right_bound; + ov::element::Type in_data_type, in_buckets_type, model_type; + + std::tie(shapes, with_right_bound, in_data_type, in_buckets_type, model_type, targetDevice) = this->GetParam(); + init_input_shapes(shapes); + + auto data = std::make_shared(in_data_type, inputDynamicShapes[0]); + data->set_friendly_name("a_data"); + auto buckets = std::make_shared(in_buckets_type, inputDynamicShapes[1]); + buckets->set_friendly_name("b_buckets"); + auto bucketize = std::make_shared(data, buckets, model_type, with_right_bound); + auto result = std::make_shared(bucketize); + function = std::make_shared(result, ov::ParameterVector{data, buckets}, "Bucketize"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/cum_sum.cpp b/src/tests/functional/shared_test_classes/src/single_op/cum_sum.cpp new file mode 100644 index 00000000000000..7adccf0aaff1aa --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/cum_sum.cpp @@ -0,0 +1,54 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/cum_sum.hpp" + +namespace ov { +namespace test { +std::string CumSumLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector shapes; + ov::element::Type model_type; + int64_t axis; + bool exclusive, reverse; + std::string targetDevice; + std::tie(shapes, model_type, axis, exclusive, reverse, targetDevice) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "Precision=" << model_type.get_type_name() << "_"; + result << "Axis=" << axis << "_"; + result << "Exclusive=" << (exclusive ? "TRUE" : "FALSE") << "_"; + result << "Reverse=" << (reverse ? "TRUE" : "FALSE") << "_"; + result << "TargetDevice=" << targetDevice; + return result.str(); +} + +void CumSumLayerTest::SetUp() { + std::vector shapes; + ov::element::Type model_type; + bool exclusive, reverse; + int64_t axis; + std::tie(shapes, model_type, axis, exclusive, reverse, targetDevice) = this->GetParam(); + init_input_shapes(shapes); + + const auto param = std::make_shared(model_type, inputDynamicShapes.front()); + const auto axis_node = std::make_shared(ov::element::Type_t::i64, ov::Shape{}, std::vector{axis}); + const auto cum_sum = std::make_shared(param, axis_node, exclusive, reverse); + + auto result = std::make_shared(cum_sum); + function = std::make_shared(result, ov::ParameterVector{param}, "cumsum"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/deformable_psroi_pooling.cpp b/src/tests/functional/shared_test_classes/src/single_op/deformable_psroi_pooling.cpp new file mode 100644 index 00000000000000..42722c8d4dad01 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/deformable_psroi_pooling.cpp @@ -0,0 +1,110 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/deformable_psroi_pooling.hpp" + +#include "openvino/op/parameter.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/deformable_psroi_pooling.hpp" + +namespace ov { +namespace test { + +std::string DeformablePSROIPoolingLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector shapes; + ov::element::Type model_type; + int64_t outputDim; + int64_t groupSize; + float spatialScale; + std::vector spatialBinsXY; + float trans_std; + int64_t part_size; + std::string target_device; + deformablePSROISpecificParams opParams; + + std::tie(opParams, shapes, model_type, target_device) = obj.param; + std::tie(outputDim, groupSize, spatialScale, spatialBinsXY, + trans_std, part_size) = opParams; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "out_dim=" << outputDim << "_"; + result << "group_size=" << groupSize << "_"; + result << "scale=" << spatialScale << "_"; + result << "bins_x=" << spatialBinsXY[0] << "_"; + result << "bins_y=" << spatialBinsXY[1] << "_"; + result << "trans_std=" << trans_std << "_"; + result << "part_size=" << part_size << "_"; + result << "prec=" << model_type.get_type_name() << "_"; + result << "dev=" << target_device; + return result.str(); +} + +void DeformablePSROIPoolingLayerTest::SetUp() { + std::vector shapes; + ov::element::Type model_type; + int64_t outputDim; + int64_t groupSize; + std::string mode = "bilinear_deformable"; + std::vector spatialBinsXY; + float trans_std, spatial_scale; + int64_t part_size; + deformablePSROISpecificParams opParams; + + std::tie(opParams, shapes, model_type, targetDevice) = this->GetParam(); + std::tie(outputDim, groupSize, spatial_scale, spatialBinsXY, trans_std, part_size) = opParams; + init_input_shapes(shapes); + + ov::ParameterVector params; + std::shared_ptr defomablePSROIPooling; + + if (2 == inputDynamicShapes.size()) { // Test without optional third input (offsets) + params = ov::ParameterVector{std::make_shared(model_type, inputDynamicShapes[0]), + std::make_shared(model_type, inputDynamicShapes[1])}; + + defomablePSROIPooling = std::make_shared(params[0], + params[1], + outputDim, + spatial_scale, + groupSize, + mode, + spatialBinsXY[0], + spatialBinsXY[1], + trans_std, + part_size); + } else { + params = ov::ParameterVector{std::make_shared(model_type, inputDynamicShapes[0]), + std::make_shared(model_type, inputDynamicShapes[1]), + std::make_shared(model_type, inputDynamicShapes[2])}; + + defomablePSROIPooling = std::make_shared(params[0], + params[1], + params[2], + outputDim, + spatial_scale, + groupSize, + mode, + spatialBinsXY[0], + spatialBinsXY[1], + trans_std, + part_size); + } + + auto result = std::make_shared(defomablePSROIPooling); + function = std::make_shared(result, params, "deformable_psroi_pooling"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/depth_to_space.cpp b/src/tests/functional/shared_test_classes/src/single_op/depth_to_space.cpp new file mode 100644 index 00000000000000..d4f45a617a8747 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/depth_to_space.cpp @@ -0,0 +1,72 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/depth_to_space.hpp" + +#include "openvino/op/parameter.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/depth_to_space.hpp" + +namespace ov { +namespace test { +using ov::op::v0::DepthToSpace; + +static inline std::string DepthToSpaceModeToString(const DepthToSpace::DepthToSpaceMode& mode) { + static std::map names = { + {DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST, "BLOCKS_FIRST"}, + {DepthToSpace::DepthToSpaceMode::DEPTH_FIRST, "DEPTH_FIRST"}, + }; + + auto i = names.find(mode); + if (i != names.end()) + return i->second; + else + throw std::runtime_error("Unsupported DepthToSpaceMode"); +} + +std::string DepthToSpaceLayerTest::getTestCaseName(const testing::TestParamInfo &obj) { + std::vector shapes; + DepthToSpace::DepthToSpaceMode mode; + std::size_t block_size; + ov::element::Type model_type; + std::string device_name; + std::tie(shapes, model_type, mode, block_size, device_name) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "inPrc=" << model_type.get_type_name() << "_"; + result << "M=" << DepthToSpaceModeToString(mode) << "_"; + result << "BS=" << block_size << "_"; + result << "targetDevice=" << device_name << "_"; + return result.str(); +} + +void DepthToSpaceLayerTest::SetUp() { + std::vector shapes; + DepthToSpace::DepthToSpaceMode mode; + std::size_t block_size; + ov::element::Type model_type; + std::tie(shapes, model_type, mode, block_size, targetDevice) = this->GetParam(); + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + auto d2s = std::make_shared(param, mode, block_size); + auto result = std::make_shared(d2s); + + function = std::make_shared(result, ov::ParameterVector{param}, "DepthToSpace"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/einsum.cpp b/src/tests/functional/shared_test_classes/src/single_op/einsum.cpp new file mode 100644 index 00000000000000..4912bf6a0afd04 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/einsum.cpp @@ -0,0 +1,61 @@ +// Copyright (C) 2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/einsum.hpp" + +namespace ov { +namespace test { + +std::string EinsumLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + EinsumEquationWithInput equation_with_input; + ov::element::Type model_type; + std::string targetDevice; + std::tie(model_type, equation_with_input, targetDevice) = obj.param; + std::string equation; + std::vector shapes; + std::tie(equation, shapes) = equation_with_input; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "PRC=" << model_type.get_type_name() << "_"; + result << "Eq=" << equation << "_"; + result << "trgDev=" << targetDevice; + return result.str(); +} + +void EinsumLayerTest::SetUp() { + EinsumEquationWithInput equation_with_input; + ov::element::Type model_type; + std::tie(model_type, equation_with_input, targetDevice) = this->GetParam(); + std::string equation; + std::vector shapes; + std::tie(equation, shapes) = equation_with_input; + init_input_shapes(shapes); + + ov::ParameterVector params; + ov::OutputVector param_outs; + for (const auto& shape : inputDynamicShapes) { + auto param = std::make_shared(model_type, shape); + params.push_back(param); + param_outs.push_back(param); + } + + auto einsum = std::make_shared(param_outs, equation); + + auto result = std::make_shared(einsum); + function = std::make_shared(result, params, "einsum"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/eye.cpp b/src/tests/functional/shared_test_classes/src/single_op/eye.cpp new file mode 100644 index 00000000000000..0aae5e1593ef43 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/eye.cpp @@ -0,0 +1,74 @@ +// Copyright (C) 2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#include "shared_test_classes/single_op/eye.hpp" + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "openvino/pass/constant_folding.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/eye.hpp" + +namespace ov { +namespace test { +std::string EyeLayerTest::getTestCaseName(testing::TestParamInfo obj) { + std::string td; + std::vector input_shapes; + ov::element::Type model_type; + std::vector out_batch_shape; + std::vector eye_par; + std::tie(input_shapes, out_batch_shape, eye_par, model_type, td) = obj.param; + std::ostringstream result; + result << "EyeTest_"; + result << "IS=("; + for (const auto& shape : input_shapes) { + result << ov::test::utils::partialShape2str({shape}) << "_"; + } + result << ")"; + result << "rowNum=" << eye_par[0] << "_"; + result << "colNum=" << eye_par[1] << "_"; + result << "diagShift=" << eye_par[2] << "_"; + result << "batchShape=" << ov::test::utils::vec2str(out_batch_shape) << "_"; + result << model_type << "_"; + result << std::to_string(obj.index); + return result.str(); +} + +void EyeLayerTest::SetUp() { + std::vector input_shapes; + int row_num, col_num; + int shift; + std::vector out_batch_shape; + ov::element::Type model_type; + std::vector eye_par; + std::tie(input_shapes, out_batch_shape, eye_par, model_type, targetDevice) = this->GetParam(); + row_num = eye_par[0]; + col_num = eye_par[1]; + shift = eye_par[2]; + + std::shared_ptr eye_operation; + + auto rows_const = std::make_shared(ov::element::i32, input_shapes[0], &row_num); + rows_const->set_friendly_name("rows"); + auto cols_const = std::make_shared(ov::element::i32, input_shapes[1], &col_num); + cols_const->set_friendly_name("cols"); + auto diag_const = std::make_shared(ov::element::i32, input_shapes[2], &shift); + diag_const->set_friendly_name("diagInd"); + + if (!out_batch_shape.empty() && out_batch_shape[0] != 0) { + auto batch_shape_par = std::make_shared(ov::element::i32, + ov::Shape{out_batch_shape.size()}, + out_batch_shape.data()); + batch_shape_par->set_friendly_name("batchShape"); + eye_operation = std::make_shared(rows_const, cols_const, diag_const, batch_shape_par, model_type); + } else { + eye_operation = std::make_shared(rows_const, cols_const, diag_const, model_type); + } + + // Without this call the eye operation will be calculated by CPU and substituted by Constant operator + ov::pass::disable_constant_folding(eye_operation); + auto result = std::make_shared(eye_operation); + function = std::make_shared(result, ov::ParameterVector(), "eye"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/gather.cpp b/src/tests/functional/shared_test_classes/src/single_op/gather.cpp index 0dad09af952720..f4c91752190e19 100644 --- a/src/tests/functional/shared_test_classes/src/single_op/gather.cpp +++ b/src/tests/functional/shared_test_classes/src/single_op/gather.cpp @@ -167,5 +167,76 @@ void Gather8IndiceScalarLayerTest::SetUp() { auto result = std::make_shared(gather); function = std::make_shared(result, ov::ParameterVector{param}, "gather"); } + +std::string Gather8withIndicesDataLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + gather7ParamsTuple basicParams; + std::vector indicesData; + std::tie(basicParams, indicesData) = obj.param; + + std::tuple axis_batch_idx; + std::vector indices; + ov::Shape indices_shape; + std::vector shapes; + ov::element::Type model_type; + std::string device_name; + std::tie(shapes, indices_shape, axis_batch_idx, model_type, device_name) = basicParams; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "axis=" << std::get<0>(axis_batch_idx) << "_"; + result << "batch_idx=" << std::get<1>(axis_batch_idx) << "_"; + result << "indices_shape=" << ov::test::utils::vec2str(indices_shape) << "_"; + result << "netPRC=" << model_type.get_type_name() << "_"; + result << "trgDev=" << device_name << "_"; + + result << "indicesData=" << ov::test::utils::vec2str(indicesData) << "_"; + + return result.str(); +} + +void Gather8withIndicesDataLayerTest::SetUp() { + gather7ParamsTuple basicParams; + std::vector indicesData; + std::tie(basicParams, indicesData) = GetParam(); + + std::tuple axis_batch_idx; + ov::Shape indices_shape; + std::vector shapes; + ov::element::Type model_type; + std::tie(shapes, indices_shape, axis_batch_idx, model_type, targetDevice) = basicParams; + init_input_shapes(shapes); + + int axis = std::get<0>(axis_batch_idx); + int batch_idx = std::get<1>(axis_batch_idx); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + // create indices tensor and fill data + ov::Tensor indices_node_tensor{ov::element::i64, indices_shape}; + auto indices_tensor_data = indices_node_tensor.data(); + for (size_t i = 0; i < shape_size(indices_shape); i++) { + indices_tensor_data[i] = indicesData[i]; + } + + auto indices_node = std::make_shared(indices_node_tensor); + auto axis_node = ov::op::v0::Constant::create(ov::element::i64, ov::Shape(), {axis}); + + auto gather = std::make_shared(param, indices_node, axis_node, batch_idx); + + auto result = std::make_shared(gather); + function = std::make_shared(result, ov::ParameterVector{param}, "gather"); +} + } // namespace test } // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/interpolate.cpp b/src/tests/functional/shared_test_classes/src/single_op/interpolate.cpp new file mode 100644 index 00000000000000..5f5a04bd694b11 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/interpolate.cpp @@ -0,0 +1,177 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/interpolate.hpp" + +#include "common_test_utils/test_enums.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/interpolate.hpp" + +namespace ov { +namespace test { +std::string InterpolateLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + using ov::test::utils::operator<<; + + InterpolateSpecificParams interpolate_params; + ov::element::Type model_type; + std::vector shapes; + ov::Shape target_shape; + std::string target_device; + std::map additional_config; + std::tie(interpolate_params, model_type, shapes, target_shape, target_device, additional_config) = obj.param; + std::vector pad_begin, pad_end; + std::vector axes; + std::vector scales; + bool antialias; + ov::op::v4::Interpolate::InterpolateMode mode; + ov::op::v4::Interpolate::ShapeCalcMode shape_calc_mode; + ov::op::v4::Interpolate::CoordinateTransformMode coordinate_transform_mode; + ov::op::v4::Interpolate::NearestMode nearest_mode; + double cube_coef; + std::tie(mode, shape_calc_mode, coordinate_transform_mode, nearest_mode, antialias, pad_begin, pad_end, cube_coef, axes, scales) = interpolate_params; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "TS=" << ov::test::utils::vec2str(target_shape) << "_"; + result << "InterpolateMode=" << mode << "_"; + result << "ShapeCalcMode=" << shape_calc_mode << "_"; + result << "CoordinateTransformMode=" << coordinate_transform_mode << "_"; + result << "NearestMode=" << nearest_mode << "_"; + result << "cube_coef=" << cube_coef << "_"; + result << "Antialias=" << antialias << "_"; + result << "PB=" << ov::test::utils::vec2str(pad_begin) << "_"; + result << "PE=" << ov::test::utils::vec2str(pad_end) << "_"; + result << "Axes=" << ov::test::utils::vec2str(axes) << "_"; + result << "Scales=" << ov::test::utils::vec2str(scales) << "_"; + result << "netType=" << model_type.get_type_name() << "_"; + result << "trgDev=" << target_device; + return result.str(); +} + +void InterpolateLayerTest::SetUp() { + InterpolateSpecificParams interpolate_params; + ov::element::Type model_type; + std::vector shapes; + ov::Shape target_shape; + std::map additional_config; + std::tie(interpolate_params, model_type, shapes, target_shape, targetDevice, additional_config) = this->GetParam(); + std::vector pad_begin, pad_end; + std::vector axes; + std::vector scales; + bool antialias; + ov::op::v4::Interpolate::InterpolateMode mode; + ov::op::v4::Interpolate::ShapeCalcMode shape_calc_mode; + ov::op::v4::Interpolate::CoordinateTransformMode coordinate_transform_mode; + ov::op::v4::Interpolate::NearestMode nearest_mode; + + configuration.insert(additional_config.begin(), additional_config.end()); + + double cube_coef; + std::tie(mode, shape_calc_mode, coordinate_transform_mode, nearest_mode, antialias, pad_begin, pad_end, cube_coef, axes, scales) = interpolate_params; + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + auto sizes_input = std::make_shared(ov::element::i64, ov::Shape{target_shape.size()}, target_shape); + + auto scales_input = std::make_shared(ov::element::f32, ov::Shape{scales.size()}, scales); + + ov::op::v4::Interpolate::InterpolateAttrs interpolate_attributes{mode, shape_calc_mode, pad_begin, + pad_end, coordinate_transform_mode, nearest_mode, antialias, cube_coef}; + + std::shared_ptr interpolate; + if (axes.empty()) { + interpolate = std::make_shared(param, + sizes_input, + scales_input, + interpolate_attributes); + } else { + auto axesInput = std::make_shared(ov::element::i64, ov::Shape{axes.size()}, axes); + + interpolate = std::make_shared(param, + sizes_input, + scales_input, + axesInput, + interpolate_attributes); + } + auto result = std::make_shared(interpolate); + + function = std::make_shared(result, ov::ParameterVector{param}, "interpolate"); +} + +std::string Interpolate11LayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + return InterpolateLayerTest::getTestCaseName(obj); +} + +namespace { +std::shared_ptr make_scales_or_sizes_input(ov::op::util::InterpolateBase::ShapeCalcMode shape_calc_mode, + const std::vector& sizes, + const std::vector& scales) { + if (shape_calc_mode == ov::op::util::InterpolateBase::ShapeCalcMode::SIZES) + return std::make_shared(ov::element::i64, ov::Shape{sizes.size()}, sizes); + else + return std::make_shared(ov::element::f32, ov::Shape{scales.size()}, scales); +} +} +void Interpolate11LayerTest::SetUp() { + InterpolateSpecificParams interpolate_params; + ov::element::Type model_type; + std::vector shapes; + ov::Shape target_shape; + std::map additional_config; + std::tie(interpolate_params, model_type, shapes, target_shape, targetDevice, additional_config) = this->GetParam(); + std::vector pad_begin, pad_end; + std::vector axes; + std::vector scales; + bool antialias; + ov::op::v4::Interpolate::InterpolateMode mode; + ov::op::v4::Interpolate::ShapeCalcMode shape_calc_mode; + ov::op::v4::Interpolate::CoordinateTransformMode coordinate_transform_mode; + ov::op::v4::Interpolate::NearestMode nearest_mode; + + configuration.insert(additional_config.begin(), additional_config.end()); + + double cube_coef; + std::tie(mode, shape_calc_mode, coordinate_transform_mode, nearest_mode, antialias, pad_begin, pad_end, cube_coef, axes, scales) = interpolate_params; + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + auto scales_orsizes_input = make_scales_or_sizes_input(shape_calc_mode, target_shape, scales); + + ov::op::util::InterpolateBase::InterpolateAttrs interpolate_attributes{mode, shape_calc_mode, pad_begin, + pad_end, coordinate_transform_mode, nearest_mode, antialias, cube_coef}; + + std::shared_ptr interpolate{}; + if (axes.empty()) { + interpolate = std::make_shared(param, + scales_orsizes_input, + interpolate_attributes); + } else { + auto axesInput = std::make_shared(ov::element::i64, ov::Shape{axes.size()}, axes); + + interpolate = std::make_shared(param, + scales_orsizes_input, + axesInput, + interpolate_attributes); + } + + auto result = std::make_shared(interpolate); + function = std::make_shared(result, ov::ParameterVector{param}, "interpolate"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/is_inf.cpp b/src/tests/functional/shared_test_classes/src/single_op/is_inf.cpp new file mode 100644 index 00000000000000..148dc86cdf1250 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/is_inf.cpp @@ -0,0 +1,70 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/is_inf.hpp" + +#include "common_test_utils/ov_tensor_utils.hpp" + +namespace ov { +namespace test { +std::string IsInfLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector shapes; + ov::element::Type model_type; + bool detect_negative, detect_positive; + std::string target_name; + std::map additional_config; + std::tie(shapes, detect_negative, detect_positive, model_type, target_name, additional_config) = obj.param; + std::ostringstream result; + + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << ")_detect_negative=" << (detect_negative ? "True" : "False") << "_"; + result << "detect_positive=" << (detect_positive ? "True" : "False") << "_"; + result << "model_type=" << model_type << "_"; + result << "trgDev=" << target_name; + + for (auto const& config_item : additional_config) { + result << "_config_item=" << config_item.first << "=" << config_item.second; + } + return result.str(); +} + +void IsInfLayerTest::SetUp() { + std::vector shapes; + ElementType model_type; + bool detect_negative, detect_positive; + std::map additional_config; + std::tie(shapes, detect_negative, detect_positive, model_type, targetDevice, additional_config) = this->GetParam(); + + init_input_shapes(shapes); + configuration.insert(additional_config.begin(), additional_config.end()); + + ov::ParameterVector parameters; + for (auto&& shape : inputDynamicShapes) { + parameters.push_back(std::make_shared(model_type, shape)); + } + parameters[0]->set_friendly_name("Data"); + + ov::op::v10::IsInf::Attributes attributes {detect_negative, detect_positive}; + auto is_inf = std::make_shared(parameters[0], attributes); + + ov::ResultVector results; + for (int i = 0; i < is_inf->get_output_size(); i++) { + results.push_back(std::make_shared(is_inf->output(i))); + } + + function = std::make_shared(results, parameters, "IsInf"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/log_softmax.cpp b/src/tests/functional/shared_test_classes/src/single_op/log_softmax.cpp new file mode 100644 index 00000000000000..a7d28a36c6f183 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/log_softmax.cpp @@ -0,0 +1,54 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/log_softmax.hpp" + +namespace ov { +namespace test { +std::string LogSoftmaxLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + ov::element::Type model_type; + std::vector shapes; + int64_t axis; + std::string target_device; + std::tie(model_type, shapes, axis, target_device) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + + result << "modelType=" << model_type.get_type_name() << "_"; + result << "axis=" << axis << "_"; + result << "trgDev=" << target_device; + + return result.str(); +} + +void LogSoftmaxLayerTest::SetUp() { + ov::element::Type model_type; + std::vector shapes; + int64_t axis; + + std::tie(model_type, shapes, axis, targetDevice) = GetParam(); + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + const auto log_softmax = std::make_shared(param, axis); + + auto result = std::make_shared(log_softmax); + + function = std::make_shared(result, ov::ParameterVector{param}, "logSoftmax"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/logical.cpp b/src/tests/functional/shared_test_classes/src/single_op/logical.cpp new file mode 100644 index 00000000000000..d4e73f32cb25da --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/logical.cpp @@ -0,0 +1,74 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/logical.hpp" + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "ov_models/builders.hpp" + +namespace ov { +namespace test { +std::string LogicalLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector shapes; + ov::test::utils::LogicalTypes comparisonOpType; + ov::test::utils::InputLayerType second_input_type; + ov::element::Type model_type; + std::string device_name; + std::map additional_config; + std::tie(shapes, comparisonOpType, second_input_type, model_type, device_name, additional_config) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "comparisonOpType=" << comparisonOpType << "_"; + result << "second_input_type=" << second_input_type << "_"; + result << "netPRC=" << model_type.get_type_name() << "_"; + result << "trgDev=" << device_name; + return result.str(); +} + +void LogicalLayerTest::SetUp() { + std::vector shapes; + ov::test::utils::LogicalTypes logical_op_type; + ov::test::utils::InputLayerType second_input_type; + ov::element::Type model_type; + std::map additional_config; + + std::tie(shapes, logical_op_type, second_input_type, model_type, targetDevice, additional_config) = this->GetParam(); + init_input_shapes(shapes); + + configuration.insert(additional_config.begin(), additional_config.end()); + + ov::ParameterVector params {std::make_shared(model_type, inputDynamicShapes[0])}; + + std::shared_ptr logical_node; + if (ov::test::utils::LogicalTypes::LOGICAL_NOT != logical_op_type) { + std::shared_ptr secondInput; + if (ov::test::utils::InputLayerType::CONSTANT == second_input_type) { + auto tensor = ov::test::utils::create_and_fill_tensor(model_type, targetStaticShapes[0][1]); + secondInput = std::make_shared(tensor); + } else { + auto param = std::make_shared(model_type, inputDynamicShapes[1]); + secondInput = param; + params.push_back(param); + } + logical_node = ngraph::builder::makeLogical(params[0], secondInput, logical_op_type); + } else { + logical_node = std::make_shared(params[0]); + } + + function = std::make_shared(logical_node, params, "Logical"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/loop.cpp b/src/tests/functional/shared_test_classes/src/single_op/loop.cpp new file mode 100644 index 00000000000000..d699fa51d8a550 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/loop.cpp @@ -0,0 +1,125 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/loop.hpp" + +#include "transformations/control_flow/unroll_tensor_iterator.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/loop.hpp" + +namespace ov { +namespace test { +std::string LoopLayerTest::getTestCaseName(const testing::TestParamInfo &obj) { + bool execute_first_iteration; + bool is_body_condition_const; + bool body_condition; // works only if is_body_condition_const == + int64_t trip_count; + std::vector shapes; + std::vector input_types; + ov::element::Type model_type; + std::string targetDevice; + std::tie(execute_first_iteration, is_body_condition_const, body_condition, trip_count, shapes, input_types, model_type, + targetDevice) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "execute_first_iteration" << execute_first_iteration << "_"; + result << "is_body_condition_const=" << is_body_condition_const << "_"; + result << "body_condition=" << body_condition << "_"; + result << "trip_count=" << trip_count << "_"; + result << "types=" << ov::test::utils::vec2str(input_types) << "_"; + result << "modelType=" << model_type.get_type_name() << "_"; + result << "targetDevice=" << targetDevice << "_"; + auto res_str = result.str(); + std::replace(res_str.begin(), res_str.end(), '-', '_'); + return res_str; +} + +void LoopLayerTest::SetUp() { + bool execute_first_iteration; + bool is_body_condition_const; + bool body_condition; // works only if is_body_condition_const == + int64_t trip_count; + std::vector shapes; + std::vector input_types; + ov::element::Type model_type; + std::tie(execute_first_iteration, is_body_condition_const, body_condition, trip_count, shapes, input_types, model_type, + targetDevice) = this->GetParam(); + init_input_shapes(shapes); + + // Example: +/* auto X = std::make_shared(ov::element::f32, ov::Shape{32, 1, 10}); + auto Y = std::make_shared(ov::element::f32, ov::Shape{32, 1, 10}); + auto M = std::make_shared(ov::element::f32, ov::Shape{32, 1, 10});*/ + ov::ParameterVector params; + for (auto&& shape : inputDynamicShapes) { + params.push_back(std::make_shared(model_type, shape)); + } + + //Example: +/* auto Xi = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); + auto Yi = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); + auto M_body = std::make_shared(ov::element::f32, ov::PartialShape::dynamic());*/ + + ov::ParameterVector body_params; + for (int i = 0; i < inputDynamicShapes.size(); i++) { + body_params.push_back(std::make_shared(model_type, ov::PartialShape::dynamic())); + } + + std::shared_ptr body_condition_const; + if (is_body_condition_const) { + body_condition_const = std::make_shared(ov::element::boolean, ov::Shape{1}, body_condition); + } + auto trip_count_const = std::make_shared(ov::element::i64, ov::Shape{1}, trip_count); + auto exec_condition = std::make_shared(ov::element::boolean, ov::Shape{1}, execute_first_iteration); + + // Body + std::shared_ptr Zo = body_params[0]; + for (int i = 1; i < body_params.size(); ++i) { + Zo = std::make_shared(body_params[i], Zo); + } + + auto body = std::make_shared(ov::OutputVector{body_condition_const, Zo}, body_params); + + auto loop = std::make_shared(trip_count_const, exec_condition); + loop->set_function(body); + loop->set_special_body_ports(ov::op::v5::Loop::SpecialBodyPorts{-1, 0}); + + for (int i = 0; i < body_params.size(); ++i) { + if (input_types[i] == LOOP_IN_TYPE::INVARIANT) { + loop->set_invariant_input(body_params[i], params[i]); + } else if (input_types[i] == LOOP_IN_TYPE::MERGED) { + // todo: support several merged inputs + // now supported only one in this sample + loop->set_merged_input(body_params[i], params[i], Zo); + } + } + + // Output 0 is last Zo + auto out0 = loop->get_iter_value(body_condition_const, -1); + auto out1 = loop->get_iter_value(Zo, -1); + // Output 1 is concat of Zos + // start=0, stride=1, part_size=1, end=-1, axis=1 + auto out2 = loop->get_concatenated_slices(Zo, 0, 1, 1, -1, 1); + + auto result0 = std::make_shared(out0); + auto result1 = std::make_shared(out1); + auto result2 = std::make_shared(out2); + function = std::make_shared(ov::ResultVector{result0, result1, result2}, params, "loop"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/lrn.cpp b/src/tests/functional/shared_test_classes/src/single_op/lrn.cpp new file mode 100644 index 00000000000000..94604dcb5f6887 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/lrn.cpp @@ -0,0 +1,66 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/lrn.hpp" + +#include "openvino/op/parameter.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/lrn.hpp" + +namespace ov { +namespace test { +std::string LrnLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + double alpha, beta, bias; + size_t size; + std::vector axes; + ov::element::Type model_type; + std::vector shapes; + std::string targetDevice; + std::tie(alpha, beta, bias, size, axes, model_type, shapes, targetDevice) = obj.param; + + std::ostringstream result; + const char separator = '_'; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "Alpha=" << alpha << separator; + result << "Beta=" << beta << separator; + result << "Bias=" << bias << separator; + result << "Size=" << size << separator; + result << "Axes=" << ov::test::utils::vec2str(axes) << separator; + result << "netPRC=" << model_type.get_type_name() << separator; + result << "trgDev=" << targetDevice; + + return result.str(); +} + +void LrnLayerTest::SetUp() { + ov::element::Type model_type; + std::vector shapes; + double alpha, beta, bias; + size_t size; + std::vector axes; + std::tie(alpha, beta, bias, size, axes, model_type, shapes, targetDevice) = GetParam(); + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + auto axes_node = std::make_shared(ov::element::i64, ov::Shape{axes.size()}, axes.data()); + + auto lrn = std::make_shared(param, axes_node, alpha, beta, bias, size); + + auto result = std::make_shared(lrn); + function = std::make_shared(result, ov::ParameterVector{param}, "lrn"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/lstm_cell.cpp b/src/tests/functional/shared_test_classes/src/single_op/lstm_cell.cpp new file mode 100644 index 00000000000000..4c717bdab3e247 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/lstm_cell.cpp @@ -0,0 +1,141 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/lstm_cell.hpp" + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "transformations/op_conversions/lstm_cell_decomposition.hpp" +#include "openvino/pass/manager.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/lstm_cell.hpp" + +namespace ov { +namespace test { +using ov::test::utils::InputLayerType; + +std::string LSTMCellTest::getTestCaseName(const testing::TestParamInfo &obj) { + 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; + InputLayerType WType; + InputLayerType RType; + InputLayerType BType; + ov::element::Type model_type; + std::string targetDevice; + std::tie(should_decompose, batch, hidden_size, input_size, activations, clip, WType, RType, BType, + model_type, targetDevice) = obj.param; + std::vector> input_shapes = { + {{batch, input_size}, {batch, hidden_size}, {batch, hidden_size}, {4 * hidden_size, input_size}, + {4 * hidden_size, hidden_size}, {4 * hidden_size}}, + }; + std::ostringstream result; + result << "decomposition" << should_decompose << "_"; + result << "batch=" << batch << "_"; + result << "hidden_size=" << hidden_size << "_"; + result << "input_size=" << input_size << "_"; + result << "IS=" << ov::test::utils::vec2str(input_shapes) << "_"; + result << "activations=" << ov::test::utils::vec2str(activations) << "_"; + result << "clip=" << clip << "_"; + result << "WType=" << WType << "_"; + result << "RType=" << RType << "_"; + result << "BType=" << BType << "_"; + result << "modelType=" << model_type.get_type_name() << "_"; + result << "targetDevice=" << targetDevice << "_"; + return result.str(); +} + +void LSTMCellTest::SetUp() { + 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; + InputLayerType WType; + InputLayerType RType; + InputLayerType BType; + ov::element::Type model_type; + std::tie(should_decompose, batch, hidden_size, input_size, activations, clip, WType, RType, BType, + model_type, targetDevice) = this->GetParam(); + + std::vector input_shapes = { + {batch, input_size}, + {batch, hidden_size}, + {batch, hidden_size}, + {4 * hidden_size, input_size}, + {4 * hidden_size, hidden_size}, + {4 * hidden_size} + }; + + std::vector param_shapes{input_shapes[0], input_shapes[1], input_shapes[2]}; + if (WType == InputLayerType::PARAMETER) + param_shapes.push_back(input_shapes[3]); + + if (RType == InputLayerType::PARAMETER) + param_shapes.push_back(input_shapes[4]); + + if (BType == InputLayerType::PARAMETER) + param_shapes.push_back(input_shapes[5]); + init_input_shapes(ov::test::static_shapes_to_test_representation(param_shapes)); + + ov::ParameterVector params{std::make_shared(model_type, inputDynamicShapes[0]), + std::make_shared(model_type, inputDynamicShapes[1]), + std::make_shared(model_type, inputDynamicShapes[2])}; + + + ov::NodeVector inputs{params[0], params[1], params[2]}; + if (WType == InputLayerType::PARAMETER) { + auto param = std::make_shared(model_type, inputDynamicShapes[params.size()]); + params.push_back(param); + inputs.push_back(param); + } else { + auto tensor = ov::test::utils::create_and_fill_tensor(model_type, input_shapes[3]); + auto constant = std::make_shared(tensor); + inputs.push_back(constant); + } + + if (RType == InputLayerType::PARAMETER) { + auto param = std::make_shared(model_type, inputDynamicShapes[params.size()]); + params.push_back(param); + inputs.push_back(param); + } else { + auto tensor = ov::test::utils::create_and_fill_tensor(model_type, input_shapes[4]); + auto constant = std::make_shared(tensor); + inputs.push_back(constant); + } + + if (BType == InputLayerType::PARAMETER) { + auto param = std::make_shared(model_type, inputDynamicShapes[params.size()]); + params.push_back(param); + inputs.push_back(param); + } else { + auto tensor = ov::test::utils::create_and_fill_tensor(model_type, input_shapes[5]); + auto constant = std::make_shared(tensor); + inputs.push_back(constant); + } + + auto lstm_cell = std::make_shared(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], + hidden_size, activations, + activations_alpha, activations_beta, clip); + + ov::ResultVector results{std::make_shared(lstm_cell->output(0)), + std::make_shared(lstm_cell->output(1))}; + function = std::make_shared(results, params, "lstm_cell"); + if (should_decompose) { + ov::pass::Manager m; + m.register_pass(); + m.run_passes(function); + } +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/lstm_sequence.cpp b/src/tests/functional/shared_test_classes/src/single_op/lstm_sequence.cpp new file mode 100644 index 00000000000000..514557ead7a72d --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/lstm_sequence.cpp @@ -0,0 +1,175 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/lstm_sequence.hpp" + +#include "transformations/op_conversions/bidirectional_sequences_decomposition.hpp" +#include "transformations/op_conversions/convert_sequences_to_tensor_iterator.hpp" +#include "openvino/pass/visualize_tree.hpp" +#include "openvino/pass/manager.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/lstm_sequence.hpp" +#include "common_test_utils/ov_tensor_utils.hpp" +#include "ov_models/utils/ov_helpers.hpp" + + +namespace ov { +namespace test { +using ov::test::utils::SequenceTestsMode; +using ov::test::utils::InputLayerType; + +std::string LSTMSequenceTest::getTestCaseName(const testing::TestParamInfo &obj) { + SequenceTestsMode mode; + 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; + ov::op::RecurrentSequenceDirection direction; + InputLayerType WRBType; + ov::element::Type model_type; + std::string targetDevice; + std::tie(mode, seq_lengths, batch, hidden_size, input_size, activations, clip, direction, + WRBType, model_type, targetDevice) = obj.param; + std::vector> input_shapes = { + {{batch, input_size}, {batch, hidden_size}, {batch, hidden_size}, {4 * hidden_size, input_size}, + {4 * hidden_size, hidden_size}, {4 * hidden_size}}, + }; + std::ostringstream result; + result << "mode=" << mode << "_"; + result << "seq_lengths=" << seq_lengths << "_"; + result << "batch=" << batch << "_"; + result << "hidden_size=" << hidden_size << "_"; + result << "input_size=" << input_size << "_"; + result << "IS=" << ov::test::utils::vec2str(input_shapes) << "_"; + result << "activations=" << ov::test::utils::vec2str(activations) << "_"; + result << "direction=" << direction << "_"; + result << "clip=" << clip << "_"; + result << "WRBType=" << WRBType << "_"; + result << "modelType=" << model_type.get_type_name() << "_"; + result << "targetDevice=" << targetDevice << "_"; + return result.str(); +} + +void LSTMSequenceTest::SetUp() { + SequenceTestsMode mode; + 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; + ov::op::RecurrentSequenceDirection direction; + InputLayerType WRBType; + ov::element::Type model_type; + std::tie(mode, seq_lengths, batch, hidden_size, input_size, activations, clip, direction, + WRBType, model_type, targetDevice) = this->GetParam(); + size_t num_directions = direction == ov::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}, + }; + + const auto& W_shape = inputShapes[4]; + const auto& R_shape = inputShapes[5]; + const auto& B_shape = inputShapes[6]; + + std::vector param_shapes{inputShapes[0], inputShapes[1], inputShapes[2]}; + std::vector const_input_shapes; + if (mode == SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_PARAM || + mode == SequenceTestsMode::CONVERT_TO_TI_RAND_SEQ_LEN_PARAM || + mode == SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_PARAM) { + param_shapes.push_back(inputShapes[3]); + } + + if (WRBType == InputLayerType::PARAMETER) { + param_shapes.push_back(inputShapes[4]); + param_shapes.push_back(inputShapes[5]); + param_shapes.push_back(inputShapes[6]); + } + init_input_shapes(ov::test::static_shapes_to_test_representation(param_shapes)); + + ov::ParameterVector params{std::make_shared(model_type, inputDynamicShapes[0]), + std::make_shared(model_type, inputDynamicShapes[1]), + std::make_shared(model_type, inputDynamicShapes[2])}; + + std::shared_ptr seq_lengths_node; + if (mode == SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_PARAM || + mode == SequenceTestsMode::CONVERT_TO_TI_RAND_SEQ_LEN_PARAM || + mode == SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_PARAM) { + auto param = std::make_shared(ov::element::i64, inputDynamicShapes[3]); + seq_lengths_node = param; + seq_lengths_node->set_friendly_name("seq_lengths"); + params.push_back(param); + } else if (mode == SequenceTestsMode::CONVERT_TO_TI_RAND_SEQ_LEN_CONST || + mode == SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_CONST) { + auto tensor = ov::test::utils::create_and_fill_tensor(ov::element::i64, inputShapes[3], seq_lengths); + seq_lengths_node = std::make_shared(tensor); + } else { + std::vector lengths(inputShapes[3][0], seq_lengths); + seq_lengths_node = ov::op::v0::Constant::create(ov::element::i64, inputShapes[3], lengths); + } + + std::shared_ptr W, R, B; + if (WRBType == InputLayerType::PARAMETER) { + auto param_num = inputDynamicShapes.size(); + const auto W_param = std::make_shared(model_type, inputDynamicShapes[param_num - 3]); + const auto R_param = std::make_shared(model_type, inputDynamicShapes[param_num - 2]); + const auto B_param = std::make_shared(model_type, inputDynamicShapes[param_num - 1]); + W = W_param; + R = R_param; + B = B_param; + params.push_back(W_param); + params.push_back(R_param); + params.push_back(B_param); + } else { + auto tensor_w = ov::test::utils::create_and_fill_tensor(model_type, W_shape); + W = std::make_shared(tensor_w); + + auto tensor_r = ov::test::utils::create_and_fill_tensor(model_type, R_shape); + R = std::make_shared(tensor_r); + + auto tensor_b = ov::test::utils::create_and_fill_tensor(model_type, B_shape); + B = std::make_shared(tensor_b); + } + + auto lstm_sequence = std::make_shared(params[0], params[1], params[2], seq_lengths_node, W, R, B, hidden_size, direction, + std::vector{}, std::vector{}, activations, clip); + + ov::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 = mode == SequenceTestsMode::PURE_SEQ || + mode == SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_PARAM || + mode == SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_CONST; + + if (!is_pure_sequence) { + ov::pass::Manager manager; + if (direction == ov::op::RecurrentSequenceDirection::BIDIRECTIONAL) + manager.register_pass(); + manager.register_pass(); + manager.run_passes(function); + bool ti_found = ngraph::helpers::is_tensor_iterator_exist(function); + EXPECT_EQ(ti_found, true); + } else { + bool ti_found = ngraph::helpers::is_tensor_iterator_exist(function); + EXPECT_EQ(ti_found, false); + } +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/mat_mul.cpp b/src/tests/functional/shared_test_classes/src/single_op/mat_mul.cpp new file mode 100644 index 00000000000000..4414febffd265b --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/mat_mul.cpp @@ -0,0 +1,81 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/mat_mul.hpp" + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/matmul.hpp" + +namespace ov { +namespace test { +using ov::test::utils::InputLayerType; + +std::string MatMulLayerTest::getTestCaseName(const testing::TestParamInfo &obj) { + std::vector shapes; + std::pair transpose; + ov::element::Type model_type; + InputLayerType secondary_input_type; + std::string target_device; + std::map additional_config; + std::tie(shapes, transpose, model_type, secondary_input_type, target_device, additional_config) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "transpose_a=" << transpose.first << "_"; + result << "transpose_b=" << transpose.second << "_"; + result << "secondary_input_type=" << secondary_input_type << "_"; + result << "modelType=" << model_type.get_type_name() << "_"; + result << "trgDev=" << target_device; + result << "config=("; + for (const auto& configEntry : additional_config) { + result << configEntry.first << ", " << configEntry.second << ";"; + } + result << ")"; + return result.str(); +} + +void MatMulLayerTest::SetUp() { + std::vector shapes; + std::pair transpose; + ov::element::Type model_type; + InputLayerType secondary_input_type; + std::map additional_config; + std::tie(shapes, transpose, model_type, secondary_input_type, targetDevice, additional_config) = this->GetParam(); + init_input_shapes(shapes); + configuration.insert(additional_config.begin(), additional_config.end()); + + ov::ParameterVector params {std::make_shared(model_type, inputDynamicShapes[0])}; + ov::NodeVector inputs {params[0]}; + + if (InputLayerType::PARAMETER == secondary_input_type) { + auto param = std::make_shared(model_type, inputDynamicShapes[1]); + params.push_back(param); + inputs.push_back(param); + } else { + auto tensor = ov::test::utils::create_and_fill_tensor(model_type, targetStaticShapes[0][1]); + auto constant = std::make_shared(tensor); + inputs.push_back(constant); + } + auto mat_mul = std::make_shared(inputs[0], inputs[1], transpose.first, transpose.second); + + auto result = std::make_shared(mat_mul); + + function = std::make_shared(result, params, "MatMul"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/minimum_maximum.cpp b/src/tests/functional/shared_test_classes/src/single_op/minimum_maximum.cpp new file mode 100644 index 00000000000000..9ab3c48284c460 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/minimum_maximum.cpp @@ -0,0 +1,85 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/minimum_maximum.hpp" + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/minimum.hpp" +#include "openvino/op/maximum.hpp" + + +namespace ov { +namespace test { +using ov::test::utils::InputLayerType; +using ov::test::utils::MinMaxOpType; + +std::string MaxMinLayerTest::getTestCaseName(const testing::TestParamInfo &obj) { + std::vector shapes; + ov::element::Type model_type; + std::string target_name; + InputLayerType second_input_type; + MinMaxOpType op_type; + std::tie(shapes, op_type, model_type, second_input_type, target_name) = obj.param; + std::ostringstream result; + + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "OpType=" << op_type << "_"; + result << "SecondaryInputType=" << second_input_type << "_"; + result << "netPRC=" << model_type.get_type_name() << "_"; + result << "trgDev=" << target_name << "_"; + return result.str(); +} + +void MaxMinLayerTest::SetUp() { + std::vector shapes; + ov::element::Type model_type; + InputLayerType second_input_type; + MinMaxOpType op_type; + std::tie(shapes, op_type, model_type, second_input_type, targetDevice) = this->GetParam(); + init_input_shapes(shapes); + + ov::ParameterVector params {std::make_shared(model_type, inputDynamicShapes[0])}; + ov::NodeVector inputs {params[0]}; + + if (InputLayerType::PARAMETER == second_input_type) { + auto param = std::make_shared(model_type, inputDynamicShapes[1]); + params.push_back(param); + inputs.push_back(param); + } else { + auto tensor = ov::test::utils::create_and_fill_tensor(model_type, targetStaticShapes[0][1]); + auto constant = std::make_shared(tensor); + inputs.push_back(constant); + } + + std::shared_ptr min_max_op; + switch (op_type) { + case MinMaxOpType::MINIMUM: + min_max_op = std::make_shared(inputs[0], inputs[1]); + break; + case MinMaxOpType::MAXIMUM: + min_max_op = std::make_shared(inputs[0], inputs[1]); + break; + default: + throw std::logic_error("Unsupported operation type"); + } + + auto result = std::make_shared(min_max_op); + function = std::make_shared(result, params, "MinMax"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/mvn.cpp b/src/tests/functional/shared_test_classes/src/single_op/mvn.cpp new file mode 100644 index 00000000000000..666ded5cdd1acb --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/mvn.cpp @@ -0,0 +1,135 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/mvn.hpp" + +#include "openvino/op/parameter.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/mvn.hpp" + +namespace ov { +namespace test { +std::string Mvn1LayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector shapes; + ov::element::Type model_type; + ov::AxisSet axes; + bool across_channels, normalize_variance; + double eps; + std::string target_device; + std::tie(shapes, model_type, axes, across_channels, normalize_variance, eps, target_device) = obj.param; + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "ModelType=" << model_type.get_type_name() << "_"; + if (!axes.empty()) { + result << "ReductionAxes=" << ov::test::utils::vec2str(axes.to_vector()) << "_"; + } else { + result << "across_channels=" << (across_channels ? "TRUE" : "FALSE") << "_"; + } + result << "normalize_variance=" << (normalize_variance ? "TRUE" : "FALSE") << "_"; + result << "Epsilon=" << eps << "_"; + result << "TargetDevice=" << target_device; + return result.str(); +} + +void Mvn1LayerTest::SetUp() { + std::vector shapes; + ov::element::Type model_type; + ov::AxisSet axes; + bool across_channels, normalize_variance; + double eps; + std::tie(shapes, model_type, axes, across_channels, normalize_variance, eps, targetDevice) = this->GetParam(); + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + std::shared_ptr mvn; + + if (axes.empty()) { + mvn = std::make_shared(param, across_channels, normalize_variance, eps); + + // OpenVINO MVN implementation implicitly adds 0th dimension to reduction axes set which is not valid behavior + ov::AxisSet axes; + const size_t startAxis = across_channels ? 1 : 2; + const size_t numOfDims = param->output(0).get_partial_shape().size(); + for (size_t i = startAxis; i < numOfDims; i++) + axes.insert(i); + mvn->set_reduction_axes(axes); + } else { + mvn = std::make_shared(param, axes, normalize_variance, eps); + } + + auto result = std::make_shared(mvn); + function = std::make_shared(result, ov::ParameterVector{param}, "MVN1"); +} + +std::string Mvn6LayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector shapes; + ov::element::Type model_type; + ov::element::Type axis_type; + std::vector axes; + bool normalize_variance; + float eps; + std::string eps_mode; + std::string target_device; + std::tie(shapes, model_type, axis_type, axes, normalize_variance, eps, eps_mode, target_device) = obj.param; + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "ModelType=" << model_type.get_type_name() << "_"; + result << "AxType=" << axis_type.get_type_name() << "_"; + result << "Ax=" << ov::test::utils::vec2str(axes) << "_"; + result << "NormVariance=" << (normalize_variance ? "TRUE" : "FALSE") << "_"; + result << "Eps=" << eps << "_"; + result << "EM=" << eps_mode << "_"; + result << "TargetDevice=" << target_device; + return result.str(); +} + +void Mvn6LayerTest::SetUp() { + std::vector shapes; + ov::element::Type model_type; + ov::element::Type axis_type; + std::vector axes; + bool normalize_variance; + float eps; + std::string eps_mode; + std::tie(shapes, model_type, axis_type, axes, normalize_variance, eps, eps_mode, targetDevice) = this->GetParam(); + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + auto axes_node = ov::op::v0::Constant::create(axis_type, ov::Shape{axes.size()}, axes); + + ov::op::MVNEpsMode nEpsMode = ov::op::MVNEpsMode::INSIDE_SQRT; + if (eps_mode == "outside_sqrt") + nEpsMode = ov::op::MVNEpsMode::OUTSIDE_SQRT; + auto mvn = std::make_shared(param, axes_node, normalize_variance, eps, nEpsMode); + + auto result = std::make_shared(mvn); + function = std::make_shared(result, ov::ParameterVector{param}, "MVN6"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/nonzero.cpp b/src/tests/functional/shared_test_classes/src/single_op/nonzero.cpp new file mode 100644 index 00000000000000..610148b9127960 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/nonzero.cpp @@ -0,0 +1,57 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/nonzero.hpp" + +#include "openvino/op/parameter.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/non_zero.hpp" + +namespace ov { +namespace test { + +std::string NonZeroLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector shapes; + ov::element::Type model_type; + std::string target_device; + std::map additional_config; + std::tie(shapes, model_type, target_device, additional_config) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "inPRC=" << model_type.get_type_name() << "_"; + result << "targetDevice=" << target_device; + return result.str(); +} + +void NonZeroLayerTest::SetUp() { + std::vector shapes; + ov::element::Type model_type; + std::map additional_config; + std::tie(shapes, model_type, targetDevice, additional_config) = GetParam(); + configuration.insert(additional_config.cbegin(), additional_config.cend()); + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + auto non_zero = std::make_shared(param); + + auto result = std::make_shared(non_zero); + + function = std::make_shared(result, ov::ParameterVector{param}, "non_zero"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/normalize_l2.cpp b/src/tests/functional/shared_test_classes/src/single_op/normalize_l2.cpp new file mode 100644 index 00000000000000..b3db915a59a035 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/normalize_l2.cpp @@ -0,0 +1,62 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/normalize_l2.hpp" + +#include "openvino/op/parameter.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/normalize_l2.hpp" + +namespace ov { +namespace test { +std::string NormalizeL2LayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector axes; + float eps; + ngraph::op::EpsMode eps_mode; + std::vector shapes; + ov::element::Type model_type; + std::string targetDevice; + std::tie(axes, eps, eps_mode, shapes, model_type, targetDevice) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "axes=" << ov::test::utils::vec2str(axes) << "_"; + result << "eps=" << eps << "_"; + result << "eps_mode=" << eps_mode << "_"; + result << "netPRC=" << model_type.get_type_name() << "_"; + result << "targetDevice=" << targetDevice; + return result.str(); +} + +void NormalizeL2LayerTest::SetUp() { + std::vector shapes; + std::vector axes; + float eps; + ngraph::op::EpsMode eps_mode; + ov::element::Type model_type; + std::tie(axes, eps, eps_mode, shapes, model_type, targetDevice) = this->GetParam(); + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + auto norm_axes = std::make_shared(ov::element::i64, ov::Shape{axes.size()}, axes); + auto norm = std::make_shared(param, norm_axes, eps, eps_mode); + + auto result = std::make_shared(norm); + function = std::make_shared(result, ov::ParameterVector{param}, "NormalizeL2"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/one_hot.cpp b/src/tests/functional/shared_test_classes/src/single_op/one_hot.cpp new file mode 100644 index 00000000000000..273c51c00cef9c --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/one_hot.cpp @@ -0,0 +1,71 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/one_hot.hpp" + +#include "openvino/op/parameter.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/one_hot.hpp" + +namespace ov { +namespace test { +std::string OneHotLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + int64_t axis; + ov::element::Type depth_type, set_type; + int64_t depth_val; + float on_val, off_val; + ov::element::Type model_type; + std::vector shapes; + std::string targetDevice; + + std::tie(depth_type, depth_val, set_type, on_val, off_val, axis, model_type, shapes, targetDevice) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "depthType=" << depth_type << "_"; + result << "depth=" << depth_val << "_"; + result << "SetValueType=" << set_type << "_"; + result << "onValue=" << on_val << "_"; + result << "offValue=" << off_val << "_"; + result << "axis=" << axis << "_"; + + result << "netPRC=" << model_type.get_type_name() << "_"; + result << "trgDev=" << targetDevice; + return result.str(); +} + +void OneHotLayerTest::SetUp() { + int64_t axis; + ov::element::Type depth_type, set_type; + int64_t depth_val; + float on_val, off_val; + ov::element::Type model_type; + std::vector shapes; + std::tie(depth_type, depth_val, set_type, on_val, off_val, axis, model_type, shapes, targetDevice) = this->GetParam(); + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + auto depth_const = std::make_shared(depth_type, ov::Shape{}, depth_val); + auto on_value_const = std::make_shared(set_type, ov::Shape{}, on_val); + auto off_value_const = std::make_shared(set_type, ov::Shape{}, off_val); + auto onehot = std::make_shared(param, depth_const, on_value_const, off_value_const, axis); + + auto result = std::make_shared(onehot); + function = std::make_shared(result, ov::ParameterVector{param}, "OneHot"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/pad.cpp b/src/tests/functional/shared_test_classes/src/single_op/pad.cpp new file mode 100644 index 00000000000000..a62b33ec21263c --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/pad.cpp @@ -0,0 +1,85 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/pad.hpp" + +#include "openvino/op/parameter.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/pad.hpp" + +namespace ov { +namespace test { +std::string PadLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + ov::element::Type model_type; + std::vector shapes; + std::vector pads_begin, pads_end; + ov::op::PadMode pad_mode; + float arg_pad_value; + std::string target_device; + std::tie(pads_begin, pads_end, arg_pad_value, pad_mode, model_type, shapes, target_device) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "PadsBegin=" << ov::test::utils::vec2str(pads_begin) << "_"; + result << "PadsEnd=" << ov::test::utils::vec2str(pads_end) << "_"; + if (pad_mode == ov::op::PadMode::CONSTANT) { + result << "Value=" << arg_pad_value << "_"; + } + result << "PadMode=" << pad_mode << "_"; + result << "ModelType=" << model_type.get_type_name() << "_"; + result << "TrgDev=" << target_device; + return result.str(); +} + +void PadLayerTest::SetUp() { + ov::element::Type model_type; + std::vector shapes; + std::vector pads_begin, pads_end; + ov::op::PadMode pad_mode; + float arg_pad_value; + std::tie(pads_begin, pads_end, arg_pad_value, pad_mode, model_type, shapes, targetDevice) = this->GetParam(); + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + auto pads_begin_const = std::make_shared(ov::element::i64, ov::Shape{pads_begin.size()}, pads_begin.data()); + auto pads_end_const = std::make_shared(ov::element::i64, ov::Shape{pads_end.size()}, pads_end.data()); + auto arg_pad_value_const = std::make_shared(model_type, ov::Shape{}, &arg_pad_value); + + auto pad = create_pad_op(param, pads_begin_const, pads_end_const, arg_pad_value_const, pad_mode); + + auto result = std::make_shared(pad); + + function = std::make_shared(result, ov::ParameterVector{param}, "pad"); +} + +std::shared_ptr PadLayerTest::create_pad_op(const std::shared_ptr& data, + const std::shared_ptr& pads_begin, + const std::shared_ptr& pads_end, + const std::shared_ptr& arg_pad_value, + ov::op::PadMode pad_mode) const { + return std::make_shared(data, pads_begin, pads_end, arg_pad_value, pad_mode); +} + +std::shared_ptr Pad12LayerTest::create_pad_op(const std::shared_ptr& data, + const std::shared_ptr& pads_begin, + const std::shared_ptr& pads_end, + const std::shared_ptr& arg_pad_value, + ov::op::PadMode pad_mode) const { + return std::make_shared(data, pads_begin, pads_end, arg_pad_value, pad_mode); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/pooling.cpp b/src/tests/functional/shared_test_classes/src/single_op/pooling.cpp new file mode 100644 index 00000000000000..c86f8a2217fee5 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/pooling.cpp @@ -0,0 +1,170 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/pooling.hpp" + +#include "ov_models/builders.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/avg_pool.hpp" +#include "openvino/op/max_pool.hpp" + +namespace ov { +namespace test { +using ov::test::utils::PoolingTypes; + +std::string PoolingLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + poolSpecificParams pool_params; + ov::element::Type model_type; + std::vector shapes; + std::string targetDevice; + std::tie(pool_params, model_type, shapes, targetDevice) = obj.param; + PoolingTypes pool_type; + std::vector kernel, stride; + std::vector pad_begin, pad_end; + ov::op::PadType pad_type; + ov::op::RoundingType rounding_type; + bool excludePad; + std::tie(pool_type, kernel, stride, pad_begin, pad_end, rounding_type, pad_type, excludePad) = pool_params; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + switch (pool_type) { + case PoolingTypes::MAX: + result << "MaxPool_"; + break; + case PoolingTypes::AVG: + result << "AvgPool_"; + result << "ExcludePad=" << excludePad << "_"; + break; + } + result << "K" << ov::test::utils::vec2str(kernel) << "_"; + result << "S" << ov::test::utils::vec2str(stride) << "_"; + result << "PB" << ov::test::utils::vec2str(pad_begin) << "_"; + result << "PE" << ov::test::utils::vec2str(pad_end) << "_"; + result << "Rounding=" << rounding_type << "_"; + result << "AutoPad=" << pad_type << "_"; + result << "modelType=" << model_type.get_type_name() << "_"; + result << "trgDev=" << targetDevice; + return result.str(); +} + +void PoolingLayerTest::SetUp() { + poolSpecificParams pool_params; + std::vector shapes; + ov::element::Type model_type; + std::tie(pool_params, model_type, shapes, targetDevice) = this->GetParam(); + PoolingTypes pool_type; + std::vector kernel, stride; + std::vector pad_begin, pad_end; + ov::op::PadType pad_type; + ov::op::RoundingType rounding_type; + bool excludePad; + std::tie(pool_type, kernel, stride, pad_begin, pad_end, rounding_type, pad_type, excludePad) = pool_params; + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + std::shared_ptr pooling = ngraph::builder::makePooling(param, + stride, + pad_begin, + pad_end, + kernel, + rounding_type, + pad_type, + excludePad, + pool_type); + + auto result = std::make_shared(pooling); + function = std::make_shared(result, ov::ParameterVector{param}, "pooling"); +} + + +std::string MaxPoolingV8LayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + maxPoolV8SpecificParams pool_params; + ov::element::Type model_type; + std::vector shapes; + std::string target_device; + std::tie(pool_params, model_type, shapes, target_device) = obj.param; + std::vector kernel, stride, dilation; + std::vector pad_begin, pad_end; + ov::op::PadType pad_type; + ov::op::RoundingType rounding_type; + ov::element::Type index_element_type; + int64_t axis; + std::tie(kernel, stride, dilation, pad_begin, pad_end, index_element_type, axis, rounding_type, pad_type) = pool_params; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "K" << ov::test::utils::vec2str(kernel) << "_"; + result << "S" << ov::test::utils::vec2str(stride) << "_"; + result << "D" << ov::test::utils::vec2str(dilation) << "_"; + result << "PB" << ov::test::utils::vec2str(pad_begin) << "_"; + result << "PE" << ov::test::utils::vec2str(pad_end) << "_"; + result << "IET" << index_element_type << "_"; + result << "A" << axis << "_"; + result << "Rounding=" << rounding_type << "_"; + result << "AutoPad=" << pad_type << "_"; + result << "modelType=" << model_type.get_type_name() << "_"; + result << "trgDev=" << target_device; + return result.str(); +} + +void MaxPoolingV8LayerTest::SetUp() { + maxPoolV8SpecificParams pool_params; + ov::element::Type model_type; + std::vector shapes; + std::tie(pool_params, model_type, shapes, targetDevice) = this->GetParam(); + std::vector kernel, stride, dilation; + std::vector pad_begin, pad_end; + ov::op::PadType pad_type; + ov::op::RoundingType rounding_type; + ov::element::Type index_element_type; + int64_t axis; + std::tie(kernel, stride, dilation, pad_begin, pad_end, index_element_type, axis, rounding_type, pad_type) = pool_params; + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + std::shared_ptr max_pool = ngraph::builder::makeMaxPoolingV8(param, stride, dilation, pad_begin, pad_end, + kernel, rounding_type, pad_type, + index_element_type, axis); + + const auto max_pool_v8_second_output_is_supported = targetDevice == ov::test::utils::DEVICE_GPU; + + ov::ResultVector results; + if (max_pool_v8_second_output_is_supported) { + results = {std::make_shared(max_pool->output(0)), + std::make_shared(max_pool->output(1))}; + } else { + results = { std::make_shared(max_pool->output(0)) }; + } + function = std::make_shared(max_pool->outputs(), ov::ParameterVector{param}, "MaxPoolV8"); +} + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/power.cpp b/src/tests/functional/shared_test_classes/src/single_op/power.cpp new file mode 100644 index 00000000000000..54da5487a41b32 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/power.cpp @@ -0,0 +1,57 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/power.hpp" + +#include "openvino/op/parameter.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/power.hpp" + +namespace ov { +namespace test { +std::string PowerLayerTest::getTestCaseName(const testing::TestParamInfo &obj) { + std::vector shapes; + ov::element::Type model_type; + std::string device_name; + std::vector power; + std::tie(shapes, model_type, power, device_name) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "Power=" << ov::test::utils::vec2str(power) << "_"; + result << "netPRC=" << model_type.get_type_name() << "_"; + result << "trgDev=" << device_name << "_"; + return result.str(); +} + +void PowerLayerTest::SetUp() { + abs_threshold = 0.04f; + + std::vector shapes; + ov::element::Type model_type; + std::vector power; + std::tie(shapes, model_type, power, targetDevice) = this->GetParam(); + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + auto power_const = std::make_shared(model_type, ngraph::Shape{1}, power); + auto pow = std::make_shared(param, power_const); + + function = std::make_shared(pow, ov::ParameterVector{param}, "power"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/prior_box.cpp b/src/tests/functional/shared_test_classes/src/single_op/prior_box.cpp new file mode 100644 index 00000000000000..9f297a1f07c505 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/prior_box.cpp @@ -0,0 +1,117 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/prior_box.hpp" + +#include "openvino/pass/constant_folding.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/shape_of.hpp" +#include "openvino/op/prior_box_clustered.hpp" + +namespace ov { +namespace test { +std::string PriorBoxLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + ov::element::Type model_type; + std::vector shapes; + std::string target_device; + priorBoxSpecificParams spec_params; + std::tie(spec_params, model_type, shapes, target_device) = obj.param; + + std::vector min_size, max_size, aspect_ratio, density, fixed_ratio, fixed_size, variance; + float step, offset; + bool clip, flip, scale_all_sizes, min_max_aspect_ratios_order; + std::tie(min_size, max_size, aspect_ratio, density, fixed_ratio, fixed_size, clip, + flip, step, offset, variance, scale_all_sizes, min_max_aspect_ratios_order) = spec_params; + + std::ostringstream result; + const char separator = '_'; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "netPRC=" << model_type.get_type_name() << separator; + result << "min_s=" << ov::test::utils::vec2str(min_size) << separator; + result << "max_s=" << ov::test::utils::vec2str(max_size)<< separator; + result << "asp_r=" << ov::test::utils::vec2str(aspect_ratio)<< separator; + result << "dens=" << ov::test::utils::vec2str(density)<< separator; + result << "fix_r=" << ov::test::utils::vec2str(fixed_ratio)<< separator; + result << "fix_s=" << ov::test::utils::vec2str(fixed_size)<< separator; + result << "var=" << ov::test::utils::vec2str(variance)<< separator; + result << "step=" << step << separator; + result << "off=" << offset << separator; + result << "clip=" << clip << separator; + result << "flip=" << flip<< separator; + result << "scale_all=" << scale_all_sizes << separator; + result << "min_max_aspect_ratios_order=" << min_max_aspect_ratios_order << separator; + result << "trgDev=" << target_device; + + return result.str(); +} + +void PriorBoxLayerTest::SetUp() { + ov::element::Type model_type; + std::vector shapes; + std::vector min_size; + std::vector max_size; + std::vector aspect_ratio; + std::vector density; + std::vector fixed_ratio; + std::vector fixed_size; + std::vector variance; + float step; + float offset; + bool clip; + bool flip; + bool scale_all_sizes; + bool min_max_aspect_ratios_order; + + priorBoxSpecificParams spec_params; + std::tie(spec_params, model_type, shapes, targetDevice) = GetParam(); + + std::tie(min_size, max_size, aspect_ratio, density, fixed_ratio, fixed_size, clip, + flip, step, offset, variance, scale_all_sizes, min_max_aspect_ratios_order) = spec_params; + init_input_shapes(shapes); + + ov::ParameterVector params{std::make_shared(model_type, inputDynamicShapes[0]), + std::make_shared(model_type, inputDynamicShapes[1])}; + + ov::op::v8::PriorBox::Attributes attributes; + attributes.min_size = min_size; + attributes.max_size = max_size; + attributes.aspect_ratio = aspect_ratio; + attributes.density = density; + attributes.fixed_ratio = fixed_ratio; + attributes.fixed_size = fixed_size; + attributes.variance = variance; + attributes.step = step; + attributes.offset = offset; + attributes.clip = clip; + attributes.flip = flip; + attributes.scale_all_sizes = scale_all_sizes; + attributes.min_max_aspect_ratios_order = min_max_aspect_ratios_order; + + auto shape_of_1 = std::make_shared(params[0]); + auto shape_of_2 = std::make_shared(params[1]); + auto priorBox = std::make_shared( + shape_of_1, + shape_of_2, + attributes); + + ov::pass::disable_constant_folding(priorBox); + + auto result = std::make_shared(priorBox); + function = std::make_shared (result, params, "PriorBoxFunction"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/prior_box_clustered.cpp b/src/tests/functional/shared_test_classes/src/single_op/prior_box_clustered.cpp new file mode 100644 index 00000000000000..a630c498ee69a3 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/prior_box_clustered.cpp @@ -0,0 +1,95 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/prior_box_clustered.hpp" + +#include "openvino/op/parameter.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/shape_of.hpp" +#include "openvino/op/prior_box_clustered.hpp" + +namespace ov { +namespace test { +std::string PriorBoxClusteredLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + ov::element::Type model_type; + std::vector shapes; + std::string target_device; + priorBoxClusteredSpecificParams specParams; + std::tie(specParams, model_type, shapes, target_device) = obj.param; + + std::vector widths, heights, variances; + float step_width, step_height, step, offset; + bool clip; + std::tie(widths, heights, clip, step_width, step_height, step, offset, variances) = specParams; + + std::ostringstream result; + const char separator = '_'; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "netPRC=" << model_type.get_type_name() << separator; + result << "widths=" << ov::test::utils::vec2str(widths) << separator; + result << "heights=" << ov::test::utils::vec2str(heights) << separator; + result << "variances="; + if (variances.empty()) + result << "()" << separator; + else + result << ov::test::utils::vec2str(variances) << separator; + result << "stepWidth=" << step_width << separator; + result << "stepHeight=" << step_height << separator; + result << "step=" << step << separator; + result << "offset=" << offset << separator; + result << "clip=" << std::boolalpha << clip << separator; + result << "trgDev=" << target_device; + return result.str(); +} + +void PriorBoxClusteredLayerTest::SetUp() { + std::vector shapes; + ov::element::Type model_type; + std::vector widths; + std::vector heights; + std::vector variances; + float step_width; + float step_height; + float step; + float offset; + bool clip; + priorBoxClusteredSpecificParams specParams; + std::tie(specParams, model_type, shapes, targetDevice) = GetParam(); + std::tie(widths, heights, clip, step_width, step_height, step, offset, variances) = specParams; + init_input_shapes(shapes); + + ov::ParameterVector params{std::make_shared(model_type, inputDynamicShapes[0]), + std::make_shared(model_type, inputDynamicShapes[1])}; + + ov::op::v0::PriorBoxClustered::Attributes attributes; + attributes.widths = widths; + attributes.heights = heights; + attributes.clip = clip; + attributes.step_widths = step_width; + attributes.step_heights = step_height; + attributes.step = step; + attributes.offset = offset; + attributes.variances = variances; + + auto shape_of_1 = std::make_shared(params[0]); + auto shape_of_2 = std::make_shared(params[1]); + auto prior_box_clustered = std::make_shared(shape_of_1, shape_of_2, attributes); + + auto result = std::make_shared(prior_box_clustered); + function = std::make_shared(result, params, "PB_Clustered"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/roi_align.cpp b/src/tests/functional/shared_test_classes/src/single_op/roi_align.cpp new file mode 100644 index 00000000000000..d191e7dda9565f --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/roi_align.cpp @@ -0,0 +1,203 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "shared_test_classes/single_op/roi_align.hpp" + +#include "openvino/core/enum_names.hpp" + +namespace ov { +namespace test { +std::string ROIAlignLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector input_shapes; + ov::Shape coords_shape; + int pooled_h; + int pooled_w; + float spatial_scale; + int pooling_ratio; + std::string pooling_mode; + ov::element::Type model_type; + std::string target_device; + std::tie(input_shapes, coords_shape, pooled_h, pooled_w, spatial_scale, + pooling_ratio, pooling_mode, model_type, target_device) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < input_shapes.size(); i++) { + result << ov::test::utils::partialShape2str({input_shapes[i].first}) + << (i < input_shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < input_shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < input_shapes.size(); j++) { + result << ov::test::utils::vec2str(input_shapes[j].second[i]) << (j < input_shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "coordShape=" << ov::test::utils::vec2str(coords_shape) << "_"; + result << "pooledH=" << pooled_h << "_"; + result << "pooledW=" << pooled_w << "_"; + result << "spatialScale=" << spatial_scale << "_"; + result << "poolingRatio=" << pooling_ratio << "_"; + result << "poolingMode=" << pooling_mode << "_"; + result << "modelType=" << model_type.to_string() << "_"; + result << "trgDev=" << target_device; + return result.str(); +} + +static int randInt(int low, int high) { + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution dis(low, high); + return dis(gen); +} + +void ROIAlignLayerTest::fillCoordTensor(std::vector& coords, int height, int width, + float spatial_scale, int pooled_ratio, int pooled_h, int pooled_w) { + int min_roi_width = pooled_w; + int max_roi_width = width / pooled_ratio; + int min_roi_height = pooled_h; + int max_roi_height = height / pooled_ratio; + + for (int i = 0; i < coords.size() / 4; i++) { + int size_x = std::min(width, randInt(min_roi_width, max_roi_width)); + int size_y = std::min(height, randInt(min_roi_height, max_roi_height)); + int start_x = randInt(0, std::max(1, width - size_x - 1)); + int start_y = randInt(0, std::max(1, height - size_y - 1)); + + coords[i * 4] = start_x / spatial_scale; + coords[i * 4 + 1] = start_y / spatial_scale; + coords[i * 4 + 2] = (start_x + size_x - 1) / spatial_scale; + coords[i * 4 + 3] = (start_y + size_y - 1) / spatial_scale; + } +} +void ROIAlignLayerTest::fillIdxTensor(std::vector& idx, int batch_size) { + int batch_id = 0; + for (int i = 0; i < idx.size(); i++) { + idx[i] = batch_id; + batch_id = (batch_id + 1) % batch_size; + } +} + +void ROIAlignLayerTest::SetUp() { + std::vector input_shapes; + ov::Shape coords_shape; + int pooled_h; + int pooled_w; + float spatial_scale; + int pooling_ratio; + std::string pooling_mode; + ov::element::Type model_type; + std::tie(input_shapes, coords_shape, pooled_h, pooled_w, spatial_scale, + pooling_ratio, pooling_mode, model_type, targetDevice) = this->GetParam(); + + init_input_shapes(input_shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes[0]); + std::vector proposal_vector; + std::vector roi_idx_vector; + proposal_vector.resize(coords_shape[0] * 4); + roi_idx_vector.resize(coords_shape[0]); + + fillCoordTensor(proposal_vector, inputDynamicShapes[0][2].get_length(), inputDynamicShapes[0][3].get_length(), + spatial_scale, pooling_ratio, pooled_h, pooled_w); + fillIdxTensor(roi_idx_vector, inputDynamicShapes[0][0].get_length()); + auto idx_shape = ov::Shape{coords_shape[0]}; + + auto coords = std::make_shared(model_type, coords_shape, proposal_vector.data()); + auto rois_Idx = std::make_shared(ov::element::i32, idx_shape, roi_idx_vector.data()); + auto roi_align = std::make_shared(param, + coords, + rois_Idx, + pooled_h, + pooled_w, + pooling_ratio, + spatial_scale, + pooling_mode); + function = std::make_shared(roi_align->outputs(), ov::ParameterVector{param}, "roi_align"); +} + +std::string ROIAlignV9LayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector input_shapes; + ov::Shape coords_shape; + int pooled_h; + int pooled_w; + float spatial_scale; + int pooling_ratio; + std::string pooling_mode; + std::string roi_aligned_mode; + ov::element::Type model_type; + std::string target_device; + std::tie(input_shapes, coords_shape, pooled_h, pooled_w, spatial_scale, + pooling_ratio, pooling_mode, roi_aligned_mode, model_type, target_device) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < input_shapes.size(); i++) { + result << ov::test::utils::partialShape2str({input_shapes[i].first}) + << (i < input_shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < input_shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < input_shapes.size(); j++) { + result << ov::test::utils::vec2str(input_shapes[j].second[i]) << (j < input_shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "coordShape=" << ov::test::utils::vec2str(coords_shape) << "_"; + result << "pooledH=" << pooled_h << "_"; + result << "pooledW=" << pooled_w << "_"; + result << "spatialScale=" << spatial_scale << "_"; + result << "poolingRatio=" << pooling_ratio << "_"; + result << "poolingMode=" << pooling_mode << "_"; + result << "ROIMode=" << roi_aligned_mode << "_"; + result << "modelType=" << model_type.to_string() << "_"; + result << "trgDev=" << target_device; + return result.str(); +} + +void ROIAlignV9LayerTest::SetUp() { + std::vector input_shapes; + ov::Shape coords_shape; + int pooled_h; + int pooled_w; + float spatial_scale; + int pooling_ratio; + std::string pooling_mode; + std::string roi_aligned_mode; + ov::element::Type model_type; + std::tie(input_shapes, coords_shape, pooled_h, pooled_w, spatial_scale, + pooling_ratio, pooling_mode, roi_aligned_mode, model_type, targetDevice) = this->GetParam(); + + init_input_shapes(input_shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes[0]); + std::vector proposal_vector; + std::vector roi_idx_vector; + proposal_vector.resize(coords_shape[0] * 4); + roi_idx_vector.resize(coords_shape[0]); + + ROIAlignLayerTest::fillCoordTensor(proposal_vector, inputDynamicShapes[0][2].get_length(), inputDynamicShapes[0][3].get_length(), + spatial_scale, pooling_ratio, pooled_h, pooled_w); + ROIAlignLayerTest::fillIdxTensor(roi_idx_vector, inputDynamicShapes[0][0].get_length()); + auto idx_shape = ov::Shape{coords_shape[0]}; + + auto coords = std::make_shared(model_type, coords_shape, proposal_vector.data()); + auto rois_Idx = std::make_shared(ov::element::i32, idx_shape, roi_idx_vector.data()); + auto roi_align = std::make_shared(param, + coords, + rois_Idx, + pooled_h, + pooled_w, + pooling_ratio, + spatial_scale, + ov::EnumNames::as_enum(pooling_mode), + ov::EnumNames::as_enum(roi_aligned_mode)); + function = std::make_shared(roi_align->outputs(), ov::ParameterVector{param}, "roi_align"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/roi_pooling.cpp b/src/tests/functional/shared_test_classes/src/single_op/roi_pooling.cpp new file mode 100644 index 00000000000000..f4867abe6629b7 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/roi_pooling.cpp @@ -0,0 +1,74 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/roi_pooling.hpp" + +namespace ov { +namespace test { +std::string ROIPoolingLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector input_shapes; + ov::Shape pool_shape; + float spatial_scale; + ov::test::utils::ROIPoolingTypes pool_method; + ov::element::Type model_type; + std::string target_device; + std::tie(input_shapes, pool_shape, spatial_scale, pool_method, model_type, target_device) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < input_shapes.size(); i++) { + result << ov::test::utils::partialShape2str({input_shapes[i].first}) + << (i < input_shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < input_shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < input_shapes.size(); j++) { + result << ov::test::utils::vec2str(input_shapes[j].second[i]) << (j < input_shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "PS=" << ov::test::utils::vec2str(pool_shape) << "_"; + result << "Scale=" << spatial_scale << "_"; + switch (pool_method) { + case utils::ROIPoolingTypes::ROI_MAX: + result << "Max_"; + break; + case utils::ROIPoolingTypes::ROI_BILINEAR: + result << "Bilinear_"; + break; + } + result << "modelType=" << model_type.to_string() << "_"; + result << "trgDev=" << target_device; + return result.str(); +} + +void ROIPoolingLayerTest::SetUp() { + std::vector input_shapes; + ov::Shape pool_shape; + float spatial_scale; + ov::test::utils::ROIPoolingTypes pool_method; + ov::element::Type model_type; + std::string target_device; + std::tie(input_shapes, pool_shape, spatial_scale, pool_method, model_type, targetDevice) = this->GetParam(); + + abs_threshold = 0.08f; + + init_input_shapes(input_shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes[0]); + auto coord_param = std::make_shared(model_type, inputDynamicShapes[1]); + std::string pool_method_str; + if (pool_method == ov::test::utils::ROIPoolingTypes::ROI_MAX) { + pool_method_str = "max"; + } else if (pool_method == ov::test::utils::ROIPoolingTypes::ROI_BILINEAR) { + pool_method_str = "bilinear"; + } else { + FAIL() << "Incorrect type of ROIPooling operation"; + } + auto roi_pooling = std::make_shared(param, coord_param, pool_shape, spatial_scale, pool_method_str); + function = std::make_shared(roi_pooling->outputs(), ov::ParameterVector{param, coord_param}, "roi_pooling"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/subgraph/conv_eltwise_fusion.cpp b/src/tests/functional/shared_test_classes/src/subgraph/conv_eltwise_fusion.cpp index 92fb39befb3ed8..625c187dffc06e 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/conv_eltwise_fusion.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/conv_eltwise_fusion.cpp @@ -4,15 +4,17 @@ #include "shared_test_classes/subgraph/conv_eltwise_fusion.hpp" +#include "common_test_utils/graph_comparator.hpp" #include "openvino/core/node.hpp" #include "openvino/opsets/opset11.hpp" #include "openvino/pass/constant_folding.hpp" +#include "openvino/pass/manager.hpp" #include "ov_models/builders.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" #include "transformations/common_optimizations/conv_mul_fusion.hpp" -using namespace ov; - -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { std::string ConvEltwiseFusion::getTestCaseName(const testing::TestParamInfo& obj) { std::tuple conv_params; @@ -205,4 +207,5 @@ void ConvEltwiseFusion::SetUp() { auto res = compare_functions(cloned_function, function_ref); ASSERT_TRUE(res.first) << res.second; } -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/subgraph/conv_strides_opt.cpp b/src/tests/functional/shared_test_classes/src/subgraph/conv_strides_opt.cpp index 8ab13e55a32423..3e2a1aa64f5829 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/conv_strides_opt.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/conv_strides_opt.cpp @@ -4,11 +4,10 @@ #include "shared_test_classes/subgraph/conv_strides_opt.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { -using namespace ngraph; - -std::string ConvStridesOpt::getTestCaseName(const testing::TestParamInfo &obj) { +std::string ConvStridesOpt::getTestCaseName(const testing::TestParamInfo& obj) { Shape input_shape; op::PadType pad; std::string targetName; @@ -25,20 +24,21 @@ void ConvStridesOpt::SetUp() { Shape input_shape; op::PadType pad_type; std::tie(input_shape, pad_type, targetDevice) = this->GetParam(); - auto param = std::make_shared(element::f32, input_shape); + auto param = std::make_shared(element::f32, input_shape); auto C = input_shape[1]; auto weights1 = ngraph::builder::makeConstant(element::f32, {C, C, 3, 3}, {}, true); auto spatial_dims = input_shape.size() - 2; Strides strides1(spatial_dims, 1); Strides dilations(spatial_dims, 1); CoordinateDiff pad_begin1(spatial_dims, 1), pad_end1(spatial_dims, 1); - auto conv1 = std::make_shared(param, weights1, strides1, pad_begin1, pad_end1, - dilations, pad_type); + auto conv1 = + std::make_shared(param, weights1, strides1, pad_begin1, pad_end1, dilations, pad_type); auto weights2 = ngraph::builder::makeConstant(element::f32, {C, C, 1, 1}, {}, true); CoordinateDiff pad_begin2(spatial_dims, 0), pad_end2(spatial_dims, 0); Strides strides2(spatial_dims, 2); - auto conv2 = std::make_shared(conv1, weights2, strides2, pad_begin2, pad_end2, - dilations); - function = std::make_shared(OutputVector{conv2}, ParameterVector{param}); + auto conv2 = std::make_shared(conv1, weights2, strides2, pad_begin2, pad_end2, dilations); + function = std::make_shared(OutputVector{conv2}, ParameterVector{param}); } -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/subgraph/convert_pad_to_group_conv.cpp b/src/tests/functional/shared_test_classes/src/subgraph/convert_pad_to_group_conv.cpp index c8f96576dc3761..5db0177f8afb57 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/convert_pad_to_group_conv.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/convert_pad_to_group_conv.cpp @@ -4,13 +4,14 @@ #include "shared_test_classes/subgraph/convert_pad_to_group_conv.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { -std::string ConvertPadToConvTests::getTestCaseName(const testing::TestParamInfo &obj) { - ngraph::Shape input_shape; +std::string ConvertPadToConvTests::getTestCaseName(const testing::TestParamInfo& obj) { + ov::Shape input_shape; std::string targetName; std::vector pad_begin, pad_end; - ngraph::op::PadMode mode; + ov::op::PadMode mode; float value; std::tie(input_shape, pad_begin, pad_end, value, mode, targetName) = obj.param; std::ostringstream results; @@ -25,20 +26,24 @@ std::string ConvertPadToConvTests::getTestCaseName(const testing::TestParamInfo< } void ConvertPadToConvTests::SetUp() { - ngraph::Shape input_shape; + ov::Shape input_shape; std::vector pad_begin, pad_end; - ngraph::op::PadMode mode; + ov::op::PadMode mode; float value; std::tie(input_shape, pad_begin, pad_end, value, mode, targetDevice) = this->GetParam(); { - auto param = std::make_shared(ngraph::element::f32, input_shape); - auto pad = std::make_shared(param, - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{pad_begin.size()}, pad_begin), - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{pad_end.size()}, pad_end), - ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{}, {value}), mode); - auto relu = std::make_shared(pad); - function = std::make_shared(ngraph::OutputVector{relu}, ngraph::ParameterVector{param}, "pad"); + auto param = std::make_shared(ov::element::f32, input_shape); + auto pad = std::make_shared( + param, + ov::op::v0::Constant::create(ov::element::i64, ov::Shape{pad_begin.size()}, pad_begin), + ov::op::v0::Constant::create(ov::element::i64, ov::Shape{pad_end.size()}, pad_end), + ov::op::v0::Constant::create(ov::element::f32, ov::Shape{}, {value}), + mode); + auto relu = std::make_shared(pad); + function = std::make_shared(ov::OutputVector{relu}, ov::ParameterVector{param}, "pad"); } } -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/subgraph/get_output_before_activation.cpp b/src/tests/functional/shared_test_classes/src/subgraph/get_output_before_activation.cpp index 8a84303f79acfb..7a566ae58a801c 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/get_output_before_activation.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/get_output_before_activation.cpp @@ -2,10 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ov_models/builders.hpp" #include "shared_test_classes/subgraph/get_output_before_activation.hpp" -namespace SubgraphTestsDefinitions { +#include "ov_models/builders.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { + std::ostream& operator<<(std::ostream& os, const midOutputType& oType) { switch (oType) { case midOutputType::Sub: @@ -21,51 +25,50 @@ std::ostream& operator<<(std::ostream& os, const midOutputType& oType) { std::string OutputBeforeActivation::getTestCaseName(const testing::TestParamInfo& obj) { std::string targetDevice; - InferenceEngine::Precision netPrecision; + ov::element::Type element_type; size_t inputSize; midOutputType outputType; - std::map config; - std::tie(targetDevice, netPrecision, inputSize, outputType, config) = obj.param; + ov::AnyMap config; + std::tie(targetDevice, element_type, inputSize, outputType, config) = obj.param; std::ostringstream result; - result << "netPrecision=" << netPrecision.name() << "_"; + result << "InputType=" << element_type << "_"; result << "IS=" << inputSize << "_"; result << "OutputType=" << outputType << "_"; result << "targetDevice=" << targetDevice; for (auto const& configItem : config) { - result << "_configItem=" << configItem.first << "_" << configItem.second; + result << "_configItem=" << configItem.first << "_" << configItem.second.as(); } return result.str(); } void OutputBeforeActivation::SetUp() { - InferenceEngine::Precision netPrecision; - std::map config; + ov::element::Type element_type; + ov::AnyMap config; size_t inputSize; midOutputType outputType; - std::tie(targetDevice, netPrecision, inputSize, outputType, config) = this->GetParam(); + std::tie(targetDevice, element_type, inputSize, outputType, config) = this->GetParam(); configuration.insert(config.begin(), config.end()); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - std::vector input_dims { 1, inputSize }; + std::vector input_dims{1, inputSize}; - ov::ParameterVector input_parameter {std::make_shared(ngPrc, ov::Shape(input_dims)), - std::make_shared(ngPrc, ov::Shape(input_dims))}; + ov::ParameterVector input_parameter{std::make_shared(element_type, ov::Shape(input_dims)), + std::make_shared(element_type, ov::Shape(input_dims))}; auto input0 = input_parameter[0]; auto input1 = input_parameter[1]; ngraph::OutputVector outputs; std::shared_ptr midLayer; switch (outputType) { - case SubgraphTestsDefinitions::midOutputType::Sum: { + case ov::test::midOutputType::Sum: { midLayer = ngraph::builder::makeEltwise(input0, input1, ngraph::helpers::EltwiseTypes::ADD); break; } - case SubgraphTestsDefinitions::midOutputType::Sub: { + case ov::test::midOutputType::Sub: { midLayer = ngraph::builder::makeEltwise(input0, input1, ngraph::helpers::EltwiseTypes::SUBTRACT); break; } - case SubgraphTestsDefinitions::midOutputType::Mul: { + case ov::test::midOutputType::Mul: { midLayer = ngraph::builder::makeEltwise(input0, input1, ngraph::helpers::EltwiseTypes::MULTIPLY); break; } @@ -73,12 +76,17 @@ void OutputBeforeActivation::SetUp() { GTEST_FAIL() << "Unknown midOutputType"; } - auto act = ngraph::builder::makeActivation(midLayer, ngPrc, ngraph::helpers::ActivationTypes::Tanh); + auto act = ngraph::builder::makeActivation(midLayer, element_type, ngraph::helpers::ActivationTypes::Tanh); outputs.insert(outputs.end(), {midLayer, act}); function = std::make_shared(outputs, input_parameter, "output_before_activation"); } -InferenceEngine::Blob::Ptr OutputBeforeActivation::GenerateInput(const InferenceEngine::InputInfo &info) const { - return FuncTestUtils::createAndFillBlob(info.getTensorDesc(), 2, -1, 100); -} -} // namespace SubgraphTestsDefinitions +// void OutputBeforeActivation::generate_inputs(const std::vector& targetInputStaticShapes) { +// ov::test::SubgraphBaseTest::generate_inputs(targetInputStaticShapes); +// } +// InferenceEngine::Blob::Ptr OutputBeforeActivation::GenerateInput(const InferenceEngine::InputInfo& info) const { +// return FuncTestUtils::createAndFillBlob(info.getTensorDesc(), 2, -1, 100); +// } + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/subgraph/matmul_const_transposes_extraction.cpp b/src/tests/functional/shared_test_classes/src/subgraph/matmul_const_transposes_extraction.cpp index 59e5d4e397df17..05e434a1307b15 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/matmul_const_transposes_extraction.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/matmul_const_transposes_extraction.cpp @@ -3,15 +3,19 @@ // #include "transformations/common_optimizations/matmul_const_transposes_extraction.hpp" -#include "shared_test_classes/subgraph/matmul_const_transposes_extraction.hpp" -#include "ov_models/builders.hpp" -#include -namespace SubgraphTestsDefinitions { +#include "common_test_utils/graph_comparator.hpp" +#include "functional_test_utils/skip_tests_config.hpp" +#include "openvino/pass/manager.hpp" +#include "openvino/runtime/exec_model_info.hpp" +#include "ov_models/builders.hpp" +#include "shared_test_classes/subgraph/matmul_const_transposes_extraction.hpp" -using namespace ngraph; +namespace ov { +namespace test { -std::string MatMulConstTransposesExtractionTest::getTestCaseName(const testing::TestParamInfo &obj) { +std::string MatMulConstTransposesExtractionTest::getTestCaseName( + const testing::TestParamInfo& obj) { MatMulConstTransposesExtractionTestShapeParams shape_params; std::string device; std::tie(shape_params, std::ignore, device) = obj.param; @@ -33,18 +37,18 @@ void MatMulConstTransposesExtractionTest::SetUp() { const auto& input_shape = shape_params.input_shape; const auto& weights_shape = shape_params.weights_shape; - auto param = std::make_shared(type, input_shape); - auto weights = opset8::Constant::create(type, weights_shape, {0.5}); - auto matmul = std::make_shared(param, weights, false, shape_params.trans_b); - function = std::make_shared(matmul, ParameterVector{param}); + auto param = std::make_shared(type, input_shape); + auto weights = ov::op::v0::Constant::create(type, weights_shape, {0.5}); + auto matmul = std::make_shared(param, weights, false, shape_params.trans_b); + function = std::make_shared(matmul, ParameterVector{param}); - auto transformed_function = clone_function(*function); + auto transformed_function = function->clone(); pass::Manager manager; manager.register_pass(); manager.run_passes(transformed_function); bool functions_equal; - auto orig_function = clone_function(*function); + auto orig_function = function->clone(); std::tie(functions_equal, std::ignore) = compare_functions(transformed_function, orig_function, true); if (can_be_fused) { ASSERT_FALSE(functions_equal); @@ -54,15 +58,19 @@ void MatMulConstTransposesExtractionTest::SetUp() { } std::string QuantizedMatMulConstTransposesExtractionTest::getTestCaseName( - const testing::TestParamInfo &obj) { + const testing::TestParamInfo& obj) { MatMulConstTransposesExtractionTestShapeParams params; std::string device; std::tie(params, std::ignore, device) = obj.param; std::ostringstream results; - results << "input=" << params.input_shape << "_" - "weights=" << params.weights_shape << "_" - "dev=" << device; + results << "input=" << params.input_shape + << "_" + "weights=" + << params.weights_shape + << "_" + "dev=" + << device; return results.str(); } @@ -75,23 +83,23 @@ void QuantizedMatMulConstTransposesExtractionTest::SetUp() { auto weights_shape = params.weights_shape; element::Type type = element::f32; - auto param = std::make_shared(type, input_shape); + auto param = std::make_shared(type, input_shape); std::shared_ptr input; - std::shared_ptr weights = opset8::Constant::create(type, weights_shape, {0.5}); - auto low = opset8::Constant::create(type, {1}, {-2}); - auto high = opset8::Constant::create(type, {1}, {2}); - input = std::make_shared(param, low, high, low, high, 256); - weights = std::make_shared(weights, low, high, low, high, 255); - auto matmul = std::make_shared(input, weights, false, false); - function = std::make_shared(matmul, ParameterVector{param}); - - auto transformed_function = clone_function(*function); + std::shared_ptr weights = ov::op::v0::Constant::create(type, weights_shape, {0.5}); + auto low = ov::op::v0::Constant::create(type, {1}, {-2}); + auto high = ov::op::v0::Constant::create(type, {1}, {2}); + input = std::make_shared(param, low, high, low, high, 256); + weights = std::make_shared(weights, low, high, low, high, 255); + auto matmul = std::make_shared(input, weights, false, false); + function = std::make_shared(matmul, ParameterVector{param}); + + auto transformed_function = function->clone(); pass::Manager manager; manager.register_pass(); manager.run_passes(transformed_function); bool functions_equal; - auto orig_function = clone_function(*function); + auto orig_function = function->clone(); std::tie(functions_equal, std::ignore) = compare_functions(transformed_function, orig_function, true); if (can_be_fused) { ASSERT_FALSE(functions_equal); @@ -102,10 +110,10 @@ void QuantizedMatMulConstTransposesExtractionTest::SetUp() { void QuantizedMatMulConstTransposesExtractionTest::TearDown() { SKIP_IF_CURRENT_TEST_IS_DISABLED(); - auto runtime_function = executableNetwork.GetExecGraphInfo().getFunction(); + auto runtime_function = compiledModel.get_runtime_model(); int ops_found = 0; for (const auto& node : runtime_function->get_ordered_ops()) { - const auto& layer_type = node->get_rt_info().at(ExecGraphInfoSerialization::LAYER_TYPE).as(); + const auto& layer_type = node->get_rt_info().at(ov::exec_model_info::LAYER_TYPE).as(); if (layer_type == "FullyConnected" || layer_type == "MatMul") { ops_found++; auto inputs = node->input_values(); @@ -115,4 +123,6 @@ void QuantizedMatMulConstTransposesExtractionTest::TearDown() { } ASSERT_GT(ops_found, 0); } -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/subgraph/matmul_multiply_fusion.cpp b/src/tests/functional/shared_test_classes/src/subgraph/matmul_multiply_fusion.cpp index 02252c96fdf4d1..1764223d930f0f 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/matmul_multiply_fusion.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/matmul_multiply_fusion.cpp @@ -2,16 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "transformations/common_optimizations/matmul_multiply_fusion.hpp" #include "shared_test_classes/subgraph/matmul_multiply_fusion.hpp" -#include "ov_models/builders.hpp" -#include -namespace SubgraphTestsDefinitions { +#include "common_test_utils/graph_comparator.hpp" +#include "functional_test_utils/skip_tests_config.hpp" +#include "openvino/pass/manager.hpp" +#include "openvino/runtime/exec_model_info.hpp" +#include "transformations/common_optimizations/matmul_multiply_fusion.hpp" -using namespace ngraph; +namespace ov { +namespace test { -std::string MatMulMultiplyFusion::getTestCaseName(const testing::TestParamInfo &obj) { +std::string MatMulMultiplyFusion::getTestCaseName(const testing::TestParamInfo& obj) { MatMulMultiplyFusionShapeParams shape_params; std::string device; std::tie(shape_params, std::ignore, device) = obj.param; @@ -35,20 +37,20 @@ void MatMulMultiplyFusion::SetUp() { const auto& weights_shape = shape_params.weights_shape; const auto& const_shape = shape_params.const_shape; - auto param = std::make_shared(precision, input_shape); - auto weights = opset8::Constant::create(precision, weights_shape, {0.5}); - auto matmul = std::make_shared(param, weights, false, shape_params.trans_b); - auto mul_const = opset8::Constant::create(precision, const_shape, {2.0}); - auto mul = std::make_shared(matmul, mul_const); - function = std::make_shared(OutputVector{mul}, ParameterVector{param}); + auto param = std::make_shared(precision, input_shape); + auto weights = ov::op::v0::Constant::create(precision, weights_shape, {0.5}); + auto matmul = std::make_shared(param, weights, false, shape_params.trans_b); + auto mul_const = ov::op::v0::Constant::create(precision, const_shape, {2.0}); + auto mul = std::make_shared(matmul, mul_const); + function = std::make_shared(OutputVector{mul}, ParameterVector{param}); - auto transformed_function = clone_function(*function); + auto transformed_function = function->clone(); pass::Manager manager; manager.register_pass(); manager.run_passes(transformed_function); bool functions_equal; - auto orig_function = clone_function(*function); + auto orig_function = function->clone(); std::tie(functions_equal, std::ignore) = compare_functions(transformed_function, orig_function, true); if (can_be_fused) { ASSERT_FALSE(functions_equal); @@ -57,7 +59,8 @@ void MatMulMultiplyFusion::SetUp() { } } -std::string QuantizedMatMulMultiplyFusion::getTestCaseName(const testing::TestParamInfo &obj) { +std::string QuantizedMatMulMultiplyFusion::getTestCaseName( + const testing::TestParamInfo& obj) { MatMulMultiplyFusionShapeParams shape_params; std::string device; std::tie(shape_params, std::ignore, device) = obj.param; @@ -81,31 +84,31 @@ void QuantizedMatMulMultiplyFusion::SetUp() { auto weights_shape = shape_params.weights_shape; const auto& const_shape = shape_params.const_shape; - auto param = std::make_shared(precision, input_shape); - auto low = opset8::Constant::create(precision, {1}, {-2}); - auto high = opset8::Constant::create(precision, {1}, {2}); - auto input_fq = std::make_shared(param, low, high, low, high, 256); - std::shared_ptr weights = opset8::Constant::create(precision, weights_shape, {0.5}); - weights = std::make_shared(weights, low, high, low, high, 255); + auto param = std::make_shared(precision, input_shape); + auto low = ov::op::v0::Constant::create(precision, {1}, {-2}); + auto high = ov::op::v0::Constant::create(precision, {1}, {2}); + auto input_fq = std::make_shared(param, low, high, low, high, 256); + std::shared_ptr weights = ov::op::v0::Constant::create(precision, weights_shape, {0.5}); + weights = std::make_shared(weights, low, high, low, high, 255); if (shape_params.trans_b) { std::vector perm(weights_shape.size(), 0); std::iota(perm.begin(), perm.end(), 0); std::swap(*(perm.end() - 2), *(perm.end() - 1)); - auto perm_const = opset8::Constant::create(element::i32, {perm.size()}, perm); - weights = std::make_shared(weights, perm_const); + auto perm_const = ov::op::v0::Constant::create(element::i32, {perm.size()}, perm); + weights = std::make_shared(weights, perm_const); } - auto matmul = std::make_shared(input_fq, weights); - auto mul_const = opset8::Constant::create(precision, const_shape, {2}); - auto mul = std::make_shared(matmul, mul_const); - function = std::make_shared(OutputVector{mul}, ParameterVector{param}); + auto matmul = std::make_shared(input_fq, weights); + auto mul_const = ov::op::v0::Constant::create(precision, const_shape, {2}); + auto mul = std::make_shared(matmul, mul_const); + function = std::make_shared(OutputVector{mul}, ParameterVector{param}); - auto transformed_function = clone_function(*function); + auto transformed_function = function->clone(); pass::Manager manager; manager.register_pass(); manager.run_passes(transformed_function); bool functions_equal; - auto orig_function = clone_function(*function); + auto orig_function = function->clone(); std::tie(functions_equal, std::ignore) = compare_functions(transformed_function, orig_function, true); if (can_be_fused) { ASSERT_FALSE(functions_equal); @@ -116,14 +119,14 @@ void QuantizedMatMulMultiplyFusion::SetUp() { void QuantizedMatMulMultiplyFusion::TearDown() { SKIP_IF_CURRENT_TEST_IS_DISABLED(); - auto get_layer_type = [] (const std::shared_ptr& node) -> const std::string& { + auto get_layer_type = [](const std::shared_ptr& node) -> const std::string& { const auto& rt_info = node->get_rt_info(); - auto it = rt_info.find(ExecGraphInfoSerialization::LAYER_TYPE); - IE_ASSERT(it != rt_info.end()); + auto it = rt_info.find(ov::exec_model_info::LAYER_TYPE); + OPENVINO_ASSERT(it != rt_info.end()); return it->second.as(); }; - auto runtime_function = executableNetwork.GetExecGraphInfo().getFunction(); + auto runtime_function = compiledModel.get_runtime_model(); int ops_found = 0; for (const auto& node : runtime_function->get_ordered_ops()) { const auto& layer_type = get_layer_type(node); @@ -136,4 +139,6 @@ void QuantizedMatMulMultiplyFusion::TearDown() { } ASSERT_GT(ops_found, 0); } -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/subgraph/matmul_squeeze_add.cpp b/src/tests/functional/shared_test_classes/src/subgraph/matmul_squeeze_add.cpp index b91b50bd8a9457..01b628d63cf8fd 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/matmul_squeeze_add.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/matmul_squeeze_add.cpp @@ -3,57 +3,68 @@ // #include "shared_test_classes/subgraph/matmul_squeeze_add.hpp" + +#include "common_test_utils/data_utils.hpp" #include "ov_models/builders.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { std::string MatmulSqueezeAddTest::getTestCaseName(const testing::TestParamInfo& obj) { - InferenceEngine::Precision netPrecision; - std::vector inputShape; + ov::element::Type element_type; + ov::Shape input_shape; std::size_t outputSize; std::string targetDevice; - std::map configuration; - std::tie(netPrecision, targetDevice, configuration, inputShape, outputSize) = obj.param; + ov::AnyMap configuration; + std::tie(element_type, targetDevice, configuration, input_shape, outputSize) = obj.param; std::ostringstream result; - result << "IS=" << ov::test::utils::vec2str(inputShape) << "_"; + result << "IS=" << ov::test::utils::vec2str(input_shape) << "_"; result << "OS=" << outputSize << "_"; - result << "netPRC=" << netPrecision.name() << "_"; + result << "IT=" << element_type << "_"; result << "targetDevice=" << targetDevice; for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; + result << "_configItem=" << configItem.first << "_" << configItem.second.as(); } return result.str(); } void MatmulSqueezeAddTest::SetUp() { auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count(); - InferenceEngine::Precision netPrecision; - std::map tempConfig; - std::vector inputShape; + ov::element::Type element_type; + ov::AnyMap tempConfig; + ov::Shape inputShape; size_t outputSize; - std::tie(netPrecision, targetDevice, tempConfig, inputShape, outputSize) = this->GetParam(); + std::tie(element_type, targetDevice, tempConfig, inputShape, outputSize) = this->GetParam(); configuration.insert(tempConfig.begin(), tempConfig.end()); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ov::ParameterVector params {std::make_shared(ngPrc, ov::Shape(inputShape))}; + ov::ParameterVector params{std::make_shared(element_type, ov::Shape(inputShape))}; - auto constant_0 = ngraph::builder::makeConstant(ngPrc, { outputSize, inputShape[1] }, - ov::test::utils::generate_float_numbers(outputSize * inputShape[1], 0, 1, seed), false); + auto constant_0 = ngraph::builder::makeConstant( + element_type, + {outputSize, inputShape[1]}, + ov::test::utils::generate_float_numbers(outputSize * inputShape[1], 0, 1, seed), + false); auto matmul_0 = std::make_shared(params[0], constant_0, false, true); - auto constant_1 = std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{ 1 }, std::vector{0}); + auto constant_1 = + std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{1}, std::vector{0}); auto unsqueeze_0 = std::make_shared(matmul_0, constant_1); - auto constant_2 = ngraph::builder::makeConstant(ngPrc, { 1, inputShape[0], outputSize }, - ov::test::utils::generate_float_numbers(inputShape[0] * outputSize, 0, 1, seed), false); + auto constant_2 = ngraph::builder::makeConstant( + element_type, + {1, inputShape[0], outputSize}, + ov::test::utils::generate_float_numbers(inputShape[0] * outputSize, 0, 1, seed), + false); auto add_0 = std::make_shared(unsqueeze_0, constant_2); - auto constant_3 = std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{ 1 }, std::vector{0}); + auto constant_3 = + std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{1}, std::vector{0}); auto squeeze_0 = std::make_shared(add_0, constant_3); - ngraph::ResultVector results {std::make_shared(squeeze_0)}; + ngraph::ResultVector results{std::make_shared(squeeze_0)}; function = std::make_shared(results, params, "MatmulSqueezeAddTest"); } -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/subgraph/mul_conv_fusion.cpp b/src/tests/functional/shared_test_classes/src/subgraph/mul_conv_fusion.cpp index d16090a2e1c819..411cff4a46ab21 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/mul_conv_fusion.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/mul_conv_fusion.cpp @@ -2,17 +2,20 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "transformations/common_optimizations/mul_conv_fusion.hpp" -#include "ngraph/pass/constant_folding.hpp" #include "shared_test_classes/subgraph/mul_conv_fusion.hpp" + +#include "common_test_utils/graph_comparator.hpp" +#include "openvino/pass/manager.hpp" #include "ov_models/builders.hpp" +#include "transformations/common_optimizations/mul_conv_fusion.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { -std::string MulConvFusion::getTestCaseName(const testing::TestParamInfo &obj) { - ngraph::NodeTypeInfo conv_type; - ngraph::Shape input_shape, weights_shape, const_shape; - ngraph::element::Type precision; +std::string MulConvFusion::getTestCaseName(const testing::TestParamInfo& obj) { + ov::NodeTypeInfo conv_type; + ov::Shape input_shape, weights_shape, const_shape; + ov::element::Type precision; std::string device; std::tie(conv_type, input_shape, weights_shape, const_shape, precision, std::ignore, device) = obj.param; std::ostringstream results; @@ -27,36 +30,43 @@ std::string MulConvFusion::getTestCaseName(const testing::TestParamInfoGetParam(); - auto param = std::make_shared(precision, input_shape); + std::tie(conv_type, input_shape, weights_shape, const_shape, precision, is_negative, targetDevice) = + this->GetParam(); + auto param = std::make_shared(precision, input_shape); auto spatial_dims = input_shape.size() - 2; auto mul_const = ngraph::builder::makeConstant(precision, const_shape, {}, true); - auto mul = std::make_shared(param, mul_const); - ngraph::Shape strides(spatial_dims, 1); + auto mul = std::make_shared(param, mul_const); + ov::Shape strides(spatial_dims, 1); std::vector pad_begin(spatial_dims, 0), pad_end(spatial_dims, 0); auto weights = ngraph::builder::makeConstant(precision, weights_shape, {}, true); - std::shared_ptr conv; - if (conv_type == ngraph::opset8::Convolution::get_type_info_static()) { - conv = std::make_shared(mul, weights, strides, pad_begin, pad_end, strides); - } else if (conv_type == ngraph::opset8::GroupConvolution::get_type_info_static()) { - conv = std::make_shared(mul, weights, strides, pad_begin, pad_end, strides); - } else if (conv_type == ngraph::opset8::ConvolutionBackpropData::get_type_info_static()) { - conv = std::make_shared(mul, weights, strides, pad_begin, pad_end, strides); - } else if (conv_type == ngraph::opset8::GroupConvolutionBackpropData::get_type_info_static()) { - conv = std::make_shared(mul, weights, strides, pad_begin, pad_end, strides); + std::shared_ptr conv; + if (conv_type == ov::op::v1::Convolution::get_type_info_static()) { + conv = std::make_shared(mul, weights, strides, pad_begin, pad_end, strides); + } else if (conv_type == ov::op::v1::GroupConvolution::get_type_info_static()) { + conv = std::make_shared(mul, weights, strides, pad_begin, pad_end, strides); + } else if (conv_type == ov::op::v1::ConvolutionBackpropData::get_type_info_static()) { + conv = + std::make_shared(mul, weights, strides, pad_begin, pad_end, strides); + } else if (conv_type == ov::op::v1::GroupConvolutionBackpropData::get_type_info_static()) { + conv = std::make_shared(mul, + weights, + strides, + pad_begin, + pad_end, + strides); } else { OPENVINO_THROW("Unsupported type"); } - function = std::make_shared(ngraph::OutputVector{conv}, ngraph::ParameterVector{param}); - auto cloned_function = ngraph::clone_function(*function); + function = std::make_shared(ov::OutputVector{conv}, ov::ParameterVector{param}); + auto cloned_function = function->clone(); - ngraph::pass::Manager manager; + ov::pass::Manager manager; manager.register_pass(); manager.register_pass(); manager.register_pass(); @@ -65,58 +75,75 @@ void MulConvFusion::SetUp() { bool functions_equal = false; if (!is_negative) { - auto param = std::make_shared(precision, input_shape); - ngraph::Shape strides(spatial_dims, 1); + auto param = std::make_shared(precision, input_shape); + ov::Shape strides(spatial_dims, 1); std::vector pad_begin(spatial_dims, 0), pad_end(spatial_dims, 0); - std::shared_ptr conv; - if (conv_type == ngraph::opset8::Convolution::get_type_info_static()) { - weights = std::make_shared(weights, mul_const); + std::shared_ptr conv; + if (conv_type == ov::op::v1::Convolution::get_type_info_static()) { + weights = std::make_shared(weights, mul_const); weights = ov::get_constant_from_source(weights); ASSERT_NE(nullptr, weights); - conv = std::make_shared(param, weights, strides, pad_begin, pad_end, strides); - } else if (conv_type == ngraph::opset8::GroupConvolution::get_type_info_static()) { + conv = std::make_shared(param, weights, strides, pad_begin, pad_end, strides); + } else if (conv_type == ov::op::v1::GroupConvolution::get_type_info_static()) { const_shape.insert(const_shape.begin(), weights_shape.size() - const_shape.size(), 1); auto G = const_shape[2] > 1 ? weights_shape[0] : 1; const_shape[0] = G; const_shape[2] /= G; - auto reshape = std::make_shared(mul_const, - ngraph::op::Constant::create(ngraph::element::u64, ngraph::Shape{const_shape.size()}, const_shape), false); - weights = std::make_shared(weights, reshape); + auto reshape = std::make_shared( + mul_const, + ov::op::v0::Constant::create(ov::element::u64, ov::Shape{const_shape.size()}, const_shape), + false); + weights = std::make_shared(weights, reshape); weights = ov::get_constant_from_source(weights); ASSERT_NE(nullptr, weights); - conv = std::make_shared(param, weights, strides, pad_begin, pad_end, strides); - } else if (conv_type == ngraph::opset8::ConvolutionBackpropData::get_type_info_static()) { + conv = std::make_shared(param, weights, strides, pad_begin, pad_end, strides); + } else if (conv_type == ov::op::v1::ConvolutionBackpropData::get_type_info_static()) { const_shape.insert(const_shape.begin(), weights_shape.size() - const_shape.size(), 1); const_shape[0] = const_shape[1]; const_shape[1] = 1; - auto reshape = std::make_shared(mul_const, - ngraph::op::Constant::create(ngraph::element::u64, ngraph::Shape{const_shape.size()}, const_shape), false); - weights = std::make_shared(weights, reshape); + auto reshape = std::make_shared( + mul_const, + ov::op::v0::Constant::create(ov::element::u64, ov::Shape{const_shape.size()}, const_shape), + false); + weights = std::make_shared(weights, reshape); weights = ov::get_constant_from_source(weights); ASSERT_NE(nullptr, weights); - conv = std::make_shared(param, weights, strides, pad_begin, pad_end, strides); - } else if (conv_type == ngraph::opset8::GroupConvolutionBackpropData::get_type_info_static()) { + conv = std::make_shared(param, + weights, + strides, + pad_begin, + pad_end, + strides); + } else if (conv_type == ov::op::v1::GroupConvolutionBackpropData::get_type_info_static()) { const_shape.insert(const_shape.begin(), weights_shape.size() - const_shape.size(), 1); auto G = const_shape[2] > 1 ? weights_shape[0] : 1; const_shape[0] = G; const_shape[1] = const_shape[2] / G; const_shape[2] = 1; - auto reshape = std::make_shared(mul_const, - ngraph::op::Constant::create(ngraph::element::u64, ngraph::Shape{const_shape.size()}, const_shape), false); - weights = std::make_shared(weights, reshape); + auto reshape = std::make_shared( + mul_const, + ov::op::v0::Constant::create(ov::element::u64, ov::Shape{const_shape.size()}, const_shape), + false); + weights = std::make_shared(weights, reshape); weights = ov::get_constant_from_source(weights); ASSERT_NE(nullptr, weights); - conv = std::make_shared(param, weights, strides, pad_begin, pad_end, strides); + conv = std::make_shared(param, + weights, + strides, + pad_begin, + pad_end, + strides); } else { OPENVINO_THROW("Unsupported type"); } - auto reference_function = std::make_shared(ngraph::OutputVector{conv}, ngraph::ParameterVector{param}); + auto reference_function = std::make_shared(ov::OutputVector{conv}, ov::ParameterVector{param}); std::tie(functions_equal, std::ignore) = compare_functions(cloned_function, reference_function, true); ASSERT_TRUE(functions_equal); } else { - auto reference_function = ngraph::clone_function(*function); + auto reference_function = function->clone(); std::tie(functions_equal, std::ignore) = compare_functions(cloned_function, reference_function, true); ASSERT_TRUE(functions_equal); } } -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/subgraph/multiply_add.cpp b/src/tests/functional/shared_test_classes/src/subgraph/multiply_add.cpp index 8b070a70026d15..dfc1dcdb5f7fd5 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/multiply_add.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/multiply_add.cpp @@ -4,37 +4,43 @@ #include "shared_test_classes/subgraph/multiply_add.hpp" -namespace SubgraphTestsDefinitions { -std::string MultiplyAddLayerTest::getTestCaseName(const testing::TestParamInfo &obj) { - std::vector inputShapes; - InferenceEngine::Precision netPrecision; +#include "ov_models/builders.hpp" +#include "ov_models/utils/ov_helpers.hpp" + +namespace ov { +namespace test { + +std::string MultiplyAddLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + ov::Shape inputShapes; + ov::element::Type element_type; std::string targetName; - std::tie(inputShapes, netPrecision, targetName) = obj.param; + std::tie(inputShapes, element_type, targetName) = obj.param; std::ostringstream results; results << "IS=" << ov::test::utils::vec2str(inputShapes) << "_"; - results << "netPRC=" << netPrecision.name() << "_"; + results << "ET=" << element_type << "_"; results << "targetDevice=" << targetName << "_"; return results.str(); } void MultiplyAddLayerTest::SetUp() { - std::vector inputShape; - auto netPrecision = InferenceEngine::Precision::UNSPECIFIED; - std::tie(inputShape, netPrecision, targetDevice) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - auto paramOuts = ngraph::helpers::convert2OutputVector( - ngraph::helpers::castOps2Nodes(params)); + ov::Shape inputShape; + ov::element::Type element_type; + std::tie(inputShape, element_type, targetDevice) = this->GetParam(); + ov::ParameterVector params{std::make_shared(element_type, ov::PartialShape(inputShape))}; + auto paramOuts = + ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(params)); std::vector constShape(inputShape.size(), 1); constShape[1] = inputShape[1]; - auto const_mul = ngraph::builder::makeConstant(ngPrc, constShape, {}, true); - auto mul = std::make_shared(paramOuts[0], const_mul); - auto const_add = ngraph::builder::makeConstant(ngPrc, constShape, {}, true); - auto add = std::make_shared(mul, const_add); - ngraph::ResultVector results{std::make_shared(add)}; - function = std::make_shared(results, params, "multiplyAdd"); + auto const_mul = ngraph::builder::makeConstant(element_type, constShape, {}, true); + auto mul = std::make_shared(paramOuts[0], const_mul); + auto const_add = ngraph::builder::makeConstant(element_type, constShape, {}, true); + auto add = std::make_shared(mul, const_add); + ov::ResultVector results{std::make_shared(add)}; + function = std::make_shared(results, params, "multiplyAdd"); } -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/subgraph/mvn_multiply_add.cpp b/src/tests/functional/shared_test_classes/src/subgraph/mvn_multiply_add.cpp index 2371182175c711..9ff6272b9ab529 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/mvn_multiply_add.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/mvn_multiply_add.cpp @@ -4,12 +4,16 @@ #include "shared_test_classes/subgraph/mvn_multiply_add.hpp" -namespace SubgraphTestsDefinitions { +#include "ov_models/builders.hpp" +#include "ov_models/utils/ov_helpers.hpp" -std::string MVNMultiplyAdd::getTestCaseName(const testing::TestParamInfo &obj) { - std::pair shapes; - InferenceEngine::SizeVector inputShapes, constantShapes; - InferenceEngine::Precision dataPrecision, axesPrecision; +namespace ov { +namespace test { + +std::string MVNMultiplyAdd::getTestCaseName(const testing::TestParamInfo& obj) { + std::pair shapes; + ov::Shape inputShapes, constantShapes; + ov::element::Type dataPrecision, axesPrecision; std::vector axes; bool normalizeVariance; float eps; @@ -20,8 +24,8 @@ std::string MVNMultiplyAdd::getTestCaseName(const testing::TestParamInfo shapes; - InferenceEngine::SizeVector inputShapes, constantShapes; - InferenceEngine::Precision dataPrecision, axesPrecision; + std::pair shapes; + ov::Shape inputShapes, constantShapes; + ov::element::Type dataType, axesType; std::vector axes; bool normalizeVariance; float eps; std::string epsMode; - std::tie(shapes, dataPrecision, axesPrecision, axes, normalizeVariance, eps, epsMode, targetDevice) = this->GetParam(); + std::tie(shapes, dataType, axesType, axes, normalizeVariance, eps, epsMode, targetDevice) = this->GetParam(); std::tie(inputShapes, constantShapes) = shapes; - auto dataType = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(dataPrecision); - auto axesType = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(axesPrecision); - - ov::ParameterVector param {std::make_shared(dataType, ov::Shape(inputShapes))}; - auto paramOuts = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(param)); - auto axesNode = ngraph::builder::makeConstant(axesType, ngraph::Shape{axes.size()}, axes); + ov::ParameterVector param{std::make_shared(dataType, ov::Shape(inputShapes))}; + auto paramOuts = + ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(param)); + auto axesNode = ngraph::builder::makeConstant(axesType, ov::Shape{axes.size()}, axes); auto mvn = ngraph::builder::makeMVN6(paramOuts[0], axesNode, normalizeVariance, eps, epsMode); auto gamma = ngraph::builder::makeConstant(dataType, constantShapes, {}, true); - auto mul = std::make_shared(mvn, gamma); + auto mul = std::make_shared(mvn, gamma); auto beta = ngraph::builder::makeConstant(dataType, constantShapes, {}, true); - auto add = std::make_shared(mul, beta); + auto add = std::make_shared(mul, beta); - ngraph::ResultVector results{std::make_shared(add)}; - function = std::make_shared(results, param, "MVNMultiplyAdd"); + ov::ResultVector results{std::make_shared(add)}; + function = std::make_shared(results, param, "MVNMultiplyAdd"); } -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/subgraph/perm_conv_perm_concat.cpp b/src/tests/functional/shared_test_classes/src/subgraph/perm_conv_perm_concat.cpp index b488166297f618..e51e30a6caaa49 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/perm_conv_perm_concat.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/perm_conv_perm_concat.cpp @@ -4,105 +4,97 @@ #include "shared_test_classes/subgraph/perm_conv_perm_concat.hpp" -namespace SubgraphTestsDefinitions { +#include "common_test_utils/data_utils.hpp" +#include "functional_test_utils/skip_tests_config.hpp" +#include "ov_models/builders.hpp" + +namespace ov { +namespace test { + std::string PermConvPermConcat::getTestCaseName(const testing::TestParamInfo& obj) { - InferenceEngine::Precision netPrecision; + ov::element::Type element_type; std::string targetName; - std::array input_shape; - std::array kernel_shape; + ov::Shape input_shape; + ov::Shape kernel_shape; size_t output_channels; - std::map configuration; - + ov::AnyMap configuration; - std::tie(netPrecision, targetName, input_shape, kernel_shape, output_channels, configuration) = obj.param; + std::tie(element_type, targetName, input_shape, kernel_shape, output_channels, configuration) = obj.param; std::ostringstream results; results << "IS=" << ov::test::utils::vec2str(std::vector(input_shape.begin(), input_shape.end())) << "_"; results << "KS=" << ov::test::utils::vec2str(std::vector(kernel_shape.begin(), kernel_shape.end())) << "_"; results << "OC=" << output_channels << "_"; - results << "netPRC=" << netPrecision.name() << "_"; + results << "ET=" << element_type << "_"; results << "targetDevice=" << targetName; for (auto const& configItem : configuration) { - results << "_configItem=" << configItem.first << "_" << configItem.second; + results << "_configItem=" << configItem.first << "_" << configItem.second.as(); } return results.str(); } void PermConvPermConcat::SetUp() { - InferenceEngine::Precision netPrecision; - std::array input_shape; - std::array kernel_shape; + ov::element::Type element_type; + ov::Shape input_shape; + ov::Shape kernel_shape; size_t output_channels; - std::map additional_config; + ov::AnyMap additional_config; - std::tie(netPrecision, targetDevice, input_shape, kernel_shape, output_channels, additional_config) = this->GetParam(); + std::tie(element_type, targetDevice, input_shape, kernel_shape, output_channels, additional_config) = + this->GetParam(); configuration.insert(additional_config.begin(), additional_config.end()); const std::size_t input_dim = std::accumulate(input_shape.begin(), input_shape.end(), 1, std::multiplies()); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - std::vector input_dims { 1, input_dim }; + std::vector input_dims{1, input_dim}; std::vector reshape_in_dims = std::vector(input_shape.begin(), input_shape.end()); - std::vector permute_in_order = { 0, 3, 1, 2 }; - std::vector permute_out_order = { 0, 2, 3, 1 }; + std::vector permute_in_order = {0, 3, 1, 2}; + std::vector permute_out_order = {0, 2, 3, 1}; - ov::ParameterVector input_parameter {std::make_shared(ngPrc, ov::Shape(input_dims))}; + ov::ParameterVector input_parameter{std::make_shared(element_type, ov::Shape(input_dims))}; - auto reshape_in_pattern = std::make_shared(ngraph::element::i64, - ngraph::Shape{4}, - reshape_in_dims); - auto reshape_in = std::make_shared(input_parameter[0], reshape_in_pattern, false); + auto reshape_in_pattern = std::make_shared(ov::element::i64, ov::Shape{4}, reshape_in_dims); + auto reshape_in = std::make_shared(input_parameter[0], reshape_in_pattern, false); - auto permute_in_params = std::make_shared(ngraph::element::i64, - ngraph::Shape{4}, - ngraph::Shape{permute_in_order}); - auto permute_in = std::make_shared(reshape_in, permute_in_params); + auto permute_in_params = + std::make_shared(ov::element::i64, ov::Shape{4}, ov::Shape{permute_in_order}); + auto permute_in = std::make_shared(reshape_in, permute_in_params); auto conv_in_shape = permute_in->get_output_shape(0); auto conv_weights_size = output_channels * (conv_in_shape[1]) * kernel_shape[0] * kernel_shape[1]; - auto conv = ngraph::builder::makeConvolution(permute_in, ngPrc, {kernel_shape[0], kernel_shape[1]}, {1, 1}, {0, 0}, {0, 0}, {1, 1}, - ngraph::op::PadType::VALID, output_channels, false, ov::test::utils::generate_float_numbers(conv_weights_size, -0.5f, 0.5f)); - - auto permute_out_params = std::make_shared(ngraph::element::i64, - ngraph::Shape{4}, - permute_out_order); - auto permute_out = std::make_shared(conv, permute_out_params); + auto conv = + ngraph::builder::makeConvolution(permute_in, + element_type, + {kernel_shape[0], kernel_shape[1]}, + {1, 1}, + {0, 0}, + {0, 0}, + {1, 1}, + ov::op::PadType::VALID, + output_channels, + false, + ov::test::utils::generate_float_numbers(conv_weights_size, -0.5f, 0.5f)); + + auto permute_out_params = std::make_shared(ov::element::i64, ov::Shape{4}, permute_out_order); + auto permute_out = std::make_shared(conv, permute_out_params); auto permute_out_shape = permute_out->get_output_shape(0); - auto concat_const = ngraph::builder::makeConstant(ngPrc, {1, 1, 1, permute_out_shape[3]}, - ov::test::utils::generate_float_numbers(permute_out_shape[3], -10, 10)); + auto concat_const = + ngraph::builder::makeConstant(element_type, + {1, 1, 1, permute_out_shape[3]}, + ov::test::utils::generate_float_numbers(permute_out_shape[3], -10, 10)); auto concat = ngraph::builder::makeConcat({permute_out, concat_const}, 2); - auto reshape_out_pattern = std::make_shared(ngraph::element::i64, - ngraph::Shape{2}, + auto reshape_out_pattern = std::make_shared( + ov::element::i64, + ov::Shape{2}, InferenceEngine::SizeVector({1, (permute_out_shape[2] + 1) * permute_out_shape[3]})); - auto reshape_out = std::make_shared(concat, reshape_out_pattern, false); + auto reshape_out = std::make_shared(concat, reshape_out_pattern, false); - function = std::make_shared(reshape_out, input_parameter, "perm_conv_perm_concat"); + function = std::make_shared(reshape_out, input_parameter, "perm_conv_perm_concat"); } -void PermConvPermConcat::Run() { - SKIP_IF_CURRENT_TEST_IS_DISABLED() - - LoadNetwork(); - - inferRequest = executableNetwork.CreateInferRequest(); - inputs.clear(); - - for (const auto &input : cnnNetwork.getInputsInfo()) { - const auto &info = input.second; - auto tensorDesc = info->getTensorDesc(); - - auto blob = FuncTestUtils::createAndFillBlobFloat(tensorDesc, 2, -1, 100, 111); - - FuncTestUtils::fillInputsBySinValues(blob); - inferRequest.SetBlob(info->name(), blob); - inputs.push_back(blob); - } - inferRequest.Infer(); - - Validate(); -} -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/subgraph/range_add.cpp b/src/tests/functional/shared_test_classes/src/subgraph/range_add.cpp index 86cfab9864b6cf..129b19667baca8 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/range_add.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/range_add.cpp @@ -4,84 +4,79 @@ #include "shared_test_classes/subgraph/range_add.hpp" -namespace SubgraphTestsDefinitions { +#include "ov_models/builders.hpp" + +namespace ov { +namespace test { // ------------------------------ V0 ------------------------------ -std::string RangeAddSubgraphTest::getTestCaseName(const testing::TestParamInfo& obj) { - InferenceEngine::Precision netPrecision; - InferenceEngine::Precision inPrc, outPrc; - InferenceEngine::Layout inLayout, outLayout; +std::string RangeAddSubgraphTest::getTestCaseName(const testing::TestParamInfo& obj) { + ov::element::Type input_type; float start, stop, step; std::string targetDevice; - std::tie(start, stop, step, netPrecision, inPrc, outPrc, inLayout, outLayout, targetDevice) = obj.param; + std::tie(start, stop, step, input_type, targetDevice) = obj.param; std::ostringstream result; const char separator = '_'; result << "Start=" << start << separator; result << "Stop=" << stop << separator; result << "Step=" << step << separator; - result << "netPRC=" << netPrecision.name() << separator; + result << "ET=" << input_type << separator; result << "targetDevice=" << targetDevice; return result.str(); } void RangeAddSubgraphTest::SetUp() { - InferenceEngine::Precision netPrecision; + ov::element::Type element_type; float start, stop, step; - std::tie(start, stop, step, netPrecision, inPrc, outPrc, inLayout, outLayout, targetDevice) = GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - auto startConstant = std::make_shared(ngPrc, ngraph::Shape{}, start); - auto stopConstant = std::make_shared(ngPrc, ngraph::Shape{}, stop); - auto stepConstant = std::make_shared(ngPrc, ngraph::Shape{}, step); - auto range = std::make_shared(startConstant, stopConstant, stepConstant); - - ov::ParameterVector params{std::make_shared(ngPrc, range->get_shape())}; - auto eltwise = ngraph::builder::makeEltwise(params.front(), range, ngraph::helpers::EltwiseTypes::ADD); - const ngraph::ResultVector results{std::make_shared(eltwise)}; - function = std::make_shared(results, params, "RangeEltwise"); + std::tie(start, stop, step, element_type, targetDevice) = GetParam(); + + auto startConstant = std::make_shared(element_type, ov::Shape{}, start); + auto stopConstant = std::make_shared(element_type, ov::Shape{}, stop); + auto stepConstant = std::make_shared(element_type, ov::Shape{}, step); + auto range = std::make_shared(startConstant, stopConstant, stepConstant); + + ov::ParameterVector params{std::make_shared(element_type, range->get_shape())}; + auto eltwise = ngraph::builder::makeEltwise(params.front(), range, ov::test::utils::EltwiseTypes::ADD); + const ov::ResultVector results{std::make_shared(eltwise)}; + function = std::make_shared(results, params, "RangeEltwise"); } // ------------------------------ V4 ------------------------------ -std::string RangeNumpyAddSubgraphTest::getTestCaseName(const testing::TestParamInfo& obj) { - InferenceEngine::Precision netPrc; - InferenceEngine::Precision constPrc; - InferenceEngine::Precision outPrc; - InferenceEngine::Layout inLayout, outLayout; +std::string RangeNumpyAddSubgraphTest::getTestCaseName(const testing::TestParamInfo& obj) { + ov::element::Type element_type; float start, stop, step; std::string targetDevice; - std::tie(start, stop, step, constPrc, netPrc, outPrc, inLayout, outLayout, targetDevice) = obj.param; + std::tie(start, stop, step, element_type, targetDevice) = obj.param; std::ostringstream result; const char separator = '_'; result << "Start=" << start << separator; result << "Stop=" << stop << separator; result << "Step=" << step << separator; - result << "constPRC=" << constPrc.name() << separator; - result << "netPRC=" << netPrc.name() << separator; + result << "ET=" << element_type << separator; result << "targetDevice=" << targetDevice; return result.str(); } void RangeNumpyAddSubgraphTest::SetUp() { - InferenceEngine::Precision netPrc; - InferenceEngine::Precision constPrc; + ov::element::Type element_type; float start, stop, step; - std::tie(start, stop, step, constPrc, netPrc, outPrc, inLayout, outLayout, targetDevice) = GetParam(); - auto ngConstPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(constPrc); - auto ngNetPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrc); + std::tie(start, stop, step, element_type, targetDevice) = GetParam(); - auto startConstant = std::make_shared(ngConstPrc, ngraph::Shape{}, start); - auto stopConstant = std::make_shared(ngConstPrc, ngraph::Shape{}, stop); - auto stepConstant = std::make_shared(ngConstPrc, ngraph::Shape{}, step); - auto range = std::make_shared(startConstant, stopConstant, stepConstant, ngNetPrc); + auto startConstant = std::make_shared(element_type, ov::Shape{}, start); + auto stopConstant = std::make_shared(element_type, ov::Shape{}, stop); + auto stepConstant = std::make_shared(element_type, ov::Shape{}, step); + auto range = std::make_shared(startConstant, stopConstant, stepConstant, element_type); - ov::ParameterVector params{std::make_shared(ngNetPrc, range->get_shape())}; + ov::ParameterVector params{std::make_shared(element_type, range->get_shape())}; - auto eltwise = ngraph::builder::makeEltwise(params.front(), range, ngraph::helpers::EltwiseTypes::ADD); - const ngraph::ResultVector results{std::make_shared(eltwise)}; - function = std::make_shared(results, params, "RangeEltwise"); + auto eltwise = ngraph::builder::makeEltwise(params.front(), range, ov::test::utils::EltwiseTypes::ADD); + const ov::ResultVector results{std::make_shared(eltwise)}; + function = std::make_shared(results, params, "RangeEltwise"); } -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/subgraph/relu_shape_of.cpp b/src/tests/functional/shared_test_classes/src/subgraph/relu_shape_of.cpp index b23f32f4d5b99f..bbb78339d04e6f 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/relu_shape_of.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/relu_shape_of.cpp @@ -4,29 +4,32 @@ #include "shared_test_classes/subgraph/relu_shape_of.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { - std::string ReluShapeOfSubgraphTest::getTestCaseName(const testing::TestParamInfo& obj) { - InferenceEngine::SizeVector inputShapes; - InferenceEngine::Precision inputPrecision; - std::string targetDevice; - std::tie(inputPrecision, inputShapes, targetDevice) = obj.param; - std::ostringstream result; - result << "IS=" << ov::test::utils::vec2str(inputShapes) << "_"; - result << "Precision=" << inputPrecision.name() << "_"; - result << "TargetDevice=" << targetDevice; - return result.str(); - } +std::string ReluShapeOfSubgraphTest::getTestCaseName(const testing::TestParamInfo& obj) { + ov::Shape inputShapes; + ov::element::Type element_type, output_type; + std::string targetDevice; + std::tie(element_type, output_type, inputShapes, targetDevice) = obj.param; + std::ostringstream result; + result << "IS=" << ov::test::utils::vec2str(inputShapes) << "_"; + result << "IET=" << element_type << "_"; + result << "OET=" << output_type << "_"; + result << "TargetDevice=" << targetDevice; + return result.str(); +} - void ReluShapeOfSubgraphTest::SetUp() { - InferenceEngine::SizeVector inputShapes; - InferenceEngine::Precision inputPrecision; - std::tie(inputPrecision, inputShapes, targetDevice) = this->GetParam(); - auto inType = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inputPrecision); - ov::ParameterVector param {std::make_shared(inType, ov::Shape(inputShapes))}; - auto relu = std::make_shared(param[0]); - auto shapeOf = std::make_shared(relu, inType); - const ngraph::ResultVector results{std::make_shared(shapeOf)}; - function = std::make_shared(results, param, "ReluShapeOf"); - } -} // namespace SubgraphTestsDefinitions +void ReluShapeOfSubgraphTest::SetUp() { + ov::Shape inputShapes; + ov::element::Type element_type, output_type; + std::tie(element_type, output_type, inputShapes, targetDevice) = this->GetParam(); + ov::ParameterVector param{std::make_shared(element_type, ov::Shape(inputShapes))}; + auto relu = std::make_shared(param[0]); + auto shapeOf = std::make_shared(relu, output_type); + const ov::ResultVector results{std::make_shared(shapeOf)}; + function = std::make_shared(results, param, "ReluShapeOf"); +} + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/subgraph/reshape_squeeze_reshape_relu.cpp b/src/tests/functional/shared_test_classes/src/subgraph/reshape_squeeze_reshape_relu.cpp index 098f1d12a5ed89..1d0c680a55408e 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/reshape_squeeze_reshape_relu.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/reshape_squeeze_reshape_relu.cpp @@ -2,46 +2,50 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include "shared_test_classes/subgraph/reshape_squeeze_reshape_relu.hpp" -namespace SubgraphTestsDefinitions { - std::string ReshapeSqueezeReshapeRelu::getTestCaseName(const testing::TestParamInfo &obj) { - ShapeAxesTuple squeezeShape; - InferenceEngine::Precision netPrecision; - std::string targetName; - ngraph::helpers::SqueezeOpType opType; - std::tie(squeezeShape, netPrecision, targetName, opType) = obj.param; - std::ostringstream results; - results << "OpType=" << opType; - results << "IS=" << ov::test::utils::vec2str(squeezeShape.first) << "_"; - results << "indices=" << ov::test::utils::vec2str(squeezeShape.second) << "_"; - results << "netPRC=" << netPrecision.name() << "_"; - results << "targetDevice=" << targetName << "_"; - return results.str(); - } +#include "ov_models/builders.hpp" - void ReshapeSqueezeReshapeRelu::SetUp() { - ShapeAxesTuple squeezeShape; - InferenceEngine::Precision netPrecision; - ngraph::helpers::SqueezeOpType opType; - std::tie(squeezeShape, netPrecision, targetDevice, opType) = this->GetParam(); - const std::size_t input_dim = InferenceEngine::details::product(squeezeShape.first); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - std::vector shape_input{1, input_dim}; - ov::ParameterVector input {std::make_shared(ngPrc, ov::Shape(shape_input))}; - auto reshape1_pattern = std::make_shared(ngraph::element::i64, - ngraph::Shape{squeezeShape.first.size()}, - squeezeShape.first); - auto reshape1 = std::make_shared(input[0], reshape1_pattern, false); - auto squeeze = ngraph::builder::makeSqueezeUnsqueeze(reshape1, ngraph::element::i64, squeezeShape.second, opType); - auto reshape2_pattern = std::make_shared(ngraph::element::i64, - ngraph::Shape{2}, - std::vector{1, input_dim}); - auto reshape2 = std::make_shared(squeeze, reshape2_pattern, false); - auto func = std::make_shared(reshape2); - std::string squeezeType; +namespace ov { +namespace test { - function = std::make_shared(func, input, "reshape_squeeze_reshape_relu"); - } -} // namespace SubgraphTestsDefinitions +std::string ReshapeSqueezeReshapeRelu::getTestCaseName( + const testing::TestParamInfo& obj) { + ShapeAxesTuple squeezeShape; + ov::element::Type element_type; + std::string targetName; + ov::test::utils::SqueezeOpType opType; + std::tie(squeezeShape, element_type, targetName, opType) = obj.param; + std::ostringstream results; + results << "OpType=" << opType; + results << "IS=" << ov::test::utils::vec2str(squeezeShape.first) << "_"; + results << "indices=" << ov::test::utils::vec2str(squeezeShape.second) << "_"; + results << "netPRC=" << element_type << "_"; + results << "targetDevice=" << targetName << "_"; + return results.str(); +} + +void ReshapeSqueezeReshapeRelu::SetUp() { + ShapeAxesTuple squeezeShape; + ov::element::Type element_type; + ov::test::utils::SqueezeOpType opType; + std::tie(squeezeShape, element_type, targetDevice, opType) = this->GetParam(); + const size_t input_dim = ov::shape_size(squeezeShape.first); + std::vector shape_input{1, input_dim}; + ov::ParameterVector input{std::make_shared(element_type, ov::Shape(shape_input))}; + auto reshape1_pattern = std::make_shared(ov::element::i64, + ov::Shape{squeezeShape.first.size()}, + squeezeShape.first); + auto reshape1 = std::make_shared(input[0], reshape1_pattern, false); + auto squeeze = ngraph::builder::makeSqueezeUnsqueeze(reshape1, ov::element::i64, squeezeShape.second, opType); + auto reshape2_pattern = + std::make_shared(ov::element::i64, ov::Shape{2}, std::vector{1, input_dim}); + auto reshape2 = std::make_shared(squeeze, reshape2_pattern, false); + auto func = std::make_shared(reshape2); + std::string squeezeType; + + function = std::make_shared(func, input, "reshape_squeeze_reshape_relu"); +} + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/subgraph/split_conv_concat.cpp b/src/tests/functional/shared_test_classes/src/subgraph/split_conv_concat.cpp index 60ad615b7567a1..7dc009d0022fff 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/split_conv_concat.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/split_conv_concat.cpp @@ -4,30 +4,40 @@ #include "shared_test_classes/subgraph/split_conv_concat.hpp" -namespace SubgraphTestsDefinitions { +#include "common_test_utils/data_utils.hpp" +#include "ie_common.h" +#include "ov_models/builders.hpp" +#include "shared_test_classes/base/layer_test_utils.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" -std::string SplitConvConcat::getTestCaseName(const testing::TestParamInfo& obj) { - InferenceEngine::Precision netPrecision; - InferenceEngine::SizeVector inputShapes, newInputShapes; +namespace ov { +namespace test { + +std::string SplitConvConcat::getTestCaseName(const testing::TestParamInfo& obj) { + ov::element::Type element_type; + ov::Shape inputShapes; std::string targetDevice; - std::tie(netPrecision, inputShapes, targetDevice) = obj.param; + std::tie(element_type, inputShapes, targetDevice) = obj.param; std::ostringstream result; result << "IS=" << ov::test::utils::vec2str(inputShapes) << "_"; - result << "netPRC=" << netPrecision.name() << "_"; + result << "ET=" << element_type << "_"; result << "targetDevice=" << targetDevice; return result.str(); } void SplitConvConcat::SetUp() { - std::vector inputShape; - InferenceEngine::Precision netPrecision; - std::tie(netPrecision, inputShape, targetDevice) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + configure_test(this->GetParam()); +} + +void SplitConvConcatBase::configure_test(const ov::test::BasicParams& param) { + ov::Shape inputShape; + ov::element::Type element_type; + std::tie(element_type, inputShape, targetDevice) = param; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; + ov::ParameterVector params{std::make_shared(element_type, ov::Shape(inputShape))}; - auto split = ngraph::builder::makeSplit(params[0], ngPrc, 2, 1); + auto split = ngraph::builder::makeSplit(params[0], element_type, 2, 1); std::vector filterWeights1; std::vector filterWeights2; @@ -35,17 +45,65 @@ void SplitConvConcat::SetUp() { filterWeights1 = ov::test::utils::generate_float_numbers(8 * inputShape[1] / 2 * 3, -0.2f, 0.2f); filterWeights2 = ov::test::utils::generate_float_numbers(8 * inputShape[1] / 2 * 3, -0.2f, 0.2f); } - auto conv1 = ngraph::builder::makeConvolution(split->output(0), ngPrc, {1, 3}, {1, 1}, {0, 0}, {0, 0}, {1, 1}, - ngraph::op::PadType::VALID, 8, false, filterWeights1); - auto relu1 = std::make_shared(conv1); + auto conv1 = ngraph::builder::makeConvolution(split->output(0), + element_type, + {1, 3}, + {1, 1}, + {0, 0}, + {0, 0}, + {1, 1}, + ov::op::PadType::VALID, + 8, + false, + filterWeights1); + auto relu1 = std::make_shared(conv1); + + auto conv2 = ngraph::builder::makeConvolution(split->output(1), + element_type, + {1, 3}, + {1, 1}, + {0, 0}, + {0, 0}, + {1, 1}, + ov::op::PadType::VALID, + 8, + false, + filterWeights2); + auto relu2 = std::make_shared(conv2); + auto concat = std::make_shared(ov::OutputVector{relu1->output(0), relu2->output(0)}, 1); + + ov::ResultVector results{std::make_shared(concat)}; + function = std::make_shared(results, params, "SplitConvConcat"); +} + +} // namespace test +} // namespace ov + +namespace SubgraphTestsDefinitions { - auto conv2 = ngraph::builder::makeConvolution(split->output(1), ngPrc, {1, 3}, {1, 1}, {0, 0}, {0, 0}, {1, 1}, - ngraph::op::PadType::VALID, 8, false, filterWeights2); - auto relu2 = std::make_shared(conv2); - auto concat = std::make_shared(ngraph::OutputVector{relu1->output(0), relu2->output(0)}, 1); +std::string SplitConvConcat::getTestCaseName(const testing::TestParamInfo& obj) { + InferenceEngine::Precision precision; + InferenceEngine::SizeVector inputShapes; + std::string targetDevice; + std::tie(precision, inputShapes, targetDevice) = obj.param; + auto element_type = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(precision); + + std::ostringstream result; + result << "IS=" << ov::test::utils::vec2str(inputShapes) << "_"; + result << "ET=" << element_type << "_"; + result << "targetDevice=" << targetDevice; + return result.str(); +} + +void SplitConvConcat::SetUp() { + InferenceEngine::Precision precision; + InferenceEngine::SizeVector inputShapes; + std::tie(precision, inputShapes, targetDevice) = this->GetParam(); + auto element_type = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(precision); + ov::Shape shape = inputShapes; - ngraph::ResultVector results{std::make_shared(concat)}; - function = std::make_shared(results, params, "SplitConvConcat"); + ov::test::BasicParams param(element_type, shape, targetDevice); + configure_test(param); } } // namespace SubgraphTestsDefinitions diff --git a/src/tests/functional/shared_test_classes/src/subgraph/variadic_split_pad.cpp b/src/tests/functional/shared_test_classes/src/subgraph/variadic_split_pad.cpp index 13d1c9c542c5cb..8c7906c275e3c1 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/variadic_split_pad.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/variadic_split_pad.cpp @@ -4,48 +4,54 @@ #include "shared_test_classes/subgraph/variadic_split_pad.hpp" -namespace SubgraphTestsDefinitions { +#include "ov_models/builders.hpp" -std::string VariadicSplitPad::getTestCaseName(const testing::TestParamInfo &obj) { - InferenceEngine::SizeVector inputShape; +namespace ov { +namespace test { + +std::string VariadicSplitPad::getTestCaseName(const testing::TestParamInfo& obj) { + ov::Shape input_shape; int64_t axis; std::vector numSplits, connectIndexes; std::vector padsBegin, padsEnd; - ngraph::helpers::PadMode padMode; - InferenceEngine::Precision netPrecision; + ov::op::PadMode padMode; + ov::element::Type element_type; std::string targetName; - std::tie(inputShape, axis, numSplits, connectIndexes, padsBegin, padsEnd, padMode, netPrecision, targetName) = obj.param; + std::tie(input_shape, axis, numSplits, connectIndexes, padsBegin, padsEnd, padMode, element_type, targetName) = + obj.param; std::ostringstream results; - results << "IS=" << ov::test::utils::vec2str(inputShape) << "_"; + results << "IS=" << ov::test::utils::vec2str(input_shape) << "_"; results << "Axis=" << axis << "_"; results << "NumSplits=" << ov::test::utils::vec2str(numSplits) << "_"; results << "ConnectIndexes=" << ov::test::utils::vec2str(connectIndexes) << "_"; results << "padsBegin=" << ov::test::utils::vec2str(padsBegin) << "_"; results << "padsEnd=" << ov::test::utils::vec2str(padsEnd) << "_"; results << "PadMode=" << padMode << "_"; - results << "netPRC=" << netPrecision.name() << "_"; + results << "netPRC=" << element_type << "_"; results << "targetDevice=" << targetName << "_"; return results.str(); } void VariadicSplitPad::SetUp() { - InferenceEngine::SizeVector inputs; + ov::Shape input_shape; int64_t axis; std::vector numSplits, connectIndexes; std::vector padBegin, padEnd; - ngraph::helpers::PadMode padMode; - InferenceEngine::Precision netPrecision; - std::tie(inputs, axis, numSplits, connectIndexes, padBegin, padEnd, padMode, netPrecision, targetDevice) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::ParameterVector input {std::make_shared(ngPrc, ov::Shape(inputs))}; + ov::op::PadMode padMode; + ov::element::Type element_type; + std::tie(input_shape, axis, numSplits, connectIndexes, padBegin, padEnd, padMode, element_type, targetDevice) = + this->GetParam(); + ov::ParameterVector input{std::make_shared(element_type, ov::Shape(input_shape))}; auto split = ngraph::builder::makeVariadicSplit(input[0], numSplits, axis); - ngraph::ResultVector results; + ov::ResultVector results; for (size_t i : connectIndexes) { auto pad = ngraph::builder::makePad(split->output(i), padBegin, padEnd, 0, padMode); - results.push_back(std::make_shared(pad)); + results.push_back(std::make_shared(pad)); } - function = std::make_shared(results, input, "variadic_split_pad"); + function = std::make_shared(results, input, "variadic_split_pad"); } -} // namespace SubgraphTestsDefinitions + +} // namespace test +} // namespace ov diff --git a/src/tests/ov_helpers/ov_lpt_models/CMakeLists.txt b/src/tests/ov_helpers/ov_lpt_models/CMakeLists.txt index f2b4514c5b0d32..7eda3438659f0d 100644 --- a/src/tests/ov_helpers/ov_lpt_models/CMakeLists.txt +++ b/src/tests/ov_helpers/ov_lpt_models/CMakeLists.txt @@ -12,7 +12,7 @@ ov_add_target( ROOT ${PUBLIC_HEADERS_DIR} INCLUDES PUBLIC - ${PUBLIC_HEADERS_DIR} + "$" ADDITIONAL_SOURCE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src LINK_LIBRARIES @@ -20,13 +20,14 @@ ov_add_target( ov_models openvino::runtime::dev ADD_CPPLINT - DEPENDENCIES - ov_models - DEVELOPER_PACKAGE - tests ) ov_build_target_faster(${TARGET_NAME} UNITY PCH PRIVATE "src/precomp.hpp" ) + +# install & export + +ov_developer_package_export_targets(TARGET ${TARGET_NAME} + INSTALL_INCLUDE_DIRECTORIES "${PUBLIC_HEADERS_DIR}/") diff --git a/src/tests/ov_helpers/ov_models/CMakeLists.txt b/src/tests/ov_helpers/ov_models/CMakeLists.txt index 6d2989f94af734..69631bd82ba2a0 100644 --- a/src/tests/ov_helpers/ov_models/CMakeLists.txt +++ b/src/tests/ov_helpers/ov_models/CMakeLists.txt @@ -12,22 +12,25 @@ ov_add_target( ROOT ${PUBLIC_HEADERS_DIR} INCLUDES PUBLIC - ${PUBLIC_HEADERS_DIR} + "$" ADDITIONAL_SOURCE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src LINK_LIBRARIES PUBLIC openvino::runtime openvino::reference - interpreter_backend + openvino::interpreter_backend openvino::runtime::dev common_test_utils ADD_CLANG_FORMAT - DEVELOPER_PACKAGE - tests ) ov_build_target_faster(${TARGET_NAME} UNITY PCH PRIVATE "src/precomp.hpp" ) + +# install & export + +ov_developer_package_export_targets(TARGET ${TARGET_NAME} + INSTALL_INCLUDE_DIRECTORIES "${PUBLIC_HEADERS_DIR}/") diff --git a/src/tests/ov_helpers/ov_models/include/ov_models/builders.hpp b/src/tests/ov_helpers/ov_models/include/ov_models/builders.hpp index 664147ae1b7eb6..7fa2e675372f26 100644 --- a/src/tests/ov_helpers/ov_models/include/ov_models/builders.hpp +++ b/src/tests/ov_helpers/ov_models/include/ov_models/builders.hpp @@ -70,6 +70,7 @@ std::shared_ptr makeConstant(const ov::element::Type& type, makeNode(ov::element::Type_t::u32); makeNode(ov::element::Type_t::u64); makeNode(ov::element::Type_t::boolean); + makeNode(ov::element::Type_t::nf4); #undef makeNode default: throw std::runtime_error("Unhandled precision"); diff --git a/src/tests/ov_helpers/ov_snippets_models/CMakeLists.txt b/src/tests/ov_helpers/ov_snippets_models/CMakeLists.txt index 69cd602bb5eab5..24f1efae26a9e8 100644 --- a/src/tests/ov_helpers/ov_snippets_models/CMakeLists.txt +++ b/src/tests/ov_helpers/ov_snippets_models/CMakeLists.txt @@ -5,8 +5,6 @@ set(TARGET_NAME ov_snippets_models) set(PUBLIC_HEADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") -set(SNIPPETS_INCLUDES "$/include") -set(COMMON_TEST_UTILS_INCLUDES "$") ov_add_target( NAME ${TARGET_NAME} @@ -14,11 +12,8 @@ ov_add_target( ROOT ${PUBLIC_HEADERS_DIR} INCLUDES PUBLIC - ${PUBLIC_HEADERS_DIR} - ${COMMON_TEST_UTILS_INCLUDES} - PRIVATE - ${SNIPPETS_INCLUDES} - + "$" + "$" ADDITIONAL_SOURCE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src LINK_LIBRARIES @@ -28,11 +23,14 @@ ov_add_target( openvino::snippets ov_lpt_models ADD_CPPLINT - DEVELOPER_PACKAGE - tests ) ov_build_target_faster(${TARGET_NAME} UNITY PCH PRIVATE "src/precomp.hpp" ) + +# install & export + +ov_developer_package_export_targets(TARGET ${TARGET_NAME} + INSTALL_INCLUDE_DIRECTORIES "${PUBLIC_HEADERS_DIR}/") diff --git a/src/tests/test_utils/common_test_utils/CMakeLists.txt b/src/tests/test_utils/common_test_utils/CMakeLists.txt index 3d63059962c4f1..1112ccd08558af 100644 --- a/src/tests/test_utils/common_test_utils/CMakeLists.txt +++ b/src/tests/test_utils/common_test_utils/CMakeLists.txt @@ -23,8 +23,6 @@ function(add_common_utils ADD_TARGET_NAME) EXCLUDED_SOURCE_PATHS ${TARGET_EXCLUDED_SOURCE_PATHS} ADD_CLANG_FORMAT - DEVELOPER_PACKAGE - tests LINK_LIBRARIES PUBLIC gtest @@ -38,12 +36,14 @@ function(add_common_utils ADD_TARGET_NAME) openvino::shape_inference INCLUDES PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/include" + "$" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src" - ) + ov_developer_package_export_targets(TARGET ${ADD_TARGET_NAME} + INSTALL_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include/") + if(ENABLE_CONFORMANCE_PGQL) target_compile_definitions(${ADD_TARGET_NAME} PUBLIC ENABLE_CONFORMANCE_PGQL) endif() @@ -58,31 +58,14 @@ function(add_common_utils ADD_TARGET_NAME) PCH PRIVATE "src/precomp.hpp" ) - # detecting regex support - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) - set(USE_BOOST_RE ON) - endif() - if (USE_BOOST_RE) - target_compile_definitions(${ADD_TARGET_NAME} PUBLIC USE_BOOST_RE) - - debug_message(STATUS "Adding boost dependency") - if (CMAKE_VERBOSE_MAKEFILE) - set(Boost_DEBUG on) - endif () - find_package(Boost REQUIRED COMPONENTS regex) - target_link_libraries(${ADD_TARGET_NAME} PUBLIC ${Boost_REGEX_LIBRARY}) - target_include_directories(${ADD_TARGET_NAME} PUBLIC ${Boost_INCLUDE_DIRS}) - endif () - target_include_directories(${ADD_TARGET_NAME} PUBLIC $ PRIVATE $) - target_include_directories(${ADD_TARGET_NAME} SYSTEM PUBLIC ${IE_TESTS_ROOT}/test_utils) + target_include_directories(${ADD_TARGET_NAME} SYSTEM PUBLIC "$") target_compile_definitions(${ADD_TARGET_NAME} PUBLIC ${ARGN}) - endfunction() # Keep old name so that library can be used from NPU repo diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/common_utils.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/common_utils.hpp index cc45a47d779d57..0bd9f4845d481b 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/common_utils.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/common_utils.hpp @@ -115,6 +115,10 @@ inline std::string set2str(const std::set& set) { return std::string("()"); } +inline std::string bool2str(const bool val) { + return val ? "True" : "False"; +} + template std::vector> combineParams(const std::map>& keyValueSets) { std::vector> resVec; diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/data_utils.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/data_utils.hpp index eacad438e30dfb..3b876a530cdf33 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/data_utils.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/data_utils.hpp @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include @@ -157,52 +158,14 @@ inline void fill_data_roi(InferenceEngine::Blob::Ptr& blob, fill_roi_raw_ptr(data, blob->size(), range, height, width, omega, is_roi_max_mode, seed); } -template -inline void fill_data_roi(ov::runtime::Tensor& tensor, - const uint32_t range, - const int height, - const int width, - const float omega, - const bool is_roi_max_mode, - const int seed = 1) { - using T = typename InferenceEngine::PrecisionTrait::value_type; - auto* data = static_cast(tensor.data()); - std::default_random_engine random(seed); - std::uniform_int_distribution distribution(0, range); - - const int max_y = (is_roi_max_mode) ? (height - 1) : 1; - const int max_x = (is_roi_max_mode) ? (width - 1) : 1; - - float center_h = (max_y) / 2.0f; - float center_w = (max_x) / 2.0f; +void fill_data_roi(ov::runtime::Tensor& tensor, + const uint32_t range, + const int height, + const int width, + const float omega, + const bool is_roi_max_mode, + const int seed = 1); - for (size_t i = 0; i < tensor.get_size(); i += 5) { - data[i] = static_cast(distribution(random)); - const float x0 = (center_w + width * 0.3f * sin(static_cast(i + 1) * omega)); - const float x1 = (center_w + width * 0.3f * sin(static_cast(i + 3) * omega)); - data[i + 1] = static_cast(is_roi_max_mode ? std::floor(x0) : x0); - data[i + 3] = static_cast(is_roi_max_mode ? std::floor(x1) : x1); - if (data[i + 3] < data[i + 1]) { - std::swap(data[i + 1], data[i + 3]); - } - if (data[i + 1] < 0) - data[i + 1] = 0; - if (data[i + 3] > max_x) - data[i + 3] = static_cast(max_x); - - const float y0 = (center_h + height * 0.3f * sin(static_cast(i + 2) * omega)); - const float y1 = (center_h + height * 0.3f * sin(static_cast(i + 4) * omega)); - data[i + 2] = static_cast(is_roi_max_mode ? std::floor(y0) : y0); - data[i + 4] = static_cast(is_roi_max_mode ? std::floor(y1) : y1); - if (data[i + 4] < data[i + 2]) { - std::swap(data[i + 2], data[i + 4]); - } - if (data[i + 2] < 0) - data[i + 2] = 0; - if (data[i + 4] > max_y) - data[i + 4] = static_cast(max_y); - } -} OPENVINO_SUPPRESS_DEPRECATED_END template @@ -223,7 +186,7 @@ void inline fill_data_random(T* pointer, const uint32_t k_range = k * range; // range with respect to k random.Generate(k_range); - if (start_from < 0 && !std::is_signed::value) { + if (start_from < 0 && !std::numeric_limits::is_signed) { start_from = 0; } for (std::size_t i = 0; i < size; i++) { @@ -269,9 +232,9 @@ void inline fill_random_unique_sequence(T* rawBlobDataPtr, auto value = static_cast(dist(generator)); value /= static_cast(k); if (std::is_same::value) { - elems.insert(static_cast(ov::float16(value).to_bits())); + elems.insert(static_cast(ov::float16(value))); } else if (std::is_same::value) { - elems.insert(static_cast(ov::bfloat16(value).to_bits())); + elems.insert(static_cast(ov::bfloat16(value))); } else { elems.insert(static_cast(value)); } diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/file_utils.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/file_utils.hpp index 6c5e66faabe4a0..58920ee8cf4379 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/file_utils.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/file_utils.hpp @@ -288,7 +288,7 @@ namespace { inline std::string get_mock_engine_path() { std::string mockEngineName("mock_engine"); return ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - mockEngineName + IE_BUILD_POSTFIX); + mockEngineName + OV_BUILD_POSTFIX); } template diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/graph_comparator.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/graph_comparator.hpp index cb90c0699a126d..22373d55292d2a 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/graph_comparator.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/graph_comparator.hpp @@ -14,6 +14,7 @@ #include "openvino/op/loop.hpp" #include "openvino/op/util/framework_node.hpp" #include "openvino/op/util/sub_graph_base.hpp" +#include "openvino/runtime/aligned_buffer.hpp" class FunctionsComparator { public: @@ -945,9 +946,7 @@ class ReadAndCompareAttributes : public ov::AttributeVisitor { template void verify(const std::string& name, const AttrValue& attr_value); - OPENVINO_SUPPRESS_DEPRECATED_START - void verify_mem_buf(const std::string& name, const std::shared_ptr& buffer); - OPENVINO_SUPPRESS_DEPRECATED_END + void verify_mem_buf(const std::string& name, const std::shared_ptr& buffer); using ModelAccessor = ov::ValueAccessor>; diff --git a/src/tests/test_utils/common_test_utils/src/data_utils.cpp b/src/tests/test_utils/common_test_utils/src/data_utils.cpp index 9991b976b467f6..ed956e7f860fd4 100644 --- a/src/tests/test_utils/common_test_utils/src/data_utils.cpp +++ b/src/tests/test_utils/common_test_utils/src/data_utils.cpp @@ -250,6 +250,88 @@ size_t byte_size(const InferenceEngine::TensorDesc& tdesc) { } OPENVINO_SUPPRESS_DEPRECATED_END +template +inline void fill_data_roi_impl(ov::runtime::Tensor& tensor, + const uint32_t range, + const int height, + const int width, + const float omega, + const bool is_roi_max_mode, + const int seed = 1) { + using T = typename ov::fundamental_type_for; + auto* data = static_cast(tensor.data()); + std::default_random_engine random(seed); + std::uniform_int_distribution distribution(0, range); + + const int max_y = (is_roi_max_mode) ? (height - 1) : 1; + const int max_x = (is_roi_max_mode) ? (width - 1) : 1; + + float center_h = (max_y) / 2.0f; + float center_w = (max_x) / 2.0f; + + for (size_t i = 0; i < tensor.get_size(); i += 5) { + data[i] = static_cast(distribution(random)); + const float x0 = (center_w + width * 0.3f * sin(static_cast(i + 1) * omega)); + const float x1 = (center_w + width * 0.3f * sin(static_cast(i + 3) * omega)); + data[i + 1] = static_cast(is_roi_max_mode ? std::floor(x0) : x0); + data[i + 3] = static_cast(is_roi_max_mode ? std::floor(x1) : x1); + if (data[i + 3] < data[i + 1]) { + std::swap(data[i + 1], data[i + 3]); + } + if (data[i + 1] < 0) + data[i + 1] = 0; + if (data[i + 3] > max_x) + data[i + 3] = static_cast(max_x); + + const float y0 = (center_h + height * 0.3f * sin(static_cast(i + 2) * omega)); + const float y1 = (center_h + height * 0.3f * sin(static_cast(i + 4) * omega)); + data[i + 2] = static_cast(is_roi_max_mode ? std::floor(y0) : y0); + data[i + 4] = static_cast(is_roi_max_mode ? std::floor(y1) : y1); + if (data[i + 4] < data[i + 2]) { + std::swap(data[i + 2], data[i + 4]); + } + if (data[i + 2] < 0) + data[i + 2] = 0; + if (data[i + 4] > max_y) + data[i + 4] = static_cast(max_y); + } +} + +void fill_data_roi(ov::runtime::Tensor& tensor, + const uint32_t range, + const int height, + const int width, + const float omega, + const bool is_roi_max_mode, + const int seed) { +#define CASE(X) \ + case X: \ + fill_data_roi_impl(tensor, range, height, width, omega, is_roi_max_mode, seed); \ + break; + + auto element_type = tensor.get_element_type(); + switch (element_type) { + CASE(ov::element::f64) + CASE(ov::element::f32) + CASE(ov::element::f16) + CASE(ov::element::bf16) + CASE(ov::element::u1) + CASE(ov::element::u4) + CASE(ov::element::u8) + CASE(ov::element::u32) + CASE(ov::element::u16) + CASE(ov::element::u64) + CASE(ov::element::i4) + CASE(ov::element::i8) + CASE(ov::element::i16) + CASE(ov::element::i32) + CASE(ov::element::i64) + default: + OPENVINO_THROW("Wrong precision specified: ", element_type); + } +#undef CASE +} + void fill_data_with_broadcast(ov::Tensor& tensor, ov::Tensor& values) { constexpr size_t MAX_N_DIMS = 7; // Suppose it's enough diff --git a/src/tests/test_utils/common_test_utils/src/graph_comparator.cpp b/src/tests/test_utils/common_test_utils/src/graph_comparator.cpp index e3c5a8b2ec1a55..053e0d6d42899a 100644 --- a/src/tests/test_utils/common_test_utils/src/graph_comparator.cpp +++ b/src/tests/test_utils/common_test_utils/src/graph_comparator.cpp @@ -895,7 +895,6 @@ void check_rt_info(const std::shared_ptr& f) { namespace attributes { namespace detail { -OPENVINO_SUPPRESS_DEPRECATED_START void ReadAndStoreAttributes::on_adapter(const std::string& name, ov::ValueAccessor& adapter) { if (auto inputs = ov::as_type>(&adapter)) { insert(name, inputs->get()); @@ -904,7 +903,7 @@ void ReadAndStoreAttributes::on_adapter(const std::string& name, ov::ValueAccess } else if (ov::is_type>(&adapter)) { // drop comparison, no more info than port indexes which will be check in // subgraph::compare_io - } else if (auto a = ov::as_type>>(&adapter)) { + } else if (auto a = ov::as_type>>(&adapter)) { const auto beg = static_cast(a->get()->get_ptr()); const auto end = beg + a->get()->size(); insert(name, storage::MemoryChunk{storage::MemoryChunk::Data(beg, end)}); @@ -923,7 +922,6 @@ void ReadAndStoreAttributes::on_adapter(const std::string& name, ov::ValueAccess adapter.get_type_info().name + "']"; } } -OPENVINO_SUPPRESS_DEPRECATED_END template void ReadAndCompareAttributes::verify(const std::string& name, const AttrValue& attr_value) { if (should_return()) { @@ -942,9 +940,8 @@ void ReadAndCompareAttributes::verify(const std::string& name, const AttrValue& } } -OPENVINO_SUPPRESS_DEPRECATED_START void ReadAndCompareAttributes::verify_mem_buf(const std::string& name, - const std::shared_ptr& buffer) { + const std::shared_ptr& buffer) { if (should_return()) { return; } @@ -961,7 +958,6 @@ void ReadAndCompareAttributes::verify_mem_buf(const std::string& name, return; } } -OPENVINO_SUPPRESS_DEPRECATED_END void ReadAndCompareAttributes::verify_function(const std::string& name, ModelAccessor& adapter) { if (should_return()) { @@ -980,7 +976,6 @@ void ReadAndCompareAttributes::verify_function(const std::string& name, ModelAcc } } -OPENVINO_SUPPRESS_DEPRECATED_START void ReadAndCompareAttributes::verify_others(const std::string& name, ov::ValueAccessor& adapter) { if (auto inputs = ov::as_type>(&adapter)) { verify(name, inputs->get()); @@ -989,7 +984,7 @@ void ReadAndCompareAttributes::verify_others(const std::string& name, ov::ValueA } else if (ov::is_type>(&adapter)) { // drop comparison, no more info than port indexes which will be check in // subgraph::compare_io - } else if (auto a = ov::as_type>>(&adapter)) { + } else if (auto a = ov::as_type>>(&adapter)) { verify_mem_buf(name, a->get()); } else if (auto attrs = ov::as_type>(&adapter)) { verify(name, attrs->get()); @@ -1005,7 +1000,6 @@ void ReadAndCompareAttributes::verify_others(const std::string& name, ov::ValueA adapter.get_type_info().name + "']"; } } -OPENVINO_SUPPRESS_DEPRECATED_END } // namespace detail diff --git a/src/tests/test_utils/common_test_utils/src/test_case.cpp b/src/tests/test_utils/common_test_utils/src/test_case.cpp index 213af43397d985..2fb703e7603ee5 100644 --- a/src/tests/test_utils/common_test_utils/src/test_case.cpp +++ b/src/tests/test_utils/common_test_utils/src/test_case.cpp @@ -192,7 +192,7 @@ TestCase::TestCase(const std::shared_ptr& function, const std::string // Register template plugin m_core.register_plugin( ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), - std::string("openvino_template_plugin") + IE_BUILD_POSTFIX), + std::string("openvino_template_plugin") + OV_BUILD_POSTFIX), "TEMPLATE"); } catch (...) { } diff --git a/src/tests/test_utils/functional_test_utils/CMakeLists.txt b/src/tests/test_utils/functional_test_utils/CMakeLists.txt index c990febcd6a0b2..e1148d82ee1132 100644 --- a/src/tests/test_utils/functional_test_utils/CMakeLists.txt +++ b/src/tests/test_utils/functional_test_utils/CMakeLists.txt @@ -9,11 +9,9 @@ ov_add_target( TYPE STATIC ROOT ${CMAKE_CURRENT_SOURCE_DIR} ADD_CLANG_FORMAT - DEVELOPER_PACKAGE - tests INCLUDES PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/include" + "$" ADDITIONAL_SOURCE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src LINK_LIBRARIES @@ -24,13 +22,17 @@ ov_add_target( PRIVATE ov_models openvino::pugixml - INCLUDES - PUBLIC - $ ) -install(DIRECTORY layer_tests_summary DESTINATION tests/functional_test_utils COMPONENT tests EXCLUDE_FROM_ALL) - ov_build_target_faster(${TARGET_NAME} PCH PRIVATE "src/precomp.hpp" ) + +# install & export + +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/layer_tests_summary" + DESTINATION tests/functional_test_utils + COMPONENT tests EXCLUDE_FROM_ALL) + +ov_developer_package_export_targets(TARGET ${TARGET_NAME} + INSTALL_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include/") diff --git a/src/tests/test_utils/functional_test_utils/include/functional_test_utils/summary/op_info.hpp b/src/tests/test_utils/functional_test_utils/include/functional_test_utils/summary/op_info.hpp index df4377d5cf9ad4..ef76694caf9691 100644 --- a/src/tests/test_utils/functional_test_utils/include/functional_test_utils/summary/op_info.hpp +++ b/src/tests/test_utils/functional_test_utils/include/functional_test_utils/summary/op_info.hpp @@ -4,45 +4,95 @@ #pragma once +#include "openvino/op/ops.hpp" #include "openvino/openvino.hpp" namespace ov { namespace test { namespace functional { +// {{ type_info, real_version }} +const std::map not_aligned_op_version = { + // opset 1 + {ov::op::v0::Abs::get_type_info_static(), 0}, + {ov::op::v0::Acos::get_type_info_static(), 0}, + {ov::op::v0::Asin::get_type_info_static(), 0}, + {ov::op::v0::Atan::get_type_info_static(), 0}, + {ov::op::v0::BatchNormInference::get_type_info_static(), 0}, + {ov::op::v0::CTCGreedyDecoder::get_type_info_static(), 0}, + {ov::op::v0::Ceiling::get_type_info_static(), 0}, + {ov::op::v0::Clamp::get_type_info_static(), 0}, + {ov::op::v0::Concat::get_type_info_static(), 0}, + {ov::op::v0::Constant::get_type_info_static(), 0}, + {ov::op::v0::Convert::get_type_info_static(), 0}, + {ov::op::v0::Cos::get_type_info_static(), 0}, + {ov::op::v0::Cosh::get_type_info_static(), 0}, + {ov::op::v0::DepthToSpace::get_type_info_static(), 0}, + {ov::op::v0::DetectionOutput::get_type_info_static(), 0}, + {ov::op::v0::Elu::get_type_info_static(), 0}, + {ov::op::v0::Erf::get_type_info_static(), 0}, + {ov::op::v0::Exp::get_type_info_static(), 0}, + {ov::op::v0::FakeQuantize::get_type_info_static(), 0}, + {ov::op::v0::Floor::get_type_info_static(), 0}, + {ov::op::v0::GRN::get_type_info_static(), 0}, + {ov::op::v0::HardSigmoid::get_type_info_static(), 0}, + {ov::op::v0::Interpolate::get_type_info_static(), 0}, + {ov::op::v0::Log::get_type_info_static(), 0}, + {ov::op::v0::LRN::get_type_info_static(), 0}, + {ov::op::v0::LSTMCell::get_type_info_static(), 0}, + {ov::op::v0::LSTMSequence::get_type_info_static(), 0}, + {ov::op::v0::MatMul::get_type_info_static(), 0}, + {ov::op::v0::Negative::get_type_info_static(), 0}, + {ov::op::v0::NormalizeL2::get_type_info_static(), 0}, + {ov::op::v0::PRelu::get_type_info_static(), 0}, + {ov::op::v0::PSROIPooling::get_type_info_static(), 0}, + {ov::op::v0::Parameter::get_type_info_static(), 0}, + {ov::op::v0::PriorBox::get_type_info_static(), 0}, + {ov::op::v0::PriorBoxClustered::get_type_info_static(), 0}, + {ov::op::v0::Proposal::get_type_info_static(), 0}, + {ov::op::v0::Range::get_type_info_static(), 0}, + {ov::op::v0::Relu::get_type_info_static(), 0}, + {ov::op::v0::RegionYolo::get_type_info_static(), 0}, + {ov::op::v0::Result::get_type_info_static(), 0}, + {ov::op::v0::ReverseSequence::get_type_info_static(), 0}, + {ov::op::v0::RNNCell::get_type_info_static(), 0}, + {ov::op::v0::Selu::get_type_info_static(), 0}, + {ov::op::v0::ShapeOf::get_type_info_static(), 0}, + {ov::op::v0::ShuffleChannels::get_type_info_static(), 0}, + {ov::op::v0::Sign::get_type_info_static(), 0}, + {ov::op::v0::Sigmoid::get_type_info_static(), 0}, + {ov::op::v0::Sin::get_type_info_static(), 0}, + {ov::op::v0::Sinh::get_type_info_static(), 0}, + {ov::op::v0::Sqrt::get_type_info_static(), 0}, + {ov::op::v0::SpaceToDepth::get_type_info_static(), 0}, + {ov::op::v0::SquaredDifference::get_type_info_static(), 0}, + {ov::op::v0::Squeeze::get_type_info_static(), 0}, + {ov::op::v0::Tan::get_type_info_static(), 0}, + {ov::op::v0::Tanh::get_type_info_static(), 0}, + {ov::op::v0::TensorIterator::get_type_info_static(), 0}, + {ov::op::v0::Tile::get_type_info_static(), 0}, + {ov::op::v0::Unsqueeze::get_type_info_static(), 0}, + {ov::op::v0::Xor::get_type_info_static(), 0}, + // opset 2 + {ov::op::v0::MVN::get_type_info_static(), 0}, + {ov::op::v0::ReorgYolo::get_type_info_static(), 0}, + {ov::op::v0::ROIPooling::get_type_info_static(), 0}, + {ov::op::v0::Gelu::get_type_info_static(), 0}, + {ov::op::v1::BatchToSpace::get_type_info_static(), 1}, + {ov::op::v1::SpaceToBatch::get_type_info_static(), 1}, + // opset 3 + {ov::op::v0::RNNCell::get_type_info_static(), 0}, + {ov::op::v0::ShuffleChannels::get_type_info_static(), 0}, + // opset 4 + {ov::op::v3::Acosh::get_type_info_static(), 3}, + {ov::op::v3::Asinh::get_type_info_static(), 3}, + {ov::op::v3::Atanh::get_type_info_static(), 3}, +}; + // todo: reuse in summary std::string get_node_version(const std::shared_ptr& node, const std::string& postfix = ""); +std::string get_node_version(const ov::NodeTypeInfo& node_type_info); } // namespace functional } // namespace test } // namespace ov - -// todo: remove these structure after remove old subgraphs dumper -namespace LayerTestsUtils { - -struct ModelInfo { - size_t unique_op_cnt; - // model_path, op_cnt - std::map model_paths; - - ModelInfo(size_t _op_cnt = 0, const std::map& _model_paths = {{}}); -}; - -struct PortInfo { - double min; - double max; - bool convert_to_const; - - PortInfo(double min, double max, bool convert_to_const); - PortInfo(); -}; - -struct OPInfo { - std::map found_in_models; - std::map ports_info; - - OPInfo(const std::string& source_model, const std::string& model_path, size_t total_op_cnt = 0); - - OPInfo() = default; -}; -} // namespace LayerTestsUtils diff --git a/src/tests/test_utils/functional_test_utils/include/functional_test_utils/summary/op_summary.hpp b/src/tests/test_utils/functional_test_utils/include/functional_test_utils/summary/op_summary.hpp index cc97fb45cd6949..44cf995f7184c8 100644 --- a/src/tests/test_utils/functional_test_utils/include/functional_test_utils/summary/op_summary.hpp +++ b/src/tests/test_utils/functional_test_utils/include/functional_test_utils/summary/op_summary.hpp @@ -32,7 +32,7 @@ class OpSummary : public virtual Summary { std::map opsStats = {}; unsigned short int downgrade_coefficient; - std::string getOpVersion(const std::string& version); + std::string get_opset_number(const std::string& opset_full_name); protected: OpSummary(unsigned short int downgrade_coefficient = 1); diff --git a/src/tests/test_utils/functional_test_utils/layer_tests_summary/skip_configs/CPU/expected_failures_OP.csv b/src/tests/test_utils/functional_test_utils/layer_tests_summary/skip_configs/CPU/expected_failures_OP.csv index 23d497e22f5d12..07f091dd7a222b 100644 --- a/src/tests/test_utils/functional_test_utils/layer_tests_summary/skip_configs/CPU/expected_failures_OP.csv +++ b/src/tests/test_utils/functional_test_utils/layer_tests_summary/skip_configs/CPU/expected_failures_OP.csv @@ -1129,3 +1129,11 @@ conformance_PriorBox/ReadIRTest.ImportExport/Op=PriorBox.1_Type=f32_IR=PriorBox- conformance_PRelu/ReadIRTest.ImportExport/Op=PRelu.1_Type=f32_IR=20e7e74f55eb5fb78014cce7e0665d6925bbefd708dd9ccff12dbfbea2a330dd_Device=CPU_Shape=static_Config=(),5.69266e-06 conformance_RegionYolo/ReadIRTest.ImportExport/Op=RegionYolo.1_Type=f32_IR=RegionYolo-1_750_Device=CPU_Shape=static_Config=(),5.06332e-06 conformance_Add/ReadIRTest.ImportExport/Op=Add.1_Type=i32_IR=28f23780d4ca0d40671caf79d5cd9223ad8f6dc2fa5ade2521f3d99586eeeb7f_Device=CPU_Shape=static_Config=(),9.72615e-07 +conformance_Convolution/ReadIRTest.Inference/Op=Convolution.1_Type=f32_IR=c301804445f273eef62f41f02204711d9d6e571da28c76ab447d7d90983b0032_Device=CPU_Shape=dynamic_Config=(),0.000113281 +conformance/OpImplCheckTest.checkPluginImplementation/Function=BitwiseAnd_opset13_Device=CPU_Config=(),1 +conformance/OpImplCheckTest.checkPluginImplementation/Function=BitwiseOr_opset13_Device=CPU_Config=(),1 +conformance/OpImplCheckTest.checkPluginImplementation/Function=BitwiseNot_opset13_Device=CPU_Config=(),1 +conformance/OpImplCheckTest.checkPluginImplementation/Function=Multinomial_opset13_Device=CPU_Config=(),1 +conformance/OpImplCheckTest.checkPluginImplementation/Function=NMSRotated_opset13_Device=CPU_Config=(),1 +conformance/OpImplCheckTest.checkPluginImplementation/Function=LSTMSequence_opset1_Device=CPU_Config=(),1 +conformance/OpImplCheckTest.checkPluginImplementation/Function=BitwiseXor_opset13_Device=CPU_Config=(),1 diff --git a/src/tests/test_utils/functional_test_utils/src/ov_plugin_cache.cpp b/src/tests/test_utils/functional_test_utils/src/ov_plugin_cache.cpp index 5d32d1a7b6abda..118368f7a1180f 100644 --- a/src/tests/test_utils/functional_test_utils/src/ov_plugin_cache.cpp +++ b/src/tests/test_utils/functional_test_utils/src/ov_plugin_cache.cpp @@ -58,7 +58,7 @@ std::shared_ptr PluginCache::core(const std::string& deviceToCheck) { // register template plugin if it is needed try { std::string pluginName = "openvino_template_plugin"; - pluginName += IE_BUILD_POSTFIX; + pluginName += OV_BUILD_POSTFIX; ov_core->register_plugin( ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), pluginName), "TEMPLATE"); diff --git a/src/tests/test_utils/functional_test_utils/src/plugin_cache.cpp b/src/tests/test_utils/functional_test_utils/src/plugin_cache.cpp index 99fff0a5ef90e7..3db56da99c3a0e 100644 --- a/src/tests/test_utils/functional_test_utils/src/plugin_cache.cpp +++ b/src/tests/test_utils/functional_test_utils/src/plugin_cache.cpp @@ -57,7 +57,7 @@ std::shared_ptr PluginCache::ie(const std::string& device // register template plugin if it is needed try { std::string pluginName = "openvino_template_plugin"; - pluginName += IE_BUILD_POSTFIX; + pluginName += OV_BUILD_POSTFIX; ie_core->RegisterPlugin( ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), pluginName), "TEMPLATE"); diff --git a/src/tests/test_utils/functional_test_utils/src/summary/op_info.cpp b/src/tests/test_utils/functional_test_utils/src/summary/op_info.cpp index 0082cba61a343f..358be2d424b177 100644 --- a/src/tests/test_utils/functional_test_utils/src/summary/op_info.cpp +++ b/src/tests/test_utils/functional_test_utils/src/summary/op_info.cpp @@ -8,45 +8,30 @@ namespace ov { namespace test { namespace functional { -// todo: reuse in summary std::string get_node_version(const std::shared_ptr& node, const std::string& postfix) { - std::string op_name = node->get_type_info().name; - std::string opset_version = node->get_type_info().get_version(); - std::string opset_name = "opset"; - auto pos = opset_version.find(opset_name); - if (pos != std::string::npos) { - op_name += "-" + opset_version.substr(pos + opset_name.size()); - } + const auto& node_type_info = node->get_type_info(); + auto op_name = get_node_version(node_type_info); if (!postfix.empty()) { op_name += "_" + postfix; } return op_name; } +std::string get_node_version(const ov::NodeTypeInfo& node_type_info) { + std::string op_name = node_type_info.name + std::string("-"); + std::string opset_version = node_type_info.get_version(); + if (not_aligned_op_version.count(node_type_info)) { + op_name += std::to_string(not_aligned_op_version.at(node_type_info)); + } else { + std::string opset_name = "opset"; + auto pos = opset_version.find(opset_name); + if (pos != std::string::npos) { + op_name += opset_version.substr(pos + opset_name.size()); + } + } + return op_name; +} + } // namespace functional } // namespace test } // namespace ov - -namespace LayerTestsUtils { - -ModelInfo::ModelInfo(size_t _op_cnt, const std::map& _model_paths) - : unique_op_cnt(_op_cnt), - model_paths(_model_paths) {} - -PortInfo::PortInfo(double min, double max, bool convert_to_const) - : min(min), - max(max), - convert_to_const(convert_to_const) {} - -PortInfo::PortInfo() { - min = std::numeric_limits::min(); - max = std::numeric_limits::max(); - convert_to_const = false; -} - -OPInfo::OPInfo(const std::string& source_model, const std::string& model_path, size_t total_op_cnt) { - found_in_models = {{source_model, ModelInfo(1, {{model_path, total_op_cnt}})}}; - ports_info = {}; -} - -} // namespace LayerTestsUtils diff --git a/src/tests/test_utils/functional_test_utils/src/summary/op_summary.cpp b/src/tests/test_utils/functional_test_utils/src/summary/op_summary.cpp index b895d14ab26ca6..fbaaf4e16629c3 100644 --- a/src/tests/test_utils/functional_test_utils/src/summary/op_summary.cpp +++ b/src/tests/test_utils/functional_test_utils/src/summary/op_summary.cpp @@ -8,6 +8,7 @@ #include #include "common_test_utils/file_utils.hpp" +#include "functional_test_utils/summary/op_info.hpp" using namespace ov::test::utils; @@ -109,13 +110,13 @@ void OpSummary::updateOPsImplStatus(const ov::NodeTypeInfo& op, const bool implS } } -std::string OpSummary::getOpVersion(const std::string& version) { +std::string OpSummary::get_opset_number(const std::string& opset_full_name) { std::string opset_name = "opset"; - auto pos = version.find(opset_name); + auto pos = opset_full_name.find(opset_name); if (pos == std::string::npos) { return "undefined"; } else { - return version.substr(pos + opset_name.size()); + return opset_full_name.substr(pos + opset_name.size()); } } @@ -259,7 +260,7 @@ void OpSummary::saveReport() { const auto& type_info_set = opset.get_type_info_set(); for (const auto& type_info : type_info_set) { auto it = opsInfo.find(type_info); - std::string op_version = getOpVersion(opset_version); + std::string op_version = get_opset_number(opset_version); if (it == opsInfo.end()) { opsInfo.insert({type_info, op_version}); } else { @@ -304,7 +305,7 @@ void OpSummary::saveReport() { pugi::xml_node opsNode = root.append_child("ops_list"); for (const auto& op : opsInfo) { - std::string name = std::string(op.first.name) + "-" + getOpVersion(op.first.version_id); + std::string name = functional::get_node_version(op.first); opsNode.append_child(name.c_str()).append_attribute("opsets").set_value(op.second.c_str()); } @@ -315,7 +316,7 @@ void OpSummary::saveReport() { it.second.rel_passed /= downgrade_coefficient; it.second.rel_all /= downgrade_coefficient; - std::string name = std::string(it.first.name) + "-" + getOpVersion(it.first.version_id); + std::string name = functional::get_node_version(it.first); opList.insert(name); pugi::xml_node entry = currentDeviceNode.append_child(name.c_str()); entry.append_attribute("implemented").set_value(it.second.isImplemented); diff --git a/src/tests/test_utils/unit_test_utils/CMakeLists.txt b/src/tests/test_utils/unit_test_utils/CMakeLists.txt index 7b8607d6bae28c..dd2bb77aa52224 100644 --- a/src/tests/test_utils/unit_test_utils/CMakeLists.txt +++ b/src/tests/test_utils/unit_test_utils/CMakeLists.txt @@ -15,14 +15,20 @@ ov_add_target( TYPE STATIC ROOT ${CMAKE_CURRENT_SOURCE_DIR} ADD_CLANG_FORMAT - DEVELOPER_PACKAGE - tests LINK_LIBRARIES PUBLIC common_test_utils_s inference_engine_s gmock + DEPENDENCIES + mock_engine INCLUDES PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/.." + "$" ) + +# install & export + +ov_developer_package_export_targets(TARGET ${TARGET_NAME} + INSTALL_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/../unit_test_utils" + INSTALL_DESTIONATION "developer_package/include/unit_test_utils/unit_test_utils") diff --git a/tests/constraints.txt b/tests/constraints.txt index 671c60bc937c83..fca15ab7cbe228 100644 --- a/tests/constraints.txt +++ b/tests/constraints.txt @@ -11,6 +11,7 @@ scipy>=1.11.1; python_version >= "3.9" wheel>=0.38.1 defusedxml>=0.7.1 fastjsonschema~=2.17.1 +tensorflow>=2.5,<2.15.0 test-generator==0.1.2 requests>=2.25.1 opencv-python>=4.5 @@ -22,4 +23,4 @@ pytest-html==3.2.0 pytest-timeout==2.1.0 jax<=0.4.14 jaxlib<=0.4.14 -torch<2.1.0 \ No newline at end of file +torch<2.1.0,>=1.13 \ No newline at end of file diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt index af134ae28e8cdc..fa206f9362d949 100644 --- a/tests/fuzz/CMakeLists.txt +++ b/tests/fuzz/CMakeLists.txt @@ -11,7 +11,7 @@ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug" "RelWithD set(OpenVINO_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../") -find_package(IEDevScripts REQUIRED +find_package(OpenVINODeveloperScripts REQUIRED PATHS "${OpenVINO_SOURCE_DIR}/cmake/developer_package" NO_CMAKE_FIND_ROOT_PATH NO_DEFAULT_PATH) diff --git a/tests/layer_tests/common/tflite_layer_test_class.py b/tests/layer_tests/common/tflite_layer_test_class.py index b7d6a2043b9366..8ff5122d8d43bc 100644 --- a/tests/layer_tests/common/tflite_layer_test_class.py +++ b/tests/layer_tests/common/tflite_layer_test_class.py @@ -1,6 +1,7 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 import os + os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' import tensorflow as tf from tensorflow.lite.tools import flatbuffer_utils as utils @@ -62,7 +63,15 @@ def check_tflite_model_has_only_allowed_ops(self): else: op_names.append(builtin_operators[op.builtinCode]) op_names = sorted(op_names) - assert op_names == self.allowed_ops, "TFLite model is not as you expect it to be: " + ", ".join(op_names) + if isinstance(self.allowed_ops, tuple): + passed = False + for allowed_ops_var in self.allowed_ops: + if op_names == allowed_ops_var: + passed = True + break + assert passed, "TFLite model is not as you expect it to be: " + ", ".join(op_names) + else: + assert op_names == self.allowed_ops, "TFLite model is not as you expect it to be: " + ", ".join(op_names) def _test(self, ie_device, precision, temp_dir, params): model = self.make_model(params) diff --git a/tests/layer_tests/common/utils/tf_utils.py b/tests/layer_tests/common/utils/tf_utils.py index fb02c3f0a1b298..913048acf2e762 100644 --- a/tests/layer_tests/common/utils/tf_utils.py +++ b/tests/layer_tests/common/utils/tf_utils.py @@ -98,7 +98,7 @@ def summarize_graph(model_path, output_nodes_for_freeze=None, reshape_net=None): variables = list() outputs = list() graph = load_graph(model_path, output_nodes_for_freeze) - unlikely_output_types = ['Const', 'Assign', 'NoOp', 'Placeholder', 'Assert', 'switch_t', 'switch_f'] + unlikely_output_types = ['Const', 'Assign', 'NoOp', 'Placeholder', 'Assert', 'switch_t', 'switch_f', 'TensorArrayCloseV3'] control_dependents_map = collect_control_dependencies(graph) for node in graph.as_graph_def().node: if node.op == 'Placeholder': diff --git a/tests/layer_tests/mo_python_api_tests/test_mo_convert_pytorch.py b/tests/layer_tests/mo_python_api_tests/test_mo_convert_pytorch.py index 6eab63bf682bd0..60bb92b85b5920 100644 --- a/tests/layer_tests/mo_python_api_tests/test_mo_convert_pytorch.py +++ b/tests/layer_tests/mo_python_api_tests/test_mo_convert_pytorch.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 import unittest +import platform from typing import Tuple import numpy as np @@ -283,8 +284,8 @@ def scripted_fn(x: torch.Tensor, y: torch.Tensor): return torch.sigmoid(torch.relu(x * y)) inp_shape = PartialShape([Dimension(1, -1), Dimension(-1, 5), 10]) - ref_model = make_ref_pt_model_two_inputs(inp_shape, dtype=Type.dynamic) - return scripted_fn, ref_model, {'input': [(inp_shape), (inp_shape)]} + ref_model = make_ref_pt_model_two_inputs(inp_shape) + return scripted_fn, ref_model, {'input': [(inp_shape, Type.f32), (inp_shape, Type.f32)]} def create_pytorch_nn_module_layout_list(tmp_dir): @@ -471,9 +472,9 @@ def create_pytorch_nn_module_scale_list_compression_enabled(tmp_dir): def create_pytorch_nn_module_shapes_list_static(tmp_dir): pt_model = make_pt_model_two_inputs() - ref_model = make_ref_pt_model_two_inputs([1, 3, 20, 20], dtype=Type.dynamic) + ref_model = make_ref_pt_model_two_inputs([1, 3, 20, 20]) - return pt_model, ref_model, {'input': [[1, 3, 20, 20], [1, 3, 20, 20]]} + return pt_model, ref_model, {'input': [([1, 3, 20, 20], Type.f32), ([1, 3, 20, 20], Type.f32)]} def create_pytorch_nn_module_shapes_list_static_via_input(tmp_dir): @@ -489,17 +490,16 @@ def create_pytorch_nn_module_shapes_list_dynamic(tmp_dir): [-1, 3, 20, Dimension(-1, 20)]] param1 = ov.opset8.parameter(PartialShape( - inp_shapes[0]), name="x", dtype=Type.dynamic) + inp_shapes[0]), name="x", dtype=Type.f32) param2 = ov.opset8.parameter(PartialShape( - inp_shapes[1]), name="y", dtype=Type.dynamic) - cl = ov.opset8.convert_like(param2, param1) - mul = ov.opset8.multiply(param1, cl) + inp_shapes[1]), name="y", dtype=Type.f32) + mul = ov.opset8.multiply(param1, param2) relu = ov.opset8.relu(mul) sigm = ov.opset8.sigmoid(relu) parameter_list = [param1, param2] ref_model = Model([sigm], parameter_list, "test") - return pt_model, ref_model, {'input': inp_shapes} + return pt_model, ref_model, {'input': [(inp_shapes[0], Type.f32), (inp_shapes[1], Type.f32)]} def create_pytorch_nn_module_shapes_list_dynamic_via_input(tmp_dir): @@ -522,8 +522,8 @@ def create_pytorch_nn_module_shapes_list_dynamic_via_input(tmp_dir): def create_pytorch_nn_module_shapes_list_dynamic_single_input(tmp_dir): pt_model = make_pt_model_one_input() - inp_shapes = [[Dimension(-1), 3, 20, Dimension(20, -1)]] - ref_model = make_ref_pt_model_one_input(inp_shapes[0], dtype=Type.dynamic) + inp_shapes = [[Dimension(-1), 3, 20, Dimension(20, -1)], Type.f32] + ref_model = make_ref_pt_model_one_input(inp_shapes[0]) return pt_model, ref_model, {'input': inp_shapes} @@ -536,8 +536,8 @@ def create_pytorch_nn_module_shapes_list_dynamic_single_input_via_input(tmp_dir) def create_pytorch_nn_module_shapes_list_static_single_input(tmp_dir): pt_model = make_pt_model_one_input() - inp_shapes = [[1, 3, 20, 20]] - ref_model = make_ref_pt_model_one_input(inp_shapes[0], dtype=Type.dynamic) + inp_shapes = [[1, 3, 20, 20], Type.f32] + ref_model = make_ref_pt_model_one_input(inp_shapes[0]) return pt_model, ref_model, {'input': inp_shapes} @@ -1236,6 +1236,8 @@ class TestPrecisionSensitive(): @pytest.mark.parametrize("create_model", test_data) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122714') def test_precision_sensitive(self, create_model, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): import numpy.testing as npt from pathlib import Path diff --git a/tests/layer_tests/onnx_tests/test_loop.py b/tests/layer_tests/onnx_tests/test_loop.py index 579c2dfca32c87..be90ccd106bcdf 100644 --- a/tests/layer_tests/onnx_tests/test_loop.py +++ b/tests/layer_tests/onnx_tests/test_loop.py @@ -16,7 +16,7 @@ def create_const(name, tensor_type, value): if tensor_type == TensorProto.INT64: np_type = np.int64 elif tensor_type == TensorProto.FLOAT: - np_type = np.float + np_type = np.float32 elif tensor_type == TensorProto.BOOL: np_type = bool else: diff --git a/tests/layer_tests/onnx_tests/test_reduce_lp.py b/tests/layer_tests/onnx_tests/test_reduce_lp.py index e64929a680c20d..73cd86a2bbbc6f 100644 --- a/tests/layer_tests/onnx_tests/test_reduce_lp.py +++ b/tests/layer_tests/onnx_tests/test_reduce_lp.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest from common.layer_test_class import check_ir_version @@ -232,6 +234,8 @@ def create_reduce_lp_const(self, shape, axes, keep_dims, reduce_p, ir_version): @pytest.mark.parametrize("keep_dims", [True, False]) @pytest.mark.parametrize("reduce_p", [1, 2]) @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122846') def test_reduce_lp_precommit(self, params, keep_dims, reduce_p, ie_device, precision, ir_version, temp_dir, use_old_api): self._test(*self.create_reduce_lp(**params, keep_dims=keep_dims, reduce_p=reduce_p, diff --git a/tests/layer_tests/onnx_tests/test_roi_align.py b/tests/layer_tests/onnx_tests/test_roi_align.py index 392856eaff7b2d..a29ddc4c1d1213 100644 --- a/tests/layer_tests/onnx_tests/test_roi_align.py +++ b/tests/layer_tests/onnx_tests/test_roi_align.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest from common.layer_test_class import check_ir_version @@ -133,6 +135,9 @@ def create_net(self, input_shape, rois_shape, indices_shape, output_shape, @pytest.mark.parametrize("params", test_data) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Windows', reason="Ticket - 122731") + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122846') def test_roi_alignv10(self, params, ie_device, precision, ir_version, temp_dir, use_old_api): # TODO: ticket for investigating GPU failures: CVS-86300 if ie_device != "GPU": diff --git a/tests/layer_tests/ovc_python_api_tests/test_pytorch.py b/tests/layer_tests/ovc_python_api_tests/test_pytorch.py index 5ae2dcac31c83e..90db75d01c0e78 100644 --- a/tests/layer_tests/ovc_python_api_tests/test_pytorch.py +++ b/tests/layer_tests/ovc_python_api_tests/test_pytorch.py @@ -281,8 +281,8 @@ def scripted_fn(x: torch.Tensor, y: torch.Tensor): return torch.sigmoid(torch.relu(x * y)) inp_shape = PartialShape([Dimension(1, -1), Dimension(-1, 5), 10]) - ref_model = make_ref_pt_model_two_inputs(inp_shape, dtype=Type.dynamic) - return scripted_fn, ref_model, {'input': [(inp_shape), (inp_shape)]} + ref_model = make_ref_pt_model_two_inputs(inp_shape) + return scripted_fn, ref_model, {'input': [(inp_shape, Type.f32), (inp_shape, Type.f32)]} def create_pytorch_nn_module_layout_list(tmp_dir): @@ -469,9 +469,9 @@ def create_pytorch_nn_module_scale_list_compression_enabled(tmp_dir): def create_pytorch_nn_module_shapes_list_static(tmp_dir): pt_model = make_pt_model_two_inputs() - ref_model = make_ref_pt_model_two_inputs([1, 3, 20, 20], dtype=Type.dynamic) + ref_model = make_ref_pt_model_two_inputs([1, 3, 20, 20]) - return pt_model, ref_model, {'input': [[1, 3, 20, 20], [1, 3, 20, 20]]} + return pt_model, ref_model, {'input': [([1, 3, 20, 20], Type.f32), ([1, 3, 20, 20], Type.f32)]} def create_pytorch_nn_module_shapes_list_static_via_input(tmp_dir): @@ -487,17 +487,16 @@ def create_pytorch_nn_module_shapes_list_dynamic(tmp_dir): [-1, 3, 20, Dimension(-1, 20)]] param1 = ov.opset8.parameter(PartialShape( - inp_shapes[0]), name="x", dtype=Type.dynamic) + inp_shapes[0]), name="x", dtype=Type.f32) param2 = ov.opset8.parameter(PartialShape( - inp_shapes[1]), name="y", dtype=Type.dynamic) - cl = ov.opset8.convert_like(param2, param1) - mul = ov.opset8.multiply(param1, cl) + inp_shapes[1]), name="y", dtype=Type.f32) + mul = ov.opset8.multiply(param1, param2) relu = ov.opset8.relu(mul) sigm = ov.opset8.sigmoid(relu) parameter_list = [param1, param2] ref_model = Model([sigm], parameter_list, "test") - return pt_model, ref_model, {'input': inp_shapes} + return pt_model, ref_model, {'input': [(inp_shapes[0], Type.f32), (inp_shapes[1], Type.f32)]} def create_pytorch_nn_module_shapes_list_dynamic_via_input(tmp_dir): @@ -520,8 +519,8 @@ def create_pytorch_nn_module_shapes_list_dynamic_via_input(tmp_dir): def create_pytorch_nn_module_shapes_list_dynamic_single_input(tmp_dir): pt_model = make_pt_model_one_input() - inp_shapes = [[Dimension(-1), 3, 20, Dimension(20, -1)]] - ref_model = make_ref_pt_model_one_input(inp_shapes[0], dtype=Type.dynamic) + inp_shapes = [[Dimension(-1), 3, 20, Dimension(20, -1)], Type.f32] + ref_model = make_ref_pt_model_one_input(inp_shapes[0]) return pt_model, ref_model, {'input': inp_shapes} @@ -534,8 +533,8 @@ def create_pytorch_nn_module_shapes_list_dynamic_single_input_via_input(tmp_dir) def create_pytorch_nn_module_shapes_list_static_single_input(tmp_dir): pt_model = make_pt_model_one_input() - inp_shapes = [[1, 3, 20, 20]] - ref_model = make_ref_pt_model_one_input(inp_shapes[0], dtype=Type.dynamic) + inp_shapes = [[1, 3, 20, 20], Type.f32] + ref_model = make_ref_pt_model_one_input(inp_shapes[0]) return pt_model, ref_model, {'input': inp_shapes} diff --git a/tests/layer_tests/py_frontend_tests/test_torch_decoder.py b/tests/layer_tests/py_frontend_tests/test_torch_decoder.py index 6adbf0d033e98f..7e1758bd84d4fe 100644 --- a/tests/layer_tests/py_frontend_tests/test_torch_decoder.py +++ b/tests/layer_tests/py_frontend_tests/test_torch_decoder.py @@ -641,7 +641,7 @@ def f(x, y): @pytest.mark.precommit def test_pytorch_decoder_can_convert_scripted_function(): - from openvino.tools.mo import convert_model + from openvino import convert_model, Type scripted = torch.jit.script(f) - model = convert_model(scripted) + model = convert_model(scripted, input=[Type.f32, Type.f32]) assert model is not None diff --git a/tests/layer_tests/py_frontend_tests/test_torch_frontend.py b/tests/layer_tests/py_frontend_tests/test_torch_frontend.py index 6b4d748fc45632..f76c7b1fa97ba8 100644 --- a/tests/layer_tests/py_frontend_tests/test_torch_frontend.py +++ b/tests/layer_tests/py_frontend_tests/test_torch_frontend.py @@ -22,6 +22,9 @@ def forward(self, x): class aten_multi_input_output(torch.nn.Module): def forward(self, x, y, z): + x = x.to(torch.float32) + y = y.to(torch.float32) + z = z.to(torch.float32) return torch.nn.functional.relu(x), x * y, z / x diff --git a/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py b/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py index 00cdc427056518..f8b726c4c5f66d 100644 --- a/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py +++ b/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py @@ -77,10 +77,13 @@ def use_torch_compile_backend(): if use_torch_compile_backend(): self.torch_compile_backend_test(model, torch_inputs, custom_eps) else: + trace_model = kwargs.get('trace_model', False) + freeze_model = kwargs.get('freeze_model', True) with torch.no_grad(): - trace_model = kwargs.get('trace_model', False) - freeze_model = kwargs.get('freeze_model', True) - smodel, converted_model = self.convert_directly_via_frontend(model, torch_inputs, trace_model, dynamic_shapes, ov_inputs, freeze_model) + if kwargs.get('use_convert_model', False): + smodel, converted_model = self.convert_via_mo(model, torch_inputs, trace_model, dynamic_shapes, ov_inputs, freeze_model) + else: + smodel, converted_model = self.convert_directly_via_frontend(model, torch_inputs, trace_model, dynamic_shapes, ov_inputs, freeze_model) if kind is not None and not isinstance(kind, (tuple, list)): kind = [kind] @@ -162,12 +165,13 @@ def _prepare_input(self): raise RuntimeError("Please provide inputs generation function") def convert_via_mo(self, model, example_input, trace_model, dynamic_shapes, ov_inputs, freeze_model): - from openvino.tools.ovc import convert_model - kwargs = {"example_input": example_input if len(example_input) > 1 else example_input[0]} + from openvino import convert_model, PartialShape if trace_model: decoder = TorchScriptPythonDecoder(model, example_input=example_input, skip_freeze=not freeze_model) + kwargs = {"example_input": example_input if len(example_input) > 1 else example_input[0]} else: decoder = TorchScriptPythonDecoder(model, skip_freeze=not freeze_model) + kwargs = {"input": [(i.dtype, PartialShape([-1] * len(i.shape))) for i in example_input]} smodel = decoder.pt_module print(smodel.inlined_graph) if not dynamic_shapes: diff --git a/tests/layer_tests/pytorch_tests/test_adaptive_avg_pool.py b/tests/layer_tests/pytorch_tests/test_adaptive_avg_pool.py new file mode 100644 index 00000000000000..f50dc8a4051519 --- /dev/null +++ b/tests/layer_tests/pytorch_tests/test_adaptive_avg_pool.py @@ -0,0 +1,101 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np +import pytest +import torch + +from pytorch_layer_test_class import PytorchLayerTest + + +@pytest.mark.parametrize('input_tensor', (np.random.randn(1, 2, 8, 9, 10).astype(np.float32), + np.random.randn(2, 8, 9, 10).astype(np.float32))) +@pytest.mark.parametrize('output_size', ([5, 7, 9], 7)) +class TestAdaptiveAvgPool3D(PytorchLayerTest): + + def _prepare_input(self): + return (self.input_tensor,) + + def create_model(self, output_size): + class aten_adaptive_avg_pool3d(torch.nn.Module): + + def __init__(self, output_size) -> None: + super().__init__() + self.output_size = output_size + + def forward(self, input_tensor): + return torch.nn.functional.adaptive_avg_pool3d(input_tensor, self.output_size) + + ref_net = None + + return aten_adaptive_avg_pool3d(output_size), ref_net, "aten::adaptive_avg_pool3d" + + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.precommit_ts_backend + @pytest.mark.precommit_fx_backend + def test_adaptive_avg_pool3d(self, ie_device, precision, ir_version, input_tensor, output_size): + self.input_tensor = input_tensor + self._test(*self.create_model(output_size), ie_device, precision, ir_version) + + +@pytest.mark.parametrize('input_tensor', [np.random.randn(2, 8, 9, 10).astype(np.float32), np.random.randn(8, 9, 10).astype(np.float32)]) +@pytest.mark.parametrize('output_size', ([7, 9], 7)) +class TestAdaptiveAvgPool2D(PytorchLayerTest): + + def _prepare_input(self): + return (self.input_tensor,) + + def create_model(self, output_size): + class aten_adaptive_avg_pool2d(torch.nn.Module): + + def __init__(self, output_size) -> None: + super().__init__() + self.output_size = output_size + + def forward(self, input_tensor): + return torch.nn.functional.adaptive_avg_pool2d(input_tensor, self.output_size) + + ref_net = None + + return aten_adaptive_avg_pool2d(output_size), ref_net, "aten::adaptive_avg_pool2d" + + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.precommit_ts_backend + @pytest.mark.precommit_fx_backend + def test_adaptive_avg_pool2d(self, ie_device, precision, ir_version, input_tensor, output_size): + self.input_tensor = input_tensor + self._test(*self.create_model(output_size), ie_device, precision, ir_version) + + +@pytest.mark.parametrize('input_tensor', [np.random.randn(8, 9, 10).astype(np.float32), np.random.randn(9, 10).astype(np.float32)] ) +@pytest.mark.parametrize('output_size', ( 7, )) +class TestAdaptiveAvgPool1D(PytorchLayerTest): + + def _prepare_input(self): + return (self.input_tensor,) + + def create_model(self, output_size): + class aten_adaptive_avg_pool1d(torch.nn.Module): + + def __init__(self, output_size) -> None: + super().__init__() + self.output_size = output_size + + def forward(self, input_tensor): + return torch.nn.functional.adaptive_avg_pool1d(input_tensor, self.output_size) + + ref_net = None + + return aten_adaptive_avg_pool1d(output_size), ref_net, "aten::adaptive_avg_pool1d" + + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.precommit_ts_backend + @pytest.mark.precommit_fx_backend + def test_adaptive_avg_pool1d(self, ie_device, precision, ir_version, input_tensor, output_size): + self.input_tensor = input_tensor + self._test(*self.create_model(output_size), ie_device, precision, ir_version) + + diff --git a/tests/layer_tests/pytorch_tests/test_adaptive_avg_pool3d.py b/tests/layer_tests/pytorch_tests/test_adaptive_avg_pool3d.py deleted file mode 100644 index 2f2dffa15ebcf0..00000000000000 --- a/tests/layer_tests/pytorch_tests/test_adaptive_avg_pool3d.py +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (C) 2018-2023 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 - -import numpy as np -import pytest -import torch - -from pytorch_layer_test_class import PytorchLayerTest - - -@pytest.mark.parametrize('input_tensor', (np.random.randn(1, 2, 8, 9, 10).astype(np.float32), - np.random.randn(2, 8, 9, 10).astype(np.float32))) -@pytest.mark.parametrize('output_size', ([5, 7, 9], 7)) -class TestAdaptiveAvgPool3D(PytorchLayerTest): - - def _prepare_input(self): - return (self.input_tensor,) - - def create_model(self, output_size): - class aten_adaptive_avg_pool3d(torch.nn.Module): - - def __init__(self, output_size) -> None: - super().__init__() - self.output_size = output_size - - def forward(self, input_tensor): - return torch.nn.functional.adaptive_avg_pool3d(input_tensor, self.output_size) - - ref_net = None - - return aten_adaptive_avg_pool3d(output_size), ref_net, "aten::adaptive_avg_pool3d" - - @pytest.mark.nightly - @pytest.mark.precommit - @pytest.mark.precommit_ts_backend - @pytest.mark.precommit_fx_backend - def test_adaptive_avg_pool3d(self, ie_device, precision, ir_version, input_tensor, output_size): - self.input_tensor = input_tensor - self._test(*self.create_model(output_size), ie_device, precision, ir_version) diff --git a/tests/layer_tests/pytorch_tests/test_adaptive_max_pool.py b/tests/layer_tests/pytorch_tests/test_adaptive_max_pool.py new file mode 100644 index 00000000000000..09be641a0fb96e --- /dev/null +++ b/tests/layer_tests/pytorch_tests/test_adaptive_max_pool.py @@ -0,0 +1,152 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import platform + +import numpy as np +import pytest +import torch +import torch.nn.functional as F + +from pytorch_layer_test_class import PytorchLayerTest + + +class TestAdaptiveMaxPool3D(PytorchLayerTest): + + def _prepare_input(self): + return (self.input_tensor,) + + def create_model(self, output_size=None, return_indices=False): + class aten_adaptive_max_pool3d(torch.nn.Module): + + def __init__(self, output_size=None, return_indices=False) -> None: + super().__init__() + self.output_size = output_size + self.return_indices = return_indices + + def forward(self, input_tensor): + if self.return_indices: + output, indices = F.adaptive_max_pool3d(input_tensor, self.output_size, True) + return output, indices + return F.adaptive_max_pool3d(input_tensor, self.output_size, False), input_tensor.to(torch.int64) + + ref_net = None + + return aten_adaptive_max_pool3d(output_size, return_indices), ref_net, "aten::adaptive_max_pool3d" + + @pytest.mark.parametrize('input_tensor', ([ + np.random.randn(2, 1, 1, 4, 4).astype(np.float32), + np.random.randn(4, 1, 3, 32, 32).astype(np.float32), + np.random.randn(1, 3, 32, 32).astype(np.float32) + ])) + @pytest.mark.parametrize('output_size', ([ + [2, 2, 2], + [4, 4, 4], + ])) + @pytest.mark.parametrize('return_indices', ([ + False, + True, + ])) + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.precommit_ts_backend + @pytest.mark.precommit_fx_backend + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') + def test_adaptive_max_pool3d(self, ie_device, precision, ir_version, input_tensor, output_size, return_indices): + self.input_tensor = input_tensor + self._test(*self.create_model(output_size, return_indices), ie_device, precision, ir_version) + + +class TestAdaptiveMaxPool2D(PytorchLayerTest): + + def _prepare_input(self): + return (self.input_tensor,) + + def create_model(self, output_size=None, return_indices=False): + class aten_adaptive_max_pool2d(torch.nn.Module): + + def __init__(self, output_size=None, return_indices=False) -> None: + super().__init__() + self.output_size = output_size + self.return_indices = return_indices + + def forward(self, input_tensor): + if self.return_indices: + output, indices = F.adaptive_max_pool2d(input_tensor, self.output_size, True) + return output, indices + return F.adaptive_max_pool2d(input_tensor, self.output_size, False), input_tensor.to(torch.int64) + + ref_net = None + + return aten_adaptive_max_pool2d(output_size, return_indices), ref_net, "aten::adaptive_max_pool2d" + + @pytest.mark.parametrize('input_tensor', ([ + np.random.randn(2, 1, 4, 4).astype(np.float32), + np.random.randn(1, 3, 32, 32).astype(np.float32), + np.random.randn(3, 32, 32).astype(np.float32) + ])) + @pytest.mark.parametrize('output_size', ([ + [2, 2], + [4, 4], + ])) + @pytest.mark.parametrize('return_indices', ([ + False, + True, + ])) + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.precommit_ts_backend + @pytest.mark.precommit_fx_backend + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') + def test_adaptive_max_pool2d(self, ie_device, precision, ir_version, input_tensor, output_size, return_indices): + self.input_tensor = input_tensor + self._test(*self.create_model(output_size, return_indices), ie_device, precision, ir_version) + + +class TestAdaptiveMaxPool1D(PytorchLayerTest): + + def _prepare_input(self): + return (self.input_tensor,) + + def create_model(self, output_size=None, return_indices=False): + class aten_adaptive_max_pool1d(torch.nn.Module): + + def __init__(self, output_size=None, return_indices=False) -> None: + super().__init__() + self.output_size = output_size + self.return_indices = return_indices + + def forward(self, input_tensor): + if self.return_indices: + output, indices = F.adaptive_max_pool1d(input_tensor, self.output_size, True) + return output, indices + return F.adaptive_max_pool1d(input_tensor, self.output_size, False), input_tensor.to(torch.int64) + + ref_net = None + + return aten_adaptive_max_pool1d(output_size, return_indices), ref_net, "aten::adaptive_max_pool1d" + + @pytest.mark.parametrize('input_tensor', ([ + np.random.randn(1, 4, 4).astype(np.float32), + np.random.randn(3, 32, 32).astype(np.float32), + np.random.randn(16, 8).astype(np.float32), + ])) + @pytest.mark.parametrize('output_size', ([ + 2, + 4, + ])) + @pytest.mark.parametrize('return_indices', ([ + False, + True, + ])) + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.precommit_ts_backend + @pytest.mark.precommit_fx_backend + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') + def test_adaptive_max_pool1d(self, ie_device, precision, ir_version, input_tensor, output_size, return_indices): + self.input_tensor = input_tensor + self._test(*self.create_model(output_size, return_indices), ie_device, precision, ir_version) \ No newline at end of file diff --git a/tests/layer_tests/pytorch_tests/test_adaptive_max_pool_2d.py b/tests/layer_tests/pytorch_tests/test_adaptive_max_pool_2d.py deleted file mode 100644 index 661c8e1788163b..00000000000000 --- a/tests/layer_tests/pytorch_tests/test_adaptive_max_pool_2d.py +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright (C) 2018-2023 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 - -import numpy as np -import pytest -import torch -import torch.nn.functional as F - -from pytorch_layer_test_class import PytorchLayerTest - - -class TestAdaptiveMaxPool2D(PytorchLayerTest): - - def _prepare_input(self): - return (self.input_tensor,) - - def create_model(self, output_size=None, return_indices=False): - class aten_adaptive_max_pool2d(torch.nn.Module): - - def __init__(self, output_size=None, return_indices=False) -> None: - super().__init__() - self.output_size = output_size - self.return_indices = return_indices - - def forward(self, input_tensor): - if self.return_indices: - output, indices = F.adaptive_max_pool2d(input_tensor, self.output_size, True) - return output - return F.adaptive_max_pool2d(input_tensor, self.output_size, False) - - ref_net = None - - return aten_adaptive_max_pool2d(output_size, return_indices), ref_net, "aten::adaptive_max_pool2d" - - @pytest.mark.parametrize('input_tensor', ([ - np.random.randn(1, 1, 4, 4).astype(np.float32), - np.random.randn(1, 3, 32, 32).astype(np.float32) - ])) - @pytest.mark.parametrize('output_size', ([ - [2, 2], - [4, 4], - ])) - @pytest.mark.parametrize('return_indices', ([ - False, - True, - ])) - @pytest.mark.nightly - @pytest.mark.precommit - @pytest.mark.precommit_ts_backend - @pytest.mark.precommit_fx_backend - def test_adaptive_max_pool2d(self, ie_device, precision, ir_version, input_tensor, output_size, return_indices): - self.input_tensor = input_tensor - self._test(*self.create_model(output_size, return_indices), ie_device, precision, ir_version) diff --git a/tests/layer_tests/pytorch_tests/test_add.py b/tests/layer_tests/pytorch_tests/test_add.py index 7cf243b0577bcb..d89a05420eb7e1 100644 --- a/tests/layer_tests/pytorch_tests/test_add.py +++ b/tests/layer_tests/pytorch_tests/test_add.py @@ -43,7 +43,7 @@ def forward2(self, lhs, rhs): @pytest.mark.parametrize("op_type", ["add", "add_"]) def test_add(self, ie_device, precision, ir_version, alpha, input_rhs, op_type): self.input_rhs = input_rhs - self._test(*self.create_model(alpha, op_type), ie_device, precision, ir_version) + self._test(*self.create_model(alpha, op_type), ie_device, precision, ir_version, use_convert_model=True) class TestAddTypes(PytorchLayerTest): diff --git a/tests/layer_tests/pytorch_tests/test_all.py b/tests/layer_tests/pytorch_tests/test_all.py index b5255f197cfef0..ca9b734c1ad1dd 100644 --- a/tests/layer_tests/pytorch_tests/test_all.py +++ b/tests/layer_tests/pytorch_tests/test_all.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import torch @@ -68,6 +70,8 @@ def test_all_noparams(self, input_tensor, ie_device, precision, ir_version): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_all(self, input_tensor, keepdim, ie_device, precision, ir_version): self.input_tensor = input_tensor for dim in range(len(input_tensor.shape)): diff --git a/tests/layer_tests/pytorch_tests/test_argmax_argmin.py b/tests/layer_tests/pytorch_tests/test_argmax_argmin.py index 05abf128da400d..80ed6fcb872b5f 100644 --- a/tests/layer_tests/pytorch_tests/test_argmax_argmin.py +++ b/tests/layer_tests/pytorch_tests/test_argmax_argmin.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest from pytorch_layer_test_class import PytorchLayerTest @@ -71,6 +73,8 @@ def forward(self, x): @pytest.mark.parametrize("dtype", ["float32", "int32", "int64"]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_argmin_argmax(self, axes, keep_dims, op_type, dtype, ie_device, precision, ir_version): self._test(*self.create_model(op_type, axes, keep_dims), ie_device, precision, ir_version, trace_model=True, diff --git a/tests/layer_tests/pytorch_tests/test_as_strided.py b/tests/layer_tests/pytorch_tests/test_as_strided.py new file mode 100644 index 00000000000000..9bfaa66d3a7f6b --- /dev/null +++ b/tests/layer_tests/pytorch_tests/test_as_strided.py @@ -0,0 +1,125 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np +import pytest +import torch + +from pytorch_layer_test_class import PytorchLayerTest + + +class TestAsStrided(PytorchLayerTest): + def _prepare_input(self): + return (np.random.randn(8, 8).astype(np.float32),) + + def create_model(self, size, stride, offset): + class aten_as_strided(torch.nn.Module): + def __init__(self, size, stride, offset): + super().__init__() + self.size = size + self.stride = stride + self.offset = offset + + def forward(self, x): + return torch.as_strided(x, self.size, self.stride, self.offset) + + ref_net = None + + return aten_as_strided(size, stride, offset), ref_net, "aten::as_strided" + + @pytest.mark.parametrize( + "size,stride", + [ + ([1], [1]), + ([2, 2], [1, 1]), + ([5, 4, 3], [1, 3, 7]), + ([5, 5, 5], [5, 0, 5]), + ([1, 2, 3, 4], [4, 3, 2, 1]), + ], + ) + @pytest.mark.parametrize("offset", [None, 1, 3, 7]) + @pytest.mark.nightly + @pytest.mark.precommit + def test_as_strided(self, size, stride, offset, ie_device, precision, ir_version): + self._test(*self.create_model(size, stride, offset), ie_device, precision, ir_version, trace_model=True) + + +class TestAsStridedListConstruct(PytorchLayerTest): + def _prepare_input(self, size_shape_tensor=[1], stride_shape_tensor=[1]): + return ( + np.random.randn(8, 8).astype(np.float32), + np.ones(size_shape_tensor), + np.ones(stride_shape_tensor), + ) + + def create_model(self, size, stride, offset, mode): + class aten_as_strided(torch.nn.Module): + def __init__(self, size, stride, offset, mode): + super().__init__() + self.size = size + self.stride = stride + self.size_shape_tensor = torch.empty(size) + self.stride_shape_tensor = torch.empty(stride) + self.offset = offset + modes = { + "no_const": self.forward_no_const, + "stride_const": self.forward_stride_const, + "size_const": self.forward_size_const, + } + self.forward = modes.get(mode) + + def forward_no_const(self, x, size_shape_tensor, stride_shape_tensor): + sz1, sz2, sz3 = size_shape_tensor.shape + st1, st2, st3 = stride_shape_tensor.shape + return torch.as_strided(x, [sz1, sz2, sz3], [st1, st2, st3], self.offset) + + def forward_stride_const(self, x, size_shape_tensor, stride_shape_tensor): + sz1, sz2, sz3 = size_shape_tensor.shape + return torch.as_strided(x, [sz1, sz2, sz3], self.stride, self.offset) + + def forward_size_const(self, x, size_shape_tensor, stride_shape_tensor): + st1, st2, st3 = stride_shape_tensor.shape + return torch.as_strided(x, self.size, [st1, st2, st3], self.offset) + + ref_net = None + + return aten_as_strided(size, stride, offset, mode), ref_net, ["aten::as_strided", "prim::ListConstruct"] + + @pytest.mark.parametrize("size,stride", [([5, 4, 3], [1, 3, 7]), ([5, 5, 5], [5, 0, 5])]) + @pytest.mark.parametrize("offset", [None, 7]) + @pytest.mark.parametrize("mode", ["no_const", "stride_const", "size_const"]) + @pytest.mark.nightly + @pytest.mark.precommit + def test_as_strided_list_construct(self, size, stride, offset, mode, ie_device, precision, ir_version): + inp_kwargs = {"size_shape_tensor": size, "stride_shape_tensor": stride} + self._test( + *self.create_model(size, stride, offset, mode), + ie_device, + precision, + ir_version, + kwargs_to_prepare_input=inp_kwargs, + trace_model=True + ) + + +class TestAsStridedLongformer(PytorchLayerTest): + def _prepare_input(self): + return (np.random.randn(1, 10, 20, 40).astype(np.float32).transpose([0, 2, 3, 1]),) + + def create_model(self): + class aten_as_strided_lf(torch.nn.Module): + def forward(self, x): + chunk_size = list(x.size()) + chunk_size[1] = chunk_size[1] * 2 - 1 + chunk_stride = list(x.stride()) + chunk_stride[1] = chunk_stride[1] // 2 + return x.as_strided(size=chunk_size, stride=chunk_stride) + + ref_net = None + + return aten_as_strided_lf(), ref_net, "aten::as_strided" + + @pytest.mark.nightly + @pytest.mark.precommit + def test_as_strided_lf(self, ie_device, precision, ir_version): + self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=True, freeze_model=False) diff --git a/tests/layer_tests/pytorch_tests/test_clamp.py b/tests/layer_tests/pytorch_tests/test_clamp.py index 346b47c3d1f631..ad869d6211e270 100644 --- a/tests/layer_tests/pytorch_tests/test_clamp.py +++ b/tests/layer_tests/pytorch_tests/test_clamp.py @@ -11,11 +11,11 @@ def _prepare_input(self): import numpy as np return (np.random.randn(1, 3, 224, 224).astype(np.float32),) - def create_model(self, minimum, maximum, as_tensors=False): + def create_model(self, minimum, maximum, as_tensors=False, op_type='clamp'): import torch class aten_clamp(torch.nn.Module): - def __init__(self, minimum, maximum, as_tensors): + def __init__(self, minimum, maximum, as_tensors, op_type="clamp"): super(aten_clamp, self).__init__() if minimum is not None and as_tensors: minimum = torch.tensor(minimum) @@ -23,20 +23,31 @@ def __init__(self, minimum, maximum, as_tensors): if maximum is not None and as_tensors: maximum = torch.tensor(maximum) self.max = maximum + self.forward = getattr(self, f"forward_{op_type}") - def forward(self, x): + def forward_clamp(self, x): return torch.clamp(x, self.min, self.max) + def forward_clip(self, x): + return torch.clip(x, self.min, self.max) + + def forward_clamp_(self, x): + return x.clamp_(self.min, self.max), x + + def forward_clip_(self, x): + return x.clip_(self.min, self.max), x + ref_net = None - op_name = "aten::clamp" - return aten_clamp(minimum, maximum, as_tensors), ref_net, op_name + op_name = f"aten::{op_type}" + return aten_clamp(minimum, maximum, as_tensors, op_type), ref_net, op_name @pytest.mark.parametrize("minimum,maximum", [(0., 1.), (-0.5, 1.5), (None, 10.), (None, -10.), (10., None), (-10., None), (100, 200)]) @pytest.mark.parametrize("as_tensors", [True, False]) + @pytest.mark.parametrize("op_type", ["clamp", "clamp_"]) @pytest.mark.nightly - def test_clamp(self, minimum, maximum, as_tensors, ie_device, precision, ir_version): - self._test(*self.create_model(minimum, maximum, as_tensors), ie_device, precision, ir_version) + def test_clamp(self, minimum, maximum, as_tensors, op_type, ie_device, precision, ir_version): + self._test(*self.create_model(minimum, maximum, as_tensors, op_type), ie_device, precision, ir_version) @pytest.mark.xfail(reason='OpenVINO clamp does not support min > max') def test_clamp_min_greater(self, ie_device, precision, ir_version): diff --git a/tests/layer_tests/pytorch_tests/test_comparision.py b/tests/layer_tests/pytorch_tests/test_comparision.py index 98134a274f7bdb..a114afb1f712c8 100644 --- a/tests/layer_tests/pytorch_tests/test_comparision.py +++ b/tests/layer_tests/pytorch_tests/test_comparision.py @@ -55,7 +55,7 @@ def forward(self, x, y): @pytest.mark.nightly @pytest.mark.precommit def test_comp(self, op, ie_device, precision, ir_version): - self._test(*self.create_model(op), ie_device, precision, ir_version) + self._test(*self.create_model(op), ie_device, precision, ir_version, use_convert_model=True) class TestCompMixedTypes(PytorchLayerTest): diff --git a/tests/layer_tests/pytorch_tests/test_cumsum.py b/tests/layer_tests/pytorch_tests/test_cumsum.py index 926cfe9e95c30a..771eb02768bdf0 100644 --- a/tests/layer_tests/pytorch_tests/test_cumsum.py +++ b/tests/layer_tests/pytorch_tests/test_cumsum.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest from pytorch_layer_test_class import PytorchLayerTest @@ -69,5 +71,7 @@ def forward_out_prim_dtype(self, x, y): @pytest.mark.parametrize("out,dtype_from_input", [(False, False), (True, False), (True, True)]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_cumsum(self, axis, dtype, out, dtype_from_input, ie_device, precision, ir_version): self._test(*self.create_model(axis, dtype, out, dtype_from_input), ie_device, precision, ir_version, kwargs_to_prepare_input={"out": out, "out_dtype": dtype}) diff --git a/tests/layer_tests/pytorch_tests/test_deformable_convolution.py b/tests/layer_tests/pytorch_tests/test_deformable_convolution.py index 8fa207efe85b41..fa4293b275e6c7 100644 --- a/tests/layer_tests/pytorch_tests/test_deformable_convolution.py +++ b/tests/layer_tests/pytorch_tests/test_deformable_convolution.py @@ -10,15 +10,6 @@ from torchvision.ops import deform_conv2d -def xfail_106712(test_param): - return pytest.param( - test_param, - marks=pytest.mark.xfail( - reason="Depending on number of groups and number of output channels, deformable convolution may return incorrect reasults. Ticket 106712" - ), - ) - - params = [ { "weights_shape": [64, 64, 3, 3], @@ -62,15 +53,13 @@ def xfail_106712(test_param): "padding": (2, 2), "dilation": (1, 1), }, - xfail_106712( - { - "weights_shape": [64, 16, 3, 3], - "offset_shape": [1, 18, 64, 64], - "stride": (1, 1), - "padding": (1, 1), - "dilation": (1, 1), - } - ), + { + "weights_shape": [64, 16, 3, 3], + "offset_shape": [1, 18, 64, 64], + "stride": (1, 1), + "padding": (1, 1), + "dilation": (1, 1), + }, { "weights_shape": [60, 16, 3, 3], "offset_shape": [1, 18, 64, 64], @@ -92,15 +81,13 @@ def xfail_106712(test_param): "padding": (1, 1), "dilation": (1, 1), }, - xfail_106712( - { - "weights_shape": [64, 32, 3, 3], - "offset_shape": [1, 36, 68, 68], - "stride": (1, 1), - "padding": (3, 3), - "dilation": (1, 1), - } - ), + { + "weights_shape": [64, 32, 3, 3], + "offset_shape": [1, 36, 68, 68], + "stride": (1, 1), + "padding": (3, 3), + "dilation": (1, 1), + }, { "weights_shape": [62, 32, 3, 3], "offset_shape": [1, 36, 68, 68], diff --git a/tests/layer_tests/pytorch_tests/test_device.py b/tests/layer_tests/pytorch_tests/test_device.py index a36bd731a6dae7..2efdf5c85c50fa 100644 --- a/tests/layer_tests/pytorch_tests/test_device.py +++ b/tests/layer_tests/pytorch_tests/test_device.py @@ -56,7 +56,8 @@ def test_device(self, device_string, ie_device, precision, ir_version): ie_device, precision, ir_version, - trace_model=False + trace_model=False, + use_convert_model=True, ) @pytest.mark.parametrize("device_string", ["cpu", "cuda"]) @@ -68,5 +69,6 @@ def test_device_type(self, device_string, ie_device, precision, ir_version): ie_device, precision, ir_version, - trace_model=False + trace_model=False, + use_convert_model=True, ) diff --git a/tests/layer_tests/pytorch_tests/test_dict.py b/tests/layer_tests/pytorch_tests/test_dict.py index a3e3c29b6baf1f..6e4db9dea825bd 100644 --- a/tests/layer_tests/pytorch_tests/test_dict.py +++ b/tests/layer_tests/pytorch_tests/test_dict.py @@ -23,4 +23,4 @@ def forward(self, x): @pytest.mark.nightly @pytest.mark.precommit def test_dict(self, ie_device, precision, ir_version): - self._test(*self.create_model(), ie_device, precision, ir_version) + self._test(*self.create_model(), ie_device, precision, ir_version, use_convert_model=True) diff --git a/tests/layer_tests/pytorch_tests/test_distance.py b/tests/layer_tests/pytorch_tests/test_distance.py index 1c76a7243b47e3..fb9fade8206996 100644 --- a/tests/layer_tests/pytorch_tests/test_distance.py +++ b/tests/layer_tests/pytorch_tests/test_distance.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest from pytorch_layer_test_class import PytorchLayerTest @@ -29,8 +31,10 @@ def forward(self, x, y): @pytest.mark.nightly @pytest.mark.precommit @pytest.mark.parametrize("p", [2., 4., 6., 8.,]) + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_cdist(self, p, ie_device, precision, ir_version): - self._test(*self.create_model(p), ie_device, precision, ir_version) + self._test(*self.create_model(p), ie_device, precision, ir_version, use_convert_model=True) class TestPairwiseDistance(PytorchLayerTest): @@ -61,5 +65,7 @@ def forward(self, x, y): @pytest.mark.parametrize("p", [2., 4., 6., 8.,]) @pytest.mark.parametrize("eps", [1e-06, 0.00001, 1e-07]) @pytest.mark.parametrize("keepdim", [True, False]) + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_cdist(self, p, eps, keepdim, ie_device, precision, ir_version): - self._test(*self.create_model(p, eps, keepdim), ie_device, precision, ir_version) \ No newline at end of file + self._test(*self.create_model(p, eps, keepdim), ie_device, precision, ir_version, use_convert_model=True) diff --git a/tests/layer_tests/pytorch_tests/test_div.py b/tests/layer_tests/pytorch_tests/test_div.py index d6e696b62882d5..564cb2915c8686 100644 --- a/tests/layer_tests/pytorch_tests/test_div.py +++ b/tests/layer_tests/pytorch_tests/test_div.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import torch @@ -47,7 +49,7 @@ def test_div_pt_spec(self, input_array, other_array, rounding_mode, ie_device, p self.other_array = other_array self.other_type = np.float32 self._test(*self.create_model(rounding_mode), - ie_device, precision, ir_version) + ie_device, precision, ir_version, use_convert_model=True) class TestDivTypes(PytorchLayerTest): @@ -116,6 +118,8 @@ def forward3(self, lhs, rhs): ])) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_div_types(self, ie_device, precision, ir_version, lhs_type, lhs_shape, rhs_type, rhs_shape, rounding_mode): self.lhs_type = lhs_type self.lhs_shape = lhs_shape diff --git a/tests/layer_tests/pytorch_tests/test_embedding_bag.py b/tests/layer_tests/pytorch_tests/test_embedding_bag.py index 2595b2269316fd..d0c6d0c532856f 100644 --- a/tests/layer_tests/pytorch_tests/test_embedding_bag.py +++ b/tests/layer_tests/pytorch_tests/test_embedding_bag.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest from pytorch_layer_test_class import PytorchLayerTest @@ -42,6 +44,8 @@ def forward_offsets_per_sample_weights(self, indicies, weight, offsets, per_samp @pytest.mark.precommit @pytest.mark.parametrize("indicies_dtype", ["int", "int32"]) @pytest.mark.parametrize("per_sample_weights", [True, False]) + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_embedding_bag(self, ie_device, precision, ir_version, indicies_dtype, per_sample_weights): self._test(*self.create_model(per_sample_weights), ie_device, precision, ir_version, kwargs_to_prepare_input={"indicies_dtype": indicies_dtype, "per_sample_weights": per_sample_weights}, @@ -85,6 +89,8 @@ def forward_per_sample_weights(self, indicies, weight, per_sample_wights): @pytest.mark.parametrize("indicies_size", [[1, 1], [2, 5], [3, 10], [4, 7]]) @pytest.mark.parametrize("indicies_dtype", ["int", "int32"]) @pytest.mark.parametrize("per_sample_weights", [True, False]) + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_embedding_bag(self, ie_device, precision, ir_version, indicies_dtype, indicies_size, per_sample_weights): self._test(*self.create_model(per_sample_weights), ie_device, precision, ir_version, kwargs_to_prepare_input={"indicies_size": indicies_size, "indicies_dtype": indicies_dtype, "per_sample_weights": per_sample_weights}, diff --git a/tests/layer_tests/pytorch_tests/test_empty.py b/tests/layer_tests/pytorch_tests/test_empty.py index 7b5a4b92563dc5..c504e262038c87 100644 --- a/tests/layer_tests/pytorch_tests/test_empty.py +++ b/tests/layer_tests/pytorch_tests/test_empty.py @@ -134,7 +134,7 @@ def forward(self, input_tensor: torch.Tensor): @pytest.mark.precommit def test_new_empty(self, shape, input_dtype, ie_device, precision, ir_version): self._test(*self.create_model(shape), ie_device, precision, ir_version, - kwargs_to_prepare_input={'input_dtype': input_dtype}) + kwargs_to_prepare_input={'input_dtype': input_dtype}, use_convert_model=True) @pytest.mark.parametrize("shape", [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5, 6]]) @pytest.mark.parametrize("input_dtype", [bool, np.uint8, np.int8, np.int32, np.int64, np.float32, np.float64]) @@ -142,4 +142,4 @@ def test_new_empty(self, shape, input_dtype, ie_device, precision, ir_version): @pytest.mark.nightly def test_new_empty_with_dtype(self, shape, dtype, input_dtype, ie_device, precision, ir_version): self._test(*self.create_model(shape, dtype=dtype, used_dtype=True), ie_device, precision, ir_version, - kwargs_to_prepare_input={'input_dtype': input_dtype}) + kwargs_to_prepare_input={'input_dtype': input_dtype}, use_convert_model=True) diff --git a/tests/layer_tests/pytorch_tests/test_eq.py b/tests/layer_tests/pytorch_tests/test_eq.py index 91c30df79fabb8..6fa5f4ecfba5eb 100644 --- a/tests/layer_tests/pytorch_tests/test_eq.py +++ b/tests/layer_tests/pytorch_tests/test_eq.py @@ -45,4 +45,4 @@ def test_eq_pt_spec(self, input_array, other_array, types, ie_device, precision, self.input_type = types[0] self.other_array = other_array self.other_type = types[1] - self._test(*self.create_model(), ie_device, precision, ir_version) + self._test(*self.create_model(), ie_device, precision, ir_version, use_convert_model=True) diff --git a/tests/layer_tests/pytorch_tests/test_erf.py b/tests/layer_tests/pytorch_tests/test_erf.py new file mode 100644 index 00000000000000..ab4d1b8d9d7ae7 --- /dev/null +++ b/tests/layer_tests/pytorch_tests/test_erf.py @@ -0,0 +1,57 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import pytest + +from pytorch_layer_test_class import PytorchLayerTest + + +class TestErf(PytorchLayerTest): + def _prepare_input(self, input_dtype, out=False): + import numpy as np + x = np.linspace(-3, 3).astype(input_dtype) + if not out: + return (x, ) + return (x, np.zeros_like(x).astype(input_dtype)) + + def create_model(self, mode="", input_dtype="float32"): + import torch + dtypes = { + "float32": torch.float32, + "float64": torch.float64, + "int32": torch.int32 + } + + dtype = dtypes[input_dtype] + class aten_erf(torch.nn.Module): + def __init__(self, mode, dtype): + super(aten_erf, self).__init__() + self.dtype = dtype + if mode == "out": + self.forward = self.forward_out + elif mode == "inplace": + self.forward = self.forward_inplace + + def forward(self, x): + return torch.special.erf(x.to(self.dtype)) + + def forward_out(self, x, y): + return torch.special.erf(x.to(self.dtype), out=y), y + + def forward_inplace(self, x): + x = x.to(self.dtype) + return x.erf_(), x + + ref_net = None + + return aten_erf(mode, dtype), ref_net, "aten::erf" if mode != "inplace" else "aten::erf_" + + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.parametrize("mode,input_dtype", [ + ("", "float32"), ("", "float64"), ("", "int32"), + ("out", "float32"), ("out", "float64"), + ("inplace", "float32"), ("inplace", "float64")]) + def test_erf(self, mode, input_dtype, ie_device, precision, ir_version): + self._test(*self.create_model(mode, input_dtype), ie_device, precision, ir_version, + kwargs_to_prepare_input={"input_dtype": input_dtype, "out": mode == "out"} ) \ No newline at end of file diff --git a/tests/layer_tests/pytorch_tests/test_fake_quantize.py b/tests/layer_tests/pytorch_tests/test_fake_quantize.py index 6bb1d6601cb43b..3146ac87b90087 100644 --- a/tests/layer_tests/pytorch_tests/test_fake_quantize.py +++ b/tests/layer_tests/pytorch_tests/test_fake_quantize.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import torch @@ -46,6 +48,8 @@ def forward(self, x): (1.0, 0, 0, 127), ], ) + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_fake_quantize_per_tensor_affine( self, ie_device, precision, ir_version, scale, zero_point, quant_min, quant_max ): @@ -96,6 +100,8 @@ def forward(self, x): (torch.tensor([-0.005, -0.7, 0.1]), torch.tensor([1, 0, 1], dtype=torch.int32), 0, 0, 255), ], ) + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_fake_quantize_per_channel_affine( self, ie_device, precision, ir_version, scale, zero_point, axis, quant_min, quant_max ): diff --git a/tests/layer_tests/pytorch_tests/test_floor_divide.py b/tests/layer_tests/pytorch_tests/test_floor_divide.py index cd427acb3dba56..0cdc46333b2651 100644 --- a/tests/layer_tests/pytorch_tests/test_floor_divide.py +++ b/tests/layer_tests/pytorch_tests/test_floor_divide.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest @@ -52,10 +54,12 @@ def forward(self, input_tensor, other_tensor): ])) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_floor_divide(self, input_tensor, other_tensor, ie_device, precision, ir_version): self.input_tensor = input_tensor self.other_tensor = other_tensor - self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=True) + self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=True, use_convert_model=True) @pytest.mark.parametrize('input_tensor', ([ np.random.randint(low=0, high=10, size=5).astype(np.float32), diff --git a/tests/layer_tests/pytorch_tests/test_fp16.py b/tests/layer_tests/pytorch_tests/test_fp16.py index b754306727935c..5952f40f167c54 100644 --- a/tests/layer_tests/pytorch_tests/test_fp16.py +++ b/tests/layer_tests/pytorch_tests/test_fp16.py @@ -29,7 +29,7 @@ def forward(self, x): @pytest.mark.parametrize("to_trace", [True, False]) def test_bf16(self, ie_device, precision, ir_version, to_trace): self._test(*self.create_model(), ie_device, precision, - ir_version, trace_model=to_trace, freeze_model=False) + ir_version, trace_model=to_trace, freeze_model=False, use_convert_model=True) class TestFP16(PytorchLayerTest): @@ -53,4 +53,4 @@ def forward(self, x): @pytest.mark.parametrize("to_trace", [True, False]) def test_fp16(self, ie_device, precision, ir_version, to_trace): self._test(*self.create_model(), ie_device, precision, - ir_version, trace_model=to_trace, freeze_model=False) + ir_version, trace_model=to_trace, freeze_model=False, use_convert_model=True) diff --git a/tests/layer_tests/pytorch_tests/test_full.py b/tests/layer_tests/pytorch_tests/test_full.py index 4ce42db7fa9167..cf3794be11e891 100644 --- a/tests/layer_tests/pytorch_tests/test_full.py +++ b/tests/layer_tests/pytorch_tests/test_full.py @@ -1,5 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 + +import platform + import numpy as np import pytest @@ -104,31 +107,98 @@ def test_full_out(self, shape, value, dtype, with_names, ie_device, precision, i ir_version, kwargs_to_prepare_input={'value': value}) class TestFill(PytorchLayerTest): - def _prepare_input(self, value, shape, input_dtype, value_dtype): - return (np.random.randn(*shape).astype(input_dtype), np.array(value, dtype=value_dtype),) + def _prepare_input(self, value, shape, input_dtype, value_dtype, out=False): + if not out: + return (np.random.randn(*shape).astype(input_dtype), np.array(value, dtype=value_dtype),) + return (np.random.randn(*shape).astype(input_dtype), np.array(value, dtype=value_dtype), np.zeros(shape, dtype=input_dtype)) - def create_model(self): + + def create_model(self, mode): import torch class aten_fill(torch.nn.Module): + def __init__(self, mode) -> None: + super().__init__() + if mode == "inplace": + self.forward = self.forward_inplace + if mode == "out": + self.forward = self.forward_out - def forward(self, input_t: torch.Tensor, x: float): + + def forward_inplace(self, input_t: torch.Tensor, x: float): return input_t.fill_(x) + + def forward_out(self, input_t: torch.Tensor, x: float, out: torch.Tensor): + return input_t.fill(x, out=out), out + + def forward(self, input_t: torch.Tensor, x:float): + return input_t.fill(x) + ref_net = None - model = aten_fill() + model = aten_fill(mode) - return model, ref_net, "aten::fill_" + return model, ref_net, "aten::fill_" if mode == "inplace" else "aten::fill" @pytest.mark.parametrize("shape", [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5, 6]]) @pytest.mark.parametrize("value", [0, 1, -1, 0.5]) @pytest.mark.parametrize("input_dtype", ["int8", "int32", "int64", "float32", "float64"]) @pytest.mark.parametrize("value_dtype", ["int8", "int32", "int64", "float32", "float64"]) + @pytest.mark.parametrize("mode", ["", "inplace", "out"]) @pytest.mark.nightly @pytest.mark.precommit - def test_fill(self, shape, value, input_dtype, value_dtype, ie_device, precision, ir_version): - self._test(*self.create_model(), ie_device, precision, ir_version, - kwargs_to_prepare_input={'value': value, 'shape': shape, "input_dtype": input_dtype, "value_dtype": value_dtype}) + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') + def test_fill(self, shape, value, input_dtype, value_dtype, mode, ie_device, precision, ir_version): + self._test(*self.create_model(mode), ie_device, precision, ir_version, + kwargs_to_prepare_input={ + 'value': value, + 'shape': shape, + "input_dtype": input_dtype, + "value_dtype": value_dtype, + "out": mode == "out" + }) + +class TestFillDiagonal(PytorchLayerTest): + def _prepare_input(self, shape, input_dtype, value, value_dtype): + return np.zeros(shape).astype(input_dtype), np.array(value, dtype=value_dtype) + + def create_model(self, shape, wrap): + import torch + + class aten_fill_diagonal(torch.nn.Module): + def __init__(self, input_shape, wrap=False) -> None: + super().__init__() + self.wrap = wrap + self.input_shape = input_shape + + def forward(self, x:torch.Tensor, y:float): + x = x.reshape(self.input_shape) + return x.fill_diagonal_(y, wrap=self.wrap), x + + ref_net = None + + model = aten_fill_diagonal(shape, wrap) + return model, "aten::fill_diagonal_", ref_net + + @pytest.mark.parametrize("shape", ([4, 4], [5, 4], [8, 4], [4, 3], [5, 5, 5], [3, 3, 3, 3], [4, 4, 4, 4, 4])) + @pytest.mark.parametrize("value", [0, 1, -1, 2.5]) + @pytest.mark.parametrize("input_dtype", ["int8", "int32", "int64", "float32", "float64"]) + @pytest.mark.parametrize("value_dtype", ["int8", "int32", "int64", "float32", "float64"]) + @pytest.mark.parametrize("wrap", [True, False]) + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') + def test_fill_diagonal(self, shape, value, input_dtype, value_dtype, wrap, ie_device, precision, ir_version): + self._test(*self.create_model(shape, wrap), ie_device, precision, ir_version, + kwargs_to_prepare_input={ + 'value': value, + 'shape': shape, + "input_dtype": input_dtype, + "value_dtype": value_dtype + }) + class TestZero(PytorchLayerTest): def _prepare_input(self, shape, input_dtype): @@ -277,7 +347,7 @@ def forward(self, input_tensor: torch.Tensor, x: float): @pytest.mark.precommit def test_new_full(self, shape, value, input_dtype, ie_device, precision, ir_version): self._test(*self.create_model(shape), ie_device, precision, ir_version, - kwargs_to_prepare_input={'value': value, 'input_dtype': input_dtype}) + kwargs_to_prepare_input={'value': value, 'input_dtype': input_dtype}, use_convert_model=True) @pytest.mark.parametrize("shape", [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5, 6]]) @pytest.mark.parametrize("value,input_dtype", [(0, np.uint8), (1, np.int32), (-1, np.float32), (0.5, np.float64)]) @@ -285,7 +355,7 @@ def test_new_full(self, shape, value, input_dtype, ie_device, precision, ir_vers @pytest.mark.nightly def test_new_full_with_dtype(self, value, shape, dtype, input_dtype, ie_device, precision, ir_version): self._test(*self.create_model(shape, dtype=dtype, used_dtype=True), ie_device, precision, ir_version, - kwargs_to_prepare_input={'value': value, 'input_dtype': input_dtype}) + kwargs_to_prepare_input={'value': value, 'input_dtype': input_dtype}, use_convert_model=True) class TestZerosAndOnes(PytorchLayerTest): @@ -492,7 +562,7 @@ def forward(self, input_tensor: torch.Tensor): @pytest.mark.precommit def test_new_zeros(self, shape, input_dtype, ie_device, precision, ir_version): self._test(*self.create_model(shape), ie_device, precision, ir_version, - kwargs_to_prepare_input={'input_dtype': input_dtype}) + kwargs_to_prepare_input={'input_dtype': input_dtype}, use_convert_model=True) @pytest.mark.parametrize("shape", [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5, 6]]) @pytest.mark.parametrize("input_dtype", [bool, np.uint8, np.int8, np.int32, np.int64, np.float32, np.float64]) @@ -500,7 +570,7 @@ def test_new_zeros(self, shape, input_dtype, ie_device, precision, ir_version): @pytest.mark.nightly def test_new_zeros_with_dtype(self, shape, dtype, input_dtype, ie_device, precision, ir_version): self._test(*self.create_model(shape, dtype=dtype, used_dtype=True), ie_device, precision, ir_version, - kwargs_to_prepare_input={'input_dtype': input_dtype}) + kwargs_to_prepare_input={'input_dtype': input_dtype}, use_convert_model=True) class TestNewOnes(PytorchLayerTest): @@ -551,7 +621,7 @@ def forward(self, input_tensor: torch.Tensor): @pytest.mark.precommit def test_new_ones(self, shape, input_dtype, ie_device, precision, ir_version): self._test(*self.create_model(shape), ie_device, precision, ir_version, - kwargs_to_prepare_input={'input_dtype': input_dtype}) + kwargs_to_prepare_input={'input_dtype': input_dtype}, use_convert_model=True) @pytest.mark.parametrize("shape", [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5, 6]]) @pytest.mark.parametrize("input_dtype", [bool, np.uint8, np.int8, np.int32, np.int64, np.float32, np.float64]) @@ -559,4 +629,4 @@ def test_new_ones(self, shape, input_dtype, ie_device, precision, ir_version): @pytest.mark.nightly def test_new_ones_with_dtype(self, shape, dtype, input_dtype, ie_device, precision, ir_version): self._test(*self.create_model(shape, dtype=dtype, used_dtype=True), ie_device, precision, ir_version, - kwargs_to_prepare_input={'input_dtype': input_dtype}) + kwargs_to_prepare_input={'input_dtype': input_dtype}, use_convert_model=True) diff --git a/tests/layer_tests/pytorch_tests/test_getitem.py b/tests/layer_tests/pytorch_tests/test_getitem.py index b827f626914125..62d7e12ada6e61 100644 --- a/tests/layer_tests/pytorch_tests/test_getitem.py +++ b/tests/layer_tests/pytorch_tests/test_getitem.py @@ -102,4 +102,4 @@ def _prepare_input(self): @pytest.mark.parametrize("idx", [-4, -3, -2, -1, 0, 1, 2, 3]) def test_add_cat(self, ie_device, precision, ir_version, idx): self._test(aten_add_getitem(idx), None, ["aten::__getitem__", "aten::add", "prim::ListConstruct"], - ie_device, precision, ir_version, freeze_model=False) + ie_device, precision, ir_version, freeze_model=False, use_convert_model=True) diff --git a/tests/layer_tests/pytorch_tests/test_grid_sampler.py b/tests/layer_tests/pytorch_tests/test_grid_sampler.py index b142544c3b6e62..7b55862e2f0c2d 100644 --- a/tests/layer_tests/pytorch_tests/test_grid_sampler.py +++ b/tests/layer_tests/pytorch_tests/test_grid_sampler.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest from pytorch_layer_test_class import PytorchLayerTest @@ -35,6 +37,8 @@ def forward(self, input, grid): @pytest.mark.parametrize("align_corners", [True, False, None]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_grid_sampler(self, h_in, w_in, h_out, w_out, mode, padding_mode, align_corners, ie_device, precision, ir_version): self._test(*self.create_model(mode, padding_mode, align_corners), ie_device, precision, ir_version, kwargs_to_prepare_input={ "h_in": h_in, "w_in": w_in, "h_out": h_out, "w_out": w_out diff --git a/tests/layer_tests/pytorch_tests/test_if.py b/tests/layer_tests/pytorch_tests/test_if.py index b4fd9470cc8be3..fa4b1e9967dd02 100644 --- a/tests/layer_tests/pytorch_tests/test_if.py +++ b/tests/layer_tests/pytorch_tests/test_if.py @@ -39,4 +39,4 @@ def forward(self, x, y): @pytest.mark.skipif(os.getenv("GITHUB_ACTIONS") == 'true', reason="Ticket - 114818") def test_if(self, y, ie_device, precision, ir_version): self.y = y - self._test(*self.create_model(), ie_device, precision, ir_version) + self._test(*self.create_model(), ie_device, precision, ir_version, use_convert_model=True) diff --git a/tests/layer_tests/pytorch_tests/test_index.py b/tests/layer_tests/pytorch_tests/test_index.py index 6f7cea86990d2c..4b4e53690f927e 100644 --- a/tests/layer_tests/pytorch_tests/test_index.py +++ b/tests/layer_tests/pytorch_tests/test_index.py @@ -150,4 +150,4 @@ def forward(self, x): [2, 2, 3, 4])) def test_index_mask(self, input_shape, ie_device, precision, ir_version): self._test(*self.create_model(), ie_device, precision, ir_version, kwargs_to_prepare_input={ - "input_shape": input_shape}, trace_model=True) + "input_shape": input_shape}, trace_model=True, use_convert_model=True) diff --git a/tests/layer_tests/pytorch_tests/test_index_put_.py b/tests/layer_tests/pytorch_tests/test_index_put_.py index 55cbe39bd92d58..6f94a0912d4df2 100644 --- a/tests/layer_tests/pytorch_tests/test_index_put_.py +++ b/tests/layer_tests/pytorch_tests/test_index_put_.py @@ -162,7 +162,7 @@ def test_nonzero_index_put_(self, ie_device, precision, ir_version, input_data, self.values = input_data["values"] self.indices_0 = indices[0] self.indices_1 = indices[1] - self._test(*self.create_model(accumulate), ie_device, precision, ir_version, trace_model=True) + self._test(*self.create_model(accumulate), ie_device, precision, ir_version, trace_model=True, use_convert_model=True) class TestMask_IndexPut(PytorchLayerTest): def _prepare_input(self): @@ -181,4 +181,4 @@ def forward(self, x, y): @pytest.mark.nightly @pytest.mark.precommit def test_nonzero_index_put_(self, ie_device, precision, ir_version): - self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=True) + self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=True, use_convert_model=True) diff --git a/tests/layer_tests/pytorch_tests/test_instance_norm.py b/tests/layer_tests/pytorch_tests/test_instance_norm.py index 2fe3f5e13e066a..3ec2dd0144573d 100644 --- a/tests/layer_tests/pytorch_tests/test_instance_norm.py +++ b/tests/layer_tests/pytorch_tests/test_instance_norm.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest from pytorch_layer_test_class import PytorchLayerTest @@ -60,6 +62,8 @@ def forward(self, x): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_group_norm(self, params, ie_device, precision, ir_version, kwargs_to_prepare_input): self._test(*self.create_model(**params), ie_device, precision, ir_version, kwargs_to_prepare_input=kwargs_to_prepare_input, diff --git a/tests/layer_tests/pytorch_tests/test_len.py b/tests/layer_tests/pytorch_tests/test_len.py index d6d3a7dc211564..7aa5f020b9c7fc 100644 --- a/tests/layer_tests/pytorch_tests/test_len.py +++ b/tests/layer_tests/pytorch_tests/test_len.py @@ -48,7 +48,7 @@ def test_len(self, ie_device, precision, ir_version, input_tensor): def test_len_int_list(self, ie_device, precision, ir_version, input_tensor): self.input_tensor = input_tensor self._test(*self.create_model_int_list(), - ie_device, precision, ir_version) + ie_device, precision, ir_version, use_convert_model=True) class TestLenEmpty(PytorchLayerTest): diff --git a/tests/layer_tests/pytorch_tests/test_linspace.py b/tests/layer_tests/pytorch_tests/test_linspace.py index aa6f70d3d71c89..4cf623e55fafad 100644 --- a/tests/layer_tests/pytorch_tests/test_linspace.py +++ b/tests/layer_tests/pytorch_tests/test_linspace.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import torch @@ -63,6 +65,8 @@ def forward(self, start, end, steps, d): @pytest.mark.parametrize( "start,end,steps", [(0, 1, 5), (-2, 1, 5), (1, -5, 7), (1, 10, 2), (-1, -5, 2), (-1, -5, 1), (1.25, -5.5, 5)] ) + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_linspace_with_prim_dtype(self, dtype, end, start, steps, ie_device, precision, ir_version): self._test( *self.create_model(dtype, ref_dtype=True), @@ -79,6 +83,8 @@ def test_linspace_with_prim_dtype(self, dtype, end, start, steps, ie_device, pre "start,end,steps", [(0, 1, 5), (-2, 1, 5), (1, -5, 7), (1, 10, 2), (-1, -5, 2), (-1, -5, 1), (1.25, -5.5, 5)] ) @pytest.mark.parametrize("use_out", [False, True]) + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_linspace_with_out(self, dtype, use_out, end, start, steps, ie_device, precision, ir_version): self._test( *self.create_model(dtype=dtype, use_out=use_out), diff --git a/tests/layer_tests/pytorch_tests/test_listunpack.py b/tests/layer_tests/pytorch_tests/test_listunpack.py index b001bccd2a97d1..39d72bfe54c6e9 100644 --- a/tests/layer_tests/pytorch_tests/test_listunpack.py +++ b/tests/layer_tests/pytorch_tests/test_listunpack.py @@ -123,6 +123,7 @@ def test_listconstruct_getitem_listunpack( ie_device, precision, ir_version, + use_convert_model=True, ) class TestMeshgridListUnpack(PytorchLayerTest): diff --git a/tests/layer_tests/pytorch_tests/test_min_max.py b/tests/layer_tests/pytorch_tests/test_min_max.py index c32fe41512f800..3a624d534fa6e0 100644 --- a/tests/layer_tests/pytorch_tests/test_min_max.py +++ b/tests/layer_tests/pytorch_tests/test_min_max.py @@ -283,4 +283,57 @@ def test_minimum_maximum_out( ie_device, precision, ir_version, kwargs_to_prepare_input= {"input_dtype": input_dtype, "second_input_dtype": input_dtype, "out": True} + ) + + +class TestAminAmax(PytorchLayerTest): + def _prepare_input(self, input_dtype="float32", out=False, axes=None, keep_dims=False): + import numpy as np + x = np.random.randn(1, 3, 10, 10).astype(input_dtype) + if not out: + return (x,) + if isinstance(axes, list): + axes = tuple(axes) + out = np.zeros_like(np.max(x, axis=axes, keepdims=keep_dims), dtype=input_dtype) + return (x, out) + + def create_model(self, op_type, axis, keep_dims, out=False): + import torch + op_types = { + "amax": torch.amax, + "amin": torch.amin + } + + + op = op_types[op_type] + + class aten_amin_amax(torch.nn.Module): + def __init__(self, op, axis, keep_dims, out): + super().__init__() + self.op = op + self.axis = axis + self.keep_dims = keep_dims + if out: + self.forward = self.forward_out + + def forward_out(self, x, y): + return self.op(x, self.axis, self.keep_dims, out=y), y + + def forward(self, x): + return self.op(x, self.axis, self.keep_dims) + + + model_cls = aten_amin_amax(op, axis, keep_dims, out) + + return model_cls, None, f"aten::{op_type}" + + @pytest.mark.parametrize("op_type", ["amin", "amax"]) + @pytest.mark.parametrize("axis", [0, -1, 1, [1, 2], [-1, -2], [2, 0, -1], [0, 1, 2, 3]]) + @pytest.mark.parametrize("keep_dims", [True, False]) + @pytest.mark.parametrize("out", [True, False]) + @pytest.mark.parametrize("input_dtype", ['float32', 'int32', 'int64', 'float64']) + def test_amin_amax(self, op_type, input_dtype, axis, keep_dims, out, ie_device, precision, ir_version): + self._test(*self.create_model(op_type, axis, keep_dims, out), + ie_device, precision, ir_version, kwargs_to_prepare_input= + {"input_dtype": input_dtype, "out": out, "axes": axis, "keep_dims": keep_dims} ) \ No newline at end of file diff --git a/tests/layer_tests/pytorch_tests/test_mul.py b/tests/layer_tests/pytorch_tests/test_mul.py index f22fd7b03bc0cb..c7aea00ee8ad89 100644 --- a/tests/layer_tests/pytorch_tests/test_mul.py +++ b/tests/layer_tests/pytorch_tests/test_mul.py @@ -37,7 +37,7 @@ def test_mul_pt_spec(self, input_array, other_array, ie_device, precision, ir_ve self.input_type = np.float32 self.other_array = other_array self.other_type = np.float32 - self._test(*self.create_model(), ie_device, precision, ir_version) + self._test(*self.create_model(), ie_device, precision, ir_version, use_convert_model=True) class TestMulTypes(PytorchLayerTest): diff --git a/tests/layer_tests/pytorch_tests/test_native_multi_head_attention.py b/tests/layer_tests/pytorch_tests/test_native_multi_head_attention.py index 41e737dba6221d..26b7cdbd14812b 100644 --- a/tests/layer_tests/pytorch_tests/test_native_multi_head_attention.py +++ b/tests/layer_tests/pytorch_tests/test_native_multi_head_attention.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import torch @@ -74,6 +76,8 @@ def _prepare_input(self): ["need_weights", "average_attn_weights"], [[False, False], [True, False], [True, True]] ) + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_native_multi_head_attention(self, ie_device, precision, ir_version, mask, need_weights, average_attn_weights): self._test(aten_native_multi_head_attention(mask, need_weights, average_attn_weights), None, "aten::_native_multi_head_attention", ie_device, precision, ir_version) diff --git a/tests/layer_tests/pytorch_tests/test_nms.py b/tests/layer_tests/pytorch_tests/test_nms.py index ae09726a23b8f9..b703e98ccaffe9 100644 --- a/tests/layer_tests/pytorch_tests/test_nms.py +++ b/tests/layer_tests/pytorch_tests/test_nms.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest from pytorch_layer_test_class import PytorchLayerTest import numpy as np @@ -35,6 +37,8 @@ def forward(self, boxes, scores): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_nms(self, ie_device, precision, ir_version, boxes_num): self.boxes_num = boxes_num self._test(*self.create_model(), ie_device, precision, ir_version) diff --git a/tests/layer_tests/pytorch_tests/test_norm.py b/tests/layer_tests/pytorch_tests/test_norm.py index aef0a074059950..9422c170401702 100644 --- a/tests/layer_tests/pytorch_tests/test_norm.py +++ b/tests/layer_tests/pytorch_tests/test_norm.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import torch @@ -245,6 +247,8 @@ def forward_out(self, x, y): @pytest.mark.parametrize("dtype", ["float32", "float64", None]) @pytest.mark.parametrize("out", [True, False]) @pytest.mark.parametrize("prim_dtype", [True, False]) + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_linalg_matrix_norm(self, p, dim, keepdim, dtype, out, prim_dtype, ie_device, precision, ir_version): self._test(*self.create_model(p, dim, keepdim, dtype, out, prim_dtype), ie_device, precision, ir_version, diff --git a/tests/layer_tests/pytorch_tests/test_or.py b/tests/layer_tests/pytorch_tests/test_or.py index c6592a11af083f..bde1e61ecce74d 100644 --- a/tests/layer_tests/pytorch_tests/test_or.py +++ b/tests/layer_tests/pytorch_tests/test_or.py @@ -25,4 +25,5 @@ def forward(self, x): @pytest.mark.nightly @pytest.mark.precommit def test_or(self, ie_device, precision, ir_version): - self._test(*self.create_model(), ie_device, precision, ir_version, dynamic_shapes=False, trace_model=True) + self._test(*self.create_model(), ie_device, precision, ir_version, + dynamic_shapes=False, trace_model=True, use_convert_model=True) diff --git a/tests/layer_tests/pytorch_tests/test_pixel_shuffle.py b/tests/layer_tests/pytorch_tests/test_pixel_shuffle.py index 8b71c9f55cc824..4422626ccba956 100644 --- a/tests/layer_tests/pytorch_tests/test_pixel_shuffle.py +++ b/tests/layer_tests/pytorch_tests/test_pixel_shuffle.py @@ -7,7 +7,7 @@ from pytorch_layer_test_class import PytorchLayerTest -class TestOneHot(PytorchLayerTest): +class TestPixelShuffle(PytorchLayerTest): def _prepare_input(self): return (np.random.randn(*self.shape).astype(np.float32),) @@ -15,21 +15,82 @@ def create_model(self, upscale_factor): import torch import torch.nn.functional as F - class aten_one_hot(torch.nn.Module): + class aten_pixel_shuffle(torch.nn.Module): def __init__(self, upscale_factor): - super(aten_one_hot, self).__init__() + super(aten_pixel_shuffle, self).__init__() self.upscale_factor = upscale_factor def forward(self, x): return F.pixel_shuffle(x, self.upscale_factor) - return aten_one_hot(upscale_factor), None, "aten::pixel_shuffle" + return aten_pixel_shuffle(upscale_factor), None, "aten::pixel_shuffle" @pytest.mark.parametrize(("upscale_factor,shape"), [(3, [1, 9, 4, 4]), (2, [1, 2, 3, 8, 4, 4]),]) @pytest.mark.nightly @pytest.mark.precommit - def test_one_hot(self, upscale_factor, shape, ie_device, precision, ir_version): + def test_pixel_shuffle(self, upscale_factor, shape, ie_device, precision, ir_version): self.shape = shape self._test(*self.create_model(upscale_factor), ie_device, precision, ir_version) + + +class TestPixelUnshuffle(PytorchLayerTest): + def _prepare_input(self): + return (np.random.randn(*self.shape).astype(np.float32),) + + def create_model(self, upscale_factor): + import torch + import torch.nn.functional as F + + class aten_pixel_unshuffle(torch.nn.Module): + def __init__(self, upscale_factor): + super(aten_pixel_unshuffle, self).__init__() + self.upscale_factor = upscale_factor + + def forward(self, x): + return F.pixel_unshuffle(x, self.upscale_factor) + + return aten_pixel_unshuffle(upscale_factor), None, "aten::pixel_unshuffle" + + @pytest.mark.parametrize(("upscale_factor,shape"), [(3, [1, 1, 12, 12]), + (2, [1, 2, 3, 2, 8, 8]),]) + @pytest.mark.nightly + @pytest.mark.precommit + def test_pixel_unshuffle(self, upscale_factor, shape, ie_device, precision, ir_version): + self.shape = shape + self._test(*self.create_model(upscale_factor), + ie_device, precision, ir_version) + + +class TestChannelShuffle(PytorchLayerTest): + def _prepare_input(self): + return (np.random.randn(*self.shape).astype(np.float32),) + + def create_model(self, groups): + import torch + import torch.nn.functional as F + + class aten_channel_shuffle(torch.nn.Module): + def __init__(self, upscale_factor): + super(aten_channel_shuffle, self).__init__() + self.upscale_factor = upscale_factor + + def forward(self, x): + return F.channel_shuffle(x, self.upscale_factor) + + return aten_channel_shuffle(groups), None, "aten::channel_shuffle" + + @pytest.mark.parametrize(("groups,shape"), [ + (3, [1, 9, 4, 4]), + (2, [1, 8, 8, 4, 4]), + (4, [4, 4, 2]), + (5, [4, 10, 2, 10, 1, 1]), + (1, [2, 3, 4]) + ]) + @pytest.mark.nightly + @pytest.mark.precommit + def test_channel_shuffle(self, groups, shape, ie_device, precision, ir_version): + self.shape = shape + self._test(*self.create_model(groups), + ie_device, precision, ir_version) diff --git a/tests/layer_tests/pytorch_tests/test_pooling.py b/tests/layer_tests/pytorch_tests/test_pooling.py index bd5e7b5345396c..f54902282ece1b 100644 --- a/tests/layer_tests/pytorch_tests/test_pooling.py +++ b/tests/layer_tests/pytorch_tests/test_pooling.py @@ -1,9 +1,12 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest from pytorch_layer_test_class import PytorchLayerTest +import numpy as np d2_params = [{'kernel_size': [3, 3], 'stride': 1, 'padding': 0}, {'kernel_size': [3, 3], 'stride': [1, 1], 'padding': 1}, @@ -95,13 +98,31 @@ def forward(self, x): return torch.nn.functional.max_pool1d(x, self.kernel_size, self.stride, self.padding, self.dilation, self.ceil_mode) + class aten_max_pool2d_indices(aten_max_pooling_base): + def forward(self, x): + return torch.nn.functional.max_pool2d(x, self.kernel_size, self.stride, self.padding, self.dilation, + self.ceil_mode, return_indices=True) + + class aten_max_pool3d_indices(aten_max_pooling_base): + def forward(self, x): + return torch.nn.functional.max_pool3d(x, self.kernel_size, self.stride, self.padding, self.dilation, + self.ceil_mode, return_indices=True) + + class aten_max_pool1d_indices(aten_max_pooling_base): + def forward(self, x): + return torch.nn.functional.max_pool1d(x, self.kernel_size, self.stride, self.padding, self.dilation, + self.ceil_mode, return_indices=True) + ops = { "max_pool1d": aten_max_pool1d, "max_pool2d": aten_max_pool2d, "max_pool3d": aten_max_pool3d, "avg_pool1d": aten_avg_pool1d, "avg_pool2d": aten_avg_pool2d, - "avg_pool3d": aten_avg_pool3d + "avg_pool3d": aten_avg_pool3d, + "max_pool1d_with_indices": aten_max_pool1d_indices, + "max_pool2d_with_indices": aten_max_pool2d_indices, + "max_pool3d_with_indices": aten_max_pool3d_indices, } ref_net = None @@ -114,6 +135,8 @@ def forward(self, x): @pytest.mark.parametrize("count_include_pad", [True, False]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_avg_pool1d(self, params, ceil_mode, count_include_pad, ie_device, precision, ir_version): self._test(*self.create_model("avg_pool1d", **params, ceil_mode=ceil_mode, count_include_pad=count_include_pad), ie_device, precision, ir_version, kwargs_to_prepare_input={'ndim': 3}, trace_model=True, @@ -132,6 +155,8 @@ def test_avg_pool1d(self, params, ceil_mode, count_include_pad, ie_device, preci @pytest.mark.parametrize("count_include_pad", [True, False]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_avg_pool2d(self, params, ceil_mode, count_include_pad, ie_device, precision, ir_version): self._test(*self.create_model("avg_pool2d", **params, ceil_mode=ceil_mode, count_include_pad=count_include_pad), ie_device, precision, ir_version, trace_model=True, dynamic_shapes=False) @@ -141,6 +166,8 @@ def test_avg_pool2d(self, params, ceil_mode, count_include_pad, ie_device, preci @pytest.mark.parametrize("count_include_pad", [True, False]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_avg_pool3d(self, params, ceil_mode, count_include_pad, ie_device, precision, ir_version): self._test(*self.create_model("avg_pool3d", **params, ceil_mode=ceil_mode, count_include_pad=count_include_pad), ie_device, precision, ir_version, kwargs_to_prepare_input={'ndim': 5}, trace_model=True, @@ -151,6 +178,8 @@ def test_avg_pool3d(self, params, ceil_mode, count_include_pad, ie_device, preci @pytest.mark.parametrize("dilation", [1, 2]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_max_pool1d(self, params, ceil_mode, dilation, ie_device, precision, ir_version): self._test(*self.create_model("max_pool1d", **params, ceil_mode=ceil_mode, dilation=dilation), ie_device, precision, ir_version, kwargs_to_prepare_input={'ndim': 3}, dynamic_shapes=False) @@ -160,7 +189,9 @@ def test_max_pool1d(self, params, ceil_mode, dilation, ie_device, precision, ir_ @pytest.mark.parametrize("dilation", [1, 2]) @pytest.mark.nightly @pytest.mark.precommit - def test_max_pool2d(self, params, ceil_mode, dilation, ie_device, precision, ir_version): + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') + def test_max_pool2d(self, params, ceil_mode, dilation, ie_device, precision, ir_version): to_trace = False if params["stride"] == []: to_trace = True @@ -172,6 +203,50 @@ def test_max_pool2d(self, params, ceil_mode, dilation, ie_device, precision, ir_ @pytest.mark.parametrize("dilation", [1, 2]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_max_pool3d(self, params, ceil_mode, dilation, ie_device, precision, ir_version): self._test(*self.create_model("max_pool3d", **params, ceil_mode=ceil_mode, dilation=dilation), ie_device, precision, ir_version, kwargs_to_prepare_input={'ndim': 5}, dynamic_shapes=False) + + @pytest.mark.parametrize("params", d1_params) + @pytest.mark.parametrize("ceil_mode", [True, False]) + @pytest.mark.parametrize("dilation", [1, 2]) + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') + def test_max_pool1d_indices(self, params, ceil_mode, dilation, ie_device, precision, ir_version): + if ceil_mode and (np.array(params["padding"]).any() != 0): + pytest.skip("ticket 122418") + self._test(*self.create_model("max_pool1d_with_indices", **params, ceil_mode=ceil_mode, dilation=dilation), + ie_device, precision, ir_version, kwargs_to_prepare_input={'ndim': 3}, dynamic_shapes=False) + + @pytest.mark.parametrize("params", d2_params + d2_params_corner_case) + @pytest.mark.parametrize("ceil_mode", [True, False]) + @pytest.mark.parametrize("dilation", [1, 2]) + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') + def test_max_pool2d_indices(self, params, ceil_mode, dilation, ie_device, precision, ir_version): + if ceil_mode and (np.array(params["padding"]).any() != 0): + pytest.skip("ticket 122418") + to_trace = False + if params["stride"] == []: + to_trace = True + self._test(*self.create_model("max_pool2d_with_indices", **params, ceil_mode=ceil_mode, dilation=dilation), + ie_device, precision, ir_version, dynamic_shapes=False, trace_model=to_trace) + + @pytest.mark.parametrize("params", d3_params) + @pytest.mark.parametrize("ceil_mode", [True, False]) + @pytest.mark.parametrize("dilation", [1, 2]) + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') + def test_max_pool3d_indices(self, params, ceil_mode, dilation, ie_device, precision, ir_version): + if ceil_mode and (np.array(params["padding"]).any() != 0): + pytest.skip("ticket 122418") + self._test(*self.create_model("max_pool3d_with_indices", **params, ceil_mode=ceil_mode, dilation=dilation), + ie_device, precision, ir_version, kwargs_to_prepare_input={'ndim': 5}, dynamic_shapes=False) diff --git a/tests/layer_tests/pytorch_tests/test_pow.py b/tests/layer_tests/pytorch_tests/test_pow.py index 9cf6468404e5d3..92e65898e353eb 100644 --- a/tests/layer_tests/pytorch_tests/test_pow.py +++ b/tests/layer_tests/pytorch_tests/test_pow.py @@ -41,7 +41,7 @@ def forward(self, input_data, exponent): @pytest.mark.precommit def test_pow(self, ie_device, precision, ir_version, test_input): self.test_input = test_input - self._test(*self.create_model(), ie_device, precision, ir_version) + self._test(*self.create_model(), ie_device, precision, ir_version, use_convert_model=True) class TestPowMixedTypes(PytorchLayerTest): diff --git a/tests/layer_tests/pytorch_tests/test_quantize.py b/tests/layer_tests/pytorch_tests/test_quantize.py index f1a7522159090e..600821fa16204c 100644 --- a/tests/layer_tests/pytorch_tests/test_quantize.py +++ b/tests/layer_tests/pytorch_tests/test_quantize.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import torch @@ -49,6 +51,8 @@ def _prepare_input(self): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_quantize_per_tensor_dequantize(self, scale, zero_point, dtype, ie_device, precision, ir_version): if dtype == torch.quint8: zero_point = abs(zero_point) self._test(aten_quantize_per_tensor_aten_dequantize(scale, zero_point, dtype), None, ["aten::quantize_per_tensor", "aten::dequantize"], @@ -88,6 +92,8 @@ def _prepare_input(self): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_quantize_per_channel_dequantize(self, scale, zero_point, dtype, axis, ie_device, precision, ir_version): np.random.shuffle(scale), np.random.shuffle(zero_point) if dtype == torch.quint8: zero_point = abs(zero_point) diff --git a/tests/layer_tests/pytorch_tests/test_quantized_add.py b/tests/layer_tests/pytorch_tests/test_quantized_add.py index 960d3b4cca7aef..59a992fc088d5a 100644 --- a/tests/layer_tests/pytorch_tests/test_quantized_add.py +++ b/tests/layer_tests/pytorch_tests/test_quantized_add.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import torch @@ -38,6 +40,8 @@ def _prepare_input(self): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_quantized_add(self, scale, zero_point, dtype, ie_device, precision, ir_version): if dtype == torch.quint8: zero_point = abs(zero_point) self._test(quantized_add(scale, zero_point, dtype), None, ["quantized::add"], diff --git a/tests/layer_tests/pytorch_tests/test_quantized_add_relu.py b/tests/layer_tests/pytorch_tests/test_quantized_add_relu.py index 4a0dd797e3525c..6cb64dfab053d6 100644 --- a/tests/layer_tests/pytorch_tests/test_quantized_add_relu.py +++ b/tests/layer_tests/pytorch_tests/test_quantized_add_relu.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import torch @@ -38,6 +40,8 @@ def _prepare_input(self): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_quantized_add_relu(self, scale, zero_point, dtype, ie_device, precision, ir_version): if dtype == torch.quint8: zero_point = abs(zero_point) self._test(quantized_add_relu(scale, zero_point, dtype), None, ["quantized::add_relu"], diff --git a/tests/layer_tests/pytorch_tests/test_quantized_cat.py b/tests/layer_tests/pytorch_tests/test_quantized_cat.py index db6e5278bb5c50..ce0bc880e78f66 100644 --- a/tests/layer_tests/pytorch_tests/test_quantized_cat.py +++ b/tests/layer_tests/pytorch_tests/test_quantized_cat.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import torch @@ -73,6 +75,8 @@ def _prepare_input(self): @pytest.mark.parametrize("dtype", [torch.quint8, torch.qint8]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_quantized_cat(self, scale, zero_point, dtype, ie_device, precision, ir_version): self._test( aten_quantized_cat(scale, zero_point, dtype), @@ -91,6 +95,8 @@ def test_quantized_cat(self, scale, zero_point, dtype, ie_device, precision, ir_ @pytest.mark.parametrize("dtype", [torch.quint8, torch.qint8]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_append_quantized_cat(self, scale, zero_point, dtype, ie_device, precision, ir_version): self._test( aten_append_quantized_cat(scale, zero_point, dtype), @@ -130,6 +136,8 @@ def test_loop_append_quantized_cat(self, scale, zero_point, dtype, ie_device, pr @pytest.mark.parametrize("dtype", [torch.quint8, torch.qint8]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_add_quantized_cat(self, scale, zero_point, dtype, ie_device, precision, ir_version): self._test( aten_add_quantized_cat(scale, zero_point, dtype), diff --git a/tests/layer_tests/pytorch_tests/test_quantized_convnd.py b/tests/layer_tests/pytorch_tests/test_quantized_convnd.py index cf3ec0142cf46b..bc4ac9e1788b34 100644 --- a/tests/layer_tests/pytorch_tests/test_quantized_convnd.py +++ b/tests/layer_tests/pytorch_tests/test_quantized_convnd.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest import numpy as np import torch @@ -78,6 +80,8 @@ def forward(self, x): @pytest.mark.parametrize("zero_point", [0, 1]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_quantized_conv2d(self, params, bias, relu, scale, zero_point, ie_device, precision, ir_version): self._test( *self.create_model(**params, bias=bias, relu=relu, diff --git a/tests/layer_tests/pytorch_tests/test_quantized_hardswish.py b/tests/layer_tests/pytorch_tests/test_quantized_hardswish.py index a0b40783c4e98d..4508bbcb266ab6 100644 --- a/tests/layer_tests/pytorch_tests/test_quantized_hardswish.py +++ b/tests/layer_tests/pytorch_tests/test_quantized_hardswish.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import torch @@ -36,6 +38,8 @@ def _prepare_input(self): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_quantized_hardswish(self, scale, zero_point, dtype, ie_device, precision, ir_version): if dtype == torch.quint8: zero_point = abs(zero_point) self._test(quantized_hardswish(scale, zero_point, dtype), None, ["quantized::hardswish"], diff --git a/tests/layer_tests/pytorch_tests/test_quantized_linear.py b/tests/layer_tests/pytorch_tests/test_quantized_linear.py index 1ded932f234055..bd89ea48303f25 100644 --- a/tests/layer_tests/pytorch_tests/test_quantized_linear.py +++ b/tests/layer_tests/pytorch_tests/test_quantized_linear.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest import torch import numpy as np @@ -73,6 +75,8 @@ def forward(self, inp): @pytest.mark.parametrize("trace", [True, False]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_quantized_linear(self, params, scale, zero_point, trace, ie_device, precision, ir_version): input_shape = params.get("input_shape") weight_shape = params.get("weight_shape") @@ -84,6 +88,8 @@ def test_quantized_linear(self, params, scale, zero_point, trace, ie_device, pre @pytest.mark.parametrize("inplace", [True, False]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_quantized_hardtanh_linear(self, trace, inplace, ie_device, precision, ir_version): self._test(*self.create_hardtanh_model([10, 9], True, 1, 0.3, inplace), ie_device, precision, ir_version, kwargs_to_prepare_input={"input_shape": [2, 3, 9]}, trace_model=trace, freeze_model=False, quantized_ops=True, quant_size=0.3) diff --git a/tests/layer_tests/pytorch_tests/test_quantized_mul.py b/tests/layer_tests/pytorch_tests/test_quantized_mul.py index cc877daa919b5b..d170d70308b6a5 100644 --- a/tests/layer_tests/pytorch_tests/test_quantized_mul.py +++ b/tests/layer_tests/pytorch_tests/test_quantized_mul.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import torch @@ -38,6 +40,8 @@ def _prepare_input(self): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_quantized_mul(self, scale, zero_point, dtype, ie_device, precision, ir_version): if dtype == torch.quint8: zero_point = abs(zero_point) self._test(quantized_mul(scale, zero_point, dtype), None, ["quantized::mul"], diff --git a/tests/layer_tests/pytorch_tests/test_remainder.py b/tests/layer_tests/pytorch_tests/test_remainder.py index 4a499e85a37870..05ad2d3b1387fe 100644 --- a/tests/layer_tests/pytorch_tests/test_remainder.py +++ b/tests/layer_tests/pytorch_tests/test_remainder.py @@ -32,7 +32,7 @@ def forward(self, lhs, rhs): @pytest.mark.precommit def test_remainder(self, ie_device, precision, ir_version, input_rhs): self.input_rhs = input_rhs - self._test(*self.create_model(), ie_device, precision, ir_version) + self._test(*self.create_model(), ie_device, precision, ir_version, use_convert_model=True) class TestRemainderTypes(PytorchLayerTest): diff --git a/tests/layer_tests/pytorch_tests/test_repeat.py b/tests/layer_tests/pytorch_tests/test_repeat.py index 45263366c76c54..884a51e2a24f6f 100644 --- a/tests/layer_tests/pytorch_tests/test_repeat.py +++ b/tests/layer_tests/pytorch_tests/test_repeat.py @@ -77,4 +77,4 @@ def forward(self, x): @pytest.mark.nightly @pytest.mark.precommit def test_repeat_t5(self, ie_device, precision, ir_version): - self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=True) + self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=True, use_convert_model=True) diff --git a/tests/layer_tests/pytorch_tests/test_rfftn_complex_transforms.py b/tests/layer_tests/pytorch_tests/test_rfftn_complex_transforms.py index 7e3dd169e5bc02..a871bbc46fd75f 100644 --- a/tests/layer_tests/pytorch_tests/test_rfftn_complex_transforms.py +++ b/tests/layer_tests/pytorch_tests/test_rfftn_complex_transforms.py @@ -1,9 +1,12 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +from sys import platform + import numpy as np import pytest import torch + from pytorch_layer_test_class import PytorchLayerTest @@ -40,7 +43,9 @@ def forward(self, x): @pytest.mark.parametrize("norm", ["forward", "backward", "ortho", None]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.skipif(platform == 'darwin', reason="Ticket - 122182") def test_rfftn(self, ie_device, precision, ir_version, input_shape, dim, s, norm): self.input_shape = input_shape # Unfrozen test would fail due to issues with prim::GetAttr containing lists, strings or none. - self._test(*self.create_model(dim, s, norm), ie_device, precision, ir_version, custom_eps=1e-3, freeze_model=True) + self._test(*self.create_model(dim, s, norm), ie_device, precision, ir_version, custom_eps=1e-3, + freeze_model=True) diff --git a/tests/layer_tests/pytorch_tests/test_rsub.py b/tests/layer_tests/pytorch_tests/test_rsub.py index 64c4b9619d7b73..9c144ad4da247b 100644 --- a/tests/layer_tests/pytorch_tests/test_rsub.py +++ b/tests/layer_tests/pytorch_tests/test_rsub.py @@ -40,9 +40,9 @@ def forward(self, x, y:int, alpha: float): @pytest.mark.nightly @pytest.mark.precommit - def test_rsub(self, ie_device, precision, ir_version, input_data): + def test_rsub_f(self, ie_device, precision, ir_version, input_data): self.input_data = input_data - self._test(*self.create_model(second_type="float"), ie_device, precision, ir_version) + self._test(*self.create_model(second_type="float"), ie_device, precision, ir_version, use_convert_model=True) @pytest.mark.parametrize('input_data', [(np.random.randn(2, 3, 4).astype(np.float32), np.array(5).astype(int), @@ -50,9 +50,9 @@ def test_rsub(self, ie_device, precision, ir_version, input_data): @pytest.mark.nightly @pytest.mark.precommit - def test_rsub(self, ie_device, precision, ir_version, input_data): + def test_rsub_i(self, ie_device, precision, ir_version, input_data): self.input_data = input_data - self._test(*self.create_model(second_type="int"), ie_device, precision, ir_version) + self._test(*self.create_model(second_type="int"), ie_device, precision, ir_version, use_convert_model=True) class TestRsubTypes(PytorchLayerTest): diff --git a/tests/layer_tests/pytorch_tests/test_scaled_dot_product_attention.py b/tests/layer_tests/pytorch_tests/test_scaled_dot_product_attention.py index 22ed325471823b..69c600a0b7562d 100644 --- a/tests/layer_tests/pytorch_tests/test_scaled_dot_product_attention.py +++ b/tests/layer_tests/pytorch_tests/test_scaled_dot_product_attention.py @@ -36,6 +36,7 @@ def forward(self, query, key, value): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_fx_backend @pytest.mark.parametrize(['mask', "is_causal"], [(False, False), (False, True), (True, True), (True, False)]) def test_scaled_dot_product_atten(self, ie_device, precision, ir_version, mask, is_causal): self._test(*self.create_model(mask, is_causal),ie_device, precision, ir_version) diff --git a/tests/layer_tests/pytorch_tests/test_strided_const.py b/tests/layer_tests/pytorch_tests/test_strided_const.py index 438edbc88e24fe..ab33e92f88b4b8 100644 --- a/tests/layer_tests/pytorch_tests/test_strided_const.py +++ b/tests/layer_tests/pytorch_tests/test_strided_const.py @@ -31,4 +31,4 @@ def forward(self, x): @pytest.mark.nightly @pytest.mark.precommit def test_strides(self, ie_device, precision, ir_version): - self._test(*self.create_model(), ie_device, precision, ir_version) + self._test(*self.create_model(), ie_device, precision, ir_version, use_convert_model=True) diff --git a/tests/layer_tests/pytorch_tests/test_sub.py b/tests/layer_tests/pytorch_tests/test_sub.py index aa97b0f23653fb..381d1672454cbe 100644 --- a/tests/layer_tests/pytorch_tests/test_sub.py +++ b/tests/layer_tests/pytorch_tests/test_sub.py @@ -50,7 +50,7 @@ def _forward_inplace(self, x, y, alpha: float): @pytest.mark.precommit def test_sub(self, ie_device, precision, ir_version, input_data, inplace): self.input_data = input_data - self._test(*self.create_model(inplace), ie_device, precision, ir_version) + self._test(*self.create_model(inplace), ie_device, precision, ir_version, use_convert_model=True) class TestSubTypes(PytorchLayerTest): diff --git a/tests/layer_tests/pytorch_tests/test_transpose.py b/tests/layer_tests/pytorch_tests/test_transpose.py index b3378761da8c74..5dec55ec59c597 100644 --- a/tests/layer_tests/pytorch_tests/test_transpose.py +++ b/tests/layer_tests/pytorch_tests/test_transpose.py @@ -91,4 +91,5 @@ def test_t_small(self, num_dims, input_dtype, mode, ie_device, precision, ir_ver precision, ir_version, kwargs_to_prepare_input={"num_dims": num_dims, "input_dtype": input_dtype}, + use_convert_model=True, ) diff --git a/tests/layer_tests/pytorch_tests/test_tuple_construct.py b/tests/layer_tests/pytorch_tests/test_tuple_construct.py index 1582df48c4b370..45413a940f132b 100644 --- a/tests/layer_tests/pytorch_tests/test_tuple_construct.py +++ b/tests/layer_tests/pytorch_tests/test_tuple_construct.py @@ -60,7 +60,7 @@ def forward(self, x): @pytest.mark.parametrize("case", ["single", "multiple", "none", "list", "tensor_tail", "list_and_tuple"]) @pytest.mark.nightly def test_tuple_construct(self, case, ie_device, precision, ir_version): - self._test(*self.create_model(case), ie_device, precision, ir_version) + self._test(*self.create_model(case), ie_device, precision, ir_version, use_convert_model=True) class TestTupleConstructTupleUnpack(PytorchLayerTest): @@ -86,7 +86,7 @@ def prepare_input(self, x): @pytest.mark.nightly def test_tuple_construct_unpack(self, ie_device, precision, ir_version): self._test(*self.create_model(), ie_device, - precision, ir_version, freeze_model=False) + precision, ir_version, freeze_model=False, use_convert_model=True) class TestTupleUnpackParameterSingle(PytorchLayerTest): @@ -208,7 +208,7 @@ def some_func(self, x: Tuple[torch.Tensor, torch.Tensor]): @pytest.mark.nightly def test(self, ie_device, precision, ir_version): self._test(*self.create_model(), ie_device, precision, - ir_version, trace_model=False, freeze_model=False) + ir_version, trace_model=False, freeze_model=False, use_convert_model=True) class TestTcOutsideTuInsideIfBody(PytorchLayerTest): @@ -236,4 +236,4 @@ def some_func(self, x: Tuple[torch.Tensor, torch.Tensor]): @pytest.mark.nightly def test(self, ie_device, precision, ir_version): self._test(*self.create_model(), ie_device, precision, - ir_version, trace_model=False, freeze_model=False) + ir_version, trace_model=False, freeze_model=False, use_convert_model=True) diff --git a/tests/layer_tests/pytorch_tests/test_upsample.py b/tests/layer_tests/pytorch_tests/test_upsample.py index cc862ee6cb5053..7406302ef5d7fe 100644 --- a/tests/layer_tests/pytorch_tests/test_upsample.py +++ b/tests/layer_tests/pytorch_tests/test_upsample.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +from sys import platform + import pytest from pytorch_layer_test_class import PytorchLayerTest @@ -41,6 +43,7 @@ def forward(self, x): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.skipif(platform == 'darwin', reason="Ticket - 122182") def test_upsample1d(self, mode, size, scale, ie_device, precision, ir_version): self._test(*self.create_model(size, scale, mode), ie_device, precision, ir_version, trace_model=True) @@ -96,7 +99,6 @@ def test_upsample2d(self, mode, size, scale, ie_device, precision, ir_version): precision, ir_version, trace_model=True, **{"custom_eps": 1e-3}) - class TestUpsample2DAntialias(PytorchLayerTest): def _prepare_input(self): import numpy as np diff --git a/tests/layer_tests/pytorch_tests/test_var_mean.py b/tests/layer_tests/pytorch_tests/test_var_mean.py index 6ce85988e9edfb..bd8a5a10617eb4 100644 --- a/tests/layer_tests/pytorch_tests/test_var_mean.py +++ b/tests/layer_tests/pytorch_tests/test_var_mean.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest from pytorch_layer_test_class import PytorchLayerTest @@ -52,6 +54,8 @@ def forward(self, x): @pytest.mark.precommit @pytest.mark.parametrize("unbiased", [True, False]) @pytest.mark.parametrize("op_type", ["var", "var_mean", "std", "std_mean"]) + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_var2args(self, unbiased, op_type, ie_device, precision, ir_version): self._test(*self.create_model(unbiased, op_type=op_type), ie_device, precision, ir_version) @@ -61,5 +65,7 @@ def test_var2args(self, unbiased, op_type, ie_device, precision, ir_version): @pytest.mark.parametrize("dim", [None, 0, 1, 2, 3, -1, -2, (0, 1), (-1, -2), (0, 1, -1), (0, 1, 2, 3)]) @pytest.mark.parametrize("keepdim", [True, False]) @pytest.mark.parametrize("op_type", ["var", "var_mean", "std", "std_mean"]) + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122715') def test_var(self, unbiased, dim, keepdim, op_type, ie_device, precision, ir_version): self._test(*self.create_model(unbiased, dim, keepdim, two_args_case=False, op_type=op_type), ie_device, precision, ir_version) \ No newline at end of file diff --git a/tests/layer_tests/requirements.txt b/tests/layer_tests/requirements.txt index b1b76c54b92abe..fd15d8bf32405d 100644 --- a/tests/layer_tests/requirements.txt +++ b/tests/layer_tests/requirements.txt @@ -1,6 +1,7 @@ -c ../constraints.txt # paddlepaddle # ticket 95904 numpy +onnxruntime requests torch torchvision diff --git a/tests/layer_tests/tensorflow_lite_tests/test_tfl_BroadcastTo.py b/tests/layer_tests/tensorflow_lite_tests/test_tfl_BroadcastTo.py index bae3f51ce97ff0..6f3eb1b70ed2f2 100644 --- a/tests/layer_tests/tensorflow_lite_tests/test_tfl_BroadcastTo.py +++ b/tests/layer_tests/tensorflow_lite_tests/test_tfl_BroadcastTo.py @@ -1,3 +1,5 @@ +import platform + import pytest import tensorflow as tf @@ -29,5 +31,7 @@ def make_model(self, params): @pytest.mark.parametrize("params", test_params) @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 123324') def test_broadcast_to(self, params, ie_device, precision, temp_dir): self._test(ie_device, precision, temp_dir, params) diff --git a/tests/layer_tests/tensorflow_lite_tests/test_tfl_FullyConnected.py b/tests/layer_tests/tensorflow_lite_tests/test_tfl_FullyConnected.py index a8119813dd4304..67f0e699eb2963 100644 --- a/tests/layer_tests/tensorflow_lite_tests/test_tfl_FullyConnected.py +++ b/tests/layer_tests/tensorflow_lite_tests/test_tfl_FullyConnected.py @@ -13,7 +13,7 @@ class TestTFLiteFullyConnectedLayerTest(TFLiteLayerTest): inputs = ["Input_x", "Input_y"] outputs = ["FullyConnected"] - allowed_ops = ['FULLY_CONNECTED'] + allowed_ops = (['FULLY_CONNECTED'], ['BATCH_MATMUL']) def make_model(self, params): assert len(set(params.keys()).intersection({'shape_x', 'shape_y'})) == 2, \ diff --git a/tests/layer_tests/tensorflow_lite_tests/test_tfl_RFFT2D.py b/tests/layer_tests/tensorflow_lite_tests/test_tfl_RFFT2D.py index b534878970ac59..1ae3464c207b34 100644 --- a/tests/layer_tests/tensorflow_lite_tests/test_tfl_RFFT2D.py +++ b/tests/layer_tests/tensorflow_lite_tests/test_tfl_RFFT2D.py @@ -1,3 +1,5 @@ +import platform + import pytest import tensorflow as tf @@ -30,5 +32,7 @@ def make_model(self, params): @pytest.mark.parametrize("params", test_params) @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 123324') def test_rfft2d(self, params, ie_device, precision, temp_dir): self._test(ie_device, precision, temp_dir, params) diff --git a/tests/layer_tests/tensorflow_lite_tests/test_tfl_ScatterND.py b/tests/layer_tests/tensorflow_lite_tests/test_tfl_ScatterND.py index d2393dc4aa5c13..77720238b1feb3 100644 --- a/tests/layer_tests/tensorflow_lite_tests/test_tfl_ScatterND.py +++ b/tests/layer_tests/tensorflow_lite_tests/test_tfl_ScatterND.py @@ -13,7 +13,7 @@ 'shape_shape': [1], 'shape_value': [8]}, {'indices_shape': [4, 1], 'indices_value': [4, 3, 1, 7], 'updates_dtype': np.float32, 'updates_shape': [4], 'shape_shape': [1], 'shape_value': [8]}, - {'indices_shape': [4, 1], 'indices_value': [4, 3, 1, 7], 'updates_dtype': np.bool, 'updates_shape': [4], + {'indices_shape': [4, 1], 'indices_value': [4, 3, 1, 7], 'updates_dtype': bool, 'updates_shape': [4], 'shape_shape': [1], 'shape_value': [8]}, {'indices_shape': [4, 2], 'indices_value': [[0, 0], [1, 0], [0, 2], [1, 2]], 'updates_dtype': np.int32, @@ -22,7 +22,7 @@ 'updates_shape': [4, 5], 'shape_shape': [3], 'shape_value': [2, 3, 5]}, {'indices_shape': [4, 2], 'indices_value': [[0, 0], [1, 0], [0, 2], [1, 2]], 'updates_dtype': np.float32, 'updates_shape': [4, 5], 'shape_shape': [3], 'shape_value': [2, 3, 5]}, - {'indices_shape': [4, 2], 'indices_value': [[0, 0], [1, 0], [0, 2], [1, 2]], 'updates_dtype': np.bool, + {'indices_shape': [4, 2], 'indices_value': [[0, 0], [1, 0], [0, 2], [1, 2]], 'updates_dtype': bool, 'updates_shape': [4, 5], 'shape_shape': [3], 'shape_value': [2, 3, 5]}, ] diff --git a/tests/layer_tests/tensorflow_lite_tests/test_tfl_SegmentSum.py b/tests/layer_tests/tensorflow_lite_tests/test_tfl_SegmentSum.py index a5ce2d314aee0b..c7339efaf7f55e 100644 --- a/tests/layer_tests/tensorflow_lite_tests/test_tfl_SegmentSum.py +++ b/tests/layer_tests/tensorflow_lite_tests/test_tfl_SegmentSum.py @@ -1,3 +1,5 @@ +import platform + import pytest import tensorflow as tf @@ -40,5 +42,7 @@ def make_model(self, params): @pytest.mark.parametrize("params", test_params) @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 123324') def test_segment_sum(self, params, ie_device, precision, temp_dir): self._test(ie_device, precision, temp_dir, params) diff --git a/tests/layer_tests/tensorflow_lite_tests/test_tfl_StridedSlice.py b/tests/layer_tests/tensorflow_lite_tests/test_tfl_StridedSlice.py index fea9364b045651..12c18d02077e2a 100644 --- a/tests/layer_tests/tensorflow_lite_tests/test_tfl_StridedSlice.py +++ b/tests/layer_tests/tensorflow_lite_tests/test_tfl_StridedSlice.py @@ -13,7 +13,7 @@ 'begin_mask': 8, 'end_mask': 3, 'shrink_axis_mask': 4}, {'shape': [12, 2, 2, 5], 'dtype': np.int64, 'strides': [1], 'begin': [0], 'end': [1], 'begin_mask': 8, 'end_mask': 3, 'shrink_axis_mask': None}, - {'shape': [12, 2, 2, 5], 'dtype': np.bool, 'strides': [1], 'begin': [0], 'end': [1], + {'shape': [12, 2, 2, 5], 'dtype': bool, 'strides': [1], 'begin': [0], 'end': [1], 'begin_mask': 8, 'end_mask': 3, 'shrink_axis_mask': None}, ] @@ -24,7 +24,7 @@ class TestTFLiteStridedSliceLayerTest(TFLiteLayerTest): allowed_ops = ['STRIDED_SLICE'] def _prepare_input(self, inputs_dict, generator=None): - if self.input_dtype == np.bool: + if self.input_dtype == bool: inputs_dict['Input'] = np.random.choice([True, False], size=inputs_dict['Input']) else: inputs_dict['Input'] = np.random.randint(-255, 255, inputs_dict['Input']).astype(self.input_dtype) diff --git a/tests/layer_tests/tensorflow_tests/test_tf_AdjustContrastv2.py b/tests/layer_tests/tensorflow_tests/test_tf_AdjustContrastv2.py index 88944c50a38091..896e1789111eaa 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_AdjustContrastv2.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_AdjustContrastv2.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import tensorflow as tf @@ -38,6 +40,8 @@ def create_adjust_contrast_net(self, input_shape, input_type): @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_adjust_contrast_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_adjust_contrast_net(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_BinaryOps.py b/tests/layer_tests/tensorflow_tests/test_tf_BinaryOps.py index 62689f5609cc12..7e3964e68c9c35 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_BinaryOps.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_BinaryOps.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest @@ -126,6 +128,8 @@ def create_add_placeholder_const_net(self, x_shape, y_shape, ir_version, op_type 'Xdivy']) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_binary_op(self, params, ie_device, precision, ir_version, temp_dir, op_type, use_new_frontend, use_old_api): if precision == "FP16": diff --git a/tests/layer_tests/tensorflow_tests/test_tf_Bucketize.py b/tests/layer_tests/tensorflow_tests/test_tf_Bucketize.py index d981b2997542b5..8ab60f9ac65beb 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_Bucketize.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_Bucketize.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import tensorflow as tf @@ -40,6 +42,8 @@ def create_bucketize_net(self, input_shape, input_type, boundaries_size): @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_bucketize_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_bucketize_net(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_CTCLoss.py b/tests/layer_tests/tensorflow_tests/test_tf_CTCLoss.py index 78289a7144ba7a..0a2eae6303386e 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_CTCLoss.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_CTCLoss.py @@ -1,6 +1,8 @@ # Copyright (C) 2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +from sys import platform + import numpy as np import pytest import tensorflow as tf @@ -54,6 +56,7 @@ def create_ctcloss_placeholder_const_net(self, inputs, targets): @pytest.mark.parametrize("params", test_data) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.skipif(platform == 'darwin', reason="Ticket - 122182") def test_ctcloss_placeholder_const(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_ctcloss_placeholder_const_net(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_CropAndResize.py b/tests/layer_tests/tensorflow_tests/test_tf_CropAndResize.py index 92ef18ff5aba98..30cefc07c942d2 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_CropAndResize.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_CropAndResize.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import tensorflow as tf @@ -53,6 +55,8 @@ def create_crop_and_resize_net(self, image_shape, num_boxes, crop_size_value, me @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_crop_and_resize_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_crop_and_resize_net(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_DivNoNan.py b/tests/layer_tests/tensorflow_tests/test_tf_DivNoNan.py index 58db73ece154e1..5a6f3883185f23 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_DivNoNan.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_DivNoNan.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import tensorflow as tf @@ -41,6 +43,8 @@ def create_div_no_nan_net(self, input_shape, input_type): @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_div_no_nan_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_div_no_nan_net(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_FakeQuantWithMinMaxVars.py b/tests/layer_tests/tensorflow_tests/test_tf_FakeQuantWithMinMaxVars.py index 43d8da8e38019d..191b46e035a376 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_FakeQuantWithMinMaxVars.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_FakeQuantWithMinMaxVars.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import tensorflow as tf @@ -42,6 +44,8 @@ def create_fake_quant_with_min_max_vars_net(self, inputs_shape, min_value, max_v ]) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_fake_quant_with_min_max_vars_basic(self, params, fake_quant_op, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): diff --git a/tests/layer_tests/tensorflow_tests/test_tf_FusedBatchNorm.py b/tests/layer_tests/tensorflow_tests/test_tf_FusedBatchNorm.py index 94ae7dc628270d..b2d44b5a07beb9 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_FusedBatchNorm.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_FusedBatchNorm.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +from sys import platform + import numpy as np import pytest import tensorflow as tf @@ -102,6 +104,7 @@ def create_fused_batch_norm_net(self, x_shape, epsilon, exponential_avg_factor, @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.skipif(platform == 'darwin', reason="Ticket - 122182") def test_fused_batch_norm_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_fused_batch_norm_net(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_If.py b/tests/layer_tests/tensorflow_tests/test_tf_If.py index 0e4e7a6fb249e5..20085e6ac86672 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_If.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_If.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import tensorflow as tf @@ -67,6 +69,8 @@ def else_branch(): @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_if_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): if ie_device == 'GPU': @@ -137,6 +141,8 @@ def else_branch(): @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_if_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): if ie_device == 'GPU': @@ -215,6 +221,8 @@ def else_branch(): @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_if_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): if ie_device == 'GPU': @@ -305,6 +313,8 @@ def else_branch(): @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_if_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): if ie_device == 'GPU': diff --git a/tests/layer_tests/tensorflow_tests/test_tf_LeakyRelu.py b/tests/layer_tests/tensorflow_tests/test_tf_LeakyRelu.py index 1504ae706a9b19..ea672ac144d987 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_LeakyRelu.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_LeakyRelu.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest import tensorflow as tf from common.tf_layer_test_class import CommonTFLayerTest @@ -31,6 +33,8 @@ def create_leaky_relu_net(self, x_shape, alpha_value): @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_leaky_relu_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_leaky_relu_net(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_LinSpace.py b/tests/layer_tests/tensorflow_tests/test_tf_LinSpace.py index c696eaaa0355e5..216fe7b7816de4 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_LinSpace.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_LinSpace.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest import tensorflow as tf from common.tf_layer_test_class import CommonTFLayerTest @@ -28,6 +30,8 @@ def create_lin_space_net(self, num_value): @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_lin_space_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_lin_space_net(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_LogSoftmax.py b/tests/layer_tests/tensorflow_tests/test_tf_LogSoftmax.py index bef52905aa3159..063e310dd8174a 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_LogSoftmax.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_LogSoftmax.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import tensorflow as tf @@ -39,6 +41,8 @@ def create_log_softmax_net(self, logits_shape): @pytest.mark.precommit @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_log_softmax_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_log_softmax_net(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_MatMul.py b/tests/layer_tests/tensorflow_tests/test_tf_MatMul.py index 460afb662851e7..2a93291af28230 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_MatMul.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_MatMul.py @@ -36,7 +36,7 @@ def create_net_with_matmul_op(self, x_shape, y_shape, x_bool, y_bool, op_type, i elif op_type == 'BatchMatMulV3': op_type_to_tf[op_type](x=tf_x, y=tf_y, Tout=tf.float32, adj_x=x_bool, adj_y=y_bool, name='Operation') else: - raise RuntimeError("Undknown operation") + raise RuntimeError("Unknown operation") tf.compat.v1.global_variables_initializer() tf_net = sess.graph_def @@ -53,7 +53,7 @@ def create_net_with_matmul_op(self, x_shape, y_shape, x_bool, y_bool, op_type, i @pytest.mark.parametrize("params", test_data_precommit) @pytest.mark.parametrize("op_type", ['BatchMatMul', 'BatchMatMulV2', - #'BatchMatMulV3', #Isn't supported + 'BatchMatMulV3', 'MatMul', ]) @pytest.mark.precommit_tf_fe @@ -72,7 +72,7 @@ def test_matmul_op_precommit(self, params, ie_device, precision, ir_version, tem @pytest.mark.parametrize("params", test_data) @pytest.mark.parametrize("op_type", ['BatchMatMul', 'BatchMatMulV2', - #'BatchMatMulV3', #Isn't supported + 'BatchMatMulV3', 'MatMul', ]) @pytest.mark.parametrize("x_bool", [ diff --git a/tests/layer_tests/tensorflow_tests/test_tf_MaxPoolWithArgmax.py b/tests/layer_tests/tensorflow_tests/test_tf_MaxPoolWithArgmax.py index 4d1fed5747ba11..f08995f3c09d11 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_MaxPoolWithArgmax.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_MaxPoolWithArgmax.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import tensorflow as tf @@ -59,6 +61,8 @@ def create_max_pool_with_argmax_net(self, input_shape, ksize, strides, input_typ ]) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_max_pool_with_argmax_basic(self, params, input_type, padding, targmax, include_batch_in_index, with_second_output, ie_device, precision, ir_version, temp_dir, diff --git a/tests/layer_tests/tensorflow_tests/test_tf_NormalizeL2.py b/tests/layer_tests/tensorflow_tests/test_tf_NormalizeL2.py index 51a1b322af6541..5de76778d1d837 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_NormalizeL2.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_NormalizeL2.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest from common.tf_layer_test_class import CommonTFLayerTest @@ -30,6 +32,8 @@ def create_normalize_l2_net(shape, axes): @pytest.mark.precommit @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_normalize_l2_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_normalize_l2_net(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_OnesLike.py b/tests/layer_tests/tensorflow_tests/test_tf_OnesLike.py new file mode 100644 index 00000000000000..71b146edc9c335 --- /dev/null +++ b/tests/layer_tests/tensorflow_tests/test_tf_OnesLike.py @@ -0,0 +1,45 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np +import pytest +import tensorflow as tf +from common.tf_layer_test_class import CommonTFLayerTest + + +class TestOnesLike(CommonTFLayerTest): + def _prepare_input(self, inputs_info): + assert 'x' in inputs_info + x_shape = inputs_info['x'] + inputs_data = {} + rng = np.random.default_rng() + inputs_data['x'] = rng.integers(-10, 10, x_shape).astype(self.x_type) + return inputs_data + + def create_ones_like_net(self, x_shape, x_type): + self.x_type = x_type + tf.compat.v1.reset_default_graph() + # Create the graph and model + with tf.compat.v1.Session() as sess: + x = tf.compat.v1.placeholder(tf.dtypes.as_dtype(x_type), x_shape, 'x') + tf.raw_ops.OnesLike(x=x) + tf.compat.v1.global_variables_initializer() + tf_net = sess.graph_def + + return tf_net, None + + test_data_basic = [ + dict(x_shape=[], x_type=np.float32), + dict(x_shape=[2], x_type=np.int32), + dict(x_shape=[2, 3, 4], x_type=np.float32), + dict(x_shape=[1, 4, 3, 1], x_type=np.int32), + ] + + @pytest.mark.parametrize("params", test_data_basic) + @pytest.mark.precommit_tf_fe + @pytest.mark.nightly + def test_ones_like(self, params, ie_device, precision, ir_version, temp_dir, + use_new_frontend, use_old_api): + self._test(*self.create_ones_like_net(**params), + ie_device, precision, ir_version, temp_dir=temp_dir, + use_new_frontend=use_new_frontend, use_old_api=use_old_api) diff --git a/tests/layer_tests/tensorflow_tests/test_tf_Pooling.py b/tests/layer_tests/tensorflow_tests/test_tf_Pooling.py index eb3ac133b3687d..7c523740d79f96 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_Pooling.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_Pooling.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest from common.layer_test_class import check_ir_version from common.tf_layer_test_class import CommonTFLayerTest @@ -145,6 +147,8 @@ def create_pooling_net(self, kernel_size, strides, pads, in_shape, out_shape, me @pytest.mark.parametrize("params", test_data_4D) @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_pool_4D(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_pooling_net(**params, ir_version=ir_version, @@ -227,6 +231,8 @@ def test_pool_4D(self, params, ie_device, precision, ir_version, temp_dir, use_n @pytest.mark.parametrize("params", test_data_5D) @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_pool_5D(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): if ie_device == 'GPU': diff --git a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py index 0006afd9ab9eca..1f5f778db3ac2f 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest import tensorflow as tf from common.layer_test_class import check_ir_version @@ -88,6 +90,8 @@ def create_tf_random_uniform_net(self, global_seed, op_seed, x_shape, min_val, m @pytest.mark.nightly @pytest.mark.precommit @pytest.mark.precommit_tf_fe + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_random_uniform_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): if ie_device == 'GPU': diff --git a/tests/layer_tests/tensorflow_tests/test_tf_Resize.py b/tests/layer_tests/tensorflow_tests/test_tf_Resize.py index 184a8115772128..c62492c7a76196 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_Resize.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_Resize.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import tensorflow as tf @@ -60,6 +62,8 @@ def create_resize_net(self, images_shape, images_type, size_value, align_corners @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_resize_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_resize_net(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_ScatterND.py b/tests/layer_tests/tensorflow_tests/test_tf_ScatterND.py index dac986b96c281e..26ddcfdd53bcc2 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_ScatterND.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_ScatterND.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest from common.tf_layer_test_class import CommonTFLayerTest @@ -69,6 +71,8 @@ def create_tf_scatternd_placeholder_const_net(self, x_shape, indices, updates, i @pytest.mark.parametrize("params", test_data) @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_tf_scatter_nd(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_tf_scatternd_placeholder_const_net(**params, ir_version=ir_version, diff --git a/tests/layer_tests/tensorflow_tests/test_tf_SegmentSum.py b/tests/layer_tests/tensorflow_tests/test_tf_SegmentSum.py index 5d74c361f51c20..f0f99d4b9cf95f 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_SegmentSum.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_SegmentSum.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import tensorflow as tf @@ -41,6 +43,8 @@ def create_segment_sum_net(self, data_shape, segment_ids_shape, data_type, segme @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_segment_sum_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): if not use_new_frontend: diff --git a/tests/layer_tests/tensorflow_tests/test_tf_Softmax.py b/tests/layer_tests/tensorflow_tests/test_tf_Softmax.py index fc9391feaae3e8..574fe3d32949f7 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_Softmax.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_Softmax.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import tensorflow as tf @@ -34,6 +36,8 @@ def create_softmax_net(self, input_shape): @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_softmax_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_softmax_net(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_SpaceToBatch.py b/tests/layer_tests/tensorflow_tests/test_tf_SpaceToBatch.py index b0f24322b01041..03e83dc39e9c8d 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_SpaceToBatch.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_SpaceToBatch.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import pytest from common.tf_layer_test_class import CommonTFLayerTest @@ -33,6 +35,8 @@ def create_space_to_batch_net(self, in_shape, pads_value, block_shape_value): @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_space_to_batch_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_space_to_batch_net(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_TensorArrayOps.py b/tests/layer_tests/tensorflow_tests/test_tf_TensorArrayOps.py new file mode 100644 index 00000000000000..098f099f74d24d --- /dev/null +++ b/tests/layer_tests/tensorflow_tests/test_tf_TensorArrayOps.py @@ -0,0 +1,200 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np +import pytest +import tensorflow as tf +from common.tf_layer_test_class import CommonTFLayerTest + + +def create_tensor_array(data_shape, data_type): + size = data_shape[0] + data = tf.compat.v1.placeholder(data_type, data_shape, 'data') + indices = tf.compat.v1.placeholder(tf.int32, [size], 'indices') + size_const = tf.constant(size, dtype=tf.int32, shape=[]) + handle, flow = tf.raw_ops.TensorArrayV3(size=size_const, dtype=tf.as_dtype(data_type)) + flow = tf.raw_ops.TensorArrayScatterV3(handle=handle, indices=indices, value=data, flow_in=flow) + return handle, flow + + +class TestTensorArraySizeV3(CommonTFLayerTest): + def _prepare_input(self, inputs_info): + assert 'data' in inputs_info + assert 'indices' in inputs_info + data_shape = inputs_info['data'] + inputs_data = {} + rng = np.random.default_rng() + inputs_data['data'] = rng.integers(-10, 10, data_shape).astype(self.data_type) + inputs_data['indices'] = rng.permutation(self.size).astype(np.int32) + return inputs_data + + def create_tensor_array_size_v3(self, data_shape, data_type): + size = data_shape[0] + self.data_type = data_type + self.size = size + tf.compat.v1.reset_default_graph() + # Create the graph and model + with tf.compat.v1.Session() as sess: + handle, flow = create_tensor_array(data_shape, data_type) + tf.raw_ops.TensorArraySizeV3(handle=handle, flow_in=flow) + tf.raw_ops.TensorArrayCloseV3(handle=handle) + tf.compat.v1.global_variables_initializer() + tf_net = sess.graph_def + + return tf_net, None + + test_data_basic = [ + dict(data_shape=[5], data_type=np.float32), + dict(data_shape=[10, 20, 30], data_type=np.int32), + ] + + @pytest.mark.parametrize("params", test_data_basic) + @pytest.mark.precommit_tf_fe + @pytest.mark.nightly + def test_tensor_array_size_v3(self, params, ie_device, precision, ir_version, temp_dir, + use_new_frontend, use_old_api): + self._test(*self.create_tensor_array_size_v3(**params), + ie_device, precision, ir_version, temp_dir=temp_dir, + use_new_frontend=use_new_frontend, use_old_api=use_old_api) + + +class TestTensorArrayReadV3(CommonTFLayerTest): + def _prepare_input(self, inputs_info): + assert 'data' in inputs_info + assert 'indices' in inputs_info + data_shape = inputs_info['data'] + inputs_data = {} + rng = np.random.default_rng() + inputs_data['data'] = rng.integers(-10, 10, data_shape).astype(self.data_type) + inputs_data['index_to_read'] = rng.integers(0, data_shape[0], []).astype(np.int32) + inputs_data['indices'] = rng.permutation(self.size).astype(np.int32) + return inputs_data + + def create_tensor_array_read_v3(self, data_shape, data_type): + size = data_shape[0] + self.data_type = data_type + self.size = size + tf.compat.v1.reset_default_graph() + # Create the graph and model + with tf.compat.v1.Session() as sess: + handle, flow = create_tensor_array(data_shape, data_type) + index_to_read = tf.compat.v1.placeholder(tf.int32, [], 'index_to_read') + tf.raw_ops.TensorArrayReadV3(handle=handle, index=index_to_read, flow_in=flow, + dtype=tf.dtypes.as_dtype(data_type)) + tf.raw_ops.TensorArrayCloseV3(handle=handle) + tf.compat.v1.global_variables_initializer() + tf_net = sess.graph_def + + return tf_net, None + + test_data_basic = [ + dict(data_shape=[6], data_type=np.float32), + dict(data_shape=[8, 5, 6, 10], data_type=np.int32), + ] + + @pytest.mark.parametrize("params", test_data_basic) + @pytest.mark.precommit_tf_fe + @pytest.mark.nightly + def test_tensor_array_read_v3(self, params, ie_device, precision, ir_version, temp_dir, + use_new_frontend, use_old_api): + self._test(*self.create_tensor_array_read_v3(**params), + ie_device, precision, ir_version, temp_dir=temp_dir, + use_new_frontend=use_new_frontend, use_old_api=use_old_api) + + +class TestTensorArrayWriteGatherV3(CommonTFLayerTest): + def _prepare_input(self, inputs_info): + assert 'data' in inputs_info + assert 'indices' in inputs_info + assert 'value_to_write' in inputs_info + data_shape = inputs_info['data'] + value_shape = inputs_info['value_to_write'] + inputs_data = {} + rng = np.random.default_rng() + inputs_data['data'] = rng.integers(-10, 10, data_shape).astype(self.data_type) + inputs_data['value_to_write'] = rng.integers(-10, 10, value_shape).astype(self.data_type) + indices_data = rng.permutation(self.size).astype(np.int32) + inputs_data['indices'] = np.delete(indices_data, np.where(indices_data == self.index_to_write)) + return inputs_data + + def create_tensor_array_write_v3(self, size, data_shape, data_type, index_to_write, indices_to_gather): + self.data_type = data_type + self.size = size + self.index_to_write = index_to_write + tf.compat.v1.reset_default_graph() + # Create the graph and model + with tf.compat.v1.Session() as sess: + value_to_write = tf.compat.v1.placeholder(data_type, data_shape[1:], 'value_to_write') + index_to_write_const = tf.constant(index_to_write, dtype=tf.int32, shape=[]) + indices_to_gather_const = tf.constant(indices_to_gather, dtype=tf.int32, shape=[len(indices_to_gather)]) + data = tf.compat.v1.placeholder(data_type, data_shape, 'data') + indices = tf.compat.v1.placeholder(tf.int32, [size - 1], 'indices') + size_const = tf.constant(size, dtype=tf.int32, shape=[]) + handle, flow = tf.raw_ops.TensorArrayV3(size=size_const, dtype=tf.as_dtype(data_type)) + flow = tf.raw_ops.TensorArrayScatterV3(handle=handle, indices=indices, value=data, flow_in=flow) + flow = tf.raw_ops.TensorArrayWriteV3(handle=handle, index=index_to_write_const, + value=value_to_write, flow_in=flow) + tf.raw_ops.TensorArrayGatherV3(handle=handle, indices=indices_to_gather_const, flow_in=flow, + dtype=tf.dtypes.as_dtype(data_type)) + tf.raw_ops.TensorArrayCloseV3(handle=handle) + tf.compat.v1.global_variables_initializer() + tf_net = sess.graph_def + + return tf_net, None + + test_data_basic = [ + dict(size=7, data_shape=[6], data_type=np.float32, index_to_write=3, indices_to_gather=[0, 3, 1]), + dict(size=10, data_shape=[9, 2, 4], data_type=np.int32, index_to_write=2, indices_to_gather=[2, 1, 4, 3]), + ] + + @pytest.mark.parametrize("params", test_data_basic) + @pytest.mark.precommit_tf_fe + @pytest.mark.nightly + def test_tensor_array_write_v3(self, params, ie_device, precision, ir_version, temp_dir, + use_new_frontend, use_old_api): + self._test(*self.create_tensor_array_write_v3(**params), + ie_device, precision, ir_version, temp_dir=temp_dir, + use_new_frontend=use_new_frontend, use_old_api=use_old_api) + + +class TestTensorArrayConcatV3(CommonTFLayerTest): + def _prepare_input(self, inputs_info): + assert 'data' in inputs_info + assert 'indices' in inputs_info + data_shape = inputs_info['data'] + inputs_data = {} + rng = np.random.default_rng() + inputs_data['data'] = rng.integers(-10, 10, data_shape).astype(self.data_type) + inputs_data['indices'] = rng.permutation(self.size).astype(np.int32) + return inputs_data + + def create_tensor_array_concat_v3(self, data_shape, data_type): + size = data_shape[0] + self.data_type = data_type + self.size = size + tf.compat.v1.reset_default_graph() + # Create the graph and model + with tf.compat.v1.Session() as sess: + handle, flow = create_tensor_array(data_shape, data_type) + tensor_array_concat_v3 = tf.raw_ops.TensorArrayConcatV3(handle=handle, flow_in=flow, + dtype=tf.as_dtype(data_type)) + tf.identity(tensor_array_concat_v3[0], name='values') + tf.identity(tensor_array_concat_v3[1], name='length') + tf.raw_ops.TensorArrayCloseV3(handle=handle) + tf.compat.v1.global_variables_initializer() + tf_net = sess.graph_def + + return tf_net, None + + test_data_basic = [ + dict(data_shape=[5, 3, 11, 2], data_type=np.int32), + ] + + @pytest.mark.parametrize("params", test_data_basic) + @pytest.mark.precommit_tf_fe + @pytest.mark.nightly + def test_tensor_array_concat_v3(self, params, ie_device, precision, ir_version, temp_dir, + use_new_frontend, use_old_api): + self._test(*self.create_tensor_array_concat_v3(**params), + ie_device, precision, ir_version, temp_dir=temp_dir, + use_new_frontend=use_new_frontend, use_old_api=use_old_api) diff --git a/tests/layer_tests/tensorflow_tests/test_tf_TensorListLength.py b/tests/layer_tests/tensorflow_tests/test_tf_TensorListLength.py index 57b17b3341d750..8d6005350fb3fd 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_TensorListLength.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_TensorListLength.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +from sys import platform + import numpy as np import pytest import tensorflow as tf @@ -38,6 +40,7 @@ def create_tensor_list_length(self, input_shape, input_type): @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.skipif(platform == 'darwin', reason="Ticket - 122182") def test_tensor_list_length_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_tensor_list_length(**params), @@ -76,6 +79,7 @@ def create_tensor_list_length_empty_list(self, tensor_list_size, element_shape): @pytest.mark.parametrize("params", test_data_tensor_list_length_empty_list) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.skipif(platform == 'darwin', reason="Ticket - 122182") def test_tensor_list_length_empty_list(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_tensor_list_length_empty_list(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_TensorListResize.py b/tests/layer_tests/tensorflow_tests/test_tf_TensorListResize.py index 39bdca06dee004..709f009a7afa93 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_TensorListResize.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_TensorListResize.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +from sys import platform + import numpy as np import pytest import tensorflow as tf @@ -42,6 +44,7 @@ def create_tensor_list_resize(self, input_shape, input_type, new_size): @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.skipif(platform == 'darwin', reason="Ticket - 122182") def test_tensor_list_resize_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_tensor_list_resize(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_ToBool.py b/tests/layer_tests/tensorflow_tests/test_tf_ToBool.py new file mode 100644 index 00000000000000..74da79c36d52a1 --- /dev/null +++ b/tests/layer_tests/tensorflow_tests/test_tf_ToBool.py @@ -0,0 +1,43 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np +import pytest +import tensorflow as tf +from common.tf_layer_test_class import CommonTFLayerTest + + +class TestToBool(CommonTFLayerTest): + def _prepare_input(self, inputs_info): + assert 'x' in inputs_info + x_shape = inputs_info['x'] + inputs_data = {} + inputs_data['x'] = np.random.randint(-10, 10, x_shape).astype(np.float32) + + return inputs_data + + def create_tobool_net(self, input_shape, input_type): + self.input_type = input_type + tf.compat.v1.reset_default_graph() + # Create the graph and model + with tf.compat.v1.Session() as sess: + x = tf.compat.v1.placeholder(input_type, input_shape, 'x') + tf.raw_ops.ToBool(input=x) + tf.compat.v1.global_variables_initializer() + tf_net = sess.graph_def + + return tf_net, None + + test_data_basic = [ + dict(input_shape=[10, 20], input_type=np.float32), + dict(input_shape=[2, 3, 4], input_type=np.float32), + ] + + @pytest.mark.parametrize("params", test_data_basic) + @pytest.mark.precommit_tf_fe + @pytest.mark.nightly + def test_to_bool_basic(self, params, ie_device, precision, ir_version, temp_dir, + use_new_frontend, use_old_api): + self._test(*self.create_tobool_net(**params), + ie_device, precision, ir_version, temp_dir=temp_dir, + use_new_frontend=use_new_frontend, use_old_api=use_old_api) \ No newline at end of file diff --git a/tests/layer_tests/tensorflow_tests/test_tf_TopKV2.py b/tests/layer_tests/tensorflow_tests/test_tf_TopKV2.py index ece6f08471a643..73efaf490b23dd 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_TopKV2.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_TopKV2.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import tensorflow as tf @@ -46,6 +48,8 @@ def create_topk_v2_net(self, input_shape, input_type, k, sorted, is_first_output @pytest.mark.parametrize("params", test_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_topk_v2_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_topk_v2_net(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_TruncateDiv.py b/tests/layer_tests/tensorflow_tests/test_tf_TruncateDiv.py new file mode 100644 index 00000000000000..18440dbcd7f44a --- /dev/null +++ b/tests/layer_tests/tensorflow_tests/test_tf_TruncateDiv.py @@ -0,0 +1,53 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import platform + +import numpy as np +import pytest +import tensorflow as tf +from common.tf_layer_test_class import CommonTFLayerTest + + +class TestTruncateDiv(CommonTFLayerTest): + def _prepare_input(self, inputs_info): + assert 'x' in inputs_info + assert 'y' in inputs_info + x_shape = inputs_info['x'] + y_shape = inputs_info['y'] + inputs_data = {} + # generate x and y to ensure truncation + inputs_data['x'] = np.random.randint(-10, 10, x_shape).astype(self.input_type) + inputs_data['y'] = np.random.randint(1, 10, y_shape).astype(self.input_type) + return inputs_data + + def create_truncate_div_net(self, input_shape, input_type): + self.input_type = input_type + tf.compat.v1.reset_default_graph() + # Create the graph and model + with tf.compat.v1.Session() as sess: + x = tf.compat.v1.placeholder(input_type, input_shape, 'x') + y = tf.compat.v1.placeholder(input_type, input_shape, 'y') + tf.raw_ops.TruncateDiv(x=x, y=y) + tf.compat.v1.global_variables_initializer() + tf_net = sess.graph_def + + return tf_net, None + + test_data_basic = [ + dict(input_shape=[10, 20], input_type=np.float32), + dict(input_shape=[8, 5], input_type=np.float32), + dict(input_shape=[5, 3], input_type=np.int32), + dict(input_shape=[6, 4], input_type=np.int32), + ] + + @pytest.mark.parametrize("params", test_data_basic) + @pytest.mark.precommit_tf_fe + @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') + def test_truncate_div_basic(self, params, ie_device, precision, ir_version, temp_dir, + use_new_frontend, use_old_api): + self._test(*self.create_truncate_div_net(**params), + ie_device, precision, ir_version, temp_dir=temp_dir, + use_new_frontend=use_new_frontend, use_old_api=use_old_api) diff --git a/tests/layer_tests/tensorflow_tests/test_tf_TruncateMod.py b/tests/layer_tests/tensorflow_tests/test_tf_TruncateMod.py new file mode 100644 index 00000000000000..48b738095c8bb0 --- /dev/null +++ b/tests/layer_tests/tensorflow_tests/test_tf_TruncateMod.py @@ -0,0 +1,49 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np +import pytest +import tensorflow as tf +from common.tf_layer_test_class import CommonTFLayerTest + + +class TestTruncateMod(CommonTFLayerTest): + def _prepare_input(self, inputs_info): + assert 'x' in inputs_info + assert 'y' in inputs_info + x_shape = inputs_info['x'] + y_shape = inputs_info['y'] + inputs_data = {} + # generate x and y to ensure truncation + inputs_data['x'] = np.random.randint(-10, 10, x_shape).astype(self.input_type) + inputs_data['y'] = np.random.randint(1, 10, y_shape).astype(self.input_type) + return inputs_data + + def create_truncate_mod_net(self, input_shape, input_type): + self.input_type = input_type + tf.compat.v1.reset_default_graph() + # Create the graph and model + with tf.compat.v1.Session() as sess: + x = tf.compat.v1.placeholder(input_type, input_shape, 'x') + y = tf.compat.v1.placeholder(input_type, input_shape, 'y') + tf.raw_ops.TruncateMod(x=x, y=y) + tf.compat.v1.global_variables_initializer() + tf_net = sess.graph_def + + return tf_net, None + + test_data_basic = [ + dict(input_shape=[10, 20], input_type=np.float32), + dict(input_shape=[8, 5], input_type=np.float32), + dict(input_shape=[5, 3], input_type=np.int32), + dict(input_shape=[6, 4], input_type=np.int32), + ] + + @pytest.mark.parametrize("params", test_data_basic) + @pytest.mark.precommit_tf_fe + @pytest.mark.nightly + def test_truncate_mod_basic(self, params, ie_device, precision, ir_version, temp_dir, + use_new_frontend, use_old_api): + self._test(*self.create_truncate_mod_net(**params), + ie_device, precision, ir_version, temp_dir=temp_dir, + use_new_frontend=use_new_frontend, use_old_api=use_old_api) diff --git a/tests/layer_tests/tensorflow_tests/test_tf_UnaryOps.py b/tests/layer_tests/tensorflow_tests/test_tf_UnaryOps.py index 7b176344271794..91ed0a72db0bcf 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_UnaryOps.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_UnaryOps.py @@ -214,6 +214,7 @@ def test_unary_op_mish_precommit(self, params, ie_device, precision, ir_version, 'Selu' ]) @pytest.mark.nightly + @pytest.mark.skipif(sys.platform == 'darwin', reason="Ticket - 122182") def test_unary_op(self, params, ie_device, precision, ir_version, temp_dir, op_type, use_new_frontend, use_old_api): if ie_device == 'GPU': diff --git a/tests/layer_tests/tensorflow_tests/test_tf_UnsortedSegmentSum.py b/tests/layer_tests/tensorflow_tests/test_tf_UnsortedSegmentSum.py index 09afd6f26330ca..f7dcf2eeb324f2 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_UnsortedSegmentSum.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_UnsortedSegmentSum.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import tensorflow as tf @@ -55,6 +57,8 @@ def create_unsorted_segment_sum_net(self, data_shape, segment_ids_shape, num_seg ]) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') def test_unsorted_segment_sum_basic(self, params, data_type, segment_ids_type, num_segments_type, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): diff --git a/tests/layer_tests/tensorflow_tests/test_tf_While.py b/tests/layer_tests/tensorflow_tests/test_tf_While.py index 3a6f9b7f291029..2a112700f30ad5 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_While.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_While.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +from sys import platform + import numpy as np import pytest import tensorflow as tf @@ -55,6 +57,7 @@ def body(x, y): @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.skipif(platform == 'darwin', reason="Ticket - 122182") def test_while_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_while_net(**params), @@ -113,6 +116,7 @@ def body(x, y): @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.skipif(platform == 'darwin', reason="Ticket - 122182") def test_while_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_while_net(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_Xlog1py.py b/tests/layer_tests/tensorflow_tests/test_tf_Xlog1py.py new file mode 100644 index 00000000000000..4da47e7b5356c4 --- /dev/null +++ b/tests/layer_tests/tensorflow_tests/test_tf_Xlog1py.py @@ -0,0 +1,53 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import platform + +import numpy as np +import pytest +import tensorflow as tf +from common.tf_layer_test_class import CommonTFLayerTest + + +class TestXlog1py(CommonTFLayerTest): + def _prepare_input(self, inputs_info): + assert 'x' in inputs_info + assert 'y' in inputs_info + x_shape = inputs_info['x'] + y_shape = inputs_info['y'] + inputs_data = {} + # x = [-3 ,3] y = [1, 2] + # generate x in way to have zeros + inputs_data['x'] = (6 * np.random.random(size=x_shape).astype(np.float32) - 3) * \ + np.random.randint(2, size=x_shape).astype(np.float32) + inputs_data['y'] = np.random.random(size=y_shape).astype(np.float32) + 1 + return inputs_data + + def create_xlog1py_net(self, input_shape, input_type): + self.input_type = input_type + tf.compat.v1.reset_default_graph() + # Create the graph and model + with tf.compat.v1.Session() as sess: + x = tf.compat.v1.placeholder(input_type, input_shape, 'x') + y = tf.compat.v1.placeholder(input_type, input_shape, 'y') + tf.raw_ops.Xlog1py(x=x, y=y) + tf.compat.v1.global_variables_initializer() + tf_net = sess.graph_def + + return tf_net, None + + test_data_basic = [ + dict(input_shape=[10, 20], input_type=np.float32), + dict(input_shape=[2, 3, 4], input_type=np.float32), + ] + + @pytest.mark.parametrize("params", test_data_basic) + @pytest.mark.precommit_tf_fe + @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') + def test_xlog1py_basic(self, params, ie_device, precision, ir_version, temp_dir, + use_new_frontend, use_old_api): + self._test(*self.create_xlog1py_net(**params), + ie_device, precision, ir_version, temp_dir=temp_dir, + use_new_frontend=use_new_frontend, use_old_api=use_old_api) diff --git a/tests/layer_tests/tensorflow_tests/test_tf_Xlogy.py b/tests/layer_tests/tensorflow_tests/test_tf_Xlogy.py new file mode 100644 index 00000000000000..911c3b0eea2154 --- /dev/null +++ b/tests/layer_tests/tensorflow_tests/test_tf_Xlogy.py @@ -0,0 +1,53 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import platform + +import numpy as np +import pytest +import tensorflow as tf +from common.tf_layer_test_class import CommonTFLayerTest + + +class TestXlogy(CommonTFLayerTest): + def _prepare_input(self, inputs_info): + assert 'x' in inputs_info + assert 'y' in inputs_info + x_shape = inputs_info['x'] + y_shape = inputs_info['y'] + inputs_data = {} + # x = [-3 ,3] y = [1, 2] + # generate x in way to have zeros + inputs_data['x'] = (6 * np.random.random(size=x_shape).astype(np.float32) - 3) * \ + np.random.randint(2, size=x_shape).astype(np.float32) + inputs_data['y'] = np.random.random(size=y_shape).astype(np.float32) + 1 + return inputs_data + + def create_xlogy_net(self, input_shape, input_type): + self.input_type = input_type + tf.compat.v1.reset_default_graph() + # Create the graph and model + with tf.compat.v1.Session() as sess: + x = tf.compat.v1.placeholder(input_type, input_shape, 'x') + y = tf.compat.v1.placeholder(input_type, input_shape, 'y') + tf.raw_ops.Xlogy(x=x, y=y) + tf.compat.v1.global_variables_initializer() + tf_net = sess.graph_def + + return tf_net, None + + test_data_basic = [ + dict(input_shape=[10, 20], input_type=np.float32), + dict(input_shape=[2, 3, 4], input_type=np.float32), + ] + + @pytest.mark.parametrize("params", test_data_basic) + @pytest.mark.precommit_tf_fe + @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + reason='Ticket - 122716') + def test_xlogy_basic(self, params, ie_device, precision, ir_version, temp_dir, + use_new_frontend, use_old_api): + self._test(*self.create_xlogy_net(**params), + ie_device, precision, ir_version, temp_dir=temp_dir, + use_new_frontend=use_new_frontend, use_old_api=use_old_api) diff --git a/tests/model_hub_tests/torch_tests/detectron2_models b/tests/model_hub_tests/torch_tests/detectron2_models index 091464ab8d3080..bf893697180835 100644 --- a/tests/model_hub_tests/torch_tests/detectron2_models +++ b/tests/model_hub_tests/torch_tests/detectron2_models @@ -1,4 +1,4 @@ -COCO-Detection/fast_rcnn_R_50_FPN_1x,none +COCO-Detection/fast_rcnn_R_50_FPN_1x,none,xfail,Tracing problem COCO-Detection/faster_rcnn_R_101_C4_3x,none COCO-Detection/faster_rcnn_R_101_DC5_3x,none COCO-Detection/faster_rcnn_R_101_FPN_3x,none diff --git a/tests/model_hub_tests/torch_tests/hf_transformers_models b/tests/model_hub_tests/torch_tests/hf_transformers_models index 028de156c32459..31a24b681eb4c5 100644 --- a/tests/model_hub_tests/torch_tests/hf_transformers_models +++ b/tests/model_hub_tests/torch_tests/hf_transformers_models @@ -3,14 +3,13 @@ abcp4/mymodel-test,mymodel,skip,Load problem abeja/gpt-neox-japanese-2.7b,gpt_neox_japanese acl-submission-anonym/EAM-spectral,examuse,skip,Load problem adalbertojunior/modular-test,modular,skip,Load problem -aerner/lm-v2,open-llama +aerner/lm-v2,open-llama,xfail,Example input problem afonsosamarques/ardt-vanilla-combo_train_hopper_v2-2508_1336-33,decision_transformer,xfail,Tracing problem aihijo/gec-zh-gector-bert-large,gector,skip,Load problem albert-base-v2,albert AlekseyKorshuk/test_reward_model,reward_model,skip,Load problem alibaba-damo/mgp-str-base,mgp-str,xfail,Compile error: unsupported Einsum allenai/hvila-block-layoutlm-finetuned-docbank,hierarchical_model,skip,Load problem -allenai/longformer-base-4096,longformer,xfail,Unsupported op aten::as_strided ameya772/sentence-t5-base-atis-fine-tuned,T5,skip,Load problem andreasmadsen/efficient_mlm_m0.40,roberta-prelayernorm anton-l/emformer-base-librispeech,emformer,skip,Load problem @@ -21,7 +20,7 @@ ArthurZ/jukebox-vqvae,jukebox_vqvae,skip,Load problem ArthurZ/persimmon-8b-base,persimmon,skip,Load problem ashishpatel26/span-marker-bert-base-fewnerd-coarse-super,span-marker,skip,Load problem asi/albert-act-tiny,albert_act,skip,Load problem -BAAI/AltCLIP,altclip,xfail,Unsupported op aten::numpy_T +BAAI/AltCLIP,altclip BAAI/AquilaCode-py,aquila,skip,Load problem bana513/opennmt-translator-en-hu,opennmt-translator,skip,Load problem benjamin/wtp-bert-mini,bert-char,skip,Load problem @@ -68,7 +67,7 @@ facebook/detr-resnet-50,detr facebook/dinov2-base,dinov2,skip,Load problem facebook/dpr-question_encoder-single-nq-base,dpr facebook/encodec_24khz,encodec,xfail,Unsupported op aten::lstm -facebook/esm2_t6_8M_UR50D,esm,xfail,Tracing error: The values for attribute 'shape' do not match +facebook/esm2_t6_8M_UR50D,esm facebook/flava-full,flava,xfail,Tracing problem facebook/flava-image-codebook,flava_image_codebook,skip,Load problem facebook/m2m100_418M,m2m_100 @@ -79,7 +78,7 @@ facebook/musicgen-small,musicgen,skip,Load problem facebook/opt-125m,opt facebook/rag-token-nq,rag,skip,Load problem facebook/sam-vit-large,sam,xfail,No node with name original_sizes -facebook/timesformer-base-finetuned-k400,timesformer,xfail,Shape inference of Add node failed: Eltwise shape infer input shapes dim index: 1 mismatch +facebook/timesformer-base-finetuned-k400,timesformer facebook/vit-mae-base,vit_mae,xfail,Accuracy validation failed facebook/wmt19-ru-en,fsmt,xfail,Tracing problem facebook/xlm-roberta-xl,xlm-roberta-xl @@ -123,10 +122,10 @@ hf-internal-testing/tiny-random-Data2VecAudioModel,data2vec-audio,skip,Load prob hf-internal-testing/tiny-random-Data2VecTextModel,data2vec-text hf-internal-testing/tiny-random-Data2VecVisionModel,data2vec-vision hf-internal-testing/tiny-random-DeiTModel,deit -hf-internal-testing/tiny-random-DonutSwinModel,donut-swin,xfail,Unsupported op aten::adaptive_avg_pool1d +hf-internal-testing/tiny-random-DonutSwinModel,donut-swin hf-internal-testing/tiny-random-EfficientFormerForImageClassification,efficientformer hf-internal-testing/tiny-random-flaubert,flaubert -hf-internal-testing/tiny-random-FocalNetModel,focalnet,xfail,Unsupported op aten::adaptive_avg_pool1d +hf-internal-testing/tiny-random-FocalNetModel,focalnet hf-internal-testing/tiny-random-GPTBigCodeForCausalLM,gpt_bigcode,xfail,Conversion is failed for: aten::mul hf-internal-testing/tiny-random-GPTJModel,gptj hf-internal-testing/tiny-random-groupvit,groupvit @@ -155,7 +154,7 @@ hf-internal-testing/tiny-random-Speech2TextModel,speech_to_text,skip,Load proble hf-internal-testing/tiny-random-speech-encoder-decoder,speech-encoder-decoder,skip,Load problem hf-internal-testing/tiny-random-SplinterModel,splinter hf-internal-testing/tiny-random-SqueezeBertModel,squeezebert -hf-internal-testing/tiny-random-SwinModel,swin,xfail,Unsupported op aten::adaptive_avg_pool1d +hf-internal-testing/tiny-random-SwinModel,swin hf-internal-testing/tiny-random-unispeech,unispeech,skip,Load problem hf-internal-testing/tiny-random-UniSpeechSatModel,unispeech-sat,skip,Load problem hf-internal-testing/tiny-random-vision_perceiver_conv,perceiver @@ -199,7 +198,7 @@ kiddothe2b/hierarchical-transformer-base-4096-v2,hat,skip,Load problem k-l-lambda/clip-text-generator,clip_text_generator,skip,Load problem k-l-lambda/stable-diffusion-v1-4-inv-embed,inv_word_embed,skip,Load problem KoboldAI/fairseq-dense-13B-Janeway,xglm,skip,Large Model -konverner/qdq-camembert-apolliner,qdqbert +konverner/qdq-camembert-apolliner,qdqbert,xfail,Repository not found krasserm/perceiver-ar-clm-base,perceiver-ar-causal-language-model,skip,Load problem krasserm/perceiver-ar-sam-giant-midi,perceiver-ar-symbolic-audio-model,skip,Load problem krasserm/perceiver-io-img-clf,perceiver-io-image-classifier,skip,Load problem @@ -242,16 +241,16 @@ microsoft/deberta-base,deberta microsoft/git-large-coco,git,skip,Load problem microsoft/layoutlm-base-uncased,layoutlm microsoft/layoutlmv2-base-uncased,layoutlmv2,skip,Load problem -microsoft/layoutlmv3-base,layoutlmv3,xfail,Unsupported op aten::amax aten::clip +microsoft/layoutlmv3-base,layoutlmv3 microsoft/markuplm-base,markuplm microsoft/resnet-50,resnet microsoft/speecht5_hifigan,hifigan,skip,Load problem microsoft/speecht5_tts,speecht5,skip,Load problem -microsoft/swinv2-tiny-patch4-window8-256,swinv2,xfail,Unsupported op aten::adaptive_avg_pool1d +microsoft/swinv2-tiny-patch4-window8-256,swinv2 microsoft/table-transformer-detection,table-transformer microsoft/wavlm-large,wavlm,skip,Load problem microsoft/xclip-base-patch32,xclip,skip,Load problem -microsoft/xprophetnet-large-wiki100-cased,xlm-prophetnet,xfail,Unsupported op aten::fill_diagonal_ +microsoft/xprophetnet-large-wiki100-cased,xlm-prophetnet miguelvictor/python-fromzero-lstmlm,lstmlm,skip,Load problem mingzi151/test-hf-wav2vec2bert,wav2vec2bert,skip,Load problem MIT/ast-finetuned-audioset-10-10-0.4593,audio-spectrogram-transformer,skip,Load problem @@ -301,7 +300,6 @@ pie/example-re-textclf-tacred,TransformerTextClassificationModel,skip,Load probl pleisto/yuren-baichuan-7b,multimodal_llama,skip,Load problem predictia/europe_reanalysis_downscaler_convbaseline,convbilinear,skip,Load problem predictia/europe_reanalysis_downscaler_convswin2sr,conv_swin2sr,skip,Load problem -pszemraj/led-large-book-summary,led,xfail,Unsupported op aten::as_strided qmeeus/whisper-small-ner-combined,whisper_for_slu,skip,Load problem raman-ai/pcqv2-tokengt-lap16,tokengt,skip,Load problem range3/pegasus-gpt2-medium,pegasusgpt2,skip,Load problem @@ -309,7 +307,7 @@ regisss/bridgetower-newyorker-a100-8x,bridgetower rinna/japanese-cloob-vit-b-16,cloob,skip,Load problem Rocketknight1/tiny-random-falcon-7b,falcon RUCAIBox/mass-base-uncased,mass,skip,Load problem -RWKV/rwkv-4-169m-pile,rwkv,xfail,Unsupported op aten::maximum +RWKV/rwkv-4-169m-pile,rwkv sahasrarjn/interbert,BERT,skip,Load problem saibo/genkalm-medium-gpt2,genkalm,skip,Load problem SajjadAyoubi/clip-fa-vision,clip_vision_model @@ -330,8 +328,8 @@ sheonhan/ict-imagenet-256,ict,skip,Load problem shibing624/text2vec-base-chinese-paraphrase,ernie shikhartuli/flexibert-mini,flexibert,skip,Load problem shikras/shikra-7b-delta-v1-0708,shikra,skip,Load problem -shi-labs/dinat-mini-in1k-224,dinat,xfail,Unsupported op aten::adaptive_avg_pool1d -shi-labs/nat-mini-in1k-224,nat,xfail,Unsupported op aten::adaptive_avg_pool1d +shi-labs/dinat-mini-in1k-224,dinat,xfail,Accuracy validation failed +shi-labs/nat-mini-in1k-224,nat,xfail,Accuracy validation failed shi-labs/oneformer_ade20k_swin_large,oneformer,skip,Load problem shuqi/seed-encoder,seed_encoder,skip,Load problem sijunhe/nezha-cn-base,nezha @@ -348,7 +346,7 @@ SteveZhan/my-resnet50d,resnet_steve,skip,Load problem suno/bark,bark,skip,Load problem surajnair/r3m-50,r3m,skip,Load problem susnato/clvp_dev,clvp,skip,Load problem -Tanrei/GPTSAN-japanese,gptsan-japanese,xfail,Unsupported op aten::clip aten::index_put_ prim::TupleConstruct +Tanrei/GPTSAN-japanese,gptsan-japanese,xfail,Unsupported op aten::index_put_ prim::TupleConstruct tau/bart-large-sled-govreport,tau/sled,skip,Load problem taufeeque/best-cb-model,codebook,skip,Load problem Team-PIXEL/pixel-base,pixel,skip,Load problem @@ -357,7 +355,7 @@ thomwolf/vqgan_imagenet_f16_1024,vqgan_model,skip,Load problem thu-ml/zh-clip-vit-roberta-large-patch14,zhclip,skip,Load problem tifa-benchmark/promptcap-coco-vqa,ofa,skip,Load problem tli8hf/robertabase_snli,transformerfornli,skip,Load problem -transfo-xl-wt103,transfo-xl,xfail,Unsupported op aten::clamp_ aten::index_copy_ +transfo-xl-wt103,transfo-xl,xfail,Unsupported op aten::index_copy_ transZ/BART_shared_clean,shared_bart,skip,Load problem transZ/BART_shared_v2,shared_bart_v2,skip,Load problem transZ/misecom,misecom,skip,Load problem diff --git a/tests/model_hub_tests/torch_tests/test_detectron2.py b/tests/model_hub_tests/torch_tests/test_detectron2.py index e8859905622260..0ceebcff9f258d 100644 --- a/tests/model_hub_tests/torch_tests/test_detectron2.py +++ b/tests/model_hub_tests/torch_tests/test_detectron2.py @@ -20,7 +20,7 @@ def setup_class(self): def load_model(self, model_name, model_link): from detectron2 import model_zoo, export - from detectron2.modeling import build_model + from detectron2.modeling import build_model, PanopticFPN from detectron2.checkpoint import DetectionCheckpointer from detectron2.config import CfgNode import torchvision.transforms as transforms @@ -32,13 +32,23 @@ def load_model(self, model_name, model_link): assert isinstance(cfg, CfgNode), "Unexpected config" cfg.MODEL.DEVICE = "cpu" model = build_model(cfg) - DetectionCheckpointer(model, save_to_disk=False).load(cfg.MODEL.WEIGHTS) - + DetectionCheckpointer( + model, save_to_disk=False).load(cfg.MODEL.WEIGHTS) + model.eval() inputs = [{"image": image, "height": torch.tensor(image.shape[1]), "width": torch.tensor(image.shape[2])}] - adapter = export.TracingAdapter(model, inputs) + # https://github.com/facebookresearch/detectron2/blob/4e80df1e58901557e2824ce3b488d30209a9be33/tools/deploy/export_model.py#L123 + # This is done only for Panoptic models, but it may be incorrect to do that, because one of outputs of panoptic model is getting lost + if isinstance(model, PanopticFPN): + def inference(model, inputs): + # use do_postprocess=False so it returns ROI mask + inst = model.inference(inputs, do_postprocess=False)[0] + return [{"instances": inst}] + else: + inference = None # assume that we just call the model directly + adapter = export.TracingAdapter(model, inputs, inference) self.example = adapter.flattened_inputs return adapter @@ -75,7 +85,8 @@ def compare_results(self, fw_outputs, ov_outputs): cur_fw_res = fw_outputs[i] cur_ov_res = ov_outputs[i] l = min(len(cur_fw_res), len(cur_ov_res)) - assert l > 0 or len(cur_fw_res) == len(cur_ov_res), "No boxes were selected." + assert l > 0 or len(cur_fw_res) == len( + cur_ov_res), "No boxes were selected." print(f"fw_re: {cur_fw_res};\n ov_res: {cur_ov_res}") is_ok = compare_two_tensors(cur_ov_res[:l], cur_fw_res[:l], fw_eps) assert is_ok, "Accuracy validation failed" @@ -86,8 +97,8 @@ def compare_results(self, fw_outputs, ov_outputs): def test_detectron2_precommit(self, name, type, mark, reason, ie_device): self.run(name, None, ie_device) - @pytest.mark.parametrize("name,type,mark,reason", - get_models_list(os.path.join(os.path.dirname(__file__), "detectron2_models"))) + @pytest.mark.parametrize("name", + [pytest.param(n, marks=pytest.mark.xfail(reason=r)) if m == "xfail" else n for n, _, m, r in get_models_list(os.path.join(os.path.dirname(__file__), "detectron2_models"))]) @pytest.mark.nightly - def test_detectron2_all_models(self, name, type, mark, reason, ie_device): + def test_detectron2_all_models(self, name, ie_device): self.run(name, None, ie_device) diff --git a/tests/model_hub_tests/torch_tests/test_transformers.py b/tests/model_hub_tests/torch_tests/test_hf_transformers.py similarity index 97% rename from tests/model_hub_tests/torch_tests/test_transformers.py rename to tests/model_hub_tests/torch_tests/test_hf_transformers.py index 3a677353c86508..caeb2e0ff2a01d 100644 --- a/tests/model_hub_tests/torch_tests/test_transformers.py +++ b/tests/model_hub_tests/torch_tests/test_hf_transformers.py @@ -292,13 +292,17 @@ def teardown_method(self): cleanup_dir(hf_hub_cache_dir) super().teardown_method() - @pytest.mark.parametrize("name,type", [("bert-base-uncased", "bert"), + @pytest.mark.parametrize("name,type", [("allenai/led-base-16384", "led"), + ("bert-base-uncased", "bert"), ("facebook/bart-large-mnli", "bart"), ("google/flan-t5-base", "t5"), ("google/tapas-large-finetuned-wtq", "tapas"), ("gpt2", "gpt2"), ("openai/clip-vit-large-patch14", "clip"), - ("RWKV/rwkv-4-169m-pile", "rwkv")]) + ("RWKV/rwkv-4-169m-pile", "rwkv"), + ("microsoft/layoutlmv3-base", "layoutlmv3"), + ("microsoft/xprophetnet-large-wiki100-cased", "xlm-prophetnet"), + ]) @pytest.mark.precommit def test_convert_model_precommit(self, name, type, ie_device): self.run(model_name=name, model_link=type, ie_device=ie_device) diff --git a/tests/model_hub_tests/torch_tests/test_timm.py b/tests/model_hub_tests/torch_tests/test_timm.py index d08f6a8c4a9a40..d6dd438df5c6c6 100644 --- a/tests/model_hub_tests/torch_tests/test_timm.py +++ b/tests/model_hub_tests/torch_tests/test_timm.py @@ -10,9 +10,28 @@ from openvino import convert_model +def filter_timm(timm_list: list) -> list: + unique_models = set() + filtered_list = [] + ignore_set = {"base", "mini", "small", "xxtiny", "xtiny", "tiny", "lite", "nano", "pico", "medium", "big", + "large", "xlarge", "xxlarge", "huge", "gigantic", "giant", "enormous", "xs", "xxs", "s", "m", "l", "xl"} + for name in timm_list: + # first: remove datasets + name_parts = name.split(".") + _name = "_".join(name.split(".")[:-1]) if len(name_parts) > 1 else name + # second: remove sizes + name_set = set([n for n in _name.split("_") if not n.isnumeric()]) + name_set = name_set.difference(ignore_set) + name_join = "_".join(name_set) + if name_join not in unique_models: + unique_models.add(name_join) + filtered_list.append(name) + return filtered_list + + def get_all_models() -> list: m_list = timm.list_pretrained() - return m_list + return filter_timm(m_list) # To make tests reproducible we seed the random generator @@ -61,6 +80,7 @@ def teardown_method(self): def test_convert_model_precommit(self, name, ie_device): self.run(name, None, ie_device) + @pytest.mark.nightly @pytest.mark.parametrize("name", get_all_models()) def test_convert_model_all_models(self, name, ie_device): self.run(name, None, ie_device) diff --git a/tests/model_hub_tests/torch_tests/test_torchvision_models.py b/tests/model_hub_tests/torch_tests/test_torchvision_models.py index a7722389e4132d..7b93ea68505a88 100644 --- a/tests/model_hub_tests/torch_tests/test_torchvision_models.py +++ b/tests/model_hub_tests/torch_tests/test_torchvision_models.py @@ -114,7 +114,7 @@ def test_convert_model_precommit(self, model_name, ie_device): self.run(model_name, None, ie_device) @pytest.mark.parametrize("name", - [pytest.param(n, marks=pytest.mark.xfail) if m == "xfail" else n for n, _, m, r in get_models_list(os.path.join(os.path.dirname(__file__), "torchvision_models"))]) + [pytest.param(n, marks=pytest.mark.xfail(reason=r)) if m == "xfail" else n for n, _, m, r in get_models_list(os.path.join(os.path.dirname(__file__), "torchvision_models"))]) @pytest.mark.nightly def test_convert_model_all_models(self, name, ie_device): self.run(name, None, ie_device) diff --git a/tests/samples_tests/smoke_tests/test_speech_sample.py b/tests/samples_tests/smoke_tests/test_speech_sample.py index 46871e31ca0dac..ff3649662d2207 100644 --- a/tests/samples_tests/smoke_tests/test_speech_sample.py +++ b/tests/samples_tests/smoke_tests/test_speech_sample.py @@ -56,6 +56,7 @@ def setup_class(cls): super().setup_class() @pytest.mark.parametrize("param", test_data) + @pytest.mark.skipif(sys.platform == 'darwin', reason="GNA is not available on macOS") def test_speech_sample_nthreads(self, param): stdout = self._test(param).split('\n') @@ -64,6 +65,7 @@ def test_speech_sample_nthreads(self, param): assert avg_error <= self.threshold @pytest.mark.parametrize("param", new_format_test_data) + @pytest.mark.skipif(sys.platform == 'darwin', reason="GNA is not available on macOS") def test_speech_sample_new_format(self, param): stdout = self._test(param, complete_path=False).split('\n') diff --git a/thirdparty/ade b/thirdparty/ade index 50ff2423e234d8..0e8a2ccdd34f29 160000 --- a/thirdparty/ade +++ b/thirdparty/ade @@ -1 +1 @@ -Subproject commit 50ff2423e234d8e340de7ce959b920f6c8c7fe79 +Subproject commit 0e8a2ccdd34f29dba55894f5f3c5179809888b9e diff --git a/thirdparty/dependencies.cmake b/thirdparty/dependencies.cmake index 8ef6c5bf1c51ea..4eed13c9a79af6 100644 --- a/thirdparty/dependencies.cmake +++ b/thirdparty/dependencies.cmake @@ -51,9 +51,6 @@ if(X86_64 OR X86 OR UNIVERSAL2) # conan creates alias xbyak::xbyak, no extra steps are required else() add_subdirectory(thirdparty/xbyak EXCLUDE_FROM_ALL) - # export and install xbyak - openvino_developer_export_targets(COMPONENT openvino_common TARGETS xbyak::xbyak) - ov_install_static_lib(xbyak ${OV_CPACK_COMP_CORE}) endif() endif() @@ -269,12 +266,13 @@ if(NOT TARGET openvino::pugixml) function(ov_build_pugixml) function(ov_build_pugixml_static) set(BUILD_SHARED_LIBS OFF) + set(PUGIXML_INSTALL OFF CACHE BOOL "" FORCE) add_subdirectory(thirdparty/pugixml EXCLUDE_FROM_ALL) endfunction() ov_build_pugixml_static() set_property(TARGET pugixml-static PROPERTY EXPORT_NAME pugixml) add_library(openvino::pugixml ALIAS pugixml-static) - openvino_developer_export_targets(COMPONENT openvino_common TARGETS openvino::pugixml) + ov_developer_package_export_targets(TARGET openvino::pugixml) ov_install_static_lib(pugixml-static ${OV_CPACK_COMP_CORE}) endfunction() @@ -300,7 +298,7 @@ if(ENABLE_GAPI_PREPROCESSING) add_subdirectory(thirdparty/ade EXCLUDE_FROM_ALL) set_target_properties(ade PROPERTIES FOLDER thirdparty) - openvino_developer_export_targets(COMPONENT openvino_common TARGETS ade) + ov_developer_package_export_targets(TARGET ade) ov_install_static_lib(ade ${OV_CPACK_COMP_CORE}) endif() @@ -316,7 +314,7 @@ if(ENABLE_GAPI_PREPROCESSING) endif() set_target_properties(fluid PROPERTIES FOLDER thirdparty) - openvino_developer_export_targets(COMPONENT openvino_common TARGETS fluid) + ov_developer_package_export_targets(TARGET fluid) ov_install_static_lib(fluid ${OV_CPACK_COMP_CORE}) endif() @@ -369,7 +367,7 @@ if(ENABLE_SAMPLES OR ENABLE_TESTS) if(NOT TARGET gflags) add_subdirectory(thirdparty/gflags EXCLUDE_FROM_ALL) - openvino_developer_export_targets(COMPONENT openvino_common TARGETS gflags) + ov_developer_package_export_targets(TARGET gflags) endif() endif() @@ -391,8 +389,14 @@ if(ENABLE_TESTS) endforeach() else() add_subdirectory(thirdparty/gtest EXCLUDE_FROM_ALL) - openvino_developer_export_targets(COMPONENT tests - TARGETS gmock gmock_main gtest gtest_main) + # install & export + set(googletest_root "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/gtest/gtest") + ov_developer_package_export_targets(TARGET gtest_main + INSTALL_INCLUDE_DIRECTORIES "${googletest_root}/googletest/include/") + ov_developer_package_export_targets(TARGET gtest + INSTALL_INCLUDE_DIRECTORIES "${googletest_root}/googletest/include/") + ov_developer_package_export_targets(TARGET gmock + INSTALL_INCLUDE_DIRECTORIES "${googletest_root}/googlemock/include/") endif() endif() @@ -410,14 +414,14 @@ if(ENABLE_OV_PADDLE_FRONTEND OR ENABLE_OV_ONNX_FRONTEND OR ENABLE_OV_TF_FRONTEND if(CMAKE_VERBOSE_MAKEFILE) set(Protobuf_DEBUG ON) endif() - if(OV_VCPKG_BUILD) - set(protobuf_config CONFIG) - endif() # try to find newer version first (major is changed) # see https://protobuf.dev/support/version-support/ and # https://github.com/protocolbuffers/protobuf/commit/d61f75ff6db36b4f9c0765f131f8edc2f86310fa - find_package(Protobuf 4.22.0 QUIET ${protobuf_config}) + find_package(Protobuf 4.22.0 QUIET CONFIG) if(NOT Protobuf_FOUND) + if(OV_VCPKG_BUILD) + set(protobuf_config CONFIG) + endif() # otherwise, fallback to existing default find_package(Protobuf 3.20.3 REQUIRED ${protobuf_config}) endif() @@ -585,8 +589,9 @@ if(ENABLE_SAMPLES) else() add_subdirectory(thirdparty/json EXCLUDE_FROM_ALL) - # this is required only because of NPU plugin reused this - openvino_developer_export_targets(COMPONENT openvino_common TARGETS nlohmann_json) + # this is required only because of NPU plugin reused this: export & install + ov_developer_package_export_targets(TARGET nlohmann_json + INSTALL_INCLUDE_DIRECTORIES "${OpenVINO_SOURCE_DIR}/thirdparty/json/nlohmann_json/include") # for nlohmann library versions older than v3.0.0 if(NOT TARGET nlohmann_json::nlohmann_json) diff --git a/thirdparty/fluid/modules/gapi/include/opencv2/gapi/imgproc.hpp b/thirdparty/fluid/modules/gapi/include/opencv2/gapi/imgproc.hpp index 5c4c6f7031e6d8..5a6f237b27cda1 100644 --- a/thirdparty/fluid/modules/gapi/include/opencv2/gapi/imgproc.hpp +++ b/thirdparty/fluid/modules/gapi/include/opencv2/gapi/imgproc.hpp @@ -1214,7 +1214,7 @@ or column if there are N channels, or have N columns if there is a single channe @param src Input set of 2D points stored in one of possible containers: Mat, std::vector, std::vector, std::vector. @param distType Distance used by the M-estimator, see #DistanceTypes. @ref DIST_USER -and @ref DIST_C are not suppored. +and @ref DIST_C are not supported. @param param Numerical parameter ( C ) for some types of distances. If it is 0, an optimal value is chosen. @param reps Sufficient accuracy for the radius (distance between the coordinate origin and the @@ -1286,7 +1286,7 @@ or column if there are N channels, or have N columns if there is a single channe @param src Input set of 3D points stored in one of possible containers: Mat, std::vector, std::vector, std::vector. @param distType Distance used by the M-estimator, see #DistanceTypes. @ref DIST_USER -and @ref DIST_C are not suppored. +and @ref DIST_C are not supported. @param param Numerical parameter ( C ) for some types of distances. If it is 0, an optimal value is chosen. @param reps Sufficient accuracy for the radius (distance between the coordinate origin and the diff --git a/thirdparty/gtest/CMakeLists.txt b/thirdparty/gtest/CMakeLists.txt index f527552903c1d7..585b80934bc4ce 100644 --- a/thirdparty/gtest/CMakeLists.txt +++ b/thirdparty/gtest/CMakeLists.txt @@ -14,16 +14,31 @@ set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) add_subdirectory(gtest EXCLUDE_FROM_ALL) -get_target_property(gtest_include_dirs gtest INTERFACE_INCLUDE_DIRECTORIES) -set_target_properties(gtest PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${gtest_include_dirs}") +function(_ov_gtest_filter_install_interface TARGET TYPE) + set(final_include_dirs "$") + + get_target_property(include_dirs ${TARGET} INTERFACE_INCLUDE_DIRECTORIES) + foreach(include_dir IN LISTS include_dirs) + if(NOT include_dir MATCHES ".*INSTALL_INTERFACE.*") + # remove leading and trailing parts of generator expressions + string(REPLACE "$" "" include_dir "${include_dir}") + # wrap to BUILD_INTERFACE again + list(APPEND final_include_dirs "$") + endif() + endforeach() -get_target_property(gmock_include_dirs gtest INTERFACE_INCLUDE_DIRECTORIES) -set_target_properties(gmock PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES - "${gmock_include_dirs};${gmock_SOURCE_DIR}/include") + set_target_properties(${TARGET} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${final_include_dirs}" + INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${final_include_dirs}") +endfunction() -set(gtest_targets gtest gtest_main gmock gmock_main) +_ov_gtest_filter_install_interface(gtest gtest) +_ov_gtest_filter_install_interface(gtest_main gtest) +_ov_gtest_filter_install_interface(gmock gmock) +_ov_gtest_filter_install_interface(gmock_main gmock) -foreach(target IN LISTS gtest_targets) +foreach(target gtest gtest_main gmock gmock_main) # If we have specified /Z7 option, remove -Zi option which comes from gtest if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") get_target_property(_target_cxx_flags ${target} COMPILE_OPTIONS) @@ -41,8 +56,7 @@ foreach(target IN LISTS gtest_targets) target_compile_options(${target} PRIVATE -Wno-deprecated-copy) endif() endif() + # disable warnings ov_disable_all_warnings(${target}) + set_target_properties(${target} PROPERTIES FOLDER thirdparty) endforeach() - -set_target_properties(${gtest_targets} - PROPERTIES FOLDER thirdparty) diff --git a/thirdparty/ittapi/CMakeLists.txt b/thirdparty/ittapi/CMakeLists.txt index fe821f74feaaac..14e18f8bbced68 100644 --- a/thirdparty/ittapi/CMakeLists.txt +++ b/thirdparty/ittapi/CMakeLists.txt @@ -4,8 +4,8 @@ if(DEFINED INTEL_VTUNE_DIR OR DEFINED ENV{INTEL_VTUNE_DIR}) find_package(ITT - PATHS "${OpenVINO_SOURCE_DIR}/src/common/itt/cmake" - NO_DEFAULT_PATH) + PATHS "${OpenVINO_SOURCE_DIR}/src/common/itt/cmake" + NO_DEFAULT_PATH) if(NOT ITT_FOUND) message(WARNING "Profiling option enabled, but no ITT library was found under INTEL_VTUNE_DIR") endif() @@ -25,6 +25,6 @@ else() # create alias ittapi::ittnotify add_library(ittapi::ittnotify ALIAS ittnotify) - openvino_developer_export_targets(COMPONENT openvino_common TARGETS ittapi::ittnotify) + ov_developer_package_export_targets(TARGET ittapi::ittnotify) ov_install_static_lib(ittnotify ${OV_CPACK_COMP_CORE}) endif() diff --git a/thirdparty/ocl/CMakeLists.txt b/thirdparty/ocl/CMakeLists.txt index 0ebe3fd6d1df39..0a402752d3397e 100644 --- a/thirdparty/ocl/CMakeLists.txt +++ b/thirdparty/ocl/CMakeLists.txt @@ -4,9 +4,9 @@ function(get_lib_name TARGET_NAME LIBRARY_NAME) if(WIN32) - set(LIB_SUFFIX "${IE_BUILD_POSTFIX}${CMAKE_LINK_LIBRARY_SUFFIX}") + set(LIB_SUFFIX "${OV_BUILD_POSTFIX}${CMAKE_LINK_LIBRARY_SUFFIX}") else() - set(LIB_SUFFIX "${IE_BUILD_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}") + set(LIB_SUFFIX "${OV_BUILD_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}") endif() set("${LIBRARY_NAME}" "${CMAKE_SHARED_MODULE_PREFIX}${TARGET_NAME}${LIB_SUFFIX}" PARENT_SCOPE) diff --git a/thirdparty/open_model_zoo b/thirdparty/open_model_zoo index d831efe10e7af4..bb98fe444c84d6 160000 --- a/thirdparty/open_model_zoo +++ b/thirdparty/open_model_zoo @@ -1 +1 @@ -Subproject commit d831efe10e7af426ceba0b6ad65dbb5e5fc82beb +Subproject commit bb98fe444c84d67fd67ee7ec15a340722c652053 diff --git a/thirdparty/pugixml b/thirdparty/pugixml index a0e064336317c9..2e357d19a3228c 160000 --- a/thirdparty/pugixml +++ b/thirdparty/pugixml @@ -1 +1 @@ -Subproject commit a0e064336317c9347a91224112af9933598714e9 +Subproject commit 2e357d19a3228c0a301727aac6bea6fecd982d21 diff --git a/tools/benchmark_tool/CMakeLists.txt b/tools/benchmark_tool/CMakeLists.txt index ccab4ec9ca8eb8..9787b5f7b5cca5 100644 --- a/tools/benchmark_tool/CMakeLists.txt +++ b/tools/benchmark_tool/CMakeLists.txt @@ -14,8 +14,8 @@ if(NOT DEFINED OpenVINO_SOURCE_DIR) get_filename_component(OpenVINO_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../.." REALPATH) endif() -if(NOT IEDevScripts_FOUND) - find_package(IEDevScripts REQUIRED +if(NOT OpenVINODeveloperScripts_FOUND) + find_package(OpenVINODeveloperScripts REQUIRED PATHS "${OpenVINO_SOURCE_DIR}/cmake/developer_package" NO_CMAKE_FIND_ROOT_PATH NO_DEFAULT_PATH) @@ -40,5 +40,5 @@ install(DIRECTORY ${OpenVINOBenchmarkTool_SOURCE_DIR}/openvino # if(CMAKE_SOURCE_DIR STREQUAL OpenVINOBenchmarkTool_SOURCE_DIR) - ie_cpack(${IE_CPACK_COMPONENTS_ALL}) + ov_cpack(${OV_CPACK_COMPONENTS_ALL}) endif() diff --git a/tools/benchmark_tool/openvino/__init__.py b/tools/benchmark_tool/openvino/__init__.py index 90552e0befed68..b7dc434f3148cc 100644 --- a/tools/benchmark_tool/openvino/__init__.py +++ b/tools/benchmark_tool/openvino/__init__.py @@ -12,47 +12,47 @@ except ImportError: pass -# API 2.0 -try: - # Import all public modules - from openvino import runtime as runtime - from openvino import frontend as frontend - from openvino import helpers as helpers - from openvino import preprocess as preprocess - from openvino import utils as utils - from openvino.runtime import properties as properties - - # Import most important classes and functions from openvino.runtime - from openvino.runtime import Model - from openvino.runtime import Core - from openvino.runtime import CompiledModel - from openvino.runtime import InferRequest - from openvino.runtime import AsyncInferQueue - - from openvino.runtime import Dimension - from openvino.runtime import Strides - from openvino.runtime import PartialShape - from openvino.runtime import Shape - from openvino.runtime import Layout - from openvino.runtime import Type - from openvino.runtime import Tensor - from openvino.runtime import OVAny - - from openvino.runtime import compile_model - from openvino.runtime import get_batch - from openvino.runtime import set_batch - from openvino.runtime import serialize - from openvino.runtime import shutdown - from openvino.runtime import tensor_from_file - from openvino.runtime import save_model - from openvino.runtime import layout_helpers - - # Set version for openvino package - from openvino.runtime import get_version - __version__ = get_version() -except ImportError: - import warnings - warnings.warn("openvino package has problems with imports!", ImportWarning, stacklevel=2) +# # +# # API 2.0 +# # This __init__.py forces checking of runtime modules to propagate errors. +# # It is not compared with init files from openvino-dev package. +# # +# Import all public modules +from openvino import runtime as runtime +from openvino import frontend as frontend +from openvino import helpers as helpers +from openvino import preprocess as preprocess +from openvino import utils as utils +from openvino.runtime import properties as properties + +# Import most important classes and functions from openvino.runtime +from openvino.runtime import Model +from openvino.runtime import Core +from openvino.runtime import CompiledModel +from openvino.runtime import InferRequest +from openvino.runtime import AsyncInferQueue + +from openvino.runtime import Dimension +from openvino.runtime import Strides +from openvino.runtime import PartialShape +from openvino.runtime import Shape +from openvino.runtime import Layout +from openvino.runtime import Type +from openvino.runtime import Tensor +from openvino.runtime import OVAny + +from openvino.runtime import compile_model +from openvino.runtime import get_batch +from openvino.runtime import set_batch +from openvino.runtime import serialize +from openvino.runtime import shutdown +from openvino.runtime import tensor_from_file +from openvino.runtime import save_model +from openvino.runtime import layout_helpers + +# Set version for openvino package +from openvino.runtime import get_version +__version__ = get_version() # Tools try: diff --git a/tools/constraints.txt b/tools/constraints.txt index 18a3080d3a1e78..2e1588a005e03f 100644 --- a/tools/constraints.txt +++ b/tools/constraints.txt @@ -18,4 +18,4 @@ pyenchant>=3.0.0 test-generator==0.1.1 py>=1.9.0 urllib3>=1.26.4 -openvino-telemetry>=2023.1.0 +openvino-telemetry>=2023.2.1 diff --git a/tools/mo/automation/package_BOM.txt b/tools/mo/automation/package_BOM.txt index 0780ce7eba8151..b9bc64d1c8bf08 100644 --- a/tools/mo/automation/package_BOM.txt +++ b/tools/mo/automation/package_BOM.txt @@ -928,6 +928,7 @@ openvino/tools/mo/ops/MatMul.py openvino/tools/mo/ops/memory.py openvino/tools/mo/ops/memoryoffset.py openvino/tools/mo/ops/merge.py +openvino/tools/mo/ops/multinomial.py openvino/tools/mo/ops/mvn.py openvino/tools/mo/ops/mxfft.py openvino/tools/mo/ops/mxrepeat.py @@ -1106,4 +1107,4 @@ openvino/tools/mo/utils/tensorboard_util.py openvino/tools/mo/utils/type_utils.py openvino/tools/mo/utils/unsupported_ops.py openvino/tools/mo/utils/utils.py -openvino/tools/mo/utils/version.py \ No newline at end of file +openvino/tools/mo/utils/version.py diff --git a/tools/mo/openvino/tools/mo/convert_impl.py b/tools/mo/openvino/tools/mo/convert_impl.py index ae6c39a144b0a3..9d683f4b6ac977 100644 --- a/tools/mo/openvino/tools/mo/convert_impl.py +++ b/tools/mo/openvino/tools/mo/convert_impl.py @@ -312,8 +312,8 @@ def update_fallback_with_conversion_error(use_new_frontend: bool, is_tf: bool, e conversion_error_re = r"^(\[TensorFlow\ Frontend\]\ Internal\ error\,\ no\ translator\ found\ for\ operation\(s\)\:\ )((\w+)(\,\ \w+)*)$" conversion_error_match = re.findall(conversion_error_re, ex_msg, re.MULTILINE) all_fallback_operations = [ - # corresponds to TF1 TensorList operation - "TensorArrayScatterV3", "TensorArrayV3", "TensorArraySizeV3", "TensorArrayGatherV3", + # corresponds to TF1 While operation + "LoopCond", "Enter", "NextIteration", "Exit", "Switch", "Merge", # corresponds to operations with complex tensors "FFT", "FFT2D", "FFT3D", "IFFT", "IFFT2D", "IFFT3D", "RFFT", "RFFT2D", "RFFT3D", "IRFFT", "IRFFT2D", "IRFFT3D", diff --git a/tools/mo/openvino/tools/mo/front/common/partial_infer/utils.py b/tools/mo/openvino/tools/mo/front/common/partial_infer/utils.py index ef788469ba4574..6f87eebcb41a04 100644 --- a/tools/mo/openvino/tools/mo/front/common/partial_infer/utils.py +++ b/tools/mo/openvino/tools/mo/front/common/partial_infer/utils.py @@ -296,7 +296,7 @@ def get_shape_from_slice(input_shape: np.ndarray, slices: List) -> np.ndarray: in_idx += 1 elif s is np.newaxis: output_shape.append(1) - elif type(s) in [int, np.int, np.int32, np.int64]: # shrink_axis + elif type(s) in [int, np.int32, np.int64]: # shrink_axis in_idx += 1 elif s is Ellipsis: for idx in range(num_ellipsis_inserts): diff --git a/tools/mo/openvino/tools/mo/ops/Cast.py b/tools/mo/openvino/tools/mo/ops/Cast.py index 77beb07c74122e..24409912429f07 100644 --- a/tools/mo/openvino/tools/mo/ops/Cast.py +++ b/tools/mo/openvino/tools/mo/ops/Cast.py @@ -36,12 +36,14 @@ def backend_attrs(self): @staticmethod def type_infer(node: Node): - assert node.has_valid('dst_type'), 'Destination type of "Cast" operation should be extracted earlier' + assert node.has_valid( + 'dst_type'), 'Destination type of "Cast" operation should be extracted earlier' node.out_port(0).set_data_type(node.dst_type) @staticmethod def helper_value_propagation(node_name, value, dst_type): - new_blob, finite_match_count, zero_match_count = convert_blob(value, dst_type) + new_blob, finite_match_count, zero_match_count = convert_blob( + value, dst_type) if finite_match_count: log.error("{} elements of {} were clipped to infinity while converting an input blob for node '{}' to {}." @@ -63,6 +65,10 @@ def custom_type_casting_and_packing(node: Node, value, dst_type): we would pad them to 6 element with the last element as zero and we would pack them into 3 uint8 values """ assert dst_type in [packed_U4, packed_I4] + # TODO: Remove this comment when it's clear that we can fix it easily + # raise Exception("Packing of u4/i4 data is no longer supported in mo because it is now incompatible with the new " + # "order of the halfs of a byte that was introduced in OpenVINO runtime recently. Use ovc " + # "command line tool or openvino.convert_model python function instead.") minimum_regular_dtype = np.uint8 if dst_type == packed_U4 else np.int8 # initial casing from the source type to the numpy-friendly type which could absorb all the values of dst_type @@ -83,10 +89,12 @@ def custom_type_casting_and_packing(node: Node, value, dst_type): padded = np.concatenate((flattened, np.zeros([pad], dtype=minimum_regular_dtype))) assert np.prod(padded.shape) % num_values_fitting_into_uint8 == 0 - bit_order_little = (padded[:, None] & (1 << np.arange(num_bits)) > 0).astype(np.uint8) - bit_order_big = np.flip(bit_order_little, axis=1) - bit_order_big_flattened = bit_order_big.flatten() - packed = np.packbits(bit_order_big_flattened) + bit_order_little = (padded[:, None] & ( + 1 << np.arange(num_bits)) > 0).astype(np.uint8) + bit_order_big_flattened = bit_order_little.flatten() + # u1 still has reversed bit order: + packed = np.packbits(bit_order_big_flattened, + bitorder='little' if num_bits > 1 else 'big') node.out_node(0)['force_shape'] = data_shape.copy() node.out_node(0)['force_type'] = np_data_type_to_precision(dst_type) diff --git a/tools/mo/openvino/tools/mo/ops/elementwise.py b/tools/mo/openvino/tools/mo/ops/elementwise.py index ede0084a3744e4..8a29181c7f1826 100644 --- a/tools/mo/openvino/tools/mo/ops/elementwise.py +++ b/tools/mo/openvino/tools/mo/ops/elementwise.py @@ -246,3 +246,27 @@ def operation(a): if np.issubdtype(a.dtype, np.signedinteger): return float32_array(a.astype(np.float32) ** 0.5) return a ** 0.5 + + +class BitwiseAnd(Elementwise): + op = 'BitwiseAnd' + op_type = 'BitwiseAnd' + version = 'opset13' + + +class BitwiseOr(Elementwise): + op = 'BitwiseOr' + op_type = 'BitwiseOr' + version = 'opset13' + + +class BitwiseXor(Elementwise): + op = 'BitwiseXor' + op_type = 'BitwiseXor' + version = 'opset13' + + +class BitwiseNot(UnaryElementwise): + op = 'BitwiseNot' + op_type = 'BitwiseNot' + version = 'opset13' diff --git a/tools/mo/openvino/tools/mo/ops/multinomial.py b/tools/mo/openvino/tools/mo/ops/multinomial.py new file mode 100644 index 00000000000000..233a9d4565f4c1 --- /dev/null +++ b/tools/mo/openvino/tools/mo/ops/multinomial.py @@ -0,0 +1,69 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np + +from openvino.tools.mo.front.common.partial_infer.utils import dynamic_dimension_value, shape_array +from openvino.tools.mo.front.extractor import bool_to_str +from openvino.tools.mo.graph.graph import Graph, Node + +from openvino.tools.mo.ops.op import Op + + +class Multinomial(Op): + op = 'Multinomial' + enabled = False + + def __init__(self, graph: Graph, attrs: dict): + super().__init__(graph, { + 'type': self.op, + 'op': self.op, + 'version': 'opset13', + 'infer': self.infer, + 'in_ports_count': 2, + 'out_ports_count': 1, + 'type_infer': self.type_infer, + 'with_replacement': False, + 'log_probs': False, + 'global_seed': 0, + 'op_seed': 0, + 'convert_type': np.int64, + }, attrs) + + def backend_attrs(self): + return ['convert_type', + ('with_replacement', lambda node: bool_to_str( + node, 'with_replacement')), + ('log_probs', lambda node: bool_to_str(node, 'log_probs')), + 'global_seed', + 'op_seed'] + + def supported_attrs(self): + return ['convert_type', + 'with_replacement', + 'log_probs', + 'global_seed', + 'op_seed'] + + @staticmethod + def type_infer(node: Node): + assert node.has_valid('convert_type') + if node['convert_type'] == 'i32': + node.out_port(0).set_data_type(np.int32) + else: + node.out_port(0).set_data_type(np.int64) + + @staticmethod + def infer(node: Node): + + input_shape = node.in_node(0).shape + output_shape = [] + if input_shape is not None and input_shape.size == 2: + output_shape.append(input_shape[0]) + + num_samples = node.in_port(1).data.get_value() + if num_samples is not None: + output_shape.append(np.array(num_samples).item()) + else: + output_shape.append(dynamic_dimension_value) + node.out_port(0).data.set_shape(shape_array(output_shape)) diff --git a/tools/mo/openvino/tools/mo/utils/telemetry_utils.py b/tools/mo/openvino/tools/mo/utils/telemetry_utils.py index 802986edf4c4c0..e2cdd0b53f61d0 100644 --- a/tools/mo/openvino/tools/mo/utils/telemetry_utils.py +++ b/tools/mo/openvino/tools/mo/utils/telemetry_utils.py @@ -22,8 +22,13 @@ def init_mo_telemetry(app_name='Model Optimizer'): - return tm.Telemetry(tid=get_tid(), app_name=app_name, app_version=get_rt_version(), backend='ga4') - + return tm.Telemetry(tid=get_tid(), + app_name=app_name, + app_version=get_rt_version(), + backend='ga4', + enable_opt_in_dialog=False, + disable_in_ci=True + ) def send_framework_info(framework: str): """ diff --git a/tools/mo/requirements_tf.txt b/tools/mo/requirements_tf.txt index 548f30808083a1..f5891c136b2830 100644 --- a/tools/mo/requirements_tf.txt +++ b/tools/mo/requirements_tf.txt @@ -1,5 +1,5 @@ -c ../constraints.txt -tensorflow>=1.15.5,<2.13.0 +tensorflow>=1.15.5,<2.15.0 numpy>=1.16.6,<1.26 networkx defusedxml diff --git a/tools/mo/requirements_tf2.txt b/tools/mo/requirements_tf2.txt index a96ed84004f984..7992cc93a3a8b1 100644 --- a/tools/mo/requirements_tf2.txt +++ b/tools/mo/requirements_tf2.txt @@ -1,5 +1,5 @@ -c ../constraints.txt -tensorflow>=2.5,<2.13.0 +tensorflow>=2.5,<2.15.0 numpy>=1.16.6,<1.26 networkx defusedxml diff --git a/tools/mo/unit_tests/mo/back/MatMulNormalizer_test.py b/tools/mo/unit_tests/mo/back/MatMulNormalizer_test.py index 5187ca71c2bd84..c896f8b0ae2b38 100644 --- a/tools/mo/unit_tests/mo/back/MatMulNormalizer_test.py +++ b/tools/mo/unit_tests/mo/back/MatMulNormalizer_test.py @@ -5,7 +5,7 @@ from argparse import Namespace import numpy as np -from generator import generate, generator +import pytest from openvino.tools.mo.back.MatMulNormalizer import SmartReshape_HC_Reshape_MatMul, PullTransposeThroughFQUp from openvino.tools.mo.ops.MatMul import MatMul @@ -19,10 +19,9 @@ from unit_tests.utils.graph import regular_op_with_empty_data as op_with_empty_data -@generator -class SmartReshape_HC_Reshape_MatMulTest(unittest.TestCase): - @generate( - *[ +class TestSmartReshape_HC_Reshape_MatMulTest(): + @pytest.mark.parametrize("in1_shape, in2_shape, reshape_pattern, transpose_a, transpose_b, updated_pattern", + [ ([1, 20, 30], [30, 40], [20, -1], False, False, [-1, 30]), ([1, 20, 30], [40, 30], [20, -1], False, True, [-1, 30]), ([1, 30, 20], [30, 40], [-1, 20], True, False, [30, -1]), @@ -59,9 +58,9 @@ def test_reshape_on_the_A_input(self, graph_ref.clean_up() (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp - @generate(*[ + @pytest.mark.parametrize("in1_shape, in2_shape, reshape_pattern, transpose_a, transpose_b, updated_pattern",[ ([20, 30], [1, 30, 40], [-1, 40], False, False, [30, -1]), ([20, 30], [1, 40, 30], [40, -1], False, True, [-1, 30]), ([30, 20], [1, 30, 40], [-1, 40], True, False, [30, -1]), @@ -97,7 +96,7 @@ def test_reshape_on_the_B_input(self, graph_ref.clean_up() (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp class FQTransposePullerTest(unittest.TestCase): diff --git a/tools/mo/unit_tests/mo/back/ShuffleChannelPatternOptimization_test.py b/tools/mo/unit_tests/mo/back/ShuffleChannelPatternOptimization_test.py index 681ea349c8de65..ff4aaf8b1897ad 100644 --- a/tools/mo/unit_tests/mo/back/ShuffleChannelPatternOptimization_test.py +++ b/tools/mo/unit_tests/mo/back/ShuffleChannelPatternOptimization_test.py @@ -1,10 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest from argparse import Namespace - -from generator import generate, generator +import pytest from openvino.tools.mo.back.ShuffleChannelPatternOptimization import ShuffleChannelFusion, DepthToSpaceFusion from openvino.tools.mo.ops.depth_to_space import DepthToSpaceOp @@ -18,8 +16,7 @@ valued_const_with_data, connect, regular_op_with_empty_data -@generator -class ShuffleChannelFusionTest(unittest.TestCase): +class TestShuffleChannelFusionTest(): @staticmethod def get_graphs(input_shape, reshape_0_pattern, order, reshape_1_pattern, group): nodes = { @@ -67,7 +64,7 @@ def get_graphs(input_shape, reshape_0_pattern, order, reshape_1_pattern, group): return graph, graph_ref - @generate(*[ + @pytest.mark.parametrize("input_shape, reshape_0_pattern, order, reshape_1_pattern, group",[ ([1, 512, 7, 6], [1, 2, 256, 7, 6], [0, 2, 1, 3, 4], [1, 512, 7, 6], 2), ([2, 512, 7, 6], [2, 2, 256, 7, 6], [0, 2, 1, 3, 4], [2, 512, 7, 6], 2), ([1, 200, 200, 200], [1, 50, 4, 200, 200], [0, 2, 1, 3, 4], [1, 200, 200, 200], 50), @@ -77,11 +74,11 @@ def test_fusion(self, input_shape, reshape_0_pattern, order, reshape_1_pattern, ShuffleChannelFusion().find_and_replace_pattern(graph) graph.clean_up() (flag, resp) = compare_graphs(graph, graph_ref, 'output') - self.assertTrue(flag, resp) - self.assertTrue(len(graph.get_op_nodes(name='final_reshape')) == 1 and - graph.get_op_nodes(name='final_reshape')[0].op == 'ShuffleChannels') + assert flag, resp + assert len(graph.get_op_nodes(name='final_reshape')) == 1 and \ + graph.get_op_nodes(name='final_reshape')[0].op == 'ShuffleChannels' - @generate(*[ + @pytest.mark.parametrize("input_shape, reshape_0_pattern, order, reshape_1_pattern, group",[ ([1, 512, 7, 6], [0, 2, 256, 7, 6], [0, 2, 1, 3, 4], [1, 512, 7, 6], 2), ([1, 512, 7, 6], [1, 2, 256, 7, 6], [0, 2, 1, 4, 3], [1, 512, 7, 6], 2), ([1, 512, 7, 6], [1, 2, 256, 7, 6], [0, 2, 1, 3, 4], [-1, 512, 7, 6], 2), @@ -91,11 +88,10 @@ def test_negative(self, input_shape, reshape_0_pattern, order, reshape_1_pattern graph_ref = graph.copy() ShuffleChannelFusion().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'output') - self.assertTrue(flag, resp) + assert flag, resp -@generator -class DepthToSpaceFusionTest(unittest.TestCase): +class TestDepthToSpaceFusionTest(): @staticmethod def get_graphs(input_shape, reshape_0_pattern, order, reshape_1_pattern, block_size): nodes = { @@ -145,7 +141,7 @@ def get_graphs(input_shape, reshape_0_pattern, order, reshape_1_pattern, block_s return graph, graph_ref - @generate(*[ + @pytest.mark.parametrize("input_shape, reshape_0_pattern, order, reshape_1_pattern, block_size",[ ([1, 512, 7, 6], [1, 2, 2, 128, 7, 6], [0, 1, 4, 2, 5, 3], [1, 128, 14, 12], 2), ([2, 512, 7, 6], [2, 2, 2, 128, 7, 6], [0, 1, 4, 2, 5, 3], [2, 128, 14, 12], 2), ([1, 200, 200, 200], [1, 2, 2, 50, 200, 200], [0, 1, 4, 2, 5, 3], [1, 50, 400, 400], 2), @@ -155,11 +151,11 @@ def test_fusion(self, input_shape, reshape_0_pattern, order, reshape_1_pattern, DepthToSpaceFusion().find_and_replace_pattern(graph) graph.clean_up() (flag, resp) = compare_graphs(graph, graph_ref, 'output') - self.assertTrue(flag, resp) - self.assertTrue(len(graph.get_op_nodes(name='final_reshape')) == 1 and - graph.get_op_nodes(name='final_reshape')[0].op == 'DepthToSpace') + assert flag, resp + assert len(graph.get_op_nodes(name='final_reshape')) == 1 and \ + graph.get_op_nodes(name='final_reshape')[0].op == 'DepthToSpace' - @generate(*[ + @pytest.mark.parametrize("input_shape, reshape_0_pattern, order, reshape_1_pattern, group",[ ([1, 512, 7, 6], [0, 2, 2, 128, 7, 6], [0, 1, 4, 2, 5, 3], [1, 128, 14, 12], 2), ([2, 512, 7, 6], [2, 2, 2, 128, 7, 6], [0, 1, 4, 2, 5, 3], [-1, 128, 14, 12], 2), ([1, 200, 200, 200], [1, 2, 2, 50, 200, 200], [0, 1, 4, 2, 3, 5], [1, 50, 400, 400], 2), @@ -169,4 +165,4 @@ def test_negative(self, input_shape, reshape_0_pattern, order, reshape_1_pattern graph_ref = graph.copy() DepthToSpaceFusion().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'output') - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/convert/import_from_mo_test.py b/tools/mo/unit_tests/mo/convert/import_from_mo_test.py index 603ff6eeb4b06d..a0565fbb0f7132 100644 --- a/tools/mo/unit_tests/mo/convert/import_from_mo_test.py +++ b/tools/mo/unit_tests/mo/convert/import_from_mo_test.py @@ -5,18 +5,16 @@ import tempfile from pathlib import Path -from generator import generator, generate +import pytest from openvino.runtime import serialize from openvino.tools.mo import InputCutInfo, LayoutMap from openvino.tools.mo.utils.ir_engine.ir_engine import IREngine -from unit_tests.mo.unit_test_with_mocked_telemetry import UnitTestWithMockedTelemetry from unit_tests.utils.graph import build_graph from utils import create_onnx_model, save_to_onnx -@generator -class ConvertImportMOTest(UnitTestWithMockedTelemetry): +class TestConvertImportMOTest(): test_directory = os.path.dirname(os.path.realpath(__file__)) @staticmethod @@ -79,7 +77,7 @@ def create_model_ref(): ]) return ref_graph - @generate(*[ + @pytest.mark.parametrize("params",[ ({}), ({'input': InputCutInfo(name='LeakyRelu_out', shape=None, type=None, value=None)}), ({'layout': {'input': LayoutMap(source_layout='NCHW', target_layout='NHWC')}}), diff --git a/tools/mo/unit_tests/mo/convert/meta_data_test.py b/tools/mo/unit_tests/mo/convert/meta_data_test.py index b5e78a15b0f67d..515dfd28ea50b2 100644 --- a/tools/mo/unit_tests/mo/convert/meta_data_test.py +++ b/tools/mo/unit_tests/mo/convert/meta_data_test.py @@ -5,7 +5,6 @@ import tempfile from pathlib import Path -from generator import generator from openvino.runtime import get_version as get_rt_version from openvino.runtime import serialize @@ -18,7 +17,6 @@ from openvino.tools.mo.utils.ir_reader.restore_graph import restore_graph_from_ir, save_restored_graph -@generator class MetaDataTest(UnitTestWithMockedTelemetry): test_directory = os.path.dirname(os.path.realpath(__file__)) diff --git a/tools/mo/unit_tests/mo/front/Pack_test.py b/tools/mo/unit_tests/mo/front/Pack_test.py index efa9a45b5179bb..73ab96db5fc80e 100644 --- a/tools/mo/unit_tests/mo/front/Pack_test.py +++ b/tools/mo/unit_tests/mo/front/Pack_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest import numpy as np -from generator import generator, generate +import pytest from openvino.tools.mo.front.Pack import Pack from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -34,10 +33,10 @@ } -@generator -class PackTest(unittest.TestCase): +class TestPackTest(): - @generate(*[(2, 2, 0), (3, 3, 0), (4, 4, 0), (4, 4, 1), (4, 1, 0), (4, 1, 1)]) + @pytest.mark.parametrize("num_inputs, num_placeholders, axis", [(2, 2, 0), (3, 3, 0), (4, 4, 0), + (4, 4, 1), (4, 1, 0), (4, 1, 1)]) def test_pack_test_all(self, num_inputs: int, num_placeholders: int, axis: list): graph_edges = [] @@ -79,4 +78,4 @@ def test_pack_test_all(self, num_inputs: int, num_placeholders: int, axis: list) replacer.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'last', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/front/common/partial_infer/concat_test.py b/tools/mo/unit_tests/mo/front/common/partial_infer/concat_test.py index a8d8347a050eb3..20edc563d213b7 100644 --- a/tools/mo/unit_tests/mo/front/common/partial_infer/concat_test.py +++ b/tools/mo/unit_tests/mo/front/common/partial_infer/concat_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generate, generator from openvino.tools.mo.front.common.partial_infer.concat import concat_infer from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors @@ -20,9 +19,9 @@ } -@generator -class TestConcatPartialInfer(unittest.TestCase): - @generate(*[([1, 3, 227, 227], [1, 3, 220, 227], [1, 3, 447, 227], 2), +class TestConcatPartialInfer(): + @pytest.mark.parametrize("shape1, shape2, output_shape, axis",[([1, 3, 227, 227], [1, 3, 220, 227], + [1, 3, 447, 227], 2), ([1, 3, 227, 227], [1, 3, 227, 220], [1, 3, 227, 447], -1), ([1, 3, dynamic_dimension_value, 227], [1, dynamic_dimension_value, 227, 220], [1, 3, 227, 447], -1), ([1, 3, 10, 227], [1, 3, 10, dynamic_dimension_value], [1, 3, 10, dynamic_dimension_value], -1), @@ -43,9 +42,10 @@ def test_concat_infer(self, shape1, shape2, output_shape, axis): concat_node = Node(graph, 'concat') concat_infer(concat_node) res_shape = graph.node['node_3']['shape'] - self.assertTrue(strict_compare_tensors(output_shape, res_shape)) + assert strict_compare_tensors(output_shape, res_shape) - @generate(*[(shape_array([1]), shape_array([4]), shape_array([1, 4]), 0), + @pytest.mark.parametrize("value1, value2, output_value, axis",[(shape_array([1]), + shape_array([4]), shape_array([1, 4]), 0), (shape_array([dynamic_dimension_value]), shape_array([4]), shape_array([dynamic_dimension_value, 4]), -1), ]) @@ -65,7 +65,7 @@ def test_concat_value_infer(self, value1, value2, output_value, axis): concat_node = Node(graph, 'concat') concat_infer(concat_node) res_value = graph.node['node_3']['value'] - self.assertTrue(strict_compare_tensors(output_value, res_value)) + assert strict_compare_tensors(output_value, res_value) def test_concat_infer_not_match(self): graph = build_graph(nodes_attributes, @@ -81,7 +81,7 @@ def test_concat_infer_not_match(self): }) concat_node = Node(graph, 'concat') - with self.assertRaisesRegex(Error, "Concat input shapes do not match for node*"): + with pytest.raises(Error, match="Concat input shapes do not match for node*"): concat_infer(concat_node) def test_concat_infer_no_shape(self): @@ -98,5 +98,5 @@ def test_concat_infer_no_shape(self): }) concat_node = Node(graph, 'concat') - with self.assertRaisesRegex(Error, "One of the input shapes is not defined for node *"): + with pytest.raises(Error, match="One of the input shapes is not defined for node *"): concat_infer(concat_node) diff --git a/tools/mo/unit_tests/mo/front/common/partial_infer/eltwise_test.py b/tools/mo/unit_tests/mo/front/common/partial_infer/eltwise_test.py index 7e4bedf454e2e0..1a352dfb19c206 100644 --- a/tools/mo/unit_tests/mo/front/common/partial_infer/eltwise_test.py +++ b/tools/mo/unit_tests/mo/front/common/partial_infer/eltwise_test.py @@ -4,7 +4,7 @@ import unittest import numpy as np -from generator import generator, generate +import pytest from openvino.tools.mo.front.common.partial_infer.eltwise import eltwise_infer, eltwise_reverse_infer from openvino.tools.mo.front.common.partial_infer.utils import shape_array, strict_compare_tensors, \ @@ -24,9 +24,9 @@ } -@generator -class TestEltwiseInfer(unittest.TestCase): - @generate(*[ + +class TestEltwiseInfer(): + @pytest.mark.parametrize("value1, shape1, value2, shape2, shape_infer, exp_value, exp_shape",[ (np.array(2), [], np.array(3), [], lambda a, b: np.multiply(a, b), np.array(6), []), (np.array(2), [], np.array(3), [], lambda a, b: np.maximum(a, b), np.array(3), []), (np.array(2), [], np.array(3), [], lambda a, b: np.add(a, b), np.array(5), []), @@ -67,8 +67,8 @@ def test_eltwise_infer(self, value1, shape1, value2, shape2, shape_infer, exp_va res_shape = graph.node['node_3']['shape'] res_value = eltwise_node.out_node().value if exp_value is not None: - self.assertTrue(strict_compare_tensors(res_value, shape_array(exp_value))) - self.assertTrue(strict_compare_tensors(res_shape, shape_array(exp_shape))) + assert strict_compare_tensors(res_value, shape_array(exp_value)) + assert strict_compare_tensors(res_shape, shape_array(exp_shape)) def test_eltwise_infer_none_val(self): graph = build_graph(nodes_attributes, @@ -89,9 +89,9 @@ def test_eltwise_infer_none_val(self): res_shape = graph.node['node_3']['shape'] res_value = eltwise_node.out_node().value for i in range(0, len(exp_shape)): - self.assertEqual(exp_shape[i], res_shape[i]) + assert exp_shape[i] == res_shape[i] - self.assertIsNone(res_value) + assert res_value is None def test_eltwise_infer_none_min_max(self): graph = build_graph(nodes_attributes, @@ -107,7 +107,7 @@ def test_eltwise_infer_none_min_max(self): graph.graph['layout'] = 'NCHW' eltwise_node = Node(graph, 'eltw_1') - with self.assertRaisesRegex(Error, 'Input shapes mismatch*'): + with pytest.raises(Error, match='Input shapes mismatch*'): eltwise_infer(eltwise_node) diff --git a/tools/mo/unit_tests/mo/front/common/partial_infer/utils_test.py b/tools/mo/unit_tests/mo/front/common/partial_infer/utils_test.py index b6fc90204ac42c..e535d7f8f20603 100644 --- a/tools/mo/unit_tests/mo/front/common/partial_infer/utils_test.py +++ b/tools/mo/unit_tests/mo/front/common/partial_infer/utils_test.py @@ -4,7 +4,7 @@ import unittest import numpy as np -from generator import generator, generate +import pytest from openvino.tools.mo.front.common.partial_infer.utils import int64_array, mo_array, is_fully_defined, \ dynamic_dimension_value, dynamic_dimension, shape_array, compatible_shapes, shape_delete, shape_insert, \ @@ -26,9 +26,8 @@ def gen_masked_array(array, masked_indices): return res -@generator -class IsFullyDefinedTest(unittest.TestCase): - @generate(*[(None, False), +class TestIsFullyDefinedTest(): + @pytest.mark.parametrize("data, result",[(None, False), (int64_array([2, 3, 5, 7]), True), # int64 array with valid values (np.array([2, 3, 5, 7]), True), # any numpy array with valid values (np.array([2, dynamic_dimension_value]), True), # array with dynamic dimension value is fully defined! @@ -42,12 +41,11 @@ class IsFullyDefinedTest(unittest.TestCase): ([dynamic_dimension, 1], False), # list with dynamic dimension is not fully defined ]) def test_is_fully_defined(self, data, result): - self.assertEqual(is_fully_defined(data), result) + assert is_fully_defined(data) == result -@generator -class ShapeArrayTest(unittest.TestCase): - @generate(*[([1], shape_array([1]), True), +class TestShapeArrayTest(): + @pytest.mark.parametrize("data, ref, result",[([1], shape_array([1]), True), # if we provide a list with dynamic_dimension_value then it is converted to dynamic dimension ([dynamic_dimension_value, 5], gen_masked_array([1, 5], [0]), True), # if we provide a list with dynamic_dimension then the generated shape array still have it @@ -56,12 +54,12 @@ class ShapeArrayTest(unittest.TestCase): ([2], gen_masked_array([1], []), False), ]) def test_shape_array(self, data, ref, result): - self.assertEqual(strict_compare_tensors(shape_array(data), ref), result) + assert strict_compare_tensors(shape_array(data), ref) == result -@generator -class CompareShapesTest(unittest.TestCase): - @generate(*[(gen_masked_array([1, 2, 3], []), gen_masked_array([1, 2, 3], []), True), +class TestCompareShapesTest(): + @pytest.mark.parametrize("input1, input2, result",[(gen_masked_array([1, 2, 3], []), + gen_masked_array([1, 2, 3], []), True), (gen_masked_array([4, 2, 3], []), gen_masked_array([1, 2, 3], []), False), (gen_masked_array([1, 2], []), gen_masked_array([1, 2, 3], []), False), (gen_masked_array([1, 2, 3], []), gen_masked_array([1, 2], []), False), @@ -75,12 +73,12 @@ class CompareShapesTest(unittest.TestCase): (np.array([1, 2]), np.array([3, 2]), False), ]) def test_compare_shapes(self, input1, input2, result): - self.assertEqual(compatible_shapes(input1, input2), result) + assert compatible_shapes(input1, input2) == result -@generator -class ShapeDeleteTest(unittest.TestCase): - @generate(*[(gen_masked_array([1, 2, 3], []), [], gen_masked_array([1, 2, 3], [])), +class TestShapeDeleteTest(): + @pytest.mark.parametrize("shape, indices, result",[(gen_masked_array([1, 2, 3], []), [], + gen_masked_array([1, 2, 3], [])), # [1, d, 3] -> [d, 3]. Indices input is a list (gen_masked_array([1, 2, 3], [1]), [0], gen_masked_array([2, 3], [0])), # [1, d, 3] -> [d, 3]. Indices input is a numpy array @@ -103,16 +101,16 @@ class ShapeDeleteTest(unittest.TestCase): (np.array([1, 2, 3, 4]), -2, [1, 2, 4]), # [1, 2, 3, 4] -> [1, 2, 4]. Negative index ]) def test_shape_delete(self, shape, indices, result): - self.assertTrue(strict_compare_tensors(shape_delete(shape, indices), result)) + assert strict_compare_tensors(shape_delete(shape, indices), result) def test_shape_delete_raise_exception(self): - with self.assertRaisesRegex(Error, '.*Incorrect parameter type.*'): + with pytest.raises(Error, match ='.*Incorrect parameter type.*'): shape_delete(gen_masked_array([1, 2, 3], []), {}) -@generator -class ShapeInsertTest(unittest.TestCase): - @generate(*[(gen_masked_array([1, 2, 3], []), 1, [5], gen_masked_array([1, 5, 2, 3], [])), +class TestShapeInsertTest(): + @pytest.mark.parametrize("shape, pos, values, result",[(gen_masked_array([1, 2, 3], []), 1, [5], + gen_masked_array([1, 5, 2, 3], [])), (gen_masked_array([1, 2, 3], [1]), 1, [5], gen_masked_array([1, 5, 2, 3], [2])), (gen_masked_array([1, 2, 3], [1]), 1, [dynamic_dimension], gen_masked_array([1, 5, 2, 3], [1, 2])), (gen_masked_array([1, 2, 3], [1]), 0, [dynamic_dimension], gen_masked_array([5, 1, 2, 3], [0, 2])), @@ -124,26 +122,25 @@ class ShapeInsertTest(unittest.TestCase): (gen_masked_array([1], [0]), 0, [7, dynamic_dimension], gen_masked_array([7, 5, 2], [1, 2])), ]) def test_shape_insert(self, shape, pos, values, result): - self.assertTrue(strict_compare_tensors(shape_insert(shape, pos, values), result)) + assert strict_compare_tensors(shape_insert(shape, pos, values), result) def test_shape_insert_raise_exception(self): - with self.assertRaisesRegex(Error, '.*Incorrect parameter type.*'): + with pytest.raises(Error, match='.*Incorrect parameter type.*'): shape_insert(gen_masked_array([1, 2, 3], []), 2, {}) -@generator -class mo_array_test(unittest.TestCase): - @generate(*[(mo_array([2, 3, 5, 7]), np.array([2, 3, 5, 7])), +class Testmo_array_test(): + @pytest.mark.parametrize("data, result",[(mo_array([2, 3, 5, 7]), np.array([2, 3, 5, 7])), (mo_array([2., 3., 5., 7.], dtype=np.float64), np.array([2., 3., 5., 7.])), (mo_array([2., 3., 5., 7.]), np.array([2., 3., 5., 7.], dtype=np.float32)), ]) def test_mo_array_positive(self, data, result): - self.assertEqual(data.dtype, result.dtype) + assert data.dtype == result.dtype - @generate(*[(mo_array([2., 3., 5., 7.]), np.array([2., 3., 5., 7.])), + @pytest.mark.parametrize("data, result",[(mo_array([2., 3., 5., 7.]), np.array([2., 3., 5., 7.])), ]) def test_mo_array_negative(self, data, result): - self.assertNotEqual(data.dtype, result.dtype) + assert data.dtype != result.dtype class clarify_partial_shape_test(unittest.TestCase): diff --git a/tools/mo/unit_tests/mo/front/interpolate_reshape_test.py b/tools/mo/unit_tests/mo/front/interpolate_reshape_test.py index da55cd415bf8a4..7d62cff4b70d96 100644 --- a/tools/mo/unit_tests/mo/front/interpolate_reshape_test.py +++ b/tools/mo/unit_tests/mo/front/interpolate_reshape_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest import numpy as np -from generator import generator, generate +import pytest from openvino.tools.mo.front.interpolate_reshape import InterpolateWithConcat from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -39,8 +38,7 @@ } -@generator -class TestInterpolateConcat(unittest.TestCase): +class TestInterpolateConcat(): def test_interpolate_concat_reshape_graph_comparison(self): graph = build_graph(nodes, [ *connect('placeholder', '0:interpolate'), @@ -64,7 +62,7 @@ def test_interpolate_concat_reshape_graph_comparison(self): *connect('concat', 'output'), ], nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_interpolate_identity_concat_reshape_graph_comparison(self): graph = build_graph(nodes, [ @@ -97,7 +95,7 @@ def test_interpolate_identity_concat_reshape_graph_comparison(self): *connect('concat', 'output'), ], nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_interpolate_concat_negate(self): graph = build_graph(nodes, [ @@ -120,9 +118,9 @@ def test_interpolate_concat_negate(self): *connect('identity_01', 'output_1'), ], nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp - @generate(*[ + @pytest.mark.parametrize("update_attrs",[ {'concat': {'axis': None}}, {'concat': {'axis': -1}}, @@ -148,7 +146,7 @@ def test_negative_axes_conditions(self, update_attrs): ], update_attributes=update_attrs, nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_interpolate_tf_style_concat(self): graph = build_graph(nodes, [ @@ -161,4 +159,4 @@ def test_interpolate_tf_style_concat(self): graph_ref = graph.copy() InterpolateWithConcat().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/front/kaldi/tdnn_component_replacer_test.py b/tools/mo/unit_tests/mo/front/kaldi/tdnn_component_replacer_test.py index 0b71abb4be8a1b..14385f66b7930b 100644 --- a/tools/mo/unit_tests/mo/front/kaldi/tdnn_component_replacer_test.py +++ b/tools/mo/unit_tests/mo/front/kaldi/tdnn_component_replacer_test.py @@ -1,20 +1,18 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest import numpy as np -from generator import generator, generate +import pytest from openvino.tools.mo.front.kaldi.tdnn_component_replacer import TdnnComponentReplacer from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs from unit_tests.utils.graph import build_graph, regular_op, result, connect_front, const -@generator -class TdnnComponentReplacerTest(unittest.TestCase): +class TestTdnnComponentReplacerTest(): - @generate(*[ + @pytest.mark.parametrize("weights, biases, time_offsets",[ ([[1, 1, 1], [4, 4, 4]], [1, 2], [-1, 1],), ([[1, 1, 1], [4, 4, 4]], [1, 2], [-1, 1, 2, 10, 1000],), ([[1, 1, 1], [4, 4, 4]], [1, 2], [-1, 0]), @@ -72,4 +70,4 @@ def generate_offsets(): TdnnComponentReplacer().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, ref_graph, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/front/mxnet/MXFFTToDFT_test.py b/tools/mo/unit_tests/mo/front/mxnet/MXFFTToDFT_test.py index 31b3f9eb97d89b..d1eb31dc1af674 100644 --- a/tools/mo/unit_tests/mo/front/mxnet/MXFFTToDFT_test.py +++ b/tools/mo/unit_tests/mo/front/mxnet/MXFFTToDFT_test.py @@ -2,9 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 -import unittest - -from generator import generator, generate +import pytest from openvino.tools.mo.front.mxnet.MXFFTToDFT import MXFFTToDFT from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -152,10 +150,8 @@ ('abs', 'output'), ] - -@generator -class MXFFTToDFTTest(unittest.TestCase): - @generate(*[int64_array([3, 100, 100, 8]), int64_array([5, 60])]) +class TestMXFFTToDFTTest(): + @pytest.mark.parametrize("input_shape",[int64_array([3, 100, 100, 8]), int64_array([5, 60])]) def test_fft_replacement(self, input_shape): graph = build_graph(nodes_attrs=fft_graph_node_attrs, edges=fft_graph_edges, @@ -170,9 +166,9 @@ def test_fft_replacement(self, input_shape): 'placeholder': {'shape': input_shape} }) (flag, resp) = compare_graphs(graph, ref_graph, 'output') - self.assertTrue(flag, resp) + assert flag, resp - @generate(*[int64_array([3, 100, 100, 8]), int64_array([5, 60])]) + @pytest.mark.parametrize("input_shape",[int64_array([3, 100, 100, 8]), int64_array([5, 60])]) def test_ifft_replacement(self, input_shape): graph = build_graph(nodes_attrs=fft_graph_node_attrs, edges=fft_graph_edges, @@ -188,4 +184,4 @@ def test_ifft_replacement(self, input_shape): 'placeholder': {'shape': input_shape} }) (flag, resp) = compare_graphs(graph, ref_graph, 'output') - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/front/onnx/AttributedSliceToSlice_test.py b/tools/mo/unit_tests/mo/front/onnx/AttributedSliceToSlice_test.py index edf66a916ed330..e6bbd636b6bc2e 100644 --- a/tools/mo/unit_tests/mo/front/onnx/AttributedSliceToSlice_test.py +++ b/tools/mo/unit_tests/mo/front/onnx/AttributedSliceToSlice_test.py @@ -1,19 +1,17 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.onnx.AttributedSliceToSlice import AttributedSliceToSliceReplacer from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, result, const, connect_front -@generator -class SliceReplacerTest(unittest.TestCase): - @generate(*[ +class TestSliceReplacerTest(): + @pytest.mark.parametrize("attributed_slice_attrs",[ {'op': 'AttributedSlice', 'type': None, 'starts': np.array([0, 0]), 'ends': np.array([1, -1]), 'axes': np.array([0, 1])} ]) def test_attributed_slice_replacer(self, attributed_slice_attrs): @@ -46,4 +44,4 @@ def test_attributed_slice_replacer(self, attributed_slice_attrs): ], nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/front/onnx/activation_ext_test.py b/tools/mo/unit_tests/mo/front/onnx/activation_ext_test.py index ff510b7573c94b..282a92c7629e36 100644 --- a/tools/mo/unit_tests/mo/front/onnx/activation_ext_test.py +++ b/tools/mo/unit_tests/mo/front/onnx/activation_ext_test.py @@ -1,11 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest - import numpy as np import onnx -from generator import generator, generate +import pytest import openvino.tools.mo.front.onnx.activation_ext as extractors from openvino.tools.mo.ops.activation_ops import Elu @@ -15,8 +13,7 @@ from unit_tests.utils.graph import build_graph -@generator -class ActivationOpsONNXExtractorTest(unittest.TestCase): +class TestActivationOpsONNXExtractorTest(): @staticmethod def _create_node(op_name: str): pb = onnx.helper.make_node(op_name, ["X"], ["Y"]) @@ -37,7 +34,7 @@ def _match(self, out, ref): status = out[key] == ref[key] if type(status) in [list, np.ndarray]: status = np.all(status) - self.assertTrue(status, 'Mismatch for field {}, observed: {}, expected: {}'.format(key, out[key], ref[key])) + assert status, f"Mismatch for field {key}, observed: {out[key]}, expected: {ref[key]}" @staticmethod def _extract(op_name): @@ -45,7 +42,7 @@ def _extract(op_name): getattr(extractors, op_name + 'Extractor').extract(node) return node.graph.node[node.id] - @generate(*['Abs', 'Acos', 'Asin', 'Atan', 'Acosh', 'Asinh', 'Atanh', 'Cos', 'Cosh', 'Erf', 'Exp', 'Floor', 'Log', 'Not', 'Sigmoid', 'Sin', + @pytest.mark.parametrize("op_name",['Abs', 'Acos', 'Asin', 'Atan', 'Acosh', 'Asinh', 'Atanh', 'Cos', 'Cosh', 'Erf', 'Exp', 'Floor', 'Log', 'Not', 'Sigmoid', 'Sin', 'Sinh', 'Tan', 'Tanh']) def test_default(self, op_name): ref = self._base_attrs(op_name) @@ -55,8 +52,7 @@ def test_default(self, op_name): self._match(out, ref) -@generator -class TestEluONNXExt(unittest.TestCase): +class TestEluONNXExt(): @staticmethod def _create_elu_node(alpha=1.0): pb = onnx.helper.make_node( @@ -72,7 +68,7 @@ def _create_elu_node(alpha=1.0): def setUpClass(cls): Op.registered_ops['Elu'] = Elu - @generate(*[1.0, 2.0, 3.0]) + @pytest.mark.parametrize("alpha",[1.0, 2.0, 3.0]) def test_elu_ext(self, alpha): node = self._create_elu_node(alpha) extractors.EluExtractor.extract(node) @@ -84,4 +80,4 @@ def test_elu_ext(self, alpha): } for key in exp_res.keys(): - self.assertEqual(node[key], exp_res[key]) + assert node[key] == exp_res[key] diff --git a/tools/mo/unit_tests/mo/front/onnx/squeeze_ext_test.py b/tools/mo/unit_tests/mo/front/onnx/squeeze_ext_test.py index 8dd62f9b1ac86c..a1659794832ebe 100644 --- a/tools/mo/unit_tests/mo/front/onnx/squeeze_ext_test.py +++ b/tools/mo/unit_tests/mo/front/onnx/squeeze_ext_test.py @@ -1,11 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest - import numpy as np import onnx -from generator import generator, generate +import pytest from openvino.tools.mo.front.onnx.squeeze_ext import SqueezeFrontExtractor from openvino.tools.mo.ops.op import Op @@ -13,8 +11,7 @@ from unit_tests.utils.extractors import PB -@generator -class TestSqueezeONNXExt(unittest.TestCase): +class TestSqueezeONNXExt(): @staticmethod def _create_squeeze_node(axes): if axes is None: @@ -38,7 +35,7 @@ def _create_squeeze_node(axes): def setUpClass(cls): Op.registered_ops['Squeeze'] = Squeeze - @generate(*[[0, 1, 2, 3], [1], None]) + @pytest.mark.parametrize("axes",[[0, 1, 2, 3], [1], None]) def test_squeeze_ext(self, axes): node = self._create_squeeze_node(axes) SqueezeFrontExtractor.extract(node) @@ -50,6 +47,6 @@ def test_squeeze_ext(self, axes): for key in exp_res.keys(): if type(node[key]) in [list, np.ndarray]: - self.assertTrue(np.array_equal(np.array(node[key]), np.array(exp_res[key]))) + assert np.array_equal(np.array(node[key]), np.array(exp_res[key])) else: - self.assertEqual(node[key], exp_res[key]) + assert node[key] == exp_res[key] diff --git a/tools/mo/unit_tests/mo/front/onnx/transpose_ext_test.py b/tools/mo/unit_tests/mo/front/onnx/transpose_ext_test.py index c7fdd8c24e9747..c58e4871cb80ec 100644 --- a/tools/mo/unit_tests/mo/front/onnx/transpose_ext_test.py +++ b/tools/mo/unit_tests/mo/front/onnx/transpose_ext_test.py @@ -2,11 +2,10 @@ # SPDX-License-Identifier: Apache-2.0 import itertools -import unittest +import pytest import numpy as np import onnx -from generator import generator, generate from openvino.tools.mo.front.onnx.transpose_ext import TransposeFrontExtractor from openvino.tools.mo.ops.transpose import Transpose @@ -14,8 +13,7 @@ from unit_tests.utils.extractors import PB -@generator -class TestTransposeONNXExt(unittest.TestCase): +class TestTransposeONNXExt(): @staticmethod def _create_transpose_node(order: list): if order is None: @@ -42,7 +40,7 @@ def setUpClass(cls): pass # This generator generates all permutations for [0,1,2,3] and [0,1,2] orders - @generate(*[list(order) for order in list(itertools.permutations(np.arange(4)))] + + @pytest.mark.parametrize("order",[list(order) for order in list(itertools.permutations(np.arange(4)))] + [list(order) for order in list(itertools.permutations(np.arange(3)))] + [None]) def test_transpose_ext(self, order): node = self._create_transpose_node(order) @@ -56,7 +54,7 @@ def test_transpose_ext(self, order): for key in exp_res.keys(): if isinstance(exp_res[key], list): - self.assertTrue(np.array_equal(node[key], exp_res[key]), - "Orders are not the same: {} and {}".format(node[key], exp_res[key])) + assert np.array_equal(node[key], exp_res[key]),\ + "Orders are not the same: {} and {}".format(node[key], exp_res[key]) else: - self.assertEqual(node[key], exp_res[key]) + assert node[key] == exp_res[key] diff --git a/tools/mo/unit_tests/mo/front/onnx/unsqueeze_ext_test.py b/tools/mo/unit_tests/mo/front/onnx/unsqueeze_ext_test.py index 852121cecab936..07a38883d2adeb 100644 --- a/tools/mo/unit_tests/mo/front/onnx/unsqueeze_ext_test.py +++ b/tools/mo/unit_tests/mo/front/onnx/unsqueeze_ext_test.py @@ -1,11 +1,10 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np import onnx -from generator import generator, generate from openvino.tools.mo.front.onnx.unsqueeze_ext import UnsqueezeFrontExtractor from openvino.tools.mo.ops.op import Op @@ -13,8 +12,7 @@ from unit_tests.utils.extractors import PB -@generator -class TestUnsqueezeONNXExt(unittest.TestCase): +class TestUnsqueezeONNXExt(): @staticmethod def _create_unsqueeze_node(axes): if axes is None: @@ -38,7 +36,7 @@ def _create_unsqueeze_node(axes): def setUpClass(cls): Op.registered_ops['Unsqueeze'] = Unsqueeze - @generate(*[[0, 1, 2, 3], [1], []]) + @pytest.mark.parametrize("axes",[[0, 1, 2, 3], [1], []]) def test_unsqueeze_ext(self, axes): node = self._create_unsqueeze_node(axes) UnsqueezeFrontExtractor.extract(node) @@ -49,6 +47,6 @@ def test_unsqueeze_ext(self, axes): for key in exp_res.keys(): if type(node[key]) in [list, np.ndarray]: - self.assertTrue(np.array_equal(np.array(node[key]), np.array(exp_res[key]))) + assert np.array_equal(np.array(node[key]), np.array(exp_res[key])) else: - self.assertEqual(node[key], exp_res[key]) + assert node[key] == exp_res[key] diff --git a/tools/mo/unit_tests/mo/front/rank_decomposer_test.py b/tools/mo/unit_tests/mo/front/rank_decomposer_test.py index b068dfcfead9f0..2b7fb690f33080 100644 --- a/tools/mo/unit_tests/mo/front/rank_decomposer_test.py +++ b/tools/mo/unit_tests/mo/front/rank_decomposer_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.rank_decomposer import RankDecomposer from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -24,10 +23,9 @@ } -@generator -class RankDecomposerTest(unittest.TestCase): +class TestRankDecomposerTest(): - @generate(np.int32, np.int64) + @pytest.mark.parametrize("output_type", [np.int32, np.int64]) def test_rank_decomposer(self, output_type): graph = build_graph(nodes_attrs=nodes(output_type), edges=[ *connect('input', 'rank'), @@ -44,9 +42,9 @@ def test_rank_decomposer(self, output_type): ], nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) - self.assertEqual(graph.get_op_nodes(type='Squeeze')[0]['name'], 'my_rank', - 'Name is not inherited from original node for RankDecomposer') + assert flag, resp + assert graph.get_op_nodes(type='Squeeze')[0]['name'] == 'my_rank',\ + 'Name is not inherited from original node for RankDecomposer' print(output_type) def test_rank_decomposer_assertion(self): @@ -54,4 +52,5 @@ def test_rank_decomposer_assertion(self): *connect('input', 'rank'), *connect('rank', 'output'), ], nodes_with_edges_only=True) - self.assertRaises(AssertionError, RankDecomposer().find_and_replace_pattern, graph) + with pytest.raises(AssertionError): + RankDecomposer().find_and_replace_pattern (graph) diff --git a/tools/mo/unit_tests/mo/front/size_replacer_test.py b/tools/mo/unit_tests/mo/front/size_replacer_test.py index 0ad4dbdcfd5803..75288d4b580cb1 100644 --- a/tools/mo/unit_tests/mo/front/size_replacer_test.py +++ b/tools/mo/unit_tests/mo/front/size_replacer_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.SizeReplacer import SizeFrontReplacer from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -23,10 +22,9 @@ } -@generator -class SizeReplacerTest(unittest.TestCase): +class TestSizeReplacerTest(): - @generate(np.int32, np.int64) + @pytest.mark.parametrize("output_type" ,[np.int32, np.int64]) def test_size_replacer(self, output_type): graph = build_graph(nodes_attrs=nodes(output_type), edges=[ *connect('input', 'size'), @@ -42,9 +40,9 @@ def test_size_replacer(self, output_type): ], nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) - self.assertEqual(graph.get_op_nodes(type='ReduceProd')[0]['name'], 'my_size', - 'Name is not inherited from original node for SizeReplacer') + assert flag, resp + assert graph.get_op_nodes(type='ReduceProd')[0]['name'] == 'my_size',\ + 'Name is not inherited from original node for SizeReplacer' print(output_type) def test_size_replacer_assertion(self): @@ -52,4 +50,5 @@ def test_size_replacer_assertion(self): *connect('input', 'size'), *connect('size', 'output'), ], nodes_with_edges_only=True) - self.assertRaises(AssertionError, SizeFrontReplacer().find_and_replace_pattern, graph) + with pytest.raises(AssertionError): + SizeFrontReplacer().find_and_replace_pattern (graph) diff --git a/tools/mo/unit_tests/mo/front/tf/CorrectPaddingsForPadAfterComplex_test.py b/tools/mo/unit_tests/mo/front/tf/CorrectPaddingsForPadAfterComplex_test.py index 744f5585b8e573..687cb9401026b8 100644 --- a/tools/mo/unit_tests/mo/front/tf/CorrectPaddingsForPadAfterComplex_test.py +++ b/tools/mo/unit_tests/mo/front/tf/CorrectPaddingsForPadAfterComplex_test.py @@ -5,7 +5,6 @@ import unittest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.tf.CorrectPaddingsForPadAfterComplex import CorrectPaddingsForPadAfterComplex from openvino.tools.mo.front.common.partial_infer.utils import int64_array diff --git a/tools/mo/unit_tests/mo/front/tf/ObjectDetectionAPI_test.py b/tools/mo/unit_tests/mo/front/tf/ObjectDetectionAPI_test.py index 44ecbe6b265ca7..235a43b540655f 100644 --- a/tools/mo/unit_tests/mo/front/tf/ObjectDetectionAPI_test.py +++ b/tools/mo/unit_tests/mo/front/tf/ObjectDetectionAPI_test.py @@ -6,7 +6,7 @@ from unittest.mock import patch import os -from generator import generator, generate +import pytest from openvino.tools.mo.front.tf.ObjectDetectionAPI import calculate_shape_keeping_aspect_ratio, \ calculate_placeholder_spatial_shape, ObjectDetectionAPIPreprocessor2Replacement @@ -31,12 +31,11 @@ def get_param(self, param: str): return self._model_params[param] -@generator -class TestCalculateShape(unittest.TestCase): +class TestCalculateShape(): min_size = 600 max_size = 1024 - @generate(*[(100, 300, 341, 1024), + @pytest.mark.parametrize("h, w, th, tw",[(100, 300, 341, 1024), (100, 600, 171, 1024), (100, 3000, 34, 1024), (300, 300, 600, 600), @@ -53,7 +52,7 @@ class TestCalculateShape(unittest.TestCase): (2000, 1800, 667, 600), ]) def test_calculate_shape(self, h, w, th, tw): - self.assertTupleEqual(calculate_shape_keeping_aspect_ratio(h, w, self.min_size, self.max_size), (th, tw)) + assert calculate_shape_keeping_aspect_ratio(h, w, self.min_size, self.max_size) == (th, tw) class TestCalculatePlaceholderSpatialShape(unittest.TestCase): diff --git a/tools/mo/unit_tests/mo/front/tf/RFFTRealImagToRFFTSplit_test.py b/tools/mo/unit_tests/mo/front/tf/RFFTRealImagToRFFTSplit_test.py index 15ec580b118d26..1dfb957c747ce2 100644 --- a/tools/mo/unit_tests/mo/front/tf/RFFTRealImagToRFFTSplit_test.py +++ b/tools/mo/unit_tests/mo/front/tf/RFFTRealImagToRFFTSplit_test.py @@ -1,10 +1,7 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 - -import unittest - -from generator import generator, generate +import pytest from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.tf.RFFTRealImagToRFFTSplit import RFFTRealImagToRDFTSplit @@ -85,9 +82,8 @@ ] -@generator -class RFFTRealImagToRFFTSplitTest(unittest.TestCase): - @generate(*[1, 2, 3]) +class TestRFFTRealImagToRFFTSplitTest(): + @pytest.mark.parametrize("num_of_dims",[1, 2, 3]) def test_replacement(self, num_of_dims): graph = build_graph(nodes_attrs=graph_node_attrs, edges=graph_edges, @@ -102,4 +98,4 @@ def test_replacement(self, num_of_dims): 'rfft': {'num_of_dimensions': num_of_dims} }) (flag, resp) = compare_graphs(graph, ref_graph, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/front/tf/TFFFTToDFT_test.py b/tools/mo/unit_tests/mo/front/tf/TFFFTToDFT_test.py index b5e5d234a0cf50..2464b8679d8117 100644 --- a/tools/mo/unit_tests/mo/front/tf/TFFFTToDFT_test.py +++ b/tools/mo/unit_tests/mo/front/tf/TFFFTToDFT_test.py @@ -2,9 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 -import unittest - -from generator import generator, generate +import pytest from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.tf.TFFFTToDFT import TFFFTToDFT @@ -83,9 +81,8 @@ ] -@generator -class TFFFTToDFTTest(unittest.TestCase): - @generate(*[(2, 'DFT', int64_array([-2, -1])), +class TestTFFFTToDFTTest(): + @pytest.mark.parametrize("num_of_dimensions, dft_type, fft_axes",[(2, 'DFT', int64_array([-2, -1])), (2, 'IDFT', int64_array([-2, -1])), (1, 'DFT', int64_array([-1])), (1, 'IDFT', int64_array([-1])), @@ -113,9 +110,9 @@ def test_replacement(self, num_of_dimensions, dft_type, fft_axes): 'fft_axes': {'value': fft_axes, 'shape': int64_array(fft_axes.shape)}, }) (flag, resp) = compare_graphs(graph, ref_graph, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp - @generate(*[ + @pytest.mark.parametrize("num_of_dims, fft_kind, fft_axes, input_shape, signal_size",[ (2, 'RDFT', int64_array([-2, -1]), int64_array([3, 100, 100]), int64_array([100, -1])), (2, 'IRDFT', int64_array([-2, -1]), int64_array([3, 100, 100, 2]), int64_array([100, -1])), (2, 'RDFT', int64_array([-2, -1]), int64_array([3, 100, 100]), int64_array([95, 116])), @@ -159,4 +156,4 @@ def test_replacement_for_signal_size(self, num_of_dims, fft_kind, fft_axes, inpu 'fft_axes': {'value': fft_axes, 'shape': int64_array(fft_axes.shape)}, }) (flag, resp) = compare_graphs(graph, ref_graph, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/front/tf/WhereDecomposition_test.py b/tools/mo/unit_tests/mo/front/tf/WhereDecomposition_test.py index 0247ab46e5530f..22dc6a4d44e2a8 100644 --- a/tools/mo/unit_tests/mo/front/tf/WhereDecomposition_test.py +++ b/tools/mo/unit_tests/mo/front/tf/WhereDecomposition_test.py @@ -1,12 +1,10 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate - from openvino.tools.mo.front.tf.WhereDecomposition import WhereDecomposition from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs @@ -64,9 +62,8 @@ ] -@generator -class TFWhereDecompositionTest(unittest.TestCase): - @generate(*[[1, 100, 120, 150], [16, 125, 14]]) +class TestTFWhereDecompositionTest(): + @pytest.mark.parametrize("input_shape",[[1, 100, 120, 150], [16, 125, 14]]) def test_1(self, input_shape): in_shape = int64_array(input_shape) graph = build_graph(graph_node_attrs, @@ -81,4 +78,4 @@ def test_1(self, input_shape): 'placeholder_data': {'shape': in_shape} }) (flag, resp) = compare_graphs(graph, ref_graph, 'output') - self.assertTrue(flag, resp) + assert flag,resp diff --git a/tools/mo/unit_tests/mo/front/tf/identityN_to_identity_test.py b/tools/mo/unit_tests/mo/front/tf/identityN_to_identity_test.py index 1c736ddb6edb2e..7a9ba24cc515e9 100644 --- a/tools/mo/unit_tests/mo/front/tf/identityN_to_identity_test.py +++ b/tools/mo/unit_tests/mo/front/tf/identityN_to_identity_test.py @@ -14,12 +14,12 @@ **regular_op_with_shaped_data('placeholder_0', [1, 227, 227, 3], {'type': 'Parameter'}), **regular_op_with_shaped_data('placeholder_1', [1, 227, 227, 3], {'type': 'Parameter'}), - **regular_op_with_empty_data('identityN', {'op': 'IdentityN', 'type': None, 'data_types': [np.int32, np.float], + **regular_op_with_empty_data('identityN', {'op': 'IdentityN', 'type': None, 'data_types': [np.int32, np.float32], 'name': 'my_identity'}), **empty_data('identityN_1_d'), **regular_op_with_empty_data('identity0', {'op': 'Identity', 'type': None, 'data_type': np.int32, 'name': 'my_identity/0_port'}), - **regular_op_with_empty_data('identity1', {'op': 'Identity', 'type': None, 'data_type': np.float, + **regular_op_with_empty_data('identity1', {'op': 'Identity', 'type': None, 'data_type': np.float32, 'name': 'my_identity/1_port'}), **result('output0'), diff --git a/tools/mo/unit_tests/mo/graph/graph_test.py b/tools/mo/unit_tests/mo/graph/graph_test.py index e106c3ee8065c6..3611c9c4c5faf3 100644 --- a/tools/mo/unit_tests/mo/graph/graph_test.py +++ b/tools/mo/unit_tests/mo/graph/graph_test.py @@ -4,7 +4,7 @@ import unittest import numpy as np -from generator import generator, generate +import pytest from openvino.tools.mo.graph.graph import Node, Graph, add_opoutput, dict_includes_compare_attrs, get_edge_attribute_between_nodes, \ set_edge_attribute_between_nodes @@ -364,8 +364,7 @@ def test_check_shape_consistency_2(self): graph.check_shapes_consistency() -@generator -class TestGraphPortsChecker(unittest.TestCase): +class TestGraphPortsChecker(): nodes = { '0': {'type': 'Parameter', 'value': None, 'kind': 'op', 'op': 'Parameter'}, '0_data': {'value': None, 'shape': None, 'kind': 'data'}, @@ -380,7 +379,7 @@ class TestGraphPortsChecker(unittest.TestCase): '3_data': {'value': None, 'shape': None, 'kind': 'data'}, } - @generate(*[('0', 'in', 1), ('0', 'out', 2), ('1', 'in', 2), ('3', 'out', 2)]) + @pytest.mark.parametrize("node_id, port_type, port_idx",[('0', 'in', 1), ('0', 'out', 2), ('1', 'in', 2), ('3', 'out', 2)]) def test_check_shape_consistency_1(self, node_id: str, port_type: str, port_idx: int): # # ,->2-->2_data---,->3-->3_data @@ -404,7 +403,7 @@ def test_check_shape_consistency_1(self, node_id: str, port_type: str, port_idx: else: node.add_output_port(idx=port_idx) - with self.assertRaisesRegex(Error, "Node {} has not consecutive {} ports indexes:.*".format(node_id, + with pytest.raises (Error, match= "Node {} has not consecutive {} ports indexes:.*".format(node_id, port_type)): graph.check_nodes_ports_are_consecutive() @@ -1864,4 +1863,5 @@ def test_sort_with_start_node(self): stat_node = Node(graph, "E") nodes_names = [node.name for node in graph.pseudo_topological_sort_with_start_node(start_node=stat_node, reverse=True)] - assert nodes_names == ['E'] \ No newline at end of file + assert nodes_names == ['E'] + \ No newline at end of file diff --git a/tools/mo/unit_tests/mo/middle/ConvertGroupedStridedSlice_test.py b/tools/mo/unit_tests/mo/middle/ConvertGroupedStridedSlice_test.py index 4eb09947a85f36..edaebbf1ee1554 100644 --- a/tools/mo/unit_tests/mo/middle/ConvertGroupedStridedSlice_test.py +++ b/tools/mo/unit_tests/mo/middle/ConvertGroupedStridedSlice_test.py @@ -4,7 +4,7 @@ import unittest import numpy as np -from generator import generator, generate +import pytest from openvino.tools.mo.middle.ConvertGroupedStridedSlice import ConvertGroupedStridedSlice from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value @@ -108,8 +108,7 @@ ] -@generator -class ConvertGroupedStridedSliceTests(unittest.TestCase): +class TestConvertGroupedStridedSliceTests(): def test_1(self): graph = build_graph(nodes_attributes, [('placeholder_1', 'placeholder_1_data'), @@ -172,7 +171,7 @@ def test_1(self): ConvertGroupedStridedSlice().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_2(self): graph = build_graph(nodes_attributes, @@ -236,7 +235,7 @@ def test_2(self): pattern.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # Intersection of split ranges in feature dimension def test_3_neg(self): @@ -307,7 +306,7 @@ def test_3_neg(self): pattern.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # Split range overflow in feature dimension def test_4_neg(self): @@ -377,7 +376,7 @@ def test_4_neg(self): ConvertGroupedStridedSlice().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # Split(1,H,W,54)--->Fake_data (1,H,W,1) # |`---->Sslice1_out (1,H,W,18) @@ -447,7 +446,7 @@ def test_5(self): ConvertGroupedStridedSlice().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # Split(1,H,W,54) # |`---->Sslice1_out (1,H,W,(0,18)) @@ -511,7 +510,7 @@ def test_6(self): ConvertGroupedStridedSlice().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_7_neg(self): graph = build_graph(nodes_attributes, @@ -567,7 +566,7 @@ def test_7_neg(self): pattern.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # Split(1,54,W,C) # |`---->Sslice1_out (1,(0,18),W,C) @@ -628,10 +627,10 @@ def test_8(self): pattern.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # Test for the case when there is only 1 StridedSlice. - @generate(*[(np.array([1, 227, 227, 54]), + @pytest.mark.parametrize("input_shape, slices, output_shape",[(np.array([1, 227, 227, 54]), np.array([slice(0, 1, 1), slice(0, 227, 1), slice(0, 227, 1), slice(0, 18, 1)]), np.array([1, 227, 227, 18])), (np.array([57, 16, 100, 23]), @@ -659,7 +658,7 @@ def test_9(self, input_shape, slices, output_shape): pattern = ConvertGroupedStridedSlice() pattern.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'op_output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # Test for case when # 1) There are 4 StridedSlice operations. @@ -763,7 +762,7 @@ def test_10(self): pattern = ConvertGroupedStridedSlice() pattern.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # dynamic slice def test_11(self): @@ -804,7 +803,7 @@ def test_11(self): pattern.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # one unuque StridedSlice def test_12(self): @@ -841,9 +840,9 @@ def test_12(self): pattern.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'sslice_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp (flag, resp) = compare_graphs(graph, graph_ref, 'sslice_2_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp class AddReshapeAfterStridedSliceTests(unittest.TestCase): diff --git a/tools/mo/unit_tests/mo/middle/FusedBatchNormTraining_test.py b/tools/mo/unit_tests/mo/middle/FusedBatchNormTraining_test.py index a58cfcecf679ca..e997e57b61471e 100644 --- a/tools/mo/unit_tests/mo/middle/FusedBatchNormTraining_test.py +++ b/tools/mo/unit_tests/mo/middle/FusedBatchNormTraining_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.middle.FusedBatchNormTraining import FusedBatchNormTraining from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -71,9 +70,8 @@ } -@generator -class FusedBatchNormTrainingTest(unittest.TestCase): - @generate(*[ +class TestFusedBatchNormTrainingTest(): + @pytest.mark.parametrize("op",[ 'FusedBatchNorm', 'FusedBatchNormV2', 'FusedBatchNormV3', ]) def test_transformation(self, op: str): @@ -137,7 +135,7 @@ def test_transformation(self, op: str): graph_ref.nodes['batchnorm']['op'] = op (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_non_training(self): graph = build_graph(nodes_attributes, @@ -161,4 +159,4 @@ def test_non_training(self): shape_inference(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/middle/L2NormFusing_test.py b/tools/mo/unit_tests/mo/middle/L2NormFusing_test.py index f952d60daacfe5..b5620a71b582ca 100644 --- a/tools/mo/unit_tests/mo/middle/L2NormFusing_test.py +++ b/tools/mo/unit_tests/mo/middle/L2NormFusing_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.middle.L2NormFusing import L2NormToNorm from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -67,9 +66,9 @@ ] -@generator -class L2NormToNormTest(unittest.TestCase): - @generate(*[(int64_array([2, 3]), int64_array([1]), 'NCHW'), # NC layout, normalize C dimension +class TestL2NormToNormTest(): + @pytest.mark.parametrize("input_shape, axes, layout", + [(int64_array([2, 3]), int64_array([1]), 'NCHW'), # NC layout, normalize C dimension (int64_array([2, 3]), int64_array([1]), 'NHWC'), # NC layout, normalize C dimension (int64_array([2, 3, 5]), int64_array([1]), 'NCHW'), # NCH layout, normalize C dimension (int64_array([2, 3, 5]), int64_array([1]), 'NHWC'), # NCH layout, normalize C dimension @@ -102,10 +101,11 @@ def test_positive(self, input_shape, axes, layout): ], edges_after_replacement, nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(graph.node[graph.get_nodes_with_attributes(type='NormalizeL2')[0]]['name'] == 'l2_norm_name') - self.assertTrue(flag, resp) + assert (graph.node[graph.get_nodes_with_attributes(type='NormalizeL2')[0]]['name'] == 'l2_norm_name') + assert flag, resp - @generate(*[(int64_array([2]), int64_array([0]), 'NCHW'), + @pytest.mark.parametrize("input_shape, axes, layout", + [(int64_array([2]), int64_array([0]), 'NCHW'), (int64_array([2, 3]), int64_array([0]), 'NCHW'), (int64_array([2, 3]), int64_array([0]), 'NHWC'), (int64_array([2, 3]), int64_array([0, 1]), 'NCHW'), @@ -161,4 +161,4 @@ def test_negative(self, input_shape, axes, layout): ], edges, nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/middle/PreserveRuntimeInfo_test.py b/tools/mo/unit_tests/mo/middle/PreserveRuntimeInfo_test.py index 11ec3cc69ae941..393b4f7bac6c85 100644 --- a/tools/mo/unit_tests/mo/middle/PreserveRuntimeInfo_test.py +++ b/tools/mo/unit_tests/mo/middle/PreserveRuntimeInfo_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.common.partial_infer.elemental import copy_shape_infer from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -94,9 +93,8 @@ ] -@generator -class PreserveRuntimeInfoTest(unittest.TestCase): - @generate(*[ +class TestPreserveRuntimeInfoTest(): + @pytest.mark.parametrize("nhwc_to_nchw_order, nchw_to_nhwc_order, add_permutation_attrs",[ ([0, 3, 1, 2], [0, 2, 3, 1], True), ([0, 4, 1, 2, 3], [0, 2, 3, 4, 1], True), (None, None, False), @@ -135,19 +133,19 @@ def test_transpose_insert(self, nhwc_to_nchw_order, nchw_to_nhwc_order, add_perm PreserveRuntimeInfo().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'result') - self.assertTrue(flag, resp) + assert flag, resp - self.assertFalse(param_node.has_valid('permute_attrs')) - self.assertFalse(param_node.out_node(0).has_valid('permutation')) + assert not param_node.has_valid('permute_attrs') + assert not param_node.out_node(0).has_valid('permutation') if add_permutation_attrs: rt_info = param_node.rt_info.info old_api_map = rt_info[('old_api_map_order', 0)].info - self.assertTrue(np.array_equal(old_api_map['inverse_order'], nchw_to_nhwc_order)) + assert np.array_equal(old_api_map['inverse_order'], nchw_to_nhwc_order) rt_info = result_node.rt_info.info old_api_map = rt_info[('old_api_map_order', 0)].info - self.assertTrue(np.array_equal(old_api_map['order'], nhwc_to_nchw_order)) + assert np.array_equal(old_api_map['order'], nhwc_to_nchw_order) def test_auto_disable_nhwc_to_nchw(self): shape_len = 4 @@ -173,18 +171,18 @@ def test_auto_disable_nhwc_to_nchw(self): PreserveRuntimeInfo().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'result') - self.assertTrue(flag, resp) + assert flag, resp rt_info = param_node.rt_info.info old_api_map = rt_info[('old_api_map_order', 0)].info - self.assertTrue(np.array_equal(old_api_map['inverse_order'], [0, 2, 3, 1])) + assert np.array_equal(old_api_map['inverse_order'], [0, 2, 3, 1]) rt_info = result_node.rt_info.info old_api_map = rt_info[('old_api_map_order', 0)].info - self.assertTrue(np.array_equal(old_api_map['order'], [0, 3, 1, 2])) + assert np.array_equal(old_api_map['order'], [0, 3, 1, 2]) - @generate(*[ - ([0, 3, 1, 2], [0, 2, 3, 1], True, 'DFT'), + @pytest.mark.parametrize("nhwc_to_nchw_order, nchw_to_nhwc_order,add_permutation_attrs, fft_kind", + [([0, 3, 1, 2], [0, 2, 3, 1], True, 'DFT'), ([0, 3, 1, 2], [0, 2, 3, 1], True, 'IDFT'), (None, None, False, 'DFT'), (None, None, False, 'IDFT'), @@ -235,12 +233,12 @@ def test_transpose_insert_with_two_result_nodes(self, nhwc_to_nchw_order, nchw_t PreserveRuntimeInfo().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'result1') - self.assertTrue(flag, resp) + assert flag, resp - self.assertFalse(param1_node.has_valid('permute_attrs')) - self.assertFalse(param1_node.out_node(0).has_valid('permutation')) + assert not param1_node.has_valid('permute_attrs') + assert not param1_node.out_node(0).has_valid('permutation') if add_permutation_attrs: rt_info = param1_node.rt_info.info old_api_map = rt_info[('old_api_map_order', 0)].info - self.assertTrue(np.array_equal(old_api_map['inverse_order'], nchw_to_nhwc_order)) + assert np.array_equal(old_api_map['inverse_order'], nchw_to_nhwc_order) diff --git a/tools/mo/unit_tests/mo/middle/UpsampleToResample_test.py b/tools/mo/unit_tests/mo/middle/UpsampleToResample_test.py index 6eff641ccdda1a..e1530ff61d37d7 100644 --- a/tools/mo/unit_tests/mo/middle/UpsampleToResample_test.py +++ b/tools/mo/unit_tests/mo/middle/UpsampleToResample_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.middle.UpsampleToResample import UpsampleToResample from openvino.tools.mo.front.common.partial_infer.utils import int64_array, float32_array @@ -41,7 +40,7 @@ 'ss_stride_data': {'kind': 'data', 'value': int64_array([1]), 'shape': int64_array([1])}, 'strided_slice': {'type': 'StridedSlice', 'kind': 'op', 'op': 'StridedSlice'}, 'strided_slice_data': {'kind': 'data', 'shape': None, 'value': None}, - 'cast_to_float': {'kind': 'op', 'op': 'Cast', 'type': 'Convert', 'dst_type': np.float}, + 'cast_to_float': {'kind': 'op', 'op': 'Cast', 'type': 'Convert', 'dst_type': np.float32}, 'cast_to_float_d': {'kind': 'data', 'value': None, 'shape': None}, 'factor': {'kind': 'op', 'op': 'Const', 'type': 'Const', 'value': int64_array([5, 5]), 'shape': int64_array([2])}, 'factor_data': {'kind': 'data', 'value': int64_array([5, 5]), 'shape': int64_array([2])}, @@ -105,7 +104,7 @@ 'ss_end_data': {'kind': 'data', 'value': None, 'shape': None}, 'ss_stride': {'kind': 'op', 'op': 'Const', 'type': 'Const', 'value': int64_array([1]), 'shape': int64_array([1])}, 'ss_stride_data': {'kind': 'data', 'value': None, 'shape': None}, - 'cast_to_float': {'kind': 'op', 'op': 'Cast', 'type': 'Convert', 'dst_type': np.float}, + 'cast_to_float': {'kind': 'op', 'op': 'Cast', 'type': 'Convert', 'dst_type': np.float32}, 'cast_to_float_d': {'kind': 'data', 'value': None, 'shape': None}, 'mul': {'type': 'Multiply', 'kind': 'op', 'op': 'Multiply'}, 'mul_data': {'kind': 'data', 'shape': None, 'value': None}, @@ -143,9 +142,8 @@ ] -@generator -class UpsampleToResampleTest(unittest.TestCase): - @generate(*[([2, 10, 20, 30], [1, 1, 5, 5], [2, 3]), +class TestUpsampleToResampleTest(): + @pytest.mark.parametrize("input_shape, scales, axes",[([2, 10, 20, 30], [1, 1, 5, 5], [2, 3]), ([2, 20, 30, 40], [1, 1, 3, 3], [2, 3]), ([2, 10, 20, 30], [1, 1, 6, 5], [2, 3]), ([2, 20, 30, 40], [1, 1, 3, 4], [2, 3]), @@ -193,9 +191,9 @@ def test_conversion(self, input_shape, scales, axes): }) UpsampleToResample().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, ref_graph, 'output') - self.assertTrue(flag, resp) + assert flag, resp - @generate(*[([2, 10, 20, 30], [1, 2, 5, 5],), + @pytest.mark.parametrize("input_shape, scales",[([2, 10, 20, 30], [1, 2, 5, 5],), ([2, 3, 20, 30, 40], [1, 2, 3, 3, 3],), ]) def test_pattern_does_not_satisfy(self, input_shape, scales): @@ -214,4 +212,4 @@ def test_pattern_does_not_satisfy(self, input_shape, scales): UpsampleToResample().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, ref_graph, 'output') - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/middle/dequantize_linear_resolver_test.py b/tools/mo/unit_tests/mo/middle/dequantize_linear_resolver_test.py index 065419fe6d475c..de0c363fb9ad49 100644 --- a/tools/mo/unit_tests/mo/middle/dequantize_linear_resolver_test.py +++ b/tools/mo/unit_tests/mo/middle/dequantize_linear_resolver_test.py @@ -9,7 +9,7 @@ from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs from unit_tests.utils.graph import build_graph -from generator import generator, generate +import pytest nodes1_attributes = { 'input': {'kind': 'op', 'op': 'AnyOp'}, @@ -145,9 +145,9 @@ def test_dequantize_no_zerop(self): (flag, resp) = compare_graphs(graph, graph_ref, 'out', check_op_attrs=True) self.assertTrue(flag, resp) -@generator -class TestDequantizeWithAxis(unittest.TestCase): - @generate(*[(int64_array([1, 3, 4, 4]), np.array([2, 3, 4, 5], dtype=np.float32), +class TestDequantizeWithAxis(): + @pytest.mark.parametrize("input_shape, scale_param_value, zero_param_value, target_shape, axis", + [(int64_array([1, 3, 4, 4]), np.array([2, 3, 4, 5], dtype=np.float32), np.array([2, 3, 4, 5], dtype=np.uint8), int64_array([1, 1, 4, 1]), 2), (int64_array([1, 3, 4, 4]), int64_array([2, 3, 4, 5]), np.array([2, 3, 4, 5], dtype=np.uint8), int64_array([1, 3, 1, 1]), 1), @@ -234,4 +234,4 @@ def test_dequantize_with_axis(self, input_shape, scale_param_value, zero_param_v DequantizeLinearResolver().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'out', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/middle/quantize_linear_resolver_test.py b/tools/mo/unit_tests/mo/middle/quantize_linear_resolver_test.py index a6b2aceb871ed1..eaacfe796946d8 100644 --- a/tools/mo/unit_tests/mo/middle/quantize_linear_resolver_test.py +++ b/tools/mo/unit_tests/mo/middle/quantize_linear_resolver_test.py @@ -9,7 +9,7 @@ from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs from unit_tests.utils.graph import build_graph -from generator import generator, generate +import pytest nodes1_attributes = { 'input': {'kind': 'op', 'op': 'AnyOp'}, @@ -247,9 +247,9 @@ def test_quantize_no_zerop(self): self.assertTrue(flag, resp) -@generator -class TestQuantizeWithAxis(unittest.TestCase): - @generate(*[(int64_array([1, 3, 4, 4]), np.array([2, 3, 4, 5], dtype=np.float32), +class TestQuantizeWithAxis(): + @pytest.mark.parametrize("input_shape, scale_param_value, zero_param_value,target_shape, in_low, in_high, out_low, out_high, axis", + [(int64_array([1, 3, 4, 4]), np.array([2, 3, 4, 5], dtype=np.float32), np.array([2, 3, 4, 5], dtype=np.uint8), int64_array([1, 1, 4, 1]), np.array([-2., -3., -4., -5.]), np.array([253., 252., 251., 250.]), 0, 255, 2), @@ -366,4 +366,4 @@ def test_quantize_with_axis(self, input_shape, scale_param_value, zero_param_val QuantizeLinearResolver().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/ops/Complex_test.py b/tools/mo/unit_tests/mo/ops/Complex_test.py index 48e37c04c39c78..4fcd8a61e610c3 100644 --- a/tools/mo/unit_tests/mo/ops/Complex_test.py +++ b/tools/mo/unit_tests/mo/ops/Complex_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.graph.graph import Node @@ -31,9 +30,8 @@ ] -@generator -class TestComplexOp(unittest.TestCase): - @generate(*[ +class TestComplexOp(): + @pytest.mark.parametrize("input_shape, output_shape",[ ([1, 260, 100, 150], [1, 260, 100, 150, 2]), ([1, 260, 100], [1, 260, 100, 2]), ([5, 14, 300, 40], [5, 14, 300, 40, 2]), @@ -52,5 +50,5 @@ def test_complex_op_shape_inference(self, input_shape, output_shape): msg = "Complex operation infer failed for case: expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['complex_data']['shape'], int64_array(output_shape)), - msg.format(output_shape, graph.node['complex_data']['shape'])) + assert np.array_equal(graph.node['complex_data']['shape'], int64_array(output_shape)),\ + msg.format(output_shape, graph.node['complex_data']['shape']) diff --git a/tools/mo/unit_tests/mo/ops/ExtractImagePatches_test.py b/tools/mo/unit_tests/mo/ops/ExtractImagePatches_test.py index 91ea30aa25f5be..89632480a0f809 100644 --- a/tools/mo/unit_tests/mo/ops/ExtractImagePatches_test.py +++ b/tools/mo/unit_tests/mo/ops/ExtractImagePatches_test.py @@ -1,10 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 - -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.ExtractImagePatches import ExtractImagePatches from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -26,9 +24,8 @@ ('EIP_data', 'output'), ] -@generator -class TestExtractImagePatchesPartialInfer(unittest.TestCase): - @generate(*[ +class TestExtractImagePatchesPartialInfer(): + @pytest.mark.parametrize("input_shape, sizes, strides, rates, auto_pad, layout, output_shape",[ ([1, 10, 10, 3], [1, 3, 3, 1], [1, 5, 5, 1], [1, 1, 1, 1], 'valid', 'NHWC', [1, 2, 2, 27]), ([1, 10, 10, 3], [1, 3, 3, 1], [1, 5, 5, 1], [1, 2, 2, 1], 'valid', 'NHWC', [1, 2, 2, 27]), ([1, 10, 10, 3], [1, 4, 4, 1], [1, 8, 8, 1], [1, 1, 1, 1], 'valid', 'NHWC', [1, 1, 1, 48]), @@ -65,4 +62,4 @@ def test_eip_infer(self, input_shape, sizes, strides, rates, auto_pad, layout, o eip_node = Node(graph, 'EIP') ExtractImagePatches.infer(eip_node) - self.assertTrue(np.array_equal(eip_node.out_port(0).data.get_shape(), output_shape)) + assert np.array_equal(eip_node.out_port(0).data.get_shape(), output_shape) diff --git a/tools/mo/unit_tests/mo/ops/If_test.py b/tools/mo/unit_tests/mo/ops/If_test.py index 4ced43aec82f3d..fcc457831bd230 100644 --- a/tools/mo/unit_tests/mo/ops/If_test.py +++ b/tools/mo/unit_tests/mo/ops/If_test.py @@ -1,11 +1,10 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np import numpy.testing as npt -from generator import generate, generator from openvino.tools.mo.ops.If import If from openvino.tools.mo.ops.elementwise import Add, Mul @@ -22,9 +21,8 @@ empty_data -@generator -class TestIf(unittest.TestCase): - @generate(*[ +class TestIf(): + @pytest.mark.parametrize("cond, output_port_0_shape, output_port_1_shape",[ (np.array([True], dtype=bool), shape_array([3]), shape_array([3])), (np.array([False], dtype=bool), shape_array([3]), shape_array([2])), (shape_array(dynamic_dimension_value), shape_array([3]), shape_array([dynamic_dimension_value])), @@ -94,9 +92,9 @@ def test_simple_shape_inf(self, cond, output_port_0_shape, output_port_1_shape): graph.stage = 'middle' partial_infer(graph) if_node = Node(graph, 'if') - self.assertTrue(strict_compare_tensors(if_node.out_port(0).data.get_shape(), output_port_0_shape)) + assert strict_compare_tensors(if_node.out_port(0).data.get_shape(), output_port_0_shape) # shape of the "then" branch is [3] and shape of the "else" branch is [2], so the output shape is "[dynamic]" - self.assertTrue(strict_compare_tensors(if_node.out_port(1).data.get_shape(), output_port_1_shape)) + assert strict_compare_tensors(if_node.out_port(1).data.get_shape(), output_port_1_shape) def test_fake_results(self): then_graph_nodes = {**valued_const_with_data('fake_const', int64_array(0)), diff --git a/tools/mo/unit_tests/mo/ops/MatMul_test.py b/tools/mo/unit_tests/mo/ops/MatMul_test.py index f1e8c29fe91aeb..319250d89a9a05 100644 --- a/tools/mo/unit_tests/mo/ops/MatMul_test.py +++ b/tools/mo/unit_tests/mo/ops/MatMul_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.MatMul import MatMul from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value @@ -12,8 +11,7 @@ from unit_tests.utils.graph import build_graph_with_attrs -@generator -class TestMatMul(unittest.TestCase): +class TestMatMul(): nodes = [ ('A', {'type': 'Parameter', 'kind': 'op'}), ('A_d', {'kind': 'data'}), @@ -32,7 +30,7 @@ class TestMatMul(unittest.TestCase): ('mat_mul_d', 'op_output'), ] - @generate(*[ + @pytest.mark.parametrize("A_shape, B_shape, C_shape, transpose_a, transpose_b",[ ([1024], [1024, 1000], [1000], False, False), ([dynamic_dimension_value], [1024, 1000], [1000], False, False), ([1024], [dynamic_dimension_value, 1000], [1000], False, False), @@ -65,11 +63,11 @@ def test_positive_matmul_infer(self, A_shape, B_shape, C_shape, transpose_a, tra msg = "MatMul infer failed for case: A_shape={}, B_shape={}, transpose_a={}, transpose_b={} " \ "expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['mat_mul_d']['shape'], shape_array(C_shape)), + assert np.array_equal(graph.node['mat_mul_d']['shape'], shape_array(C_shape)),\ msg.format(A_shape, B_shape, transpose_a, transpose_b, C_shape, - graph.node['mat_mul_d']['shape'])) + graph.node['mat_mul_d']['shape']) - @generate(*[ + @pytest.mark.parametrize("A_shape, B_shape",[ (None, [1024, 1000]), (1, [1024, 1000]), ([], [1024, 1000]), @@ -84,4 +82,5 @@ def test_negative_matmul_infer(self, A_shape, B_shape): ]) node = Node(graph, 'mat_mul') - self.assertRaises(AssertionError, MatMul.infer, node) + with pytest.raises(AssertionError): + MatMul.infer(node) diff --git a/tools/mo/unit_tests/mo/ops/MatMul_value_propagation_test.py b/tools/mo/unit_tests/mo/ops/MatMul_value_propagation_test.py index f71a84d966c737..e845fe5f20a374 100644 --- a/tools/mo/unit_tests/mo/ops/MatMul_value_propagation_test.py +++ b/tools/mo/unit_tests/mo/ops/MatMul_value_propagation_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.MatMul import MatMul, transpose from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -32,9 +31,8 @@ ] -@generator -class TestMatMulValuePropagation(unittest.TestCase): - @generate(*[ +class TestMatMulValuePropagation(): + @pytest.mark.parametrize("a_shape, a_value, b_shape, b_value, transpose_a, transpose_b",[ ([16, 3], np.arange(-5, -5 + 16 * 3).reshape((16, 3)), [3, 5], np.arange(0, 3 * 5).reshape((3, 5)), False, False), @@ -91,4 +89,4 @@ def test_value_propagation(self, a_shape, a_value, b_shape, b_value, transpose_a node_data_shape = node_data.shape ref_data_shape = ref_data.shape msg = "Value propagation for 'matmul' node is not correct." - self.assertTrue(node_data_shape == ref_data_shape and np.all(node_data == ref_data), msg) + assert node_data_shape == ref_data_shape and np.all(node_data == ref_data), msg diff --git a/tools/mo/unit_tests/mo/ops/ONNXResize11_test.py b/tools/mo/unit_tests/mo/ops/ONNXResize11_test.py index 319ccc69dbc233..bf9a42a6b9c0bf 100644 --- a/tools/mo/unit_tests/mo/ops/ONNXResize11_test.py +++ b/tools/mo/unit_tests/mo/ops/ONNXResize11_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.ONNXResize11 import ONNXResize11Op from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -68,9 +67,8 @@ ] -@generator -class TestONNXResize11Op(unittest.TestCase): - @generate(*[([1, 260, 100, 150], [1, 260, 200, 350], [1, 260, 200, 350], [1.0, 1.0, 1.0, 1.0]), +class TestONNXResize11Op(): + @pytest.mark.parametrize("input_shape, output_shape, sizes, scales",[([1, 260, 100, 150], [1, 260, 200, 350], [1, 260, 200, 350], [1.0, 1.0, 1.0, 1.0]), ([1, 260, 100, 150], [1, 260, 200, 350], [1, 1, 200, 350], [1.0, 1.0, 1.0, 1.0]), ([5, 14, 300, 40], [5, 14, 140, 280], [1, 1, 140, 280], [1.0, 1.0, 1.0, 1.0]), ([5, 14, 300, 40], [5, 14, 140, 280], [5, 14, 140, 280], [1.0, 1.0, 1.0, 1.0]), @@ -95,10 +93,11 @@ def test_onnx_resize11_using_sizes(self, input_shape, output_shape, sizes, scale msg = "ONNXResize11 infer failed for case: sizes={}, scales={}, expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)), - msg.format(sizes, scales, output_shape, graph.node['onnx_resize11_data']['shape'])) + assert np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)),\ + msg.format(sizes, scales, output_shape, graph.node['onnx_resize11_data']['shape']) - @generate(*[([1, 260, 100, 150], [1, 260, 200, 350], [1.0, 1.0, 2.0, 350 / 150]), + @pytest.mark.parametrize("input_shape, output_shape, scales", + [([1, 260, 100, 150], [1, 260, 200, 350], [1.0, 1.0, 2.0, 350 / 150]), ([1, 3, 100, 200], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]), ([5, 14, 300, 40], [5, 14, 140, 280], [1.0, 1.0, 140 / 300, 7.0]), ([5, 14, 300, 40], [5, 14, 140, 560], [1.0, 1.0, 140 / 300, 14.0]), @@ -121,10 +120,11 @@ def test_onnx_resize_using_scales(self, input_shape, output_shape, scales): msg = "ONNXResize11 infer failed for case: scales={}, expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)), - msg.format(scales, output_shape, graph.node['onnx_resize11_data']['shape'])) + assert np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)),\ + msg.format(scales, output_shape, graph.node['onnx_resize11_data']['shape']) - @generate(*[([1, 260, 100, 150], [1, 260, 200, 350], [1, 260, 200, 350], [1.0, 1.0, 1.0, 1.0]), + @pytest.mark.parametrize("input_shape, output_shape, sizes, scales", + [([1, 260, 100, 150], [1, 260, 200, 350], [1, 260, 200, 350], [1.0, 1.0, 1.0, 1.0]), ([1, 260, 100, 150], [1, 260, 200, 350], [1, 1, 200, 350], [1.0, 1.0, 1.0, 1.0]), ([5, 14, 300, 40], [5, 14, 140, 280], [1, 1, 140, 280], [1.0, 1.0, 1.0, 1.0]), ([5, 14, 300, 40], [5, 14, 140, 280], [5, 14, 140, 280], [1.0, 1.0, 1.0, 1.0]), @@ -155,10 +155,11 @@ def test_onnx_resize11_using_sizes_without_roi_input(self, input_shape, output_s msg = "ONNXResize11 infer failed for case: sizes={}, scales={}, expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)), - msg.format(sizes, scales, output_shape, graph.node['onnx_resize11_data']['shape'])) + assert np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)),\ + msg.format(sizes, scales, output_shape, graph.node['onnx_resize11_data']['shape']) - @generate(*[([1, 260, 100, 150], [1, 260, 200, 350], [1.0, 1.0, 2.0, 350 / 150]), + @pytest.mark.parametrize("input_shape, output_shape, scales", + [([1, 260, 100, 150], [1, 260, 200, 350], [1.0, 1.0, 2.0, 350 / 150]), ([1, 3, 100, 200], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]), ([5, 14, 300, 40], [5, 14, 140, 280], [1.0, 1.0, 140 / 300, 7.0]), ([5, 14, 300, 40], [5, 14, 140, 560], [1.0, 1.0, 140 / 300, 14.0]), @@ -187,5 +188,5 @@ def test_onnx_resize_using_scales_without_roi(self, input_shape, output_shape, s msg = "ONNXResize11 infer failed for case: scales={}, expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)), - msg.format(scales, output_shape, graph.node['onnx_resize11_data']['shape'])) + assert np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)),\ + msg.format(scales, output_shape, graph.node['onnx_resize11_data']['shape']) diff --git a/tools/mo/unit_tests/mo/ops/ReduceOps_test.py b/tools/mo/unit_tests/mo/ops/ReduceOps_test.py index 8db3a7ab75cd5c..3cfa78c544e910 100644 --- a/tools/mo/unit_tests/mo/ops/ReduceOps_test.py +++ b/tools/mo/unit_tests/mo/ops/ReduceOps_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generate, generator from openvino.tools.mo.ops.ReduceOps import reduce_infer from openvino.tools.mo.front.common.partial_infer.utils import int64_array, strict_compare_tensors, is_fully_defined @@ -21,9 +20,8 @@ } -@generator -class ReduceLpTest(unittest.TestCase): - @generate(*[ +class TestReduceLpTest(): + @pytest.mark.parametrize("shape, axes, keepdims, p",[ ([3, 2, 2], [0], True, 1), ([3, 2, 2], [0], True, 2), ([3, 2, 2], [1], True, 2), @@ -53,9 +51,9 @@ def test_reduce_lp(self, shape, axes, keepdims, p): reduce_node = Node(graph, 'reduce_lp') reduce_node.op = reduce_node.type = 'ReduceL' + str(p) reduce_infer(reduce_node) - self.assertTrue(np.array_equal(reduce_node.out_port(0).data.get_value(), reduced)) + assert np.array_equal(reduce_node.out_port(0).data.get_value(), reduced) - @generate(*[ + @pytest.mark.parametrize("shape, axes, keepdims, p",[ ([3, 2, 2], [0], True, 1), ([3, 2, 2], [2], False, 2), ([3, 2, 2], [0, 2], False, 2), @@ -86,4 +84,4 @@ def test_reduce_dynamic(self, shape, axes, keepdims, p): reduce_node = Node(graph, 'reduce_lp') reduce_node.op = reduce_node.type = 'ReduceL' + str(p) reduce_infer(reduce_node) - self.assertTrue(strict_compare_tensors(reduce_node.out_port(0).data.get_value(), fully_undefined)) + assert strict_compare_tensors(reduce_node.out_port(0).data.get_value(), fully_undefined) diff --git a/tools/mo/unit_tests/mo/ops/broadcast_test.py b/tools/mo/unit_tests/mo/ops/broadcast_test.py index 7da252317a7e3c..72ee2cf5c23d47 100644 --- a/tools/mo/unit_tests/mo/ops/broadcast_test.py +++ b/tools/mo/unit_tests/mo/ops/broadcast_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.common.partial_infer.utils import int64_array, undefined_shape_of_rank from openvino.tools.mo.graph.graph import Node @@ -13,31 +12,30 @@ shaped_data -@generator -class BroadcastTest(unittest.TestCase): - @generate(*[ - ([1], [3, 3], None, 'numpy', [[1, 1, 1], [1, 1, 1], [1, 1, 1]]), - ([1], [3, 3], None, 'numpy'), +class TestBroadcastTest(): + @pytest.mark.parametrize("data, target_shape, axes_mapping, mode, ref_out, test_raising",[ + ([1], [3, 3], None, 'numpy', [[1, 1, 1], [1, 1, 1], [1, 1, 1]], False), + ([1], [3, 3], None, 'numpy', None, False), # shape broadcasting - ([1], [1, 2], [0], 'explicit'), - ([1], [1, 2], [-2], 'explicit'), - ([1, 7], [5, 1, 7, 3], [1, 2], 'explicit'), - ([2, 1, 3], [2, 1, 3, 3], [0, 1, 2], 'explicit'), - ([2, 1, 3], [5, 2, 1, 3], [1, 2, 3], 'explicit'), + ([1], [1, 2], [0], 'explicit', None, False), + ([1], [1, 2], [-2], 'explicit', None, False), + ([1, 7], [5, 1, 7, 3], [1, 2], 'explicit', None, False), + ([2, 1, 3], [2, 1, 3, 3], [0, 1, 2], 'explicit', None, False), + ([2, 1, 3], [5, 2, 1, 3], [1, 2, 3], 'explicit', None, False), # value broadcasting - ([1], [1, 2], [0], 'explicit', [[1, 1]]), + ([1], [1, 2], [0], 'explicit', [[1, 1]], False), - ([[3, 1]], [2, 1, 2], [1, 2], 'explicit', [[[3, 1]], [[3, 1]]]), # ref_shape (2, 1, 2) + ([[3, 1]], [2, 1, 2], [1, 2], 'explicit', [[[3, 1]], [[3, 1]]], False), # ref_shape (2, 1, 2) - ([[3, 1]], [2, 1, 2], [-2, -1], 'explicit', [[[3, 1]], [[3, 1]]]), # ref_shape (2, 1, 2) + ([[3, 1]], [2, 1, 2], [-2, -1], 'explicit', [[[3, 1]], [[3, 1]]], False), # ref_shape (2, 1, 2) ([[[9, 5, 7]], [[9, 5, 7]]], [2, 2, 1, 3], [1, 2, 3], 'explicit', # in_shape (2, 1, 3) - [[[[9, 5, 7]], [[9, 5, 7]]], [[[9, 5, 7]], [[9, 5, 7]]]]), # ref_out_shape (2, 2, 1, 3) + [[[[9, 5, 7]], [[9, 5, 7]]], [[[9, 5, 7]], [[9, 5, 7]]]], False), # ref_out_shape (2, 2, 1, 3) ([[[9, 5, 7]], [[3, 4, 8]]], [2, 1, 3, 3], [0, 1, 2], 'explicit', # in_shape (2, 1, 3) - [[[[9, 9, 9], [5, 5, 5], [7, 7, 7]]], [[[3, 3, 3], [4, 4, 4], [8, 8, 8]]]]), # ref_out_shape (2, 1, 3, 3) + [[[[9, 9, 9], [5, 5, 5], [7, 7, 7]]], [[[3, 3, 3], [4, 4, 4], [8, 8, 8]]]], False), # ref_out_shape (2, 1, 3, 3) # negative tests ([1], [2, 2], [0], 'explicit', None, True), @@ -45,7 +43,7 @@ class BroadcastTest(unittest.TestCase): ([1, 7], [5, 2, 7, 3], [2, 1], 'explicit', None, True), ([1, 7], [5, 2, 7, 3], [-3, -2], 'explicit', None, True), ]) - def test_broadcast(self, data, target_shape, axes_mapping=None, mode='numpy', ref_out=None, test_raising=False): + def test_broadcast(self, data, target_shape, axes_mapping, mode, ref_out, test_raising): if ref_out is not None: input = valued_const_with_data('data', int64_array(data)) else: @@ -68,25 +66,26 @@ def test_broadcast(self, data, target_shape, axes_mapping=None, mode='numpy', re broadcast_node = Node(graph, 'broadcast') if test_raising: - self.assertRaises(AssertionError, Broadcast.infer, broadcast_node) + with pytest.raises(AssertionError): + Broadcast.infer(broadcast_node) return Broadcast.infer(broadcast_node) if ref_out is not None: - self.assertTrue(np.array_equal(broadcast_node.out_node().value, np.array(ref_out))) + assert np.array_equal(broadcast_node.out_node().value, np.array(ref_out)) else: - self.assertTrue(np.array_equal(broadcast_node.out_node().shape, np.array(target_shape))) - - @generate(*[ - ([1], [3], [0], 'explicit', undefined_shape_of_rank(3)), - ([1], [3], None, 'numpy', undefined_shape_of_rank(3)), - ([1], [3], None, 'bidirectional', undefined_shape_of_rank(3)), - ([1, 7], [4], [1, 2], 'explicit', undefined_shape_of_rank(4)), - ([1, 2], [3], None, 'numpy', undefined_shape_of_rank(3)), - ([1, 1], [2], None, 'bidirectional', undefined_shape_of_rank(2)), + assert np.array_equal(broadcast_node.out_node().shape, np.array(target_shape)) + + @pytest.mark.parametrize("data, target_shape_shape, axes_mapping, mode, ref_out_shape, test_raising",[ + ([1], [3], [0], 'explicit', undefined_shape_of_rank(3), False), + ([1], [3], None, 'numpy', undefined_shape_of_rank(3), False), + ([1], [3], None, 'bidirectional', undefined_shape_of_rank(3),False), + ([1, 7], [4], [1, 2], 'explicit', undefined_shape_of_rank(4), False), + ([1, 2], [3], None, 'numpy', undefined_shape_of_rank(3),False), + ([1, 1], [2], None, 'bidirectional', undefined_shape_of_rank(2), False), ([1, 1], [2, 1], None, 'numpy', None, True), ]) - def test_broadcast_dynamic(self, data, target_shape_shape, axes_mapping=None, mode='numpy', ref_out_shape=None, test_raising=False): + def test_broadcast_dynamic(self, data, target_shape_shape, axes_mapping, mode, ref_out_shape, test_raising): nodes = { **shaped_data('data', int64_array(data)), **shaped_data('target_shape', int64_array(target_shape_shape)), @@ -105,8 +104,9 @@ def test_broadcast_dynamic(self, data, target_shape_shape, axes_mapping=None, mo broadcast_node = Node(graph, 'broadcast') if test_raising: - self.assertRaises(AssertionError, Broadcast.infer, broadcast_node) + with pytest.raises(AssertionError): + Broadcast.infer(broadcast_node) return Broadcast.infer(broadcast_node) - self.assertTrue(np.array_equal(broadcast_node.out_node().shape, ref_out_shape)) + assert np.array_equal(broadcast_node.out_node().shape, ref_out_shape) diff --git a/tools/mo/unit_tests/mo/ops/cast_test.py b/tools/mo/unit_tests/mo/ops/cast_test.py index efdf33a4e90db0..73a468e9fb80fa 100644 --- a/tools/mo/unit_tests/mo/ops/cast_test.py +++ b/tools/mo/unit_tests/mo/ops/cast_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.Cast import Cast from openvino.tools.mo.middle.passes.convert_data_type import packed_U4, packed_I4 @@ -19,85 +18,23 @@ } -@generator -class CastTest(unittest.TestCase): +class TestCastTest(): """ Example of checking: - 7 == 0111, padded to 0111 0000, results in 112 - 7 == 0111, 8 == 1000 packed to 0111 1000, results in 120 + 7 == 0111, padded to 00000111, results in 7 + 7 == 0111, 8 == 1000 packed to 10000111, results in 7+16 - -8 == 1000, padded to 1000 0000, results in 128 + -8 == 1000, padded to 00001000, results in 8 """ - @generate(*[ - ([0], [0], packed_U4), - ([1], [16], packed_U4), - ([2], [32], packed_U4), - ([3], [48], packed_U4), - ([4], [64], packed_U4), - ([5], [80], packed_U4), - ([6], [96], packed_U4), - ([7], [112], packed_U4), - ([8], [128], packed_U4), - ([9], [144], packed_U4), - ([10], [160], packed_U4), - ([11], [176], packed_U4), - ([12], [192], packed_U4), - ([13], [208], packed_U4), - ([14], [224], packed_U4), - ([15], [240], packed_U4), - - ([0, 15], [15], packed_U4), - ([1, 14], [30], packed_U4), - ([2, 13], [45], packed_U4), - ([3, 12], [60], packed_U4), - ([4, 11], [75], packed_U4), - ([5, 10], [90], packed_U4), - ([6, 9], [105], packed_U4), - ([7, 8], [120], packed_U4), - ([8, 7], [135], packed_U4), - ([9, 6], [150], packed_U4), - ([10, 5], [165], packed_U4), - ([11, 4], [180], packed_U4), - ([12, 3], [195], packed_U4), - ([13, 2], [210], packed_U4), - ([14, 1], [225], packed_U4), - ([15, 0], [240], packed_U4), - - ([-8], [128], packed_I4), - ([-7], [144], packed_I4), - ([-6], [160], packed_I4), - ([-5], [176], packed_I4), - ([-4], [192], packed_I4), - ([-3], [208], packed_I4), - ([-2], [224], packed_I4), - ([-1], [240], packed_I4), - ([0], [0], packed_I4), - ([1], [16], packed_I4), - ([2], [32], packed_I4), - ([3], [48], packed_I4), - ([4], [64], packed_I4), - ([5], [80], packed_I4), - ([6], [96], packed_I4), - ([7], [112], packed_I4), - - ([-8, 7], [135], packed_I4), - ([-7, 6], [150], packed_I4), - ([-6, 5], [165], packed_I4), - ([-5, 4], [180], packed_I4), - ([-4, 3], [195], packed_I4), - ([-3, 2], [210], packed_I4), - ([-2, 1], [225], packed_I4), - ([-1, 0], [240], packed_I4), - ([0, -1], [15], packed_I4), - ([1, -2], [30], packed_I4), - ([2, -3], [45], packed_I4), - ([3, -4], [60], packed_I4), - ([4, -5], [75], packed_I4), - ([5, -6], [90], packed_I4), - ([6, -7], [105], packed_I4), - ([7, -8], [120], packed_I4), - ]) + @pytest.mark.parametrize("value, expected, custom_dtype", + [([i], [i], packed_U4) for i in range(16)] + + [([i, 15-i], [i + (15-i)*16], packed_U4) for i in range(16)] + + [([-i], [16-i], packed_I4) for i in range(1, 8+1)] + + [([i], [i], packed_I4) for i in range(8)] + + [([-i-1, i], [16-i-1 + 16*i], packed_I4) for i in range(8)] + + [([i, -i-1], [i + 16*(16-i-1)], packed_I4) for i in range(8)] + ) def test_custom_value_propagation(self, value, expected, custom_dtype): graph = build_graph(nodes(value, custom_dtype), [ *connect('value', 'convert'), *connect('convert', 'output'), @@ -110,4 +47,4 @@ def test_custom_value_propagation(self, value, expected, custom_dtype): 'value': expected}}) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/ops/dft_signal_size_canonicalization_test.py b/tools/mo/unit_tests/mo/ops/dft_signal_size_canonicalization_test.py index 23c893bd215ad3..7843b20337140b 100644 --- a/tools/mo/unit_tests/mo/ops/dft_signal_size_canonicalization_test.py +++ b/tools/mo/unit_tests/mo/ops/dft_signal_size_canonicalization_test.py @@ -1,18 +1,16 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.dft import FFTBase from openvino.tools.mo.front.common.partial_infer.utils import int64_array -@generator -class DFTSignalSizeCanonicalizationTest(unittest.TestCase): - @generate(*[ +class TestDFTSignalSizeCanonicalizationTest(): + @pytest.mark.parametrize("signal_size, axes, input_shape, expected_result",[ (int64_array([-1, 77]), int64_array([1, 2]), int64_array([2, 180, 180, 2]), int64_array([180, 77])), (int64_array([390, 87]), int64_array([2, 0]), int64_array([2, 180, 180, 2]), int64_array([390, 87])), (int64_array([600, -1, 40]), @@ -38,4 +36,4 @@ class DFTSignalSizeCanonicalizationTest(unittest.TestCase): ]) def test_canonicalization(self, signal_size, axes, input_shape, expected_result): canonicalized_signal_size = FFTBase.canonicalize_signal_size(signal_size, axes, input_shape) - self.assertTrue(np.array_equal(canonicalized_signal_size, expected_result)) + assert np.array_equal(canonicalized_signal_size, expected_result) diff --git a/tools/mo/unit_tests/mo/ops/div_value_propagation_test.py b/tools/mo/unit_tests/mo/ops/div_value_propagation_test.py index 9202aa08c98d2a..5d68f196e62fc6 100644 --- a/tools/mo/unit_tests/mo/ops/div_value_propagation_test.py +++ b/tools/mo/unit_tests/mo/ops/div_value_propagation_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.elementwise import Div from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -32,9 +31,8 @@ ] -@generator -class TestDivValuePropagation(unittest.TestCase): - @generate(*[ +class TestDivValuePropagation(): + @pytest.mark.parametrize("a_shape, a_value, b_shape, b_value, elem_type",[ ([2, 3], np.array([[1, 4, -6], [0, -16, 45]], dtype=np.int64), [2, 3], np.array([[1, 2, -4], [1, -8, -5]], dtype=np.int64), np.int64), @@ -80,4 +78,4 @@ def func_for_ref(): node_data_shape = node_data.shape ref_data_shape = ref_data.shape msg = "Value propagation for 'div' node is not correct." - self.assertTrue(node_data_shape == ref_data_shape and np.all(node_data == ref_data), msg) + assert node_data_shape == ref_data_shape and np.all(node_data == ref_data), msg diff --git a/tools/mo/unit_tests/mo/ops/einsum_test.py b/tools/mo/unit_tests/mo/ops/einsum_test.py index ad7e81a2c117fa..884f6b5e10c8b6 100644 --- a/tools/mo/unit_tests/mo/ops/einsum_test.py +++ b/tools/mo/unit_tests/mo/ops/einsum_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.einsum import Einsum from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -35,9 +34,8 @@ def create_einsum_graph(input_shapes: list, equation: str) -> Graph: return graph -@generator -class TestEinsum(unittest.TestCase): - @generate(*[ +class TestEinsum(): + @pytest.mark.parametrize("input_shapes, equation, ref_output_shape",[ # dot product ([int64_array([10]), int64_array([10])], "i,i->", int64_array([])), # matrix multiplication @@ -74,22 +72,23 @@ def test_einsum(self, input_shapes, equation, ref_output_shape): # get the result res_output_shape = graph.node['einsum_node_d']['shape'] - self.assertTrue(np.array_equal(ref_output_shape, res_output_shape), - 'shape does not match expected: {} and given: {}'.format(ref_output_shape, res_output_shape)) + assert np.array_equal(ref_output_shape, res_output_shape),\ + 'shape does not match expected: {} and given: {}'.format(ref_output_shape, res_output_shape) - @generate(*[ - # incorrect subscript numbers or inputs - ([int64_array([3, 11]), int64_array([11, 4])], "ab,bc,cd->ac", None), - # invalid labels - ([int64_array([3, 11]), int64_array([11, 4])], "a$,Bc->ac", None), - # incompatible shapes - ([int64_array([3, 11]), int64_array([12, 4])], "ab,bc->ac", None), - # not broadcastable shapes - ([int64_array([11, 1, 4, 3]), int64_array([3, 11, 7, 5])], "a...b,b...->a...", None), - # missed ellipsis - ([int64_array([11, 1, 4, 3]), int64_array([3, 11, 7, 4])], "a...b,b...->a", None), - ]) + @pytest.mark.parametrize("input_shapes, equation, ref_output_shape", [ + # incorrect subscript numbers or inputs + ([int64_array([3, 11]), int64_array([11, 4])], "ab,bc,cd->ac", None), + # invalid labels + ([int64_array([3, 11]), int64_array([11, 4])], "a$,Bc->ac", None), + # incompatible shapes + ([int64_array([3, 11]), int64_array([12, 4])], "ab,bc->ac", None), + # not broadcastable shapes + ([int64_array([11, 1, 4, 3]), int64_array([3, 11, 7, 5])], "a...b,b...->a...", None), + # missed ellipsis + ([int64_array([11, 1, 4, 3]), int64_array([3, 11, 7, 4])], "a...b,b...->a", None), +]) def test_invalid_cases(self, input_shapes, equation, ref_output_shape): graph = create_einsum_graph(input_shapes, equation) einsum_node = Node(graph, 'einsum_node') - self.assertRaises(AssertionError, Einsum.infer, einsum_node) + with pytest.raises(AssertionError): + Einsum.infer(einsum_node) diff --git a/tools/mo/unit_tests/mo/ops/expand_dims_test.py b/tools/mo/unit_tests/mo/ops/expand_dims_test.py index be36d55bd21d97..768fe4077f4a81 100644 --- a/tools/mo/unit_tests/mo/ops/expand_dims_test.py +++ b/tools/mo/unit_tests/mo/ops/expand_dims_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors from openvino.tools.mo.graph.graph import Node @@ -28,9 +27,8 @@ } } -@generator -class ExpandDimsOp(unittest.TestCase): - @generate(*[(0, [1, 2, 3, 224, 224]), +class TestExpandDimsOp(): + @pytest.mark.parametrize("axis, ref_out_shape",[(0, [1, 2, 3, 224, 224]), (1, [2, 1, 3, 224, 224]), (2, [2, 3, 1, 224, 224]), (3, [2, 3, 224, 1, 224]), @@ -45,12 +43,11 @@ def test_expand_dims_infer(self, axis, ref_out_shape): ExpandDims.infer(expand_dims_node) - self.assertTrue(np.array_equal(expand_dims_node.out_node().shape, np.array(ref_out_shape))) + assert np.array_equal(expand_dims_node.out_node().shape, np.array(ref_out_shape)) -@generator -class ExpandDimsOpDynamicDims(unittest.TestCase): - @generate(*[(0, [1, 2, 3, dynamic_dimension_value, 224]), +class TestExpandDimsOpDynamicDims(): + @pytest.mark.parametrize("axis, ref_out_shape",[(0, [1, 2, 3, dynamic_dimension_value, 224]), (1, [2, 1, 3, dynamic_dimension_value, 224]), (2, [2, 3, 1, dynamic_dimension_value, 224]), (3, [2, 3, dynamic_dimension_value, 1, 224]), @@ -66,12 +63,11 @@ def test_expand_dims_infer(self, axis, ref_out_shape): ExpandDims.infer(expand_dims_node) - self.assertTrue(strict_compare_tensors(expand_dims_node.out_node().shape, shape_array(ref_out_shape))) + assert strict_compare_tensors(expand_dims_node.out_node().shape, shape_array(ref_out_shape)) -@generator -class ExpandDimsOpValueInfer(unittest.TestCase): - @generate(*[(0, [2, 3, 224, 224], [1, 2, 3, 224, 224]), +class TestExpandDimsOpValueInfer(): + @pytest.mark.parametrize("axis, in_shape, ref_out_shape",[(0, [2, 3, 224, 224], [1, 2, 3, 224, 224]), (1, [2, 3, 224, 224], [2, 1, 3, 224, 224]), (2, [2, 3, 224, 224], [2, 3, 1, 224, 224]), (3, [2, 3, 224, 224], [2, 3, 224, 1, 224]), @@ -88,5 +84,5 @@ def test_expand_dims_infer_value(self, axis, in_shape, ref_out_shape): ExpandDims.infer(expand_dims_node) - self.assertTrue(np.array_equal(expand_dims_node.out_node().shape, np.array(ref_out_shape))) - self.assertTrue(np.array_equal(expand_dims_node.out_node().value, np.array(in_value.reshape(ref_out_shape)))) + assert np.array_equal(expand_dims_node.out_node().shape, np.array(ref_out_shape)) + assert np.array_equal(expand_dims_node.out_node().value, np.array(in_value.reshape(ref_out_shape))) diff --git a/tools/mo/unit_tests/mo/ops/eye_test.py b/tools/mo/unit_tests/mo/ops/eye_test.py index c005200be961a1..1689f161fdd40b 100644 --- a/tools/mo/unit_tests/mo/ops/eye_test.py +++ b/tools/mo/unit_tests/mo/ops/eye_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.eye import Eye from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -50,17 +49,16 @@ ] -@generator -class TestComplexOp(unittest.TestCase): - @generate(*[ - ([], [dynamic_dimension_value, dynamic_dimension_value]), - ([1], [dynamic_dimension_value, dynamic_dimension_value]), +class TestComplexOp(): + @pytest.mark.parametrize("input_shape, output_shape, num_rows, num_cols, batch_shape",[ + ([], [dynamic_dimension_value, dynamic_dimension_value],None,None,[]), + ([1], [dynamic_dimension_value, dynamic_dimension_value],None,None,[]), ([1], [2, dynamic_dimension_value, dynamic_dimension_value], None, None, [2]), ([1], [2, 3, dynamic_dimension_value], 3, None, [2]), ([1], [2, dynamic_dimension_value, 4], None, 4, [2]), ([1], [2, 3, 4], [3], [4], [2]) ]) - def test_complex_op_shape_inference(self, input_shape, output_shape, num_rows=None, num_cols=None, batch_shape=[]): + def test_complex_op_shape_inference(self, input_shape, output_shape, num_rows, num_cols, batch_shape): graph = build_graph_with_attrs(nodes_with_attrs=graph_node_attrs_sizes, edges_with_attrs=graph_edges_sizes, update_nodes_attributes=[ @@ -75,8 +73,8 @@ def test_complex_op_shape_inference(self, input_shape, output_shape, num_rows=No msg = "Eye operation infer failed for case: expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['eye_op_data']['shape'], output_shape), - msg.format(output_shape, graph.node['eye_op_data']['shape'])) + assert np.array_equal(graph.node['eye_op_data']['shape'], output_shape),\ + msg.format(output_shape, graph.node['eye_op_data']['shape']) def test_value_inference(self): graph_node_attrs_sizes = { @@ -103,5 +101,5 @@ def test_value_inference(self): msg = "Eye operation infer failed for case: expected_value={}, actual_value={}" - self.assertTrue(np.array_equal(graph.node['eye_op_d']['value'], output_value), - msg.format(output_value, graph.node['eye_op_d']['value'])) + assert np.array_equal(graph.node['eye_op_d']['value'], output_value),\ + msg.format(output_value, graph.node['eye_op_d']['value']) diff --git a/tools/mo/unit_tests/mo/ops/gatherelements_test.py b/tools/mo/unit_tests/mo/ops/gatherelements_test.py index 90ee62fd4b0f41..feb1807c5cbb5d 100644 --- a/tools/mo/unit_tests/mo/ops/gatherelements_test.py +++ b/tools/mo/unit_tests/mo/ops/gatherelements_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.gatherelements import GatherElements from openvino.tools.mo.front.common.partial_infer.utils import int64_array, strict_compare_tensors, dynamic_dimension @@ -15,9 +14,8 @@ dyn = dynamic_dimension -@generator -class GatherElementsInferTest(unittest.TestCase): - @generate(*[ +class TestGatherElementsInferTest(): + @pytest.mark.parametrize("data, indices, axis, ref_res",[ ([[1, 2], [3, 4]], [[0, 1], @@ -96,11 +94,11 @@ def test_gatherelements_value_infer(self, data, indices, axis, ref_res): GatherElements.infer(gather_el_node) res_output_shape = gather_el_node.out_node().shape - self.assertTrue(np.array_equal(int64_array(ref_res).shape, res_output_shape)) + assert np.array_equal(int64_array(ref_res).shape, res_output_shape) res_output_value = gather_el_node.out_node().value if res_output_value is not None: - self.assertTrue(np.array_equal(int64_array(ref_res), res_output_value)) + assert np.array_equal(int64_array(ref_res), res_output_value) def check_shape_infer(self, data_shape, indices_shape, axis, ref): nodes = { @@ -121,7 +119,7 @@ def check_shape_infer(self, data_shape, indices_shape, axis, ref): GatherElements.infer(gather_el_node) res_output_shape = gather_el_node.out_node().shape - self.assertTrue(strict_compare_tensors(res_output_shape, ref)) + assert strict_compare_tensors(res_output_shape, ref) def test_shape_infer_1(self): self.check_shape_infer(data_shape=[3], indices_shape=[100], ref=[100], axis=0) @@ -165,13 +163,13 @@ def test_shape_infer_13(self): # negative tests def test_negative_shape_infer_ranks_differ(self): - self.assertRaises(AssertionError, self.check_shape_infer, - data_shape=[1, 3, 64], indices_shape=[1, 3], ref=[1, 3, 1024], axis=2) + with pytest.raises(AssertionError): + self.check_shape_infer(data_shape=[1, 3, 64], indices_shape=[1, 3], ref=[1, 3, 1024], axis=2) def test_negative_shape_infer_axis_out_of_bound(self): - self.assertRaises(AssertionError, self.check_shape_infer, - data_shape=[1, 4, 64], indices_shape=[1, 3, 64], ref=[1, 3, 1024], axis=20) + with pytest.raises(AssertionError): + self.check_shape_infer(data_shape=[1, 4, 64], indices_shape=[1, 3, 64], ref=[1, 3, 1024], axis=20) def test_negative_shape_infer_inconsistent_shapes(self): - self.assertRaises(Error, self.check_shape_infer, - data_shape=[1, 4, 64], indices_shape=[1, 3, 64], ref=[1, 3, 1024], axis=2) + with pytest.raises(Error): + self.check_shape_infer(data_shape=[1, 4, 64], indices_shape=[1, 3, 64], ref=[1, 3, 1024], axis=2) diff --git a/tools/mo/unit_tests/mo/ops/interpolate_test.py b/tools/mo/unit_tests/mo/ops/interpolate_test.py index 3d773ea8177c3e..72b954509365b4 100644 --- a/tools/mo/unit_tests/mo/ops/interpolate_test.py +++ b/tools/mo/unit_tests/mo/ops/interpolate_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.interpolate import Interpolate from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -72,9 +71,9 @@ ] -@generator -class TestInterpolateOp(unittest.TestCase): - @generate(*[([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [350, 150], [3.5, 150 / 200], [2, 3]), +class TestInterpolateOp(): + @pytest.mark.parametrize("pads_begin, pads_end, input_shape, output_shape, sizes, scales, axes", + [([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [350, 150], [3.5, 150 / 200], [2, 3]), ([0, 3, 10, 10], [0], [16, 7, 190, 400], [8, 10, 390, 600], [8, 390, 600], [0.5, 390 / 200, 600 / 410], [0, 2, 3]), ([10, 5, 0, 10], [0, 4, 16, 18], [4, 33, 1024, 8000], [56, 42, 520, 8028], @@ -114,11 +113,12 @@ def test_interpolate4_using_sizes(self, pads_begin, pads_end, input_shape, outpu msg = "Interpolate-4 infer failed for case: sizes={}, scales={}, pads_begin={}, pads_end={}, axes={}," \ " expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)), + assert np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)),\ msg.format(sizes, scales, pads_begin, pads_end, axes, output_shape, - graph.node['interpolate_data']['shape'])) + graph.node['interpolate_data']['shape']) - @generate(*[([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [350, 150], [3.5, 150 / 200], [2, 3]), + @pytest.mark.parametrize("pads_begin, pads_end, input_shape, output_shape, sizes, scales, axes", + [([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [350, 150], [3.5, 150 / 200], [2, 3]), ([0, 3, 10, 10], [0], [16, 7, 190, 400], [8, 10, 390, 600], [8, 390, 600], [0.5, 390 / 200, 600 / 410], [0, 2, 3]), ([10, 5, 0, 10], [0, 4, 16, 18], [4, 33, 1024, 8000], [56, 42, 520, 8028], @@ -165,11 +165,12 @@ def test_interpolate4_using_scales(self, pads_begin, pads_end, input_shape, outp msg = "Interpolate-4 infer failed for case: sizes={}, scales={}, pads_begin={}, pads_end={}, axes={}," \ " expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)), + assert np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)),\ msg.format(sizes, scales, pads_begin, pads_end, axes, output_shape, - graph.node['interpolate_data']['shape'])) + graph.node['interpolate_data']['shape']) - @generate(*[([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]), + @pytest.mark.parametrize("pads_begin, pads_end, input_shape, output_shape, sizes, scales", + [([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]), ([0, 3, 10, 10], [0], [16, 7, 190, 400], [8, 10, 390, 600], [8, 10, 390, 600], [0.5, 1.0, 390 / 200, 600 / 410]), ([10, 5, 0, 10], [0, 4, 16, 18], [4, 33, 1024, 8000], [56, 42, 520, 8028], @@ -212,11 +213,12 @@ def test_interpolate4_using_sizes_without_axes(self, pads_begin, pads_end, input msg = "Interpolate-4 infer failed for case: sizes={}, scales={}, pads_begin={}, pads_end={}," \ " expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)), + assert np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)),\ msg.format(sizes, scales, pads_begin, pads_end, output_shape, - graph.node['interpolate_data']['shape'])) + graph.node['interpolate_data']['shape']) - @generate(*[([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]), + @pytest.mark.parametrize("pads_begin, pads_end, input_shape, output_shape, sizes, scales", + [([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]), ([0, 3, 10, 10], [0], [16, 7, 190, 400], [8, 10, 390, 600], [8, 10, 390, 600], [0.5, 1.0, 390 / 200, 600 / 410]), ([10, 5, 0, 10], [0, 4, 16, 18], [4, 33, 1024, 8000], [56, 42, 520, 8028], @@ -262,6 +264,6 @@ def test_interpolate4_using_scales_without_axes(self, pads_begin, pads_end, inpu msg = "Interpolate-4 infer failed for case: sizes={}, scales={}, pads_begin={}, pads_end={}," \ " expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)), + assert np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)),\ msg.format(sizes, scales, pads_begin, pads_end, output_shape, - graph.node['interpolate_data']['shape'])) + graph.node['interpolate_data']['shape']) diff --git a/tools/mo/unit_tests/mo/ops/one_hot_test.py b/tools/mo/unit_tests/mo/ops/one_hot_test.py index be5248177987d5..0c4d839dc620cb 100644 --- a/tools/mo/unit_tests/mo/ops/one_hot_test.py +++ b/tools/mo/unit_tests/mo/ops/one_hot_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.one_hot import OneHot from openvino.tools.mo.front.common.partial_infer.utils import int64_array, float_array @@ -32,29 +31,28 @@ def generate_nodes(data, axis=-1, depth=4, on_value=1., off_value=0.): ] -@generator -class TestOneHotInfer(unittest.TestCase): - @generate(*[ +class TestOneHotInfer(): + @pytest.mark.parametrize("input_value, exp_value, axis",[ # 0d input - (1, [0, 1, 0, 0]), + (1, [0, 1, 0, 0], -1), # 1d input - ([1, 2], [[0, 1, 0, 0], [0, 0, 1, 0]]), + ([1, 2], [[0, 1, 0, 0], [0, 0, 1, 0]], -1), # 2D input ([[1, 2], [3, 4]], [[[0, 1, 0, 0], [0, 0, 1, 0]], - [[0, 0, 0, 1], [0, 0, 0, 0]]]), + [[0, 0, 0, 1], [0, 0, 0, 0]]], -1), # 3d input ([[[0, 2], [1, 2]], [[2, 1], [3, 0]]], [[[[1, 0, 0, 0], [0, 0, 1, 0]], [[0, 1, 0, 0], [0, 0, 1, 0]]], - [[[0, 0, 1, 0], [0, 1, 0, 0]], [[0, 0, 0, 1], [1, 0, 0, 0]]]]), + [[[0, 0, 1, 0], [0, 1, 0, 0]], [[0, 0, 0, 1], [1, 0, 0, 0]]]], -1), # 1d input with negative indices - ([-2, 2], [[0, 0, 1, 0], [0, 0, 1, 0]]), + ([-2, 2], [[0, 0, 1, 0], [0, 0, 1, 0]], -1), # check if axis is neither 0 nor -1 ([[1, 2], [3, 4]], [[[0, 0], [1, 0], [0, 1], [0, 0]], [[0, 0], [0, 0], [0, 0], [1, 0]]], 1) ]) - def test_infer(self, input_value, exp_value, axis=-1): + def test_infer(self, input_value, exp_value, axis): graph = build_graph(generate_nodes(int64_array(input_value), axis), edges) onehot_node = Node(graph, 'one_hot') OneHot.infer(onehot_node) res_value = graph.node['one_hot_d']['value'] - self.assertTrue(np.array_equal(exp_value, int64_array(res_value))) + assert np.array_equal(exp_value, int64_array(res_value)) diff --git a/tools/mo/unit_tests/mo/ops/reshape_test.py b/tools/mo/unit_tests/mo/ops/reshape_test.py index 7b0bb26676b6aa..86fd2eb85b24f7 100644 --- a/tools/mo/unit_tests/mo/ops/reshape_test.py +++ b/tools/mo/unit_tests/mo/ops/reshape_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generate, generator from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors from openvino.tools.mo.graph.graph import Node @@ -47,9 +46,8 @@ } -@generator -class TestReshapeShapeInfer(unittest.TestCase): - @generate(*[ +class TestReshapeShapeInfer(): + @pytest.mark.parametrize("input_value, input_shape, output_shape, ref_value, ref_shape",[ (None, shape_array([1, 100, 4]), shape_array([-1, 25]), None, [16, 25]), (None, shape_array([5, 100, 4]), shape_array([0, -1, 25]), None, [5, 16, 25]), (None, shape_array([5, dynamic_dimension_value, 4]), shape_array([4, -1, 5]), None, @@ -89,5 +87,5 @@ def test_reshape_infer(self, input_value, input_shape, output_shape, ref_value, node = Node(graph, 'reshape') Reshape.infer(node) if ref_value is not None: - self.assertTrue(strict_compare_tensors(node.out_port(0).data.get_value(), shape_array(ref_value))) - self.assertTrue(strict_compare_tensors(node.out_port(0).data.get_shape(), shape_array(ref_shape))) + assert strict_compare_tensors(node.out_port(0).data.get_value(), shape_array(ref_value)) + assert strict_compare_tensors(node.out_port(0).data.get_shape(), shape_array(ref_shape)) diff --git a/tools/mo/unit_tests/mo/ops/scatter_test.py b/tools/mo/unit_tests/mo/ops/scatter_test.py index 79b91cec1ceb68..1066ea8b1c5c43 100644 --- a/tools/mo/unit_tests/mo/ops/scatter_test.py +++ b/tools/mo/unit_tests/mo/ops/scatter_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.scatter import ScatterElementsUpdate, ScatterUpdate from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value @@ -12,9 +11,8 @@ from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, result, connect, valued_const_with_data -@generator -class ScatterElementsInferTest(unittest.TestCase): - @generate(*[ +class TestScatterElementsInferTest(): + @pytest.mark.parametrize("data, indices, updates, axis, ref_res",[ ([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], @@ -96,15 +94,14 @@ def test_scatterelements_value_infer(self, data, indices, updates, axis, ref_res ScatterElementsUpdate.infer(scatter_el_node) res_output_shape = scatter_el_node.out_node().shape - self.assertTrue(np.array_equal(int64_array(ref_res).shape, res_output_shape)) + assert np.array_equal(int64_array(ref_res).shape, res_output_shape) res_output_value = scatter_el_node.out_node().value - self.assertTrue(np.array_equal(ref_res, res_output_value)) + assert np.array_equal(ref_res, res_output_value) -@generator -class ScatterUpdateInferTest(unittest.TestCase): - @generate(*[ +class TestScatterUpdateInferTest(): + @pytest.mark.parametrize("data, indices, updates, axis, ref_res",[ ([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], @@ -188,7 +185,7 @@ def test_scatter_update_value_infer(self, data, indices, updates, axis, ref_res) ScatterUpdate.infer(scatter_update_node) res_output_shape = scatter_update_node.out_node().shape - self.assertTrue(np.array_equal(int64_array(ref_res).shape, res_output_shape)) + assert np.array_equal(int64_array(ref_res).shape, res_output_shape) res_output_value = scatter_update_node.out_node().value - self.assertTrue(np.array_equal(ref_res, res_output_value)) + assert np.array_equal(ref_res, res_output_value) diff --git a/tools/mo/unit_tests/mo/ops/slice_test.py b/tools/mo/unit_tests/mo/ops/slice_test.py index a07514728ef7eb..c69a8fec7ec3d1 100644 --- a/tools/mo/unit_tests/mo/ops/slice_test.py +++ b/tools/mo/unit_tests/mo/ops/slice_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.common.partial_infer.utils import int64_array, dynamic_dimension_value, shape_array, \ strict_compare_tensors @@ -14,9 +13,8 @@ connect, shaped_data, shaped_const_with_data -@generator -class TestSliceOp(unittest.TestCase): - @generate(*[ +class TestSliceOp(): + @pytest.mark.parametrize("inp_value, inp_shape, starts, ends, axes, steps, expected_value, expected_shape",[ # standard case ([[4, 5, 6, 7], [2, 3, 5, 6], [5, 6, 8, 9], [5, 6, 8, 9]], [4, 4], [0, 1], [3, 2], [0, 1], [1, 1], [[5], [3], [6]], [3, 1]), @@ -107,13 +105,12 @@ def convert_args(val, name=''): Slice.infer(slice_node) if expected_value is not None: - self.assertTrue(strict_compare_tensors(slice_node.out_node().value, expected_value)) - self.assertTrue(strict_compare_tensors(slice_node.out_node().shape, expected_shape)) + assert strict_compare_tensors(slice_node.out_node().value, expected_value) + assert strict_compare_tensors(slice_node.out_node().shape, expected_shape) -@generator -class TestOvSliceOp(unittest.TestCase): - @generate(*[ +class TestOvSliceOp(): + @pytest.mark.parametrize("inp_value, inp_shape, starts, ends, axes, steps, expected_value, expected_shape",[ # standard case ([[4, 5, 6, 7], [2, 3, 5, 6], [5, 6, 8, 9], [5, 6, 8, 9]], [4, 4], [0, 1], [3, 2], [0, 1], [1, 1], [[5], [3], [6]], [3, 1]), @@ -204,5 +201,5 @@ def convert_args(val, name=''): OvSlice.infer(slice_node) if expected_value is not None: - self.assertTrue(strict_compare_tensors(slice_node.out_node().value, expected_value)) - self.assertTrue(strict_compare_tensors(slice_node.out_node().shape, expected_shape)) + assert strict_compare_tensors(slice_node.out_node().value, expected_value) + assert strict_compare_tensors(slice_node.out_node().shape, expected_shape) diff --git a/tools/mo/unit_tests/mo/ops/split_test.py b/tools/mo/unit_tests/mo/ops/split_test.py index 962a476489cc50..de7e5c71c2cd48 100644 --- a/tools/mo/unit_tests/mo/ops/split_test.py +++ b/tools/mo/unit_tests/mo/ops/split_test.py @@ -4,7 +4,7 @@ import unittest import numpy as np -from generator import generator, generate +import pytest from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, \ dynamic_dimension_value, dynamic_dimension, strict_compare_tensors, mo_array @@ -248,8 +248,7 @@ def test_splitv_2_zero_not_last(self): self.assertTrue(np.all(node.split_lengths == np.array([2, 13, 10]))) -@generator -class TestVariadicSplitOp(unittest.TestCase): +class TestVariadicSplitOp(): nodes = { 'input': {'kind': 'op'}, 'split_input_data': {'kind': 'data', 'shape': None, 'value': None}, @@ -280,7 +279,7 @@ class TestVariadicSplitOp(unittest.TestCase): ('split_output_2_data', 'output_2'), ] - @generate(*[int64_array(2), + @pytest.mark.parametrize("axis",[int64_array(2), int64_array([2])]) def test_variadic_split_axis(self, axis): lengths = int64_array([2, 13, 10]) @@ -299,9 +298,9 @@ def test_variadic_split_axis(self, axis): VariadicSplit.infer(node) ont_nodes_count = len(node.out_edges()) - self.assertTrue(ont_nodes_count == 3) + assert ont_nodes_count == 3 for out in range(ont_nodes_count): - self.assertTrue(np.all(node.out_node(out).shape == int64_array([2, 12, lengths[out], 30]))) + assert np.all(node.out_node(out).shape == int64_array([2, 12, lengths[out], 30])) def test_variadic_split_value_inference_with_uint32(self): axis = int64_array(2) @@ -329,11 +328,11 @@ def test_variadic_split_value_inference_with_uint32(self): VariadicSplit.infer(node) ont_nodes_count = len(node.out_edges()) - self.assertTrue(ont_nodes_count == 3) + assert ont_nodes_count == 3 for out in range(ont_nodes_count): - self.assertTrue(np.all(node.out_node(out).shape == int64_array([2, 12, lengths[out], 30]))) + assert np.all(node.out_node(out).shape == int64_array([2, 12, lengths[out], 30])) - @generate(*[int64_array([[2], [2]]), + @pytest.mark.parametrize("axis",[int64_array([[2], [2]]), int64_array([2, 2])]) def test_negative_variadic_split_axis(self, axis): lengths = int64_array([2, 13, 10]) @@ -352,8 +351,8 @@ def test_negative_variadic_split_axis(self, axis): try: VariadicSplit.infer(node) except AssertionError as e: - self.assertTrue(e.args[0] == 'VariadicSplit `axis` should be scalar or tensor with shape [1], ' - 'but it`s not for node split_op') + assert e.args[0] == 'VariadicSplit `axis` should be scalar or tensor with shape [1], '\ + 'but it`s not for node split_op' class TestSplitReverseInfer(unittest.TestCase): diff --git a/tools/mo/unit_tests/mo/ops/squeeze_test.py b/tools/mo/unit_tests/mo/ops/squeeze_test.py index 714e90928b538f..42118250477e8d 100644 --- a/tools/mo/unit_tests/mo/ops/squeeze_test.py +++ b/tools/mo/unit_tests/mo/ops/squeeze_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generate, generator from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors from openvino.tools.mo.graph.graph import Node @@ -41,9 +40,8 @@ } -@generator -class TestSqueezeInfer(unittest.TestCase): - @generate(*[ +class TestSqueezeInfer(): + @pytest.mark.parametrize("input_value, input_shape, squeeze_dims, ref_value, ref_shape",[ (None, shape_array([1, 2, 1, 4]), shape_array([2]), None, [1, 2, 4]), # allow squeezing dynamic dimensions (None, shape_array([1, 2, dynamic_dimension_value, 4]), shape_array([2]), None, [1, 2, 4]), @@ -67,10 +65,10 @@ def test_squeeze_squeeze_dims(self, input_value, input_shape, squeeze_dims, ref_ }) node = Node(graph, 'squeeze') if ref_shape is None: # the test should fail - with self.assertRaises(Error): + with pytest.raises(Error): Squeeze.infer(node) else: Squeeze.infer(node) if ref_value is not None: - self.assertTrue(strict_compare_tensors(node.out_port(0).data.get_value(), ref_value)) - self.assertTrue(strict_compare_tensors(node.out_port(0).data.get_shape(), ref_shape)) + assert strict_compare_tensors(node.out_port(0).data.get_value(), ref_value) + assert strict_compare_tensors(node.out_port(0).data.get_shape(), ref_shape) diff --git a/tools/mo/unit_tests/mo/ops/transpose_test.py b/tools/mo/unit_tests/mo/ops/transpose_test.py index da3968cb3785d0..b28e0d381d1ae4 100644 --- a/tools/mo/unit_tests/mo/ops/transpose_test.py +++ b/tools/mo/unit_tests/mo/ops/transpose_test.py @@ -3,9 +3,8 @@ import itertools import unittest - +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, strict_compare_tensors, \ dynamic_dimension_value @@ -19,8 +18,7 @@ input_shape = np.array([1, 3, 224, 224]) -@generator -class TestTransposeOp(unittest.TestCase): +class TestTransposeOp(): nodes_attributes = { 'parameter': { 'kind': 'op', @@ -71,7 +69,7 @@ def _create_graph_with_transpose(self, order): graph.graph['layout'] = 'NCHW' return graph - @generate(*[list(order) for order in list(itertools.permutations(np.arange(4)))]) + @pytest.mark.parametrize("order",[list(order) for order in list(itertools.permutations(np.arange(4)))]) def test_transpose_infer_1(self, order): graph = self._create_graph_with_transpose(order) transpose_node = Node(graph, 'transpose') @@ -79,7 +77,7 @@ def test_transpose_infer_1(self, order): Transpose.infer(transpose_node) ref = [transpose_node.in_node().shape[i] for i in order] - self.assertTrue(np.array_equal(transpose_node.out_node().shape, np.array(ref))) + assert np.array_equal(transpose_node.out_node().shape, np.array(ref)) def test_transpose_infer_2(self): order = None @@ -89,22 +87,24 @@ def test_transpose_infer_2(self): Transpose.infer(transpose_node) ref = np.array([x for x in reversed(transpose_node.in_node().shape)]) - self.assertTrue(np.array_equal(transpose_node.out_node().shape, ref), - "Shapes are not the same: {} and {}".format(transpose_node.out_node().shape, ref)) + assert np.array_equal(transpose_node.out_node().shape, ref),\ + "Shapes are not the same: {} and {}".format(transpose_node.out_node().shape, ref) def test_transpose_infer_neg_1(self): order = np.array([0, 1, 2, 3]) graph = self._create_graph_with_transpose(order) transpose_node = Node(graph, 'transpose') transpose_node['reverse_order'] = True - self.assertRaises(AssertionError, Transpose.infer, transpose_node) + with pytest.raises(AssertionError): + Transpose.infer(transpose_node) def test_transpose_infer_neg_2(self): order = None graph = self._create_graph_with_transpose(order) transpose_node = Node(graph, 'transpose') transpose_node['reverse_order'] = False - self.assertRaises(AssertionError, Transpose.infer, transpose_node) + with pytest.raises(AssertionError): + Transpose.infer(transpose_node) dyn = dynamic_dimension_value diff --git a/tools/mo/unit_tests/mo/ops/unsqueeze_test.py b/tools/mo/unit_tests/mo/ops/unsqueeze_test.py index 72d519dd64c389..668bb71d3d1a7d 100644 --- a/tools/mo/unit_tests/mo/ops/unsqueeze_test.py +++ b/tools/mo/unit_tests/mo/ops/unsqueeze_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value, strict_compare_tensors from openvino.tools.mo.graph.graph import Node @@ -13,8 +12,7 @@ from unit_tests.utils.graph import build_graph -@generator -class TestUnsqueezeOp(unittest.TestCase): +class TestUnsqueezeOp(): nodes_attributes = { 'data_1': { 'kind': 'data', @@ -39,7 +37,8 @@ class TestUnsqueezeOp(unittest.TestCase): } } - @generate(*[(shape_array([1, 3, 64, 64]), int64_array([0, 4]), shape_array([1, 1, 3, 64, 1, 64]), + @pytest.mark.parametrize("input_shape, unsq_dims, output_shape, ref_uns_dims, input_value, output_value", + [(shape_array([1, 3, 64, 64]), int64_array([0, 4]), shape_array([1, 1, 3, 64, 1, 64]), int64_array([0, 4]), None, None), (shape_array([2, 3, 64, 64]), int64_array([-1]), shape_array([2, 3, 64, 64, 1]), int64_array([4]), None, None), @@ -75,7 +74,7 @@ def test_unsqueeze_infer(self, input_shape, unsq_dims, output_shape, ref_uns_dim Unsqueeze.infer(unsqueeze_node) (flag, resp) = compare_graphs(graph, graph_ref, 'data_2') - self.assertTrue(flag, resp) - self.assertTrue(strict_compare_tensors(Node(graph, 'data_2').shape, Node(graph_ref, 'data_2').shape)) + assert flag, resp + assert strict_compare_tensors(Node(graph, 'data_2').shape, Node(graph_ref, 'data_2').shape) if Node(graph_ref, 'data_2').value is not None: - self.assertTrue(strict_compare_tensors(Node(graph, 'data_2').value, Node(graph_ref, 'data_2').value)) + assert strict_compare_tensors(Node(graph, 'data_2').value, Node(graph_ref, 'data_2').value) diff --git a/tools/mo/unit_tests/mo/ops/upsample_test.py b/tools/mo/unit_tests/mo/ops/upsample_test.py index e0ae9020372b61..f70e37a7c2b404 100644 --- a/tools/mo/unit_tests/mo/ops/upsample_test.py +++ b/tools/mo/unit_tests/mo/ops/upsample_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.upsample import UpsampleOp from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors @@ -18,9 +17,8 @@ } -@generator -class TestUpsampleOp(unittest.TestCase): - @generate(*[ +class TestUpsampleOp(): + @pytest.mark.parametrize("scales, input_shape, expected_shape",[ (np.array([1., 1., 2., 2.]), shape_array([1, 3, 227, 227]), shape_array([1, 3, 454, 454])), (np.array([1., 1., 2.5, 1.5]), shape_array([1, 5, 227, 227]), shape_array([1, 5, 567, 340])), (np.array([1., 1., 1.3, 0.7]), shape_array([1, 14, 1023, 713]), shape_array([1, 14, 1329, 499])), @@ -46,9 +44,9 @@ def test_upsample_with_scales_infer(self, scales, input_shape, expected_shape): upsample_node = Node(graph, 'upsample') UpsampleOp.upsample_infer(upsample_node) res_shape = graph.node['node_3']['shape'] - self.assertTrue(strict_compare_tensors(expected_shape, res_shape)) + assert strict_compare_tensors(expected_shape, res_shape) - @generate(*[ + @pytest.mark.parametrize("scales, input_shape, expected_shape",[ (np.array([1., 1., 2., 2.]), shape_array([1, 3, 227, 227]), shape_array([1, 3, 454, 454])), (np.array([1., 1., 2.5, 1.5]), shape_array([1, 5, 227, 227]), shape_array([1, 5, 567, 340])), (np.array([1., 1., 1.3, 0.7]), shape_array([1, 14, 1023, 713]), shape_array([1, 14, 1329, 499])), @@ -76,4 +74,4 @@ def test_upsample_with_second_input_infer(self, scales, input_shape, expected_sh upsample_node = Node(graph, 'upsample') UpsampleOp.upsample_infer(upsample_node) res_shape = graph.node['node_3']['shape'] - self.assertTrue(strict_compare_tensors(expected_shape, res_shape)) + assert strict_compare_tensors(expected_shape, res_shape) diff --git a/tools/mo/unit_tests/mo/pipeline/common_test.py b/tools/mo/unit_tests/mo/pipeline/common_test.py index c62a45a5b97771..bb71d40b22d0f7 100644 --- a/tools/mo/unit_tests/mo/pipeline/common_test.py +++ b/tools/mo/unit_tests/mo/pipeline/common_test.py @@ -2,17 +2,14 @@ # SPDX-License-Identifier: Apache-2.0 import unittest - -from generator import generator, generate - +import pytest from openvino.tools.mo.graph.graph import Node from openvino.tools.mo.pipeline.common import determined_sort, get_fw_tensor_debug_info, get_sorted_outputs from unit_tests.utils.graph import build_graph_with_edge_attrs -@generator -class TestTopologicalSort(unittest.TestCase): - @generate( +class TestTopologicalSort(): + @pytest.mark.parametrize( "edges",[ [('A', 'Ad', {'out': 0}), ('Ad', 'B', {'in': 0}), ('B', 'Bd', {'out': 0}), @@ -92,7 +89,7 @@ class TestTopologicalSort(unittest.TestCase): ('Hd', 'J', {'in': 1}), ('Dd', 'F', {'in': 1}), ('Fd', 'H', {'in': 1}), - ('Gd', 'H', {'in': 0})] + ('Gd', 'H', {'in': 0})]] ) def test_determined_topological_sort(self, edges): nodes = {'A': {'type': 'Identity', 'kind': 'op'}, @@ -123,8 +120,8 @@ def test_determined_topological_sort(self, edges): outputs = [Node(graph, 'Kd')] for i in range(100): op_order, data_order = determined_sort(outputs) - self.assertListEqual(op_order, ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']) - self.assertListEqual(data_order, ['Ad', 'Bd', 'Cd', 'Dd', 'Ed', 'Fd', 'Gd', 'Hd', 'Id', 'Jd', 'Kd']) + assert op_order == ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'] + assert data_order == ['Ad', 'Bd', 'Cd', 'Dd', 'Ed', 'Fd', 'Gd', 'Hd', 'Id', 'Jd', 'Kd'] class TestGetFWTensorName(unittest.TestCase): diff --git a/tools/mo/unit_tests/mo/utils/broadcasting_test.py b/tools/mo/unit_tests/mo/utils/broadcasting_test.py index f12fa029919b56..91b79be4de6361 100644 --- a/tools/mo/unit_tests/mo/utils/broadcasting_test.py +++ b/tools/mo/unit_tests/mo/utils/broadcasting_test.py @@ -1,19 +1,17 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.common.partial_infer.utils import int64_array, dynamic_dimension_value, shape_array, strict_compare_tensors from openvino.tools.mo.utils.broadcasting import uni_directional_broadcasting, uni_directional_shape_broadcasting, \ bi_directional_shape_broadcasting -@generator -class TestingBroadcasting(unittest.TestCase): - @generate(*[([], [20, 30, 10], [20, 30, 10]), +class TestingBroadcasting(): + @pytest.mark.parametrize("input_shape, target_shape, expected_shape",[([], [20, 30, 10], [20, 30, 10]), ([1], [20, 30, 10], [20, 30, 10]), ([1, 1, 10], [20, 30, 10], [20, 30, 10]), ([20, 1, 10], [20, 30, 10], [20, 30, 10]), @@ -24,18 +22,18 @@ class TestingBroadcasting(unittest.TestCase): ([5, 10], [1, 10], None), ]) def test_uni_directional_broadcasting(self, input_shape, target_shape, expected_shape): - self.assertTrue(np.array_equal(uni_directional_shape_broadcasting(input_shape, target_shape), expected_shape)) + assert np.array_equal(uni_directional_shape_broadcasting(input_shape, target_shape), expected_shape) input_value = np.array(np.random.rand(*input_shape)) if expected_shape is not None: expected_value = np.broadcast_to(input_value, int64_array(target_shape)) - self.assertTrue(np.array_equal(uni_directional_broadcasting(input_value, int64_array(target_shape)), - expected_value)) + assert np.array_equal(uni_directional_broadcasting(input_value, int64_array(target_shape)), + expected_value) else: - with self.assertRaisesRegex(Exception, '.*cannot be uni-directionally broadcasted.*'): + with pytest.raises(Exception,match = '.*cannot be uni-directionally broadcasted.*'): uni_directional_broadcasting(input_value, int64_array(target_shape)) - @generate(*[([], [20, 30, 10], [20, 30, 10]), + @pytest.mark.parametrize("input_shape, target_shape, expected_shape",[([], [20, 30, 10], [20, 30, 10]), ([1], [20, 30, 10], [20, 30, 10]), ([1, 1, 10], [20, 30, 10], [20, 30, 10]), ([20, 1, 10], [20, 30, 10], [20, 30, 10]), @@ -58,11 +56,11 @@ def test_uni_directional_broadcasting(self, input_shape, target_shape, expected_ def test_uni_directional_shape_broadcasting(self, input_shape, target_shape, expected_shape): result = uni_directional_shape_broadcasting(input_shape, target_shape) if expected_shape is None: - self.assertIsNone(result) + assert result is None else: - self.assertTrue(strict_compare_tensors(result, expected_shape)) + assert strict_compare_tensors(result, expected_shape) - @generate(*[([], [20, 30, 10], [20, 30, 10]), + @pytest.mark.parametrize("input_shape, target_shape, expected_shape",[([], [20, 30, 10], [20, 30, 10]), ([1], [20, 30, 10], [20, 30, 10]), ([1, 1, 10], [20, 30, 10], [20, 30, 10]), ([20, 1, 10], [20, 30, 10], [20, 30, 10]), @@ -85,6 +83,6 @@ def test_uni_directional_shape_broadcasting(self, input_shape, target_shape, exp def test_bi_directional_shape_broadcasting(self, input_shape, target_shape, expected_shape): result = bi_directional_shape_broadcasting(input_shape, target_shape) if expected_shape is None: - self.assertIsNone(result) + assert result is None else: - self.assertTrue(strict_compare_tensors(result, expected_shape)) + assert strict_compare_tensors(result, expected_shape) diff --git a/tools/mo/unit_tests/mo/utils/ir_reader/layer_to_class_test.py b/tools/mo/unit_tests/mo/utils/ir_reader/layer_to_class_test.py index 4c846bfe4e5cb1..5fec0f6d0b4e56 100644 --- a/tools/mo/unit_tests/mo/utils/ir_reader/layer_to_class_test.py +++ b/tools/mo/unit_tests/mo/utils/ir_reader/layer_to_class_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate import openvino.tools.mo.graph.graph from openvino.tools.mo.graph.graph import Node @@ -17,9 +16,8 @@ from openvino.tools.mo.ops.op import Op -@generator -class TestFunction(unittest.TestCase): - @generate(*[([1, 32, 112, 112], [32, 1, 1, 3], [32, 1, 1, 1, 3], 32), +class TestFunction(): + @pytest.mark.parametrize("shape, weights_shape, reshape_shape, group",[([1, 32, 112, 112], [32, 1, 1, 3], [32, 1, 1, 1, 3], 32), ([1, 32, 112, 112], [32, 1, 1, 1, 3], None, 32), ]) def test_groupconv_to_conv(self, shape, weights_shape, reshape_shape, group): @@ -75,7 +73,7 @@ def test_groupconv_to_conv(self, shape, weights_shape, reshape_shape, group): assert len(reshape_node.in_nodes()) == 0 and len(reshape_node.out_nodes()) == 0 (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_restore_tensor_names(self): @@ -144,7 +142,7 @@ def test_squeeze(self): # Check that graph wasn't changed after shape infer (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_squeeze_no_axes(self): nodes_attributes = { @@ -172,7 +170,7 @@ def test_squeeze_no_axes(self): # Check that graph wasn't changed after shape infer (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_unsqueeze(self): nodes_attributes = { @@ -205,4 +203,4 @@ def test_unsqueeze(self): # Check that graph wasn't changed after shape infer (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/utils/ir_reader/ops_test.py b/tools/mo/unit_tests/mo/utils/ir_reader/ops_test.py index 2df88dab8bdbb7..3e5b35ef62fabb 100644 --- a/tools/mo/unit_tests/mo/utils/ir_reader/ops_test.py +++ b/tools/mo/unit_tests/mo/utils/ir_reader/ops_test.py @@ -6,10 +6,11 @@ import numpy as np from pathlib import Path +import openvino.runtime.opset13 as opset13 import openvino.runtime.opset12 as opset12 import openvino.runtime.opset11 as opset11 import openvino.runtime.opset10 as opset10 -from openvino.runtime import Model, serialize, Core, PartialShape, Dimension +from openvino.runtime import Model, serialize, Core, PartialShape, Dimension, Type from openvino.tools.mo.utils.ir_reader.restore_graph import restore_graph_from_ir, save_restored_graph from openvino.tools.mo.utils.logger import init_logger @@ -22,16 +23,22 @@ class TestOps(unittest.TestCase): @staticmethod def check_graph_can_save(model, name): with tempfile.TemporaryDirectory() as tmp: - model_xml = Path(tmp) / (name + '.xml') - model_bin = Path(tmp) / (name + '.bin') + tmp_path = Path(tmp) + model_xml = tmp_path / (name + '.xml') + model_bin = tmp_path / (name + '.bin') serialize(model, model_xml, model_bin) graph, _ = restore_graph_from_ir(model_xml, model_bin) - save_restored_graph(graph, tmp, {}, name) + save_restored_graph(graph, tmp, {}, name + '_restored') # restore 2 times to validate that after save graph doesn't lose attributes etc. - graph, _ = restore_graph_from_ir(model_xml, model_bin) + restored_model_xml = tmp_path / (name + '_restored.xml') + restored_model_bin = tmp_path / (name + '_restored.bin') + graph, _ = restore_graph_from_ir( + restored_model_xml, restored_model_bin) + core = Core() + core.set_property({"ENABLE_MMAP": False}) # check that re-saved model can be read in runtime - Core().read_model(model_xml) - return graph + model = core.read_model(restored_model_xml) + return graph, model def test_topk_11(self): data_shape = [6, 12, 10, 24] @@ -42,7 +49,7 @@ def test_topk_11(self): topk = opset11.topk(data_parameter, k_val, axis, "max", "value", stable=True, name="TopK_11") model = Model(topk, [data_parameter]) - graph = TestOps.check_graph_can_save(model, 'topk_model') + graph, _ = TestOps.check_graph_can_save(model, 'topk_model') topk_node = graph.get_op_nodes(op="TopK")[0] self.assertEqual(topk_node["version"], "opset11") self.assertTrue(topk_node["stable"]) @@ -55,7 +62,7 @@ def test_interpolate_11(self): interpolate = opset11.interpolate(data_parameter, np.int32( [20, 48]), "nearest", "sizes", axes=np.int32([2, 3]), name="Interpolate_11") model = Model(interpolate, [data_parameter]) - graph = TestOps.check_graph_can_save(model, 'interpolate_model') + graph, _ = TestOps.check_graph_can_save(model, 'interpolate_model') interpolate_node = graph.get_op_nodes(op="Interpolate")[0] self.assertEqual(interpolate_node["version"], "opset11") self.assertTrue("force_precision_in_ports" in interpolate_node) @@ -68,7 +75,7 @@ def test_interpolate_11_scales(self): interpolate = opset11.interpolate(data_parameter, np.float32( [2., 2.]), "nearest", "scales", axes=np.int32([2, 3]), name="Interpolate_11") model = Model(interpolate, [data_parameter]) - graph = TestOps.check_graph_can_save(model, 'interpolate_model') + graph, _ = TestOps.check_graph_can_save(model, 'interpolate_model') interpolate_node = graph.get_op_nodes(op="Interpolate")[0] self.assertEqual(interpolate_node["version"], "opset11") self.assertTrue("force_precision_in_ports" not in interpolate_node) @@ -80,7 +87,7 @@ def test_interpolate_11_no_axes(self): interpolate = opset11.interpolate(data_parameter, np.int32( [6, 12, 20, 48]), "nearest", "sizes", name="Interpolate_11") model = Model(interpolate, [data_parameter]) - graph = TestOps.check_graph_can_save(model, 'interpolate_model') + graph, _ = TestOps.check_graph_can_save(model, 'interpolate_model') interpolate_node = graph.get_op_nodes(op="Interpolate")[0] self.assertEqual(interpolate_node["version"], "opset11") self.assertTrue("force_precision_in_ports" in interpolate_node) @@ -93,7 +100,7 @@ def test_interpolate_4(self): interpolate = opset10.interpolate(data_parameter, np.int32([20, 48]), np.float32( [2, 2]), "nearest", "sizes", axes=np.int32([2, 3]), name="Interpolate_4") model = Model(interpolate, [data_parameter]) - graph = TestOps.check_graph_can_save(model, 'interpolate4_model') + graph, _ = TestOps.check_graph_can_save(model, 'interpolate4_model') interpolate_node = graph.get_op_nodes(op="Interpolate")[0] self.assertEqual(interpolate_node["version"], "opset4") @@ -104,7 +111,7 @@ def test_unique(self): unique = opset10.unique(data_parameter, axis=np.int32( [2]), sorted=True, name="Unique_10") model = Model(unique, [data_parameter]) - graph = TestOps.check_graph_can_save(model, 'unique_model') + graph, _ = TestOps.check_graph_can_save(model, 'unique_model') unique_node = graph.get_op_nodes(op="Unique")[0] self.assertEqual(unique_node["version"], "opset10") self.assertListEqual(unique_node.out_port( @@ -117,7 +124,7 @@ def test_is_finite(self): data_shape, name="Data", dtype=np.float32) is_finite = opset10.is_finite(data_parameter, name="Is_finite_10") model = Model(is_finite, [data_parameter]) - graph = TestOps.check_graph_can_save(model, 'is_finite_model') + graph, _ = TestOps.check_graph_can_save(model, 'is_finite_model') is_finite_node = graph.get_op_nodes(op="IsFinite")[0] self.assertEqual(is_finite_node["version"], "opset10") @@ -127,7 +134,7 @@ def test_is_inf(self): data_shape, name="Data", dtype=np.float32) is_inf = opset10.is_inf(data_parameter, name="Is_inf_10") model = Model(is_inf, [data_parameter]) - graph = TestOps.check_graph_can_save(model, 'is_inf_model') + graph, _ = TestOps.check_graph_can_save(model, 'is_inf_model') is_inf_node = graph.get_op_nodes(op="IsInf")[0] self.assertEqual(is_inf_node["version"], "opset10") @@ -137,7 +144,7 @@ def test_is_nan(self): data_shape, name="Data", dtype=np.float32) is_nan = opset10.is_nan(data_parameter, name="Is_nan_10") model = Model(is_nan, [data_parameter]) - graph = TestOps.check_graph_can_save(model, 'is_nan_model') + graph, _ = TestOps.check_graph_can_save(model, 'is_nan_model') is_nan_node = graph.get_op_nodes(op="IsNaN")[0] self.assertEqual(is_nan_node["version"], "opset10") @@ -176,7 +183,7 @@ def test_if(self): out2 = if_node.set_output(then_body_res_2, else_body_res_2) model = Model([out1, out2], [parameter_x, parameter_y]) - graph = TestOps.check_graph_can_save(model, 'if_model') + graph, _ = TestOps.check_graph_can_save(model, 'if_model') if_node = graph.get_op_nodes(op="If")[0] self.assertEqual(if_node["version"], "opset8") _, layer_info, _ = if_node['IE'][0] @@ -191,7 +198,7 @@ def test_strided_slice_no_begin_end_mask(self): strided_slice = opset11.strided_slice(data_parameter, np.int32([1, 2, 3, 4]), np.int32( [3, 6, 9, 12]), np.int32([1, 1, 1, 1]), begin_mask=[], end_mask=[], name="StridedSlice_10") model = Model(strided_slice, [data_parameter]) - graph = TestOps.check_graph_can_save(model, 'strided_slice_model') + graph, _ = TestOps.check_graph_can_save(model, 'strided_slice_model') strided_slice_node = graph.get_op_nodes(op="StridedSlice")[0] self.assertEqual(strided_slice_node["version"], "opset1") @@ -205,7 +212,7 @@ def test_scatter_dynamic_shape(self): mul = opset11.multiply(scatter, np.int64([1, 2])) reshape = opset11.reshape(data_parameter, mul, True) model = Model(reshape, [data_parameter]) - graph = TestOps.check_graph_can_save(model, 'scatter_dynamic_model') + graph, _ = TestOps.check_graph_can_save(model, 'scatter_dynamic_model') scatter_update_node = graph.get_op_nodes(op="ScatterUpdate")[0] self.assertListEqual(scatter_update_node.out_port(0).data.get_value().tolist(), [0, None]) @@ -213,7 +220,7 @@ def test_pad_12(self): data_parameter = opset12.parameter([6, 12, 10, 24], name="Data", dtype=np.float32) pad = opset12.pad(data_parameter, np.int64([0, 0, -1, -2]), np.int64([0, 0, -3, -4]), "constant") model = Model(pad, [data_parameter]) - graph = TestOps.check_graph_can_save(model, 'pad_model') + graph, _ = TestOps.check_graph_can_save(model, 'pad_model') pad_node = graph.get_op_nodes(op="Pad")[0] self.assertEqual(pad_node["version"], "opset12") self.assertListEqual(pad_node.in_port(1).data.get_value().tolist(), [0, 0, -1, -2]) @@ -224,7 +231,7 @@ def test_scatter_elements_update_12(self): data_parameter = opset12.parameter([10], name="Data", dtype=np.float32) scatter = opset12.scatter_elements_update(data_parameter, np.int32([5, 0, 7, 5]), np.float32([5., 6., 1.5, -5.]), np.int32(0), "sum", False) model = Model(scatter, [data_parameter]) - graph = TestOps.check_graph_can_save(model, 'scatter_model') + graph, _ = TestOps.check_graph_can_save(model, 'scatter_model') scatter_node = graph.get_op_nodes(op="ScatterElementsUpdate")[0] self.assertListEqual(scatter_node.out_port(0).data.get_shape().tolist(), [10]) self.assertEqual(scatter_node["version"], "opset12") @@ -239,9 +246,114 @@ def test_group_norm_12(self): epsilon = 1e-6 node = opset12.group_normalization(data_parameter, scale, bias, num_groups, epsilon) model = Model(node, [data_parameter]) - graph = TestOps.check_graph_can_save(model, 'group_norm_model') + graph, _ = TestOps.check_graph_can_save(model, 'group_norm_model') gn_node = graph.get_op_nodes(op="GroupNormalization")[0] self.assertListEqual(gn_node.out_port(0).data.get_shape().tolist(), [1, 3, 3, 3]) self.assertEqual(gn_node["version"], "opset12") self.assertEqual(gn_node['num_groups'], 1) self.assertEqual(gn_node['epsilon'], 1e-06) + + def test_bitwise_and_13(self): + a = opset13.parameter([4, 1], name="A", dtype=np.int32) + b = opset13.parameter([1, 2], name="B", dtype=np.int32) + + op = opset13.bitwise_and(a, b) + model = Model(op, [a, b]) + graph, _ = TestOps.check_graph_can_save(model, "bitwise_and_model") + op_node = graph.get_op_nodes(op="BitwiseAnd")[0] + self.assertListEqual(op_node.out_port(0).data.get_shape().tolist(), [4, 2]) + self.assertEqual(op_node["version"], "opset13") + self.assertEqual(op_node["auto_broadcast"], "numpy") + + def test_bitwise_or_13(self): + a = opset13.parameter([4, 1], name="A", dtype=np.int32) + b = opset13.parameter([1, 2], name="B", dtype=np.int32) + + op = opset13.bitwise_or(a, b) + model = Model(op, [a, b]) + graph, _ = TestOps.check_graph_can_save(model, "bitwise_or_model") + op_node = graph.get_op_nodes(op="BitwiseOr")[0] + self.assertListEqual(op_node.out_port(0).data.get_shape().tolist(), [4, 2]) + self.assertEqual(op_node["version"], "opset13") + self.assertEqual(op_node["auto_broadcast"], "numpy") + + def test_bitwise_xor_13(self): + a = opset13.parameter([4, 1], name="A", dtype=np.int32) + b = opset13.parameter([1, 2], name="B", dtype=np.int32) + + op = opset13.bitwise_xor(a, b) + model = Model(op, [a, b]) + graph, _ = TestOps.check_graph_can_save(model, "bitwise_xor_model") + op_node = graph.get_op_nodes(op="BitwiseXor")[0] + self.assertListEqual(op_node.out_port(0).data.get_shape().tolist(), [4, 2]) + self.assertEqual(op_node["version"], "opset13") + self.assertEqual(op_node["auto_broadcast"], "numpy") + + def test_bitwise_not_13(self): + a = opset13.parameter([4, 2], name="A", dtype=np.int32) + + op = opset13.bitwise_not(a) + model = Model(op, [a]) + graph, _ = TestOps.check_graph_can_save(model, "bitwise_not_model") + op_node = graph.get_op_nodes(op="BitwiseNot")[0] + self.assertListEqual(op_node.out_port(0).data.get_shape().tolist(), [4, 2]) + self.assertEqual(op_node["version"], "opset13") + + def test_multinomial_13_param_inputs(self): + data_shape = [2, 8] + probs = opset13.parameter( + data_shape, name="probs", dtype=np.float32) + num_samples = opset13.parameter( + [1], name="num_samples", dtype=np.int32) + + op = opset13.multinomial(probs, num_samples, + convert_type="i32", + with_replacement=True, + log_probs=True, + global_seed=456, + op_seed=213) + + model = Model(op, [probs, num_samples]) + graph, loaded_model = TestOps.check_graph_can_save( + model, 'multinomial_param_model') + graph_node = graph.get_op_nodes(op="Multinomial")[0] + + self.assertEqual(graph_node["version"], "opset13") + self.assertListEqual(graph_node.out_port( + 0).data.get_shape().tolist(), [2, None]) + self.assertEqual(graph_node["convert_type"], "i32") + self.assertTrue(graph_node["with_replacement"]) + self.assertTrue(graph_node["log_probs"]) + self.assertEqual(graph_node["global_seed"], 456) + self.assertEqual(graph_node["op_seed"], 213) + self.assertEqual(loaded_model.get_output_element_type(0), Type.i32) + self.assertEqual(loaded_model.get_output_partial_shape( + 0), PartialShape([2, -1])) + + def test_multinomial_13_const_inputs(self): + probs = opset13.constant( + [[0.4, 0.5, 0.1], [0.3, 0.2, 0.5]], name="probs", dtype=np.float32) + num_samples = opset13.constant( + [3], name="num_samples", dtype=np.int64) + + op = opset13.multinomial(probs, num_samples, + convert_type="i64", + with_replacement=False, + log_probs=False) + + model = Model(op, []) + graph, loaded_model = TestOps.check_graph_can_save( + model, 'multinomial_const_model') + graph_node = graph.get_op_nodes(op="Multinomial")[0] + + self.assertEqual(graph_node["version"], "opset13") + self.assertListEqual(graph_node.out_port( + 0).data.get_shape().tolist(), [2, 3]) + self.assertEqual(graph_node["convert_type"], "i64") + self.assertFalse(graph_node["with_replacement"]) + self.assertFalse(graph_node["log_probs"]) + self.assertEqual(graph_node["global_seed"], 0) + self.assertEqual(graph_node["op_seed"], 0) + self.assertEqual(loaded_model.get_output_element_type(0), Type.i64) + self.assertEqual(loaded_model.get_output_partial_shape( + 0), PartialShape([2, 3])) diff --git a/tools/mo/unit_tests/moc_tf_fe/conversion_basic_models_test.py b/tools/mo/unit_tests/moc_tf_fe/conversion_basic_models_test.py index 3e5c46ecb3ac90..26ea01b77d6722 100644 --- a/tools/mo/unit_tests/moc_tf_fe/conversion_basic_models_test.py +++ b/tools/mo/unit_tests/moc_tf_fe/conversion_basic_models_test.py @@ -3,10 +3,10 @@ import os import unittest +from sys import platform import numpy as np from generator import generator, generate - from openvino.runtime import Core from openvino.tools.mo.convert import convert_model @@ -40,7 +40,6 @@ def basic(self, input_model, argv_input, inputs, dtype, expected, freeze_placeho assert values.dtype == dtype assert np.allclose(values, expected) - @generate( *[ ( @@ -236,16 +235,13 @@ def test_freeze_placeholder_with_unknown_rank(self, inputs, inputs_data, expecte freeze_placeholder_with_value, input_shape, only_conversion, True) - def test_conversion_failure_fallback_default(self): + def test_conversion_tf1_while_default(self): self.basic("ctc_model_based.pbtxt", None, None, None, None, None, None, True, True, False, False) - def test_conversion_failure_fallback_use_new_frontend(self): - with self.assertRaisesRegex(Exception, - "\[TensorFlow Frontend\] Internal error, no translator found for operation\(s\)\: " - "TensorArrayGatherV3\, TensorArrayReadV3\, TensorArraySizeV3\, TensorArrayV3\, TensorArrayWriteV3"): - self.basic("ctc_model_based.pbtxt", None, None, None, None, - None, None, True, True, True, False) + def test_conversion_tf1_while_use_new_frontend(self): + self.basic("ctc_model_based.pbtxt", None, None, None, None, + None, None, True, True, True, False) @unittest.skip("88349: Fix auto-pruning in legacy FE") def test_conversion_model_oneshot_iterator_use_legacy_frontend(self): diff --git a/tools/openvino_dev/CMakeLists.txt b/tools/openvino_dev/CMakeLists.txt index 061e9c4e8e6b82..00223262494ca2 100644 --- a/tools/openvino_dev/CMakeLists.txt +++ b/tools/openvino_dev/CMakeLists.txt @@ -14,8 +14,8 @@ if(NOT DEFINED OpenVINO_SOURCE_DIR) get_filename_component(OpenVINO_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../.." REALPATH) endif() -if(NOT IEDevScripts_FOUND) - find_package(IEDevScripts REQUIRED +if(NOT OpenVINODeveloperScripts_FOUND) + find_package(OpenVINODeveloperScripts REQUIRED PATHS "${OpenVINO_SOURCE_DIR}/cmake/developer_package" NO_CMAKE_FIND_ROOT_PATH NO_DEFAULT_PATH) @@ -36,7 +36,10 @@ set(WHEEL_BUILD "${OpenVINO_VERSION_BUILD}" CACHE STRING "Build number of this r ov_cpack_add_component(${OV_CPACK_COMP_OPENVINO_DEV_REQ_FILES} HIDDEN) set(REQUIREMENTS_IN "${CMAKE_CURRENT_SOURCE_DIR}/requirements_dev.txt.in") -set(EXTRAS_LIST _ caffe kaldi mxnet onnx pytorch tensorflow tensorflow2) +set(EXTRAS_LIST _ caffe kaldi onnx pytorch tensorflow tensorflow2) +if(NOT (APPLE AND AARCH64)) + list(APPEND EXTRAS_LIST mxnet) +endif() foreach(EXTRAS IN LISTS EXTRAS_LIST) if(EXTRAS STREQUAL "_") @@ -56,17 +59,8 @@ endforeach() # check __init__.py files alignment -function(ov_check_init_files_alignment) +function(ov_check_init_files_alignment init_files) # check the files in pairs - list(APPEND init_files - "${OpenVINO_SOURCE_DIR}/src/bindings/python/src/openvino/__init__.py" - "${OpenVINO_SOURCE_DIR}/src/bindings/python/src/compatibility/openvino/__init__.py" - "${OpenVINO_SOURCE_DIR}/tools/mo/openvino/__init__.py" - "${OpenVINO_SOURCE_DIR}/tools/pot/openvino/__init__.py" - "${OpenVINO_SOURCE_DIR}/tools/ovc/openvino/__init__.py" - "${OpenVINO_SOURCE_DIR}/tools/benchmark_tool/openvino/__init__.py" - "${OpenVINO_SOURCE_DIR}/tools/openvino_dev/src/openvino/__init__.py") - list(LENGTH init_files init_files_count) math(EXPR file_loop_range "${init_files_count}-2") foreach(init_file_idx RANGE 0 ${file_loop_range}) @@ -78,14 +72,17 @@ function(ov_check_init_files_alignment) RESULT_VARIABLE compare_result ) if(compare_result EQUAL 1) - message(STATUS ${file1}) - message(STATUS ${file2}) - message(FATAL_ERROR "The __init__.py files are misaligned: ${file1} and ${file2}") + message(FATAL_ERROR "The tools __init__.py files are misaligned: ${file1} and ${file2}") endif() endforeach() endfunction() -ov_check_init_files_alignment() +set(INIT_FILES_TOOLS +"${OpenVINO_SOURCE_DIR}/tools/mo/openvino/__init__.py" +"${OpenVINO_SOURCE_DIR}/tools/pot/openvino/__init__.py" +"${OpenVINO_SOURCE_DIR}/tools/openvino_dev/src/openvino/__init__.py") + +ov_check_init_files_alignment("${INIT_FILES_TOOLS}") # openvino_dev build diff --git a/tools/ovc/CMakeLists.txt b/tools/ovc/CMakeLists.txt index d5c3ddfe3cca4a..cea078768604f7 100644 --- a/tools/ovc/CMakeLists.txt +++ b/tools/ovc/CMakeLists.txt @@ -14,8 +14,8 @@ if(NOT DEFINED OpenVINO_SOURCE_DIR) get_filename_component(OpenVINO_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../.." REALPATH) endif() -if(NOT IEDevScripts_FOUND) - find_package(IEDevScripts REQUIRED +if(NOT OpenVINODeveloperScripts_FOUND) + find_package(OpenVINODeveloperScripts REQUIRED PATHS "${OpenVINO_SOURCE_DIR}/cmake/developer_package" NO_CMAKE_FIND_ROOT_PATH NO_DEFAULT_PATH) @@ -40,5 +40,5 @@ install(DIRECTORY ${OpenVINOConverter_SOURCE_DIR}/openvino # if(CMAKE_SOURCE_DIR STREQUAL OpenVINOConverter_SOURCE_DIR) - ie_cpack(${IE_CPACK_COMPONENTS_ALL}) + ov_cpack(${OV_CPACK_COMPONENTS_ALL}) endif() diff --git a/tools/ovc/openvino/__init__.py b/tools/ovc/openvino/__init__.py index 90552e0befed68..b7dc434f3148cc 100644 --- a/tools/ovc/openvino/__init__.py +++ b/tools/ovc/openvino/__init__.py @@ -12,47 +12,47 @@ except ImportError: pass -# API 2.0 -try: - # Import all public modules - from openvino import runtime as runtime - from openvino import frontend as frontend - from openvino import helpers as helpers - from openvino import preprocess as preprocess - from openvino import utils as utils - from openvino.runtime import properties as properties - - # Import most important classes and functions from openvino.runtime - from openvino.runtime import Model - from openvino.runtime import Core - from openvino.runtime import CompiledModel - from openvino.runtime import InferRequest - from openvino.runtime import AsyncInferQueue - - from openvino.runtime import Dimension - from openvino.runtime import Strides - from openvino.runtime import PartialShape - from openvino.runtime import Shape - from openvino.runtime import Layout - from openvino.runtime import Type - from openvino.runtime import Tensor - from openvino.runtime import OVAny - - from openvino.runtime import compile_model - from openvino.runtime import get_batch - from openvino.runtime import set_batch - from openvino.runtime import serialize - from openvino.runtime import shutdown - from openvino.runtime import tensor_from_file - from openvino.runtime import save_model - from openvino.runtime import layout_helpers - - # Set version for openvino package - from openvino.runtime import get_version - __version__ = get_version() -except ImportError: - import warnings - warnings.warn("openvino package has problems with imports!", ImportWarning, stacklevel=2) +# # +# # API 2.0 +# # This __init__.py forces checking of runtime modules to propagate errors. +# # It is not compared with init files from openvino-dev package. +# # +# Import all public modules +from openvino import runtime as runtime +from openvino import frontend as frontend +from openvino import helpers as helpers +from openvino import preprocess as preprocess +from openvino import utils as utils +from openvino.runtime import properties as properties + +# Import most important classes and functions from openvino.runtime +from openvino.runtime import Model +from openvino.runtime import Core +from openvino.runtime import CompiledModel +from openvino.runtime import InferRequest +from openvino.runtime import AsyncInferQueue + +from openvino.runtime import Dimension +from openvino.runtime import Strides +from openvino.runtime import PartialShape +from openvino.runtime import Shape +from openvino.runtime import Layout +from openvino.runtime import Type +from openvino.runtime import Tensor +from openvino.runtime import OVAny + +from openvino.runtime import compile_model +from openvino.runtime import get_batch +from openvino.runtime import set_batch +from openvino.runtime import serialize +from openvino.runtime import shutdown +from openvino.runtime import tensor_from_file +from openvino.runtime import save_model +from openvino.runtime import layout_helpers + +# Set version for openvino package +from openvino.runtime import get_version +__version__ = get_version() # Tools try: diff --git a/tools/ovc/openvino/tools/ovc/telemetry_utils.py b/tools/ovc/openvino/tools/ovc/telemetry_utils.py index 87e0132ccd17a6..42232b0839a6be 100644 --- a/tools/ovc/openvino/tools/ovc/telemetry_utils.py +++ b/tools/ovc/openvino/tools/ovc/telemetry_utils.py @@ -17,7 +17,13 @@ def init_mo_telemetry(app_name='Model Conversion API'): - return tm.Telemetry(tid=get_tid(), app_name=app_name, app_version=get_rt_version(), backend='ga4') + return tm.Telemetry(tid=get_tid(), + app_name=app_name, + app_version=get_rt_version(), + backend='ga4', + enable_opt_in_dialog=False, + disable_in_ci=True + ) def send_framework_info(framework: str): """