Skip to content
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

Refactor TL2 codegen #84

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reduce repetition
JCGoran committed Oct 25, 2024
commit d466e944b6bc2d546ba42954360e61ba3d80e78d
36 changes: 12 additions & 24 deletions utils/templates/tl2.h
Original file line number Diff line number Diff line change
@@ -552,34 +552,22 @@ void ggml_qgemm_lut(int bs, int m, int k, int BK, void* A, void* sign, void* LUT
{% for kernel_shape in kernel_shapes %}
{% if loop.index0 > 0 %}else {% endif %}if (m == {{ kernel_shapes[loop.index0][0] }} && k == {{ kernel_shapes[loop.index0][1] }}) {
if (BK == {{ k_list[loop.index0][0] }}) {
if (bs == 1) {
two_qgemm_lut_{{ kernel_shapes[loop.index0][0] }}_{{ kernel_shapes[loop.index0][1] }}<1>(A, LUT, Scales, LUT_Scales, C);
} else if (bs == 8) {
two_qgemm_lut_{{ kernel_shapes[loop.index0][0] }}_{{ kernel_shapes[loop.index0][1] }}<8>(A, LUT, Scales, LUT_Scales, C);
} else if (bs == 32) {
two_qgemm_lut_{{ kernel_shapes[loop.index0][0] }}_{{ kernel_shapes[loop.index0][1] }}<32>(A, LUT, Scales, LUT_Scales, C);
} else if (bs == 128) {
two_qgemm_lut_{{ kernel_shapes[loop.index0][0] }}_{{ kernel_shapes[loop.index0][1] }}<128>(A, LUT, Scales, LUT_Scales, C);
} else if (bs == 256) {
two_qgemm_lut_{{ kernel_shapes[loop.index0][0] }}_{{ kernel_shapes[loop.index0][1] }}<256>(A, LUT, Scales, LUT_Scales, C);
} else if (bs == 512) {
two_qgemm_lut_{{ kernel_shapes[loop.index0][0] }}_{{ kernel_shapes[loop.index0][1] }}<512>(A, LUT, Scales, LUT_Scales, C);
{% set block_sizes = [1, 8, 32, 128, 256, 512] %}
{% set outer_loop = loop %}
{% for bs in block_sizes %}
{% if loop.index0 > 0 %}else {% endif %}if (bs == {{ bs }}) {
two_qgemm_lut_{{ kernel_shapes[outer_loop.index0][0] }}_{{ kernel_shapes[outer_loop.index0][1] }}<{{ bs }}>(A, LUT, Scales, LUT_Scales, C);
}
{% endfor %}
}
else if (BK == {{ k_list[loop.index0][1] }}) {
if (bs == 1) {
three_qgemm_lut_{{ kernel_shapes[loop.index0][0] }}_{{ kernel_shapes[loop.index0][1] }}<1>(A, sign, LUT, Scales, LUT_Scales, C);
}else if (bs == 8) {
three_qgemm_lut_{{ kernel_shapes[loop.index0][0] }}_{{ kernel_shapes[loop.index0][1] }}<8>(A, sign, LUT, Scales, LUT_Scales, C);
}else if (bs == 32) {
three_qgemm_lut_{{ kernel_shapes[loop.index0][0] }}_{{ kernel_shapes[loop.index0][1] }}<32>(A, sign, LUT, Scales, LUT_Scales, C);
}else if (bs == 128) {
three_qgemm_lut_{{ kernel_shapes[loop.index0][0] }}_{{ kernel_shapes[loop.index0][1] }}<128>(A, sign, LUT, Scales, LUT_Scales, C);
}else if (bs == 256) {
three_qgemm_lut_{{ kernel_shapes[loop.index0][0] }}_{{ kernel_shapes[loop.index0][1] }}<256>(A, sign, LUT, Scales, LUT_Scales, C);
}else if (bs == 512) {
three_qgemm_lut_{{ kernel_shapes[loop.index0][0] }}_{{ kernel_shapes[loop.index0][1] }}<512>(A, sign, LUT, Scales, LUT_Scales, C);
{% set block_sizes = [1, 8, 32, 128, 256, 512] %}
{% set outer_loop = loop %}
{% for bs in block_sizes %}
{% if loop.index0 > 0 %}else {% endif %}if (bs == {{ bs }}) {
three_qgemm_lut_{{ kernel_shapes[outer_loop.index0][0] }}_{{ kernel_shapes[outer_loop.index0][1] }}<{{ bs }}>(A, sign, LUT, Scales, LUT_Scales, C);
}
{% endfor %}
}
}
{% endfor %}