(no commit message)
[libreriscv.git] / nlnet_2019_amdvlk_port.mdwn
1 # NL.net proposal 2019-10-042
2
3 * [[questions]]
4
5 ## Project name
6
7 Port of AMDVLK/RADV 3D Driver to the Libre RISC-V SoC
8
9 ## Website / wiki
10
11 <https://libre-riscv.org/nlnet_2019_amdvlk_port>
12
13 Please be short and to the point in your answers; focus primarily on
14 the what and how, not so much on the why. Add longer descriptions as
15 attachments (see below). If English isn't your first language, don't
16 worry - our reviewers don't care about spelling errors, only about
17 great ideas. We apologise for the inconvenience of having to submit in
18 English. On the up side, you can be as technical as you need to be (but
19 you don't have to). Do stay concrete. Use plain text in your reply only,
20 if you need any HTML to make your point please include this as attachment.
21
22 ## Abstract: Can you explain the whole project and its expected outcome(s).
23
24 The Libre RISCV SoC is being developed to provide a privacy-respecting
25 modern processor, developed transparently and as libre to the bedrock
26 as possible. As a hybrid processor, it is intended to be both a CPU
27 *and* a GPU. GPUs are normally proprietary (and thus are perfect candidate
28 attack vectors), as is the 3D driver software.
29
30 In January 2019, AMD released a fully-functioning libre-licensed Vulkan
31 Driver for their Radeon GPUs. A close examination of its source code
32 shows that it would be relatively straightforward to replace the libraries
33 that generate Radeon GPU assembly code with ones that generate assembly
34 for the Libre RISC-V SoC, instead.
35
36 In addition, further investigation shows that RADV, the libre-licensed
37 MESA 3D Driver, also supports SPIR-V (by way of conversion to MESA NIR),
38 and, likewise, may be a good candidate for replacing Radeon with Libre
39 RISC-V assembly.
40
41 Thus we intend to do exactly that: leverage the excellent work already
42 done to create a libre-licensed commercial-grade Vulkan 3D driver that
43 takes full advantage
44 of the parallelism and Vectorisation in the hybrid Libre RISC-V SoC.
45
46 # Have you been involved with projects or organisations relevant to this project before? And if so, can you tell us a bit about your contributions?
47
48 Luke Leighton is an ethical technology specialist who has a consistent
49 24-year track record of developing code in a real-time transparent
50 (fully libre) fashion, and in managing Software Libre teams. He is the
51 lead developer on the Libre RISC-V SoC.
52
53 Jacob Lifshay is a software libre 3D expert who developed a Vulkan 3D
54 software render engine under the GSoc2017 Programme. He also developed
55 his own libre-licensed 32-bit RISC-V processor, and has written an
56 optimising javascript compiler. Jacob is a valuable member of the team and is
57 working on Kazan (https://salsa.debian.org/Kazan-team/kazan)
58
59 # Requested Amount
60
61 EUR 50,000.
62
63 # Explain what the requested budget will be used for?
64
65 After a thorough and comprehensive evaluation to see which will be the
66 best to choose (RADV or AMDVLK), we are aiming for a multi-stage process,
67 starting with the basics:
68
69 * The first stage is to remove AMD's "PAL" Library in AMDVLK, or the
70 AMDGPU engine used in RADV, and replace it with a straightforward
71 upstream port of the current LLVM JIT compiler, alongside a "support"
72 library that will call OpenCL / OpenGL functions directly on the main
73 processor. This "effectively" turns the engine into a peer of google
74 swiftshader (a "Software 3D Renderer") which will allow us to carry out
75 rapid testing on stable x86 systems before moving on to the next stage.
76 * The second stage is to confirm that the standard RISC-V LLVM JIT
77 (which was recently upstreamed as of LLVM 9.0.0) is properly functional
78 under an emulator or other RV64GC system.
79 * The third phase will be to begin the iterative process, tying in closely
80 with the work on Kazan, to experiment in both a software simulator
81 as well as in FPGAs, with the addition of both Vectorisation as well
82 as custom opcodes that will significantly improve performance as well
83 as meet commercially-acceptable power-performance demands.
84
85 At the point where commercial power-performance requirements are met we may
86 officially declare the project a "success".
87
88 # Does the project have other funding sources, both past and present?
89
90 The overall project has sponsorship from Purism as well as a prior grant
91 from NLNet. However that is for specifically covering the development
92 of the RTL (the hardware source code), and for a "parallel" 3D Vulkan
93 Driver effort, Kazan.
94
95 Kazan is to be written in Rust and its inclusion in the initial 2018
96 proposal was *before* AMDVLK was released (Jan 2019). AMDVLK is written
97 in c++, is a significant way along (further than Kazan), however there
98 is a different design focus in each that makes choosing one over the
99 other not only difficult but potentially a costly mistake.
100
101 # Compare your own project with existing or historical efforts.
102
103 Nyuzi is a Software-based 3D Engine that has an LLVM port. The problem
104 is that it has deliberately been designed to be a software-only
105 Vector Processor. As such, with no custom accelerated opcodes
106 dedicated to 3D, its power-performance metric is a whopping 25% that of
107 commercially-acceptable 3D GPUs. It also has no actual 3D Vulkan Driver:
108 the developers focussed only on the "core algorithms" as part of an
109 (extremely useful) academic exercise, only.
110
111 Google's swiftshader is a software-based 3D Driver/Engine that is compatible
112 with at least one version of Vulkan. On the face of it, this would be a
113 perfect match for the Libre RISC-V SoC due to it being a hybrid CPU / GPU.
114 The problem is that swiftshader was designed - from the ground up - never
115 to have Vectorisation or any form of accelerated hardware beyond SIMD
116 (NEON, Altivec, SSE/AVX). As Nyuzi clearly shows, this approach is
117 known to give a massive 400% power penalty. Not only that, but our
118 additions would not be welcome due to the primary focus of swiftshader
119 being on non-hardware-accelerated, non-custom processors.
120
121 RADV is the free software competitor to AMDVLK. It takes a different
122 route: converting SPIR-V to NIR (New Internal Representation) which will
123 need close evaluation to ensure that it's directly suited to Vector
124 Processing. Like AMDVLK, it does not directly support RISC-V: it was
125 purely intended to support Radeon GPUs.
126
127 Our initial proposal - Kazan - is much more interesting to discern and
128 compare against. Kazan is being specifically designed so that the
129 SPIR-V compiler is capable of fully supporting "full-function vectorisation".
130 LLVM IR does *NOT* normally support this (which is why SPIR-V was created
131 by the Khronos Group in the first place). However, AMDVLK, which is a
132 hard fork of LLVM, has had its LLVM-IR specifically modified to support
133 both full-function vectorisation, predication, and in addition, texturisation,
134 such that this information may be "carried" down to the Radeon assembly level,
135 through the PAL library.
136
137 Standard LLVM does *not* support this full-function vectorisation
138 capability: it is typically left up to any given assembly-level
139 converter (such as the RISC-V Vector Engine) to "opportunistically"
140 turn non-vectorised programs *into* vectorised ones, whereas AMDVLK
141 *explicitly* carries this very same information.
142
143 Kazan on the other hand intends to perform explicit Vectorisation
144 code-transformations in a different location: inside the SPIR-V compiler
145 itself. This key radical technical difference is why we seek to explore
146 the alternative approach taken by AMD side-by-side with that of Kazan,
147 because it is just not possible to predict in advance which would be "better".
148
149 ## What are significant technical challenges you expect to solve during the project, if any?
150
151 This is compiler technology, which is traditionally viewed as particularly
152 challenging. We are slightly fortunate in that much of the pieces of
153 the puzzle already exist: AMDVLK, RADV, the upstreamed acceptance of
154 RISC-V LLVM 9.0.0 being the key ones.
155
156 Whilst we know *technically* what they did and why they did it, the key
157 challenge will be to unravel what exact changes AMD made which caused
158 them to have to "fork" LLVM several years back, to keep track of their
159 efforts to introduce "mainline" LLVM patches on an ongoing piecemeal
160 basis, and at the same time *add our own assembler back-end* into the
161 same fast-moving target.
162
163 Whereas with RADV it is upstreamed in MESA, and has much wider community
164 support, it will need very careful detailed evaluation to ensure that it meets
165 the needs of the Libre RISC-V Vector Engine.
166
167 ## Describe the ecosystem of the project, and how you will engage with relevant actors and promote the outcomes?
168
169 As mentioned in the 2018 submission, the Libre RISC-V
170 SoC has a full set of resources for Libre Project Management and development:
171 mailing list, bugtracker, git repository and wiki - all listed here:
172 <https://libre-riscv.org/>
173
174 In addition, we have a Crowdsupply page
175 <https://www.crowdsupply.com/libre-risc-v/m-class> which provides a public
176 gateway, and heise.de, reddit, phoronix, slashdot and other locations have
177 all picked up the story. The list is updated and maintained here:
178 <https://libre-riscv.org/3d_gpu/>
179
180 # Extra info to be submitted
181
182 * <http://libre-riscv.org/3d_gpu/>
183 * <https://nlnet.nl/project/Libre-RISCV/>
184 * <https://github.com/GPUOpen-Drivers/AMDVLK>
185 * <https://github.com/google/swiftshader/>
186 * <https://salsa.debian.org/Kazan-team/kazan>
187 * <https://github.com/mesa3d/mesa/tree/master/src/amd/vulkan>
188
189 # Management Summary
190
191 The Libre SoC Project core is funded from an initial 2018 proposal. This includes a 3D Driver, called Kazan, and its purpose is to provide a Vulkan compliant hybrid hardware-software API. Given the complex nature of 3D driver development, and because Kazan is a novel approach (written in rust, for security reasons) a second oroposal was submitted to develop a Mesa3D driver (in c++). A second more traditional (c++) 3D Driver allows for increased transparency and collaboration on this ambitious project.