TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Polyhedral Compilation

32 pointsby lpage4 months ago

5 comments

xelxebar4 months ago
Oh, cool. This came up in a conversation a work somewhat recently, which is where I first heard the term. The basic idea is slick but straightforward:<p>Say you have a multidimensional array, A[i][j] for concreteness. A loop over the array will typically look like nested loops, e.g. assuming we start with a properly initialized array, something like<p><pre><code> for(i=0; i&lt;I; i++) { for(j=i; j&lt;2*i; j++) { A[i+1][j+2]+=A[i][j]; } } </code></pre> Since A[i+1][j+1] has a data dependency on both i and j indicies, the loop has to be executed sequentially over both i and j. However, drawing out the data flow shows how a change of perspective can make the inner loop completely vectorizable. First, let&#x27;s draw the traversed indices on a grid like<p><pre><code> . . . . . o o o o o . . . . o o o o o . . . . . o o o o . . . . . o o o o . . . . . . o o o . . . . . . o o o . . . . . . . o o . . . . . . . o o . . . . . . . . o . . . . . . . . o . . . . . . . . . </code></pre> Notice that we get a polygon in this 2D case. Drawing with more indices and a higher-dimensional pen will give you polyhedron, whence the name! Now connect marked indices that have a data dependency; zooming into the bottom-left corner, it looks something like the below in our example:<p><pre><code> . . &#x2F; o &#x2F; o &#x2F; &#x2F; &#x2F; . o &#x2F; o . &#x2F; &#x2F; . &#x2F; o . . &#x2F; o . . . </code></pre> The key insight here is that we have a bunch of parallel lines, meaning we should be able to start our calculation at all the bottom left points and flow up-and-right (at slope 2!) along each line in parallel. Doing this in code means we want all those lines to be parallel with grid lines as much as possible, reducing the problem to a simple linear transformation of the polygon!<p>In particular, the indices correspond to the grid points and the polygon our data. We want data to be flowing perpendicular to an index in order to parallelize said axis, so crunching out the details of a solution for our example gives<p><pre><code> for(i=0; i&lt;I; i++) { for(j=i; j&lt;2*(i-I); i++, j+=2) { A[i+1][j]+=A[i][j]; } } </code></pre> Notice that array in the inner loop no longer data between j indices any more! That lets us run the entire thing in parallel.<p>That&#x27;s the basic idea anyway.
pvg4 months ago
Small related a thread a few months ago <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=40848340">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=40848340</a>
andybak4 months ago
As someone that frequently searches for code and algorithms related to <i>actual</i> polyhedra, I find this choice of terminology rather irritating.
评论 #42830747 未加载
rurban4 months ago
Most likely this API is used then <a href="https:&#x2F;&#x2F;libisl.sourceforge.io&#x2F;user.html#Polyhedral-Compilation-Library" rel="nofollow">https:&#x2F;&#x2F;libisl.sourceforge.io&#x2F;user.html#Polyhedral-Compilati...</a>
Double_a_924 months ago
I have no idea what this is, and I still have no idea after reading the website.<p>It reads like one of those fake AI written papers about nonsense that seem kinda real at first glance.