-
Notifications
You must be signed in to change notification settings - Fork 12.2k
ggml-opencl, llama: using reserve() if count already known #7272
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
Conversation
llama.cpp
Outdated
@@ -6116,6 +6116,7 @@ static bool llm_load_tensors( | |||
mlock_buf->init (ggml_backend_buffer_get_base(buf)); | |||
mlock_buf->grow_to(ggml_backend_buffer_get_size(buf)); | |||
} | |||
bufs.reserve(ml.files.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already reserved on line 6060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it 4ee29e5
ggml-opencl.cpp
Outdated
int64_t i12 = i02 * r2; | ||
int64_t e12 = i12 + r2; | ||
events.reserve(e12 - i12); | ||
while (i12 < e12) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to keep the for
loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it 4ee29e5
for (int64_t i12 = i02 * r2, e12 = i12 + r2; i12 < e12; i12++) { | ||
int64_t i12 = i02 * r2; | ||
int64_t e12 = i12 + r2; | ||
events.reserve(e12 - i12); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future reference: events
is cleared at the end of this inner loop, so its actual maximum capacity is 3
. Even ignoring the clear()
, reserve()
does not grow the vector by the specified amount, it increases the capacity to the specified amount—so you would need to reserve events.size() + e12 - i12
instead, if you were to even bother.
Luckily, this file is gone now, so this particular instance doesn't matter. But we should be more careful going forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cebtenzzre, good catch. More reviewers there are, lower chance making a mistake, you're right.
It affects a lot
ggml_cl_mul_mat_q_f32
function.