From 8cff0697a724455ec5c7447774212b777e2c0f18 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Wed, 13 Sep 2023 12:46:40 +0400 Subject: [PATCH] Ability to use RapidJSON as find_package() (#19762) * Ability to use RapidJSON as find_package() * Use default features in vcpkg.json --- conan.lock | 6 +- conanfile.txt | 11 ++-- install_build_dependencies.sh | 1 + src/plugins/intel_gpu/CMakeLists.txt | 1 + .../src/kernel_selector/CMakeLists.txt | 5 +- .../src/kernel_selector/auto_tuner.cpp | 52 +++++++++-------- .../src/kernel_selector/auto_tuner.h | 9 +-- .../intel_gpu/src/kernel_selector/jitter.cpp | 12 ++-- .../kernel_selector/kernel_selector_params.h | 1 - .../intel_gpu/thirdparty/CMakeLists.txt | 8 --- .../thirdparty/cmake/rapidjson.cmake | 22 ++++++++ vcpkg.json | 56 +++++++------------ 12 files changed, 99 insertions(+), 85 deletions(-) create mode 100644 src/plugins/intel_gpu/thirdparty/cmake/rapidjson.cmake diff --git a/conan.lock b/conan.lock index aa5731e6640..2f88a46d9bb 100644 --- a/conan.lock +++ b/conan.lock @@ -4,6 +4,7 @@ "zlib/1.2.13#97d5730b529b4224045fe7090592d4c1%1692672717.049", "xbyak/6.73#250bc3bc73379f90f255876c1c00a4cd%1691853024.351", "snappy/1.1.10#916523630083f6d855cb2977de8eefb6%1689780661.062", + "rapidjson/cci.20220822#8ca51918340f3a21127822258e95ec0f%1663194355.698", "pybind11/2.10.4#dd44c80a5ed6a2ef11194380daae1248%1682692198.909", "pugixml/1.13#f615c1fcec55122b2e177d17061276e7%1691917296.869", "protobuf/3.21.12#d9f5f4e3b86552552dda4c0a2e928eeb%1685218275.69", @@ -17,13 +18,16 @@ "hwloc/2.9.2#1c63e2eccac57048ae226e6c946ebf0e%1688677682.002", "gflags/2.2.2#48d1262ffac8d30c3224befb8275a533%1676224985.343", "flatbuffers/23.5.26#b153646f6546daab4c7326970b6cd89c%1685838458.449", - "ade/0.1.2a#b569ff943843abd004e65536e265a445%1688125447.482" + "ade/0.1.2c#8c03c130df6dc35186b38ba73a40a71d%1694253992.577" ], "build_requires": [ "zlib/1.2.13#97d5730b529b4224045fe7090592d4c1%1692672717.049", "protobuf/3.21.12#d9f5f4e3b86552552dda4c0a2e928eeb%1685218275.69", "protobuf/3.21.9#515ceb0a1653cf84363d9968b812d6be%1678364058.993", + "pkgconf/1.9.5#743ca0d41d35a84b1f89af337ddaa1a0%1688570267.802", "patchelf/0.13#0eaada8970834919c3ce14355afe7fac%1680534241.341", + "ninja/1.11.1#77587f8c8318662ac8e5a7867eb4be21%1684431244.21", + "meson/1.0.0#15586c0ac6f682805875ef903dbe7ee2%1673885561.647", "m4/1.4.19#c1c4b1ee919e34630bb9b50046253d3c%1676610086.39", "libtool/2.4.6#9ee8efc04c2e106e7fba13bb1e477617%1677509454.345", "gnu-config/cci.20210814#15c3bf7dfdb743977b84d0321534ad90%1681250000.747", diff --git a/conanfile.txt b/conanfile.txt index bdbf5965f4a..a4c1e465311 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,13 +1,12 @@ [requires] -ade/0.1.2a +ade/0.1.2c onetbb/[>=2021.2.1] pugixml/[>=1.10] protobuf/3.21.12 ittapi/[>=3.23.0] zlib/[>=1.2.8] -opencl-icd-loader/2023.04.17 -opencl-clhpp-headers/2023.04.17 -opencl-headers/2023.04.17 +opencl-icd-loader/[>=2023.04.17] +rapidjson/[>=1.1.0] xbyak/[>=6.62] snappy/[>=1.1.7] gflags/2.2.2 @@ -17,13 +16,15 @@ pybind11/[>=2.10.1] flatbuffers/[>=22.9.24] [tool_requires] -cmake/[>=3.15] +cmake/[>=3.20] +pkgconf/1.9.5 patchelf/[>=0.12] protobuf/3.21.9 flatbuffers/[>=22.9.24] [options] protobuf/*:lite=True +protobuf/*:shared=False flatbuffers/*:header_only=True [generators] diff --git a/install_build_dependencies.sh b/install_build_dependencies.sh index 4fe4f0f13b6..21faba35e5a 100755 --- a/install_build_dependencies.sh +++ b/install_build_dependencies.sh @@ -53,6 +53,7 @@ if [ -f /etc/lsb-release ] || [ -f /etc/debian_version ] ; then `# OpenCL for GPU` \ ocl-icd-opencl-dev \ opencl-headers \ + rapidjson-dev \ `# GPU plugin extensions` \ libva-dev \ `# For TF FE saved models` \ diff --git a/src/plugins/intel_gpu/CMakeLists.txt b/src/plugins/intel_gpu/CMakeLists.txt index 1770b34b654..4e8a9d0e689 100644 --- a/src/plugins/intel_gpu/CMakeLists.txt +++ b/src/plugins/intel_gpu/CMakeLists.txt @@ -35,6 +35,7 @@ set(MAIN_DIR "${CMAKE_CURRENT_SOURCE_DIR}") set(INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") add_subdirectory(thirdparty) +include(thirdparty/cmake/rapidjson.cmake) if(CMAKE_COMPILER_IS_GNUCXX) ie_add_compiler_flags(-Werror) diff --git a/src/plugins/intel_gpu/src/kernel_selector/CMakeLists.txt b/src/plugins/intel_gpu/src/kernel_selector/CMakeLists.txt index b76d8ee7328..4e4aa260520 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/CMakeLists.txt +++ b/src/plugins/intel_gpu/src/kernel_selector/CMakeLists.txt @@ -61,7 +61,8 @@ endif() target_include_directories(${TARGET_NAME} PUBLIC $ $ $ - $) + $ + PRIVATE $) target_compile_options(${TARGET_NAME} PRIVATE $<$:$,/Os,-Os>>) @@ -70,7 +71,7 @@ if(COMMAND add_cpplint_target) add_cpplint_target(${TARGET_NAME}_cpplint FOR_TARGETS ${TARGET_NAME}) endif() -target_link_libraries(${TARGET_NAME} PUBLIC OpenCL::OpenCL rapidjson inference_engine_plugin_api) +target_link_libraries(${TARGET_NAME} PUBLIC OpenCL::OpenCL inference_engine_plugin_api) set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO}) diff --git a/src/plugins/intel_gpu/src/kernel_selector/auto_tuner.cpp b/src/plugins/intel_gpu/src/kernel_selector/auto_tuner.cpp index cfac486cdfc..a5d0711f61c 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/auto_tuner.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/auto_tuner.cpp @@ -3,18 +3,21 @@ // #include "auto_tuner.h" + #include #include #include #include #include -#include "istreamwrapper.h" -#include "stringbuffer.h" -#include "prettywriter.h" #include #include #include +#include "rapidjson/istreamwrapper.h" +#include "rapidjson/stringbuffer.h" +#include "rapidjson/prettywriter.h" +#include "rapidjson/document.h" + #ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN @@ -35,32 +38,37 @@ namespace kernel_selector { +class TuningCache::Impl { +public: + rapidjson::Document cache; +}; + TuningCache::TuningCache(const std::string& cacheFilePath) - : cache() { + : impl(new Impl()) { // Read cache file std::ifstream tuningFile(cacheFilePath); if (tuningFile && tuningFile.good()) { std::stringstream buffer; buffer << tuningFile.rdbuf(); - cache.Parse(buffer.str().c_str()); + impl->cache.Parse(buffer.str().c_str()); } else { throw std::runtime_error("Tuning file: " + cacheFilePath + " could not be read! Must provide a valid cache file in USE_CACHE mode."); } - if (cache.IsNull()) { - cache.SetObject(); - } else if (!cache.IsObject()) { + if (impl->cache.IsNull()) { + impl->cache.SetObject(); + } else if (!impl->cache.IsObject()) { throw std::runtime_error("Tuning file: " + cacheFilePath + " has incorrect format."); } - auto cacheObj = cache.GetObject(); + auto cacheObj = impl->cache.GetObject(); // Update to new format with version markers if (!cacheObj.HasMember(version2Marker)) { - auto newName = rapidjson::Value(version2Marker, cache.GetAllocator()); + auto newName = rapidjson::Value(version2Marker, impl->cache.GetAllocator()); auto newObj = rapidjson::Value(rapidjson::Type::kObjectType); - cacheObj.AddMember(newName, newObj, cache.GetAllocator()); + cacheObj.AddMember(newName, newObj, impl->cache.GetAllocator()); } bool needsV1 = false; @@ -73,9 +81,9 @@ TuningCache::TuningCache(const std::string& cacheFilePath) if (needsV1) { if (!cacheObj.HasMember(version1Marker)) { - auto newName = rapidjson::Value(version1Marker, cache.GetAllocator()); + auto newName = rapidjson::Value(version1Marker, impl->cache.GetAllocator()); auto newObj = rapidjson::Value(rapidjson::Type::kObjectType); - cacheObj.AddMember(newName, newObj, cache.GetAllocator()); + cacheObj.AddMember(newName, newObj, impl->cache.GetAllocator()); } for (auto it = cacheObj.begin(); it != cacheObj.end();) { @@ -86,7 +94,7 @@ TuningCache::TuningCache(const std::string& cacheFilePath) auto newValue = rapidjson::Value(rapidjson::Type::kObjectType); newName.Swap(member.name); newValue.Swap(member.value); - cache[version1Marker].AddMember(newName, newValue, cache.GetAllocator()); + impl->cache[version1Marker].AddMember(newName, newValue, impl->cache.GetAllocator()); it = cacheObj.EraseMember(it); } else { it++; @@ -96,11 +104,11 @@ TuningCache::TuningCache(const std::string& cacheFilePath) } TuningCache::TuningCache() - : cache() { - cache.SetObject(); - auto v2Name = rapidjson::Value(version2Marker, cache.GetAllocator()); + : impl(new Impl()) { + impl->cache.SetObject(); + auto v2Name = rapidjson::Value(version2Marker, impl->cache.GetAllocator()); auto v2Obj = rapidjson::Value(rapidjson::Type::kObjectType); - cache.AddMember(v2Name, v2Obj, cache.GetAllocator()); + impl->cache.AddMember(v2Name, v2Obj, impl->cache.GetAllocator()); } TuningCache::Entry TuningCache::LoadKernel(const Params& params) { @@ -129,8 +137,8 @@ TuningCache::Entry TuningCache::LoadKernel_v1(const Params& params, uint32_t com auto hashStr = std::to_string(create_hash(params.to_string())); auto computeUnitsStr = std::to_string(computeUnitsCount); - auto v1It = cache.FindMember(version1Marker); - if (v1It == cache.MemberEnd()) + auto v1It = impl->cache.FindMember(version1Marker); + if (v1It == impl->cache.MemberEnd()) return result; auto computeUnitsIt = v1It->value.FindMember(computeUnitsStr.c_str()); @@ -152,8 +160,8 @@ TuningCache::Entry TuningCache::LoadKernel_v2(const Params& params, uint32_t com auto paramStr = params.to_cache_string_v2(); auto computeUnitsStr = std::to_string(computeUnitsCount); - auto v2It = cache.FindMember(version2Marker); - if (v2It == cache.MemberEnd()) + auto v2It = impl->cache.FindMember(version2Marker); + if (v2It == impl->cache.MemberEnd()) return result; auto computeUnitsIt = v2It->value.FindMember(computeUnitsStr.c_str()); diff --git a/src/plugins/intel_gpu/src/kernel_selector/auto_tuner.h b/src/plugins/intel_gpu/src/kernel_selector/auto_tuner.h index 1a875b7d4d7..8a9da813540 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/auto_tuner.h +++ b/src/plugins/intel_gpu/src/kernel_selector/auto_tuner.h @@ -8,12 +8,12 @@ #include #include #include -#include "kernel_selector_common.h" -#include "kernel_selector_params.h" -#include "document.h" #include #include +#include "kernel_selector_common.h" +#include "kernel_selector_params.h" + namespace kernel_selector { class TuningCache { @@ -42,7 +42,8 @@ private: Entry LoadKernel_v1(const Params& params, uint32_t computeUnitsCount); Entry LoadKernel_v2(const Params& params, uint32_t computeUnitsCount); - rapidjson::Document cache; + class Impl; + std::shared_ptr impl; static constexpr const char* version1Marker = "version_1"; static constexpr const char* version2Marker = "version_2"; diff --git a/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp b/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp index aa6284ef12e..09a219306c2 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp @@ -1541,11 +1541,11 @@ JitConstants MakeActivationJitConstants(std::vector(SCHAR_MIN))); - nl_n = toCodeString(std::min(params[i].n, static_cast(SCHAR_MAX))); + nl_m = toCodeString(std::max(params[i].m, std::numeric_limits::min())); + nl_n = toCodeString(std::min(params[i].n, std::numeric_limits::max())); } else if (out_dt == Datatype::UINT8) { nl_m = toCodeString(std::max(params[i].m, 0.0f)); - nl_n = toCodeString(std::min(params[i].n, static_cast(UCHAR_MAX))); + nl_n = toCodeString(std::min(params[i].n, std::numeric_limits::max())); } } auto jitConstants = JitConstants{MakeJitConstant("NL_M" + activation_suffix, nl_m), @@ -1950,11 +1950,11 @@ JitConstants FusedOpsCodeGenerator::MakeOpJitConstants(const FusedOpsConfigurati if (activation_p.function == ActivationFunction::CLAMP) { if (out_type == Datatype::INT8) { - nl_m = toCodeString(std::max(activation_p.m, static_cast(SCHAR_MIN))); - nl_n = toCodeString(std::min(activation_p.n, static_cast(SCHAR_MAX))); + nl_m = toCodeString(std::max(activation_p.m, std::numeric_limits::min())); + nl_n = toCodeString(std::min(activation_p.n, std::numeric_limits::max())); } else if (out_type == Datatype::UINT8) { nl_m = toCodeString(std::max(activation_p.m, 0.0f)); - nl_n = toCodeString(std::min(activation_p.n, static_cast(UCHAR_MAX))); + nl_n = toCodeString(std::min(activation_p.n, std::numeric_limits::max())); } } diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.h b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.h index 187b6c5e2cc..604db427f7c 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.h +++ b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.h @@ -10,7 +10,6 @@ #include #include "common_types.h" #include "tensor_type.h" -#include "document.h" #include #include #include diff --git a/src/plugins/intel_gpu/thirdparty/CMakeLists.txt b/src/plugins/intel_gpu/thirdparty/CMakeLists.txt index 63eeade1f18..3fd37615fd1 100644 --- a/src/plugins/intel_gpu/thirdparty/CMakeLists.txt +++ b/src/plugins/intel_gpu/thirdparty/CMakeLists.txt @@ -2,14 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 # -add_library(rapidjson INTERFACE) - -set_target_properties(rapidjson PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES $ -) - -ov_install_static_lib(rapidjson gpu) - # # oneDNN for GPU plugin # diff --git a/src/plugins/intel_gpu/thirdparty/cmake/rapidjson.cmake b/src/plugins/intel_gpu/thirdparty/cmake/rapidjson.cmake new file mode 100644 index 00000000000..655224dbc13 --- /dev/null +++ b/src/plugins/intel_gpu/thirdparty/cmake/rapidjson.cmake @@ -0,0 +1,22 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# + +find_package(RapidJSON QUIET) + +if(NOT TARGET rapidjson) + # sometimes RapidJSONConfig.cmake defines only RAPIDJSON_INCLUDE_DIRS + add_library(rapidjson INTERFACE) + + if(RapidJSON_FOUND) + if(TARGET RapidJSON) + target_link_libraries(rapidjson INTERFACE RapidJSON) + elseif(DEFINED RAPIDJSON_INCLUDE_DIRS) + target_include_directories(rapidjson INTERFACE $) + else() + message(FATAL_ERROR "RapidJSON does not define RAPIDJSON_INCLUDE_DIRS nor RapidJSON / rapidjson targets") + endif() + else() + target_include_directories(rapidjson INTERFACE $) + endif() +endif() diff --git a/vcpkg.json b/vcpkg.json index 6b1fd4b2f25..30653c6ea99 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -14,7 +14,7 @@ "homepage": "https://github.com/openvinotoolkit/openvino", "documentation": "https://docs.openvino.ai/latest/index.html", "license": "Apache-2.0", - "builtin-baseline": "db95d1c098a728ce39ef232bee95391cbd350561", + "builtin-baseline": "962e5e39f8a25f42522f51fffc574e05a3efd26b", "dependencies": [ "ade", { @@ -26,6 +26,7 @@ "name": "tbb", "version>=": "2021.10.0#2" }, + "rapidjson", { "name": "xbyak", "platform": "!(arm | uwp)", @@ -33,8 +34,24 @@ } ], "default-features": [ - "default-features" - ], + "auto", + "auto-batch", + { + "name": "cpu", + "platform": "!(windows & arm)" + }, + { + "name": "gpu", + "platform": "(x64 | arm64) & !(arm64 & windows) & !(osx | uwp)" + }, + "hetero", + "ir", + "onnx", + "paddle", + "pytorch", + "tensorflow", + "tensorflow-lite" + ], "features": { "auto": { "description": "Enables Auto plugin for inference" @@ -46,39 +63,6 @@ "description": "Enables CPU plugin for inference", "supports": "!(windows & arm)" }, - "default-features": { - "description": "Enables all default features", - "dependencies": [ - { - "name": "openvino", - "features": [ - "auto", - "auto-batch", - "hetero", - "ir", - "onnx", - "paddle", - "pytorch", - "tensorflow", - "tensorflow-lite" - ] - }, - { - "name": "openvino", - "features": [ - "cpu" - ], - "platform": "!(windows & arm)" - }, - { - "name": "openvino", - "features": [ - "gpu" - ], - "platform": "(x64 | arm64) & !(arm64 & windows) & !(osx | uwp)" - } - ] - }, "gpu": { "description": "Enables GPU plugin for inference", "supports": "(x64 | arm64) & !(arm64 & windows) & !(osx | uwp)",