Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C API] Add ov_core_add_extension C API #26670

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
10 changes: 10 additions & 0 deletions src/bindings/c/include/openvino/c/ov_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ ov_core_compile_model(const ov_core_t* core,
ov_compiled_model_t** compiled_model,
...);

/**
* @brief Adds an extension to the core.
* @ingroup ov_core_c_api
* @param core A pointer to the ov_core_t instance.
* @param library_path Path to an extension.
* @return Status code of the operation: OK(0) for success.
*/
OPENVINO_C_API(ov_status_e)
ov_core_add_extension(const ov_core_t* core, const char* library_path);
riverlijunjie marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Reads a model and creates a compiled model from the IR/ONNX/PDPD file.
* This can be more efficient than using the ov_core_read_model_from_XXX + ov_core_compile_model flow,
Expand Down
12 changes: 12 additions & 0 deletions src/bindings/c/src/ov_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ ov_status_e ov_core_read_model_from_memory_buffer(const ov_core_t* core,
return ov_status_e::OK;
}

ov_status_e ov_core_add_extension(const ov_core_t* core, const char* extension_path) {
if (!core || !extension_path) {
return ov_status_e::INVALID_C_PARAM;
}

try {
core->object->add_extension(extension_path);
}
CATCH_OV_EXCEPTIONS
return ov_status_e::OK;
riverlijunjie marked this conversation as resolved.
Show resolved Hide resolved
praasz marked this conversation as resolved.
Show resolved Hide resolved
}

ov_status_e ov_core_compile_model(const ov_core_t* core,
const ov_model_t* model,
const char* device_name,
Expand Down
9 changes: 9 additions & 0 deletions src/bindings/c/tests/ov_core_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ TEST_P(ov_core_test, ov_core_compile_model) {
ov_core_free(core);
}

TEST_P(ov_core_test, ov_core_add_extension) {
ov_core_t* core = nullptr;
OV_EXPECT_OK(ov_core_create(&core));
EXPECT_NE(nullptr, core);

OV_EXPECT_OK(ov_core_add_extension(core, extension_file_path.c_str()));
ov_core_free(core);
}

TEST_P(ov_core_test, ov_core_compile_model_with_property) {
auto device_name = GetParam();
ov_core_t* core = nullptr;
Expand Down
11 changes: 10 additions & 1 deletion src/bindings/c/tests/ov_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <fstream>
#include <openvino/util/file_util.hpp>

#include "common_test_utils/file_utils.hpp"
#include "openvino/c/openvino.h"
#include "openvino/openvino.hpp"
#include "test_model_repo.hpp"
Expand All @@ -25,22 +26,30 @@
extern std::map<ov_element_type_e, size_t> element_type_size_map;
#define GET_ELEMENT_TYPE_SIZE(a) element_type_size_map[a]

inline std::string get_extension_file_path();

class ov_capi_test_base : public ::testing::TestWithParam<std::string> {
public:
void SetUp() override {
TestDataHelpers::generate_test_model();
xml_file_name = TestDataHelpers::get_model_xml_file_name();
bin_file_name = TestDataHelpers::get_model_bin_file_name();
extension_file_path = get_extension_file_path();
}

void TearDown() override {
TestDataHelpers::release_test_model();
}

public:
std::string xml_file_name, bin_file_name;
std::string xml_file_name, bin_file_name, extension_file_path;
};

inline std::string get_extension_file_path() {
praasz marked this conversation as resolved.
Show resolved Hide resolved
return ov::util::make_plugin_library_name<char>(ov::test::utils::getExecutableDirectory(),
std::string("openvino_template_extension") + OV_BUILD_POSTFIX);
}

inline size_t find_device(ov_available_devices_t avai_devices, const char* device_name) {
for (size_t i = 0; i < avai_devices.size; ++i) {
if (strstr(avai_devices.devices[i], device_name))
Expand Down
Loading