Adding a page on additional info regarding JTAG/pinmux test code
[libreriscv.git] / nlnet_2019_opencl.mdwn
1 # NL.net proposal
2
3 ## Project name
4
5 OpenCL hardware support on Libre RISC-V
6
7 ## Website / wiki
8
9 <https://libre-riscv.org/nlnet_2019_opencl>
10
11 Please be short and to the point in your answers; focus primarily on
12 the what and how, not so much on the why. Add longer descriptions as
13 attachments (see below). If English isn't your first language, don't
14 worry - our reviewers don't care about spelling errors, only about
15 great ideas. We apologise for the inconvenience of having to submit in
16 English. On the up side, you can be as technical as you need to be (but
17 you don't have to). Do stay concrete. Use plain text in your reply only,
18 if you need any HTML to make your point please include this as attachment.
19
20 ## Abstract: Can you explain the whole project and its expected outcome(s).
21
22 The Libre RISC-V SoC is being developed to provide a privacy-respecting
23 modern processor, developed transparently and as libre to the bedrock
24 as possible.
25
26 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 low-level software that runs on it.
29
30 Despite the original meaning of GPU, GPUs are not only limited to graphics
31 processing. In fact, there is a quite common use case of using GPUs for
32 more general computation these days. The work of scientists, AI and ML
33 developers, multimedia applications such as FFmpeg, etc., depend on
34 unique traits of GPUs to accelerate their processing. A standard, open API
35 to facilitate this is OpenCL.
36
37 Almost all the major mobile-class GPUs, such as Vivante GC, ARM Mali,
38 Broadcom VideoCore, and Qualcomm Adreno, support OpenCL, but of course
39 they are proprietary implementations which cannot be trusted completely.
40
41 While the mobile-class GPUs have terrible open-source support, at least
42 the bigger GPU names such as AMD and Intel have open-sourced their OpenCL
43 solutions. In addition, since we are reusing the SPIR-V/LLVM/Mesa stack
44 for Vulkan (as detailed in our AMDVLK/RADV NlNet proposal) and OpenGL
45 support, Mesa also happens to come with an OpenCL implementation which
46 we can possibly reuse as well (Gallium/Clover).
47
48 However, these OpenCL implementations tend to be very specific to the
49 vendors processors so we will have to investigate which pieces to reuse
50 and develop our own specific implementation.
51
52 Thus we intend to leverage the excellent work already done to create a
53 libre-licensed commercial-grade OpenCL driver that takes full advantage
54 of the parallelism and vectorisation in the hybrid Libre RISC-V SoC to
55 accelerate compute applications.
56
57 # 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?
58
59 Luke Leighton is an ethical technology specialist who has a consistent
60 24-year track record of developing code in a real-time transparent
61 (fully libre) fashion, and in managing Software Libre teams. He is the
62 lead developer on the Libre RISC-V SoC.
63
64 Jacob Lifshay is a software libre 3D expert who developed a Vulkan 3D
65 software render engine under the GSoc2017 Programme. He also developed
66 his own libre-licensed 32-bit RISC-V processor, and has written an
67 optimising javascript compiler. Jacob is a valuable member of the team and is
68 working on Kazan (https://salsa.debian.org/Kazan-team/kazan)
69
70 # Requested Amount
71
72 EUR 50,000.
73
74 # Explain what the requested budget will be used for?
75
76 After a thorough and comprehensive evaluation to see which will be the
77 best to choose to start from (Intel NEO, AMD ROCm, Mesa Gallium/Clover),
78 we are aiming for a multi-stage process, starting with the basics:
79
80 * The first stage is to make sure we have the necessary hardware
81 support for hardware acceleration of OpenCL. OpenCL would be pointless
82 if all done in software.
83 * The second stage is to create a basic OpenCL
84 driver by looking at how other OpenCL implementations are done.
85 * The third phase will be to begin the iterative
86 process, to experiment in both a software simulator as well as in FPGAs,
87 with the addition of both vectorisation as well as custom opcodes that
88 will significantly improve performance as well as meet
89 commercially-acceptable power-performance demands.
90
91 At the point where commercial power-performance requirements are met and
92 OpenCL applications are able to run on Libre RISC-V without software
93 emulation, we may officially declare the project a "success".
94
95 # Does the project have other funding sources, both past and present?
96
97 The overall project has sponsorship from Purism as well as a prior
98 grant from NLNet. However that is for specifically covering the
99 development of the RTL (the hardware source code).
100
101 Actual development of OpenCL drivers, accelerated by the capabilities
102 of this hybrid design, was not part of the original proposal.
103
104 A previous proposal supported the creation of Kazan which will serve
105 as a Vulkan graphics driver. While Vulkan does have some compute
106 capabilities, its use is limited to the graphics domain. This OpenCL
107 driver will allow for full compute cabilities on Libre RISC-V.
108
109 # Compare your own project with existing or historical efforts.
110
111 The Vivante GC800 is capable of OpenCL but as many other mobile-class
112 GPUs, it is proprietary.
113
114 The Broadcom VideoCore GPU used in Raspberry Pis are also capable of OpenCL.
115 In the future, it is very likely that Libre RISC-V will be used to create
116 a Single-board computer (SBC) just like a Raspberry Pi (possibly by us or
117 third-party).
118
119 Intel's NEO is a modern OpenCL driver that leverages an LLVM-based graphics
120 compiler stack to provide OpenCL usage for Intel GPUs. Compared to other
121 OpenCL implementations, the community considers Intel's to be the best one
122 and NEO also is compliant with the latest OpenCL standard at 2.2.
123
124 AMD's ROCm not only provides an OpenCL driver, but also AMD's own specific
125 compute stack that deviates from OpenCL. ROCm supports an older version
126 of OpenCL 2.0 but not higher.
127
128 Kazan is our Vulkan graphics driver. While Vulkan can be used for a limited
129 set of compute functionality geared towards graphics use-cases, Vulkan is
130 not meant to be used for general-purpose compute.
131
132 There are also some open-source projects (clvk, clspv) to adapt OpenCL on
133 Vulkan, however, given that Vulkan is a completely different API than OpenCL,
134 there will likely be drawbacks to this approach as well as a performance
135 penalty for not having OpenCL support in hardware. Moreover, clvk and clspv
136 only support OpenCL 1.2.
137
138 Nvidia has very limited OpenCL support due mainly to the fact that they have
139 a competing compute solution called CUDA. As such, they are stuck on OpenCL 1.2
140 in order to promote their own proprietary API instead. As a libre project,
141 we cannot support a closed solution such as CUDA and instead we will support
142 the alternative open Khronos standard for compute - OpenCL.
143
144 ## What are significant technical challenges you expect to solve during the project, if any?
145
146 There are many levels to supporting OpenCL. This proposal is for
147 funding the development of hardware acceleration for OpenCL which
148 should be relatively easier to do given that Vulkan and OpenCL share
149 some low-level details.
150
151 We will also detail the software side which will require *far* more
152 engineering resources because we will have to handle the runtime and
153 compiler technology for the OpenCL driver.
154
155 ## Describe the ecosystem of the project, and how you will engage with relevant actors and promote the outcomes?
156
157 As mentioned in the 2018 submission, the Libre RISC-V
158 SoC has a full set of resources for Libre Project Management and development:
159 mailing list, bugtracker, git repository and wiki - all listed here:
160 <https://libre-riscv.org/>
161
162 In addition, we have a Crowdsupply page
163 <https://www.crowdsupply.com/libre-risc-v/m-class> which provides a public
164 gateway, and heise.de, reddit, phoronix, slashdot and other locations have
165 all picked up the story. The list is updated and maintained here:
166 <https://libre-riscv.org/3d_gpu/>
167
168 # Extra info to be submitted
169
170 Applications of OpenCL/GPGPU:
171
172 * <https://en.wikipedia.org/wiki/List_of_OpenCL_applications>
173 * <https://en.wikipedia.org/wiki/General-purpose_computing_on_graphics_processing_units#Applications>
174 * <https://wiki.archlinux.org/index.php/GPGPU>
175
176 Implementations:
177
178 * Intel Neo <https://01.org/compute-runtime>
179 * AMD ROCm <https://rocm.github.io/>
180 * Google clspv <https://github.com/google/clspv>
181 * clvk <https://github.com/kpet/clvk>
182 * Mesa OpenCL <https://gitlab.freedesktop.org/mesa/mesa/tree/master/include/CL>
183 * <https://www.iwocl.org/resources/opencl-implementations/>
184
185 Khronos Vulkan/OpenCL Bridge for future revision of OpenCL which is
186 still in development:
187
188 * <https://www.phoronix.com/scan.php?page=news_item&px=Vulkan-OpenCL-Interop-2019>