Skip to content

Commit 213e90e

Browse files
authored
ggml-opencl, llama: using reserve() if count already known (ggml-org#7272)
1 parent 65c5820 commit 213e90e

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
@@ -16162,6 +16162,7 @@ static bool llama_control_vector_init(struct llama_control_vector & cvec, const
1616216162
}
1616316163

1616416164
// make tensors
16165+
cvec.tensors.reserve(model.hparams.n_layer);
1616516166
cvec.tensors.push_back(nullptr); // there's never a tensor for layer 0
1616616167
for (size_t il = 1; il < model.hparams.n_layer; il++) {
1616716168
struct ggml_context * ctx = ctx_map.at(model.buft_layer[il].buft);
@@ -16170,6 +16171,8 @@ static bool llama_control_vector_init(struct llama_control_vector & cvec, const
1617016171
}
1617116172

1617216173
// allocate tensors / buffers and zero
16174+
cvec.ctxs.reserve(ctx_map.size());
16175+
cvec.bufs.reserve(ctx_map.size());
1617316176
for (auto it : ctx_map) {
1617416177
ggml_backend_buffer_type_t buft = it.first;
1617516178
ggml_context * ctx = it.second;

0 commit comments

Comments
 (0)