7 ms·
LLVM Backend for the VideoCore4, Raspberry Pi 2 VPU
- willvarfar 10y agoIt bugs me that LLVM targets are not properly 'plug in'. LLVM backends can be in a plugin, but you have to tell the frontend which target to use (so it can use the correct data-layout etc). Its the frontends that don't support plug-in targets. Clang, for example, hardcodes the supported targets. A combination of using enums as a 'target triple' and lack of dynamic target registration conspire against easy-to-use out-of-tree targets :(
- krasin 10y agoOut-of-tree targets for LLVM are generally a bad idea given how fast LLVM is changed. Every change could break the out-of-tree target, and being out-of-tree, there's no way the upstream developers could notice that.
- sklogic 10y agoThe other side of this approach is that when the mainline developers do not have much love to a particular platform, it is dropped altogether with little to no remorse - see the fate of Microblaze support, or even the good ol' C backend. I wish we had a more stable API (maybe with a transformation layer) for the backends that may not probably need much of the new features. If LLVM had a maintained transformation layer from the "current" SelectionDAG to a stable one, it would have helped a lot.
- DannyBee 10y ago"A combination of using enums as a 'target triple' and lack of dynamic target registration conspire against easy-to-use out-of-tree targets :( Have you considered this is a deliberate decision, with a goal of having most targets in-tree? :)
- duaneb 10y agoWhy is this beneficial? It means you need to change several repositories to add one target triple. This may be a win in terms of in-tree stability, but it reduces accessibility to everyone else.
- sanxiyn 10y agoIt is beneficial in that it discourages proprietary backends to LLVM which are not contributed back to LLVM. It is the same benefit GCC enjoys by using GPL.
- crazysim 10y agoDoes Apple have some proprietary backends? I guess they have the resources to maintain such.
- duaneb 10y agoYes, they definitely do.
- gsnedders 10y agoLike what, nowadays? I know their ARM64 backend was, but what is now? Do they still maintain forks of them? (With more target data for their SoCs?)
- jevinskie 10y agoGPUs.
- willvarfar 10y agoSwift is still out-of-tree.
- ashitlerferad 10y agoSounds like the LLVM project should be using the GPL. This constant churn kind of turns the MIT license into the GPL but only for small companies and individuals who can't keep up with the churn. I guess that is why Apple likes LLVM.
- Joky 10y agoIt depends what you mean by "plugin": targets are configured at compile time. I don't think you can build LLVM and then dynamically load a backend as plugin.
- willvarfar 10y agoYou can load targets as plugins in llc :) You cannot load targets as plugins in clang :(
- pepijndevos 10y agoWhat can you do with this?
- cnvogel 10y agoThis has some additional info from the author: http://crna.cc/ http://crna.cc/
- pepijndevos 10y agoI get that it's a compiler backend for the GPU of the Raspi, but what does that mean? I mean, can you compile arbitrary C code to run on the GPU? Is this for making a GPU firmware? Divers? games? Bitcoin miners?
- jdmoreira 10y agoWhatever you want. It runs on each GPU core. You can do a lot of DSP for example.
- JonathonW 10y agoAny and all of the above. Although the VideoCore in the Pi is particularly interesting because it's responsible for the early stages of the Pi's boot process (the ARM cores are actually turned off when you initially apply power). Right now, that's all a big Broadcom-proprietary binary chunk; good compilers would be the first step towards freeing that code.
- agumonkey 10y agoLessen the burden from the relatively weak ARM core used as CPU. The VPU seems very potent.
- ciroduran 10y agoThe RPi can handle playing back video (1080p) very well. Raspbian comes with omxplayer which uses the GPU to play video.
- haberman 10y agoYou can run C code on GPUs? I don't know anything about GPUs, but I thought they had a completely different programming model that requires different programming languages and paradigms.
- TD-Linux 10y agoYup. Check out the VideoCore ISA: http://www.broadcom.com/docs/support/videocore/VideoCoreIV-AG100-R.pdf http://www.broadcom.com/docs/support/videocore/VideoCoreIV-A... Note that in this case, the author is writing the bootloader firmware so performance isn't a major concern, though.
- christina_b 10y agoThis isn't the same, the document in question relates to the QPU ISA. The VPU ISA hasn't been officially documented but there were many projects that involved reverse engineering it. The VC4 ISA is documented here: https://github.com/hermanhermitage/videocoreiv https://github.com/hermanhermitage/videocoreiv The VPU is basically a general purpose RISC processor with some fancy vector instructions on top. In fact, most of the firmware that runs on it is written in C.
- TD-Linux 10y agoAh okay, this explains a lot! I somehow thought that the initial boot happened on the QPU.
- corysama 10y agoThey do. Or, at least they did. But, their capabilities have been improving rapidly for a couple decades now. To the point that shader compilers are integrating recent C++ features and some degrees of straight-up C++ support. You won't be able to magically run classic, single-threaded programs fast. But, you can start using advanced features you already know from CPU programming to write programs for the GPU.
- sklogic 10y agoVPU is not a GPU, it was designed for stuff like video decoding. It is just a simple RISC with some SIMD instructions. QPU is a different beast, in VC4 it cannot even run arbitraty C code. In VC5 it can, but inefficiently.
- mangix 10y agodoes this have opencl support now?
- Narishma 10y agoNo.
- Narishma 10y agoVC4 is used in all the Raspberry Pi boards, not just the RPi 2.
- 0xdeadbeefbabe 10y agoHow is this different than using gcc like they describe in this book https://jan.newmarch.name/RPi/ https://jan.newmarch.name/RPi/?
- kenz0r 10y agoThe LLVM backend that has been written generates code that directly runs on the Videocore GPU, which also handles the early boot process. Your link is concerned with code that runs on the ARM core, and interfaces with the GPU via the existing code running on the GPU
- mappu 10y agoOutstanding! Is it possible to use the LLVMLinux patches to run the kernel directly on the VC4?
- q3k 10y agoThere's much more to porting Linux successfully than just having a working compiler for the target architecture.
- christina_b 10y agoVC4 itself doesn't have a MMU per se, it supports very limited memory remap (like PPC BATs) so running a conventional kernel on it is probably not possible. Best bet would be to port an RTOS to it, but my current plan for my firmware pretty much involves halting the VPU once the ARM is running.
- peteforde 10y agoCould this be used to give more direct access to the Raspberry Pi Camera subsystem? Would appreciate any pointers, no pun intended initially.
- puppeh 10y agoI did GCC too, https://github.com/puppeh/vc4-toolchain https://github.com/puppeh/vc4-toolchain.
- christina_b 10y agoYeah, I saw, I haven't looked at it in detail but I think yours probably works better than mine since you did comprehensive testing. My only tests involved compiling my own firmware code, but from what I can tell, it works well, I haven't ran into any bugs yet aside from what I outlined in the README. The assembler/linker I'm using is not ideal, I want to get MC code emission working eventually. I saw that you mentioned limitations on ld/st, why not use lea for data? For example: BB1_12: # %sdram_clkman_update_end.exit2 mov r0, 2114982312 # long ld r2, (r0) lea r0, .str8(pc) # PCrel load lea r1, __FUNCTION__.sdram_init_late(pc) # PCrel load bl xprintf
- puppeh 10y agoNo reason I guess, except it means an extra instruction. I thought about adding a flag for "large model" compilation, but it's not been a priority so far.