Skip to content

Commit 4ee29e5

Browse files
committed
ggml-opencl, llama: using reserve() if count already known
1 parent b228aba commit 4ee29e5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

ggml-opencl.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "ggml.h"
1+
#include "ggml.h"
22
#include "ggml-opencl.h"
33
#include "ggml-backend-impl.h"
44

@@ -1835,7 +1835,10 @@ static void ggml_cl_mul_mat_q_f32(const ggml_tensor * src0, const ggml_tensor *
18351835
CL_CHECK(clEnqueueNDRangeKernel(queue, *to_fp32_cl, 1, &offset, &global, local > 0 ? &local : NULL, events.size(), !events.empty() ? events.data() : NULL, NULL));
18361836
}
18371837

1838-
for (int64_t i12 = i02 * r2, e12 = i12 + r2; i12 < e12; i12++) {
1838+
int64_t i12 = i02 * r2;
1839+
int64_t e12 = i12 + r2;
1840+
events.reserve(e12 - i12);
1841+
for (; i12 < e12; i12++) {
18391842
if (mul_mat_vec) { // specialized dequantize_mul_mat_vec kernel
18401843
// copy src1 to device
18411844
events.emplace_back();

llama.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16062,6 +16062,7 @@ static bool llama_control_vector_init(struct llama_control_vector & cvec, const
1606216062
}
1606316063

1606416064
// make tensors
16065+
cvec.tensors.reserve(model.hparams.n_layer);
1606516066
cvec.tensors.push_back(nullptr); // there's never a tensor for layer 0
1606616067
for (size_t il = 1; il < model.hparams.n_layer; il++) {
1606716068
struct ggml_context * ctx = ctx_map.at(model.buft_layer[il].buft);
@@ -16070,6 +16071,8 @@ static bool llama_control_vector_init(struct llama_control_vector & cvec, const
1607016071
}
1607116072

1607216073
// allocate tensors / buffers and zero
16074+
cvec.ctxs.reserve(ctx_map.size());
16075+
cvec.bufs.reserve(ctx_map.size());
1607316076
for (auto it : ctx_map) {
1607416077
ggml_backend_buffer_type_t buft = it.first;
1607516078
ggml_context * ctx = it.second;

0 commit comments

Comments
 (0)