From ce7366bc90a116ea64e0d1fa348d984be0eded7d Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Thu, 28 Sep 2023 01:15:36 +0400 Subject: [PATCH 01/35] Enabled Android arm64 GHA in precommit (#20094) --- .github/workflows/android_arm64.yml | 144 ++++++++++++++++++ .github/workflows/code_style.yml | 2 +- .github/workflows/linux.yml | 4 +- .github/workflows/linux_android_arm64.yml | 173 ---------------------- vcpkg.json | 4 +- 5 files changed, 150 insertions(+), 177 deletions(-) create mode 100644 .github/workflows/android_arm64.yml delete mode 100644 .github/workflows/linux_android_arm64.yml diff --git a/.github/workflows/android_arm64.yml b/.github/workflows/android_arm64.yml new file mode 100644 index 00000000000000..96f686a8d94777 --- /dev/null +++ b/.github/workflows/android_arm64.yml @@ -0,0 +1,144 @@ +name: Android ARM64 with vcpkg +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 }}-android-arm64-vcpkg + cancel-in-progress: true + +jobs: + Build: + defaults: + run: + shell: bash + runs-on: aks-linux-16-cores + container: + image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 + volumes: + - /mount/caches:/mount/caches + env: + DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input + CMAKE_GENERATOR: 'Ninja' + CMAKE_CXX_COMPILER_LAUNCHER: ccache + CMAKE_C_COMPILER_LAUNCHER: ccache + OPENVINO_REPO: '/__w/openvino/openvino/openvino' + VCPKG_ROOT: '/__w/openvino/openvino/vcpkg' + BUILD_DIR: '/__w/openvino/openvino/build' + INSTALL_DIR: '/__w/openvino/openvino/install' + ANDROID_TOOLS: '/__w/openvino/openvino/android_tools' + ANDROID_NDK_HOME: '/__w/openvino/openvino/android_tools/ndk-bundle' + ANDROID_SDK_VERSION: 29 + ANDROID_ABI_CONFIG: arm64-v8a + CCACHE_DIR: '/mount/caches/ccache/android_arm64' + CCACHE_TEMPDIR: '/__w/openvino/openvino/ccache_temp' + CCACHE_MAXSIZE: 50G + steps: + - name: Install git + run: apt-get update && apt-get install --assume-yes --no-install-recommends git ca-certificates + + - name: Clone OpenVINO + uses: actions/checkout@v4 + with: + path: 'openvino' + + - name: Init submodules for non vcpkg dependencies + run: | + pushd ${OPENVINO_REPO} + git submodule update --init -- ${OPENVINO_REPO}/src/plugins + git submodule update --init -- ${OPENVINO_REPO}/thirdparty/gtest + git submodule update --init -- ${OPENVINO_REPO}/thirdparty/gflags + git submodule update --init -- ${OPENVINO_REPO}/thirdparty/open_model_zoo + popd + + - name: Clone vcpkg + uses: actions/checkout@v4 + with: + repository: 'microsoft/vcpkg' + path: 'vcpkg' + fetch-depth: '0' + + # + # Dependencies + # + + - name: Install dependencies + run: | + # generic dependencies + apt --assume-yes install ccache scons ninja-build build-essential python3-pip + + # vcpkg requires cmake 3.19 or later + python3 -m pip install -U pip cmake + # vcpkg's tool dependencies + apt --assume-yes install curl zip unzip tar + # vcpkg 'python3' port dependencies + apt --assume-yes install autoconf libtool autoconf-archive + # vcpkg tree of dependencies require extra packages + apt --assume-yes install pkg-config linux-libc-dev + + # Install Android SDK, NDK and Tools + apt -y --no-install-recommends install unzip wget default-jdk + wget https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip + unzip commandlinetools-linux-7583922_latest.zip + echo "yes" | ./cmdline-tools/bin/sdkmanager --sdk_root=${ANDROID_TOOLS} --install "ndk-bundle" "platform-tools" "platforms;android-${{ env.ANDROID_SDK_VERSION }}" + + # + # Build + # + + - name: Build vcpkg + run: | + ${VCPKG_ROOT}/bootstrap-vcpkg.sh + # patch vcpkg default toolchain to build only Release configuration + echo "set(VCPKG_BUILD_TYPE release)" >> ${VCPKG_ROOT}/triplets/arm64-android.cmake + + - name: CMake - configure + run: | + cmake \ + -G '${{ env.CMAKE_GENERATOR }}' \ + -DENABLE_INTEL_GPU=ON \ + -DENABLE_TESTS=ON \ + -DENABLE_SYSTEM_OPENCL=ON \ + -DENABLE_SYSTEM_PROTOBUF=ON \ + -DENABLE_SYSTEM_PUGIXML=ON \ + -DENABLE_SYSTEM_SNAPPY=ON \ + -DENABLE_SYSTEM_TBB=ON \ + -DENABLE_SYSTEM_FLATBUFFERS=ON \ + -DANDROID_ABI=${{ env.ANDROID_ABI_CONFIG }} \ + -DANDROID_PLATFORM=${{ env.ANDROID_SDK_VERSION }} \ + -DVCPKG_TARGET_TRIPLET=arm64-android \ + -DVCPKG_HOST_TRIPLET=x64-linux-release \ + -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake \ + -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \ + -DCMAKE_COMPILE_WARNING_AS_ERROR=ON \ + -DCMAKE_CXX_COMPILER_LAUNCHER=${{ env.CMAKE_CXX_COMPILER_LAUNCHER }} \ + -DCMAKE_C_COMPILER_LAUNCHER=${{ env.CMAKE_C_COMPILER_LAUNCHER }} \ + -S ${OPENVINO_REPO} \ + -B ${BUILD_DIR} + + - name: Clean ccache stats + run: ccache --zero-stats --show-config + + - name: Cmake - build + run: cmake --build ${BUILD_DIR} --parallel + + - name: Show ccache stats + run: ccache --show-stats diff --git a/.github/workflows/code_style.yml b/.github/workflows/code_style.yml index 164a5454465bf5..96c75ce55aef43 100644 --- a/.github/workflows/code_style.yml +++ b/.github/workflows/code_style.yml @@ -86,7 +86,7 @@ jobs: run: | sudo apt update sudo apt --assume-yes remove clang-7 clang-8 clang-9 clang-10 clang-11 clang-12 clang-13 - sudo apt --assume-yes install libclang-14-dev + sudo apt --assume-yes install clang-14 libclang-14-dev - name: Install Python-based dependencies run: python3 -m pip install -r cmake/developer_package/ncc_naming_style/requirements_dev.txt diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index c7d20c346b5641..60dc3d8c7c7be7 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -81,10 +81,10 @@ jobs: - name: Install build dependencies run: | bash ${OPENVINO_REPO}/install_build_dependencies.sh - # openjdk-11-jdk - Java API + # default-jdk - Java API # libssl1.1 - 'python3 -m pip' in self-hosted runner # unzip - to download ninja - apt install --assume-yes --no-install-recommends openjdk-11-jdk libssl1.1 unzip + apt install --assume-yes --no-install-recommends default-jdk libssl1.1 unzip wget https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-linux.zip unzip ninja-linux.zip diff --git a/.github/workflows/linux_android_arm64.yml b/.github/workflows/linux_android_arm64.yml deleted file mode 100644 index 4d0e40640ac5b5..00000000000000 --- a/.github/workflows/linux_android_arm64.yml +++ /dev/null @@ -1,173 +0,0 @@ -name: Linux Android ARM64 (Ubuntu 20.04, Python 3.11) -on: - schedule: - # run daily at 00:00 - - cron: '0 0 * * *' - 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: - group: ${{ github.head_ref || github.run_id }}-linux-android-arm64 - cancel-in-progress: true - -jobs: - Build: - # TODO: remove. Temporary measure to prevent the workflow from scheduling on forks. - if: ${{ github.repository_owner == 'openvinotoolkit' }} - defaults: - run: - shell: bash - runs-on: ubuntu-20.04-8-cores - env: - CMAKE_BUILD_TYPE: 'Release' - CMAKE_GENERATOR: 'Ninja' - CMAKE_CXX_COMPILER_LAUNCHER: ccache - CMAKE_C_COMPILER_LAUNCHER: ccache - BUILD_TYPE: Debug - OPENVINO_REPO: ${{ github.workspace }}/openvino - VCPKG_ROOT: ${{ github.workspace }}/vcpkg - BUILD_DIR: ${{ github.workspace }}/build - INSTALL_DIR: ${{ github.workspace }}/install - OV_TEMP: ${{ github.workspace }}/openvino_temp - ANDROID_TOOLS: ${{ github.workspace }}/android_tools - ANDROID_NDK_HOME: ${{ github.workspace }}/android_tools/ndk-bundle - ANDROID_SDK_VERSION: 29 - ANDROID_ABI_CONFIG: arm64-v8a - steps: - - name: Clone OpenVINO - uses: actions/checkout@v4 - with: - path: 'openvino' - - - name: Init submodules for non vcpkg dependencies - run: | - pushd ${{ env.OPENVINO_REPO }} - git submodule update --init -- ${{ env.OPENVINO_REPO }}/src/plugins - git submodule update --init -- ${{ env.OPENVINO_REPO }}/thirdparty/gtest - git submodule update --init -- ${{ env.OPENVINO_REPO }}/thirdparty/open_model_zoo - popd - - - name: Clone VCPKG - uses: actions/checkout@v4 - with: - repository: 'microsoft/vcpkg' - path: 'vcpkg' - fetch-depth: '0' - - - name: Setup Python 3.11 - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - # - # Dependencies - # - - - name: Install dependencies - run: | - # generic dependencies - sudo -E apt update - sudo -E apt --assume-yes install ccache scons default-jdk python3-pip ninja-build build-essential - - wget https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-linux.zip - unzip ninja-linux.zip - sudo cp -v ninja /usr/local/bin/ - - ln -s /usr/local/bin/ninja /usr/local/bin/ninja-build - - # vcpkg's tool dependencies - sudo -E apt --assume-yes install curl zip unzip tar - - # vcpkg 'python3' port dependencies - sudo -E apt --assume-yes install autoconf libtool autoconf-archive - - # vcpkg tree of dependencies require extra packages - sudo -E apt --assume-yes install pkg-config linux-libc-dev - - # Install Android SDK, NDK and Tools - sudo apt -y --no-install-recommends install unzip - wget https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip - unzip commandlinetools-linux-7583922_latest.zip - echo "yes" | ./cmdline-tools/bin/sdkmanager --sdk_root=${{ env.ANDROID_TOOLS }} --install "ndk-bundle" "platform-tools" "platforms;android-${{ env.ANDROID_SDK_VERSION }}" - - - 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: ${{ github.job }}-linux-android-arm64 - restore-keys: | - ${{ github.job }}-linux-android-arm64 - - # - # Build - # - - - name: Build vcpkg - run: | - ${{ env.VCPKG_ROOT }}/bootstrap-vcpkg.sh --disableMetrics - # patch vcpkg default (community) toolchain to build only Release configuration - echo "set(VCPKG_BUILD_TYPE release)" >> ${{ env.VCPKG_ROOT }}/triplets/community/arm64-android.cmake - - - name: Get number of CPU cores - uses: SimenB/github-actions-cpu-cores@v2 - id: cpu-cores - - - name: CMake configure - run: | - cmake \ - -G Ninja \ - -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \ - -DVCPKG_TARGET_TRIPLET=arm64-android \ - -DVCPKG_HOST_TRIPLET=x64-linux-release \ - -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake \ - -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${{ env.ANDROID_NDK_HOME }}/build/cmake/android.toolchain.cmake \ - -DCMAKE_COMPILE_WARNING_AS_ERROR=ON \ - -DANDROID_ABI=${{ env.ANDROID_ABI_CONFIG }} \ - -DANDROID_PLATFORM=${{ env.ANDROID_SDK_VERSION }} \ - -DENABLE_PYTHON=OFF \ - -DENABLE_SYSTEM_OPENCL=ON \ - -DENABLE_SYSTEM_PROTOBUF=ON \ - -DENABLE_SYSTEM_PUGIXML=ON \ - -DENABLE_SYSTEM_SNAPPY=ON \ - -DENABLE_SYSTEM_TBB=ON \ - -DENABLE_SYSTEM_FLATBUFFERS=ON \ - -DENABLE_INTEL_GPU=ON \ - -DENABLE_TESTS=ON \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -S ${{ env.OPENVINO_REPO }} \ - -B ${{ env.BUILD_DIR }} - - - name: Clean ccache stats - run: ccache --zero-stats --show-config - - - name: Build Android ARM64 - run: cmake --build ${{ env.BUILD_DIR }} --parallel ${{ steps.cpu-cores.outputs.count }} --config ${{ env.BUILD_TYPE }} - - - name: Show ccache stats - run: ccache --show-stats - - - name: List binary files - run: ls -alR ${{ env.OPENVINO_REPO }}/bin/ diff --git a/vcpkg.json b/vcpkg.json index 802e2ce9603f79..fc30546a81f6d8 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -14,9 +14,11 @@ "homepage": "https://github.com/openvinotoolkit/openvino", "documentation": "https://docs.openvino.ai/latest/index.html", "license": "Apache-2.0", - "builtin-baseline": "962e5e39f8a25f42522f51fffc574e05a3efd26b", + "builtin-baseline": "db0473513e5dc73ec6b6f431ff05d2f398eea042", "dependencies": [ "ade", + "gflags", + "nlohmann-json", { "name": "pkgconf", "host": true From 920d1badf373a032a2c99398e5da89e1258edd6e Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Thu, 28 Sep 2023 01:18:17 +0400 Subject: [PATCH 02/35] Added WebAssembly workflow (#20092) --- .github/workflows/webassembly.yml | 77 +++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 .github/workflows/webassembly.yml diff --git a/.github/workflows/webassembly.yml b/.github/workflows/webassembly.yml new file mode 100644 index 00000000000000..1cedaa107bf63d --- /dev/null +++ b/.github/workflows/webassembly.yml @@ -0,0 +1,77 @@ +name: Webassembly +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 + - 'releases/**' + +concurrency: + # github.ref is not unique in post-commit + group: ${{ github.event_name == 'push' && github.run_id || github.ref }}-webassembly + cancel-in-progress: true + +jobs: + Build: + defaults: + run: + shell: bash + runs-on: aks-linux-16-cores + container: + image: emscripten/emsdk + volumes: + - /mount/caches:/mount/caches + env: + CMAKE_BUILD_TYPE: 'Release' + CMAKE_CXX_COMPILER_LAUNCHER: ccache + CMAKE_C_COMPILER_LAUNCHER: ccache + OPENVINO_REPO: /__w/openvino/openvino/openvino + OPENVINO_BUILD_DIR: /__w/openvino/openvino/openvino_build + CCACHE_DIR: /mount/caches/ccache/webassembly_Release + CCACHE_TEMPDIR: /__w/openvino/openvino/ccache_temp + CCACHE_MAXSIZE: 50G + steps: + - name: Install git + run: apt-get update && apt-get install --assume-yes --no-install-recommends git ca-certificates + + - name: Clone OpenVINO + uses: actions/checkout@v4 + with: + path: 'openvino' + submodules: 'true' + + - name: Install ccache + run: apt-get install --assume-yes --no-install-recommends ccache + + - name: emcmake cmake - configure + run: | + emcmake cmake \ + -DCMAKE_CXX_FLAGS="-Wno-deprecated-declarations" \ + -DCMAKE_C_FLAGS="-Wno-deprecated-declarations" \ + -DCMAKE_COMPILE_WARNING_AS_ERROR=ON \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \ + -S ${OPENVINO_REPO} \ + -B ${OPENVINO_BUILD_DIR} + + - name: emmake make - build + run: emmake make -j$(nproc) hello_query_device -C ${OPENVINO_BUILD_DIR} + + - name: Show ccache stats + run: ccache --show-stats From 2f9727aef99e0cf4565669a7b73480bbaa86e71d Mon Sep 17 00:00:00 2001 From: Fang Xu Date: Thu, 28 Sep 2023 11:26:10 +0530 Subject: [PATCH 03/35] fix compilation issue on Windows arm64 (#19873) * fix compilation issue on Windows arm64 * fix build issue * fix build issue * disable clang compiler for Windows on ARM * disable clang compiler for cpu plugin * Update CMakeLists.txt removed fatal_error from cpu cmake * Update features.cmake disable Intel CPU plugin by default on Windows ARM64 with clangl-cl compiler * update comments * fix build issue --------- Co-authored-by: Ilya Lavrenov --- cmake/features.cmake | 9 ++++++++- src/plugins/intel_cpu/CMakeLists.txt | 2 +- src/plugins/intel_cpu/src/nodes/subgraph.cpp | 20 ++++++++++++++------ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/cmake/features.cmake b/cmake/features.cmake index 455ff21388989a..5f5a58d2daf435 100644 --- a/cmake/features.cmake +++ b/cmake/features.cmake @@ -8,7 +8,14 @@ ov_option (ENABLE_PROXY "Proxy plugin for OpenVINO Runtime" ON) -ie_dependent_option (ENABLE_INTEL_CPU "CPU plugin for OpenVINO Runtime" ON "RISCV64 OR X86 OR X86_64 OR AARCH64 OR ARM" OFF) +if(WIN32 AND AARCH64 AND OV_COMPILER_IS_CLANG) + set(ENABLE_INTEL_CPU_DEFAULT OFF) +else() + set(ENABLE_INTEL_CPU_DEFAULT ON) +endif() + +ie_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) diff --git a/src/plugins/intel_cpu/CMakeLists.txt b/src/plugins/intel_cpu/CMakeLists.txt index 72784b793277c8..4212bacb8cc055 100644 --- a/src/plugins/intel_cpu/CMakeLists.txt +++ b/src/plugins/intel_cpu/CMakeLists.txt @@ -36,7 +36,7 @@ set(OV_CPU_ARM_TARGET_ARCH ${OV_CPU_ARM_TARGET_ARCH_DEFAULT}) if(X86 OR X86_64 OR AARCH64) # disable mlas with webassembly - if(EMSCRIPTEN OR MINGW OR (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7)) + if(EMSCRIPTEN OR (WIN32 AND AARCH64) OR MINGW OR (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7)) set(ENABLE_MLAS_FOR_CPU_DEFAULT OFF) else() set(ENABLE_MLAS_FOR_CPU_DEFAULT ON) diff --git a/src/plugins/intel_cpu/src/nodes/subgraph.cpp b/src/plugins/intel_cpu/src/nodes/subgraph.cpp index ce0216b4fd5cba..5a70cf89d2d273 100644 --- a/src/plugins/intel_cpu/src/nodes/subgraph.cpp +++ b/src/plugins/intel_cpu/src/nodes/subgraph.cpp @@ -517,9 +517,14 @@ Snippet::SnippetJitExecutor::SnippetJitExecutor(const SnippetAttrs& attrs, bool 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()); - 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; +#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, @@ -693,12 +698,15 @@ bool Snippet::SnippetJitExecutor::optimizeExecDomain(std::vector& in 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; - std::vector backend_passes; - -#define SNIPPETS_REGISTER_PASS(PASS_POS, PASS, ...) \ - backend_passes.emplace_back(PASS_POS, std::make_shared(__VA_ARGS__)) +# 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()) { From ca7031f69dfe49ac61ade18c7eb93f43afa6b406 Mon Sep 17 00:00:00 2001 From: Sebastian Golebiewski Date: Thu, 28 Sep 2023 08:47:33 +0200 Subject: [PATCH 04/35] Changing file structure of documentation section of docs. (#20104) --- docs/{ => articles_en}/documentation.md | 0 .../documentation/openvino_security.md} | 0 .../documentation/openvino_security}/protecting_model_guide.md | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename docs/{ => articles_en}/documentation.md (100%) rename docs/{security_guide/introduction.md => articles_en/documentation/openvino_security.md} (100%) rename docs/{OV_Runtime_UG => articles_en/documentation/openvino_security}/protecting_model_guide.md (100%) diff --git a/docs/documentation.md b/docs/articles_en/documentation.md similarity index 100% rename from docs/documentation.md rename to docs/articles_en/documentation.md diff --git a/docs/security_guide/introduction.md b/docs/articles_en/documentation/openvino_security.md similarity index 100% rename from docs/security_guide/introduction.md rename to docs/articles_en/documentation/openvino_security.md diff --git a/docs/OV_Runtime_UG/protecting_model_guide.md b/docs/articles_en/documentation/openvino_security/protecting_model_guide.md similarity index 100% rename from docs/OV_Runtime_UG/protecting_model_guide.md rename to docs/articles_en/documentation/openvino_security/protecting_model_guide.md From c90bcbf5eb15c8a19a8ae6e3d42a6b8e8080b081 Mon Sep 17 00:00:00 2001 From: Anastasia Kuporosova Date: Thu, 28 Sep 2023 09:35:54 +0200 Subject: [PATCH 05/35] [PyOV] fix if_op return types (#20014) * [PyOV] fix if_op return types * fix if * other types * test for if * add tests, try fix loop, ti * fix ci --- .../python/src/pyopenvino/graph/model.cpp | 12 ++++++++++ .../python/src/pyopenvino/graph/ops/if.cpp | 24 +++++++++++++------ .../python/src/pyopenvino/graph/ops/loop.cpp | 4 +++- .../pyopenvino/graph/ops/tensor_iterator.cpp | 8 +++++-- .../python/tests/test_graph/test_if.py | 8 ++++++- .../python/tests/test_graph/test_loop.py | 7 +++++- .../tests/test_graph/test_tensor_iterator.py | 7 +++++- 7 files changed, 57 insertions(+), 13 deletions(-) diff --git a/src/bindings/python/src/pyopenvino/graph/model.cpp b/src/bindings/python/src/pyopenvino/graph/model.cpp index 3bb4995d27aed6..f666fcd8e7602d 100644 --- a/src/bindings/python/src/pyopenvino/graph/model.cpp +++ b/src/bindings/python/src/pyopenvino/graph/model.cpp @@ -998,6 +998,18 @@ void regclass_graph_Model(py::module m) { :type path: str )"); + model.def( + "_get_raw_address", + [](ov::Model& self) { + return reinterpret_cast(&self); + }, + R"( + Returns raw address of the Model object. + + :return: a raw address of the Model object. + :rtype: int + )"); + model.def_property_readonly("inputs", (std::vector>(ov::Model::*)()) & ov::Model::inputs); model.def_property_readonly("outputs", (std::vector>(ov::Model::*)()) & ov::Model::outputs); model.def_property_readonly("name", &ov::Model::get_name); diff --git a/src/bindings/python/src/pyopenvino/graph/ops/if.cpp b/src/bindings/python/src/pyopenvino/graph/ops/if.cpp index d1eb84eb014d46..ad83891ebaa68a 100644 --- a/src/bindings/python/src/pyopenvino/graph/ops/if.cpp +++ b/src/bindings/python/src/pyopenvino/graph/ops/if.cpp @@ -49,9 +49,14 @@ void regclass_graph_op_If(py::module m) { :rtype: openvino.impl.op.If )"); - cls.def("get_else_body", - &ov::op::v8::If::get_else_body, - R"( + cls.def( + "get_else_body", + [](ov::op::v8::If& self) { + auto model = self.get_else_body(); + py::type model_class = py::module_::import("openvino.runtime").attr("Model"); + return model_class(py::cast(model)); + }, + R"( Gets else_body as Model object. :return: else_body as Model object. @@ -119,10 +124,15 @@ void regclass_graph_op_If(py::module m) { :rtype: openvino.runtime.Output )"); - cls.def("get_function", - &ov::op::util::MultiSubGraphOp::get_function, - py::arg("index"), - R"( + cls.def( + "get_function", + [](ov::op::v8::If& self, size_t index) { + auto model = self.get_function(index); + py::type model_class = py::module_::import("openvino.runtime").attr("Model"); + return model_class(py::cast(model)); + }, + py::arg("index"), + R"( Gets internal sub-graph by index in MultiSubGraphOp. :param index: sub-graph's index in op. diff --git a/src/bindings/python/src/pyopenvino/graph/ops/loop.cpp b/src/bindings/python/src/pyopenvino/graph/ops/loop.cpp index c378c9cbe322ed..ebf317d3c460e8 100644 --- a/src/bindings/python/src/pyopenvino/graph/ops/loop.cpp +++ b/src/bindings/python/src/pyopenvino/graph/ops/loop.cpp @@ -92,7 +92,9 @@ void regclass_graph_op_Loop(py::module m) { py::arg("successive_value")); cls.def("get_function", [](const std::shared_ptr& self) { - return self->get_function(); + auto model = self->get_function(); + py::type model_class = py::module_::import("openvino.runtime").attr("Model"); + return model_class(py::cast(model)); }); cls.def( diff --git a/src/bindings/python/src/pyopenvino/graph/ops/tensor_iterator.cpp b/src/bindings/python/src/pyopenvino/graph/ops/tensor_iterator.cpp index 1a973fa04ed93a..1b2b159bb7e51f 100644 --- a/src/bindings/python/src/pyopenvino/graph/ops/tensor_iterator.cpp +++ b/src/bindings/python/src/pyopenvino/graph/ops/tensor_iterator.cpp @@ -55,11 +55,15 @@ void regclass_graph_op_TensorIterator(py::module m) { py::arg("successive_value")); cls.def("get_body", [](const std::shared_ptr& self) { - return self->get_body(); + auto model = self->get_body(); + py::type model_class = py::module_::import("openvino.runtime").attr("Model"); + return model_class(py::cast(model)); }); cls.def("get_function", [](const std::shared_ptr& self) { - return self->get_function(); + auto model = self->get_function(); + py::type model_class = py::module_::import("openvino.runtime").attr("Model"); + return model_class(py::cast(model)); }); cls.def( diff --git a/src/bindings/python/tests/test_graph/test_if.py b/src/bindings/python/tests/test_graph/test_if.py index eff446219c109a..7e165342a2ce02 100644 --- a/src/bindings/python/tests/test_graph/test_if.py +++ b/src/bindings/python/tests/test_graph/test_if.py @@ -8,6 +8,8 @@ from openvino.runtime.op.util import InvariantInputDescription, BodyOutputDescription +from tests.utils.helpers import compare_models + def create_simple_if_with_two_outputs(condition_val): condition = ov.constant(condition_val, dtype=bool) @@ -191,7 +193,11 @@ def test_simple_if_basic(): if_node = ov.if_op(condition.output(0)) if_node.set_function(0, then_body) - assert if_node.get_function(0) == then_body + subgraph_func = if_node.get_function(0) + + assert type(subgraph_func) == type(then_body) + assert compare_models(subgraph_func, then_body) + assert subgraph_func._get_raw_address() == then_body._get_raw_address() if_node.set_input_descriptions(0, then_body_inputs) if_node.set_output_descriptions(1, else_body_outputs) diff --git a/src/bindings/python/tests/test_graph/test_loop.py b/src/bindings/python/tests/test_graph/test_loop.py index c30cfad11032f4..9a2fb6fcaf62d9 100644 --- a/src/bindings/python/tests/test_graph/test_loop.py +++ b/src/bindings/python/tests/test_graph/test_loop.py @@ -13,6 +13,7 @@ MergedInputDescription, ConcatOutputDescription, ) +from tests.utils.helpers import compare_models def test_simple_loop(): @@ -139,7 +140,11 @@ def test_loop_basic(): loop.get_iter_value(curr_cma.output(0), -1) loop.get_concatenated_slices(cma_hist.output(0), 0, 1, 1, -1, 0) - assert loop.get_function() == graph_body + subgraph_func = loop.get_function() + + assert type(subgraph_func) == type(graph_body) + assert subgraph_func._get_raw_address() == graph_body._get_raw_address() + assert compare_models(subgraph_func, graph_body) assert loop.get_special_body_ports() == body_ports assert loop.get_num_iterations() == 16 diff --git a/src/bindings/python/tests/test_graph/test_tensor_iterator.py b/src/bindings/python/tests/test_graph/test_tensor_iterator.py index 36c50713f6a86e..dd58b3da3f403a 100644 --- a/src/bindings/python/tests/test_graph/test_tensor_iterator.py +++ b/src/bindings/python/tests/test_graph/test_tensor_iterator.py @@ -13,6 +13,7 @@ MergedInputDescription, ConcatOutputDescription, ) +from tests.utils.helpers import compare_models def test_simple_tensor_iterator(): @@ -118,7 +119,11 @@ def test_tensor_iterator_basic(): ti.get_iter_value(curr_cma.output(0), -1) ti.get_concatenated_slices(cma_hist.output(0), 0, 1, 1, -1, 0) - assert ti.get_function() == graph_body + subgraph_func = ti.get_function() + + assert type(subgraph_func) == type(graph_body) + assert compare_models(subgraph_func, graph_body) + assert subgraph_func._get_raw_address() == graph_body._get_raw_address() assert ti.get_num_iterations() == 16 input_desc = ti.get_input_descriptions() From 20ec04bfcc50be49ede6df5c60b4fbfef5b83a89 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Thu, 28 Sep 2023 12:03:46 +0400 Subject: [PATCH 06/35] Try to use vcpkg cache (#20102) --- .github/workflows/android_arm64.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/android_arm64.yml b/.github/workflows/android_arm64.yml index 96f686a8d94777..e4360eb08d3850 100644 --- a/.github/workflows/android_arm64.yml +++ b/.github/workflows/android_arm64.yml @@ -43,13 +43,15 @@ jobs: OPENVINO_REPO: '/__w/openvino/openvino/openvino' VCPKG_ROOT: '/__w/openvino/openvino/vcpkg' BUILD_DIR: '/__w/openvino/openvino/build' - INSTALL_DIR: '/__w/openvino/openvino/install' ANDROID_TOOLS: '/__w/openvino/openvino/android_tools' ANDROID_NDK_HOME: '/__w/openvino/openvino/android_tools/ndk-bundle' ANDROID_SDK_VERSION: 29 ANDROID_ABI_CONFIG: arm64-v8a + VCPKG_DEFAULT_BINARY_CACHE: '/mount/caches/ccache/android_arm64/vcpkg_cache' + VCPKG_FORCE_SYSTEM_BINARIES: '1' CCACHE_DIR: '/mount/caches/ccache/android_arm64' CCACHE_TEMPDIR: '/__w/openvino/openvino/ccache_temp' + CCACHE_COMPILERCHECK: 'content' CCACHE_MAXSIZE: 50G steps: - name: Install git @@ -106,6 +108,7 @@ jobs: - name: Build vcpkg run: | + mkdir -p ${VCPKG_DEFAULT_BINARY_CACHE} ${VCPKG_ROOT}/bootstrap-vcpkg.sh # patch vcpkg default toolchain to build only Release configuration echo "set(VCPKG_BUILD_TYPE release)" >> ${VCPKG_ROOT}/triplets/arm64-android.cmake From 1be993dd39c146800947e3c8b2e6fd27fb0bba6e Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Thu, 28 Sep 2023 12:11:14 +0400 Subject: [PATCH 07/35] [GHA] Don't build documentation in post-commit (#20099) --- .github/workflows/build_doc.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/build_doc.yml b/.github/workflows/build_doc.yml index 9e61875f563073..b7e688d55f8c4a 100644 --- a/.github/workflows/build_doc.yml +++ b/.github/workflows/build_doc.yml @@ -1,10 +1,6 @@ name: Documentation on: pull_request: - push: - branches: - - 'master' - - 'releases/**' env: DOXY_VER: '1.9.6' From fea6db1a5f595128bd338facc6c99d5347ad41a3 Mon Sep 17 00:00:00 2001 From: Maxim Vafin Date: Thu, 28 Sep 2023 10:52:09 +0200 Subject: [PATCH 08/35] [PT FE] Fix issue when cat input is folded to tensor (#20090) * [PT FE] Fix issue when cat input is folded to tensor * CHeck real first input * Update src/frontends/pytorch/src/op/cat.cpp --- src/frontends/pytorch/src/input_model.cpp | 4 +-- src/frontends/pytorch/src/op/cat.cpp | 31 +++++++++++++++---- .../layer_tests/pytorch_tests/test_linear.py | 28 +++++++++++++++++ 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/frontends/pytorch/src/input_model.cpp b/src/frontends/pytorch/src/input_model.cpp index 78400ad91785f7..bce1937151d92d 100644 --- a/src/frontends/pytorch/src/input_model.cpp +++ b/src/frontends/pytorch/src/input_model.cpp @@ -141,7 +141,7 @@ void InputModel::override_all_inputs(const std::vector& inputs) { "Number of inputs provided is incorrect. Graph modification is not supported for " "this model. Expected number of inputs: ", m_inputs.size() - 1, - " recieved ", + " received ", inputs.size()); auto self_place = m_inputs[0]; // Verify that no same place already in vector @@ -158,7 +158,7 @@ void InputModel::override_all_inputs(const std::vector& inputs) { "Number of inputs provided is incorrect. Graph modification is not supported for " "this model. Expected number of inputs: ", m_inputs.size(), - " recieved ", + " received ", inputs.size()); m_inputs = inputs; } diff --git a/src/frontends/pytorch/src/op/cat.cpp b/src/frontends/pytorch/src/op/cat.cpp index 7c2a43f0c38ff5..63e61734544333 100644 --- a/src/frontends/pytorch/src/op/cat.cpp +++ b/src/frontends/pytorch/src/op/cat.cpp @@ -5,6 +5,10 @@ #include "openvino/frontend/pytorch/node_context.hpp" #include "openvino/op/concat.hpp" #include "openvino/op/parameter.hpp" +#include "openvino/op/reshape.hpp" +#include "openvino/op/scatter_elements_update.hpp" +#include "openvino/op/shape_of.hpp" +#include "openvino/op/slice.hpp" #include "pt_framework_node.hpp" #include "utils.hpp" #include "utils_quantize.hpp" @@ -28,12 +32,27 @@ OutputVector translate_cat_common(const NodeContext& context, attrs["axis"] = std::to_string(axis); fw_node->set_attrs(attrs); return {context.mark_node(fw_node)}; - } else { - auto first_elem = list_elems.front().get_node_shared_ptr(); - FRONT_END_OP_CONVERSION_CHECK( - list_elems.size() > 1 || !ov::as_type_ptr(first_elem), - "::cat is located inside body while inputs are located outside of the body. " - "This case is not supported."); + } + auto first_node = list_elems.front().get_node_shared_ptr(); + FRONT_END_OP_CONVERSION_CHECK( + list_elems.size() > 1 || !ov::as_type_ptr(first_node), + "::cat is located inside body while inputs are located outside of the body. " + "This case is not supported."); + if (list_elems.size() == 1 && + !std::dynamic_pointer_cast(context.get_input(0).get_node_shared_ptr())) { + // Case when list was merged into tensor + auto tensor = list_elems[0]; + auto shape = context.mark_node(std::make_shared(tensor, element::i32)); + auto zero = context.mark_node(v0::Constant::create(element::i32, Shape{}, {0})); + auto neg_1 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {-1})); + auto axis_const = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {axis})); + auto one = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {1})); + auto int_max = + context.mark_node(v0::Constant::create(element::i32, Shape{1}, {std::numeric_limits().max()})); + auto shape_sliced = context.mark_node(std::make_shared(shape, one, int_max, one)); + auto new_shape = + context.mark_node(std::make_shared(shape_sliced, axis_const, neg_1, zero)); + return {context.mark_node(std::make_shared(tensor, new_shape, false))}; } auto concat = std::make_shared(OutputVector(list_elems.begin(), list_elems.end()), axis); return {context.mark_node(concat)}; diff --git a/tests/layer_tests/pytorch_tests/test_linear.py b/tests/layer_tests/pytorch_tests/test_linear.py index 4b7d9d58b1b458..7093eb507ddaba 100644 --- a/tests/layer_tests/pytorch_tests/test_linear.py +++ b/tests/layer_tests/pytorch_tests/test_linear.py @@ -48,3 +48,31 @@ def forward2(self, m1, m2, bias): def test_matmul(self, kwargs_to_prepare_input, ie_device, precision, ir_version): self._test(*self.create_model(len(kwargs_to_prepare_input) == 3), ie_device, precision, ir_version, kwargs_to_prepare_input=kwargs_to_prepare_input) + + +class TestLinearBiasList(PytorchLayerTest): + def _prepare_input(self): + import numpy as np + return (np.random.randn(1, 15, 10).astype(np.float32), np.random.randn(66, 10).astype(np.float32)) + + def create_model(self): + import torch + + class aten_mm(torch.nn.Module): + def __init__(self): + super(aten_mm, self).__init__() + self.bias = [torch.randn(22), + torch.randn(22), + torch.randn(22)] + + def forward(self, m1, m2): + m2 = m2.reshape([66, -1]) + return torch.nn.functional.linear(m1, m2, torch.cat(self.bias, 0)) + + return aten_mm(), None, "aten::linear" + + @pytest.mark.nightly + @pytest.mark.precommit + def test_linear_bias_list(self, ie_device, precision, ir_version): + self._test(*self.create_model(), ie_device, precision, ir_version, + trace_model=True, freeze_model=False) From b0507b99184dc732fa063ad20f4ba4b34b139a89 Mon Sep 17 00:00:00 2001 From: Maciej Smyk Date: Thu, 28 Sep 2023 11:03:58 +0200 Subject: [PATCH 09/35] Update release_notes.md (#20113) --- docs/articles_en/about_openvino/release_notes.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/articles_en/about_openvino/release_notes.md b/docs/articles_en/about_openvino/release_notes.md index 0392a84c975082..9d7427f919d6ad 100644 --- a/docs/articles_en/about_openvino/release_notes.md +++ b/docs/articles_en/about_openvino/release_notes.md @@ -4,7 +4,7 @@ .. raw:: html - + .. toctree:: @@ -12,7 +12,7 @@ prerelease_information -The official OpenVINO Release Notes are published at `www.intel.com `__ +The official OpenVINO Release Notes are published at `www.intel.com `__ @endsphinxdirective \ No newline at end of file From 7dd5d9720c78e05e63d4eb1ac7ffea3f37a49b98 Mon Sep 17 00:00:00 2001 From: Sebastian Golebiewski Date: Thu, 28 Sep 2023 11:09:14 +0200 Subject: [PATCH 10/35] Changing file structure of documentation gapi section of docs (#20107) --- .../documentation}/media_processing_cv_libraries.md | 0 .../documentation/media_processing_cv_libraries}/dlstreamer.md | 0 .../documentation/media_processing_cv_libraries}/gapi_intro.md | 0 .../gapi_intro}/face_beautification.md | 0 .../gapi_intro}/gapi_face_analytics_pipeline.md | 0 .../media_processing_cv_libraries/gapi_intro}/kernel_api.md | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename docs/{Documentation => articles_en/documentation}/media_processing_cv_libraries.md (100%) rename docs/{ => articles_en/documentation/media_processing_cv_libraries}/dlstreamer.md (100%) rename docs/{gapi => articles_en/documentation/media_processing_cv_libraries}/gapi_intro.md (100%) rename docs/{gapi => articles_en/documentation/media_processing_cv_libraries/gapi_intro}/face_beautification.md (100%) rename docs/{gapi => articles_en/documentation/media_processing_cv_libraries/gapi_intro}/gapi_face_analytics_pipeline.md (100%) rename docs/{gapi => articles_en/documentation/media_processing_cv_libraries/gapi_intro}/kernel_api.md (100%) diff --git a/docs/Documentation/media_processing_cv_libraries.md b/docs/articles_en/documentation/media_processing_cv_libraries.md similarity index 100% rename from docs/Documentation/media_processing_cv_libraries.md rename to docs/articles_en/documentation/media_processing_cv_libraries.md diff --git a/docs/dlstreamer.md b/docs/articles_en/documentation/media_processing_cv_libraries/dlstreamer.md similarity index 100% rename from docs/dlstreamer.md rename to docs/articles_en/documentation/media_processing_cv_libraries/dlstreamer.md diff --git a/docs/gapi/gapi_intro.md b/docs/articles_en/documentation/media_processing_cv_libraries/gapi_intro.md similarity index 100% rename from docs/gapi/gapi_intro.md rename to docs/articles_en/documentation/media_processing_cv_libraries/gapi_intro.md diff --git a/docs/gapi/face_beautification.md b/docs/articles_en/documentation/media_processing_cv_libraries/gapi_intro/face_beautification.md similarity index 100% rename from docs/gapi/face_beautification.md rename to docs/articles_en/documentation/media_processing_cv_libraries/gapi_intro/face_beautification.md diff --git a/docs/gapi/gapi_face_analytics_pipeline.md b/docs/articles_en/documentation/media_processing_cv_libraries/gapi_intro/gapi_face_analytics_pipeline.md similarity index 100% rename from docs/gapi/gapi_face_analytics_pipeline.md rename to docs/articles_en/documentation/media_processing_cv_libraries/gapi_intro/gapi_face_analytics_pipeline.md diff --git a/docs/gapi/kernel_api.md b/docs/articles_en/documentation/media_processing_cv_libraries/gapi_intro/kernel_api.md similarity index 100% rename from docs/gapi/kernel_api.md rename to docs/articles_en/documentation/media_processing_cv_libraries/gapi_intro/kernel_api.md From 7761fc754cefde0e76a8528a1a87a28dccd477b6 Mon Sep 17 00:00:00 2001 From: Roman Kazantsev Date: Thu, 28 Sep 2023 13:10:39 +0400 Subject: [PATCH 11/35] [Hub Tests] Move TF Hub tests to AKS runners (#20049) * [Hub Tests] Move Hub tests to self-host runners Signed-off-by: Kazantsev, Roman * Not all directories possible to clean up * Move Hub models tests to AKS nodes * Add install actions python setup * Add ca-certificate deps to install * Fix bug for PT models * Update .github/workflows/linux.yml Co-authored-by: Ilya Lavrenov * Update .github/workflows/linux.yml * Revert changes for PT models tests Signed-off-by: Kazantsev, Roman * Install correct version of OV --------- Signed-off-by: Kazantsev, Roman Co-authored-by: Ilya Lavrenov --- .github/workflows/linux.yml | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 60dc3d8c7c7be7..51b550e6e960a1 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -874,7 +874,11 @@ jobs: defaults: run: shell: bash - runs-on: ${{ github.event_name == 'schedule' && 'ubuntu-20.04-8-cores' || 'ubuntu-20.04'}} + runs-on: ${{ github.event_name == 'schedule' && 'aks-linux-16-cores' || 'aks-linux-4-cores'}} + container: + image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 + volumes: + - /mount/caches:/mount/caches env: INSTALL_DIR: ${{ github.workspace }}/install INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests @@ -882,7 +886,10 @@ jobs: steps: - name: Create Directories - run: mkdir -p ${{ env.INSTALL_DIR }} ${{ env.INSTALL_TEST_DIR }} + run: mkdir -p ${INSTALL_DIR} ${INSTALL_TEST_DIR} + + - name: Install 'actions/setup-python@v4' dependencies + run: apt-get update && apt-get install -y libssl1.1 ca-certificates - uses: actions/setup-python@v4 with: @@ -902,26 +909,25 @@ jobs: - 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 + pushd ${INSTALL_DIR} + tar -xzf openvino_package.tar.gz -C ${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 + pushd ${INSTALL_TEST_DIR} + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} && rm openvino_tests.tar.gz || exit 1 popd - name: Install OpenVINO Python wheels - run: | - python3 -m pip install openvino --find-links=${{ env.INSTALL_DIR }}/tools + run: python3 -m pip install ${INSTALL_DIR}/tools/openvino-* - name: Install TF Hub tests requirements run: | - python3 -m pip install -r ${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}/tf_hub_tests/requirements.txt + python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/tf_hub_tests/requirements.txt - name: TensorFlow Hub Tests - TF FE run: | - export PYTHONPATH=${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}:$PYTHONPATH - python3 -m pytest ${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}/tf_hub_tests/ -m ${{ env.TYPE }} --html=${{ env.INSTALL_TEST_DIR }}/TEST-tf_hub_tf_fe.html --self-contained-html + export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH + python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/tf_hub_tests/ -m ${TYPE} --html=${INSTALL_TEST_DIR}/TEST-tf_hub_tf_fe.html --self-contained-html -v env: TYPE: ${{ github.event_name == 'schedule' && 'nightly' || 'precommit'}} TEST_DEVICE: CPU From 886be26c0bfea099eee3644c2c362aca7e05c61a Mon Sep 17 00:00:00 2001 From: Sergey Shlyapnikov Date: Thu, 28 Sep 2023 13:39:41 +0400 Subject: [PATCH 12/35] [GPU] Add handling of unsupported simd8 for PVC (#20093) --- .../convolution_kernel_b_fs_yx_fsv_16_32_imad_dw.cpp | 3 +++ .../kernel_selector/kernels/gemm/gemm_kernel_mmad_int8.cpp | 4 ++++ .../kernels/gemm/gemm_kernel_mmad_int8_slm.cpp | 3 +++ .../kernel_selector/kernels/gemm/gemm_kernel_tiled_opt.cpp | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_b_fs_yx_fsv_16_32_imad_dw.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_b_fs_yx_fsv_16_32_imad_dw.cpp index c7d80a8c8096ce..105930edb9423c 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_b_fs_yx_fsv_16_32_imad_dw.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_b_fs_yx_fsv_16_32_imad_dw.cpp @@ -213,6 +213,9 @@ bool ConvolutionKernel_b_fs_yx_fsv_16_32_imad_dw::ValidateAutoTuneParams(const c const AutoTuneParams& tparams) const { bool valid_tune_params = true; + if (!IsSIMDSizeSupported(params.engineInfo, tparams.simd)) + return false; + auto total_lws = tparams.simd * tparams.lws0 * tparams.lws1; valid_tune_params &= total_lws <= params.engineInfo.maxWorkGroupSize; diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/gemm/gemm_kernel_mmad_int8.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/gemm/gemm_kernel_mmad_int8.cpp index 1fab54da075335..0f67b5b99e2884 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernels/gemm/gemm_kernel_mmad_int8.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/gemm/gemm_kernel_mmad_int8.cpp @@ -183,6 +183,10 @@ bool GemmKernelMMADint8::Validate(const Params& params, const optional_params& o (input1_type != Datatype::UINT8 && input1_type != Datatype::INT8)) return false; + GemmTuningData tuning_data = SetTuningParams(gmm_params); + if (!IsSIMDSizeSupported(params.engineInfo, tuning_data.simd_size)) + return false; + return true; } } // namespace kernel_selector diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/gemm/gemm_kernel_mmad_int8_slm.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/gemm/gemm_kernel_mmad_int8_slm.cpp index 16119fd5b72440..b7c8100189fcec 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernels/gemm/gemm_kernel_mmad_int8_slm.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/gemm/gemm_kernel_mmad_int8_slm.cpp @@ -161,6 +161,9 @@ bool GemmKernelMMADslmInt8::Validate(const Params& params, const optional_params if (HasLeftovers(tuning_data)) return false; + if (!IsSIMDSizeSupported(params.engineInfo, tuning_data.simd_size)) + return false; + if ((input0_type != Datatype::UINT8 && input0_type != Datatype::INT8) || (input1_type != Datatype::UINT8 && input1_type != Datatype::INT8)) return false; diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/gemm/gemm_kernel_tiled_opt.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/gemm/gemm_kernel_tiled_opt.cpp index e0c4eabaeab18e..7d8a1dceb178c8 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernels/gemm/gemm_kernel_tiled_opt.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/gemm/gemm_kernel_tiled_opt.cpp @@ -83,7 +83,7 @@ GemmKernelTiledOpt::GemmTuningData GemmKernelTiledOpt::SetTuningParams(const gem bool leftovers = m_size % tuning_data.tile_m_size || k_size % tuning_data.tile_k_size || n_size % tuning_data.tile_n_size; - if (leftovers || total_batches > 1 || params.transpose_input0 || params.transpose_input1) { + if (leftovers || total_batches > 1 || params.transpose_input0 || params.transpose_input1 || !IsSIMDSizeSupported(params.engineInfo, 8)) { tuning_data.simd_size = 16; tuning_data.tile_n_size = tuning_data.simd_size; tuning_data.tile_k_size = tuning_data.simd_size; From f9678a285c9373e86ac459fd4d4c103e91036b9d Mon Sep 17 00:00:00 2001 From: Sergey Shlyapnikov Date: Thu, 28 Sep 2023 13:53:51 +0400 Subject: [PATCH 13/35] [GPU] Do not use usm_host memory buffers for PVC as a device inputs (#19767) --- .../src/plugin/sync_infer_request.cpp | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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 2e6699333070f9..d5ee5d423fcd13 100644 --- a/src/plugins/intel_gpu/src/plugin/sync_infer_request.cpp +++ b/src/plugins/intel_gpu/src/plugin/sync_infer_request.cpp @@ -28,6 +28,19 @@ namespace { +inline bool can_use_usm_host(const cldnn::engine& engine) { + auto can_use_usm = engine.use_unified_shared_memory(); + + // WA: Disable USM host memory for infer request`s tensors for PVC as + // it has performance issues in case of host <-> device data transfers inside kernels + // Use unsupported SIMD8 as unique attribute of PVC + auto supported_simd_sizes = engine.get_device_info().supported_simd_sizes; + if (std::find(supported_simd_sizes.begin(), supported_simd_sizes.end(), 8) == supported_simd_sizes.end()) + can_use_usm = false; + + return can_use_usm; +} + 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 @@ -480,6 +493,10 @@ std::shared_ptr SyncInferRequest::create_device_tensor(const ov::Sh tensor_type = TensorType::BT_BUF_INTERNAL; } + // Create OpenCL buffer for PVC if lockable memory is needed due to performance issue with usm host + 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 @@ -512,7 +529,9 @@ TensorWrapper SyncInferRequest::create_or_share_device_tensor(const TensorWrappe 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); + bool can_share = is_usm_host && + !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 From 197e954846aa8d434f9bb86672d4b138d2b34bd1 Mon Sep 17 00:00:00 2001 From: Pawel Raasz Date: Thu, 28 Sep 2023 12:12:21 +0200 Subject: [PATCH 14/35] [core]Migrate reduce ops max min mean prod sum evaluate to new API (#19756) * Migrate ReduceL1, ReduceL2 to new API - add some new utils which are deprecated * Hide helper functions from public API * Migrate reductions ops to new API * Migrate get_constant_from_source to dev API * Rename ref max to reduce_max * Rename ref min to reduce_min * Rename ref mean to reduce_mean * Rename ref sum to reduce_sum * Rename ref product to reduce_prod - minor optimization in ReduceProd operator * Restore custom isfinite for ov float types * Fix type name in reduce_max.hpp * Add missing include in shape_util.hpp * Make count same type as data type in reduce mean * Correct reduce sum doxy comment --- src/core/dev_api/validation_util.hpp | 9 ++ src/core/include/openvino/op/reduce_max.hpp | 4 +- src/core/include/openvino/op/reduce_mean.hpp | 4 +- src/core/include/openvino/op/reduce_min.hpp | 4 +- src/core/include/openvino/op/reduce_prod.hpp | 4 +- src/core/include/openvino/op/reduce_sum.hpp | 4 +- .../reference/group_normalization.hpp | 8 +- .../openvino/reference/log_softmax.hpp | 8 +- .../include/openvino/reference/max.hpp | 46 ------ .../include/openvino/reference/mean.hpp | 58 -------- .../include/openvino/reference/min.hpp | 51 ------- .../include/openvino/reference/mvn.hpp | 12 +- .../openvino/reference/normalize_l2.hpp | 4 +- .../include/openvino/reference/product.hpp | 39 ----- .../include/openvino/reference/reduce_l1.hpp | 2 +- .../include/openvino/reference/reduce_max.hpp | 46 ++++++ .../openvino/reference/reduce_mean.hpp | 36 +++++ .../include/openvino/reference/reduce_min.hpp | 46 ++++++ .../openvino/reference/reduce_prod.hpp | 42 ++++++ .../include/openvino/reference/reduce_sum.hpp | 94 +++++++++++++ .../include/openvino/reference/softmax.hpp | 8 +- .../include/openvino/reference/sum.hpp | 84 ----------- src/core/reference/src/op/einsum.cpp | 6 +- src/core/shape_inference/include/utils.hpp | 9 +- src/core/src/op/reduce_l1.cpp | 4 +- src/core/src/op/reduce_l2.cpp | 2 +- src/core/src/op/reduce_max.cpp | 109 ++++++-------- src/core/src/op/reduce_mean.cpp | 104 ++++++-------- src/core/src/op/reduce_min.cpp | 108 ++++++-------- src/core/src/op/reduce_prod.cpp | 133 ++++++++---------- src/core/src/op/reduce_sum.cpp | 105 ++++++-------- src/core/src/op/util/axes_util.cpp | 2 +- src/core/src/op/util/reduction_base.cpp | 11 +- src/core/src/validation_util.cpp | 24 +++- 34 files changed, 567 insertions(+), 663 deletions(-) delete mode 100644 src/core/reference/include/openvino/reference/max.hpp delete mode 100644 src/core/reference/include/openvino/reference/mean.hpp delete mode 100644 src/core/reference/include/openvino/reference/min.hpp delete mode 100644 src/core/reference/include/openvino/reference/product.hpp create mode 100644 src/core/reference/include/openvino/reference/reduce_max.hpp create mode 100644 src/core/reference/include/openvino/reference/reduce_mean.hpp create mode 100644 src/core/reference/include/openvino/reference/reduce_min.hpp create mode 100644 src/core/reference/include/openvino/reference/reduce_prod.hpp create mode 100644 src/core/reference/include/openvino/reference/reduce_sum.hpp delete mode 100644 src/core/reference/include/openvino/reference/sum.hpp diff --git a/src/core/dev_api/validation_util.hpp b/src/core/dev_api/validation_util.hpp index 452445a055b8a5..fe607828c80148 100644 --- a/src/core/dev_api/validation_util.hpp +++ b/src/core/dev_api/validation_util.hpp @@ -38,5 +38,14 @@ OPENVINO_API int64_t clip(const int64_t& value, const int64_t& min, const int64_ /// /// \return Constant node or nullptr if unable to constantfold the subgraph OPENVINO_API std::shared_ptr constantfold_subgraph(const Output& subgraph_sink); + +/** + * @brief Runs an estimation of source tensor. If it succeeded to calculate both bounds and + * they are the same returns Constant operation from the resulting bound, otherwise nullptr. + * + * @param source Node output used to get its tensor data as constant. + * @return Shared pointer to constant data or nullptr. + */ +OPENVINO_API std::shared_ptr get_constant_from_source(const Output& source); } // namespace util } // namespace ov diff --git a/src/core/include/openvino/op/reduce_max.hpp b/src/core/include/openvino/op/reduce_max.hpp index 594450d69d9532..1e8e508b30c637 100644 --- a/src/core/include/openvino/op/reduce_max.hpp +++ b/src/core/include/openvino/op/reduce_max.hpp @@ -26,9 +26,7 @@ class OPENVINO_API ReduceMax : public util::ArithmeticReductionKeepDims { 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 evaluate_lower(TensorVector& outputs) const override; bool evaluate_upper(TensorVector& outputs) const override; diff --git a/src/core/include/openvino/op/reduce_mean.hpp b/src/core/include/openvino/op/reduce_mean.hpp index 7b50dd57b7dafc..f8c4bb9bf91eb2 100644 --- a/src/core/include/openvino/op/reduce_mean.hpp +++ b/src/core/include/openvino/op/reduce_mean.hpp @@ -24,9 +24,7 @@ class OPENVINO_API ReduceMean : public util::ArithmeticReductionKeepDims { 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/reduce_min.hpp b/src/core/include/openvino/op/reduce_min.hpp index 830021a0bb2ae0..0fe90c35caf7ec 100644 --- a/src/core/include/openvino/op/reduce_min.hpp +++ b/src/core/include/openvino/op/reduce_min.hpp @@ -26,9 +26,7 @@ class OPENVINO_API ReduceMin : public util::ArithmeticReductionKeepDims { 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 evaluate_lower(TensorVector& outputs) const override; bool evaluate_upper(TensorVector& outputs) const override; diff --git a/src/core/include/openvino/op/reduce_prod.hpp b/src/core/include/openvino/op/reduce_prod.hpp index 4a9af6339b6797..d53ba7ca4049a2 100644 --- a/src/core/include/openvino/op/reduce_prod.hpp +++ b/src/core/include/openvino/op/reduce_prod.hpp @@ -27,9 +27,7 @@ class OPENVINO_API ReduceProd : public util::ArithmeticReductionKeepDims { 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 evaluate_lower(TensorVector& outputs) const override; bool evaluate_upper(TensorVector& outputs) const override; diff --git a/src/core/include/openvino/op/reduce_sum.hpp b/src/core/include/openvino/op/reduce_sum.hpp index 7a3221c68e52ef..8a210c60986fdf 100644 --- a/src/core/include/openvino/op/reduce_sum.hpp +++ b/src/core/include/openvino/op/reduce_sum.hpp @@ -73,9 +73,7 @@ class OPENVINO_API ReduceSum : public util::ArithmeticReductionKeepDims { 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/reference/include/openvino/reference/group_normalization.hpp b/src/core/reference/include/openvino/reference/group_normalization.hpp index 35a215b7123757..d6e5602a586742 100644 --- a/src/core/reference/include/openvino/reference/group_normalization.hpp +++ b/src/core/reference/include/openvino/reference/group_normalization.hpp @@ -8,8 +8,8 @@ #include #include "openvino/core/shape.hpp" -#include "openvino/reference/mean.hpp" -#include "openvino/reference/sum.hpp" +#include "openvino/reference/reduce_mean.hpp" +#include "openvino/reference/reduce_sum.hpp" namespace ov { namespace reference { @@ -38,11 +38,11 @@ void group_normalization(const T* const data, const auto group_begin = data + n * batch_size + g * group_size; const auto group_end = group_begin + group_size; std::vector mean_value(1); - mean(group_begin, mean_value.data(), Shape{group_size}, {0}); + reduce_mean(group_begin, mean_value.data(), Shape{group_size}, {0}); T mean = mean_value[0]; T variance = 0, err = 0; for_each(group_begin, group_end, [&](const T d) { - return details::kahan_summation(static_cast(pow(d - mean, 2)), err, variance); + variance = details::kahan_summation(static_cast(pow(d - mean, 2)), variance, err); }); variance /= group_size; const T standard_deviation = sqrt(variance + eps); diff --git a/src/core/reference/include/openvino/reference/log_softmax.hpp b/src/core/reference/include/openvino/reference/log_softmax.hpp index fb5d455b28a330..7335bd36989b18 100644 --- a/src/core/reference/include/openvino/reference/log_softmax.hpp +++ b/src/core/reference/include/openvino/reference/log_softmax.hpp @@ -7,8 +7,8 @@ #include #include "ngraph/shape_util.hpp" -#include "openvino/reference/max.hpp" -#include "openvino/reference/sum.hpp" +#include "openvino/reference/reduce_max.hpp" +#include "openvino/reference/reduce_sum.hpp" #include "openvino/reference/utils/coordinate_transform.hpp" namespace ov { @@ -21,7 +21,7 @@ void log_softmax(const T* arg, T* out, const Shape& shape, const AxisSet& axes) auto temp_max = std::vector(temp_elements, 0); auto temp_sum = std::vector(temp_elements, 0); - max(arg, temp_max.data(), shape, axes); + reduce_max(arg, temp_max.data(), shape, axes); CoordinateTransform transform(shape); CoordinateTransform temp_transform(temp_shape); @@ -31,7 +31,7 @@ void log_softmax(const T* arg, T* out, const Shape& shape, const AxisSet& axes) static_cast(std::exp(arg[transform.index(coord)] - temp_max[temp_transform.index(temp_coord)])); } - sum(out, temp_sum.data(), shape, axes); + reduce_sum(out, temp_sum.data(), shape, axes); for (const Coordinate& coord : transform) { Coordinate temp_coord = ngraph::reduce(coord, axes, true); diff --git a/src/core/reference/include/openvino/reference/max.hpp b/src/core/reference/include/openvino/reference/max.hpp deleted file mode 100644 index 0cbb810ecafbe5..00000000000000 --- a/src/core/reference/include/openvino/reference/max.hpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "ngraph/shape_util.hpp" -#include "openvino/reference/utils/coordinate_transform.hpp" - -namespace ov { -namespace reference { -template -void max(const T* arg, T* out, const Shape& in_shape, const AxisSet& reduction_axes) { - T minval = std::numeric_limits::lowest(); - - constexpr bool dont_keep_dims_in_output = false; - OPENVINO_SUPPRESS_DEPRECATED_START - const auto out_shape = ngraph::reduce(in_shape, reduction_axes, dont_keep_dims_in_output); - std::fill(out, out + shape_size(out_shape), minval); - - const auto in_strides = row_major_strides(in_shape); - const auto out_strides = row_major_strides(out_shape); - - CoordinateTransformBasic input_transform(in_shape); - for (const Coordinate& input_coord : input_transform) { - const Coordinate output_coord = ngraph::reduce(input_coord, reduction_axes, dont_keep_dims_in_output); - - const size_t in_idx = - std::inner_product(input_coord.begin(), input_coord.end(), in_strides.begin(), uint64_t(0)); - const size_t out_idx = - std::inner_product(output_coord.begin(), output_coord.end(), out_strides.begin(), uint64_t(0)); - - const T x = arg[in_idx]; - const T max = out[out_idx]; - if (x > max) { - out[out_idx] = x; - } - } - OPENVINO_SUPPRESS_DEPRECATED_END -} -} // namespace reference -} // namespace ov diff --git a/src/core/reference/include/openvino/reference/mean.hpp b/src/core/reference/include/openvino/reference/mean.hpp deleted file mode 100644 index 85fe10eddcf6bd..00000000000000 --- a/src/core/reference/include/openvino/reference/mean.hpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include - -#include "ngraph/shape_util.hpp" -#include "ngraph/type/bfloat16.hpp" -#include "ngraph/type/float16.hpp" -#include "openvino/reference/sum.hpp" -#include "openvino/reference/utils/coordinate_transform.hpp" - -namespace ov { -namespace reference { -template -void mean(const T* arg, T* out, const Shape& in_shape, const AxisSet& reduction_axes) { - constexpr bool dont_keep_dims_in_output = false; - OPENVINO_SUPPRESS_DEPRECATED_START - const auto out_shape = ngraph::reduce(in_shape, reduction_axes, dont_keep_dims_in_output); - std::vector cs(shape_size(out_shape), 0); - std::fill(out, out + shape_size(out_shape), T(0)); - - const auto in_strides = row_major_strides(in_shape); - const auto out_strides = row_major_strides(out_shape); - - CoordinateTransformBasic input_transform(in_shape); - std::map index_to_count_map; - - for (const Coordinate& input_coord : input_transform) { - const Coordinate output_coord = ngraph::reduce(input_coord, reduction_axes, dont_keep_dims_in_output); - - const size_t in_idx = - std::inner_product(input_coord.begin(), input_coord.end(), in_strides.begin(), uint64_t(0)); - const size_t out_idx = - std::inner_product(output_coord.begin(), output_coord.end(), out_strides.begin(), uint64_t(0)); - - details::kahan_summation(arg[in_idx], cs[out_idx], out[out_idx]); - - if (index_to_count_map.find(out_idx) == index_to_count_map.end()) { - index_to_count_map[out_idx] = 1; - } else { - index_to_count_map[out_idx]++; - } - } - OPENVINO_SUPPRESS_DEPRECATED_END - - for (size_t i = 0; i < shape_size(out_shape); ++i) { - auto count = index_to_count_map[i]; - out[i] = out[i] / count; - } -} -} // namespace reference -} // namespace ov diff --git a/src/core/reference/include/openvino/reference/min.hpp b/src/core/reference/include/openvino/reference/min.hpp deleted file mode 100644 index 6d6c3e05df3ed1..00000000000000 --- a/src/core/reference/include/openvino/reference/min.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "ngraph/shape_util.hpp" -#include "openvino/reference/utils/coordinate_transform.hpp" - -#ifdef _WIN32 -# undef min -#endif - -namespace ov { -namespace reference { -template -void min(const T* arg, T* out, const Shape& in_shape, const AxisSet& reduction_axes) { - T minval = - std::numeric_limits::has_infinity ? std::numeric_limits::infinity() : std::numeric_limits::max(); - - constexpr bool dont_keep_dims_in_output = false; - OPENVINO_SUPPRESS_DEPRECATED_START - const auto out_shape = ngraph::reduce(in_shape, reduction_axes, dont_keep_dims_in_output); - std::fill(out, out + shape_size(out_shape), minval); - - const auto in_strides = row_major_strides(in_shape); - const auto out_strides = row_major_strides(out_shape); - - CoordinateTransformBasic input_transform(in_shape); - for (const Coordinate& input_coord : input_transform) { - const Coordinate output_coord = ngraph::reduce(input_coord, reduction_axes, dont_keep_dims_in_output); - - const size_t in_idx = - std::inner_product(input_coord.begin(), input_coord.end(), in_strides.begin(), uint64_t(0)); - const size_t out_idx = - std::inner_product(output_coord.begin(), output_coord.end(), out_strides.begin(), uint64_t(0)); - - const T x = arg[in_idx]; - const T min = out[out_idx]; - if (x < min) { - out[out_idx] = x; - } - } - OPENVINO_SUPPRESS_DEPRECATED_END -} -} // namespace reference -} // namespace ov diff --git a/src/core/reference/include/openvino/reference/mvn.hpp b/src/core/reference/include/openvino/reference/mvn.hpp index cd171fe73f24d5..8bcce83295e5eb 100644 --- a/src/core/reference/include/openvino/reference/mvn.hpp +++ b/src/core/reference/include/openvino/reference/mvn.hpp @@ -10,11 +10,11 @@ #include "openvino/reference/add.hpp" #include "openvino/reference/divide.hpp" -#include "openvino/reference/mean.hpp" #include "openvino/reference/multiply.hpp" +#include "openvino/reference/reduce_mean.hpp" +#include "openvino/reference/reduce_sum.hpp" #include "openvino/reference/sqrt.hpp" #include "openvino/reference/subtract.hpp" -#include "openvino/reference/sum.hpp" namespace ov { namespace reference { @@ -28,13 +28,13 @@ void mvn(const T* arg, const double eps) { auto reduced_shape = ngraph::reduce(in_shape, reduction_axes, true); std::vector tmp_buffer(shape_size(in_shape)); - mean(arg, tmp_buffer.data(), in_shape, reduction_axes); + reduce_mean(arg, tmp_buffer.data(), in_shape, reduction_axes); subtract(arg, tmp_buffer.data(), out, in_shape, reduced_shape, op::AutoBroadcastType::NUMPY); if (normalize_variance) { multiply(out, out, tmp_buffer.data(), shape_size(in_shape)); std::vector mean_value(shape_size(reduced_shape)); - mean(tmp_buffer.data(), mean_value.data(), in_shape, reduction_axes); + reduce_mean(tmp_buffer.data(), mean_value.data(), in_shape, reduction_axes); add(mean_value.data(), std::vector(shape_size(reduced_shape), static_cast(eps)).data(), @@ -58,13 +58,13 @@ void mvn_6(const T* arg, op::MVNEpsMode eps_mode) { auto reduced_shape = ngraph::reduce(in_shape, reduction_axes, true); std::vector tmp_buffer(shape_size(in_shape)); - mean(arg, tmp_buffer.data(), in_shape, reduction_axes); + reduce_mean(arg, tmp_buffer.data(), in_shape, reduction_axes); subtract(arg, tmp_buffer.data(), out, in_shape, reduced_shape, op::AutoBroadcastType::NUMPY); if (normalize_variance) { multiply(out, out, tmp_buffer.data(), shape_size(in_shape)); std::vector mean_value(shape_size(reduced_shape)); - mean(tmp_buffer.data(), mean_value.data(), in_shape, reduction_axes); + reduce_mean(tmp_buffer.data(), mean_value.data(), in_shape, reduction_axes); if (eps_mode == op::MVNEpsMode::INSIDE_SQRT) { add(mean_value.data(), diff --git a/src/core/reference/include/openvino/reference/normalize_l2.hpp b/src/core/reference/include/openvino/reference/normalize_l2.hpp index ce737f652afc7c..69c0cff34fdc34 100644 --- a/src/core/reference/include/openvino/reference/normalize_l2.hpp +++ b/src/core/reference/include/openvino/reference/normalize_l2.hpp @@ -7,7 +7,7 @@ #include #include "openvino/reference/autobroadcast_binop.hpp" -#include "openvino/reference/sum.hpp" +#include "openvino/reference/reduce_sum.hpp" namespace ov { namespace reference { @@ -38,7 +38,7 @@ void normalize_l2(const T* data, } std::vector sum_data(shape_size(reduce_shape)); - sum(sqr_data.data(), sum_data.data(), data_shape, reduction_axes); + reduce_sum(sqr_data.data(), sum_data.data(), data_shape, reduction_axes); autobroadcast_binop(data, sum_data.data(), out, diff --git a/src/core/reference/include/openvino/reference/product.hpp b/src/core/reference/include/openvino/reference/product.hpp deleted file mode 100644 index 41ce4cf3b1d841..00000000000000 --- a/src/core/reference/include/openvino/reference/product.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "ngraph/shape_util.hpp" -#include "openvino/reference/utils/coordinate_transform.hpp" - -namespace ov { -namespace reference { -template -void product(const T* arg, T* out, const Shape& in_shape, const AxisSet& reduction_axes) { - constexpr bool dont_keep_dims_in_output = false; - OPENVINO_SUPPRESS_DEPRECATED_START - const auto out_shape = ngraph::reduce(in_shape, reduction_axes, dont_keep_dims_in_output); - std::fill(out, out + shape_size(out_shape), T(1)); - - const auto in_strides = row_major_strides(in_shape); - const auto out_strides = row_major_strides(out_shape); - - CoordinateTransformBasic input_transform(in_shape); - for (const Coordinate& input_coord : input_transform) { - const Coordinate output_coord = ngraph::reduce(input_coord, reduction_axes, dont_keep_dims_in_output); - - const size_t in_idx = - std::inner_product(input_coord.begin(), input_coord.end(), in_strides.begin(), uint64_t(0)); - const size_t out_idx = - std::inner_product(output_coord.begin(), output_coord.end(), out_strides.begin(), uint64_t(0)); - - out[out_idx] = out[out_idx] * arg[in_idx]; - } - OPENVINO_SUPPRESS_DEPRECATED_END -} -} // namespace reference -} // namespace ov diff --git a/src/core/reference/include/openvino/reference/reduce_l1.hpp b/src/core/reference/include/openvino/reference/reduce_l1.hpp index 50228962f334cf..c729f97490890b 100644 --- a/src/core/reference/include/openvino/reference/reduce_l1.hpp +++ b/src/core/reference/include/openvino/reference/reduce_l1.hpp @@ -9,7 +9,7 @@ #include "openvino/core/shape_util.hpp" #include "openvino/reference/abs.hpp" -#include "openvino/reference/sum.hpp" +#include "openvino/reference/reduce_sum.hpp" #include "openvino/reference/utils/type_util.hpp" namespace ov { diff --git a/src/core/reference/include/openvino/reference/reduce_max.hpp b/src/core/reference/include/openvino/reference/reduce_max.hpp new file mode 100644 index 00000000000000..3d16d343de79e0 --- /dev/null +++ b/src/core/reference/include/openvino/reference/reduce_max.hpp @@ -0,0 +1,46 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "openvino/core/shape_util.hpp" +#include "openvino/reference/utils/coordinate_index.hpp" +#include "openvino/reference/utils/coordinate_transform.hpp" + +namespace ov { +namespace reference { + +/** + * @brief Reference implementation of ReduceMax operator. + * + * @param in Input pointer to data. + * @param out Output pointer to results. + * @param in_shape Input shape. + * @param reduction_axes Axes on which reduction is applied. + */ +template +void reduce_max(const T* in, T* out, const Shape& in_shape, const AxisSet& reduction_axes) { + constexpr auto min_value = std::numeric_limits::lowest(); + + const auto out_shape = util::reduce(in_shape, reduction_axes); + std::fill(out, std::next(out, shape_size(out_shape)), min_value); + + const auto in_strides = row_major_strides(in_shape); + const auto out_strides = row_major_strides(out_shape); + + CoordinateTransformBasic input_transform(in_shape); + for (const auto& in_coord : input_transform) { + const auto out_coord = util::reduce(in_coord, reduction_axes); + const auto in_idx = coordinate_offset(in_coord, in_strides); + const auto out_idx = coordinate_offset(out_coord, out_strides); + + out[out_idx] = std::max(out[out_idx], in[in_idx]); + } +} +} // namespace reference +} // namespace ov diff --git a/src/core/reference/include/openvino/reference/reduce_mean.hpp b/src/core/reference/include/openvino/reference/reduce_mean.hpp new file mode 100644 index 00000000000000..e7dfd1b9766404 --- /dev/null +++ b/src/core/reference/include/openvino/reference/reduce_mean.hpp @@ -0,0 +1,36 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "openvino/core/shape_util.hpp" +#include "openvino/reference/reduce_sum.hpp" + +namespace ov { +namespace reference { + +/** + * @brief Reference implementation of ReduceMean operator. + * + * @param in Input pointer to data. + * @param out Output pointer to results. + * @param in_shape Input shape. + * @param reduction_axes Axes on which reduction is applied. + */ +template +void reduce_mean(const T* in, T* out, const Shape& in_shape, const AxisSet& reduction_axes) { + reduce_sum(in, out, in_shape, reduction_axes); + + const auto out_shape = util::reduce(in_shape, reduction_axes); + const auto out_size = shape_size(out_shape); + const auto count = static_cast(shape_size(in_shape) / out_size); + std::transform(out, std::next(out, out_size), out, [count](const T value) { + return value / count; + }); +} +} // namespace reference +} // namespace ov diff --git a/src/core/reference/include/openvino/reference/reduce_min.hpp b/src/core/reference/include/openvino/reference/reduce_min.hpp new file mode 100644 index 00000000000000..1acc4c29a55f7c --- /dev/null +++ b/src/core/reference/include/openvino/reference/reduce_min.hpp @@ -0,0 +1,46 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "openvino/core/shape_util.hpp" +#include "openvino/reference/utils/coordinate_index.hpp" +#include "openvino/reference/utils/coordinate_transform.hpp" + +namespace ov { +namespace reference { +/** + * @brief Reference implementation of ReduceMin operator. + * + * @param in Input pointer to data. + * @param out Output pointer to results. + * @param in_shape Input shape. + * @param reduction_axes Axes on which reduction is applied. + */ +template +void reduce_min(const T* in, T* out, const Shape& in_shape, const AxisSet& reduction_axes) { + constexpr auto max_value = + std::numeric_limits::has_infinity ? std::numeric_limits::infinity() : std::numeric_limits::max(); + + const auto out_shape = util::reduce(in_shape, reduction_axes); + std::fill(out, out + shape_size(out_shape), max_value); + + const auto in_strides = row_major_strides(in_shape); + const auto out_strides = row_major_strides(out_shape); + + CoordinateTransformBasic input_transform(in_shape); + for (const auto& in_coord : input_transform) { + const auto out_coord = util::reduce(in_coord, reduction_axes); + const auto in_idx = coordinate_offset(in_coord, in_strides); + const auto out_idx = coordinate_offset(out_coord, out_strides); + + out[out_idx] = std::min(out[out_idx], in[in_idx]); + } +} +} // namespace reference +} // namespace ov diff --git a/src/core/reference/include/openvino/reference/reduce_prod.hpp b/src/core/reference/include/openvino/reference/reduce_prod.hpp new file mode 100644 index 00000000000000..32741036e8cf22 --- /dev/null +++ b/src/core/reference/include/openvino/reference/reduce_prod.hpp @@ -0,0 +1,42 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "openvino/core/shape_util.hpp" +#include "openvino/reference/utils/coordinate_index.hpp" +#include "openvino/reference/utils/coordinate_transform.hpp" + +namespace ov { +namespace reference { +/** + * @brief Reference implementation of ReduceProduct operator. + * + * @param in Input pointer to data. + * @param out Output pointer to results. + * @param in_shape Input shape. + * @param reduction_axes Axes on which reduction is applied. + */ +template +void reduce_prod(const T* arg, T* out, const Shape& in_shape, const AxisSet& reduction_axes) { + const auto out_shape = util::reduce(in_shape, reduction_axes); + std::fill(out, out + shape_size(out_shape), T(1)); + + const auto in_strides = row_major_strides(in_shape); + const auto out_strides = row_major_strides(out_shape); + + CoordinateTransformBasic input_transform(in_shape); + for (const auto& in_coord : input_transform) { + const auto out_coord = util::reduce(in_coord, reduction_axes); + const auto in_idx = coordinate_offset(in_coord, in_strides); + const auto out_idx = coordinate_offset(out_coord, out_strides); + + out[out_idx] *= arg[in_idx]; + } +} +} // namespace reference +} // namespace ov diff --git a/src/core/reference/include/openvino/reference/reduce_sum.hpp b/src/core/reference/include/openvino/reference/reduce_sum.hpp new file mode 100644 index 00000000000000..c7d9ecf98bf2af --- /dev/null +++ b/src/core/reference/include/openvino/reference/reduce_sum.hpp @@ -0,0 +1,94 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "openvino/core/shape_util.hpp" +#include "openvino/core/type/bfloat16.hpp" +#include "openvino/core/type/float16.hpp" +#include "openvino/reference/utils/coordinate_index.hpp" +#include "openvino/reference/utils/coordinate_transform.hpp" +#include "openvino/reference/utils/type_util.hpp" + +namespace ov { +namespace reference { +namespace details { + +template ::value, bool>::type = true> +bool isfinite(T x) { + return std::isfinite(x); +} + +template < + typename T, + typename std::enable_if::value || std::is_same::value, bool>::type = true> +bool isfinite(T x) { + return std::isfinite(static_cast(x)); +} + +/** + * @brief Performs one element summation based on Kahan algorithm to significantly reduce (integral types). + * + * @param in Value to add with previous value of summation. + * @param prev_sum Previous value of summation (accumulator). + * @return Compensate sum. + */ +template ::value>::type* = nullptr> +constexpr T kahan_summation(const T in, const T prev_sum, T&) { + return in + prev_sum; +} + +/** + * @brief Performs one element summation based on Kahan algorithm to significantly reduce (floating point types). + * + * @param in Value to add with previous value of summation. + * @param prev_sum Previous value of summation (accumulator). + * @param compensation Accumulates the summation error. + * @return Compensate sum. + */ +template ()>::type* = nullptr> +T kahan_summation(const T in, const T prev_sum, T& compensation) { + if (isfinite(in) && isfinite(prev_sum)) { + T temp = prev_sum + (in - compensation); + compensation = (temp - prev_sum) - (in - compensation); + return temp; + } else { + return in + prev_sum; + } +} +} // namespace details + +/** + * @brief Reference implementation of ReduceSum operator. + * + * @param in Input pointer to data. + * @param out Output pointer to results. + * @param in_shape Input shape. + * @param reduction_axes Axes on which reduction is applied. + */ +template +void reduce_sum(const T* in, T* out, const Shape& in_shape, const AxisSet& reduction_axes) { + const auto out_shape = util::reduce(in_shape, reduction_axes); + + const auto out_size = shape_size(out_shape); + std::vector cs(out_size, T{0}); + std::fill(out, std::next(out, out_size), T{0}); + + const auto in_strides = row_major_strides(in_shape); + const auto out_strides = row_major_strides(out_shape); + + CoordinateTransformBasic input_transform(in_shape); + for (const auto& in_coord : input_transform) { + const auto out_coord = util::reduce(in_coord, reduction_axes); + const auto in_idx = coordinate_offset(in_coord, in_strides); + const auto out_idx = coordinate_offset(out_coord, out_strides); + + out[out_idx] = details::kahan_summation(in[in_idx], out[out_idx], cs[out_idx]); + } +} +} // namespace reference +} // namespace ov diff --git a/src/core/reference/include/openvino/reference/softmax.hpp b/src/core/reference/include/openvino/reference/softmax.hpp index d4cbf5bbaff63f..69ea583fbc6a2a 100644 --- a/src/core/reference/include/openvino/reference/softmax.hpp +++ b/src/core/reference/include/openvino/reference/softmax.hpp @@ -7,8 +7,8 @@ #include #include "ngraph/shape_util.hpp" -#include "openvino/reference/max.hpp" -#include "openvino/reference/sum.hpp" +#include "openvino/reference/reduce_max.hpp" +#include "openvino/reference/reduce_sum.hpp" #include "openvino/reference/utils/coordinate_transform.hpp" namespace ov { @@ -20,7 +20,7 @@ void softmax(const T* arg, T* out, const Shape& shape, const AxisSet& axes) { auto temp_elements = shape_size(temp_shape); auto temp_ptr = new T[temp_elements]; - max(arg, temp_ptr, shape, axes); + reduce_max(arg, temp_ptr, shape, axes); CoordinateTransform transform(shape); CoordinateTransform temp_transform(temp_shape); @@ -30,7 +30,7 @@ void softmax(const T* arg, T* out, const Shape& shape, const AxisSet& axes) { std::exp(arg[transform.index(coord)] - temp_ptr[temp_transform.index(temp_coord)]); } - sum(out, temp_ptr, shape, axes); + reduce_sum(out, temp_ptr, shape, axes); for (const Coordinate& coord : transform) { Coordinate temp_coord = ngraph::reduce(coord, axes, true); diff --git a/src/core/reference/include/openvino/reference/sum.hpp b/src/core/reference/include/openvino/reference/sum.hpp deleted file mode 100644 index 3f811b3d566f43..00000000000000 --- a/src/core/reference/include/openvino/reference/sum.hpp +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "ngraph/shape_util.hpp" -#include "ngraph/type/bfloat16.hpp" -#include "ngraph/type/float16.hpp" -#include "openvino/reference/utils/coordinate_transform.hpp" - -namespace ov { -namespace reference { -namespace details { -// Windows doesn't seem to like it if we directly use std::isfinite on integer -// types, so we will roll our own thing here. -template ::value, bool>::type = true> -bool is_finite(T x) { - return std::isfinite(x); -} - -template < - typename T, - typename std::enable_if::value || std::is_same::value, bool>::type = true> -bool is_finite(T x) { - return std::isfinite(static_cast(x)); -} - -template ::value, bool>::type = true> -bool is_finite(T /* x */) { - return true; -} - -/// -/// \brief Performs one element summation based on Kahan algorithm to -/// significantly reduce -/// the numerical error. -/// -/// \param[in] elem Element to add into the accumulator. -/// \param compensation Variable that accumulates the error. -/// \param sum Result of compensated summation. -/// -template -void kahan_summation(const T& elem, T& compensation, T& sum) { - if (is_finite(elem) && is_finite(sum)) { - T temp = sum + (elem - compensation); - compensation = (temp - sum) - (elem - compensation); - sum = temp; - } else { - sum = sum + elem; - } -} -} // namespace details - -template -void sum(const T* arg, T* out, const Shape& in_shape, const AxisSet& reduction_axes) { - constexpr bool dont_keep_dims_in_output = false; - NGRAPH_SUPPRESS_DEPRECATED_START - const auto out_shape = ngraph::reduce(in_shape, reduction_axes, dont_keep_dims_in_output); - - std::vector cs(shape_size(out_shape), 0); - std::fill(out, out + shape_size(out_shape), T(0)); - - const auto in_strides = row_major_strides(in_shape); - const auto out_strides = row_major_strides(out_shape); - - CoordinateTransformBasic input_transform(in_shape); - for (const Coordinate& input_coord : input_transform) { - const Coordinate output_coord = ngraph::reduce(input_coord, reduction_axes, dont_keep_dims_in_output); - - const size_t in_idx = - std::inner_product(input_coord.begin(), input_coord.end(), in_strides.begin(), uint64_t(0)); - const size_t out_idx = - std::inner_product(output_coord.begin(), output_coord.end(), out_strides.begin(), uint64_t(0)); - - details::kahan_summation(arg[in_idx], cs[out_idx], out[out_idx]); - } - NGRAPH_SUPPRESS_DEPRECATED_END -} -} // namespace reference -} // namespace ov diff --git a/src/core/reference/src/op/einsum.cpp b/src/core/reference/src/op/einsum.cpp index 125e33e3aa6b49..a48dc998495286 100644 --- a/src/core/reference/src/op/einsum.cpp +++ b/src/core/reference/src/op/einsum.cpp @@ -10,8 +10,8 @@ #include "openvino/reference/broadcast.hpp" #include "openvino/reference/matmul.hpp" #include "openvino/reference/multiply.hpp" +#include "openvino/reference/reduce_sum.hpp" #include "openvino/reference/reshape.hpp" -#include "openvino/reference/sum.hpp" #include "openvino/reference/transpose.hpp" #include "openvino/reference/utils/span.hpp" @@ -352,7 +352,7 @@ void reduce_input(ov::TensorVector& inputs, auto output_ptr = ov::Tensor(input_ptr.get_element_type(), output_shape); - reference::sum(input_ptr.data(), output_ptr.data(), input_shape, reduced_axes); + reference::reduce_sum(input_ptr.data(), output_ptr.data(), input_shape, reduced_axes); // update a vector of inputs and input subscripts inputs[input_ind] = output_ptr; @@ -595,7 +595,7 @@ void extract_diagonal(ov::TensorVector& inputs, std::vector& input_ ov::op::AutoBroadcastType::NUMPY); auto result = ov::Tensor(input_ptr.get_element_type(), result_shape); - reference::sum(mul_output.data(), result.data(), mul_output.get_shape(), reduced_axes); + reference::reduce_sum(mul_output.data(), result.data(), mul_output.get_shape(), reduced_axes); inputs[input_ind] = result; input_subscripts[input_ind] = resultant_subscript; } diff --git a/src/core/shape_inference/include/utils.hpp b/src/core/shape_inference/include/utils.hpp index 7a1193f3a25a10..360c4eaa5f7b58 100644 --- a/src/core/shape_inference/include/utils.hpp +++ b/src/core/shape_inference/include/utils.hpp @@ -14,6 +14,7 @@ #include "ov_optional.hpp" #include "shape_infer_type_utils.hpp" #include "tensor_data_accessor.hpp" +#include "validation_util.hpp" namespace ov { @@ -277,10 +278,8 @@ std::unique_ptr get_input_const_data_as(const ov::Node* op, UnaryOperation&& func = ov::util::Cast()) { if (auto t = tensor_accessor(idx)) { return std::unique_ptr(new TRes(get_tensor_data_as(t, std::forward(func)))); - OPENVINO_SUPPRESS_DEPRECATED_START } else if (const auto& constant = - (idx < op->get_input_size()) ? ov::get_constant_from_source(op->input_value(idx)) : nullptr) { - OPENVINO_SUPPRESS_DEPRECATED_END + (idx < op->get_input_size()) ? ov::util::get_constant_from_source(op->input_value(idx)) : nullptr) { const auto& et = constant->get_element_type(); const auto& shape = constant->get_shape(); return std::unique_ptr(new TRes(get_raw_data_as(et, @@ -358,9 +357,7 @@ ov::optional get_input_const_data_as_shape(const ov::Node* op, inline element::Type get_input_const_element_type(const ov::Node* const op, size_t port, const ITensorAccessor& ta) { if (auto t = ta(port)) { return t.get_element_type(); - OPENVINO_SUPPRESS_DEPRECATED_START - } else if (const auto& constant = ov::get_constant_from_source(op->input_value(port))) { - OPENVINO_SUPPRESS_DEPRECATED_END + } else if (const auto& constant = ov::util::get_constant_from_source(op->input_value(port))) { return constant->get_element_type(); } else { return element::undefined; diff --git a/src/core/src/op/reduce_l1.cpp b/src/core/src/op/reduce_l1.cpp index 5670ae4609890b..75f8a000580bc3 100644 --- a/src/core/src/op/reduce_l1.cpp +++ b/src/core/src/op/reduce_l1.cpp @@ -21,7 +21,7 @@ struct Evaluate : element::NoAction { template static result_type visit(const Tensor& in0, Tensor& out, const AxisSet& reduction_axes) { using T = fundamental_type_for; - reference::reduce_l1(in0.data(), out.data(), in0.get_shape(), reduction_axes); + reference::reduce_l1(in0.data(), out.data(), in0.get_shape(), reduction_axes); return true; } }; @@ -48,7 +48,7 @@ bool ReduceL1::evaluate(TensorVector& outputs, const TensorVector& inputs) const outputs[0].set_shape(ov::util::reduce(inputs[0].get_shape(), reduction_axes, get_keep_dims())); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), + return IfTypeOf::apply(inputs[0].get_element_type(), inputs[0], outputs[0], reduction_axes); diff --git a/src/core/src/op/reduce_l2.cpp b/src/core/src/op/reduce_l2.cpp index 1e7669ce625f48..5477a56986be16 100644 --- a/src/core/src/op/reduce_l2.cpp +++ b/src/core/src/op/reduce_l2.cpp @@ -20,7 +20,7 @@ struct Evaluate : element::NoAction { template static result_type visit(const Tensor& in0, Tensor& out, const AxisSet& reduction_axes) { using T = fundamental_type_for; - reference::reduce_l2(in0.data(), out.data(), in0.get_shape(), reduction_axes); + reference::reduce_l2(in0.data(), out.data(), in0.get_shape(), reduction_axes); return true; } }; diff --git a/src/core/src/op/reduce_max.cpp b/src/core/src/op/reduce_max.cpp index 35f2216bac8bfc..989f0a771f2b1c 100644 --- a/src/core/src/op/reduce_max.cpp +++ b/src/core/src/op/reduce_max.cpp @@ -2,98 +2,81 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include "openvino/op/reduce_max.hpp" #include "bound_evaluate.hpp" +#include "element_visitor.hpp" #include "itt.hpp" -#include "ngraph/graph_util.hpp" -#include "ngraph/op/max.hpp" -#include "ngraph/op/util/evaluate_helpers.hpp" -#include "ngraph/runtime/host_tensor.hpp" -#include "ngraph/shape_util.hpp" -#include "openvino/reference/max.hpp" +#include "openvino/core/shape_util.hpp" +#include "openvino/op/util/axes_util.hpp" +#include "openvino/reference/reduce_max.hpp" -using namespace std; -using namespace ngraph; +namespace ov { +namespace op { +namespace reduce_max { +struct Evaluate : element::NoAction { + using element::NoAction::visit; -OPENVINO_SUPPRESS_DEPRECATED_START -namespace maxop { -namespace { -template -bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out, const AxisSet& axes, bool keep_dims) { - OPENVINO_SUPPRESS_DEPRECATED_START - out->set_shape(reduce(arg->get_shape(), axes, keep_dims)); - OPENVINO_SUPPRESS_DEPRECATED_END - ov::reference::max(arg->get_data_ptr(), out->get_data_ptr(), arg->get_shape(), axes); - return true; -} - -bool evaluate_max(const HostTensorPtr& arg, const HostTensorPtr& out, const AxisSet& axes, bool keep_dims) { - bool rc = true; - switch (arg->get_element_type()) { - NGRAPH_TYPE_CASE(evaluate_max, i32, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_max, i64, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_max, u32, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_max, u64, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_max, f16, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_max, f32, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_max, u8, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_max, i8, arg, out, axes, keep_dims); - default: - rc = false; - break; + template + static result_type visit(const Tensor& in0, Tensor& out, const AxisSet& reduction_axes) { + using T = fundamental_type_for; + reference::reduce_max(in0.data(), out.data(), in0.get_shape(), reduction_axes); + return true; } - return rc; -} -} // namespace -} // namespace maxop +}; +} // namespace reduce_max +namespace v1 { -op::v1::ReduceMax::ReduceMax(const Output& arg, const Output& reduction_axes, bool keep_dims) +ReduceMax::ReduceMax(const Output& arg, const Output& reduction_axes, bool keep_dims) : ArithmeticReductionKeepDims(arg, reduction_axes, keep_dims) { constructor_validate_and_infer_types(); } -shared_ptr op::v1::ReduceMax::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr ReduceMax::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_ReduceMax_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), get_keep_dims()); + return std::make_shared(new_args.at(0), new_args.at(1), get_keep_dims()); } -bool op::v1::ReduceMax::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { +bool ReduceMax::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v1_ReduceMax_evaluate); - OPENVINO_SUPPRESS_DEPRECATED_START - OPENVINO_ASSERT(validate_host_tensor_vector(inputs, 2)); - OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(outputs.size() == 1); + OPENVINO_ASSERT(inputs.size() == 2); - const auto reduction_axes = - get_normalized_axes_from_tensor(inputs[1], inputs[0]->get_partial_shape().rank(), get_friendly_name()); - OPENVINO_SUPPRESS_DEPRECATED_END + const auto reduction_axes = get_normalized_axes_from_tensor(this, inputs[1], inputs[0].get_shape().size()); + outputs[0].set_shape(ov::util::reduce(inputs[0].get_shape(), reduction_axes, get_keep_dims())); - return maxop::evaluate_max(inputs[0], outputs[0], reduction_axes, get_keep_dims()); + using namespace ov::element; + return IfTypeOf::apply(inputs[0].get_element_type(), + inputs[0], + outputs[0], + reduction_axes); } -bool op::v1::ReduceMax::has_evaluate() const { +bool ReduceMax::has_evaluate() const { OV_OP_SCOPE(v1_ReduceMax_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 ngraph::element::i8: - case ngraph::element::u8: + case element::i32: + case element::i64: + case element::u32: + case element::u64: + case element::f16: + case element::f32: + case element::i8: + case element::u8: return true; default: - break; + return false; } - return false; } -bool op::v1::ReduceMax::evaluate_lower(ov::TensorVector& output_values) const { +bool ReduceMax::evaluate_lower(ov::TensorVector& output_values) const { return input_value(1).get_tensor().has_and_set_bound() && default_lower_bound_evaluator(this, output_values); } -bool op::v1::ReduceMax::evaluate_upper(ov::TensorVector& output_values) const { +bool ReduceMax::evaluate_upper(ov::TensorVector& output_values) const { return input_value(1).get_tensor().has_and_set_bound() && default_upper_bound_evaluator(this, output_values); } +} // namespace v1 +} // namespace op +} // namespace ov diff --git a/src/core/src/op/reduce_mean.cpp b/src/core/src/op/reduce_mean.cpp index bc425fa0c2095c..762bc1c09719ee 100644 --- a/src/core/src/op/reduce_mean.cpp +++ b/src/core/src/op/reduce_mean.cpp @@ -2,87 +2,69 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/reduce_mean.hpp" - -#include +#include "openvino/op/reduce_mean.hpp" +#include "element_visitor.hpp" #include "itt.hpp" -#include "ngraph/graph_util.hpp" -#include "ngraph/op/broadcast.hpp" -#include "ngraph/op/util/evaluate_helpers.hpp" -#include "ngraph/runtime/host_tensor.hpp" -#include "ngraph/shape_util.hpp" -#include "openvino/reference/mean.hpp" +#include "openvino/core/shape_util.hpp" +#include "openvino/op/util/axes_util.hpp" +#include "openvino/reference/reduce_mean.hpp" -using namespace std; -using namespace ngraph; +namespace ov { +namespace op { +namespace reduce_mean { +struct Evaluate : element::NoAction { + using element::NoAction::visit; -op::v1::ReduceMean::ReduceMean(const Output& arg, const Output& reduction_axes, bool keep_dims) + template + static result_type visit(const Tensor& in0, Tensor& out, const AxisSet& reduction_axes) { + using T = fundamental_type_for; + reference::reduce_mean(in0.data(), out.data(), in0.get_shape(), reduction_axes); + return true; + } +}; +} // namespace reduce_mean +namespace v1 { +ReduceMean::ReduceMean(const Output& arg, const Output& reduction_axes, bool keep_dims) : ArithmeticReductionKeepDims(arg, reduction_axes, keep_dims) { constructor_validate_and_infer_types(); } -shared_ptr op::v1::ReduceMean::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr ReduceMean::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_ReduceMean_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), get_keep_dims()); -} - -OPENVINO_SUPPRESS_DEPRECATED_START -namespace mean { -namespace { -template -bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out, const AxisSet& axes, bool keep_dims) { - OPENVINO_SUPPRESS_DEPRECATED_START - out->set_shape(reduce(arg->get_shape(), axes, keep_dims)); - OPENVINO_SUPPRESS_DEPRECATED_END - ov::reference::mean(arg->get_data_ptr(), out->get_data_ptr(), arg->get_shape(), axes); - return true; -} - -bool evaluate_mean(const HostTensorPtr& arg, const HostTensorPtr& out, const AxisSet& axes, bool keep_dims) { - bool rc = true; - switch (arg->get_element_type()) { - NGRAPH_TYPE_CASE(evaluate_mean, i32, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_mean, i64, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_mean, u32, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_mean, u64, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_mean, f16, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_mean, f32, arg, out, axes, keep_dims); - default: - rc = false; - break; - } - return rc; + return std::make_shared(new_args.at(0), new_args.at(1), get_keep_dims()); } -} // namespace -} // namespace mean -bool op::v1::ReduceMean::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { +bool ReduceMean::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v1_ReduceMean_evaluate); - OPENVINO_SUPPRESS_DEPRECATED_START - OPENVINO_ASSERT(validate_host_tensor_vector(inputs, 2)); - OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(outputs.size() == 1); + OPENVINO_ASSERT(inputs.size() == 2); - const auto reduction_axes = - get_normalized_axes_from_tensor(inputs[1], inputs[0]->get_partial_shape().rank(), get_friendly_name()); - OPENVINO_SUPPRESS_DEPRECATED_END + const auto reduction_axes = get_normalized_axes_from_tensor(this, inputs[1], inputs[0].get_shape().size()); + outputs[0].set_shape(ov::util::reduce(inputs[0].get_shape(), reduction_axes, get_keep_dims())); - return mean::evaluate_mean(inputs[0], outputs[0], reduction_axes, get_keep_dims()); + using namespace ov::element; + return IfTypeOf::apply(inputs[0].get_element_type(), + inputs[0], + outputs[0], + reduction_axes); } -bool op::v1::ReduceMean::has_evaluate() const { +bool ReduceMean::has_evaluate() const { OV_OP_SCOPE(v1_ReduceMean_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::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/reduce_min.cpp b/src/core/src/op/reduce_min.cpp index 7f6e927748bb56..3334b02d5fa3ea 100644 --- a/src/core/src/op/reduce_min.cpp +++ b/src/core/src/op/reduce_min.cpp @@ -2,97 +2,79 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include "openvino/op/reduce_min.hpp" #include "bound_evaluate.hpp" +#include "element_visitor.hpp" #include "itt.hpp" -#include "ngraph/op/min.hpp" -#include "ngraph/op/util/evaluate_helpers.hpp" -#include "ngraph/runtime/host_tensor.hpp" -#include "ngraph/shape_util.hpp" -#include "openvino/reference/min.hpp" +#include "openvino/op/util/axes_util.hpp" +#include "openvino/reference/reduce_min.hpp" -using namespace std; -using namespace ngraph; +namespace ov { +namespace op { +namespace reduce_min { +struct Evaluate : element::NoAction { + using element::NoAction::visit; -OPENVINO_SUPPRESS_DEPRECATED_START -namespace minop { -namespace { -template -bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out, const AxisSet& axes, const bool keep_dims) { - OPENVINO_SUPPRESS_DEPRECATED_START - out->set_shape(reduce(arg->get_shape(), axes, keep_dims)); - OPENVINO_SUPPRESS_DEPRECATED_END - ov::reference::min(arg->get_data_ptr(), out->get_data_ptr(), arg->get_shape(), axes); - return true; -} - -bool evaluate_min(const HostTensorPtr& arg, const HostTensorPtr& out, const AxisSet& axes, const bool keep_dims) { - bool rc = true; - switch (arg->get_element_type()) { - NGRAPH_TYPE_CASE(evaluate_min, i32, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_min, i64, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_min, u32, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_min, u64, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_min, f16, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_min, f32, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_min, i8, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_min, u8, arg, out, axes, keep_dims); - default: - rc = false; - break; + template + static result_type visit(const Tensor& in0, Tensor& out, const AxisSet& reduction_axes) { + using T = fundamental_type_for; + reference::reduce_min(in0.data(), out.data(), in0.get_shape(), reduction_axes); + return true; } - return rc; -} -} // namespace -} // namespace minop - -op::v1::ReduceMin::ReduceMin(const Output& arg, const Output& reduction_axes, bool keep_dims) +}; +} // namespace reduce_min +namespace v1 { +ReduceMin::ReduceMin(const Output& arg, const Output& reduction_axes, bool keep_dims) : ArithmeticReductionKeepDims(arg, reduction_axes, keep_dims) { constructor_validate_and_infer_types(); } -shared_ptr op::v1::ReduceMin::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr ReduceMin::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_ReduceMin_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), get_keep_dims()); + return std::make_shared(new_args.at(0), new_args.at(1), get_keep_dims()); } -bool op::v1::ReduceMin::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { +bool ReduceMin::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v1_ReduceMin_evaluate); - OPENVINO_SUPPRESS_DEPRECATED_START - OPENVINO_ASSERT(validate_host_tensor_vector(inputs, 2)); - OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(outputs.size() == 1); + OPENVINO_ASSERT(inputs.size() == 2); - const auto reduction_axes = - get_normalized_axes_from_tensor(inputs[1], inputs[0]->get_partial_shape().rank(), get_friendly_name()); - OPENVINO_SUPPRESS_DEPRECATED_END + const auto reduction_axes = get_normalized_axes_from_tensor(this, inputs[1], inputs[0].get_shape().size()); + outputs[0].set_shape(ov::util::reduce(inputs[0].get_shape(), reduction_axes, get_keep_dims())); - return minop::evaluate_min(inputs[0], outputs[0], reduction_axes, get_keep_dims()); + using namespace ov::element; + return IfTypeOf::apply(inputs[0].get_element_type(), + inputs[0], + outputs[0], + reduction_axes); } -bool op::v1::ReduceMin::has_evaluate() const { +bool ReduceMin::has_evaluate() const { OV_OP_SCOPE(v1_ReduceMin_has_evaluate); switch (get_input_element_type(0)) { - case ngraph::element::i8: - case ngraph::element::u8: - 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::i8: + case element::u8: + 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; } -bool op::v1::ReduceMin::evaluate_lower(ov::TensorVector& output_values) const { +bool ReduceMin::evaluate_lower(ov::TensorVector& output_values) const { return input_value(1).get_tensor().has_and_set_bound() && default_lower_bound_evaluator(this, output_values); } -bool op::v1::ReduceMin::evaluate_upper(ov::TensorVector& output_values) const { +bool ReduceMin::evaluate_upper(ov::TensorVector& output_values) const { return input_value(1).get_tensor().has_and_set_bound() && default_upper_bound_evaluator(this, output_values); } +} // namespace v1 +} // namespace op +} // namespace ov diff --git a/src/core/src/op/reduce_prod.cpp b/src/core/src/op/reduce_prod.cpp index dd915427b2415d..9d345ae63cf301 100644 --- a/src/core/src/op/reduce_prod.cpp +++ b/src/core/src/op/reduce_prod.cpp @@ -2,105 +2,90 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/reduce_prod.hpp" +#include "openvino/op/reduce_prod.hpp" #include "bound_evaluate.hpp" +#include "element_visitor.hpp" #include "itt.hpp" -#include "ngraph/graph_util.hpp" -#include "ngraph/op/util/evaluate_helpers.hpp" -#include "ngraph/runtime/host_tensor.hpp" -#include "ngraph/shape_util.hpp" -#include "openvino/reference/product.hpp" +#include "openvino/core/shape_util.hpp" +#include "openvino/op/util/axes_util.hpp" +#include "openvino/reference/reduce_prod.hpp" -using namespace std; -using namespace ngraph; +namespace ov { +namespace op { +namespace reduce_prod { +namespace { +bool has_positive_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); +} +} // namespace + +struct Evaluate : element::NoAction { + using element::NoAction::visit; + + template + static result_type visit(const Tensor& in0, Tensor& out, const AxisSet& reduction_axes) { + using T = fundamental_type_for; + reference::reduce_prod(in0.data(), out.data(), in0.get_shape(), reduction_axes); + return true; + } +}; +} // namespace reduce_prod +namespace v1 { -op::v1::ReduceProd::ReduceProd(const Output& arg, const Output& reduction_axes, bool keep_dims) +ReduceProd::ReduceProd(const Output& arg, const Output& reduction_axes, bool keep_dims) : ArithmeticReductionKeepDims(arg, reduction_axes, keep_dims) { constructor_validate_and_infer_types(); } -shared_ptr op::v1::ReduceProd::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr ReduceProd::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_ReduceProd_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), get_keep_dims()); -} - -OPENVINO_SUPPRESS_DEPRECATED_START -namespace reduce_prod { -namespace { -template -bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out, const AxisSet& axes, bool keep_dims) { - OPENVINO_SUPPRESS_DEPRECATED_START - out->set_shape(reduce(arg->get_shape(), axes, keep_dims)); - OPENVINO_SUPPRESS_DEPRECATED_END - ov::reference::product(arg->get_data_ptr(), out->get_data_ptr(), arg->get_shape(), axes); - return true; + return std::make_shared(new_args.at(0), new_args.at(1), get_keep_dims()); } -bool evaluate_product(const HostTensorPtr& arg, const HostTensorPtr& out, const AxisSet& axes, bool keep_dims) { - bool rc = true; - switch (arg->get_element_type()) { - NGRAPH_TYPE_CASE(evaluate_product, i32, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_product, i64, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_product, u32, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_product, u64, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_product, f16, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_product, f32, arg, out, axes, keep_dims); - default: - rc = false; - break; - } - return rc; -} // namespace -} // namespace -} // namespace reduce_prod - -bool op::v1::ReduceProd::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { +bool ReduceProd::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v1_ReduceProd_evaluate); - OPENVINO_SUPPRESS_DEPRECATED_START - OPENVINO_ASSERT(validate_host_tensor_vector(inputs, 2)); - OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(outputs.size() == 1); + OPENVINO_ASSERT(inputs.size() == 2); - const auto reduction_axes = - get_normalized_axes_from_tensor(inputs[1], inputs[0]->get_partial_shape().rank(), get_friendly_name()); - OPENVINO_SUPPRESS_DEPRECATED_END + const auto reduction_axes = get_normalized_axes_from_tensor(this, inputs[1], inputs[0].get_shape().size()); + outputs[0].set_shape(ov::util::reduce(inputs[0].get_shape(), reduction_axes, get_keep_dims())); - return reduce_prod::evaluate_product(inputs[0], outputs[0], reduction_axes, get_keep_dims()); + using namespace ov::element; + return IfTypeOf::apply(inputs[0].get_element_type(), + inputs[0], + outputs[0], + reduction_axes); } -bool op::v1::ReduceProd::has_evaluate() const { +bool ReduceProd::has_evaluate() const { OV_OP_SCOPE(v1_ReduceProd_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; } -bool op::v1::ReduceProd::evaluate_lower(ov::TensorVector& output_values) const { - if (!input_value(1).get_tensor().has_and_set_bound()) - return false; - - const auto &lb = input_value(0).get_tensor().get_lower_value(), ub = input_value(0).get_tensor().get_upper_value(); - if (!lb || !ub || !tensor_is_positive(lb) || !tensor_is_positive(ub)) - return false; - return default_lower_bound_evaluator(this, output_values); +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() && + default_lower_bound_evaluator(this, output_values); } -bool op::v1::ReduceProd::evaluate_upper(ov::TensorVector& output_values) const { - if (!input_value(1).get_tensor().has_and_set_bound()) - return false; - - const auto &lb = input_value(0).get_tensor().get_lower_value(), ub = input_value(0).get_tensor().get_upper_value(); - if (!lb || !ub || !tensor_is_positive(lb) || !tensor_is_positive(ub)) - return false; - return default_upper_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); } +} // namespace v1 +} // namespace op +} // namespace ov diff --git a/src/core/src/op/reduce_sum.cpp b/src/core/src/op/reduce_sum.cpp index 54797693251ae1..33e7ced8204faf 100644 --- a/src/core/src/op/reduce_sum.cpp +++ b/src/core/src/op/reduce_sum.cpp @@ -2,88 +2,69 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/reduce_sum.hpp" - -#include +#include "openvino/op/reduce_sum.hpp" +#include "element_visitor.hpp" #include "itt.hpp" -#include "ngraph/graph_util.hpp" -#include "ngraph/op/broadcast.hpp" -#include "ngraph/op/util/evaluate_helpers.hpp" -#include "ngraph/op/util/op_types.hpp" -#include "ngraph/runtime/host_tensor.hpp" -#include "ngraph/shape_util.hpp" -#include "openvino/reference/sum.hpp" +#include "openvino/core/shape_util.hpp" +#include "openvino/op/util/axes_util.hpp" +#include "openvino/reference/reduce_sum.hpp" -using namespace std; -using namespace ngraph; +namespace ov { +namespace op { +namespace reduce_sum { +struct Evaluate : element::NoAction { + using element::NoAction::visit; -op::v1::ReduceSum::ReduceSum(const Output& arg, const Output& reduction_axes, bool keep_dims) + template + static result_type visit(const Tensor& in0, Tensor& out, const AxisSet& reduction_axes) { + using T = fundamental_type_for; + reference::reduce_sum(in0.data(), out.data(), in0.get_shape(), reduction_axes); + return true; + } +}; +} // namespace reduce_sum +namespace v1 { +ReduceSum::ReduceSum(const Output& arg, const Output& reduction_axes, bool keep_dims) : ArithmeticReductionKeepDims(arg, reduction_axes, keep_dims) { constructor_validate_and_infer_types(); } -shared_ptr op::v1::ReduceSum::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr ReduceSum::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_ReduceSum_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), get_keep_dims()); -} - -OPENVINO_SUPPRESS_DEPRECATED_START -namespace reduce_sum { -namespace { -template -bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out, const AxisSet& axes, bool keep_dims) { - OPENVINO_SUPPRESS_DEPRECATED_START - out->set_shape(reduce(arg->get_shape(), axes, keep_dims)); - OPENVINO_SUPPRESS_DEPRECATED_END - ov::reference::sum(arg->get_data_ptr(), out->get_data_ptr(), arg->get_shape(), axes); - return true; + return std::make_shared(new_args.at(0), new_args.at(1), get_keep_dims()); } -bool evaluate_sum(const HostTensorPtr& arg, const HostTensorPtr& out, const AxisSet& axes, bool keep_dims) { - bool rc = true; - switch (arg->get_element_type()) { - NGRAPH_TYPE_CASE(evaluate_reduce_sum, i32, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_reduce_sum, i64, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_reduce_sum, u32, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_reduce_sum, u64, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_reduce_sum, f16, arg, out, axes, keep_dims); - NGRAPH_TYPE_CASE(evaluate_reduce_sum, f32, arg, out, axes, keep_dims); - default: - rc = false; - break; - } - return rc; -} // namespace -} // namespace -} // namespace reduce_sum - -bool op::v1::ReduceSum::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { +bool ReduceSum::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v1_ReduceSum_evaluate); - OPENVINO_SUPPRESS_DEPRECATED_START - OPENVINO_ASSERT(validate_host_tensor_vector(inputs, 2)); - OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(outputs.size() == 1); + OPENVINO_ASSERT(inputs.size() == 2); - const auto reduction_axes = - get_normalized_axes_from_tensor(inputs[1], inputs[0]->get_partial_shape().rank(), get_friendly_name()); - OPENVINO_SUPPRESS_DEPRECATED_END + const auto reduction_axes = get_normalized_axes_from_tensor(this, inputs[1], inputs[0].get_shape().size()); + outputs[0].set_shape(ov::util::reduce(inputs[0].get_shape(), reduction_axes, get_keep_dims())); - return reduce_sum::evaluate_sum(inputs[0], outputs[0], reduction_axes, get_keep_dims()); + using namespace ov::element; + return IfTypeOf::apply(inputs[0].get_element_type(), + inputs[0], + outputs[0], + reduction_axes); } -bool op::v1::ReduceSum::has_evaluate() const { +bool ReduceSum::has_evaluate() const { OV_OP_SCOPE(v1_ReduceSum_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 diff --git a/src/core/src/op/util/axes_util.cpp b/src/core/src/op/util/axes_util.cpp index d5921edf6f580f..1736025527f71e 100644 --- a/src/core/src/op/util/axes_util.cpp +++ b/src/core/src/op/util/axes_util.cpp @@ -11,7 +11,7 @@ namespace ov { namespace op { namespace util { AxisSet get_normalized_axes_from_tensor(const Node* const node, const Tensor& tensor, const Rank& rank) { - const auto axes = ov::get_tensor_data_as(tensor, ov::util::Cast()); + const auto axes = ov::get_tensor_data_as(tensor); OPENVINO_SUPPRESS_DEPRECATED_START return {normalize_axes(node->get_friendly_name(), axes, rank)}; diff --git a/src/core/src/op/util/reduction_base.cpp b/src/core/src/op/util/reduction_base.cpp index dbe7cb4b5228b9..30d56715c248e3 100644 --- a/src/core/src/op/util/reduction_base.cpp +++ b/src/core/src/op/util/reduction_base.cpp @@ -6,6 +6,7 @@ #include "openvino/op/constant.hpp" #include "reduce_shape_inference.hpp" +#include "validation_util.hpp" ov::op::util::ReductionBase::ReductionBase() = default; @@ -24,18 +25,16 @@ bool ov::op::util::ReductionBase::reduction_axes_constant() const { } const ov::AxisSet ov::op::util::ReductionBase::get_reduction_axes() const { - AxisSet axes; - OPENVINO_SUPPRESS_DEPRECATED_START - if (const auto& const_op = get_constant_from_source(input_value(1))) { - OPENVINO_SUPPRESS_DEPRECATED_END + if (const auto& const_op = ov::util::get_constant_from_source(input_value(1))) { const auto const_data = const_op->cast_vector(); const auto input_data_rank = get_input_partial_shape(0).rank(); OPENVINO_SUPPRESS_DEPRECATED_START const auto normalized_axes = ov::normalize_axes(get_friendly_name(), const_data, input_data_rank); OPENVINO_SUPPRESS_DEPRECATED_END - axes = AxisSet{normalized_axes}; + return {normalized_axes}; + } else { + return {}; } - return axes; } void ov::op::util::ReductionBase::set_reduction_axes(const AxisSet& reduction_axes) { diff --git a/src/core/src/validation_util.cpp b/src/core/src/validation_util.cpp index d44e6b0bf5b718..b1f03d198f1152 100644 --- a/src/core/src/validation_util.cpp +++ b/src/core/src/validation_util.cpp @@ -1295,13 +1295,7 @@ std::shared_ptr ngraph::get_constant_lowest_of_type(el } shared_ptr ov::get_constant_from_source(const Output& source) { - if (!has_and_set_equal_bounds(source)) - return nullptr; - if (const auto& c = ov::as_type_ptr(source.get_node_shared_ptr())) - return c; - - const auto t = source.get_tensor().get_upper_value(); - return std::make_shared(t.get_element_type(), t.get_shape(), t.data()); + return ov::util::get_constant_from_source(source); } bool ngraph::validate_host_tensor_vector(const HostTensorVector& tensor_vector, const size_t& size) { @@ -1370,3 +1364,19 @@ std::shared_ptr ov::util::constantfold_subgraph(const Outp return nullptr; return ov::as_type_ptr(outputs[subgraph_sink.get_index()].get_node_shared_ptr()); } + +namespace ov { +namespace util { +using ov::op::v0::Constant; + +std::shared_ptr get_constant_from_source(const Output& source) { + if (const auto& c = ov::as_type_ptr(source.get_node_shared_ptr())) { + return c; + } else if (has_and_set_equal_bounds(source)) { + return std::make_shared(source.get_tensor().get_upper_value()); + } else { + return {}; + } +} +} // namespace util +} // namespace ov From 23e602f06f3a46339b9b7e1393fe740d15ab1d84 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Thu, 28 Sep 2023 15:01:52 +0400 Subject: [PATCH 15/35] Fixed NCC style check (#20121) --- .github/workflows/code_style.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code_style.yml b/.github/workflows/code_style.yml index 96c75ce55aef43..0500ba86b12412 100644 --- a/.github/workflows/code_style.yml +++ b/.github/workflows/code_style.yml @@ -85,7 +85,7 @@ jobs: - name: Install Clang dependency run: | sudo apt update - sudo apt --assume-yes remove clang-7 clang-8 clang-9 clang-10 clang-11 clang-12 clang-13 + sudo apt --assume-yes remove clang-7 clang-8 clang-9 clang-10 clang-11 clang-12 clang-13 clang-15 sudo apt --assume-yes install clang-14 libclang-14-dev - name: Install Python-based dependencies From c5320bf7f075a3b5040a89c9203bb6ae46f2f962 Mon Sep 17 00:00:00 2001 From: Chenhu Wang Date: Thu, 28 Sep 2023 19:36:12 +0800 Subject: [PATCH 16/35] [CPU] DetectionOutput perf fix (#19773) --- .../intel_cpu/src/nodes/detection_output.cpp | 257 +++++++++--------- .../intel_cpu/src/nodes/detection_output.h | 5 +- .../single_layer_tests/detection_output.cpp | 88 +++++- 3 files changed, 215 insertions(+), 135 deletions(-) diff --git a/src/plugins/intel_cpu/src/nodes/detection_output.cpp b/src/plugins/intel_cpu/src/nodes/detection_output.cpp index e6f5e77b83a958..992f7e4d9a4e16 100644 --- a/src/plugins/intel_cpu/src/nodes/detection_output.cpp +++ b/src/plugins/intel_cpu/src/nodes/detection_output.cpp @@ -84,6 +84,7 @@ DetectionOutput::DetectionOutput(const std::shared_ptr& op, const imgWidth = attributes.input_width; priorSize = normalized ? 4 : 5; coordOffset = normalized ? 0 : 1; + cacheSizeL3 = utils::get_cache_size(3, true); withAddBoxPred = getOriginalInputsNumber() == 5; objScore = attributes.objectness_score; @@ -123,14 +124,13 @@ void DetectionOutput::prepareParams() { confInfoForPrior.resize(imgNum * priorsNum); // confs...count...indices for caffe style and sparsity case. - // caffe: conf_info for sparsity or indices for dense --> topk(buffer) --> nms(indices) + // caffe: filter(conf_info for sparsity or indices for dense) --> topk(buffer) --> nms(indices) // --> g_topk(vector<>(all detections) --> indices per class)) // MXNet: max conf for prior within img, filter(indices) --> topk_img(buffer) --> nms_cls(indices) // --> g_topk(vector<>(all detections) --> indices per class)) - unsigned cacheSizeL3 = utils::get_cache_size(3, true); isSparsityWorthwhile = (confidenceThreshold > sparsityThreshold) && - ((classesNum * priorsNum * sizeof(float) * 2) > cacheSizeL3); + ((classesNum * priorsNum * sizeof(float) * 2) > static_cast(cacheSizeL3)); confInfoLen = (!decreaseClassId && isSparsityWorthwhile) ? (2 * priorsNum + 1) : priorsNum; reorderedConf.resize(imgNum * classesNum * confInfoLen); @@ -202,12 +202,6 @@ void DetectionOutput::execute(dnnl::stream strm) { if (!isSparsityWorthwhile) { confReorderDense(confData, ARMConfData, reorderedConfData); - - if (!decreaseClassId) { - confFilterCF(reorderedConfData, indicesData, indicesBufData, detectionsData); - } else { - confFilterMX(confData, ARMConfData, reorderedConfData, indicesData, indicesBufData, detectionsData); - } } else { // sparsity if (!decreaseClassId) { confReorderAndFilterSparsityCF(confData, ARMConfData, reorderedConfData, indicesData, indicesBufData, detectionsData); @@ -270,10 +264,15 @@ void DetectionOutput::execute(dnnl::stream strm) { // Caffe style parallel_for(classesNum, [&](int c) { if (c != backgroundClassId) { // Ignore background class - int *pindices = indicesData + n * classesNum * priorsNum + c * priorsNum; - int *pbuffer = indicesBufData + n * classesNum * priorsNum + c * priorsNum; + const int off = n * priorsNum * classesNum + c * priorsNum; + const float *pconfReorder = reorderedConfData + off; + int *pindices = indicesData + off; + int *pbuffer = indicesBufData + off; int *pdetections = detectionsData + n * classesNum + c; + if (!isSparsityWorthwhile) + confFilterCF(pconfReorder, pindices, pbuffer, pdetections, n); + const float *pboxes; const float *psizes; if (isShareLoc) { @@ -289,9 +288,16 @@ void DetectionOutput::execute(dnnl::stream strm) { }); } else { // MXNet style - int *pbuffer = indicesBufData + n * classesNum * priorsNum; + const int offImg = n * priorsNum * classesNum; + const float *pconf = confData + offImg; + float *pconfReorder = reorderedConfData + offImg; + int *pbuffer = indicesBufData + offImg; + int *pindices = indicesData + offImg; int *pdetections = detectionsData + n * classesNum; - int *pindices = indicesData + n * classesNum * priorsNum; + + if (!isSparsityWorthwhile) + confFilterMX(pconf, ARMConfData, pconfReorder, pindices, pbuffer, pdetections, n); + const float *pboxes = decodedBboxesData + n * 4 * locNumForClasses * priorsNum; const float *psizes = bboxSizesData + n * locNumForClasses * priorsNum; @@ -309,7 +315,7 @@ void DetectionOutput::execute(dnnl::stream strm) { std::mutex mtx; parallel_for(classesNum, [&](int c) { - int detections = detectionsData[n * classesNum + c]; + const int detections = detectionsData[n * classesNum + c]; int *pindices = indicesData + n * classesNum * priorsNum + c * priorsNum; float *pconf = reorderedConfData + n * classesNum * confInfoLen + c * confInfoLen; @@ -330,8 +336,8 @@ void DetectionOutput::execute(dnnl::stream strm) { memset(detectionsData + n * classesNum, 0, classesNum * sizeof(int)); for (size_t j = 0; j < confIndicesClassMap.size(); ++j) { - int cls = confIndicesClassMap[j].second.first; - int pr = confIndicesClassMap[j].second.second; + const int cls = confIndicesClassMap[j].second.first; + const int pr = confIndicesClassMap[j].second.second; int *pindices = indicesData + n * classesNum * priorsNum + cls * priorsNum; pindices[detectionsData[n * classesNum + cls]] = pr; detectionsData[n * classesNum + cls]++; @@ -343,6 +349,85 @@ void DetectionOutput::execute(dnnl::stream strm) { generateOutput(reorderedConfData, indicesData, detectionsData, decodedBboxesData, dstData); } +inline void DetectionOutput::confFilterCF(const float* pconf, int* pindices, int* pbuffer, int* detectionsData, const int& n) { + // in: reorderedConf + // out: pindices count + int count = 0; + for (int i = 0; i < numPriorsActual[n]; ++i) { + if (pconf[i] > confidenceThreshold) { + pindices[count] = i; + count++; + } + } + + // in: pindices count + // out: buffer detectionCount + int k = (topK == -1 ? count : (std::min)(topK, count)); + topk(pindices, pbuffer, pconf, count, k); + detectionsData[0] = k; +} + +// MX filter is per image filter, max output is prior num(select max for all class within this prior) +// NMS is per class, keep topk is per image, final output is per class +inline void DetectionOutput::confFilterMX(const float* confData, const float* ARMConfData, float* reorderedConfData, + int* indicesData, int* indicesBufData, int* detectionsData, const int& n) { + std::mutex mtx; + parallel_for(numPriorsActual[n], [&](size_t p) { + // in: origin conf + // out: pindices, detectionCount + // intentionally code branch from higher level + if (withAddBoxPred) { + const bool isARMPrior = ARMConfData[n*priorsNum*2 + p * 2 + 1] < objScore; + float maxConf = -1; + int maxCIdx = 0; + for (int c = 1; c < classesNum; ++c) { + float conf = confData[p * classesNum + c]; + if (isARMPrior) + conf = (c == backgroundClassId) ? 1.0f : 0.0f; // still need refresh conf due to read from origin conf + if (conf >= confidenceThreshold && conf > maxConf) { + maxConf = conf; + maxCIdx = c; + } + } + if (maxCIdx > 0) { + // include this prior + mtx.lock(); + indicesData[detectionsData[0]] = maxCIdx*priorsNum + p; // de-refer to get prior and class id. + detectionsData[0]++; + mtx.unlock(); + } + } else { + float maxConf = -1; + int maxCIdx = 0; + for (int c = 1; c < classesNum; ++c) { + float conf = confData[p * classesNum + c]; + if (conf >= confidenceThreshold && conf > maxConf) { + maxConf = conf; + maxCIdx = c; + } + } + if (maxCIdx > 0) { + // include this prior and class with max conf + mtx.lock(); + indicesData[detectionsData[0]] = maxCIdx*priorsNum + p; // de-refer to get prior and class id. + detectionsData[0]++; + mtx.unlock(); + } + } + }); + + // in: pindices, detectionCount(filtered num) + // out: buffer, detectionCount(k) + int count = detectionsData[0]; + int k = (topK == -1 ? count : (std::min)(topK, count)); + + const float *pconf = reorderedConfData; + // int *indices = indicesData; + // int *pbuffer = indicesBufData; + topk(indicesData, indicesBufData, pconf, count, k); + detectionsData[0] = k; +} + inline void DetectionOutput::getActualPriorNum(const float *priorData, int* numPriorsActual, int n) { numPriorsActual[n] = priorsNum; if (!normalized) { @@ -374,7 +459,7 @@ inline void DetectionOutput::confReorderDense(const float *confData, const float } // withAddBoxPred is false parallel_for2d(imgNum, classesNum, [&](size_t n, size_t c) { - int offset = n * priorsNum * classesNum; + const int offset = n * priorsNum * classesNum; for (int p = 0; p < priorsNum; ++p) { reorderedConfData[offset + c * priorsNum + p] = confData[offset + p * classesNum + c]; @@ -382,108 +467,17 @@ inline void DetectionOutput::confReorderDense(const float *confData, const float }); } -inline void DetectionOutput::confFilterCF(float* reorderedConfData, int* indicesData, int* indicesBufData, int* detectionsData) { - parallel_for2d(imgNum, classesNum, [&](size_t n, size_t c) { - // in: reorderedConf - // out: pindices count - if (c == static_cast(backgroundClassId)) - return; - int off = n * priorsNum * classesNum + c * priorsNum; - const float *pconf = reorderedConfData + off; - int *pindices = indicesData + off; - int *pbuffer = indicesBufData + off; - - int count = 0; - for (int i = 0; i < numPriorsActual[n]; ++i) { - if (pconf[i] > confidenceThreshold) { - pindices[count] = i; - count++; - } - } - - // in: pindices count - // out: buffer detectionCount - int k = (topK == -1 ? count : (std::min)(topK, count)); - topk(pindices, pbuffer, pconf, count, k); - detectionsData[n*classesNum + c] = k; - }); -} - -// MX filter is per image filter, max output is prior num(select max for all class within this prior) -// NMS is per class, keep topk is per image, final output is per class -inline void DetectionOutput::confFilterMX(const float* confData, const float* ARMConfData, float* reorderedConfData, - int* indicesData, int* indicesBufData, int* detectionsData) { - for (int n = 0; n < imgNum; ++n) { - int offB = n * priorsNum * classesNum; - std::mutex mtx; - parallel_for(numPriorsActual[n], [&](size_t p) { - // in: origin conf - // out: pindices, detectionCount - // intentionally code branch from higher level - if (withAddBoxPred) { - bool isARMPrior = ARMConfData[n*priorsNum*2 + p * 2 + 1] < objScore; - float maxConf = -1; - int maxCIdx = 0; - for (int c = 1; c < classesNum; ++c) { - float conf = confData[offB + p * classesNum + c]; - if (isARMPrior) - conf = (c == backgroundClassId) ? 1.0f : 0.0f; // still need refresh conf due to read from origin conf - if (conf >= confidenceThreshold && conf > maxConf) { - maxConf = conf; - maxCIdx = c; - } - } - if (maxCIdx > 0) { - // include this prior - mtx.lock(); - indicesData[offB + detectionsData[n*classesNum]] = maxCIdx*priorsNum + p; // de-refer to get prior and class id. - detectionsData[n*classesNum]++; - mtx.unlock(); - } - } else { - float maxConf = -1; - int maxCIdx = 0; - for (int c = 1; c < classesNum; ++c) { - float conf = confData[offB + p * classesNum + c]; - if (conf >= confidenceThreshold && conf > maxConf) { - maxConf = conf; - maxCIdx = c; - } - } - if (maxCIdx > 0) { - // include this prior and class with max conf - mtx.lock(); - indicesData[offB + detectionsData[n*classesNum]] = maxCIdx*priorsNum + p; // de-refer to get prior and class id. - detectionsData[n*classesNum]++; - mtx.unlock(); - } - } - }); - - // in: pindices, detectionCount(filtered num) - // out: buffer, detectionCount(k) - int count = detectionsData[n*classesNum]; - int k = (topK == -1 ? count : (std::min)(topK, count)); - - const float *pconf = reorderedConfData + offB; - int *indices = indicesData + offB; - int *pbuffer = indicesBufData + offB; - topk(indices, pbuffer, pconf, count, k); - detectionsData[n * classesNum] = k; - } -} - inline void DetectionOutput::confReorderAndFilterSparsityCF(const float* confData, const float* ARMConfData, float* reorderedConfData, int* indicesData, int* indicesBufData, int* detectionsData) { int* reorderedConfDataIndices = reinterpret_cast(reorderedConfData); for (int n = 0; n < imgNum; ++n) { - int off = n * priorsNum * classesNum; - int offV = n * priorsNum; // vertical info + const int off = n * priorsNum * classesNum; + const int offV = n * priorsNum; // vertical info - int offH = n * confInfoLen * classesNum; // horizontal info + const int offH = n * confInfoLen * classesNum; // horizontal info // reset count parallel_for(classesNum, [&](size_t c) { - int countIdx = offH + c * confInfoLen + priorsNum; + const int countIdx = offH + c * confInfoLen + priorsNum; reorderedConfDataIndices[countIdx] = 0; }); @@ -491,7 +485,7 @@ inline void DetectionOutput::confReorderAndFilterSparsityCF(const float* confDat parallel_for(numPriorsActual[n], [&](size_t p) { // intentionally code branch from higher level if (withAddBoxPred) { - bool isARMPrior = ARMConfData[n * priorsNum * 2 + p * 2 + 1] < objScore; + const bool isARMPrior = ARMConfData[n * priorsNum * 2 + p * 2 + 1] < objScore; bool priorStatusSet = false; if (isShareLoc) confInfoForPrior[offV + p] = -1; @@ -501,7 +495,7 @@ inline void DetectionOutput::confReorderAndFilterSparsityCF(const float* confDat if (isARMPrior) conf = (c == backgroundClassId) ? 1.0f : 0.0f; if (conf > confidenceThreshold) { - int idx = offH + c * confInfoLen; + const int idx = offH + c * confInfoLen; reorderedConfData[idx + p] = conf; mtx.lock(); reorderedConfDataIndices[idx + priorsNum]++; @@ -522,7 +516,7 @@ inline void DetectionOutput::confReorderAndFilterSparsityCF(const float* confDat for (int c = 0; c < classesNum; ++c) { float conf = confData[confIdxPrior + c]; if (conf > confidenceThreshold) { - int idx = offH + c * confInfoLen; + const int idx = offH + c * confInfoLen; reorderedConfData[idx + p] = conf; mtx.lock(); reorderedConfDataIndices[idx + priorsNum]++; @@ -542,9 +536,9 @@ inline void DetectionOutput::confReorderAndFilterSparsityCF(const float* confDat // out: buffer, detectionCount(k) if (c == static_cast(backgroundClassId)) // Ignore background class return; - int countIdx = offH + c * confInfoLen + priorsNum; - int count = reorderedConfDataIndices[countIdx]; - int k = (topK == -1 ? count : (std::min)(topK, count)); + const int countIdx = offH + c * confInfoLen + priorsNum; + const int count = reorderedConfDataIndices[countIdx]; + const int k = (topK == -1 ? count : (std::min)(topK, count)); int *reorderedConfIndices = reorderedConfDataIndices + countIdx + 1; int *pbuffer = indicesBufData + off + c * priorsNum; @@ -559,8 +553,8 @@ inline void DetectionOutput::confReorderAndFilterSparsityCF(const float* confDat inline void DetectionOutput::confReorderAndFilterSparsityMX(const float* confData, const float* ARMConfData, float* reorderedConfData, int* indicesData, int* indicesBufData, int* detectionsData) { for (int n = 0; n < imgNum; ++n) { - int off = n * priorsNum * classesNum; - int offV = n * priorsNum; // vertical info + const int off = n * priorsNum * classesNum; + const int offV = n * priorsNum; // vertical info std::mutex mtx; parallel_for(numPriorsActual[n], [&](size_t p) { @@ -605,8 +599,8 @@ inline void DetectionOutput::confReorderAndFilterSparsityMX(const float* confDat // topk // in: indicesData, detection_count(filtered num) // out: buffer, detection_count(k) - int count = detectionsData[n * classesNum]; - int k = (topK == -1 ? count : (std::min)(topK, count)); + const int count = detectionsData[n * classesNum]; + const int k = (topK == -1 ? count : (std::min)(topK, count)); const float *pconf = reorderedConfData + off; int *indices = indicesData + off; @@ -616,6 +610,7 @@ inline void DetectionOutput::confReorderAndFilterSparsityMX(const float* confDat } } +// apply locData(offset) to priordata, generate decodedBox inline void DetectionOutput::decodeBBoxes(const float *priorData, const float *locData, const float *varianceData, @@ -729,15 +724,15 @@ static inline float JaccardOverlap(const float *decodedBbox, const float *bboxSizes, const int idx1, const int idx2) { - float xmin1 = decodedBbox[idx1 * 4 + 0]; - float ymin1 = decodedBbox[idx1 * 4 + 1]; - float xmax1 = decodedBbox[idx1 * 4 + 2]; - float ymax1 = decodedBbox[idx1 * 4 + 3]; - - float xmin2 = decodedBbox[idx2 * 4 + 0]; - float ymin2 = decodedBbox[idx2 * 4 + 1]; - float xmax2 = decodedBbox[idx2 * 4 + 2]; - float ymax2 = decodedBbox[idx2 * 4 + 3]; + const float xmin1 = decodedBbox[idx1 * 4 + 0]; + const float ymin1 = decodedBbox[idx1 * 4 + 1]; + const float xmax1 = decodedBbox[idx1 * 4 + 2]; + const float ymax1 = decodedBbox[idx1 * 4 + 3]; + + const float xmin2 = decodedBbox[idx2 * 4 + 0]; + const float ymin2 = decodedBbox[idx2 * 4 + 1]; + const float xmax2 = decodedBbox[idx2 * 4 + 2]; + const float ymax2 = decodedBbox[idx2 * 4 + 3]; if (xmin2 > xmax1 || xmax2 < xmin1 || ymin2 > ymax1 || ymax2 < ymin1) { return 0.0f; diff --git a/src/plugins/intel_cpu/src/nodes/detection_output.h b/src/plugins/intel_cpu/src/nodes/detection_output.h index 4aa2b04ecdb057..7697752415dc44 100644 --- a/src/plugins/intel_cpu/src/nodes/detection_output.h +++ b/src/plugins/intel_cpu/src/nodes/detection_output.h @@ -60,6 +60,7 @@ class DetectionOutput : public Node { int imgWidth = 0; int imgHeight = 0; int coordOffset = 0; + int cacheSizeL3 = 0; enum CodeType { CORNER = 1, @@ -73,10 +74,10 @@ class DetectionOutput : public Node { inline void confReorderDense(const float* confData, const float* ARMConfData, float* reorderedConfData); - inline void confFilterCF(float* reorderedConfData, int* indicesData, int* indicesBufData, int* detectionsData); + inline void confFilterCF(const float* pConf, int* pindices, int* pbuffer, int* detectionsData, const int& n); inline void confFilterMX(const float* confData, const float* ARMConfData, float* reorderedConfData, - int* indicesData, int* indicesBufData, int* detectionsData); + int* indicesData, int* indicesBufData, int* detectionsData, const int& n); inline void confReorderAndFilterSparsityCF(const float* confData, const float* ARMConfData, float* reorderedConfData, int* indicesData, int* indicesBufData, int* detectionsData); diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/detection_output.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/detection_output.cpp index 049ccd4ec805c7..29be49f621a309 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/detection_output.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/detection_output.cpp @@ -90,8 +90,6 @@ class DetectionOutputLayerCPUTest : public testing::WithParamInterface specificParams3InDynamicLargeTensor = { + // dynamic input shapes + ParamsWhichSizeDependsDynamic { + true, true, true, 1, 1, + {{ov::Dimension::dynamic(), ov::Dimension::dynamic()}, {{1, 381360}, {1, 381360}}}, + {{ov::Dimension::dynamic(), ov::Dimension::dynamic()}, {{1, 1048740}, {1, 1048740}}}, + {{ov::Dimension::dynamic(), ov::Dimension::dynamic(), ov::Dimension::dynamic()}, {{1, 1, 381360}, {1, 1, 381360}}}, + {}, + {} + }, + ParamsWhichSizeDependsDynamic { + false, true, true, 1, 1, + {{ov::Dimension::dynamic(), ov::Dimension::dynamic()}, {{1, 381360}, {1, 381360}}}, + {{ov::Dimension::dynamic(), ov::Dimension::dynamic()}, {{1, 1048740}, {1, 1048740}}}, + {{ov::Dimension::dynamic(), ov::Dimension::dynamic(), ov::Dimension::dynamic()}, {{1, 1, 381360}, {1, 1, 381360}}}, + {}, + {} + }, +}; + +const std::vector confThreshold = {0.032f, 0.88f}; +const auto commonAttributesLargeTensor = ::testing::Combine( + ::testing::Values(numClasses), + ::testing::Values(backgroundLabelId), + ::testing::ValuesIn(topK), + ::testing::ValuesIn(keepTopK), + ::testing::ValuesIn(codeType), + ::testing::Values(nmsThreshold), + ::testing::ValuesIn(confThreshold), + ::testing::ValuesIn(clipAfterNms), + ::testing::ValuesIn(clipBeforeNms), + ::testing::Values(false) +); + +const auto params3InputsDynamicLargeTensor = ::testing::Combine( + commonAttributesLargeTensor, + ::testing::ValuesIn(specificParams3InDynamicLargeTensor), + ::testing::ValuesIn(numberBatch), + ::testing::Values(0.0f), + ::testing::Values(false, true), + ::testing::Values(ov::test::utils::DEVICE_CPU) +); +INSTANTIATE_TEST_SUITE_P( + CPUDetectionOutputDynamic3InLargeTensor, + DetectionOutputLayerCPUTest, + params3InputsDynamicLargeTensor, + DetectionOutputLayerCPUTest::getTestCaseName); + /* =============== 5 inputs cases =============== */ const std::vector specificParams5InDynamic = { @@ -459,5 +508,40 @@ INSTANTIATE_TEST_SUITE_P( params5InputsDynamic, DetectionOutputLayerCPUTest::getTestCaseName); +//////////////////large tensor///////////////// +const std::vector specificParams5InDynamicLargeTensor = { + // dynamic input shapes + ParamsWhichSizeDependsDynamic { + true, true, true, 1, 1, + {{ov::Dimension::dynamic(), ov::Dimension::dynamic()}, {{1, 381360}, {1, 381360}}}, + {{ov::Dimension::dynamic(), ov::Dimension::dynamic()}, {{1, 1048740}, {1, 1048740}}}, + {{ov::Dimension::dynamic(), ov::Dimension::dynamic(), ov::Dimension::dynamic()}, {{1, 1, 381360}, {1, 1, 381360}}}, + {{ov::Dimension::dynamic(), ov::Dimension::dynamic()}, {{1, 190680}, {1, 190680}}}, + {{ov::Dimension::dynamic(), ov::Dimension::dynamic()}, {{1, 381360}, {1, 381360}}}, + }, + ParamsWhichSizeDependsDynamic { + true, false, true, 1, 1, + {{ov::Dimension::dynamic(), ov::Dimension::dynamic()}, {{1, 4194960}, {1, 4194960}}}, + {{ov::Dimension::dynamic(), ov::Dimension::dynamic()}, {{1, 1048740}, {1, 1048740}}}, + {{ov::Dimension::dynamic(), ov::Dimension::dynamic(), ov::Dimension::dynamic()}, {{1, 1, 381360}, {1, 1, 381360}}}, + {{ov::Dimension::dynamic(), ov::Dimension::dynamic()}, {{1, 190680}, {1, 190680}}}, + {{ov::Dimension::dynamic(), ov::Dimension::dynamic()}, {{1, 4194960}, {1, 4194960}}}, + }, +}; +const auto params5InputsDynamicLargeTensor = ::testing::Combine( + commonAttributesLargeTensor, + ::testing::ValuesIn(specificParams5InDynamicLargeTensor), + ::testing::ValuesIn(numberBatch), + ::testing::Values(objectnessScore), + ::testing::Values(false, true), + ::testing::Values(ov::test::utils::DEVICE_CPU) +); + +INSTANTIATE_TEST_SUITE_P( + CPUDetectionOutputDynamic5InLargeTensor, + DetectionOutputLayerCPUTest, + params5InputsDynamicLargeTensor, + DetectionOutputLayerCPUTest::getTestCaseName); + } // namespace } // namespace CPULayerTestsDefinitions From d2ba528993a157a4bea6fb5568bf5972b87f1990 Mon Sep 17 00:00:00 2001 From: Mikhail Ryzhov Date: Thu, 28 Sep 2023 14:42:55 +0300 Subject: [PATCH 17/35] switched to 8 core runner (#20120) --- .github/workflows/linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 51b550e6e960a1..f767503a0a24c8 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -787,7 +787,7 @@ jobs: defaults: run: shell: bash - runs-on: aks-linux-4-cores + runs-on: aks-linux-8-cores container: image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 env: From 960cfa09ad0b8f6bac7af2eacaeab5089615797b Mon Sep 17 00:00:00 2001 From: Maciej Smyk Date: Thu, 28 Sep 2023 13:43:18 +0200 Subject: [PATCH 18/35] update (#20106) --- .../get started}/troubleshooting.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/{install_guides => articles_en/get started}/troubleshooting.md (100%) diff --git a/docs/install_guides/troubleshooting.md b/docs/articles_en/get started/troubleshooting.md similarity index 100% rename from docs/install_guides/troubleshooting.md rename to docs/articles_en/get started/troubleshooting.md From 9a88eed9f2e8f90842fb1013d1df4b4c588168a8 Mon Sep 17 00:00:00 2001 From: Sebastian Golebiewski Date: Thu, 28 Sep 2023 14:04:48 +0200 Subject: [PATCH 19/35] Fix Issue 20097 - providing an easy to read Cmake command (#20126) --- docs/dev/build_windows.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/dev/build_windows.md b/docs/dev/build_windows.md index 86785e8bdc494f..28001328ea3013 100644 --- a/docs/dev/build_windows.md +++ b/docs/dev/build_windows.md @@ -35,7 +35,7 @@ Supported configurations: 3. In the `build` directory, run `cmake` to fetch project dependencies and generate a Visual Studio solution: ```sh - cmake -G "Visual Studio 17 2022" + cmake -G "Visual Studio 17 2022" ``` > **HINT**: **Generating PDB Files and Debugging Your Build**
@@ -46,14 +46,14 @@ Supported configurations: 4. Build generated solution in Visual Studio or run `cmake --build . --config Release --verbose -j8` to build from the command line. Be aware that this process may take some time. -5. Before running the samples, add paths to the Threading Building Blocks (TBB) binaries used for the build to the `%PATH%` environment variable. By default, TBB binaries are downloaded by the CMake-based script to the `/temp/tbb/bin` folder. +5. Before running the samples, add paths to the Threading Building Blocks (TBB) binaries used for the build to the `%PATH%` environment variable. By default, TBB binaries are downloaded by the CMake-based script to the `/temp/tbb/bin` folder. ### Additional Build Options - To build the OpenVINO Runtime Python API: 1. First, install all additional packages (e.g., cython) listed in the file: ```sh - pip install -r \src\bindings\python\src\compatibility\openvino\requirements-dev.txt + pip install -r \src\bindings\python\src\compatibility\openvino\requirements-dev.txt ``` 2. Second, enable the `-DENABLE_PYTHON=ON` in the CMake (Step #4) option above. To specify an exact Python version, use the following options (requires cmake 3.16 and higher): ```sh From 744f5d4130633842bd8437f90690155bff8a1631 Mon Sep 17 00:00:00 2001 From: Anastasia Kuporosova Date: Thu, 28 Sep 2023 14:06:20 +0200 Subject: [PATCH 20/35] [PyOV] Fix docs and add test for Model._get_raw_address (#20109) --- src/bindings/python/src/pyopenvino/graph/model.cpp | 4 +++- src/bindings/python/tests/test_runtime/test_model.py | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/bindings/python/src/pyopenvino/graph/model.cpp b/src/bindings/python/src/pyopenvino/graph/model.cpp index f666fcd8e7602d..52be0daf714ab7 100644 --- a/src/bindings/python/src/pyopenvino/graph/model.cpp +++ b/src/bindings/python/src/pyopenvino/graph/model.cpp @@ -1004,7 +1004,9 @@ void regclass_graph_Model(py::module m) { return reinterpret_cast(&self); }, R"( - Returns raw address of the Model object. + Returns a raw address of the Model object from C++. + + Use this function in order to compare underlying C++ addresses instead of using `__eq__` in Python. :return: a raw address of the Model object. :rtype: int diff --git a/src/bindings/python/tests/test_runtime/test_model.py b/src/bindings/python/tests/test_runtime/test_model.py index 90e9ff4e4bb9f5..9806fb1b0e0b75 100644 --- a/src/bindings/python/tests/test_runtime/test_model.py +++ b/src/bindings/python/tests/test_runtime/test_model.py @@ -657,3 +657,12 @@ def test_model_add_remove_result_parameter_sink(): assert ["Assign"] == [sink.get_type_name() for sink in assign_nodes] model.remove_sink(assign) assert len(model.sinks) == 0 + + +def test_model_get_raw_address(): + model = generate_add_model() + model_with_same_addr = model + model_different = generate_add_model() + + assert model._get_raw_address() == model_with_same_addr._get_raw_address() + assert model._get_raw_address() != model_different._get_raw_address() From 3de133283896564d519cf7d4f15142a4dbab34fd Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Thu, 28 Sep 2023 19:55:20 +0400 Subject: [PATCH 21/35] VCPKG docs for dynamic OpenVINO build (#20127) * VCPKG docs for dynamic OpenVINO build * Apply suggestions from code review Co-authored-by: Ilya Lavrenov * Update installing-openvino-vcpkg.md * Update docs/install_guides/installing-openvino-vcpkg.md Co-authored-by: Ilya Lavrenov --------- Co-authored-by: Sebastian Golebiewski --- .../installing-openvino-vcpkg.md | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/docs/install_guides/installing-openvino-vcpkg.md b/docs/install_guides/installing-openvino-vcpkg.md index c0eba8c88943d6..eb508a520f2e1c 100644 --- a/docs/install_guides/installing-openvino-vcpkg.md +++ b/docs/install_guides/installing-openvino-vcpkg.md @@ -55,7 +55,7 @@ Installing OpenVINO Runtime vcpkg install 'openvino[core,cpu,ir]' - vcpkg also provides a way to install OpenVINO for any specific configuration you want via `triplets `, for example to install OpenVINO statically on Windows, use: + vcpkg also provides a way to install OpenVINO for any specific configuration you want via `triplets `__, for example to install OpenVINO statically on Windows, use: .. code-block:: sh @@ -64,6 +64,37 @@ Installing OpenVINO Runtime Note that the vcpkg installation means building all packages and dependencies from source, which means the compiler stage will require additional time to complete the process. +.. important:: + + If you are building OpenVINO as dynamic libraries and you want to use either Paddle, TensorFlow or ONNX frontends, you need to create `custom vcpkg `__ triplet file, like ``/triplets/community/x64-linux-release-dynamic.cmake``, which builds ``protobuf`` dependency statically: + + .. code-block:: sh + + # typical values of vcpkg toolchain + set(VCPKG_TARGET_ARCHITECTURE x64) + set(VCPKG_CRT_LINKAGE dynamic) + # by default, all libraries are built dynamically + set(VCPKG_LIBRARY_LINKAGE dynamic) + + set(VCPKG_CMAKE_SYSTEM_NAME Linux) + set(VCPKG_BUILD_TYPE release) + + set(VCPKG_FIXUP_ELF_RPATH ON) + + # OpenVINO specific additions: build statically the following internal dependencies + # IMPORTANT: you need to build at least protobuf statically, others can be dynamic + if(PORT MATCHES "^(ade|hwloc|onnx|protobuf|pugixml|snappy)$") + set(VCPKG_LIBRARY_LINKAGE static) + endif() + + + Then, you can use such a triplet file with the following command: + + .. code-block:: sh + + vcpkg install openvino:x64-linux-release-dynamic + + After installation, you can use OpenVINO in your product's cmake scripts: .. code-block:: sh @@ -74,7 +105,7 @@ And running from terminal: .. code-block:: sh - cmake -B -S -DCMAKE_TOOLCHAIN_FILE=/scripts/buildsystems/vcpkg.cmake + cmake -B -S -DCMAKE_TOOLCHAIN_FILE=/scripts/buildsystems/vcpkg.cmake Congratulations! You've just Installed and used OpenVINO in your project! For some use cases you may still need to install additional components. Check the From b73b2502b115904a0d42ec64d2d961bc488bab5d Mon Sep 17 00:00:00 2001 From: andreyanufr Date: Thu, 28 Sep 2023 18:56:57 +0200 Subject: [PATCH 22/35] Introduce NF4 data type (#19900) * NF4 reference initial commit * Compilable version. * Executable NF4. * Fixed nf4 unpacking. * 1) Fixed warnings with nf4. 2) Removed unused functions. * Added one test for nf4. * Fixed code-style errors. * Fixed code-style errors. * Fixed NamingConventionCheck errors. * Fixed test with nf4. * Fixed windows compilation. * Fixed casting warning. * Fixed incorrect changes. * Changed order of elements in nf4 pack/unpack. * 1) Made Convert only on direction nf4->other type. 2) Applied reviewers suggestions. * Fixed code style. * Fised code style. * 1) Added array header. 2) Added Bitsandbytes to third-party-programs.txt. * 1) Removed unused code. 2) Fixed style typos. 3) Revert submodule version. * Added test for nf4 compression. * NF4 test refactoring. * Added cpp tests for NF4. * Removed model compilation from NF4 tests. * Reverted submodule version. --- .../ncc_naming_style/openvino.style | 2 +- licensing/third-party-programs.txt | 26 +++++ src/bindings/c/include/openvino/c/ov_common.h | 1 + src/bindings/c/src/ov_tensor.cpp | 3 +- .../python/src/openvino/helpers/packing.py | 4 +- .../python/src/pyopenvino/core/common.cpp | 1 + .../pyopenvino/graph/types/element_type.cpp | 1 + .../python/tests/test_runtime/test_tensor.py | 1 + .../test_compression_4bit.py | 50 ++++++++++ .../low_precision/layer_transformation.hpp | 1 + .../include/ngraph/builder/make_constant.hpp | 3 + src/core/include/ngraph/type/element_type.hpp | 1 + .../openvino/core/type/element_type.hpp | 7 +- .../core/type/element_type_traits.hpp | 5 + src/core/include/openvino/core/type/nf4.hpp | 47 +++++++++ src/core/include/openvino/op/constant.hpp | 73 ++++++++++++-- .../include/openvino/reference/convert.hpp | 3 + src/core/shape_inference/include/utils.hpp | 2 +- src/core/src/op/constant.cpp | 11 +++ src/core/src/op/convert.cpp | 5 +- src/core/src/pass/serialize.cpp | 2 + src/core/src/pass/visualize_tree.cpp | 1 + src/core/src/type/element_type.cpp | 10 +- src/core/src/type/nf4.cpp | 81 ++++++++++++++++ src/core/tests/element_type.cpp | 2 + src/core/tests/nf4.cpp | 96 +++++++++++++++++++ src/plugins/template/backend/ops/convert.cpp | 6 +- .../common_test_utils/src/ov_tensor_utils.cpp | 1 + .../sea_itt_lib/IttNotifyStdSrc.cpp | 2 +- 29 files changed, 431 insertions(+), 17 deletions(-) create mode 100644 src/bindings/python/tests/test_transformations/test_compression_4bit.py create mode 100644 src/core/include/openvino/core/type/nf4.hpp create mode 100644 src/core/src/type/nf4.cpp create mode 100644 src/core/tests/nf4.cpp diff --git a/cmake/developer_package/ncc_naming_style/openvino.style b/cmake/developer_package/ncc_naming_style/openvino.style index c264122d881a6d..2eb616aae8cf85 100644 --- a/cmake/developer_package/ncc_naming_style/openvino.style +++ b/cmake/developer_package/ncc_naming_style/openvino.style @@ -18,7 +18,7 @@ VariableReference: '^\w+$' EnumName: '^[A-Z][\w]+$' # excepts element_type -EnumConstantName: '^([A-Z\d_]+|undefined|dynamic|boolean|bf16|f16|f32|f64|i4|i8|i16|i32|i64|u1|u4|u8|u16|u32|u64|asymmetric|align_corners|round_prefer_floor|round_prefer_ceil|floor|ceil|simple|nearest|linear|linear_onnx|cubic|area|scales|sizes|half_pixel|tf_half_pixel_for_nn|pytorch_half_pixel|asymetric)$' +EnumConstantName: '^([A-Z\d_]+|undefined|dynamic|boolean|bf16|f16|f32|f64|i4|i8|i16|i32|i64|u1|u4|u8|u16|u32|u64|nf4|asymmetric|align_corners|round_prefer_floor|round_prefer_ceil|floor|ceil|simple|nearest|linear|linear_onnx|cubic|area|scales|sizes|half_pixel|tf_half_pixel_for_nn|pytorch_half_pixel|asymetric)$' # TODO: align UsingDeclaration: '^.*$' TypedefName: '^.*$' diff --git a/licensing/third-party-programs.txt b/licensing/third-party-programs.txt index b1fdd9a5ca0bbb..6cbc20511fe648 100644 --- a/licensing/third-party-programs.txt +++ b/licensing/third-party-programs.txt @@ -1640,3 +1640,29 @@ INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------- + +30. Bitsandbytes (https://github.com/TimDettmers/bitsandbytes) + +MIT License + +Copyright (c) Facebook, Inc. and its affiliates. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/bindings/c/include/openvino/c/ov_common.h b/src/bindings/c/include/openvino/c/ov_common.h index e37448e6582505..faf9369050c839 100644 --- a/src/bindings/c/include/openvino/c/ov_common.h +++ b/src/bindings/c/include/openvino/c/ov_common.h @@ -186,6 +186,7 @@ typedef enum { U16, //!< u16 element type U32, //!< u32 element type U64, //!< u64 element type + NF4, //!< nf4 element type } ov_element_type_e; /** diff --git a/src/bindings/c/src/ov_tensor.cpp b/src/bindings/c/src/ov_tensor.cpp index 24688cbd8464fe..a3372583637ff5 100644 --- a/src/bindings/c/src/ov_tensor.cpp +++ b/src/bindings/c/src/ov_tensor.cpp @@ -23,7 +23,8 @@ const std::map element_type_map = { {ov_element_type_e::U8, ov::element::u8}, {ov_element_type_e::U16, ov::element::u16}, {ov_element_type_e::U32, ov::element::u32}, - {ov_element_type_e::U64, ov::element::u64}}; + {ov_element_type_e::U64, ov::element::u64}, + {ov_element_type_e::NF4, ov::element::nf4}}; inline ov_element_type_e find_ov_element_type_e(ov::element::Type type) { for (auto iter = element_type_map.begin(); iter != element_type_map.end(); iter++) { diff --git a/src/bindings/python/src/openvino/helpers/packing.py b/src/bindings/python/src/openvino/helpers/packing.py index 914392c06469c3..2b94c7ab11631f 100644 --- a/src/bindings/python/src/openvino/helpers/packing.py +++ b/src/bindings/python/src/openvino/helpers/packing.py @@ -23,7 +23,7 @@ def pack_data(array: np.ndarray, type: Type) -> np.ndarray: :param type: Type to interpret the array values. Type must be u1, u4 or i4. :type type: openvino.runtime.Type """ - assert type in [Type.u1, Type.u4, Type.i4], "Packing algorithm for the" "data types stored in 1, 2 or 4 bits" + assert type in [Type.u1, Type.u4, Type.i4, Type.nf4], "Packing algorithm for the" "data types stored in 1, 2 or 4 bits" minimum_regular_dtype = np.int8 if type == Type.i4 else np.uint8 casted_to_regular_type = array.astype(dtype=minimum_regular_dtype, casting="unsafe") @@ -62,7 +62,7 @@ def unpack_data(array: np.ndarray, type: Type, shape: Union[list, Shape]) -> np. :param shape: the new shape for the unpacked array. :type shape: Union[list, openvino.runtime.Shape] """ - assert type in [Type.u1, Type.u4, Type.i4], "Unpacking algorithm for the" "data types stored in 1, 2 or 4 bits" + assert type in [Type.u1, Type.u4, Type.i4, Type.nf4], "Unpacking algorithm for the" "data types stored in 1, 2 or 4 bits" unpacked = np.unpackbits(array.view(np.uint8)) shape = list(shape) if type.bitwidth == 1: diff --git a/src/bindings/python/src/pyopenvino/core/common.cpp b/src/bindings/python/src/pyopenvino/core/common.cpp index c818832b48b52d..b78d3ea4c37bff 100644 --- a/src/bindings/python/src/pyopenvino/core/common.cpp +++ b/src/bindings/python/src/pyopenvino/core/common.cpp @@ -30,6 +30,7 @@ const std::map& ov_type_to_dtype() { {ov::element::boolean, py::dtype("bool")}, {ov::element::u1, py::dtype("uint8")}, {ov::element::u4, py::dtype("uint8")}, + {ov::element::nf4, py::dtype("uint8")}, {ov::element::i4, py::dtype("int8")}, }; return ov_type_to_dtype_mapping; diff --git a/src/bindings/python/src/pyopenvino/graph/types/element_type.cpp b/src/bindings/python/src/pyopenvino/graph/types/element_type.cpp index 9153287c5b230f..1b5e8fda19eb35 100644 --- a/src/bindings/python/src/pyopenvino/graph/types/element_type.cpp +++ b/src/bindings/python/src/pyopenvino/graph/types/element_type.cpp @@ -48,6 +48,7 @@ void regclass_graph_Type(py::module m) { type.attr("u32") = ov::element::u32; type.attr("u64") = ov::element::u64; type.attr("bf16") = ov::element::bf16; + type.attr("nf4") = ov::element::nf4; type.def("__hash__", &ov::element::Type::hash); type.def("__repr__", [](const ov::element::Type& self) { diff --git a/src/bindings/python/tests/test_runtime/test_tensor.py b/src/bindings/python/tests/test_runtime/test_tensor.py index 46ebbb749fefd0..6b9f3272b81f62 100644 --- a/src/bindings/python/tests/test_runtime/test_tensor.py +++ b/src/bindings/python/tests/test_runtime/test_tensor.py @@ -377,6 +377,7 @@ def test_init_with_packed_buffer(dtype, ov_type): (0, 2, ov.Type.u1, np.uint8), (0, 16, ov.Type.u4, np.uint8), (-8, 7, ov.Type.i4, np.int8), + (0, 16, ov.Type.nf4, np.uint8), ]) def test_packing(shape, low, high, ov_type, dtype): ov_tensor = Tensor(ov_type, shape) diff --git a/src/bindings/python/tests/test_transformations/test_compression_4bit.py b/src/bindings/python/tests/test_transformations/test_compression_4bit.py new file mode 100644 index 00000000000000..345f86870867fe --- /dev/null +++ b/src/bindings/python/tests/test_transformations/test_compression_4bit.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + + +import numpy as np +from openvino.runtime import opset9 as opset + +import openvino as ov +import pytest + + +@pytest.mark.parametrize(("ov_type", "numpy_dtype"), [ + (ov.Type.f32, np.float32), + (ov.Type.f64, np.float64), + (ov.Type.f16, np.float16), +]) +def test_float_to_nf4_convert(ov_type, numpy_dtype): + data = np.linspace(-1.5, 1.5, num=41, dtype=numpy_dtype) + + compressed_const = opset.constant(data, dtype=ov.Type.nf4, name="nf4_constant") + convert = opset.convert(compressed_const, data.dtype) + parameter = opset.parameter(ov.PartialShape([-1]), ov_type) + add_op = opset.add(parameter, convert) + model = ov.Model([add_op], [parameter]) + + compiled = ov.compile_model(model) + tensor = np.zeros(data.shape, dtype=numpy_dtype) + result = compiled(tensor)[0] + + uniq = [] + for res_val in result: + if res_val not in uniq: + uniq.append(res_val) + uniq = np.array(uniq) + + assert len(uniq) == 16 + + target = [-1.0, -0.6961928009986877, -0.5250730514526367, + -0.39491748809814453, -0.28444138169288635, + -0.18477343022823334, -0.09105003625154495, + 0.0, 0.07958029955625534, 0.16093020141124725, + 0.24611230194568634, 0.33791524171829224, + 0.44070982933044434, 0.5626170039176941, + 0.7229568362236023, 1.0] + target = np.array(target) + + diff = np.max(np.abs(target - uniq)) + + assert diff < 0.001 diff --git a/src/common/low_precision_transformations/include/low_precision/layer_transformation.hpp b/src/common/low_precision_transformations/include/low_precision/layer_transformation.hpp index 6acb2cd76343bd..80096cdf7c18f6 100644 --- a/src/common/low_precision_transformations/include/low_precision/layer_transformation.hpp +++ b/src/common/low_precision_transformations/include/low_precision/layer_transformation.hpp @@ -88,6 +88,7 @@ class LP_TRANSFORMATIONS_API DataPrecision { switch (precision) { case element::i4: case element::u4: + case element::nf4: return (levels == low_precision::levels::int4) || (levels == low_precision::levels::int4_narrow_range); case element::i8: case element::u8: diff --git a/src/core/builder/include/ngraph/builder/make_constant.hpp b/src/core/builder/include/ngraph/builder/make_constant.hpp index 5fa7ba68dcf873..61c09b41ac839f 100644 --- a/src/core/builder/include/ngraph/builder/make_constant.hpp +++ b/src/core/builder/include/ngraph/builder/make_constant.hpp @@ -99,6 +99,9 @@ std::shared_ptr make_constant(const element::Type& type, const Shape& shap case element::Type_t::u4: unsupported_data_type = "u4"; break; + case element::Type_t::nf4: + unsupported_data_type = "nf4"; + break; case element::Type_t::undefined: unsupported_data_type = "undefined"; break; diff --git a/src/core/include/ngraph/type/element_type.hpp b/src/core/include/ngraph/type/element_type.hpp index 484aba40827872..e3db087ccf7f16 100644 --- a/src/core/include/ngraph/type/element_type.hpp +++ b/src/core/include/ngraph/type/element_type.hpp @@ -40,6 +40,7 @@ using ov::element::i32; using ov::element::i4; using ov::element::i64; using ov::element::i8; +using ov::element::nf4; using ov::element::u1; using ov::element::u16; using ov::element::u32; diff --git a/src/core/include/openvino/core/type/element_type.hpp b/src/core/include/openvino/core/type/element_type.hpp index 5bc60c0a397b65..1534e9e0cc8fca 100644 --- a/src/core/include/openvino/core/type/element_type.hpp +++ b/src/core/include/openvino/core/type/element_type.hpp @@ -20,6 +20,7 @@ #include "openvino/core/rtti.hpp" #include "openvino/core/type/bfloat16.hpp" #include "openvino/core/type/float16.hpp" +#include "openvino/core/type/nf4.hpp" /** * @defgroup ov_element_cpp_api Element types @@ -50,7 +51,8 @@ enum class Type_t { u8, //!< u8 element type u16, //!< u16 element type u32, //!< u32 element type - u64 //!< u64 element type + u64, //!< u64 element type + nf4 //!< nf4 element type }; /// \brief Base class to define element type @@ -177,6 +179,9 @@ constexpr Type u32(Type_t::u32); /// \brief u64 element type /// \ingroup ov_element_cpp_api constexpr Type u64(Type_t::u64); +/// \brief nf4 element type +/// \ingroup ov_element_cpp_api +constexpr Type nf4(Type_t::nf4); template Type from() { diff --git a/src/core/include/openvino/core/type/element_type_traits.hpp b/src/core/include/openvino/core/type/element_type_traits.hpp index 7f5ea7e0fc3364..e26cf8e88857e3 100644 --- a/src/core/include/openvino/core/type/element_type_traits.hpp +++ b/src/core/include/openvino/core/type/element_type_traits.hpp @@ -92,4 +92,9 @@ template <> struct element_type_traits { using value_type = uint64_t; }; + +template <> +struct element_type_traits { + using value_type = int8_t; +}; } // namespace ov diff --git a/src/core/include/openvino/core/type/nf4.hpp b/src/core/include/openvino/core/type/nf4.hpp new file mode 100644 index 00000000000000..58a036b97f34a7 --- /dev/null +++ b/src/core/include/openvino/core/type/nf4.hpp @@ -0,0 +1,47 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include "openvino/core/core_visibility.hpp" + +namespace ov { +class OPENVINO_API ConvertNF4 { +public: + constexpr ConvertNF4() = default; + + template ::value, bool>::type = true> + static void unpack(T* dst, const uint8_t* src, std::size_t idx) { + uint8_t nf4_idx = get_u4(src, idx); + float val = dequantize(nf4_idx); + dst[idx] = static_cast(val); + } + + template ::value, bool>::type = true> + static void unpack(T* dst, const uint8_t* src, std::size_t idx) { + uint8_t nf4_idx = get_u4(src, idx); + dst[idx] = static_cast(nf4_idx); + } + + static float dequantize(uint8_t val); + + static uint8_t quantize(float x); + +private: + static 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); + return (buf[byte_idx] >> bit_shift) & 0xF; + } +}; + +}; // namespace ov diff --git a/src/core/include/openvino/op/constant.hpp b/src/core/include/openvino/op/constant.hpp index 3c2d048e0db7bf..bc36330217d876 100644 --- a/src/core/include/openvino/op/constant.hpp +++ b/src/core/include/openvino/op/constant.hpp @@ -143,6 +143,9 @@ class OPENVINO_API Constant : public Op { case Type_t::u64: fill_data(value); break; + case Type_t::nf4: + fill_data(value); + break; case Type_t::undefined: case Type_t::dynamic: OPENVINO_THROW("unsupported type"); @@ -408,7 +411,7 @@ class OPENVINO_API Constant : public Op { template , typename std::enable_if::type = true> StorageDataType get_element_value(size_t index) const { return get_data_ptr()[index]; @@ -428,6 +431,13 @@ class OPENVINO_API Constant : public Op { return (get_data_ptr()[index / 2] >> (index % 2 ? 0 : 4)) & 0x0F; } + template , + typename std::enable_if::type = true> + StorageDataType get_element_value(size_t index) const { + return (get_data_ptr()[index / 2] >> (index % 2 ? 4 : 0)) & 0x0F; + } + template , typename std::enable_if::type = true> @@ -554,7 +564,7 @@ class OPENVINO_API Constant : public Op { typename T, typename StorageDataType = fundamental_type_for, typename std::enable_if::type = true> void fill_data(const T& value) { #ifdef __clang__ @@ -607,7 +617,9 @@ class OPENVINO_API Constant : public Op { template , - typename std::enable_if::type = true> + typename std::enable_if::type = true> void fill_data(const T& value) { uint8_t v = value_in_range(value); v &= 0x0F; @@ -640,8 +652,8 @@ 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(); @@ -670,6 +682,50 @@ class OPENVINO_API Constant : public Op { } } + template , + 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; + 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 = (v2 << 4) | v1; + p[i] = static_cast(v); + } + if (source.size() % 2) { + const auto v = value_in_range(source[i * 2]) & 0x0F; + p[i] = static_cast(v); + } + } + + template , + typename std::enable_if::value || std::is_same::value || + std::is_same::value), + bool>::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 idx1 = ConvertNF4::quantize(static_cast(source[i * 2])); + const auto idx2 = ConvertNF4::quantize(static_cast(source[i * 2 + 1])); + const auto v1 = value_in_range(idx1) & 0x0F; + const auto v2 = value_in_range(idx2) & 0x0F; + const auto v = (v2 << 4) | v1; + p[i] = static_cast(v); + } + if (source.size() % 2) { + const auto idx1 = ConvertNF4::quantize(static_cast(source[i * 2])); + const auto v = value_in_range(idx1) & 0x0F; + p[i] = static_cast(v); + } + } + template , @@ -755,6 +811,9 @@ class OPENVINO_API Constant : public Op { case Type_t::u64: write_buffer(source); break; + case Type_t::nf4: + write_buffer(source); + break; case element::Type_t::undefined: case element::Type_t::dynamic: OPENVINO_THROW("unsupported type"); @@ -765,7 +824,9 @@ class OPENVINO_API Constant : public Op { } template ::type = true> + typename std::enable_if::type = true> static ov::fundamental_type_for value_in_range(const ValueT& value) { const auto result = ov::fundamental_type_for(value); OPENVINO_ASSERT(0 <= result && result <= 15, "assigned value out of range u4 values"); diff --git a/src/core/reference/include/openvino/reference/convert.hpp b/src/core/reference/include/openvino/reference/convert.hpp index d95ce275328ee2..a6b843bd5f0c9d 100644 --- a/src/core/reference/include/openvino/reference/convert.hpp +++ b/src/core/reference/include/openvino/reference/convert.hpp @@ -70,6 +70,7 @@ TO get_value(const uint8_t* buf, size_t idx, element::Type from_type) { if (from_type == element::i4) { return detail::get_i4(buf, idx); } + auto v = reinterpret_cast(buf); return static_cast(v[idx]); } @@ -85,6 +86,8 @@ void lp_convert(const TI* arg, TO* out, size_t count, element::Type_t src_type, detail::set_u4(output, i, detail::get_value(input, i, src_type)); } else if (dst_type == element::i4) { detail::set_i4(output, i, detail::get_value(input, i, src_type)); + } else if (src_type == element::nf4) { + ConvertNF4::unpack(out, input, i); } else { out[i] = detail::get_value(input, i, src_type); } diff --git a/src/core/shape_inference/include/utils.hpp b/src/core/shape_inference/include/utils.hpp index 360c4eaa5f7b58..2b6b17f06b336e 100644 --- a/src/core/shape_inference/include/utils.hpp +++ b/src/core/shape_inference/include/utils.hpp @@ -53,7 +53,7 @@ TResult get_raw_data_as(const element::Type_t et, const void* const ptr, const s auto out_it = std::inserter(out, out.end()); using namespace ov::element; - IfTypeOf::apply( + IfTypeOf::apply( et, ptr, size, diff --git a/src/core/src/op/constant.cpp b/src/core/src/op/constant.cpp index 44211151fa2826..34ed30d636cf64 100644 --- a/src/core/src/op/constant.cpp +++ b/src/core/src/op/constant.cpp @@ -130,6 +130,9 @@ ov::op::v0::Constant::Constant(const element::Type& type, case Type_t::u64: fill_data(ngraph::parse_string(values[0])); break; + case Type_t::nf4: + fill_data(ngraph::parse_string(values[0])); + break; case Type_t::undefined: OPENVINO_THROW("deserialize unsupported type undefined"); case Type_t::dynamic: @@ -186,6 +189,9 @@ ov::op::v0::Constant::Constant(const element::Type& type, case Type_t::u64: write_buffer(ngraph::parse_string(values)); break; + case Type_t::nf4: + write_buffer(ngraph::parse_string(values)); + break; case Type_t::undefined: OPENVINO_THROW("deserialize unsupported type undefined"); case Type_t::dynamic: @@ -296,6 +302,9 @@ string ov::op::v0::Constant::convert_value_to_string(size_t index) const { case Type_t::u64: rc = to_string(get_element_value(index)); break; + case Type_t::nf4: + rc = to_string(get_element_value(index)); + break; case Type_t::undefined: case Type_t::dynamic: OPENVINO_THROW("unsupported type"); @@ -367,6 +376,7 @@ vector ov::op::v0::Constant::get_value_strings() const { break; case element::Type_t::u1: case element::Type_t::u4: + case element::Type_t::nf4: for (auto value : cast_vector()) { rc.push_back(to_string(value)); } @@ -523,6 +533,7 @@ bool ov::op::v0::Constant::are_all_data_elements_bitwise_identical() const { case element::Type_t::i4: case element::Type_t::u1: case element::Type_t::u4: + case element::Type_t::nf4: case element::Type_t::undefined: case element::Type_t::dynamic: break; diff --git a/src/core/src/op/convert.cpp b/src/core/src/op/convert.cpp index b36b8c6ef44449..2d602161fb4e5a 100644 --- a/src/core/src/op/convert.cpp +++ b/src/core/src/op/convert.cpp @@ -52,7 +52,8 @@ bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out) { } if (((INPUT_ET == element::u1) || (OUTPUT_ET == element::u1)) || ((INPUT_ET == element::u4) || (OUTPUT_ET == element::u4)) || - ((INPUT_ET == element::i4) || (OUTPUT_ET == element::i4))) { + ((INPUT_ET == element::i4) || (OUTPUT_ET == element::i4)) || + ((INPUT_ET == element::nf4) || (OUTPUT_ET == element::nf4))) { ov::reference::detail::lp_convert(arg->get_data_ptr(), out->get_data_ptr(), element_count, @@ -91,6 +92,7 @@ bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out) { TYPE_OUT_CASE(f32, arg, out); TYPE_OUT_CASE(f64, arg, out); TYPE_OUT_CASE(boolean, arg, out); + TYPE_OUT_CASE(nf4, arg, out); default: rc = false; break; @@ -117,6 +119,7 @@ bool evaluate_convert(const HostTensorPtr& arg, const HostTensorPtr& out) { NGRAPH_TYPE_CASE(evaluate_convert, f32, arg, out); NGRAPH_TYPE_CASE(evaluate_convert, f64, arg, out); NGRAPH_TYPE_CASE(evaluate_convert, boolean, arg, out); + NGRAPH_TYPE_CASE(evaluate_convert, nf4, arg, out); default: rc = false; break; diff --git a/src/core/src/pass/serialize.cpp b/src/core/src/pass/serialize.cpp index b9f39f0d842db6..dc1263d7991deb 100644 --- a/src/core/src/pass/serialize.cpp +++ b/src/core/src/pass/serialize.cpp @@ -741,6 +741,8 @@ std::string get_precision_name(const ov::element::Type& elem_type) { return "BIN"; case ::ov::element::Type_t::boolean: return "BOOL"; + case ::ov::element::Type_t::nf4: + return "NF4"; default: OPENVINO_THROW("Unsupported precision: ", elem_type); } diff --git a/src/core/src/pass/visualize_tree.cpp b/src/core/src/pass/visualize_tree.cpp index 15f1bc410b2189..7e9192d4a1ac00 100644 --- a/src/core/src/pass/visualize_tree.cpp +++ b/src/core/src/pass/visualize_tree.cpp @@ -374,6 +374,7 @@ static std::string get_value(const std::shared_ptr& consta case ov::element::Type_t::dynamic: case ov::element::Type_t::u1: case ov::element::Type_t::u4: + case ov::element::Type_t::nf4: case ov::element::Type_t::i4: ss << constant->get_output_element_type(0).get_type_name() << " value"; break; diff --git a/src/core/src/type/element_type.cpp b/src/core/src/type/element_type.cpp index d08197df8e99bc..e7cf311c857836 100644 --- a/src/core/src/type/element_type.cpp +++ b/src/core/src/type/element_type.cpp @@ -69,6 +69,8 @@ inline TypeInfo get_type_info(ov::element::Type_t type) { return {32, false, false, false, "uint32_t", "u32"}; case ov::element::Type_t::u64: return {64, false, false, false, "uint64_t", "u64"}; + case ov::element::Type_t::nf4: + return {4, false, false, true, "nfloat4", "nf4"}; default: OPENVINO_THROW("ov::element::Type_t not supported: ", type); } @@ -111,6 +113,8 @@ ov::element::Type type_from_string(const std::string& type) { return ::ov::element::Type(::ov::element::Type_t::undefined); } else if (type == "dynamic") { return ::ov::element::Type(::ov::element::Type_t::dynamic); + } else if (type == "nf4" || type == "NF4") { + return ::ov::element::Type(::ov::element::Type_t::nf4); } else { OPENVINO_THROW("Incorrect type: ", type); } @@ -163,6 +167,7 @@ ov::element::Type::Type(size_t bitwidth, {ov::element::Type_t::u16, {16, false, false, false, "uint16_t", "u16"}}, {ov::element::Type_t::u32, {32, false, false, false, "uint32_t", "u32"}}, {ov::element::Type_t::u64, {64, false, false, false, "uint64_t", "u64"}}, + {ov::element::Type_t::u4, {4, false, false, false, "uint4_t", "nf4"}}, }; for (const auto& t : elements_map) { const TypeInfo& info = t.second; @@ -319,6 +324,7 @@ std::istream& ov::element::operator>>(std::istream& in, ov::element::Type& obj) {"FP64", ov::element::f64}, {"FP16", ov::element::f16}, {"BIN", ov::element::u1}, + {"NF4", ov::element::nf4}, }; std::string str; in >> str; @@ -400,6 +406,7 @@ inline size_t compiler_byte_size(ov::element::Type_t et) { ET_CASE(u16); ET_CASE(u32); ET_CASE(u64); + ET_CASE(nf4); #undef ET_CASE case ov::element::Type_t::undefined: return 0; @@ -431,7 +438,8 @@ OPENVINO_API EnumNames& EnumNames::get() { {"u8", element::Type_t::u8}, {"u16", element::Type_t::u16}, {"u32", element::Type_t::u32}, - {"u64", element::Type_t::u64}}); + {"u64", element::Type_t::u64}, + {"nf4", element::Type_t::nf4}}); return enum_names; } diff --git a/src/core/src/type/nf4.cpp b/src/core/src/type/nf4.cpp new file mode 100644 index 00000000000000..7031b9c28983f6 --- /dev/null +++ b/src/core/src/type/nf4.cpp @@ -0,0 +1,81 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +// Contains logic derived from bitsandbytes +// https://github.com/TimDettmers/bitsandbytes/blob/c82f51c0f784d8a43ebcb9cdefbf94e3f3b9c6c3/csrc/kernels.cu#L223 +// implementation. +// Copyright notice from original source file is as follows. + +//******************************************************************************* +// Copyright (c) Facebook, Inc. and its affiliates. +// +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. +//============================================================================== + +#include "openvino/core/type/nf4.hpp" + +using namespace ov; + +float ConvertNF4::dequantize(uint8_t val) { + static const std::array lookup = {-1.0f, + -0.6961928009986877f, + -0.5250730514526367f, + -0.39491748809814453f, + -0.28444138169288635f, + -0.18477343022823334f, + -0.09105003625154495f, + 0.0f, + 0.07958029955625534f, + 0.16093020141124725f, + 0.24611230194568634f, + 0.33791524171829224f, + 0.44070982933044434f, + 0.5626170039176941f, + 0.7229568362236023f, + 1.0f}; + return lookup[val]; +} + +uint8_t ConvertNF4::quantize(float x) { + if (x > 0.03979014977812767f) + if (x > 0.3893125355243683f) // 1 + if (x > 0.6427869200706482f) // 11 + if (x > 0.8614784181118011f) // 111 + return 0b1111; + else + return 0b1110; + else if (x > 0.5016634166240692f) // 110 + return 0b1101; + else + return 0b1100; + else if (x > 0.2035212516784668f) // 10 + if (x > 0.2920137718319893f) // 101 + return 0b1011; + else + return 0b1010; + else if (x > 0.1202552504837513f) // 100 + return 0b1001; + else + return 0b1000; + else if (x > -0.33967943489551544f) // 0 + if (x > -0.13791173323988914f) // 01 + if (x > -0.045525018125772476f) // 011 + return 0b0111; + else + return 0b0110; + else if (x > -0.23460740596055984f) // 010 + return 0b0101; + else + return 0b0100; + else if (x > -0.6106329262256622f) // 00 + if (x > -0.4599952697753906f) // 001 + return 0b0011; + else + return 0b0010; + else if (x > -0.8480964004993439f) // 000 + return 0b0001; + else + return 0b0000; +} diff --git a/src/core/tests/element_type.cpp b/src/core/tests/element_type.cpp index 7be265534198d9..d0d416e3fd5d17 100644 --- a/src/core/tests/element_type.cpp +++ b/src/core/tests/element_type.cpp @@ -64,6 +64,8 @@ TEST(element_type, from_string) { EXPECT_EQ(element::Type("U32"), element::u32); EXPECT_EQ(element::Type("u64"), element::u64); EXPECT_EQ(element::Type("U64"), element::u64); + EXPECT_EQ(element::Type("nf4"), element::nf4); + EXPECT_EQ(element::Type("NF4"), element::nf4); EXPECT_EQ(element::Type("undefined"), element::undefined); EXPECT_EQ(element::Type("UNSPECIFIED"), element::undefined); diff --git a/src/core/tests/nf4.cpp b/src/core/tests/nf4.cpp new file mode 100644 index 00000000000000..6975d3fba42be7 --- /dev/null +++ b/src/core/tests/nf4.cpp @@ -0,0 +1,96 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/core/type/nf4.hpp" + +#include "common_test_utils/test_tools.hpp" +#include "gtest/gtest.h" +#include "openvino/op/constant.hpp" + +using namespace std; + +TEST(nf4, convert_nf4_to_string) { + vector values{186, 17}; + auto constant = make_shared(ov::element::nf4, ov::Shape{3}, &values[0]); + + vector ref{"10", "11", "1"}; + for (size_t i = 0; i < 3; ++i) { + ASSERT_EQ(constant->convert_value_to_string(i), ref[i]); + } +} + +TEST(nf4, tensor_or_constant_size) { + vector values{171, 16}; + auto constant = make_shared(ov::element::nf4, ov::Shape{3}, &values[0]); + EXPECT_EQ(2, constant->get_byte_size()); + + ov::Tensor runtime_tensor(ov::element::nf4, ov::Shape{3}); + EXPECT_EQ(constant->get_byte_size(), runtime_tensor.get_byte_size()); +} + +template +void test_nf4_convert() { + vector const_data_f{-1.5f, -1.425f, -1.35f, -1.275f, -1.2f, -1.125f, -1.05f, -0.975f, -0.9f, + -0.825f, -0.75f, -0.675f, -0.6f, -0.525f, -0.45f, -0.375f, -0.3f, -0.225f, + -0.15f, -0.075f, 0.0f, 0.075f, 0.15f, 0.225f, 0.3f, 0.375f, 0.45f, + 0.525f, 0.6f, 0.675f, 0.75f, 0.825f, 0.9f, 0.975f, 1.05f, 1.125f, + 1.2f, 1.275f, 1.35f, 1.425f, 1.5}; + + vector target_f{-1.0f, + -0.6961928009986877f, + -0.5250730514526367f, + -0.39491748809814453f, + -0.28444138169288635f, + -0.18477343022823334f, + -0.09105003625154495f, + 0.0f, + 0.07958029955625534f, + 0.16093020141124725f, + 0.24611230194568634f, + 0.33791524171829224f, + 0.44070982933044434f, + 0.5626170039176941f, + 0.7229568362236023f, + 1.0f}; + + vector const_data; + const_data.reserve(const_data_f.size()); + for (auto& val : const_data_f) { + const_data.push_back(static_cast(val)); + } + vector target; + target.reserve(target_f.size()); + for (auto& val : target_f) { + target.push_back(static_cast(val)); + } + + auto constant = ov::op::v0::Constant::create(ov::element::nf4, ov::Shape{const_data.size()}, const_data); + + const uint8_t* p = static_cast(constant->get_data_ptr()); + EXPECT_NE(p, nullptr); + std::vector packed_data(p, p + const_data.size() / 2 + const_data.size() % 2); + + std::vector decompressed_data(const_data.size(), 0); + for (size_t i = 0; i < const_data.size(); i++) { + ov::ConvertNF4::unpack(&decompressed_data[0], &packed_data[0], i); + } + + auto it = std::unique(decompressed_data.begin(), decompressed_data.end()); + decompressed_data.resize(std::distance(decompressed_data.begin(), it)); + + EXPECT_EQ(16, decompressed_data.size()); + + float max_diff = 0.0; + for (size_t i = 0; i < 16; i++) { + float diff = fabs(static_cast(decompressed_data[i] - target[i])); + max_diff = std::max(max_diff, diff); + } + EXPECT_LE(max_diff, 0.001); +} + +TEST(nf4, convert_float) { + test_nf4_convert(); + test_nf4_convert(); + test_nf4_convert(); +} diff --git a/src/plugins/template/backend/ops/convert.cpp b/src/plugins/template/backend/ops/convert.cpp index 71f6f3cc87a152..4563e0081fd4bb 100644 --- a/src/plugins/template/backend/ops/convert.cpp +++ b/src/plugins/template/backend/ops/convert.cpp @@ -16,8 +16,10 @@ inline void evaluate(const std::shared_ptr& op, outputs[0].set_shape(inputs[0].get_shape()); size_t element_count = ov::shape_size(outputs[0].get_shape()); - if (((ti == ov::element::u1) || (to == ov::element::u1)) || ((ti == ov::element::u4) || (to == ov::element::u4)) || - ((ti == ov::element::i4) || (to == ov::element::i4))) { + if (((ti == ngraph::element::u1) || (to == ngraph::element::u1)) || + ((ti == ngraph::element::u4) || (to == ngraph::element::u4)) || + ((ti == ngraph::element::i4) || (to == ngraph::element::i4)) || + ((ti == ngraph::element::nf4) || (to == ngraph::element::nf4))) { ov::reference::detail::lp_convert(inputs[0].data(), outputs[0].data(), element_count, ti, to); } else { ov::reference::convert(inputs[0].data(), outputs[0].data(), element_count); diff --git a/src/tests/test_utils/common_test_utils/src/ov_tensor_utils.cpp b/src/tests/test_utils/common_test_utils/src/ov_tensor_utils.cpp index f455b49abdcb04..f559e8f945274e 100644 --- a/src/tests/test_utils/common_test_utils/src/ov_tensor_utils.cpp +++ b/src/tests/test_utils/common_test_utils/src/ov_tensor_utils.cpp @@ -44,6 +44,7 @@ ov::Tensor create_and_fill_tensor(const ov::element::Type element_type, case ov::element::Type_t::u1: case ov::element::Type_t::i4: case ov::element::Type_t::u4: + case ov::element::Type_t::nf4: fill_data_random(static_cast(tensor.data()), tensor.get_byte_size(), range, diff --git a/thirdparty/itt_collector/sea_itt_lib/IttNotifyStdSrc.cpp b/thirdparty/itt_collector/sea_itt_lib/IttNotifyStdSrc.cpp index 91da5e7f3f4b9c..ee2daf88d79ece 100644 --- a/thirdparty/itt_collector/sea_itt_lib/IttNotifyStdSrc.cpp +++ b/thirdparty/itt_collector/sea_itt_lib/IttNotifyStdSrc.cpp @@ -99,7 +99,7 @@ inline bool operator==(const __itt_id& left, const __itt_id& right) { namespace sea { -uint64_t g_nRingBuffer = 1000000000ll * atoi(get_environ_value("INTEL_SEA_RING").c_str()); // in nanoseconds +uint64_t g_nRingBuffer = 1000000000ll * atoi(get_environ_value("INTEL_SEA_RING").c_str()); // in nanoseconds uint64_t g_nAutoCut = 1024ull * 1024 * atoi(get_environ_value("INTEL_SEA_AUTOCUT").c_str()); // in MB uint64_t g_features = sea::GetFeatureSet(); From 84d98d8bf70cbb4bae763329e70fddf582189bd7 Mon Sep 17 00:00:00 2001 From: Maxim Vafin Date: Thu, 28 Sep 2023 19:09:54 +0200 Subject: [PATCH 23/35] [PT FE] Add support for aten::pixel_shuffle (#20124) * [PT FE] Add support for aten::pixel_shuffle * Add comments * Update src/frontends/pytorch/src/op/pixel_shuffle.cpp --- .../pytorch/src/op/pixel_shuffle.cpp | 73 +++++++++++++++++++ src/frontends/pytorch/src/op_table.cpp | 2 + .../pytorch_tests/test_pixel_shuffle.py | 35 +++++++++ 3 files changed, 110 insertions(+) create mode 100644 src/frontends/pytorch/src/op/pixel_shuffle.cpp create mode 100644 tests/layer_tests/pytorch_tests/test_pixel_shuffle.py diff --git a/src/frontends/pytorch/src/op/pixel_shuffle.cpp b/src/frontends/pytorch/src/op/pixel_shuffle.cpp new file mode 100644 index 00000000000000..e2d3e8c6390c55 --- /dev/null +++ b/src/frontends/pytorch/src/op/pixel_shuffle.cpp @@ -0,0 +1,73 @@ +// 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/concat.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/shape_of.hpp" +#include "openvino/op/slice.hpp" +#include "openvino/op/split.hpp" +#include "openvino/op/squeeze.hpp" +#include "openvino/op/transpose.hpp" +#include "utils.hpp" + +namespace ov { +namespace frontend { +namespace pytorch { +namespace op { + +using namespace ov::op; + +OutputVector translate_pixel_shuffle(const NodeContext& context) { + // aten::pixel_shuffle(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, r, r, H, W], 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 upscale_factor_1d = context.mark_node(std::make_shared(upscale_factor, neg_1, false)); + auto intermediate_shape = context.mark_node( + std::make_shared(OutputVector{dims_before, neg_1, upscale_factor_1d, upscale_factor_1d, h, w}, 0)); + auto reshape = context.mark_node(std::make_shared(x, intermediate_shape, false)); + // 2. Transpose tensor to [*, C, r, H, r, W] + auto dims_before_len = context.mark_node(std::make_shared(dims_before, element::i32)); + auto dims_before_len_s = context.mark_node(std::make_shared(dims_before_len, zero)); + auto order_begin = context.mark_node(std::make_shared(zero_s, dims_before_len_s, one_s, element::i32)); + auto order_end_neg = context.mark_node( + v0::Constant::create(element::i32, Shape{5}, {-3, 0, -2, 1, -1})); // +2 because rank is expanded + auto order_end = context.mark_node(std::make_shared(order_end_neg, rank)); + auto order = context.mark_node(std::make_shared(OutputVector{order_begin, order_end}, 0)); + auto transpose = context.mark_node(std::make_shared(reshape, order)); + // 3. Reshape to [*, -1, r * H, r * W] + auto new_h = context.mark_node(std::make_shared(h, upscale_factor)); + auto new_w = context.mark_node(std::make_shared(w, upscale_factor)); + auto shape_after = + context.mark_node(std::make_shared(OutputVector{dims_before, neg_1, new_h, new_w}, 0)); + return {context.mark_node(std::make_shared(transpose, shape_after, false))}; +}; + +} // namespace op +} // namespace pytorch +} // namespace frontend +} // namespace ov \ No newline at end of file diff --git a/src/frontends/pytorch/src/op_table.cpp b/src/frontends/pytorch/src/op_table.cpp index 0bc6d77b3fc707..5d85bf05dcab79 100644 --- a/src/frontends/pytorch/src/op_table.cpp +++ b/src/frontends/pytorch/src/op_table.cpp @@ -120,6 +120,7 @@ OP_CONVERTER(translate_or); OP_CONVERTER(translate_outer); OP_CONVERTER(translate_pad); OP_CONVERTER(translate_pairwise_distance); +OP_CONVERTER(translate_pixel_shuffle); OP_CONVERTER(translate_pow); OP_CONVERTER(translate_pythonop); OP_CONVERTER(translate_quantize_per_channel); @@ -390,6 +391,7 @@ const std::map get_supported_ops_ts() { {"aten::pad", op::translate_pad}, {"aten::pairwise_distance", op::translate_pairwise_distance}, {"aten::permute", op::translate_1to1_match_2_inputs}, + {"aten::pixel_shuffle", op::translate_pixel_shuffle}, {"aten::prelu", op::translate_1to1_match_2_inputs}, {"aten::pow", op::translate_pow}, {"aten::quantize_per_channel", op::translate_quantize_per_channel}, diff --git a/tests/layer_tests/pytorch_tests/test_pixel_shuffle.py b/tests/layer_tests/pytorch_tests/test_pixel_shuffle.py new file mode 100644 index 00000000000000..8b71c9f55cc824 --- /dev/null +++ b/tests/layer_tests/pytorch_tests/test_pixel_shuffle.py @@ -0,0 +1,35 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np +import pytest + +from pytorch_layer_test_class import PytorchLayerTest + + +class TestOneHot(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_one_hot(torch.nn.Module): + def __init__(self, upscale_factor): + super(aten_one_hot, 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" + + @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): + self.shape = shape + self._test(*self.create_model(upscale_factor), + ie_device, precision, ir_version) From f85a276782827fbeedd1a8a53217a4fe3e96bfff Mon Sep 17 00:00:00 2001 From: Mikhail Ryzhov Date: Thu, 28 Sep 2023 21:21:32 +0300 Subject: [PATCH 24/35] [GHA] Azure pip cache (#20029) * switched PyTorch_Models * fixed root issue * upgrade pip * set bash environments * install pip deps * added git installation * added g++ deps * added python-dev package * get particular python-dev package * fixed package name * removed python-dev * cython dep * debug * fixed inlude path * test cache * set home dir * changed disk space calculation * crosspipeline pip cache * added tag for source builded deps * immutable deps * use commit id instead of tag * Update .github/workflows/linux.yml Co-authored-by: Ilya Lavrenov * fixed logs upload condition * removed pip upgrade * changed detectotron version * Update tests/model_hub_tests/torch_tests/requirements_secondary.txt Co-authored-by: Ilya Lavrenov * changed wheel installation way * reset onednn * added cleanup workload * cleanup test * fixed reqs install * test cache depending on pip version * syntax fix * env overwriting test * test env output * fixed set env step * move pip cahc initialization to step * changed pip ver regexp * set custom pip cahce for each step * cleanup code and enabled test cleanup job * test cleanup 2 * speedup removal * check existed dir * Enabled cache for samples job * removed debug job * changed way how to get pip ver * improved pip version extration * revert omz * switched PyTorch_Models * fixed root issue * upgrade pip * set bash environments * install pip deps * added git installation * added g++ deps * added python-dev package * get particular python-dev package * fixed package name * removed python-dev * cython dep * debug * fixed inlude path * test cache * set home dir * changed disk space calculation * crosspipeline pip cache * added tag for source builded deps * immutable deps * use commit id instead of tag * Update .github/workflows/linux.yml Co-authored-by: Ilya Lavrenov * fixed logs upload condition * removed pip upgrade * changed detectotron version * Update tests/model_hub_tests/torch_tests/requirements_secondary.txt Co-authored-by: Ilya Lavrenov * changed wheel installation way * added cleanup workload * reset onednn * cleanup test * fixed reqs install * test cache depending on pip version * syntax fix * env overwriting test * test env output * fixed set env step * move pip cahc initialization to step * changed pip ver regexp * set custom pip cahce for each step * cleanup code and enabled test cleanup job * test cleanup 2 * speedup removal * check existed dir * Enabled cache for samples job * removed debug job * changed way how to get pip ver * improved pip version extration * revert omz * review fixes * remove cache files using atime * mtime->atime --------- Co-authored-by: Ilya Lavrenov --- .github/workflows/cleanup_pip_cache.yml | 31 +++++ .github/workflows/linux.yml | 119 ++++++++++++------ .../torch_tests/requirements_secondary.txt | 3 +- 3 files changed, 111 insertions(+), 42 deletions(-) create mode 100644 .github/workflows/cleanup_pip_cache.yml diff --git a/.github/workflows/cleanup_pip_cache.yml b/.github/workflows/cleanup_pip_cache.yml new file mode 100644 index 00000000000000..eaf8d0ec743f5a --- /dev/null +++ b/.github/workflows/cleanup_pip_cache.yml @@ -0,0 +1,31 @@ +name: Cleanup PIP caches +on: + schedule: + # at 00:00 on the 1st day of every month + - cron: '0 0 1 * *' + +jobs: + Cleanup_PIP_Caches: + runs-on: aks-linux-2-cores + container: + image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 + volumes: + - /mount/caches:/mount/caches + env: + PIP_CACHE_PATH: /mount/caches/pip + + steps: + - name: Pre-Collecting Cache Info + run: | + echo "Cache info: " + du -h -d2 ${PIP_CACHE_PATH} + + - name: Cleanup cache + run: | + echo "Delete cache files if they have not been used in over 30 days" + [ ! -z "${PIP_CACHE_PATH}" ] && find ${PIP_CACHE_PATH} ! -type d -atime +30 -delete + + - name: Post-Collecting Cache Info + run: | + echo "Cache info: " + du -h -d2 ${PIP_CACHE_PATH} diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index f767503a0a24c8..050d4c81ed133f 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -29,6 +29,10 @@ concurrency: group: ${{ github.event_name == 'push' && github.run_id || github.ref }}-linux cancel-in-progress: true +env: + PIP_CACHE_PATH: /mount/caches/pip/linux + PYTHON_VERSION: '3.11' + jobs: Build: defaults: @@ -55,6 +59,7 @@ jobs: CCACHE_DIR: /mount/caches/ccache/ubuntu20_x86_64_Release CCACHE_TEMPDIR: /__w/openvino/openvino/ccache_temp CCACHE_MAXSIZE: 50G + steps: - name: Install git run: | @@ -92,7 +97,12 @@ jobs: - uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: ${{ env.PYTHON_VERSION }} + - name: Setup pip cache dir + run: | + PIP_VER=$(python3 -c "import pip; print(pip.__version__)") + echo "Using pip version: ${PIP_VER}" + echo "PIP_CACHE_DIR=${PIP_CACHE_PATH}/${PIP_VER}" >> $GITHUB_ENV - name: Install python dependencies run: | @@ -116,9 +126,8 @@ jobs: # Build # - - name: Setup ccache - run: | - mkdir -p $CCACHE_DIR + - name: Setup ccache dir + run: mkdir -p ${CCACHE_DIR} - name: CMake configure - OpenVINO run: | @@ -321,7 +330,12 @@ jobs: - uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: ${{ env.PYTHON_VERSION }} + - name: Setup pip cache dir + run: | + PIP_VER=$(python3 -c "import pip; print(pip.__version__)") + echo "Using pip version: ${PIP_VER}" + echo "PIP_CACHE_DIR=${PIP_CACHE_PATH}/${PIP_VER}" >> $GITHUB_ENV - name: Install OpenVINO dependencies run: ${INSTALL_DIR}/install_dependencies/install_openvino_dependencies.sh -c=core -c=dev -y @@ -367,7 +381,7 @@ jobs: - name: Upload Test Results uses: actions/upload-artifact@v3 - if: ${{ always() }} + if: ${{ !cancelled() }} with: name: test-results-cpp path: ${{ env.INSTALL_TEST_DIR }}/TEST*.xml @@ -560,7 +574,7 @@ jobs: - name: Upload Test Results uses: actions/upload-artifact@v3 - if: ${{ always() }} + if: ${{ !cancelled() }} with: name: test-results-cpp path: ${{ env.INSTALL_TEST_DIR }}/TEST*.xml @@ -574,6 +588,8 @@ jobs: runs-on: aks-linux-4-cores container: image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 + volumes: + - /mount/caches:/mount/caches env: OPENVINO_REPO: /__w/openvino/openvino/openvino INSTALL_DIR: /__w/openvino/openvino/install @@ -600,7 +616,12 @@ jobs: - uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: ${{ env.PYTHON_VERSION }} + - name: Setup pip cache dir + run: | + PIP_VER=$(python3 -c "import pip; print(pip.__version__)") + echo "Using pip version: ${PIP_VER}" + echo "PIP_CACHE_DIR=${PIP_CACHE_PATH}/${PIP_VER}" >> $GITHUB_ENV - name: Install Python API tests dependencies run: | @@ -774,7 +795,7 @@ jobs: - name: Upload Test Results uses: actions/upload-artifact@v3 - if: ${{ always() }} + if: ${{ !cancelled() }} with: name: test-results-python path: | @@ -829,7 +850,7 @@ jobs: - uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: ${{ env.PYTHON_VERSION }} - name: Install python dependencies for run_parallel.py run: python3 -m pip install -r ${INSTALL_TEST_DIR}/functional_test_utils/requirements.txt @@ -857,7 +878,7 @@ jobs: - name: Upload Test Results uses: actions/upload-artifact@v3 - if: ${{ always() }} + if: ${{ !cancelled() }} with: name: test-results-functional-cpu path: | @@ -893,7 +914,12 @@ jobs: - uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: ${{ env.PYTHON_VERSION }} + - name: Setup pip cache dir + run: | + PIP_VER=$(python3 -c "import pip; print(pip.__version__)") + echo "Using pip version: ${PIP_VER}" + echo "PIP_CACHE_DIR=${PIP_CACHE_PATH}/${PIP_VER}" >> $GITHUB_ENV - name: Download OpenVINO package uses: actions/download-artifact@v3 @@ -934,7 +960,7 @@ jobs: - name: Upload Test Results uses: actions/upload-artifact@v3 - if: ${{ always() }} + if: ${{ !cancelled() }} with: name: test-results-tensorflow-hub-models path: | @@ -946,27 +972,30 @@ jobs: defaults: run: shell: bash - runs-on: ${{ github.event_name == 'schedule' && 'ubuntu-20.04-8-cores' || 'ubuntu-20.04'}} + runs-on: ${{ github.event_name == 'schedule' && 'aks-linux-16-cores' || 'aks-linux-8-cores'}} + container: + image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 + volumes: + - /mount/caches:/mount/caches env: INSTALL_DIR: ${{ github.workspace }}/install INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests MODEL_HUB_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/model_hub_tests steps: - - name: Maximize build space - run: | - sudo rm -rf /usr/local/lib/android # will release about 10 GB if you don't need Android - sudo rm -rf /usr/share/dotnet # will release about 20GB if you don't need .NET - sudo rm -rf /opt/ghc - echo "Available storage:" - df -h + - name: Check sudo + run: if [ "$(id -u)" -eq 0 ]; then apt update && apt --assume-yes install sudo; fi - - name: Create Directories - run: mkdir -p ${{ env.INSTALL_DIR }} ${{ env.INSTALL_TEST_DIR }} + - name: Install dependencies + run: | + # libssl1.1 - 'python3 -m pip' in self-hosted runner + sudo apt install --assume-yes --no-install-recommends libssl1.1 + # install git (required to build pip deps from the sources) + # install 'g++' to build 'detectron2' and 'natten' wheels + sudo apt-get install --assume-yes --no-install-recommends g++ git ca-certificates - - uses: actions/setup-python@v4 - with: - python-version: '3.11' + - name: Create Directories + run: mkdir -p ${INSTALL_DIR} ${INSTALL_TEST_DIR} - name: Download OpenVINO package uses: actions/download-artifact@v3 @@ -982,29 +1011,38 @@ jobs: - 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 + pushd ${INSTALL_DIR} + tar -xzf openvino_package.tar.gz -C ${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 + pushd ${INSTALL_TEST_DIR} + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} && rm openvino_tests.tar.gz || exit 1 popd - - name: Install Python wheels + + - uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + - name: Setup pip cache dir run: | - python3 -m pip install openvino --find-links=${{ env.INSTALL_DIR }}/tools + PIP_VER=$(python3 -c "import pip; print(pip.__version__)") + echo "Using pip version: ${PIP_VER}" + echo "PIP_CACHE_DIR=${PIP_CACHE_PATH}/${PIP_VER}" >> $GITHUB_ENV + + - name: Install OpenVINO Python wheels + run: python3 -m pip install ${INSTALL_DIR}/tools/openvino-* - name: Install PyTorch tests requirements run: | - python3 -m pip install -r ${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}/torch_tests/requirements.txt - python3 -m pip install -r ${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}/torch_tests/requirements_secondary.txt - python3 -m pip cache purge + python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/torch_tests/requirements.txt + python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/torch_tests/requirements_secondary.txt echo "Available storage:" df -h - du -h -d0 ~/.cache ~/* + env: + CPLUS_INCLUDE_PATH: ${{ env.Python_ROOT_DIR }}/include/python${{ env.PYTHON_VERSION }} - name: PyTorch Models Tests run: | - export PYTHONPATH=${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}:$PYTHONPATH - python3 -m pytest ${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}/torch_tests/ -m ${{ env.TYPE }} --html=${{ env.INSTALL_TEST_DIR }}/TEST-torch_model_tests.html --self-contained-html -v + export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH + python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/torch_tests/ -m ${TYPE} --html=${INSTALL_TEST_DIR}/TEST-torch_model_tests.html --self-contained-html -v env: TYPE: ${{ github.event_name == 'schedule' && 'nightly' || 'precommit'}} TEST_DEVICE: CPU @@ -1013,13 +1051,12 @@ jobs: run: | echo "Available storage:" df -h - du -h -d0 ~/.cache ~/* - name: Upload Test Results uses: actions/upload-artifact@v3 - if: ${{ always() }} + if: ${{ !cancelled() }} with: name: test-results-torch-models path: | ${{ env.INSTALL_TEST_DIR }}/TEST*.html - if-no-files-found: 'error' + if-no-files-found: 'error' \ No newline at end of file diff --git a/tests/model_hub_tests/torch_tests/requirements_secondary.txt b/tests/model_hub_tests/torch_tests/requirements_secondary.txt index f37ba0e81008ae..803c3c4b839006 100644 --- a/tests/model_hub_tests/torch_tests/requirements_secondary.txt +++ b/tests/model_hub_tests/torch_tests/requirements_secondary.txt @@ -1,4 +1,5 @@ -c ../../constraints.txt # This file contains requirements dependednt from modules in requirements.txt -git+https://github.com/facebookresearch/detectron2.git +# get immutable commit to be able to use pip cache +git+https://github.com/facebookresearch/detectron2.git@1a4df4d954089534daebbd7a0a45f08ece87056e natten From 64cc3a96bb520d8c3c2057a16f01c39c1448b68c Mon Sep 17 00:00:00 2001 From: Maxim Vafin Date: Thu, 28 Sep 2023 21:11:41 +0200 Subject: [PATCH 25/35] Restrict version of pytorch-quantization (#20137) --- tests/model_hub_tests/torch_tests/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/model_hub_tests/torch_tests/requirements.txt b/tests/model_hub_tests/torch_tests/requirements.txt index 181786db4a4528..f0a013faadbcc3 100644 --- a/tests/model_hub_tests/torch_tests/requirements.txt +++ b/tests/model_hub_tests/torch_tests/requirements.txt @@ -11,7 +11,7 @@ sacremoses sentencepiece datasets pyctcdecode -pytorch-quantization --extra-index-url https://pypi.ngc.nvidia.com +pytorch-quantization<=2.1.3 --extra-index-url https://pypi.ngc.nvidia.com protobuf soundfile pandas From f38b5f4f061bc2ab0a603e52fdabb449fa213fde Mon Sep 17 00:00:00 2001 From: Maxim Vafin Date: Thu, 28 Sep 2023 23:11:09 +0200 Subject: [PATCH 26/35] [PT FE] Support moving TupleConstruct inside If body (#20081) * Support moving TupleConstruct inside If body * Fix win build --------- Co-authored-by: Alina Kladieva --- src/frontends/pytorch/src/frontend.cpp | 1 + .../pytorch/src/pt_framework_node.hpp | 4 +- .../src/transforms/tuple_unpack_replacer.cpp | 142 ++++++++++++++++++ .../src/transforms/tuple_unpack_replacer.hpp | 6 + .../pytorch_tests/test_tuple_construct.py | 30 +++- 5 files changed, 180 insertions(+), 3 deletions(-) diff --git a/src/frontends/pytorch/src/frontend.cpp b/src/frontends/pytorch/src/frontend.cpp index decab9e6df1e15..0910aa3e057e72 100644 --- a/src/frontends/pytorch/src/frontend.cpp +++ b/src/frontends/pytorch/src/frontend.cpp @@ -178,6 +178,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/pytorch/src/pt_framework_node.hpp b/src/frontends/pytorch/src/pt_framework_node.hpp index 9dc78c0f0ae59b..04b71d1169ae81 100644 --- a/src/frontends/pytorch/src/pt_framework_node.hpp +++ b/src/frontends/pytorch/src/pt_framework_node.hpp @@ -75,8 +75,8 @@ class PtFrameworkNode : public ov::op::util::FrameworkNode { return m_decoder->get_op_type(); } - TorchDecoder* get_decoder() const { - return m_decoder.get(); + std::shared_ptr get_decoder() const { + return m_decoder; } private: diff --git a/src/frontends/pytorch/src/transforms/tuple_unpack_replacer.cpp b/src/frontends/pytorch/src/transforms/tuple_unpack_replacer.cpp index ae1c1aa3379d84..9352d148e823f7 100644 --- a/src/frontends/pytorch/src/transforms/tuple_unpack_replacer.cpp +++ b/src/frontends/pytorch/src/transforms/tuple_unpack_replacer.cpp @@ -4,9 +4,11 @@ #include "tuple_unpack_replacer.hpp" +#include "openvino/op/if.hpp" #include "openvino/op/util/framework_node.hpp" #include "openvino/pass/pattern/matcher.hpp" #include "openvino/pass/pattern/op/wrap_type.hpp" +#include "pt_framework_node.hpp" #include "utils.hpp" namespace ov { @@ -14,6 +16,8 @@ namespace frontend { namespace pytorch { namespace pass { +using namespace ov::op; + PrimTupleUnpackReplacer::PrimTupleUnpackReplacer() { auto tuple_unpack = ov::pass::pattern::wrap_type(); @@ -41,6 +45,144 @@ PrimTupleUnpackReplacer::PrimTupleUnpackReplacer() { this->register_matcher(m, callback); }; +bool TupleUnpackInBodyReplacer::run_on_model(const std::shared_ptr& model) { + bool result = false; + for (auto op : model->get_ordered_ops()) { + const auto if_op = as_type_ptr(op); + if (if_op) { + for (size_t i = 1; i < if_op->get_input_size(); i++) { + auto input = if_op->input_value(i); + auto tuple_construct = std::dynamic_pointer_cast( + cast_fw_node(input.get_node_shared_ptr(), "prim::TupleConstruct")); + if (!tuple_construct) { + continue; + } + int then_body_idx = -1; + int else_body_idx = -1; + auto then_descs = if_op->get_input_descriptions(v8::If::THEN_BODY_INDEX); + auto else_descs = if_op->get_input_descriptions(v8::If::ELSE_BODY_INDEX); + for (auto inp_desc : then_descs) { + if (inp_desc->m_input_index == i) { + if (then_body_idx != -1) { + add_exception_to_fw_node( + tuple_construct, + "Unexpected: TupleConstruct output is used in body more then once."); + } else { + then_body_idx = static_cast(inp_desc->m_body_parameter_index); + } + } + } + for (auto inp_desc : else_descs) { + if (inp_desc->m_input_index == i) { + if (else_body_idx != -1) { + add_exception_to_fw_node( + tuple_construct, + "Unexpected: TupleConstruct output is used in body more then once."); + } else { + else_body_idx = static_cast(inp_desc->m_body_parameter_index); + } + } + } + auto new_if = std::make_shared(if_op->input_value(0)); + auto then_body = if_op->get_function(v8::If::THEN_BODY_INDEX); + auto else_body = if_op->get_function(v8::If::ELSE_BODY_INDEX); + ov::ParameterVector new_then_params; + ov::ParameterVector new_else_params; + if (then_body_idx != -1) { + auto then_param = then_body->get_parameters().at(then_body_idx); + ov::OutputVector new_tc_inputs; + for (size_t i = 0; i < tuple_construct->get_input_size(); i++) { + auto new_param = std::make_shared(element::dynamic, PartialShape::dynamic()); + new_then_params.push_back(new_param); + new_tc_inputs.push_back(new_param); + } + auto new_tc = + std::make_shared(tuple_construct->get_decoder(), + new_tc_inputs, + 1); + then_body->add_parameters(new_then_params); + then_body->remove_parameter(then_param); + then_param->output(0).replace(new_tc->output(0)); + } + if (else_body_idx != -1) { + auto else_param = else_body->get_parameters().at(else_body_idx); + ov::OutputVector new_tc_inputs; + for (size_t i = 0; i < tuple_construct->get_input_size(); i++) { + auto new_param = std::make_shared(element::dynamic, PartialShape::dynamic()); + new_else_params.push_back(new_param); + new_tc_inputs.push_back(new_param); + } + auto new_tc = + std::make_shared(tuple_construct->get_decoder(), + new_tc_inputs, + 1); + else_body->add_parameters(new_else_params); + else_body->remove_parameter(else_param); + else_param->output(0).replace(new_tc->output(0)); + } + new_if->set_function(v8::If::THEN_BODY_INDEX, then_body); + new_if->set_function(v8::If::ELSE_BODY_INDEX, else_body); + new_if->set_output_size(if_op->get_output_size()); + new_if->set_output_descriptions(v8::If::THEN_BODY_INDEX, + if_op->get_output_descriptions(v8::If::THEN_BODY_INDEX)); + new_if->set_output_descriptions(v8::If::ELSE_BODY_INDEX, + if_op->get_output_descriptions(v8::If::ELSE_BODY_INDEX)); + + // create new If inputs + std::vector> inputs_mapping(if_op->get_input_size(), {-1, -1}); + for (auto inp_desc : then_descs) { + inputs_mapping[inp_desc->m_input_index].first = static_cast(inp_desc->m_body_parameter_index); + } + for (auto inp_desc : else_descs) { + inputs_mapping[inp_desc->m_input_index].second = static_cast(inp_desc->m_body_parameter_index); + } + for (size_t j = 0; j < inputs_mapping.size(); j++) { + if (j == i) + continue; + int then_p_idx = inputs_mapping[j].first; + if (then_p_idx > then_body_idx && then_body_idx != -1) + then_p_idx--; + int else_p_idx = inputs_mapping[j].second; + if (else_p_idx > else_body_idx && else_body_idx != -1) + else_p_idx--; + auto then_p = then_p_idx == -1 ? nullptr : then_body->get_parameters()[then_p_idx]; + auto else_p = else_p_idx == -1 ? nullptr : else_body->get_parameters()[else_p_idx]; + if (then_p || else_p) + new_if->set_invariant_inputs(if_op->input_value(j), {then_p, else_p}); + } + for (size_t j = 0; j < tuple_construct->get_input_size(); j++) { + ParameterVector body_inps; + if (then_body_idx != -1) { + FRONT_END_GENERAL_CHECK(j < new_then_params.size(), "Unexpected number of Parameters."); + body_inps.push_back(new_then_params[j]); + } else { + body_inps.push_back(nullptr); + } + if (else_body_idx != -1) { + FRONT_END_GENERAL_CHECK(j < new_else_params.size(), "Unexpected number of Parameters."); + body_inps.push_back(new_else_params[j]); + } else { + body_inps.push_back(nullptr); + } + new_if->set_invariant_inputs(tuple_construct->input_value(j), body_inps); + } + new_if->set_friendly_name(if_op->get_friendly_name()); + replace_node(if_op, new_if); + new_if->validate_and_infer_types(); + op = std::dynamic_pointer_cast(new_if); + result = true; + break; + } + } + if (const auto multiSubGraph = ov::as_type_ptr(op)) { + for (size_t i = 0; i < multiSubGraph->get_internal_subgraphs_size(); i++) + result = result || run_on_model(multiSubGraph->get_function(i)); + } + } + + return result; +}; + } // namespace pass } // namespace pytorch } // namespace frontend diff --git a/src/frontends/pytorch/src/transforms/tuple_unpack_replacer.hpp b/src/frontends/pytorch/src/transforms/tuple_unpack_replacer.hpp index 012c8e8c05ff0e..81aae1eefaf4d6 100644 --- a/src/frontends/pytorch/src/transforms/tuple_unpack_replacer.hpp +++ b/src/frontends/pytorch/src/transforms/tuple_unpack_replacer.hpp @@ -18,6 +18,12 @@ class PrimTupleUnpackReplacer : public ov::pass::MatcherPass { PrimTupleUnpackReplacer(); }; +class TupleUnpackInBodyReplacer : public ov::pass::ModelPass { +public: + OPENVINO_RTTI("ov::frontend::pytorch::pass::TupleUnpackInBodyReplacer"); + bool run_on_model(const std::shared_ptr& model) override; +}; + } // namespace pass } // namespace pytorch } // namespace frontend diff --git a/tests/layer_tests/pytorch_tests/test_tuple_construct.py b/tests/layer_tests/pytorch_tests/test_tuple_construct.py index b4f48354dcfdb6..1582df48c4b370 100644 --- a/tests/layer_tests/pytorch_tests/test_tuple_construct.py +++ b/tests/layer_tests/pytorch_tests/test_tuple_construct.py @@ -198,7 +198,7 @@ def create_model(self): class model(torch.nn.Module): def forward(self, x): - return self.some_func((x,x)) + return self.some_func((x, x)) def some_func(self, x: Tuple[torch.Tensor, torch.Tensor]): return x[1] * 2, x[0] * 3 @@ -209,3 +209,31 @@ def some_func(self, x: Tuple[torch.Tensor, torch.Tensor]): def test(self, ie_device, precision, ir_version): self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=False, freeze_model=False) + + +class TestTcOutsideTuInsideIfBody(PytorchLayerTest): + def _prepare_input(self): + return (np.random.randn(1, 2, 10).astype(np.float32), np.random.randn(1, 2, 10).astype(np.float32)) + + def create_model(self): + import torch + from typing import Tuple + + class model(torch.nn.Module): + def forward(self, x, y): + return self.some_func((x, y)) + + def some_func(self, x: Tuple[torch.Tensor, torch.Tensor]): + if x[0].numel() > 10: + n, m = x + return n * m + else: + n, m = x + return n - m + + return model(), None, ["prim::TupleConstruct", "prim::TupleUnpack", "prim::If"] + + @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) From 932179252f58b860543ddbe1d61fad4c75acccf1 Mon Sep 17 00:00:00 2001 From: Maciej Smyk Date: Fri, 29 Sep 2023 10:02:10 +0200 Subject: [PATCH 27/35] get started & install configurations (#20128) --- .../get started}/configurations-header.md | 0 .../configurations-header}/configurations-for-intel-gna.md | 0 .../configurations-header}/configurations-for-intel-gpu.md | 0 .../configurations-header}/configurations-for-intel-npu.md | 0 docs/{ => articles_en}/get_started.md | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename docs/{install_guides => articles_en/get started}/configurations-header.md (100%) rename docs/{install_guides => articles_en/get started/configurations-header}/configurations-for-intel-gna.md (100%) rename docs/{install_guides => articles_en/get started/configurations-header}/configurations-for-intel-gpu.md (100%) rename docs/{install_guides => articles_en/get started/configurations-header}/configurations-for-intel-npu.md (100%) rename docs/{ => articles_en}/get_started.md (100%) diff --git a/docs/install_guides/configurations-header.md b/docs/articles_en/get started/configurations-header.md similarity index 100% rename from docs/install_guides/configurations-header.md rename to docs/articles_en/get started/configurations-header.md diff --git a/docs/install_guides/configurations-for-intel-gna.md b/docs/articles_en/get started/configurations-header/configurations-for-intel-gna.md similarity index 100% rename from docs/install_guides/configurations-for-intel-gna.md rename to docs/articles_en/get started/configurations-header/configurations-for-intel-gna.md diff --git a/docs/install_guides/configurations-for-intel-gpu.md b/docs/articles_en/get started/configurations-header/configurations-for-intel-gpu.md similarity index 100% rename from docs/install_guides/configurations-for-intel-gpu.md rename to docs/articles_en/get started/configurations-header/configurations-for-intel-gpu.md diff --git a/docs/install_guides/configurations-for-intel-npu.md b/docs/articles_en/get started/configurations-header/configurations-for-intel-npu.md similarity index 100% rename from docs/install_guides/configurations-for-intel-npu.md rename to docs/articles_en/get started/configurations-header/configurations-for-intel-npu.md diff --git a/docs/get_started.md b/docs/articles_en/get_started.md similarity index 100% rename from docs/get_started.md rename to docs/articles_en/get_started.md From 064ee982df184b4abd403a5e626f609d6198cc1e Mon Sep 17 00:00:00 2001 From: Maciej Smyk Date: Fri, 29 Sep 2023 10:37:34 +0200 Subject: [PATCH 28/35] install guide overview (#20129) --- .../get started}/installing-openvino-overview.md | 0 .../installing-openvino-linux-header.md | 0 .../installing-openvino-macos-header.md | 0 .../installing-openvino-windows-header.md | 0 .../installing-openvino-overview}/installing-openvino-yocto.md | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename docs/{install_guides => articles_en/get started}/installing-openvino-overview.md (100%) rename docs/{install_guides => articles_en/get started/installing-openvino-overview}/installing-openvino-linux-header.md (100%) rename docs/{install_guides => articles_en/get started/installing-openvino-overview}/installing-openvino-macos-header.md (100%) rename docs/{install_guides => articles_en/get started/installing-openvino-overview}/installing-openvino-windows-header.md (100%) rename docs/{install_guides => articles_en/get started/installing-openvino-overview}/installing-openvino-yocto.md (100%) diff --git a/docs/install_guides/installing-openvino-overview.md b/docs/articles_en/get started/installing-openvino-overview.md similarity index 100% rename from docs/install_guides/installing-openvino-overview.md rename to docs/articles_en/get started/installing-openvino-overview.md diff --git a/docs/install_guides/installing-openvino-linux-header.md b/docs/articles_en/get started/installing-openvino-overview/installing-openvino-linux-header.md similarity index 100% rename from docs/install_guides/installing-openvino-linux-header.md rename to docs/articles_en/get started/installing-openvino-overview/installing-openvino-linux-header.md diff --git a/docs/install_guides/installing-openvino-macos-header.md b/docs/articles_en/get started/installing-openvino-overview/installing-openvino-macos-header.md similarity index 100% rename from docs/install_guides/installing-openvino-macos-header.md rename to docs/articles_en/get started/installing-openvino-overview/installing-openvino-macos-header.md diff --git a/docs/install_guides/installing-openvino-windows-header.md b/docs/articles_en/get started/installing-openvino-overview/installing-openvino-windows-header.md similarity index 100% rename from docs/install_guides/installing-openvino-windows-header.md rename to docs/articles_en/get started/installing-openvino-overview/installing-openvino-windows-header.md diff --git a/docs/install_guides/installing-openvino-yocto.md b/docs/articles_en/get started/installing-openvino-overview/installing-openvino-yocto.md similarity index 100% rename from docs/install_guides/installing-openvino-yocto.md rename to docs/articles_en/get started/installing-openvino-overview/installing-openvino-yocto.md From 51060c2643e8e5875d4b16559ce6d3622a8cbdfc Mon Sep 17 00:00:00 2001 From: Maciej Smyk Date: Fri, 29 Sep 2023 12:22:02 +0200 Subject: [PATCH 29/35] macOS runtime (#20143) --- .../installing-openvino-from-archive-macos.md | 0 .../installing-openvino-shared}/installing-openvino-brew.md | 0 .../installing-openvino-shared}/installing-openvino-conda.md | 0 .../installing-openvino-shared}/installing-openvino-pip.md | 0 .../installing-openvino-shared}/installing-openvino-vcpkg.md | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename docs/{install_guides => articles_en/get started/installing-openvino-overview/installing-openvino-macos-header}/installing-openvino-from-archive-macos.md (100%) rename docs/{install_guides => articles_en/get started/installing-openvino-overview/installing-openvino-shared}/installing-openvino-brew.md (100%) rename docs/{install_guides => articles_en/get started/installing-openvino-overview/installing-openvino-shared}/installing-openvino-conda.md (100%) rename docs/{install_guides => articles_en/get started/installing-openvino-overview/installing-openvino-shared}/installing-openvino-pip.md (100%) rename docs/{install_guides => articles_en/get started/installing-openvino-overview/installing-openvino-shared}/installing-openvino-vcpkg.md (100%) diff --git a/docs/install_guides/installing-openvino-from-archive-macos.md b/docs/articles_en/get started/installing-openvino-overview/installing-openvino-macos-header/installing-openvino-from-archive-macos.md similarity index 100% rename from docs/install_guides/installing-openvino-from-archive-macos.md rename to docs/articles_en/get started/installing-openvino-overview/installing-openvino-macos-header/installing-openvino-from-archive-macos.md diff --git a/docs/install_guides/installing-openvino-brew.md b/docs/articles_en/get started/installing-openvino-overview/installing-openvino-shared/installing-openvino-brew.md similarity index 100% rename from docs/install_guides/installing-openvino-brew.md rename to docs/articles_en/get started/installing-openvino-overview/installing-openvino-shared/installing-openvino-brew.md diff --git a/docs/install_guides/installing-openvino-conda.md b/docs/articles_en/get started/installing-openvino-overview/installing-openvino-shared/installing-openvino-conda.md similarity index 100% rename from docs/install_guides/installing-openvino-conda.md rename to docs/articles_en/get started/installing-openvino-overview/installing-openvino-shared/installing-openvino-conda.md diff --git a/docs/install_guides/installing-openvino-pip.md b/docs/articles_en/get started/installing-openvino-overview/installing-openvino-shared/installing-openvino-pip.md similarity index 100% rename from docs/install_guides/installing-openvino-pip.md rename to docs/articles_en/get started/installing-openvino-overview/installing-openvino-shared/installing-openvino-pip.md diff --git a/docs/install_guides/installing-openvino-vcpkg.md b/docs/articles_en/get started/installing-openvino-overview/installing-openvino-shared/installing-openvino-vcpkg.md similarity index 100% rename from docs/install_guides/installing-openvino-vcpkg.md rename to docs/articles_en/get started/installing-openvino-overview/installing-openvino-shared/installing-openvino-vcpkg.md From 332305b1ebf8d6c1ebe95c964bb6eebb9e81bcb3 Mon Sep 17 00:00:00 2001 From: Sebastian Golebiewski Date: Fri, 29 Sep 2023 12:48:56 +0200 Subject: [PATCH 30/35] Changing file structure of OpenVINO Extensibility section of docs (#20145) --- .../documentation/openvino_extensibility.md} | 0 .../documentation/openvino_extensibility}/GPU_Extensibility.md | 0 .../documentation/openvino_extensibility}/add_openvino_ops.md | 0 .../documentation/openvino_extensibility}/frontend_extensions.md | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename docs/{Extensibility_UG/Intro.md => articles_en/documentation/openvino_extensibility.md} (100%) rename docs/{Extensibility_UG => articles_en/documentation/openvino_extensibility}/GPU_Extensibility.md (100%) rename docs/{Extensibility_UG => articles_en/documentation/openvino_extensibility}/add_openvino_ops.md (100%) rename docs/{Extensibility_UG => articles_en/documentation/openvino_extensibility}/frontend_extensions.md (100%) diff --git a/docs/Extensibility_UG/Intro.md b/docs/articles_en/documentation/openvino_extensibility.md similarity index 100% rename from docs/Extensibility_UG/Intro.md rename to docs/articles_en/documentation/openvino_extensibility.md diff --git a/docs/Extensibility_UG/GPU_Extensibility.md b/docs/articles_en/documentation/openvino_extensibility/GPU_Extensibility.md similarity index 100% rename from docs/Extensibility_UG/GPU_Extensibility.md rename to docs/articles_en/documentation/openvino_extensibility/GPU_Extensibility.md diff --git a/docs/Extensibility_UG/add_openvino_ops.md b/docs/articles_en/documentation/openvino_extensibility/add_openvino_ops.md similarity index 100% rename from docs/Extensibility_UG/add_openvino_ops.md rename to docs/articles_en/documentation/openvino_extensibility/add_openvino_ops.md diff --git a/docs/Extensibility_UG/frontend_extensions.md b/docs/articles_en/documentation/openvino_extensibility/frontend_extensions.md similarity index 100% rename from docs/Extensibility_UG/frontend_extensions.md rename to docs/articles_en/documentation/openvino_extensibility/frontend_extensions.md From 6906af1d7283c213abd397eda785b7aafa63b78d Mon Sep 17 00:00:00 2001 From: Maciej Smyk Date: Fri, 29 Sep 2023 13:39:43 +0200 Subject: [PATCH 31/35] runtime windows & linux (#20148) --- .../installing-openvino-linux-header}/installing-openvino-apt.md | 0 .../installing-openvino-from-archive-linux.md | 0 .../installing-openvino-linux-header}/installing-openvino-yum.md | 0 .../installing-openvino-docker-linux.md | 0 .../installing-openvino-from-archive-windows.md | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename docs/{install_guides => articles_en/get started/installing-openvino-overview/installing-openvino-linux-header}/installing-openvino-apt.md (100%) rename docs/{install_guides => articles_en/get started/installing-openvino-overview/installing-openvino-linux-header}/installing-openvino-from-archive-linux.md (100%) rename docs/{install_guides => articles_en/get started/installing-openvino-overview/installing-openvino-linux-header}/installing-openvino-yum.md (100%) rename docs/{install_guides => articles_en/get started/installing-openvino-overview/installing-openvino-shared}/installing-openvino-docker-linux.md (100%) rename docs/{install_guides => articles_en/get started/installing-openvino-overview/installing-openvino-windows-header}/installing-openvino-from-archive-windows.md (100%) diff --git a/docs/install_guides/installing-openvino-apt.md b/docs/articles_en/get started/installing-openvino-overview/installing-openvino-linux-header/installing-openvino-apt.md similarity index 100% rename from docs/install_guides/installing-openvino-apt.md rename to docs/articles_en/get started/installing-openvino-overview/installing-openvino-linux-header/installing-openvino-apt.md diff --git a/docs/install_guides/installing-openvino-from-archive-linux.md b/docs/articles_en/get started/installing-openvino-overview/installing-openvino-linux-header/installing-openvino-from-archive-linux.md similarity index 100% rename from docs/install_guides/installing-openvino-from-archive-linux.md rename to docs/articles_en/get started/installing-openvino-overview/installing-openvino-linux-header/installing-openvino-from-archive-linux.md diff --git a/docs/install_guides/installing-openvino-yum.md b/docs/articles_en/get started/installing-openvino-overview/installing-openvino-linux-header/installing-openvino-yum.md similarity index 100% rename from docs/install_guides/installing-openvino-yum.md rename to docs/articles_en/get started/installing-openvino-overview/installing-openvino-linux-header/installing-openvino-yum.md diff --git a/docs/install_guides/installing-openvino-docker-linux.md b/docs/articles_en/get started/installing-openvino-overview/installing-openvino-shared/installing-openvino-docker-linux.md similarity index 100% rename from docs/install_guides/installing-openvino-docker-linux.md rename to docs/articles_en/get started/installing-openvino-overview/installing-openvino-shared/installing-openvino-docker-linux.md diff --git a/docs/install_guides/installing-openvino-from-archive-windows.md b/docs/articles_en/get started/installing-openvino-overview/installing-openvino-windows-header/installing-openvino-from-archive-windows.md similarity index 100% rename from docs/install_guides/installing-openvino-from-archive-windows.md rename to docs/articles_en/get started/installing-openvino-overview/installing-openvino-windows-header/installing-openvino-from-archive-windows.md From 6e1e8105fe8feda4f4bf272355c33a0f9fd748e5 Mon Sep 17 00:00:00 2001 From: Sebastian Golebiewski Date: Fri, 29 Sep 2023 13:57:00 +0200 Subject: [PATCH 32/35] Changing file structure of Overview of Transformations API section of docs (#20150) --- .../documentation/openvino_extensibility}/ov_transformations.md | 0 .../ov_transformations}/graph_rewrite_pass.md | 0 .../openvino_extensibility/ov_transformations}/matcher_pass.md | 0 .../openvino_extensibility/ov_transformations}/model_pass.md | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename docs/{Extensibility_UG => articles_en/documentation/openvino_extensibility}/ov_transformations.md (100%) rename docs/{Extensibility_UG => articles_en/documentation/openvino_extensibility/ov_transformations}/graph_rewrite_pass.md (100%) rename docs/{Extensibility_UG => articles_en/documentation/openvino_extensibility/ov_transformations}/matcher_pass.md (100%) rename docs/{Extensibility_UG => articles_en/documentation/openvino_extensibility/ov_transformations}/model_pass.md (100%) diff --git a/docs/Extensibility_UG/ov_transformations.md b/docs/articles_en/documentation/openvino_extensibility/ov_transformations.md similarity index 100% rename from docs/Extensibility_UG/ov_transformations.md rename to docs/articles_en/documentation/openvino_extensibility/ov_transformations.md diff --git a/docs/Extensibility_UG/graph_rewrite_pass.md b/docs/articles_en/documentation/openvino_extensibility/ov_transformations/graph_rewrite_pass.md similarity index 100% rename from docs/Extensibility_UG/graph_rewrite_pass.md rename to docs/articles_en/documentation/openvino_extensibility/ov_transformations/graph_rewrite_pass.md diff --git a/docs/Extensibility_UG/matcher_pass.md b/docs/articles_en/documentation/openvino_extensibility/ov_transformations/matcher_pass.md similarity index 100% rename from docs/Extensibility_UG/matcher_pass.md rename to docs/articles_en/documentation/openvino_extensibility/ov_transformations/matcher_pass.md diff --git a/docs/Extensibility_UG/model_pass.md b/docs/articles_en/documentation/openvino_extensibility/ov_transformations/model_pass.md similarity index 100% rename from docs/Extensibility_UG/model_pass.md rename to docs/articles_en/documentation/openvino_extensibility/ov_transformations/model_pass.md From 30b0f660d3f00d6a6dec035432ea971ccd6bdf3a Mon Sep 17 00:00:00 2001 From: Sebastian Golebiewski Date: Fri, 29 Sep 2023 14:21:16 +0200 Subject: [PATCH 33/35] Changing file structure of OpenVINO Plugin Developer Guide section of (#20153) --- .../openvino_extensibility/openvino_plugin_library.md} | 0 .../openvino_plugin_library}/AsyncInferRequest.md | 0 .../openvino_extensibility/openvino_plugin_library}/Building.md | 0 .../openvino_plugin_library}/CompiledModel.md | 0 .../openvino_plugin_library}/InferRequest.md | 0 .../openvino_extensibility/openvino_plugin_library}/Plugin.md | 0 .../openvino_plugin_library}/PluginTesting.md | 0 .../openvino_extensibility/openvino_plugin_library}/Properties.md | 0 .../openvino_plugin_library}/RemoteContext.md | 0 .../openvino_plugin_library}/RemoteTensor.md | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename docs/{IE_PLUGIN_DG/Intro.md => articles_en/documentation/openvino_extensibility/openvino_plugin_library.md} (100%) rename docs/{IE_PLUGIN_DG => articles_en/documentation/openvino_extensibility/openvino_plugin_library}/AsyncInferRequest.md (100%) rename docs/{IE_PLUGIN_DG => articles_en/documentation/openvino_extensibility/openvino_plugin_library}/Building.md (100%) rename docs/{IE_PLUGIN_DG => articles_en/documentation/openvino_extensibility/openvino_plugin_library}/CompiledModel.md (100%) rename docs/{IE_PLUGIN_DG => articles_en/documentation/openvino_extensibility/openvino_plugin_library}/InferRequest.md (100%) rename docs/{IE_PLUGIN_DG => articles_en/documentation/openvino_extensibility/openvino_plugin_library}/Plugin.md (100%) rename docs/{IE_PLUGIN_DG => articles_en/documentation/openvino_extensibility/openvino_plugin_library}/PluginTesting.md (100%) rename docs/{IE_PLUGIN_DG => articles_en/documentation/openvino_extensibility/openvino_plugin_library}/Properties.md (100%) rename docs/{IE_PLUGIN_DG => articles_en/documentation/openvino_extensibility/openvino_plugin_library}/RemoteContext.md (100%) rename docs/{IE_PLUGIN_DG => articles_en/documentation/openvino_extensibility/openvino_plugin_library}/RemoteTensor.md (100%) diff --git a/docs/IE_PLUGIN_DG/Intro.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library.md similarity index 100% rename from docs/IE_PLUGIN_DG/Intro.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library.md diff --git a/docs/IE_PLUGIN_DG/AsyncInferRequest.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/AsyncInferRequest.md similarity index 100% rename from docs/IE_PLUGIN_DG/AsyncInferRequest.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/AsyncInferRequest.md diff --git a/docs/IE_PLUGIN_DG/Building.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/Building.md similarity index 100% rename from docs/IE_PLUGIN_DG/Building.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/Building.md diff --git a/docs/IE_PLUGIN_DG/CompiledModel.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/CompiledModel.md similarity index 100% rename from docs/IE_PLUGIN_DG/CompiledModel.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/CompiledModel.md diff --git a/docs/IE_PLUGIN_DG/InferRequest.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/InferRequest.md similarity index 100% rename from docs/IE_PLUGIN_DG/InferRequest.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/InferRequest.md diff --git a/docs/IE_PLUGIN_DG/Plugin.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/Plugin.md similarity index 100% rename from docs/IE_PLUGIN_DG/Plugin.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/Plugin.md diff --git a/docs/IE_PLUGIN_DG/PluginTesting.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/PluginTesting.md similarity index 100% rename from docs/IE_PLUGIN_DG/PluginTesting.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/PluginTesting.md diff --git a/docs/IE_PLUGIN_DG/Properties.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/Properties.md similarity index 100% rename from docs/IE_PLUGIN_DG/Properties.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/Properties.md diff --git a/docs/IE_PLUGIN_DG/RemoteContext.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/RemoteContext.md similarity index 100% rename from docs/IE_PLUGIN_DG/RemoteContext.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/RemoteContext.md diff --git a/docs/IE_PLUGIN_DG/RemoteTensor.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/RemoteTensor.md similarity index 100% rename from docs/IE_PLUGIN_DG/RemoteTensor.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/RemoteTensor.md From cb315e8f917f1652e10a874d7c3afec497f21b6f Mon Sep 17 00:00:00 2001 From: Sebastian Golebiewski Date: Fri, 29 Sep 2023 14:42:50 +0200 Subject: [PATCH 34/35] Changing file structure of Advanced Topics section of OpenVINO Plugin Developer Guide (#20154) --- .../openvino_plugin_library}/detailed_guides.md | 0 .../openvino_plugin_library/detailed_guides}/QuantizedNetworks.md | 0 .../detailed_guides/low_precision_transformations.md} | 0 .../low_precision_transformations/lpt_attributes.md | 0 .../low_precision_transformations}/step1_prerequisites.md | 0 .../low_precision_transformations}/step2_markup.md | 0 .../detailed_guides/low_precision_transformations}/step3_main.md | 0 .../low_precision_transformations}/step4_cleanup.md | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename docs/{IE_PLUGIN_DG => articles_en/documentation/openvino_extensibility/openvino_plugin_library}/detailed_guides.md (100%) rename docs/{IE_PLUGIN_DG => articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides}/QuantizedNetworks.md (100%) rename docs/{IE_PLUGIN_DG/plugin_transformation_pipeline/low_precision_transformations/lpt.md => articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations.md} (100%) rename docs/{IE_PLUGIN_DG/plugin_transformation_pipeline => articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides}/low_precision_transformations/lpt_attributes.md (100%) rename docs/{IE_PLUGIN_DG/plugin_transformation_pipeline/low_precision_transformations/pipeline => articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations}/step1_prerequisites.md (100%) rename docs/{IE_PLUGIN_DG/plugin_transformation_pipeline/low_precision_transformations/pipeline => articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations}/step2_markup.md (100%) rename docs/{IE_PLUGIN_DG/plugin_transformation_pipeline/low_precision_transformations/pipeline => articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations}/step3_main.md (100%) rename docs/{IE_PLUGIN_DG/plugin_transformation_pipeline/low_precision_transformations/pipeline => articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations}/step4_cleanup.md (100%) diff --git a/docs/IE_PLUGIN_DG/detailed_guides.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides.md similarity index 100% rename from docs/IE_PLUGIN_DG/detailed_guides.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides.md diff --git a/docs/IE_PLUGIN_DG/QuantizedNetworks.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/QuantizedNetworks.md similarity index 100% rename from docs/IE_PLUGIN_DG/QuantizedNetworks.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/QuantizedNetworks.md diff --git a/docs/IE_PLUGIN_DG/plugin_transformation_pipeline/low_precision_transformations/lpt.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations.md similarity index 100% rename from docs/IE_PLUGIN_DG/plugin_transformation_pipeline/low_precision_transformations/lpt.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations.md diff --git a/docs/IE_PLUGIN_DG/plugin_transformation_pipeline/low_precision_transformations/lpt_attributes.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations/lpt_attributes.md similarity index 100% rename from docs/IE_PLUGIN_DG/plugin_transformation_pipeline/low_precision_transformations/lpt_attributes.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations/lpt_attributes.md diff --git a/docs/IE_PLUGIN_DG/plugin_transformation_pipeline/low_precision_transformations/pipeline/step1_prerequisites.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations/step1_prerequisites.md similarity index 100% rename from docs/IE_PLUGIN_DG/plugin_transformation_pipeline/low_precision_transformations/pipeline/step1_prerequisites.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations/step1_prerequisites.md diff --git a/docs/IE_PLUGIN_DG/plugin_transformation_pipeline/low_precision_transformations/pipeline/step2_markup.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations/step2_markup.md similarity index 100% rename from docs/IE_PLUGIN_DG/plugin_transformation_pipeline/low_precision_transformations/pipeline/step2_markup.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations/step2_markup.md diff --git a/docs/IE_PLUGIN_DG/plugin_transformation_pipeline/low_precision_transformations/pipeline/step3_main.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations/step3_main.md similarity index 100% rename from docs/IE_PLUGIN_DG/plugin_transformation_pipeline/low_precision_transformations/pipeline/step3_main.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations/step3_main.md diff --git a/docs/IE_PLUGIN_DG/plugin_transformation_pipeline/low_precision_transformations/pipeline/step4_cleanup.md b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations/step4_cleanup.md similarity index 100% rename from docs/IE_PLUGIN_DG/plugin_transformation_pipeline/low_precision_transformations/pipeline/step4_cleanup.md rename to docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations/step4_cleanup.md From 201403ecd0fb9bcfa8748f25751001475f8ef529 Mon Sep 17 00:00:00 2001 From: Andrey Babushkin Date: Fri, 29 Sep 2023 15:00:52 +0100 Subject: [PATCH 35/35] More RAM for 4 core AKS runner (#20138) --- .github/workflows/linux.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 050d4c81ed133f..aefe5227b6a840 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -392,7 +392,7 @@ jobs: defaults: run: shell: bash - runs-on: aks-linux-4-cores + runs-on: aks-linux-4-cores-16gb container: image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 env: @@ -585,7 +585,7 @@ jobs: defaults: run: shell: bash - runs-on: aks-linux-4-cores + runs-on: aks-linux-4-cores-16gb container: image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 volumes: @@ -895,7 +895,7 @@ jobs: defaults: run: shell: bash - runs-on: ${{ github.event_name == 'schedule' && 'aks-linux-16-cores' || 'aks-linux-4-cores'}} + runs-on: ${{ github.event_name == 'schedule' && 'aks-linux-16-cores' || 'aks-linux-4-cores-16gb'}} container: image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 volumes: @@ -1059,4 +1059,4 @@ jobs: name: test-results-torch-models path: | ${{ env.INSTALL_TEST_DIR }}/TEST*.html - if-no-files-found: 'error' \ No newline at end of file + if-no-files-found: 'error'