No. Compilation is a long and complicated process that doesn't benefit from parallelization.
Some compilers try very hard to do some parallelization, but splitting stuff up is very very hard, and even when possible, any splitting makes the generated code worse and less optimized.
And that's done in maybe 16 parallel jobs. GPUs are made to do thousands or more very small things in parallel. It would be excruciatingly slow to do compilation.
There's a build tool known as Bazel and that's the idea. You break up your project into modules and compile them with different cores. It caches compiled artifacts so if nothing changes, it won't compile it again. Finally, it's distributed locally and over the web so you can set up a team of machines to compile for you. So it makes for incredibly fast builds.
Google developed it internally as Blaze and Bazel is the open source free version. Granted, I don't do any build or tech work anymore, so things may have changed.
People have tried. There's a 2022 paper from Leiden, "Compilation on the GPU? A feasibility study", and they built a small compiler that runs on the GPU (Pareas on GitHub). The problem is that compiling is full of branches and pointer chasing, which GPUs are bad at. So the CPU keeps the homework for now.
If your code consists of several source files which will ultimately be linked together, it's certainly possible to run all the compile steps in parallel; but this is not the kind of parallelization that GPUs are good at. The best use of a GPU is to perform the same lowest-level operation (e.g addition) on multiple operand pairs in a single operation (as in adding two vectors).
Maybe a part of the process could, but when you parallelize something its easiest when you dont have dependancies on one another and can just plan stuff that are mostly independent. Most programming languages let you write some code and use it else where, meaning you now get a dependancy. In theory you could have a process were you covert the code to something intermediate that doesnt actually check if the dependancy exists, but you still need to comeback later and fill that dependancy and because you have these types pf dependancies everything gets slowed down and less parallelizeable. Then you really need to eventually link stuff together to get an executable. I imagine there is probably some parts of the process that would benefit from something like that but it probably makes more sense with more files, but ultimately there is a point where stuff needs to go together. Not everything is nessarily ganna go faster either if you want to parallelize you probably need to spend some overhead to split the task, i imagine smaller work would take longer or failure feedback may come later in the process.
Keep in mind I’m not really a compiler engineer and I may not know much about modern compilers, but this what I would expect from the little I know.
Even with 0 dependency, GPU parallelization is not feasible, because the cores are not independent. GPUs are good at having a lot of cores perform the same set of instructions on ideally adjacent data (SIMD). If you're trying to compile many independent things in parallel, that's when CPU cores sre useful, because they each do their own thing.
I don't have time to find it now, but there was a nice writeup about the parallelization in the Rust compiler. Basically, it first does tokenization, parsing, and a few other parts in parallel. This generates MIR (mid level intermediate representation), which is then fully type checked, borrow checked, etc in parallel. The MIR is then lowered into LLVM IR, which is trivially parallel. Lastly, the LLVM IR is optimized and translated to assembly/bytecode. Generally, each stage in this pipeline needs to be fully competed before the next stage can begin.
The LLVM IR optimization and translation to assembly is actually much harder to parallelize. LLVM has a mechanism to split this work into parallel chunks, but it's not perfect. Specifically, certain optimizations, especially inlining, don't work properly across these chunks, and there is a measurable impact on the final optimized code. The Rust compiler provides an option (and several large projects set it) to not split the LLVM IR into multiple chunks. This is pretty much a direct trade off between compile time and optimization of the generated code.
This being said, GPU-style parallel computation isn't a good fit for compilation. GPUs work best when running the same math across a bunch of inputs (think SIMD if you know what that means), while compilation involves making tons of decisions.
Compiling shaders caused stuttering, so they did the impossible and made an Uber shader that can reconfigure itself, essentially turning the GPU into a live interpreter for a foreign shader.
Nowadays the CPU will still make a new shader and just use the Uber Shader just for the few frames it takes to make one.
That's not worth the effort. Imo where research is best spent is in only compiling what is needed. If 99,8% of the code is already compiled then there'd no reason to recompile it. Many langauges do this to some degree - basically caching. But doing it well it's an hard problem.
Oh there's also a lot SIMD bullshit that can be pulled when parsing text / ASTs
Well and the cpu is able to do more with its instructions, the gpu is mesnt to do like 8 things, across many cores in parallel but like they are the simplest things.
You can do quite a bit in a shader. I.e. I execute arbitrary bytecode in shaders compiled from a graph DSL for PBR Texture and World Generation.
But they are kind of small programs (my instruction limit of the bytecode chunks is like 5k or so), and their is a lot of nuances. I.e. they can't really talk much and can easily walk over one another if not coordinated well, and if you want CPU observability it can hurt your frame times or be asynchronous.
Here's a sample. A ton of things in this use them, i.e. the world generator for the foreground and background.
Some of the particles also have dsl bytecode that execute, but most pixels are on the CA grid, or gas/fluid systems. Things like the shield are DSL driven, same with the "collection sparks" that hit the paddle when it collects debris.
RISC systems (examples being most modern GPUs, ARM, and RISC-V) have a few simple instructions. Each instruction can do little but is simple to implement and optimize.
CISC systems (example being X86) have a bunch of complex instructions. Each instruction can do lots in hardware but you have more instructions.
Newer CPUs are typically CISC systems for a whole bunch of reasons related to performance and power use. Even a modern X86 CPU translates the instructions into a internal microcode to run on a CISC systems inside the processor.
A GPU SM/CU is incredibly complicated. You can think of this as the equivalent of a core on a CPU.
A modern Nivida SM has 32-64 warps that are each typically 32 threads wide.
A warp on a GPU is like a hart on a CPU. It is a separate "thread" to the os scheduler but shares the same resources on the core with the other harts on that core. For example a Intel CPU that has hyperthreading enabled will have 2 harts per core.
The difference is a hart on a CPU only works with a single thread of data. On a modern Nivida GPU each warp does identical operations on 32 threads of data in parallel.
The part that does the execution on each thread is functionally identical on both. The main difference is how it is controlled and replicated across the processor.
For example a 5090 has 170SMs that each have 48 warps that are 32 threads wide. In terms of a CPU this would be a 170 core processor that each core has 48 harts and executes on upto 32 threads of data in parallel.
Funny enough, now that bvh structures for raytracing are often made on the gpu to be handed to the cpu to be handed back to the GPU you could argue the GPU compiles code for the CPU to execute (or tell it to execute) as well.
34
u/KerPop42 5d ago
Is there a way to do code compilation that would benefit from GPU parallelization?
446
u/ilnarildarovuch 5d ago
Support CPU! Especially in doom, where it renders even image
197
u/ProjectSnowman 5d ago
230
u/Drfoxthefurry 5d ago
cpu faster per core but gpu got way more cores
87
u/Dhruv_Malaviya 5d ago
GPU gets all the credit, CPU gets all the homework. Sounds like a group project 💀
10
u/robthemonster 5d ago
what if i told you cpu also compiles code for cpu?
2
u/MiserablyWatchful 3d ago
gpu gets the trophy, CPU did the whole training montage
1
u/Leftover_Salad 4d ago
Outside of shaders, that CPU in this reference belongs to the game devs
0
u/Serializedrequests 4d ago
The whole accidental architectural complexity of running shaders at all is so silly.