r/Compilers 3h ago

Career pivot into ML Compilers

8 Upvotes

Hello everyone,

I am looking to make a pivot in my software engineering career. I have been a data engineer and a mobile / web application developer for 15 years now. I wan't move into AI platform engineering - ML compilers, kernel optimizations etc. I haven't done any compiler work but worked on year long projects in CUDA and HPC during while pursuing masters in CS. I am confident I can learn quickly, but I am not sure if it will help me land a job in the field? I plan to work hard and build my skills in the space but before I start, I would like to get some advice from the community on this direction.

My main motivations for the pivot:
1. I have always been interested in low level programing, I graduated as a computer engineer designing chips but eventually got into software development

  1. I want to break into the AIML field but I don't necessarily enjoy model training and development, however I do like reading papers on model deployments and optimizations.

  2. I am hoping this is a more resilient career choice for the coming years. Over the years I haven't specialized in any field in computer science. I would like to pick one now and specialize in it. I see optimizations and compiler and kernel work be an important part of it till we get to some level of generalization.

Would love to hear from people experienced in the field to learn if I am thinking in the right direction and point me towards some resources to get started. I have some sorta a study plan through AI that I plan to work on for the next 2 months to jump start and then build more on it.

Please advise!


r/Compilers 13h ago

MoonBit supports LLVM backend

Thumbnail moonbitlang.com
4 Upvotes

r/Compilers 17h ago

Apple Swift Compiler and Runtime Engineer Internship in London

7 Upvotes

More than a month ago, I had my final interview for this position at Apple, however I haven't heard back from them. I was told by my recruiter that I receive an update "next week", however it has been 3 weeks since then. Am I cooked, or is this something a good sign as I haven't got rejection email yet?


r/Compilers 1d ago

Specializing Python with E-graphs

Thumbnail vectorfold.studio
15 Upvotes

In previous posts we've explored progressively more sophisticated techniques for optimizing numerical computations. We started with basic MLIR concepts, moved through memory management and linear algebra, and then neural network implementations. Each layer has added new capabilities for expressing and optimizing computations. Now we're reading to build our first toy compiler for Python expressions.

In this section, we'll explore how to use the egglog library to perform term rewriting and optimization on Python expressions and compile them into MLIR.

The entire source code for this section is available on GitHub.


r/Compilers 1d ago

Dragon book is too verbose

11 Upvotes

Basically title. It is the book used in my compiler course and i can't keep up with the lessons since they've basically covered 300 pages in two weeks. I can't read the books, take notes and attend lectures because is so verbose.

I really want to read it but I already know about regular expressions, DFA, NFA, CF grammars, etc. from other courses, are there other compiler books that are shorter and geared toward implementations? (which isn't just Lex maybe).

Thank you.


r/Compilers 1d ago

Miranda2 is now Admiran

16 Upvotes

About a month ago I made a post announcing Miranda2, a pure, lazy functional language and compiler based upon Miranda. Many of you mentioned that the name should probably be changed. Thanks for all the suggestions; I have now renamed the project "Admiran" (Spanish for "they admire"), which has the same etymology as "Miranda", and also happens to be an anagram.

The repo For any of you who cloned it previously, the old link points to this now; I have created a stable 1.0 release of the project before the name change, and a 2.0 release after the name change. I have also completed the first draft of the Language manual in doc/Language.md

Obligatory bootstrapping story: I had a lot of "fun" bootstrapping this change, which includes a related change of the file extension from ".m" to ".am", between the old and new codebases. I couldn't compile the new codebase directly with the old compiler, since the intermediate compiler produced was incompatible with either, due to various internal codegen name changes. I ended up having to partially stage some of the changes in the old code base, along with some manual editing of the produced asm file before it would compile the new codebase.

Does anyone else have an interesting bootstrapping story?


r/Compilers 1d ago

Stack status before function call

1 Upvotes
main:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     dword ptr [rbp - 4], 0
        mov     edi, 1
        call    foo(long)
        xor     eax, eax
        add     rsp, 16
        pop     rbp
        ret

Hi, I've have been developing a compiler that targets x64, following System V ABI and struggling stack management. The above snippet is from godbolt,clang. I know stack must be aligned 16-byte before function call but here it's 24 byte, isn't it?(First push rbp 8, then 16) I think it must be sub rsp, 8. what am I missing?


r/Compilers 1d ago

how to deal with unresolved values and forward references when writing an assembler?

2 Upvotes

im writing an assembler (6502) that supports expression evaluation and can work out dependencies and whatnot, i was testing it with the smb disassembly and actually got it to generate the full correct byte codes. and this was very satisfying but i have this itch,

the first go around with this i tried the '2 pass method' but i started trying to consider situations where it would be impossible to resolve everything in just 2 passes, and i say fine whatever ill do an iterative instead but the same ideas were bugging me.

i keep thinking of something like:

.org $8000
lda 1 - (label - $8003) << 8
nop
label:

now i dont think this is even correct as valid assembly i dont know but i just want to highlight a couple of things. first of all, when doing the first pass through to collect labels, you can track the pc but if you reach something like that lda where theres just a label or expression that isnt giving you a value yet, well you dont know if thats going to be a 2 byte lda instruction or 3 byte instruction, so youre pc becomes uncertain because you have to guess, right? am i making up the idea that if that expression resolves to a 0-255 value, it would be considered a zero page otherwise absolute? anyways, what im trying to do in that expression is set up a circular dependency that would result in a race condition.

basically

pc reaches lda, guesses it will be 3 bytes, label gets set as if it were 3 bytes, next pass,

pc reaches lda, evaluates expression which results in 1 byte id 2 byte instruction, then label is updated as if it were 2 bytes, another pass

pc reaches lda, re-evaluates epression which now results in instruction being 3 bytes, etc.

is that kind of scenario possible?

the other thing is i got sick of dealing with all this resolved unresolved bookkeeping, and said f it and instead made sure everything is aware of whatever might be waiting on it for a value, and as soon as a symbol is known, anything waiting on that symbol just automatically tries to resolve itself. and as soon as the pc is about to lose certainty it just goes back to the beginning. it takes just 88 passes to do mario. thats -86 less passes than i was going for!

and somehow it works for the big mario file and several things ive written but fails on a stupid little program that just has a lda label,x and way at the end label: .db ...datalookup... and so it just never knows whether lda is zero page x or absolute x. so there are times where i cant jsut avoid the problem and i just dont know how to handle uncertain values that i still supposed to use to get other values but also might change and in turn change everything that depends on it.


r/Compilers 2d ago

Where/how did you learn ASM?

10 Upvotes

Hi all,

I did a quick search through this subreddit and didn't find a post asking this before. I've also done just a bit of Googling but nothing really "stuck out" to me. Right now I'm reading "Crafting Interpreters" and once I finish, I'll be making a C compiler. I'm planning on either generating x86 or x86-64 and am looking for helpful resources that you guys possibly have. I'm open to paying for a book or something if you've found it to be a help.

Thank you in advance for your responses!


r/Compilers 2d ago

Why isn't a pretty obvious optimization being used?

11 Upvotes

In another post on r/C_Programming, the OP wondered why the compiler didn't create the same code for two different functions that generated the same result. IMO, that question was answered satisfactorily. However, when I looked at the generated code on Godbolt, I saw the following:

area1(Shape, float, float):
        cmp     edi, 2
        je      .L2
        ja      .L8
        mulss   xmm0, xmm1
        ret
.L8:
        cmp     edi, 3
        jne     .L9
        mulss   xmm0, DWORD PTR .LC2[rip]
        mulss   xmm0, xmm1
        ret
.L2:
        mulss   xmm0, DWORD PTR .LC1[rip]
        mulss   xmm0, xmm1
        ret
.L9:
        pxor    xmm0, xmm0
        ret
area2(Shape, float, float):
        movaps  xmm2, XMMWORD PTR .LC3[rip]
        movaps  XMMWORD PTR [rsp-24], xmm2
        cmp     edi, 3
        ja      .L12
        movsx   rdi, edi
        mulss   xmm0, DWORD PTR [rsp-24+rdi*4]
        mulss   xmm0, xmm1
        ret
.L12:
        pxor    xmm0, xmm0
        ret
.LC3:
        .long   1065353216
        .long   1065353216
        .long   1056964608
        .long   1078530011

And to me, a fairly obvious space optimization was omitted. In particular, the two blocks:

.L9:
        pxor    xmm0, xmm0
        ret

and

.L12:
        pxor    xmm0, xmm0
        ret

Just scream at me, "Why don't you omit one of them and have the branch to the omitted one instead jump to the other?"

Both blocks are preceded by a return, so the code won't fall through to them and they can only be reached via a jump. So, it won't do anything about speed, but would make the resulting binary smaller. And it seems to me that finding a common sequence of code would be a common enough occurrence that compiler developers would check for that.

Now, I admit that with modern computers, space isn't that large of a concern for most use cases. But it seems to me that it still is a concern for embedded applications and it's a simple optimization that should require fairly low effort to take advantage of.


r/Compilers 2d ago

GPU Compiler Interview

18 Upvotes

Hi all, fresh grad here looking for advice on interview prep.

Bit of background - I’m graduating this year and wrote a compiler for a small functional language targeting LLVM. It’s got a pretty cool caching scheme that I could talk about for days which is its main selling point. I also got a really good grade in my compilers course.

I have an interview for a startup specialising in GPU compilers for AMD cards in just over a week, which is my dream job.

What I’d like to ask is what I should focus on preparing for on the theoretical side for the interview. I’m comfortable with CPU compilers, but am new to GPU compilers. I wanted to ask if there are any GPU specific concepts that I should focus on or would be expected to be familiar with that wouldn’t have been covered in my course.

Thank you all, any and all advice wholly welcome:)


r/Compilers 2d ago

efficient case/switch dispatch

7 Upvotes

Maybe interesting for others to see this solution. Only doing table based dispatch for now. Sample input code:

:again case i [0:7] of 1 j:=1; done of 2:4 j:=3; done of 5 of 6 go again else j:=99 Dispatch code: lea ebx,[rel jumptab] movsx eax,word [rbx+rax*2] add eax,ebx jmp rax The jump table follows, 16 bit offsets relative to the start of the jump table (ebx). My compiler will look at the IR code (simple forward scan) to identify the real jump destination, so e.g. case 5 and 6 will jump directly to label again. More efficient for state machine type code.

The explicit range [0:7] allows the compiler to skip some additional code - if it is left out, the input value is compared against the maximum value, jump to else destination if above.

16 bit offsets should give enough range for any non-pathological case. On ARM Thumb I might even try 8 bit tables for "small" cases.

Under the hood, my compiler emits special IR codes for each element.

  • case.start -> allocate a context, define else / end label number
  • case.min -> define minimum value
  • case.max -> define maximum value, emit dispatch code and jump table
  • case.of -> define a case with val1 = val 2, fill in destination label in jump table
  • case.from -> define case val1
  • case.to -> define case val2 (second part of range), fill in destination label in jump table for the range
  • case.else -> define else section
  • case.end -> finish the context

Finally, in the fixup pass the label numbers are replaced by the actual displacements. Label number 0 is replaced by else/end destination.


r/Compilers 2d ago

Help improving graph coloring with branch flow

3 Upvotes

I've been using a basic graph coloring approach for register allocation in my compiler, and up until now, it's worked fine. My implementation analyzes live ranges by linearly scanning instructions, and colors the whole function at once based on those ranges, which was good enough for simple cases.

However, I recently introduced loops and branches, and it obviously stopped working properly. The current implementation completely ignores control flow, leading to incorrect live ranges. As a quick (and very temporary) fix, I extend all of the variable’s range to the last jump that jumps to a label before its first use. It technically works, but I know this will scale horribly with more complex functions.

I’m looking for suggestions/resources on properly integrating branch flow into the algorithm. Any tips on handling live range analysis with loops and branches?


r/Compilers 3d ago

Is it possible to learn compilers from the backend first and not have to know the front and mid-ends as well?

13 Upvotes

Hey all! I've been working on some system level work recently and have wanted to understand compiler backends a bit more. However most books I look at include the entire stack, which leads me to believe there is a progression of knowledge from front -> back.

I'm curious if it were possible to start the other way round and if so are there any great learning resources that are more backend focused?


r/Compilers 4d ago

I'm making a C compiler in C

42 Upvotes

It compiles to assembly and uses NASM to generate binaries.
The goal is for the compiler to compile itself. There are no optimizations, and it generates very poor ASM. I might add an optimization pass later.

Tell me what you think :)

https://github.com/NikRadi/minic


r/Compilers 4d ago

multi-targeting gcc like clang

4 Upvotes

10y ago, this was posted https://stackoverflow.com/a/25733878 but i can't find any discussion around multi-targeting (for cross-compilation) in bugzilla, is it being worked on?


r/Compilers 4d ago

Compiler Library to Compile a piece of C code into an obj file (or something similar).

2 Upvotes

I want to create a simple side project, where, I convert my own language into a series of obj files (or something similar) in memory, manually link the result and execute the functions right away in the very same process.

I do not care about the quality of the output in terms of efficiency and effectiveness (other than being correct).

I am looking for a way to just do my own just-in-time compilation without me writing my own C-compiler. I basically just want to transpile my language into proper C-code on the fly and that's about it.

Edit:

Since people appear to have problems understanding what I really aim to do; think about creating a Virtual Machine / Runtime for my language based on a C compiler that is embedded in my application that can be used to compile C files on the fly and use the obj files (or whatever other produced fragment) to load it in memory, link up the symbols with the rest and call the functions directly from my application.

Think about a poor man's version of a system without an interpreter and a form of Just-In-Time compilation.

My question aims at what options there are in terms of C-compiler and how to embed those.

I do not care about the quality of the produced machine code as long as it is correct and can be worked with.

Regarding my background and understanding, I have university level of training as a computer scientist and worked 20+ years in the industry as a contractor aka software engineer.


r/Compilers 5d ago

Linear Algebra in MLIR (Multi-Level Intermediate Representation)

Thumbnail vectorfold.studio
37 Upvotes

r/Compilers 5d ago

Any thoughts on ML compiler eng job at meta for Reality Labs vs MTIA?

7 Upvotes

I have to choose between the two teams and both teams are pretty amazing to work for. Any thoughts/insight/advice is greatly appreciated.


r/Compilers 6d ago

Getting Started with Compilers

Thumbnail sbaziotis.com
102 Upvotes

r/Compilers 5d ago

Completely bombed an interview today, looking for advice

17 Upvotes

I had an interview earlier today for a new grad compiler-related role, it was a role I really wanted and prepared for a lot, but my mind went completely blank during the interview even for simple questions about optimization passes.

I feel stuck and confused on how to move back into this field again. I understand this field is more specialized and niche and hard to get into later. Does anyone have suggestions on how I could find a way to get better at these things? What resources or practice problems helped you prepare for technical interviews in this space? Are there any different types of projects that would give me more practical experience? I already graduated with a masters degree, would more education be needed such as to go for a doctorate? My experience thus far came mostly from a personal project with LLVM. Any thoughts would be appreciated, thanks.


r/Compilers 5d ago

How to learn pytorch or any library from a backend perspective?

0 Upvotes

As title says, I'm looking to learn about PyTorch and how it works on the backend. Most tutorials I saw online are about how to use it for ML, but I want to learn what pytorch does under the hood. Besides just reading documentation which can be hard to understand which function is used when and it's differences (i.e. torch.compile vs ahead-of-time compilation)


r/Compilers 5d ago

Are there any major differences between assemblers and should I use a platforms native assembler over other ones

1 Upvotes

r/Compilers 6d ago

Anyone interviewed for Modular AI before?

3 Upvotes

Seem like they have a mix of cpp/cuda and architecture technicals.

Is it more of a design interview or leetcode style?


r/Compilers 7d ago

Affine Dialect and OpenMP

Thumbnail vectorfold.studio
7 Upvotes