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
Open
8 changes: 8 additions & 0 deletions src/bindings/c/docs/api_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,14 @@ This struct represents OpenVINO entity and allows you to manipulate with plugins

- Return value: Status code of the operation: OK(0) for success.

- `ov_status_e ov_core_add_extension(const ov_core_t* core, const char* library_path)`

- Description: Adds an extension to the core.
- Parameters:
- `core` - A pointer `ov_core_t` instance.
- `library_path` - Path to an extension.
- Return value: Status code of the operation: OK(0) for success.

## OV Model

This struct contains the information about the model read from IR and allows you to manipulate with some model parameters such as layers affinity and output layers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ OPENVINO_C_VAR(const char*) ov_property_key_intel_gpu_dev_object_handle;

//!< Read-write property<uint32_t string>: video decoder surface plane in a shared memory blob parameter map.
OPENVINO_C_VAR(const char*) ov_property_key_intel_gpu_va_plane;

//!< Read-write property to pass config file.
OPENVINO_C_VAR(const char*) ov_property_key_intel_gpu_config_file;
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
1 change: 1 addition & 0 deletions src/bindings/c/src/ov_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const char* ov_property_key_hint_execution_mode = "EXECUTION_MODE_HINT";
const char* ov_property_key_force_tbb_terminate = "FORCE_TBB_TERMINATE";
const char* ov_property_key_enable_mmap = "ENABLE_MMAP";
const char* ov_property_key_auto_batch_timeout = "AUTO_BATCH_TIMEOUT";
const char* ov_property_key_intel_gpu_config_file = "CONFIG_FILE";

// Write-only property key
const char* ov_property_key_cache_encryption_callbacks = "CACHE_ENCRYPTION_CALLBACKS";
3 changes: 3 additions & 0 deletions src/bindings/c/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(TARGET_NAME "ov_capi_test")

file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ov_*.cpp test_model_repo.cpp)
file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
list(APPEND DEFINES TEST_CUSTOM_OP_CONFIG_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../../../plugins/intel_gpu/tests/functional/custom_op/custom_op.xml")

if(NOT TARGET OpenCL::OpenCL)
list(FILTER SOURCES EXCLUDE REGEX ov_remote_context_test.cpp)
Expand All @@ -16,6 +17,8 @@ add_executable(${TARGET_NAME} ${SOURCES} ${HEADERS})
target_link_libraries(${TARGET_NAME} PRIVATE openvino_c openvino::util
common_test_utils gtest_main)

target_compile_definitions(${TARGET_NAME} PRIVATE ${DEFINES})

target_include_directories(${TARGET_NAME} PUBLIC
$<BUILD_INTERFACE:${OPENVINO_API_SOURCE_DIR}/include>)

Expand Down
57 changes: 57 additions & 0 deletions src/bindings/c/tests/ov_core_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,35 @@ class ov_core_test : public ov_capi_test_base {
}
};

class ov_core_test_gpu : public ov_capi_test_base {
public:
void SetUp() override {
core = nullptr;
OV_EXPECT_OK(ov_core_create(&core));
EXPECT_NE(nullptr, core);

// Check gpu plugin and hardware available.
bool gpu_device_available = false;
char* info = nullptr;
const char* key = ov_property_key_available_devices;
if (ov_core_get_property(core, "GPU", key, &info) == ov_status_e::OK) {
if (strlen(info) > 0) {
gpu_device_available = true;
}
}
ov_free(info);
if (!gpu_device_available) {
GTEST_SKIP();
}
}

void TearDown() override {
ov_core_free(core);
}

ov_core_t* core;
};

INSTANTIATE_TEST_SUITE_P(ov_core, ov_core_test, ::testing::Values("CPU"));

TEST_P(ov_core_test, ov_core_create_with_config) {
Expand Down Expand Up @@ -126,6 +155,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 Expand Up @@ -721,6 +759,25 @@ TEST_P(ov_core_test, ov_core_compile_model_from_file_unicode) {
}
#endif

INSTANTIATE_TEST_SUITE_P(ov_core_gpu, ov_core_test_gpu, ::testing::Values("GPU"));

TEST_P(ov_core_test_gpu, ov_core_set_get_property_gpu) {
auto device_name = GetParam();
ov_core_t* core = nullptr;
OV_EXPECT_OK(ov_core_create(&core));
EXPECT_NE(nullptr, core);

const char* key_config = "ov_property_key_intel_gpu_config_file";

OV_EXPECT_OK(ov_core_set_property(core, device_name.c_str(), key_config, TEST_CUSTOM_OP_CONFIG_PATH));

char* property_value_config = nullptr;
OV_EXPECT_OK(ov_core_get_property(core, device_name.c_str(), key_config, &property_value_config));
EXPECT_STREQ(TEST_CUSTOM_OP_CONFIG_PATH, property_value_config);

ov_core_free(core);
}

using ov_util_test = ov_core_test;
INSTANTIATE_TEST_SUITE_P(ov_capi_test, ov_util_test, ::testing::Values("CPU"));

Expand Down
8 changes: 7 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 @@ -31,14 +32,19 @@ class ov_capi_test_base : public ::testing::TestWithParam<std::string> {
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() {
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) {
Expand Down
Loading