<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: arial,helvetica,sans-serif; font-size: 10pt; color: #000000'><br><hr id="zwchr"><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><b>From: </b>"Vikram TV via llvm-dev" <llvm-dev@lists.llvm.org><br><b>To: </b>"DEV" <llvm-dev@lists.llvm.org><br><b>Sent: </b>Wednesday, June 8, 2016 2:58:17 AM<br><b>Subject: </b>[llvm-dev] [Proposal][RFC] Cache aware Loop Cost Analysis<br><br><div dir="ltr">Hi,<div><br></div><div>This is a proposal about implementing an analysis that calculates loop cost based on cache data. The primary motivation for implementing this is to write profitability measures for cache related optimizations like interchange, fusion, fission, pre-fetching and others.</div><div><br></div><div id="DWT2019">I have implemented a prototypical version at <a href="http://reviews.llvm.org/D21124" target="_blank">http://reviews.llvm.org/D21124</a>.</div></div></blockquote>I quick comment on your pass: You'll also want to add the ability to get the loop trip count from profiling information from BFI when available (by dividing the loop header frequency by the loop predecessor-block frequencies).<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div></div><div>The patch basically creates groups of references that would lie in the same cache line. Each group is then analysed with respect to innermost loops considering cache lines. Penalty for the reference is:</div><div>a. 1, if the reference is invariant with the innermost loop,</div><div>b. TripCount for non-unit stride access,</div><div>c. TripCount / CacheLineSize for a unit-stride access.</div><div id="DWT1955">Loop Cost is then calculated as the sum of the reference penalties times the product of the loop bounds of the outer loops. This loop cost can then be used as a profitability measure for cache reuse related optimizations. This is just a brief description; please refer to [1] for more details.</div></div></blockquote>This sounds like the right approach, and is certainly something we need. One question is how the various transformations you name above (loop fusion, interchange, etc.) will use this analysis to evaluate the effect of the transformation they are considering performing. Specifically, they likely need to do this without actually rewriting the IR (speculatively).<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div></div><div id="DWT1954">A primary drawback in the above patch is the static use of Cache Line Size. I wish to get this data from tblgen/TTI and I am happy to submit patches on it.</div></div></blockquote>Yes, this sounds like the right direction. The targets obviously need to provide this information.<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div></div><div><br></div><div>Finally, if the community is interested in the above work, I have the following work-plan:</div><div>a. Update loop cost patch to a consistent, commit-able state.</div><div>b. Add cache data information to tblgen/TTI.</div><div id="DWT2018">c. Rewrite Loop Interchange profitability to start using Loop Cost.</div></div></blockquote>Great!<br><br>This does not affect loop interchange directly, but one thing we need to also consider is the number of prefetching streams supported by the hardware prefetcher on various platforms. This is generally, per thread, some number around 5 to 10. Splitting loops requiring more streams than supported, and preventing fusion from requiring more streams than supported, is also an important cost metric. Of course, so is ILP and other factors.<br><br> -Hal<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div></div><div><br></div><div>Please share your valuable thoughts.</div><div><br></div><div>Thank you.</div><div><br></div><div>References:</div><div>[1] [Carr-McKinley-Tseng] <a href="http://www.cs.utexas.edu/users/mckinley/papers/asplos-1994.pdf" target="_blank">http://www.cs.utexas.edu/users/mckinley/papers/asplos-1994.pdf</a></div><div><br></div><div>-- </div><div><div><div dir="ltr"><div><div dir="ltr"><div><br></div><div>Good time...</div><div>Vikram TV</div><div>CompilerTree Technologies</div><div>Mysore, Karnataka, INDIA</div></div></div></div></div>
</div></div>
<br>_______________________________________________<br>LLVM Developers mailing list<br>llvm-dev@lists.llvm.org<br>http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br></blockquote><br><br><br>-- <br><div><span name="x"></span>Hal Finkel<br>Assistant Computational Scientist<br>Leadership Computing Facility<br>Argonne National Laboratory<span name="x"></span><br></div></div></body></html>