5 ms·
Vcc – The Vulkan Clang Compiler
- the__alchemist 3y agoLong overdue. Please give CUDA some competition. It's always been possible to do general purpose compute in Vulkan, but the API was high-friction due to the shader language, and the glue between shader and CPU. It sounds like Vcc is an attempt to address this.
- SubjectToChange 3y agoPlease give CUDA some competition. I doubt Vulkan, a low-level graphics API with compute shaders, could ever directly compete with CUDA, a pure play GPGPU API. Although it isn't hard to imagine situations in which Vulkan compute shaders are sufficient to replace and/or avoid CUDA.
- Const-me 3y ago> the API was high-friction due to the shader language, and the glue between shader and CPU Direct3D 11 compute shaders share these things with Vulkan, yet D3D11 is relatively easy to use. For example, see that library which implements ML-targeted compute shaders for C# with minimal friction: https://github.com/Const-me/Cgml https://github.com/Const-me/Cgml The backend implemented in C++ is rather simple, just binds resources and dispatches these shaders. I think the main usability issue with Vulkan is API design. Vulkan was only designed with AAA game engines in mind. The developers of these game engines have borderline unlimited budgets, and their requirements are very different from ordinary folks who want to leverage GPU hardware.
- pjmlp 3y agoOn top of that, while Vulkan has a fraction of OpenGL lifetime, it isn't shy of outpacing it in extensions spaghetti.
- danielEM 3y agoWell, that is amazing news!!!
- JonChesterfield 3y agoSeems a huge pain relative to freestanding C++ to LLVM IR but more options in this space are welcome.
- novagameco 3y agoI wonder why people haven't coalesced around HLSL; I vastly prefer defining vertices as structs and having cbuffers over declaring every individual uniform or vertex variable with its specific location. It makes much more sense to me to define structs with semantics over saying location(X) for each var or addressing uniforms by name/string. I often see GLSL to HLSL transpilers, but not vice-versa, which is weird because HLSL is the more ergonomic language to me
- pjmlp 3y agoThey have, HLSL has practically won the shading language wars in the games industry, even on consoles, the Playstation and Switch shading languages are heavily inspired on HLSL. Also as I noted on another comment, Khronos is basically leaving to Microsoft HLSL as de facto shading language for Vulkan, as they don't have monetary resources, nor anyone else, interested in improving GLSL as a language. However, as per MSL and HLSL 2021 improvements, alongside SYCL and CUDA, eventually C++ will get the spot, and I doubt this is an area where any of the wannabe C++ replacements can do better.
- pcwalton 3y agoNote that WGSL is closer to Rust than C++--syntactically speaking anyway--and it's pretty much guaranteed to get traction as it'll be the only way to talk to the GPU using a modern API on the Web.
- dang 3y agoSee also https://xol.io/blah/introducing-vcc/ https://xol.io/blah/introducing-vcc/
- Kelteseth 3y agoS̶o̶u̶n̶d̶s̶ ̶c̶o̶o̶l̶,̶ ̶b̶u̶t̶ ̶t̶h̶i̶s̶ ̶r̶e̶q̶u̶i̶r̶e̶s̶ ̶y̶e̶t̶ ̶a̶n̶o̶t̶h̶e̶r̶ ̶l̶a̶n̶g̶u̶a̶g̶e̶ ̶t̶o̶ ̶l̶e̶a̶r̶n̶[0]. As someone who only has limited knowledge in this space, could someone tell me how comparable is the compute functionality of rust-gpu[1], where I can just write rust? [0] https://github.com/Hugobros3/shady#language-syntax https://github.com/Hugobros3/shady#language-syntax [1] https://github.com/EmbarkStudios/rust-gpu https://github.com/EmbarkStudios/rust-gpu Edit: No new language to learn required, this was about IR
- sspiff 3y agoNo, the entire project is about using existing languages (C/C++) on GPUs, the project you linked is their internal IR (intermediate representation) which is what they compile the C/C++ down to before it is turned into a Vulkan compute shader.
- Kelteseth 3y agoAhh, thanks for the clarification!
- fao_ 3y agoIDK that shady is that far from literally any other C-like shader language. Any skill you have in that area is going to transfer (unless you only know Rust, lol)
- g0b 3y agoAs others have commented, Shady is an IR that happens to have a Clang front-end bolted on, that combination is what I call Vcc. I really don't expect people to start writing shaders in the IR directly, even though has a textual form! It's very comparable to Rust-GPU, I actually know a really nice person who does key work on that (you know who you are!) and they're actually facing very similar challenges, and we get to exchange ideas regularly. I am confident it's in good hands.
- slimsag 3y agoI often see folks complain/express confusion about shading languages.. but I think it's often incorrectly stated as syntax of the language, when in reality the confusion is about underlying GPU concepts. Like, people (naturally) want to say 'I know how to write X, and therefor if X can run on the GPU then I can just write X for the GPU and be productive!" but in reality programming for a CPU and GPU are just.. very very different. Vector processing differences.. shader stage concepts.. primitive types like textures/samplers.. bindings.. push constants.. uniforms.. recursion limitations.. dynamic array limitations.. invocation groups.. control flow limitations.. extension hell.. -- these aren't going anywhere Heck, even if you stick with just modern compute APIs like Cuda - as close as you can get to treating the GPU as a general compute device - the way you write code for a GPU using that is just going to be very very different than how most write code for the CPU.
- MahdeenSky 3y agoThis looks interesting, I wonder how this would help Apple M1 Mac's ARM to x86/x64 emulation.
- cloudhan 3y agoI am long sought after a CUDA or HIP compiler that target SPIR-V or DXIL. So that we can compile all thoes neural network kernels to almost all compute devices. The requirements are, 1. extend on C++17 this means template meta programming works so that cub or cutlass/cute works 2. AOT 3. and no shitshow! The only thing that comes to close is circle[1]. - OpenCL is a no go, as it is purely C. And it is full of shitshow especially on Android devices. And the vendor drivers are the main source of shit, jit compile adds the other. - Vulkan+GLSL is a no go. The degree of shitness is on par with OpenCL due to driver and jit compiler. - slang[2] has the potential, but the meta programming part is not as strong as C++, existing libraries cannot be used. The above conclusion is drawn from my work on OpenCL EP for onnxruntime. And it purely is a nightmare to work with thoes drivers and jit compilers. Hopefully Vcc can take compute shader more seriously. [1]: https://www.circle-lang.org/ https://www.circle-lang.org/ [2]: https://shader-slang.com/ https://shader-slang.com/ [3]: https://github.com/microsoft/onnxruntime/tree/dev/opencl https://github.com/microsoft/onnxruntime/tree/dev/opencl
- pjmlp 3y agoWhat about HLSL, specially since it is a kind of C++ flavour, specially after HLSL2021 improvements? https://devblogs.microsoft.com/directx/opening-hlsl-planning/ https://devblogs.microsoft.com/directx/opening-hlsl-planning... https://devblogs.microsoft.com/directx/announcing-hlsl-2021/ https://devblogs.microsoft.com/directx/announcing-hlsl-2021/ At Vulkanised 2023 discussion round Khronos admited that they aren't going to improve GLSL any further, and ironicly rely on Microsoft's HLSL work as the main shader language to go alongside Vulkan. Maybe there is something else discussed at Vulkanises 2024, but I doubt it. There was some SYCL work to target Vulkan, but seems to have been a paper attempt and fizzled out. https://dl.acm.org/doi/fullHtml/10.1145/3456669.3456683 https://dl.acm.org/doi/fullHtml/10.1145/3456669.3456683
- cloudhan 3y agoAt the time of the dev of the EP, the tooling is not that good as current. I have imagined a pipeline that HLSL compiles down to DXIL then go through spirv cross and then target wide variety of mobile devices with opencl runtime. But they are more focused on graphics part and is cannot work with the kernel execution model, not to even mention the structural control flow things, it definitely not going to work. The OpenGL does not work with the imagined pipeline, because IIRC it cannot consume SPIRV bytecode. Vulkan is so niche and discarded very early. The final result with opencl runtime and cl language worked but the driver is a mess [palmface]
- hjabird 3y agoWhat kind of performance is achieveable with some of the features that Vcc enables (true function calls, function pointers, goto), and what are some of the limitations? On GPU, function calls are much more expensive than on CPU. Usually it seems to be worth inlining as much as possible. Implementing a stack for recursion on GPUs is also likely to have performance implications. The whole point of using a GPU is to obtain good performance, but I can see the argument for having these features in order to port CPU code to GPU code incrementally. For function pointers, how does that work? Multiple different implementations of the function are needed to support different devices and the host, which limits what a single pointer can do. EDIT: To answer my second question, neither function nor data pointers are portable between host and device since Vulkan doesn't support unified addressing.
- zozbot234 3y agoStrictly speaking, a stack is only needed for reentrant calls. Function pointers can be implemented via defunctionalization in a whole-program context (i.e. there is a single 'eval' function taking a variant record as an argument, and each case in the variant record marks some function implementation to dispatch to and the corresponding arguments).
- JonChesterfield 3y agoFunction pointers between different architectures can be done. Index into a table, webasm style is the easy option. Writing a prolog that is valid in both architectures works too, I quite like that one. You declare one to be the more important (e.g. x64) and do a hash table lookup on the other. Or the most popular option of crash when calling a pointer from the other arch.
- sevagh 3y agoAre vendor-specific compilers generally clang-based? Emcc (emscripten), aocc (AMD), now vcc (Vulkan). I'm not sure about nvcc (NVIDIA) or icc (Intel)
- hjabird 3y agoIntel's modern compilers (icx, icpx) are clang-based. There is an open-source version [1], and the closed-source version is built atop of this with extra closed-source special sauce. AOCC and ROCm are also based on LLVM/clang. [1] https://github.com/intel/llvm https://github.com/intel/llvm
- sevagh 3y agoI forgot to ask my question which was "why are vendor compilers based on clang over gcc", but it must be related to LLVM?
- xcdzvyn 3y agoIf I had to guess, permissive licensing, better platform support, and the perception of LLVM being easier to target than GCC.
- outworlder 3y agoLLVM is a big part of it. GCC is more opaque (and monolithic) in comparison. Having an intermediate language and a modular architecture makes it easier to build specialized compilers.
- SubjectToChange 3y agoAnother selling point is the Clang CFE, which amortizes the complexity of C++ parsing and semantic analysis, much to the chagrin of the Edison Design Group.
- pjmlp 3y agoMeanwhile EDG are the ones coming up with an usable reflection proposal for C++26, and since Apple and Google stepped out, not many of those profiting from clang are that eager to contribute to upstream fronted.