[Unicode API] Add wide char for compiler model APIs (#16180)
* [Unicode API] Add wide char for compiler model APIs Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * Avoid duplicated func description Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * Fix format issue Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * Add unite test for wstring of complie model Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * Clear code Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * Add unite test for other compile model unicode APIs Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * Clear log output Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> * Add parameter of device for compiled model unicode test Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com> --------- Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>
This commit is contained in:
1 parent
5e98696464
commit
95636f7715
3 files changed
+231
-2
No files matched your search
@@ -196,22 +196,29 @@ public:
|
||||
* operation.
|
||||
*
|
||||
* @return A compiled model.
|
||||
* @{
|
||||
*/
|
||||
CompiledModel compile_model(const std::string& model_path, const AnyMap& properties = {});
|
||||
|
||||
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
|
||||
CompiledModel compile_model(const std::wstring& model_path, const AnyMap& properties = {});
|
||||
#endif
|
||||
/// @}
|
||||
|
||||
/**
|
||||
* @brief Reads and loads a compiled model from IR / ONNX / PDPD file to the default OpenVINI device selected by
|
||||
* @brief Reads and loads a compiled model from IR / ONNX / PDPD file to the default OpenVINO device selected by
|
||||
* AUTO plugin.
|
||||
*
|
||||
* This can be more efficient than using read_model + compile_model(Model) flow
|
||||
* especially for cases when caching is enabled and cached model is available
|
||||
*
|
||||
* @tparam Properties Should be the pack of `std::pair<std::string, ov::Any>` types
|
||||
* @param model_path path to model
|
||||
* @param model_path path to model with string or wstring
|
||||
* @param properties Optional pack of pairs: (property name, property value) relevant only for this
|
||||
* load operation
|
||||
*
|
||||
* @return A compiled model
|
||||
* @{
|
||||
*/
|
||||
template <typename... Properties>
|
||||
util::EnableIfAllStringAny<CompiledModel, Properties...> compile_model(const std::string& model_path,
|
||||
@@ -219,6 +226,15 @@ public:
|
||||
return compile_model(model_path, AnyMap{std::forward<Properties>(properties)...});
|
||||
}
|
||||
|
||||
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
|
||||
template <typename... Properties>
|
||||
util::EnableIfAllStringAny<CompiledModel, Properties...> compile_model(const std::wstring& model_path,
|
||||
Properties&&... properties) {
|
||||
return compile_model(model_path, AnyMap{std::forward<Properties>(properties)...});
|
||||
}
|
||||
#endif
|
||||
/// @}
|
||||
|
||||
/**
|
||||
* @brief Reads a model and creates a compiled model from the IR/ONNX/PDPD file.
|
||||
*
|
||||
@@ -231,11 +247,19 @@ public:
|
||||
* operation.
|
||||
*
|
||||
* @return A compiled model.
|
||||
* @{
|
||||
*/
|
||||
CompiledModel compile_model(const std::string& model_path,
|
||||
const std::string& device_name,
|
||||
const AnyMap& properties = {});
|
||||
|
||||
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
|
||||
CompiledModel compile_model(const std::wstring& model_path,
|
||||
const std::string& device_name,
|
||||
const AnyMap& properties = {});
|
||||
#endif
|
||||
/// @}
|
||||
|
||||
/**
|
||||
* @brief Reads a model and creates a compiled model from the IR/ONNX/PDPD file.
|
||||
*
|
||||
@@ -249,6 +273,7 @@ public:
|
||||
* load operation.
|
||||
*
|
||||
* @return A compiled model.
|
||||
* @{
|
||||
*/
|
||||
template <typename... Properties>
|
||||
util::EnableIfAllStringAny<CompiledModel, Properties...> compile_model(const std::string& model_path,
|
||||
@@ -257,6 +282,16 @@ public:
|
||||
return compile_model(model_path, device_name, AnyMap{std::forward<Properties>(properties)...});
|
||||
}
|
||||
|
||||
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
|
||||
template <typename... Properties>
|
||||
util::EnableIfAllStringAny<CompiledModel, Properties...> compile_model(const std::wstring& model_path,
|
||||
const std::string& device_name,
|
||||
Properties&&... properties) {
|
||||
return compile_model(model_path, device_name, AnyMap{std::forward<Properties>(properties)...});
|
||||
}
|
||||
#endif
|
||||
/// @}
|
||||
|
||||
/**
|
||||
* @brief Reads a model and creates a compiled model from the IR/ONNX/PDPD memory.
|
||||
* @param model String with a model in IR/ONNX/PDPD format.
|
||||
|
||||
@@ -131,6 +131,12 @@ CompiledModel Core::compile_model(const std::string& model_path, const AnyMap& c
|
||||
return compile_model(model_path, ov::DEFAULT_DEVICE_NAME, config);
|
||||
}
|
||||
|
||||
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
|
||||
CompiledModel Core::compile_model(const std::wstring& model_path, const AnyMap& config) {
|
||||
return compile_model(ov::util::wstring_to_string(model_path), config);
|
||||
}
|
||||
#endif
|
||||
|
||||
CompiledModel Core::compile_model(const std::string& model_path, const std::string& device_name, const AnyMap& config) {
|
||||
OV_CORE_CALL_STATEMENT({
|
||||
auto exec = _impl->compile_model(model_path, device_name, config);
|
||||
@@ -138,6 +144,14 @@ CompiledModel Core::compile_model(const std::string& model_path, const std::stri
|
||||
});
|
||||
}
|
||||
|
||||
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
|
||||
CompiledModel Core::compile_model(const std::wstring& model_path,
|
||||
const std::string& device_name,
|
||||
const AnyMap& config) {
|
||||
return compile_model(ov::util::wstring_to_string(model_path), device_name, config);
|
||||
}
|
||||
#endif
|
||||
|
||||
CompiledModel Core::compile_model(const std::string& model,
|
||||
const ov::Tensor& weights,
|
||||
const std::string& device_name,
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
# define GTEST_COUT std::cerr << "[ ] [ INFO ] "
|
||||
# include <codecvt>
|
||||
# include <functional_test_utils/skip_tests_config.hpp>
|
||||
# include "openvino/pass/manager.hpp"
|
||||
#endif
|
||||
|
||||
namespace ov {
|
||||
@@ -203,6 +204,185 @@ TEST(OVClassBasicTest, smoke_createMockEngineConfigThrows) {
|
||||
}
|
||||
|
||||
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
|
||||
inline void generateModelFile() {
|
||||
ov::pass::Manager manager;
|
||||
manager.register_pass<ov::pass::Serialize>("test_model.xml", "test_model.bin");
|
||||
auto function = ngraph::builder::subgraph::makeConvPoolReluNoReshapes({1, 3, 227, 227});
|
||||
manager.run_passes(function);
|
||||
}
|
||||
|
||||
TEST(OVClassBasicTest, compile_model_no_property_unicode) {
|
||||
std::string model_xml_name = "test_model.xml";
|
||||
std::string model_bin_name = "test_model.bin";
|
||||
generateModelFile();
|
||||
for (std::size_t testIndex = 0; testIndex < CommonTestUtils::test_unicode_postfix_vector.size(); testIndex++) {
|
||||
std::wstring postfix = L"_" + CommonTestUtils::test_unicode_postfix_vector[testIndex];
|
||||
std::wstring modelXmlPathW = CommonTestUtils::addUnicodePostfixToPath(model_xml_name, postfix);
|
||||
std::wstring modelBinPathW = CommonTestUtils::addUnicodePostfixToPath(model_bin_name, postfix);
|
||||
GTEST_COUT << testIndex << ": " << ::ov::util::wstring_to_string(modelXmlPathW) << std::endl;
|
||||
|
||||
try {
|
||||
bool is_copy_successfully;
|
||||
is_copy_successfully = CommonTestUtils::copyFile(model_xml_name, modelXmlPathW);
|
||||
if (!is_copy_successfully) {
|
||||
FAIL() << "Unable to copy from '" << model_xml_name << "' to '"
|
||||
<< ::ov::util::wstring_to_string(modelXmlPathW) << "'";
|
||||
}
|
||||
|
||||
is_copy_successfully = CommonTestUtils::copyFile(model_bin_name, modelBinPathW);
|
||||
if (!is_copy_successfully) {
|
||||
FAIL() << "Unable to copy from '" << model_bin_name << "' to '"
|
||||
<< ::ov::util::wstring_to_string(modelBinPathW) << "'";
|
||||
}
|
||||
|
||||
ov::Core core = createCoreWithTemplate();
|
||||
|
||||
OV_ASSERT_NO_THROW(core.compile_model(modelXmlPathW));
|
||||
CommonTestUtils::removeFile(modelXmlPathW);
|
||||
CommonTestUtils::removeFile(modelBinPathW);
|
||||
GTEST_COUT << "OK" << std::endl;
|
||||
} catch (const ov::Exception& e_next) {
|
||||
CommonTestUtils::removeFile(modelXmlPathW);
|
||||
CommonTestUtils::removeFile(modelBinPathW);
|
||||
CommonTestUtils::removeFile(model_xml_name);
|
||||
CommonTestUtils::removeFile(model_bin_name);
|
||||
FAIL() << e_next.what();
|
||||
}
|
||||
}
|
||||
CommonTestUtils::removeFile(model_xml_name);
|
||||
CommonTestUtils::removeFile(model_bin_name);
|
||||
}
|
||||
|
||||
TEST(OVClassBasicTest, compile_model_with_property_unicode) {
|
||||
std::string model_xml_name = "test_model.xml";
|
||||
std::string model_bin_name = "test_model.bin";
|
||||
generateModelFile();
|
||||
for (std::size_t testIndex = 0; testIndex < CommonTestUtils::test_unicode_postfix_vector.size(); testIndex++) {
|
||||
std::wstring postfix = L"_" + CommonTestUtils::test_unicode_postfix_vector[testIndex];
|
||||
std::wstring modelXmlPathW = CommonTestUtils::addUnicodePostfixToPath(model_xml_name, postfix);
|
||||
std::wstring modelBinPathW = CommonTestUtils::addUnicodePostfixToPath(model_bin_name, postfix);
|
||||
GTEST_COUT << testIndex << ": " << ::ov::util::wstring_to_string(modelXmlPathW) << std::endl;
|
||||
|
||||
try {
|
||||
bool is_copy_successfully;
|
||||
is_copy_successfully = CommonTestUtils::copyFile(model_xml_name, modelXmlPathW);
|
||||
if (!is_copy_successfully) {
|
||||
FAIL() << "Unable to copy from '" << model_xml_name << "' to '"
|
||||
<< ::ov::util::wstring_to_string(modelXmlPathW) << "'";
|
||||
}
|
||||
|
||||
is_copy_successfully = CommonTestUtils::copyFile(model_bin_name, modelBinPathW);
|
||||
if (!is_copy_successfully) {
|
||||
FAIL() << "Unable to copy from '" << model_bin_name << "' to '"
|
||||
<< ::ov::util::wstring_to_string(modelBinPathW) << "'";
|
||||
}
|
||||
|
||||
ov::Core core = createCoreWithTemplate();
|
||||
|
||||
OV_ASSERT_NO_THROW(
|
||||
core.compile_model(modelXmlPathW, ov::hint::performance_mode(ov::hint::PerformanceMode::LATENCY)));
|
||||
CommonTestUtils::removeFile(modelXmlPathW);
|
||||
CommonTestUtils::removeFile(modelBinPathW);
|
||||
GTEST_COUT << "OK" << std::endl;
|
||||
} catch (const ov::Exception& e_next) {
|
||||
CommonTestUtils::removeFile(modelXmlPathW);
|
||||
CommonTestUtils::removeFile(modelBinPathW);
|
||||
CommonTestUtils::removeFile(model_xml_name);
|
||||
CommonTestUtils::removeFile(model_bin_name);
|
||||
FAIL() << e_next.what();
|
||||
}
|
||||
}
|
||||
CommonTestUtils::removeFile(model_xml_name);
|
||||
CommonTestUtils::removeFile(model_bin_name);
|
||||
}
|
||||
|
||||
TEST_P(OVClassBasicTestP, compile_model_with_device_no_property_unicode) {
|
||||
std::string model_xml_name = "test_model.xml";
|
||||
std::string model_bin_name = "test_model.bin";
|
||||
generateModelFile();
|
||||
for (std::size_t testIndex = 0; testIndex < CommonTestUtils::test_unicode_postfix_vector.size(); testIndex++) {
|
||||
std::wstring postfix = L"_" + CommonTestUtils::test_unicode_postfix_vector[testIndex];
|
||||
std::wstring modelXmlPathW = CommonTestUtils::addUnicodePostfixToPath(model_xml_name, postfix);
|
||||
std::wstring modelBinPathW = CommonTestUtils::addUnicodePostfixToPath(model_bin_name, postfix);
|
||||
GTEST_COUT << testIndex << ": " << ::ov::util::wstring_to_string(modelXmlPathW) << std::endl;
|
||||
try {
|
||||
bool is_copy_successfully;
|
||||
is_copy_successfully = CommonTestUtils::copyFile(model_xml_name, modelXmlPathW);
|
||||
if (!is_copy_successfully) {
|
||||
FAIL() << "Unable to copy from '" << model_xml_name << "' to '"
|
||||
<< ::ov::util::wstring_to_string(modelXmlPathW) << "'";
|
||||
}
|
||||
|
||||
is_copy_successfully = CommonTestUtils::copyFile(model_bin_name, modelBinPathW);
|
||||
if (!is_copy_successfully) {
|
||||
FAIL() << "Unable to copy from '" << model_bin_name << "' to '"
|
||||
<< ::ov::util::wstring_to_string(modelBinPathW) << "'";
|
||||
}
|
||||
|
||||
ov::Core core = createCoreWithTemplate();
|
||||
|
||||
OV_ASSERT_NO_THROW(core.compile_model(modelXmlPathW, target_device));
|
||||
CommonTestUtils::removeFile(modelXmlPathW);
|
||||
CommonTestUtils::removeFile(modelBinPathW);
|
||||
GTEST_COUT << "OK" << std::endl;
|
||||
} catch (const ov::Exception& e_next) {
|
||||
CommonTestUtils::removeFile(modelXmlPathW);
|
||||
CommonTestUtils::removeFile(modelBinPathW);
|
||||
CommonTestUtils::removeFile(model_xml_name);
|
||||
CommonTestUtils::removeFile(model_bin_name);
|
||||
FAIL() << e_next.what();
|
||||
}
|
||||
}
|
||||
CommonTestUtils::removeFile(model_xml_name);
|
||||
CommonTestUtils::removeFile(model_bin_name);
|
||||
}
|
||||
|
||||
TEST_P(OVClassBasicTestP, compile_model_with_device_with_property_unicode) {
|
||||
std::string model_xml_name = "test_model.xml";
|
||||
std::string model_bin_name = "test_model.bin";
|
||||
generateModelFile();
|
||||
for (std::size_t testIndex = 0; testIndex < CommonTestUtils::test_unicode_postfix_vector.size(); testIndex++) {
|
||||
std::wstring postfix = L"_" + CommonTestUtils::test_unicode_postfix_vector[testIndex];
|
||||
std::wstring modelXmlPathW = CommonTestUtils::addUnicodePostfixToPath(model_xml_name, postfix);
|
||||
std::wstring modelBinPathW = CommonTestUtils::addUnicodePostfixToPath(model_bin_name, postfix);
|
||||
GTEST_COUT << testIndex << ": " << ::ov::util::wstring_to_string(modelXmlPathW) << std::endl;
|
||||
|
||||
try {
|
||||
bool is_copy_successfully;
|
||||
is_copy_successfully = CommonTestUtils::copyFile(model_xml_name, modelXmlPathW);
|
||||
if (!is_copy_successfully) {
|
||||
FAIL() << "Unable to copy from '" << model_xml_name << "' to '"
|
||||
<< ::ov::util::wstring_to_string(modelXmlPathW) << "'";
|
||||
}
|
||||
|
||||
is_copy_successfully = CommonTestUtils::copyFile(model_bin_name, modelBinPathW);
|
||||
if (!is_copy_successfully) {
|
||||
FAIL() << "Unable to copy from '" << model_bin_name << "' to '"
|
||||
<< ::ov::util::wstring_to_string(modelBinPathW) << "'";
|
||||
}
|
||||
|
||||
ov::Core core = createCoreWithTemplate();
|
||||
|
||||
OV_ASSERT_NO_THROW(core.compile_model(modelXmlPathW,
|
||||
target_device,
|
||||
ov::hint::performance_mode(ov::hint::PerformanceMode::LATENCY)));
|
||||
CommonTestUtils::removeFile(modelXmlPathW);
|
||||
CommonTestUtils::removeFile(modelBinPathW);
|
||||
GTEST_COUT << "OK" << std::endl;
|
||||
} catch (const ov::Exception& e_next) {
|
||||
CommonTestUtils::removeFile(modelXmlPathW);
|
||||
CommonTestUtils::removeFile(modelBinPathW);
|
||||
CommonTestUtils::removeFile(model_xml_name);
|
||||
CommonTestUtils::removeFile(model_bin_name);
|
||||
FAIL() << e_next.what();
|
||||
}
|
||||
}
|
||||
CommonTestUtils::removeFile(model_xml_name);
|
||||
CommonTestUtils::removeFile(model_bin_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPOR
|
||||
TEST_P(OVClassBasicTestP, smoke_registerPluginsXMLUnicodePath) {
|
||||
const std::string pluginXML = getPluginFile();
|
||||
|
||||
|
||||
Reference in new issue
Block a user