184 points · by rjinman · 2y ago · 24 comments
I don't see many other people using Vulkan for GPGPU, and there may be many good reasons for that, but I wanted to try something a bit different.
I've made every attempt to make the code very clean and readable and I've written up the math in documentation/math.pdf, so hopefully this is a useful learning resource for anyone interested in how neural nets work under the hood.
I'll be continuing to add new features over the coming months.
> don't see many other people using Vulkan for GPGPU, and there may be many good reasons for that
I think the main of these reasons is nVidia’s contributions to the ecosystem. It’s much easier to call library functions implemented by cuDNN or cuBLAS first-party library, than it is to write and dispatch compute shaders to multiply these matrices.
However, for use cases when hardware costs are substantial compared to software development costs, using Vulkan or D3D can be a reasonable thing to do. nVidia is too greedy, in the EULA of their drivers they forbid to use GeForce GPUs in data centres. For people who need GPGPU on their servers, that paragraph of text sometimes makes nVidia hardware an order of magnitude more expensive than AMD hardware.
I'm definitely going to be looking at this. Hope you had fun making it.
A big reason is that C++ for Vulkan (SPIR-V) isn't quite there, while CUDA does C, C++20 (minus modules currently), Fortran, Haskell, Java, C#, Julia, Python JITs, and anything else that might target PTX.
SPIR was a late response after Khronos realized the world wasn't willing to be stuck with C for GPGPU, and the tooling is still catching up to PTX.
how well does Vulcan api fit Neural Net primitives [ matmul / relu / backprop / tensor arrays ] ?
Also.. do you think the in-browser WebGPU api, the successor to webGL, is a good api for NN ?
There are no Vulkan constructs corresponding to those things. Vulkan lets you run compute shaders written in GLSL, HLSL, or any language for which there exists a compiler that outputs SPIR-V. Vulkan doesn’t have its own shader language. Deciding how to break the problem down into separate shader programs each with different workgroup sizes is a challenge.
And the end result performs very poorly compared with tensorflow. However, I haven’t yet put much effort into optimisation, so I expect there’s some easy performance gains to be made.
I don’t know anything about WebGL or WebGPU.
Context: I am interested in writing GPU-code as well (for ML too, but also for custom physic simulation). I also think, that compute-shaders are the way to go. But my intution says, that openCL would be simpler than vulcan.
Question: Have you considered alternatives to vulcan's compute shaders? (e.g. opencl instead of vulcan, or maybe some other ways entirely to run GPU code, such as rust-gpu)