CLBlast: Add outer loops over src0 for broadcasting in mulmat #3669
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When broadcasting, each 2D plane of src0 is matched with multiple 2D planes of src1. Planes of src0 need to be copied and/or de-quantized only once per multiple GEMM operations. A more natural way to handle this is to create outer loop over src0 and do copying and de-quantisation there.
Previously, de-quantization was performed before each GEMM. Now it is moved to an outer loop.
There is still duplication in case of broadcasting over dimension 3. Handling that properly would require a more substantial change, i.e. storing 3D instead of 2D slices of src0 in VRAM. I don't know of a case where broadcasting over dimension 3 is currently used, so I leave it for the future. Nevertheless, it produces correct results even in this case.
In case of matrix-vector multiplication, de-quantization is done repeatedly because de-quantized data is not stored in RAM.
Tested in isolation and with models that use GQA.