Skip to content

Commit 8201823

Browse files
committed
opencl: remove limits on tensor_extra
1 parent fae244b commit 8201823

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

ggml/src/ggml-opencl/ggml-opencl.cpp

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030

3131
#define UNUSED(x) (void)(x)
3232

33-
#define GGML_CL_MAX_NODES 16384
34-
3533
#define CL_CHECK(err) \
3634
do { \
3735
cl_int err_ = (err); \
@@ -1066,41 +1064,32 @@ struct ggml_backend_opencl_buffer_context {
10661064
CL_CHECK(clReleaseMemObject(im));
10671065
}
10681066

1069-
delete[] temp_tensor_extras;
1070-
delete[] temp_tensor_extras_q4_0;
1067+
for (ggml_tensor_extra_cl * e : temp_tensor_extras) {
1068+
delete e;
1069+
}
1070+
for (ggml_tensor_extra_cl_q4_0 * e : temp_tensor_extras_q4_0) {
1071+
delete e;
1072+
}
10711073
}
10721074

10731075
ggml_tensor_extra_cl * ggml_opencl_alloc_temp_tensor_extra() {
1074-
if (temp_tensor_extras == nullptr) {
1075-
temp_tensor_extras = new ggml_tensor_extra_cl[GGML_CL_MAX_NODES];
1076-
}
1077-
1078-
size_t alloc_index = temp_tensor_extra_index;
1079-
temp_tensor_extra_index = (temp_tensor_extra_index + 1) % GGML_CL_MAX_NODES;
1080-
ggml_tensor_extra_cl * extra = &temp_tensor_extras[alloc_index];
1076+
ggml_tensor_extra_cl * extra = new ggml_tensor_extra_cl();
10811077
extra->reset();
1078+
temp_tensor_extras.push_back(extra);
10821079

10831080
return extra;
10841081
}
10851082

10861083
ggml_tensor_extra_cl_q4_0 * ggml_opencl_alloc_temp_tensor_extra_q4_0() {
1087-
if (temp_tensor_extras_q4_0 == nullptr) {
1088-
temp_tensor_extras_q4_0 = new ggml_tensor_extra_cl_q4_0[GGML_CL_MAX_NODES];
1089-
}
1090-
1091-
size_t alloc_index = temp_tensor_extra_index_q4_0;
1092-
temp_tensor_extra_index_q4_0 = (temp_tensor_extra_index_q4_0 + 1) % GGML_CL_MAX_NODES;
1093-
ggml_tensor_extra_cl_q4_0 * extra = &temp_tensor_extras_q4_0[alloc_index];
1084+
ggml_tensor_extra_cl_q4_0 * extra = new ggml_tensor_extra_cl_q4_0();
10941085
extra->reset();
1086+
temp_tensor_extras_q4_0.push_back(extra);
10951087

10961088
return extra;
10971089
}
10981090

1099-
ggml_tensor_extra_cl * temp_tensor_extras = nullptr;
1100-
size_t temp_tensor_extra_index = 0;
1101-
1102-
ggml_tensor_extra_cl_q4_0 * temp_tensor_extras_q4_0 = nullptr;
1103-
size_t temp_tensor_extra_index_q4_0 = 0;
1091+
std::vector<ggml_tensor_extra_cl *> temp_tensor_extras;
1092+
std::vector<ggml_tensor_extra_cl_q4_0 *> temp_tensor_extras_q4_0;
11041093

11051094
// The buffer_context is initially created by ggml_backend_buft_alloc_buffer
11061095
// before any tensor is initialized (at the beginning of alloc_tensor_range).

0 commit comments

Comments
 (0)