Skip to content

Commit 252ef84

Browse files
committed
Remove unused structs
1 parent 41179c0 commit 252ef84

5 files changed

Lines changed: 33 additions & 81 deletions

File tree

ggml/include/ggml-openvino.h

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
#pragma once
22

33
#include "ggml-backend.h"
4-
#include "ggml.h"
54

6-
#include <array>
75
#include <cstring>
86

97
#ifdef __cplusplus
108
extern "C" {
119
#endif
1210

13-
#define GGML_OPENVINO_NAME "OPENVINO"
14-
#define GGML_OPENVINO_MAX_DEVICES 16
11+
#define GGML_OPENVINO_NAME "OPENVINO"
1512

1613
// backend API
1714
GGML_BACKEND_API ggml_backend_t ggml_backend_openvino_init(int device);
@@ -35,28 +32,6 @@ GGML_BACKEND_API int ggml_backend_openvino_get_device_count(void);
3532

3633
GGML_BACKEND_API ggml_backend_reg_t ggml_backend_openvino_reg(void);
3734

38-
struct ggml_openvino_device_info {
39-
int device_count;
40-
41-
struct openvino_device_info {
42-
int cc; // compute capability
43-
int nsm; // number of streaming multiprocessors
44-
size_t smpb; // max. shared memory per block
45-
size_t smpbo; // max. shared memory per block (with opt-in)
46-
bool vmm; // virtual memory support
47-
size_t vmm_granularity; // granularity of virtual memory
48-
size_t total_vram;
49-
};
50-
51-
openvino_device_info devices[GGML_OPENVINO_MAX_DEVICES] = {};
52-
53-
std::array<float, GGML_OPENVINO_MAX_DEVICES> default_tensor_split = {};
54-
};
55-
5635
#ifdef __cplusplus
5736
}
5837
#endif
59-
60-
#ifdef __cplusplus
61-
const ggml_openvino_device_info & ggml_openvino_info();
62-
#endif

ggml/src/ggml-openvino/ggml-openvino-extra.h

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -172,26 +172,11 @@ void ggml_openvino_buffer_register_extra(ggml_tensor * tensor, ggml_openvino_ext
172172
// OpenVINO Backend Context and Interface
173173
// =====================================================
174174
struct ggml_backend_openvino_context {
175-
int device; // the device ID currently in use
176-
std::string name; // context Name
177-
std::string description; // context description
178-
179-
// OpenVINO runtime context
180-
std::shared_ptr<void> ov_runtime_context;
181-
182-
// OpenVINO Multi-stream support
183-
static const int MAX_STREAMS = 8; // define the maximum number of flows
184-
std::vector<ov::InferRequest> streams; // used to support multi-stream reasoning
185-
int current_stream; // the currently active stream index
186-
187-
// state Management
188-
bool is_initialized; // initialize
189-
190-
ggml_backend_openvino_context() :
191-
device(0),
192-
name("OpenVINO"),
193-
description("OpenVINO Backend Context"),
194-
current_stream(0),
195-
ov_runtime_context(nullptr),
196-
is_initialized(false) {}
175+
int device = 0;
176+
std::string name = "OpenVINO";
177+
std::string description = "OpenVINO Backend Context";
178+
179+
std::shared_ptr<void> runtime_context = nullptr;
180+
181+
ggml_backend_openvino_context() = default;
197182
};

ggml/src/ggml-openvino/ggml-openvino.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "ggml.h"
1010

1111
#include <atomic>
12+
#include <cstdlib>
1213
#include <cstdint>
1314
#include <cstring>
1415
#include <memory>
@@ -627,7 +628,7 @@ static const ggml_backend_i ggml_backend_openvino_interface = {
627628
};
628629

629630
int ggml_backend_openvino_get_device_count() {
630-
return ggml_openvino_info().device_count;
631+
return 1;
631632
}
632633

633634
static ggml_guid_t ggml_backend_openvino_guid(void) {
@@ -649,6 +650,17 @@ GGML_BACKEND_API ggml_backend_t ggml_backend_openvino_init(int device) {
649650
return nullptr;
650651
}
651652

653+
ctx->runtime_context = std::make_shared<ov_runtime_context>();
654+
if (ctx->runtime_context == nullptr) {
655+
GGML_LOG_ERROR("%s: failed to allocate runtime context\n", __func__);
656+
delete ctx;
657+
return nullptr;
658+
}
659+
660+
std::shared_ptr<ov_runtime_context> r_ctx = std::static_pointer_cast<ov_runtime_context>(ctx->runtime_context);
661+
r_ctx->device = ggml_openvino_get_device_name();
662+
r_ctx->stateful = getenv("GGML_OPENVINO_STATEFUL_EXECUTION") && !ggml_openvino_is_npu();
663+
652664
ggml_backend_t openvino_backend = new ggml_backend{
653665
/* .guid = */ ggml_backend_openvino_guid(),
654666
/* .interface = */ ggml_backend_openvino_interface,
@@ -1026,7 +1038,7 @@ static const char * ggml_backend_openvino_reg_get_name(ggml_backend_reg_t reg) {
10261038

10271039
static size_t ggml_backend_openvino_reg_get_device_count(ggml_backend_reg_t reg) {
10281040
GGML_UNUSED(reg);
1029-
return ggml_openvino_info().device_count;
1041+
return (size_t) ggml_backend_openvino_get_device_count();
10301042
}
10311043

10321044
static ggml_backend_dev_t ggml_backend_openvino_reg_get_device(ggml_backend_reg_t reg, size_t index) {
@@ -1035,36 +1047,17 @@ static ggml_backend_dev_t ggml_backend_openvino_reg_get_device(ggml_backend_reg_
10351047
return ctx->devices[index];
10361048
}
10371049

1038-
static void * ggml_backend_openvino_get_proc_address(ggml_backend_reg_t reg, const char * name) {
1039-
GGML_UNUSED(reg);
1040-
GGML_UNUSED(name);
1041-
return nullptr;
1042-
}
1043-
10441050
static const struct ggml_backend_reg_i ggml_backend_openvino_reg_interface = {
10451051
/* .get_name = */ ggml_backend_openvino_reg_get_name,
10461052
/* .get_device_count = */ ggml_backend_openvino_reg_get_device_count,
10471053
/* .get_device = */ ggml_backend_openvino_reg_get_device,
1048-
/* .get_proc_address = */ ggml_backend_openvino_get_proc_address,
1054+
/* .get_proc_address = */ NULL,
10491055
};
10501056

1051-
static int get_openvino_device_count() {
1052-
return 1;
1053-
}
1054-
1055-
static ggml_openvino_device_info ggml_openvino_init() {
1057+
static void ggml_openvino_init() {
10561058
// Initialize device config singleton from env var
10571059
ggml_openvino_init_device_config();
10581060
GGML_LOG_INFO("OpenVINO: using device %s\n", ggml_openvino_get_device_name().c_str());
1059-
1060-
ggml_openvino_device_info info = {};
1061-
info.device_count = get_openvino_device_count();
1062-
return info;
1063-
}
1064-
1065-
const ggml_openvino_device_info & ggml_openvino_info() {
1066-
static ggml_openvino_device_info info = ggml_openvino_init();
1067-
return info;
10681061
}
10691062

10701063
GGML_BACKEND_API ggml_backend_reg_t ggml_backend_openvino_reg(void) {
@@ -1075,9 +1068,11 @@ GGML_BACKEND_API ggml_backend_reg_t ggml_backend_openvino_reg(void) {
10751068
static std::mutex mutex;
10761069
std::lock_guard<std::mutex> lock(mutex);
10771070
if (!initialized) {
1071+
ggml_openvino_init();
1072+
10781073
ggml_backend_openvino_reg_context * ctx = new ggml_backend_openvino_reg_context;
10791074

1080-
for (int i = 0; i < ggml_openvino_info().device_count; i++) {
1075+
for (int i = 0; i < ggml_backend_openvino_get_device_count(); i++) {
10811076
ggml_backend_openvino_device_context * dev_ctx = new ggml_backend_openvino_device_context;
10821077
dev_ctx->device = i;
10831078
dev_ctx->name = GGML_OPENVINO_NAME + std::to_string(i);

ggml/src/ggml-openvino/utils.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,8 @@ enum ggml_status ov_graph_compute(ggml_cgraph * cgraph, ggml_backend_t backend)
4747

4848
const auto is_static = ggml_openvino_is_npu();
4949

50-
if (ctx->ov_runtime_context == nullptr) {
51-
ctx->ov_runtime_context = std::make_shared<ov_runtime_context>();
52-
}
53-
std::shared_ptr<ov_runtime_context> r_ctx = std::static_pointer_cast<ov_runtime_context>(ctx->ov_runtime_context);
54-
r_ctx->device = ggml_openvino_get_device_name();
55-
r_ctx->stateful = false;
56-
if (getenv("GGML_OPENVINO_STATEFUL_EXECUTION") && !is_static) {
57-
r_ctx->stateful = true;
58-
}
50+
GGML_ASSERT(ctx->runtime_context != nullptr);
51+
std::shared_ptr<ov_runtime_context> r_ctx = std::static_pointer_cast<ov_runtime_context>(ctx->runtime_context);
5952

6053
return is_static ? ov_graph_compute_static(cgraph, r_ctx) : ov_graph_compute_dynamic(cgraph, r_ctx);
6154
} catch (const ov::Exception & e) {

ggml/src/ggml-openvino/utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
#include <algorithm>
66
#include <cstddef>
7+
#include <memory>
8+
#include <mutex>
79
#include <openvino/runtime/core.hpp>
810
#include <string>
11+
#include <unordered_map>
12+
#include <vector>
913

1014
struct graph_key {
1115
int n_nodes;

0 commit comments

Comments
 (0)