A High-Level Lua API for GPU Parallelism
willcrichton.github.io
willcrichton.github.io
Why is that benchmark completely meaningles? Because cuda matrix multiplication is so optimized that no one with a bit of sense would roll out his own, and even if he does, that implementation would have to use very specialized and ugly code - can this be done in terracuda, and is it simpler than in C?
Addidionally, the main issue in gpu kernels is not the ugliness of c itself, but the need to optimize algorithms to the hardware of the gpu, thus making the code much more verbose and ugly than the naive c code. That's why terracuda and the likes look fantastic when you compare them with naive C implementations, but they try to solve the wrong problem IMO.
However, I would dispute that it makes the benchmark meaningless. I agree that no one will write the hand-optimized matrix multiply routine in Terra, but I think that misunderstands the use case of the language. Terracuda is intended to make everyday GPGPU computations super easy, so you can speed up simple scripting code that would otherwise be order of magnitudes slower. Look at the other examples in the repo: if you wanted to write a simple hash function, Mandelbrot generator, or renderer, Terracuda makes it simple to accelerate Lua code.
There will always be room for super optimized kernels for common functions like matrix multiplication, but I believe there's a strong need for a language that handles everything else.
If you're dealing with larger pieces of code at once (that is, if you have a bigger view of what the programmer wants to run, which you should have), one interesting thing you could do is "exploratory compiling". Try different compilation step sequences and transformations, if you have enough invariants in the code. Machine time is cheap and this could yield some interesting results. Of course, the more constrained the language model is, the more opportunities for this.
(There's been some interesting results in this area, like superoptimizers for local optimization, but larger scale compilation would probably use something like genetic algorithms, as you're unlikely to have the opportunity for exhaustive searches.)
Really? What if you have, for example, special matrices, not general ones? What's going to be faster, generating a matrix and then running the fastest general matrix multiplication code money can buy on it, or, even a somewhat slower code, but one that can instead use some extra invariants?
> Addidionally, the main issue in gpu kernels is not the ugliness of c itself, but the need to optimize algorithms to the hardware of the gpu, thus making the code much more verbose and ugly than the naive c code.
But that sounds like a compiler issue to be solved. And then you don't have to do it by hand, you let the machine find it out. (And I can't help but think that C is terrible for array based programming anyway. Granted, pure Lua might not be great either for the same reasons.)
As a side note. I'm not sure this is usable in software other than Scientific Computing kernels, as relying solely on CUDA rules out AMD and Intel GPUs, if i'm not mistaken.
Though I guess one could use it as an inspiration for implementing something similar for OpenCL or Vulkan.
Sidenote -- I hate to be the guy complaining about web design, but the Raleway font is very hard to read (Retina MacBook). Here's a screenshot: http://i.imgur.com/9DkVEaQ.png
The screenshot is at 2x resolution so the readability problem is not quite obvious, but look at the vertical lines on the "m" letters -- the line width is all over the place even within a single letter. Raleway's miserable kerning doesn't help things either.
My understanding is that the hardest part of moving stuff to the GPU is moving data around to and from the GPU without killing the computational performance gains by data dependencies, and to transform your problem to something that doesn't need a lot of control flow or rich/complex data structures. Does Terracuda address these things?
As for the second point, that is still mostly left to the programmer. GPU code doesn't necessarily preclude complex data structures, however. For one of my benchmarks, we used a software renderer that generates a quadtree on the fly and accesses that during the shading phase (https://github.com/willcrichton/terracuda/blob/master/render...).
What would make your project even more interesting is to see how it would perform on an heterogeneous system architecture (HSA), ie: what AMD is working towards. In an HSA, the CPU and GPU share the same memory and address space and a program can basically move processing between the two at close to no cost (no memory ever needs to be copied or mapped in/out GPU address space). For problems that allow some kind of pipelining to absorb start-up latencies caused by data dependencies, a combination of Lua + Terracuda would be pretty awesome, allowing you to move even small/short-running computational tasks to the GPU.
(I have worked with Lua for personal gamedev projects before)
Lecture on "GPU Architecture and CUDA Programming": http://15418.courses.cs.cmu.edu/spring2016/lecture/gpuarch
CUDA C Programming Guide: http://docs.nvidia.com/cuda/pdf/CUDA_C_Programming_Guide.pdf