Skip to content

opencl: add set_rows for f16 and f32 #14547

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lhez
Copy link
Collaborator

@lhez lhez commented Jul 6, 2025

Following a70c8a0, this PR adds set_rows for f16 and f32.

Make sure to read the contributing guidelines before submitting a PR

@github-actions github-actions bot added ggml changes relating to the ggml tensor library for machine learning OpenCL Issues specific to the OpenCL backend labels Jul 6, 2025
Comment on lines 3482 to 3486

int nth0 = 256;
size_t global_work_size[] = {(size_t)ne01*nth0, (size_t)ne02, (size_t)ne03};
size_t local_work_size[] = {(size_t)nth0, 1, 1};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that implementing it like this won't be very efficient. This dedicates 256 threads for each row of data. So for small rows with less than 256 elements, there will be wasted resources. For example, when FA is disabled, ggml_set_rows() is used with rows of 1 element (due to the V cache being transposed), so 255 out of the 256 local threads will be idle.

That's why in the Metal implementation I did "threadgroup batching" so that the local threads can work on multiple rows. Might want to consider implementing it here too for improved performance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the suggestion - it makes a good point. Looking into this.

@lhez lhez marked this pull request as ready for review July 7, 2025 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ggml changes relating to the ggml tensor library for machine learning OpenCL Issues specific to the OpenCL backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants