You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Use full names for `rustc_codegen_*` crates rather than shortened
`cg_*` forms.
- Streamline `rustc_codegen_ssa` description.
- Minor grammer, punctuation, capitalization fixes.
- Fix formatting of some lists.
Copy file name to clipboardExpand all lines: guide/src/faq.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -153,7 +153,7 @@ things to gain in terms of safety using Rust.
153
153
The reasoning for this is the same reasoning as to why you would use CUDA over opengl/vulkan compute shaders:
154
154
- CUDA usually outperforms shaders if kernels are written well and launch configurations are optimal.
155
155
- CUDA has many useful features such as shared memory, unified memory, graphs, fine grained thread control, streams, the PTX ISA, etc.
156
-
- rust-gpu does not perform many optimizations, and with cg_ssa's less than ideal codegen, the optimizations by llvm and libnvvm are needed.
156
+
- rust-gpu does not perform many optimizations, and with rustc_codegen_ssa's less than ideal codegen, the optimizations by llvm and libnvvm are needed.
157
157
- SPIRV is arguably still not suitable for serious GPU kernel codegen, it is underspecced, complex, and does not mention many things which are needed.
158
158
While libnvvm (which uses a well documented subset of LLVM IR) and the PTX ISA are very thoroughly documented/specified.
159
159
- rust-gpu is primarily focused on graphical shaders, compute shaders are secondary, which the rust ecosystem needs, but it also
Copy file name to clipboardExpand all lines: guide/src/nvvm/backends.md
+10-14Lines changed: 10 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,13 +15,13 @@ Nowadays, Rustc is almost fully decoupled from LLVM and it is instead generic ov
15
15
Rustc instead uses a system of codegen backends that implement traits and then get loaded as dynamically linked libraries.
16
16
This allows rust to compile to virtually anything with a surprisingly small amount of work. At the time of writing, there are
17
17
five publicly known codegens that exist:
18
-
-rustc_codegen_clif, cranelift
18
+
-rustc_codegen_cranelift
19
19
- rustc_codegen_llvm
20
20
- rustc_codegen_gcc
21
21
- rustc_codegen_spirv
22
22
- rustc_codegen_nvvm, obviously the best codegen ;)
23
23
24
-
`rustc_codegen_clif` targets the cranelift backend, which is a codegen backend written in rust that is faster than LLVM but does not have many optimizations
24
+
`rustc_codegen_cranelift` targets the cranelift backend, which is a codegen backend written in rust that is faster than LLVM but does not have many optimizations
25
25
compared to LLVM. `rustc_codegen_llvm` is obvious, it is the backend almost everybody uses which targets LLVM. `rustc_codegen_gcc` targets GCC (GNU Compiler Collection)
26
26
which is able to target more exotic targets than LLVM, especially for embedded. `rustc_codegen_spirv` targets the SPIR-V (Standard Portable Intermediate Representation 5)
27
27
format, which is a format mostly used for compiling shader languages such as GLSL or WGSL to a standard representation that Vulkan/OpenGL can use, the reasons
@@ -32,16 +32,12 @@ What NVVM IR/libnvvm are has been covered in the [CUDA section](../../cuda/pipel
32
32
33
33
# rustc_codegen_ssa
34
34
35
-
Despite its name, `rustc_codegen_ssa` does not actually codegen to anything, it is however the central crate behind every single codegen.
36
-
The SSA codegen does most of the hard work in codegen, which is actually codegenning MIR and taking care of managing codegen altogether.
35
+
`rustc_codegen_ssa` is the central crate behind every single codegen and does much of the hard work.
36
+
It abstracts away the MIR lowering logic so that custom codegens only have to implement some
37
+
traits and the SSA codegen does everything else. For example:
38
+
- A trait for getting a type like an integer type.
39
+
- A trait for optimizing a module.
40
+
- A trait for linking everything.
41
+
- A trait for declaring a function.
37
42
38
-
The SSA codegen abstracts away the MIR lowering logic so that custom codegens do not have to implement the time consuming logic of lowering MIR,
39
-
they can just implement a bunch of traits and the SSA codegen does everything else.
40
-
41
-
The SSA codegen is literally just a bunch of traits, for example:
42
-
- A trait for getting a type like an integer type
43
-
- A trait for optimizing a module
44
-
- A trait for linking everything
45
-
- A trait for declaring a function
46
-
...etc
47
-
You will find an SSA codegen trait in almost every single file.
43
+
And so on. You will find an SSA codegen trait in almost every file.
Copy file name to clipboardExpand all lines: guide/src/nvvm/nvvm.md
+19-16Lines changed: 19 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,15 +42,18 @@ dive into each trait.
42
42
43
43
But first, let's talk about the end of the codegen, it is pretty simple, we do a couple of things:
44
44
*after codegen is done and LLVM has been run to optimize each module*
45
-
- 1: We gather every llvm bitcode module we created.
46
-
- 2: We create a new libnvvm program.
47
-
- 3: We add every bitcode module to the libnvvm program.
48
-
- 4: We try to find libdevice and add it to the program (see [nvidia docs](https://docs.nvidia.com/cuda/libdevice-users-guide/introduction.html#what-is-libdevice) on what libdevice is).
49
-
- 5: We run the verifier on the nvvm program just to check that we did not create any invalid nvvm ir.
50
-
- 6: We run the compiler which gives us a final PTX string, hooray!
51
-
- 7: Finally, the PTX goes through a small stage where its parsed and function DCE is run to eliminate
52
-
Most of the bloat in the file, traditionally this is done by the linker but theres no linker to be found for miles here.
53
-
- 8: We write this ptx file to wherever rustc tells us to write the final file.
45
+
1. We gather every LLVM bitcode module we created.
46
+
2. We create a new libnvvm program.
47
+
3. We add every bitcode module to the libnvvm program.
48
+
4. We try to find libdevice and add it to the program (see [nvidia
49
+
docs](https://docs.nvidia.com/cuda/libdevice-users-guide/introduction.html#what-is-libdevice) on
50
+
what libdevice is).
51
+
5. We run the verifier on the nvvm program just to check that we did not create any invalid NVVM IR.
52
+
6. We run the compiler which gives us a final PTX string, hooray!
53
+
7. Finally, the PTX goes through a small stage where its parsed and function DCE is run to
54
+
eliminate most of the bloat in the file. Traditionally this is done by the linker but there's no
55
+
linker to be found for miles here.
56
+
8. We write this PTX file to wherever rustc tells us to write the final file.
54
57
55
58
We will cover the libnvvm steps in more detail later on.
56
59
@@ -71,12 +74,12 @@ rlibs are mysterious files, their origins are mysterious and their contents are
71
74
but rlibs often confuse people (including me at first). Rlibs are rustc's way of encoding basically everything it needs to know
72
75
about a crate into a file. Rlibs usually contain the following:
73
76
- Object files for each CGU.
74
-
- LLVM Bitcode.
75
-
-a Symbol table.
76
-
-metadata:
77
-
- rustc version (because things can go kaboom if version mismatches, ABIs are fun amirite)
77
+
- LLVM bitcode.
78
+
-A symbol table.
79
+
-Metadata:
80
+
-The rustc version (because things can go kaboom if version mismatches, ABIs are fun amirite)
78
81
- A crate hash
79
-
-a crate id
80
-
-info about the source files
81
-
-the exported API, things like macros, traits, etc.
82
+
-A crate id
83
+
-Info about the source files
84
+
-The exported API, things like macros, traits, etc.
82
85
- MIR, for things such as generic functions and `#[inline]`d functions (please don't put `#[inline]` on everything, rustc will cry)
0 commit comments