[all-commits] [llvm/llvm-project] 17065e: [Polly] Allocate packed arrays of matrix multiplic...
Timur Baidusenov via All-commits
all-commits at lists.llvm.org
Wed Sep 30 14:46:43 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 17065e8ad007fa47db2e8541ba00b4fe06cd0205
https://github.com/llvm/llvm-project/commit/17065e8ad007fa47db2e8541ba00b4fe06cd0205
Author: Timur Baidusenov <timurbaidusenov at gmail.com>
Date: 2026-09-30 (Wed, 30 Sep 2026)
Changed paths:
M polly/docs/ReleaseNotes.rst
M polly/lib/Transform/MatmulOptimizer.cpp
A polly/test/ScheduleOptimizer/pattern-matching-based-opts-packed-arrays.ll
Log Message:
-----------
[Polly] Allocate packed arrays of matrix multiplication on heap (#226163)
Problem: The matrix multiplication optimization copies blocks of its
operands into the arrays Packed_A and Packed_B. Their sizes are derived
from the cache parameters rather than from the operands; with the
default parameters, Packed_B takes 4 MiB even for a 100x100 product.
They are allocated with alloca in the entry block of the function, so
two optimized multiplications in one function exceed the default 8 MiB
stack: two products of 100x100 int32 matrices declared as VLAs and
inlined into main crash with a segmentation fault.
Solution: Allocate a packed array on the heap, with malloc at the start
of the SCoP and free at its exit, only if it is larger than
-polly-pattern-matching-max-stack-array-size (1 MiB by default), and
keep smaller ones on the stack. -1 keeps all of them on the stack, 0
puts all of them on the heap. With the default parameters, Packed_B goes
to the heap and Packed_A (192 KiB) stays on the stack.
Default size depends only on the cache parameters. The default
parameters are 32 KiB L1 and 256 KiB L2, both 8-way: the X86 TTI reports
these for every CPU, and they are the Polly defaults for targets whose
TTI reports none. With them, for gemm with float and double on x86-64
(generic, skylake-avx512, znver4) and AArch64 (generic, neoverse-v2), I
get:
- Packed_A: 192 KiB in all cases. It is sized to fit into the L2 cache
and takes at most (1 - 2/associativity) of it.
- Packed_B: 3 to 4 MiB. It holds 256
(-polly-pattern-matching-nc-quotient) micro-panels sized for the L1
cache.
Two Packed_B already exceed the default 8 MiB stack, so Packed_B has to
go to the heap, while Packed_A fits on the stack, like any threshold
from 192 KiB to 3 MiB. I chose 1 MiB because it also keeps Packed_A on
the stack if the L2 parameters are set for current CPUs with up to about
1.25 MiB of L2 (768 KiB for 1 MiB 8-way, 1 MiB for 1.25 MiB 10-way). It
also limits each array on the stack to 1/8 of the default 8 MiB stack of
Linux and macOS.
Assisted-by: Claude (Anthropic)
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list