From 99eda5b5e155101fb56b2cc8ebe460ac264a3ecb Mon Sep 17 00:00:00 2001 From: Wang Wangwang Date: Mon, 3 Apr 2023 11:56:48 +0800 Subject: [PATCH] =?UTF-8?q?[PYTHON][CAPI][AUTO]=20Add=20ENABLE=5FSTARTUP?= =?UTF-8?q?=5FFALLBACK=20and=20ENABLE=5FRUNTIME=5FFALLBACK=20proper?= =?UTF-8?q?=E2=80=A6=20(#16436)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [AUTO] Add ENABLE_STARTUP_FALLBACK and ENABLE_RUNTIME_FALLBACK properties to Python API * Add DEVICE_BIND_BUFFER property * Add AUTO properties to C API * Update test case && Update AUTO properties in PYTHON API * Create dedicated files for auto plugin * Update header files * Update test case * Modify code style * Update variable name * Add test case for invalid input value --- .../c/include/openvino/c/auto/properties.h | 34 ++++++++++++ .../openvino/c/gpu/gpu_plugin_properties.h | 2 +- src/bindings/c/include/openvino/c/openvino.h | 1 + src/bindings/c/src/ov_auto_property.cpp | 10 ++++ .../c/tests/ov_auto_property_test.cpp | 53 +++++++++++++++++++ .../pyopenvino/core/properties/properties.cpp | 9 ++++ .../pyopenvino/core/properties/properties.hpp | 1 + .../tests/test_runtime/test_properties.py | 30 +++++++++++ 8 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 src/bindings/c/include/openvino/c/auto/properties.h create mode 100644 src/bindings/c/src/ov_auto_property.cpp create mode 100644 src/bindings/c/tests/ov_auto_property_test.cpp diff --git a/src/bindings/c/include/openvino/c/auto/properties.h b/src/bindings/c/include/openvino/c/auto/properties.h new file mode 100644 index 00000000000..87d920cc131 --- /dev/null +++ b/src/bindings/c/include/openvino/c/auto/properties.h @@ -0,0 +1,34 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +/** + * @brief This is a specified header file for auto plugin's properties + * + * @file properties.h + */ + +#pragma once +#include "openvino/c/ov_common.h" + +/** + * @brief Read-write property for setting that enables performance improvement by binding + * buffer to hw infer request + * @ingroup ov_property_c_api + */ +OPENVINO_C_VAR(const char*) +ov_property_key_intel_auto_device_bind_buffer; + +/** + * @brief Read-write property to enable/disable CPU as accelerator (or helper device) at the beginning + * @ingroup ov_property_c_api + */ +OPENVINO_C_VAR(const char*) +ov_property_key_intel_auto_enable_startup_fallback; + +/** + * @brief Read-write property to enable/disable runtime fallback to other devices when infer fails + * @ingroup ov_property_c_api + */ +OPENVINO_C_VAR(const char*) +ov_property_key_intel_auto_enable_runtime_fallback; \ No newline at end of file diff --git a/src/bindings/c/include/openvino/c/gpu/gpu_plugin_properties.h b/src/bindings/c/include/openvino/c/gpu/gpu_plugin_properties.h index 9d3aa162ac1..7ec3b46731b 100644 --- a/src/bindings/c/include/openvino/c/gpu/gpu_plugin_properties.h +++ b/src/bindings/c/include/openvino/c/gpu/gpu_plugin_properties.h @@ -1,4 +1,4 @@ -// Copyright (C) 2018-2022 Intel Corporation +// Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // diff --git a/src/bindings/c/include/openvino/c/openvino.h b/src/bindings/c/include/openvino/c/openvino.h index 7ffcb79da63..f49a5049f7e 100644 --- a/src/bindings/c/include/openvino/c/openvino.h +++ b/src/bindings/c/include/openvino/c/openvino.h @@ -15,6 +15,7 @@ **/ #pragma once +#include "openvino/c/auto/properties.h" #include "openvino/c/ov_common.h" #include "openvino/c/ov_compiled_model.h" #include "openvino/c/ov_core.h" diff --git a/src/bindings/c/src/ov_auto_property.cpp b/src/bindings/c/src/ov_auto_property.cpp new file mode 100644 index 00000000000..c8900e87c7a --- /dev/null +++ b/src/bindings/c/src/ov_auto_property.cpp @@ -0,0 +1,10 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/c/auto/properties.h" + +// Read-write property key +const char* ov_property_key_intel_auto_device_bind_buffer = "DEVICE_BIND_BUFFER"; +const char* ov_property_key_intel_auto_enable_startup_fallback = "ENABLE_STARTUP_FALLBACK"; +const char* ov_property_key_intel_auto_enable_runtime_fallback = "ENABLE_RUNTIME_FALLBACK"; diff --git a/src/bindings/c/tests/ov_auto_property_test.cpp b/src/bindings/c/tests/ov_auto_property_test.cpp new file mode 100644 index 00000000000..6750092d845 --- /dev/null +++ b/src/bindings/c/tests/ov_auto_property_test.cpp @@ -0,0 +1,53 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ov_test.hpp" + +using test_params = std::tuple; + +class ov_auto_plugin_test : public ::testing::TestWithParam { +public: + std::string device_name; + const char* auto_property; + const char* property_value; + bool invalid_value; + +public: + void SetUp() override { + std::tie(device_name, auto_property, property_value, invalid_value) = GetParam(); + } +}; + +TEST_P(ov_auto_plugin_test, ov_core_auto_set_and_get_property_bool) { + ov_core_t* core = nullptr; + OV_EXPECT_OK(ov_core_create(&core)); + EXPECT_NE(nullptr, core); + OV_EXPECT_OK(ov_core_set_property(core, device_name.c_str(), auto_property, property_value)); + char* ret = nullptr; + if (invalid_value) { + OV_EXPECT_NOT_OK(ov_core_get_property(core, device_name.c_str(), auto_property, &ret)); + EXPECT_STRNE(property_value, ret); + } else { + OV_EXPECT_OK(ov_core_get_property(core, device_name.c_str(), auto_property, &ret)); + EXPECT_STREQ(property_value, ret); + } + ov_free(ret); + ov_core_free(core); +} + +const std::vector test_property_config = { + test_params{"AUTO", ov_property_key_intel_auto_device_bind_buffer, "YES", false}, + test_params{"AUTO", ov_property_key_intel_auto_device_bind_buffer, "NO", false}, + test_params{"AUTO", ov_property_key_intel_auto_device_bind_buffer, "TEST", true}, + test_params{"AUTO", ov_property_key_intel_auto_enable_startup_fallback, "YES", false}, + test_params{"AUTO", ov_property_key_intel_auto_enable_startup_fallback, "NO", false}, + test_params{"AUTO", ov_property_key_intel_auto_enable_startup_fallback, "TEST", true}, + test_params{"AUTO", ov_property_key_intel_auto_enable_runtime_fallback, "YES", false}, + test_params{"AUTO", ov_property_key_intel_auto_enable_runtime_fallback, "NO", false}, + test_params{"AUTO", ov_property_key_intel_auto_enable_runtime_fallback, "TEST", true}, +}; + +INSTANTIATE_TEST_SUITE_P(ov_auto_plugin_test_properties, + ov_auto_plugin_test, + ::testing::ValuesIn(test_property_config)); \ No newline at end of file diff --git a/src/bindings/python/src/pyopenvino/core/properties/properties.cpp b/src/bindings/python/src/pyopenvino/core/properties/properties.cpp index 105695e5bc9..d5002d382cf 100644 --- a/src/bindings/python/src/pyopenvino/core/properties/properties.cpp +++ b/src/bindings/python/src/pyopenvino/core/properties/properties.cpp @@ -271,4 +271,13 @@ void regmodule_properties(py::module m) { m_streams.def("num", [](const int32_t value) { return ov::streams::num(ov::streams::Num(value)); }); + + // Submodule auto + py::module m_intel_auto = + m_properties.def_submodule("intel_auto", + "openvino.runtime.properties.intel_auto submodule that simulates ov::intel_auto"); + + wrap_property_RW(m_intel_auto, ov::intel_auto::device_bind_buffer, "device_bind_buffer"); + wrap_property_RW(m_intel_auto, ov::intel_auto::enable_startup_fallback, "enable_startup_fallback"); + wrap_property_RW(m_intel_auto, ov::intel_auto::enable_runtime_fallback, "enable_runtime_fallback"); } diff --git a/src/bindings/python/src/pyopenvino/core/properties/properties.hpp b/src/bindings/python/src/pyopenvino/core/properties/properties.hpp index 7625e58e90e..7437ba8073f 100644 --- a/src/bindings/python/src/pyopenvino/core/properties/properties.hpp +++ b/src/bindings/python/src/pyopenvino/core/properties/properties.hpp @@ -10,6 +10,7 @@ #include "openvino/runtime/properties.hpp" #include "openvino/runtime/intel_cpu/properties.hpp" #include "openvino/runtime/intel_gpu/properties.hpp" +#include "openvino/runtime/auto/properties.hpp" #include "pyopenvino/core/properties/properties.hpp" namespace py = pybind11; diff --git a/src/bindings/python/tests/test_runtime/test_properties.py b/src/bindings/python/tests/test_runtime/test_properties.py index f2a905d38ba..cc8af6d5429 100644 --- a/src/bindings/python/tests/test_runtime/test_properties.py +++ b/src/bindings/python/tests/test_runtime/test_properties.py @@ -268,6 +268,36 @@ def test_properties_ro(ov_property_ro, expected_value): (2.0, 2.0), ), ), + ( + properties.intel_auto.device_bind_buffer, + "DEVICE_BIND_BUFFER", + ( + (True, True), + (False, False), + (1, True), + (0, False), + ), + ), + ( + properties.intel_auto.enable_startup_fallback, + "ENABLE_STARTUP_FALLBACK", + ( + (True, True), + (False, False), + (1, True), + (0, False), + ), + ), + ( + properties.intel_auto.enable_runtime_fallback, + "ENABLE_RUNTIME_FALLBACK", + ( + (True, True), + (False, False), + (1, True), + (0, False), + ), + ), (properties.device.id, "DEVICE_ID", (("0", "0"),)), ( properties.log.level,