Ability to use RapidJSON as find_package() (#19762)

* Ability to use RapidJSON as find_package()

* Use default features in vcpkg.json
This commit is contained in:
Ilya Lavrenov 2023-09-13 12:46:40 +04:00 committed by GitHub
parent e9f4e4db65
commit 8cff0697a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 99 additions and 85 deletions

View File

@ -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",

View File

@ -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]

View File

@ -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` \

View File

@ -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)

View File

@ -61,7 +61,8 @@ endif()
target_include_directories(${TARGET_NAME} PUBLIC $<BUILD_INTERFACE:${INCLUDE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/kernels/>
$<BUILD_INTERFACE:${CODEGEN_INCDIR}>)
$<BUILD_INTERFACE:${CODEGEN_INCDIR}>
PRIVATE $<TARGET_PROPERTY:rapidjson,INTERFACE_INCLUDE_DIRECTORIES>)
target_compile_options(${TARGET_NAME} PRIVATE
$<$<CONFIG:Release>:$<IF:$<CXX_COMPILER_ID:MSVC>,/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})

View File

@ -3,18 +3,21 @@
//
#include "auto_tuner.h"
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <string>
#include "istreamwrapper.h"
#include "stringbuffer.h"
#include "prettywriter.h"
#include <memory>
#include <utility>
#include <tuple>
#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());

View File

@ -8,12 +8,12 @@
#include <mutex>
#include <map>
#include <string>
#include "kernel_selector_common.h"
#include "kernel_selector_params.h"
#include "document.h"
#include <memory>
#include <tuple>
#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> impl;
static constexpr const char* version1Marker = "version_1";
static constexpr const char* version2Marker = "version_2";

View File

@ -1541,11 +1541,11 @@ JitConstants MakeActivationJitConstants(std::vector<kernel_selector::base_activa
std::string nl_n = toCodeString(params[i].n);
if (params[i].function == ActivationFunction::CLAMP) {
if (out_dt == Datatype::INT8) {
nl_m = toCodeString(std::max(params[i].m, static_cast<float>(SCHAR_MIN)));
nl_n = toCodeString(std::min(params[i].n, static_cast<float>(SCHAR_MAX)));
nl_m = toCodeString(std::max<float>(params[i].m, std::numeric_limits<signed char>::min()));
nl_n = toCodeString(std::min<float>(params[i].n, std::numeric_limits<signed char>::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<float>(UCHAR_MAX)));
nl_n = toCodeString(std::min<float>(params[i].n, std::numeric_limits<unsigned char>::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<float>(SCHAR_MIN)));
nl_n = toCodeString(std::min(activation_p.n, static_cast<float>(SCHAR_MAX)));
nl_m = toCodeString(std::max<float>(activation_p.m, std::numeric_limits<signed char>::min()));
nl_n = toCodeString(std::min<float>(activation_p.n, std::numeric_limits<signed char>::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<float>(UCHAR_MAX)));
nl_n = toCodeString(std::min<float>(activation_p.n, std::numeric_limits<unsigned char>::max()));
}
}

View File

@ -10,7 +10,6 @@
#include <limits>
#include "common_types.h"
#include "tensor_type.h"
#include "document.h"
#include <vector>
#include <utility>
#include <bitset>

View File

@ -2,14 +2,6 @@
# SPDX-License-Identifier: Apache-2.0
#
add_library(rapidjson INTERFACE)
set_target_properties(rapidjson PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/rapidjson>
)
ov_install_static_lib(rapidjson gpu)
#
# oneDNN for GPU plugin
#

View File

@ -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 $<BUILD_INTERFACE:${RAPIDJSON_INCLUDE_DIRS}>)
else()
message(FATAL_ERROR "RapidJSON does not define RAPIDJSON_INCLUDE_DIRS nor RapidJSON / rapidjson targets")
endif()
else()
target_include_directories(rapidjson INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty>)
endif()
endif()

View File

@ -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)",