Code generation with fully unrolled loops gets extremely slow
- Dominant language
- Python
- Stars
- 636
- Forks
- 81
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 7
Description
We have this simple kernel:
```python
domains = ["{ [i,j,l] : 0 <= i< m and 0 <= j < k and 0<= l < n }"]
instructions = """
C[i,j] = C[i, j] + A[i,l] * B[l,j]
"""
assumptions = "m>0 and n>0 and k>0 and m mod {0} = 0 and n mod {0} = 0 and k mod {0} = 0".format(
MAT_DIM)
outer_knl = lp.make_kernel(domains, instructions,
target=lp.CFamilyTarget(), assumptions=assumptions,name=name)
outer_knl = lp.add_and_infer_dtypes(
outer_knl, {"A,B,C": np.float64, "m,n,k": outer_knl.index_dtype})
```
Simply generating Code and header like this
```python
code = lp.generate_code_v2(outer_knl)
header = str(lp.generate_header(outer_knl,code)[0])
```
with no transformations is unproblematic and fast.
Fully unrolling all of these loops gets extremely slow with even small loop sizes.
Adding these transformations:
```python
outer_knl = lp.split_iname(outer_knl, "i", MAT_DIM)
outer_knl = lp.split_iname(outer_knl, "j", MAT_DIM)
outer_knl = lp.split_iname(outer_knl, "l", MAT_DIM)
outer_knl = lp.tag_inames(outer_knl, dict(i_inner="unr"))
outer_knl = lp.tag_inames(outer_knl, dict(j_inner="unr"))
outer_knl = lp.tag_inames(outer_knl, dict(l_inner="unr"))
outer_knl = lp.tag_inames(outer_knl, dict(i_outer="unr"))
outer_knl = lp.tag_inames(outer_knl, dict(j_outer="unr"))
outer_knl = lp.tag_inames(outer_knl, dict(l_outer="unr"))
outer_knl = lp.add_prefetch(outer_knl, "A[:,l]", default_tag="l.auto")
outer_knl = lp.add_prefetch(outer_knl, "B[l,:]", default_tag="l.auto")
outer_knl = lp.tag_inames(outer_knl, dict(A_dim_0="unr"))
outer_knl = lp.tag_inames(outer_knl, dict(B_dim_1="unr"))
outer_knl = lp.fix_parameters(outer_knl, m=MAT_DIM, n=MAT_DIM, k=MAT_DIM)
```
Running this with MAT_DIM = 100 already takes over an hour on a reasonably fast CPU (Ryzen 5 3600). Is a fully unrolled program not intended or is there some way to speed this up?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.