I mean, sorta. From the Tensor Seeks Layout paper from Amazon: Layout Selection is NP-hard even when each operator has only a constant number of inputs and each tensor admits only a small number of…

33 points•gmays•4 days ago•8 comments•

8 comments

saagarjhaabout 23 hours ago
> in this case it moved one local_load 6 ops earlier, which caused ptxas to drop from 255 registers to 40. I don’t know why!

This is usually because ptxas runs a very simple pass to try to calculate register usage and it has a number of heuristics that it tries to apply to decide whether to keep things in the same registers or to grab new ones. Usually I find that for very high performance code they are not useful and produce very surprising behavior that makes it hard to predict performance :(

mathisfun1231 day ago
This isn't special - almost every compiler pass is a heuristic approximation of an NP-hard problem (hello register allocation, instruction scheduling).
ebiedermabout 21 hours ago
A small nit. The problem of assigning registers to values (in SSA form) has a single pass optimal solution.

Adding other complexities such as when to spill, and the possibility of reordering computation to reduce the number of registers makes the problem more difficult.

All of which makes me wonder how many of the "NP-hard problems" are in fact easier problems that a covering general case is hard

fookerabout 16 hours ago
There's no guarantee that what's optimal when assigning registers in SSA form remains optimal when you lower out of SSA.

That's why it's a simpler problem with a polynomial time solution, not a magical bypass for np-completeness.

mathisfun123about 20 hours ago
> The problem of assigning registers to values (in SSA form) has a single pass optimal solution

I knew someone would comment this because hn is always "well akshually...". But the parenthetical is doing all the work in this "nit". Yes coloring chordal graphs is polynomial but real compilers don't do register allocation on SSA form. Spilling and spitting break chordal form.

Read the full thread on Hacker News →

Related stories