Commit e428545f authored by Jean-Matthieu Gallard's avatar Jean-Matthieu Gallard
Browse files

KernelGen - add index_fixed_X macros

parent d56431ec
......@@ -6,6 +6,14 @@
Will simplify 0 index values and fuse dimension if possible index_3(x1,0,x3,L2,L3) => x1*(L2*L3)+x3
The index_fixed macro assume L2, L3, ... represent the full dimension length factoring the inner dimensions.
index_fixed_4(x1,x2,x3,x4,L2,L3,L4) => x1*L2+x2*L3+x3*L4+x4
Will simplify 0 index values (no need to fuse dimensions)
To use without having to specify Lx everytime, define a local macro in your template
Assuming the macro where imported with
{% import "subtemplates/index.template" as i with context %}
......@@ -17,6 +25,7 @@
B[(t*40+y)*2+i]
The index macros are defined recursively to correctly perform the dimension fusion
*/#}
{#
......@@ -45,7 +54,8 @@ Size 3 index
{% else %}
{{index_2("("~x1~"*"~L2~"+"~x2~")",x3,L3)}}{##}
{% endif %}
{% endmacro %}{#
{% endmacro %}
{#
Size 4 index
......@@ -100,4 +110,78 @@ Size 7 index
{% else %}
{{index_6("("~x1~"*"~L2~"+"~x2~")",x3,x4,x5,x6,x7,L3,L4,L5,L6,L7)}}{##}
{% endif %}
{% endmacro %}
{#
Size 2 index fixed size
#}
{% macro index_fixed_2(x1, x2, L2) %}
{% if x1 == 0 or x1 == "0" %}
{{x2}}{##}
{% elif x2 == 0 or x2 == "0" %}{# fuse dimension #}
{{x1}}*{{L2}}{##}
{% else %}
{{x1}}*{{L2}}+{{x2}}{##}
{% endif %}
{% endmacro %}
{#
Size 3 index fixed size
#}
{% macro index_fixed_3(x1, x2, x3, L2, L3) %}
{% if x1 == 0 or x1 == "0" %}
{{index_fixed_2(x2,x3,L3)}}{##}
{% else %}
{{x1~"*"~L2~"+"~index_fixed_2(x2,x3,L3)}}{##}
{% endif %}
{% endmacro %}
{#
Size 4 index fixed size
#}
{% macro index_fixed_4(x1, x2, x3, x4, L2, L3, L4) %}
{% if x1 == 0 or x1 == "0" %}
{{index_fixed_3(x2,x3,x4,L3,L4)}}{##}
{% else %}
{{x1~"*"~L2~"+"~index_fixed_3(x2,x3,x4,L3,L4)}}{##}
{% endif %}
{% endmacro %}
{#
Size 5 index fixed size
#}
{% macro index_fixed_5(x1, x2, x3, x4, x5, L2, L3, L4, L5) %}
{% if x1 == 0 or x1 == "0" %}
{{index_fixed_4(x2,x3,x4,x5,L3,L4,L5)}}{##}
{% else %}
{{x1~"*"~L2~"+"~index_fixed_4(x2,x3,x4,x5,L3,L4,L5)}}{##}
{% endif %}
{% endmacro %}
{#
Size 6 index fixed size
#}
{% macro index_fixed_6(x1, x2, x3, x4, x5, x6, L2, L3, L4, L5, L6) %}
{% if x1 == 0 or x1 == "0" %}
{{index_fixed_5(x2,x3,x4,x5,x6,L3,L4,L5,L6)}}{##}
{% else %}
{{x1~"*"~L2~"+"~index_fixed_5(x2,x3,x4,x5,x6,L3,L4,L5,L6)}}{##}
{% endif %}
{% endmacro %}
{#
Size 7 index fixed size
#}
{% macro index_fixed_7(x1, x2, x3, x4, x5, x6, x7, L2, L3, L4, L5, L6, L7) %}
{% if x1 == 0 or x1 == "0" %}
{{index_fixed_6(x2,x3,x4,x5,x6,x7,L3,L4,L5,L6,L7)}}{##}
{% else %}
{{x1~"*"~L2~"+"~index_fixed_6(x2,x3,x4,x5,x6,x7,L3,L4,L5,L6,L7)}}{##}
{% endif %}
{% endmacro %}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment