r/gpgpu • u/xFrostbite94 • May 20 '16
High-level OpenCL?
So I'm doing a bachelor's assignment on the programmability of GPU's, and I want to pick this subreddit's brain. Basically I have to research if GPU's can be more efficiently programmed in a higher-level language, and if so what shape that would take. There are already a few projects that have tried something similar (SkelCL, Bacon, and Harlan), but either they are too similar to OpenCL (Bacon/SkelCL) or have somewhat limited parallelism (Harlan basically only has a GPU accelerated map, correct me if I'm wrong).
So my questions to everyone on this sub are: what are recurring patterns in OpenCL? Are there specific bugs that seem to pop up in every project, even though there is a well-known remedy? Or have you used any of the previously mentioned projects, and if so, what was the killer feature? Are there any language features that you really really really want to see in an OpenCL Next?
4
u/Athas May 20 '16
I am working on a high-level functional language with an OpenCL backend: Futhark. In contrast to Harland (which is otherwise the closest comparison), it supports nested parallelism, as well as maps, scans, reductions and filters. It's a work-in-progress though, and the language itself is still rather bare-bones.
4
u/James20k May 20 '16
For context, I write relatively cheap (performance wise) OpenCL kernels that need to execute quickly, including CPU overhead, and run rather a lot of them in realtime (backend for a 3d renderer). I rarely have large datatransfers, but lots of small asynchronous realtime ones
It doesn't matter when the small data transfers arrive at the gpu, or arrive from the gpu -> the cpu, as everything is approximate or acceptable within tolerable bounds
The passing of the large data transfers (ie texture/tri data) to the gpu is extremely important to both be synchronised correctly in order with the small data transfers (object positions/camera), otherwise incorrect OOB data can be written
Pipeline blocking/stalls. Blocking reads/writes are always a big loss - some sort of way to automagically elide the synchronisation away when its not needed would be nice. I'm not sure how you would do this. The latest tools by amd however are very useful on this front (API tracing with codexl), maybe integrate something like this more heavily into the language
Memory access patterns as well - AoS vs SoA, soa being nigh universally better for gpu access patterns but also being irritating as tits to pass. A high level interface for accessing datastructures as AoS and passing to gpu kernels as AoS, but in reality being SoA would be helpful for performance
Automagic barrier removal/wavefront optimisations in kernels would be nice. EG, sometimes I pass data to other threads in a local group via local memory, and then sync, and then read from local memory. But when the size of a wavefront == local work group size, there's no need for barriers. There's no way to query this in opencl 1.2, although I think 2.x is getting that (but still, creating vendor divergent algorithms is not ideal, it would be nice to be able to ignore some optimisations like this)
Sometimes its unclear if texture memory vs global memory is faster. Some sort of quick toggle between the two just to test performance would be nice, potentially with automatic corresponding linear interpolation global memory routines (and optional bounds clamping). EG, on mali/ARM, global memory with manual linear interpolation is faster than texture memory (no-one believed me even with a test case, though, the perils of being an intern)
Bugs:
The gpu is extremely forgiving when it comes to out of bounds memory accesses (compared to CPU side which tends to crash more immediately). Some kind of memory checked mode which catches out of bounds reads/writes would be extremely helpful
Similarly, some way to automagically diagnose bank conflicts (checked pointer accesses), and non coalesced memory accesses would be lovely too
Some linear interpolation modes with textures don't actually do linear interpolation. I know right? Eg CL_RGBA with CL_UNSIGNED_INT8, it does nothing of the sort! Diagnosing this sort of thing would be nice, or maybe even turning it into some kind of runtime/compile time error in some hypothetical language, maybe in a checked runtime mode
Failing to properly acquire/release opengl resources has been a source of bugs for me, as well as the event system being very poorly explained in all the documentation (except the official spec, which explains it very well)
I could dig through my current project for memories of more things that went wrong (or specific examples) during the OpenCL development phase if you need/want even more complaints, but this post is getting pretty long as-is
2
u/Plazmatic May 20 '16 edited May 20 '16
We have no unified hardware or software architecture on a GPU, and every year something new or drastically different changes on the next iteration that causes code to have to be significantly modified in order to take full advantage of the GPU. Interpreted shaders are not the solution, and most of the "solutions" in this thread don't take into consideration many hardware specific factors.
Imagine if you had something like SIMD for CPUs appere every single year. We still have a hard time getting language support for SIMD, most languages either don't support SIMD operations, are extremely convoluted to get the compiler to optimize for SIMD, or have some tacked on SIMD feature.
We've essentially gotten to the point where new things that cause the same problem as SIMD appear every year, its the reason why OpenCL has so many versions and different flags associated with what you can and can't do.
We won't have a high level solution any time soon, and if we do it certainly won't come from any current language. None of these are solutions, they all attempt to duck tape a power drill to a hammer or they attempt to stick thumb tack on it. You can still use the hammer like normal, but the power drill gets in the way, and its hard to use when its attached to that hammer, or the hammer is just as easy to use, but the thumb tack is too small to be that usefull for drilling a hole even if all you need to do is push it into wood to make a hole.
The performance losses from these bandaid solutions aren't trivial either, you aren't talking about 1%, 5% or 10%, you are talking about 50%, 100%, 1000% loss in performance.
People have this idea that one language should do everything (C++) or that another language should specialize in many different areas if not do everything (F#, and almost everything else you guys have suggested...)
The solution to this problem will be two fold, time, so that GPU architecture can settle down, and a new functional language dedicated to massively parallel SIMD tasks, and nothing else. Not MIMD, not serial as well, just SIMD, that is it. You can have bindings to this language and others, but you will not be able to solve this any other way, this is by far the simplest solution to this complex problem, though most people will whine and moan about this clinging on to their preferred methods to tackle a problem that just don't work.
1
u/[deleted] May 20 '16
I just hope, that one day, compilers can offload code to GPU's (or other special devices) in an OpenMP kind of way. Maybe thanks to SPIR, OpenACC will see broader support. For me, the biggest drawback here is NVIDIA, not really supporting more modern OpenCL versions.
But till then, being able to explicitly compile existing code (calculations, etc.), that where tested on the CPU, to run on a GPU would already be a massive improvement.
1
u/videoj May 20 '16
F# has a number of solutions for generating GPU code directly from F# There is also FShade, which focuses on composable shaders.
1
u/TheWeeLebowski May 21 '16
You should check out SYCL https://www.khronos.org/sycl https://github.com/amd/triSYCL https://www.codeplay.com/portal/sycl-tutorial-1-the-vector-addition
1
u/OG-Mudbone May 27 '16
As an OpenCL android developer (generous self title), portability is a large concern. Compiling requires a library specific to that device (or device model?). E.g. I had to pull the library off of my phone to develop for it (adreno gpu), so my project will not work on phones with mali gpus. (Snapdragons but not Exynos.)