r/Compilers • • Oct 06 '26

I'm building a tensor graph compiler

I crossposted from r/Zig here before, but removed it quickly and decided this deserved it's own post. Earlier this year, I began work on representing the forward step for a neural network graph defined by the user as a standalone, optimized binary, with no allocations, shape, or validation checks at runtime and through a series of trials and pivots wound up here.

I wasn't necessarily intending to build a compiler from the start, but the problem quickly became compiler shaped, and I've learned a lot while seeing it through. It's coming to a stage where I'd like to share the work, and get feedback from others. The Zig language made this kind of idea fairly direct and simple for me to implement through its use of comptime. So if it interests you, or anything stands out, comments and questions are welcome.

project here: https://github.com/krypticlogan/zig-graph-compiler

Thanks for the read!

7 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/fernando_quintao Oct 09 '26

Hi u/ccannedbeansoupp.

for this kind of problem, where the intention is that entire memory space is known ahead of time can't it actually be optimal?

The classic formalization of this problem is called Dynamic Storage Allocation. The problem is known to be NP-complete. See Luby's paper. So, today we only know of exp-time algorithms to solve it optimally. But there are many good heuristics. Just last year, there was idealloc, for instance.

1

u/ccannedbeansoupp Oct 09 '26

Thanks for all the sources. Now, I'm trying to get the cost heuristics and search frontier to be something that can actually identify a good binary. And then I'm sure memory will quickly become a concern again. I wanted to explore some other ideas for the memory planner but I haven't really changed it much in a while.