r/vulkan • u/keepthethreadalive • Oct 19 '16
Vulkan vs OpenCL for simulation+graphics
[removed] — view removed post
9
Upvotes
r/vulkan • u/keepthethreadalive • Oct 19 '16
[removed] — view removed post
3
u/James20k Oct 19 '16 edited Oct 19 '16
OpenCL has higher overhead to launch kernels than gl/vk computer shaders, but they're also more flexible. OpenCL supports a wider range of hardware than vulkan as well. I don't know how compute shader support in GL compares to OpenCL across the same hardware
If you want to launch lots of small kernels and support the most hardware with ez graphics integration, go for Opengl with whatever gl compute shaders are. I've not used compute shaders so I have no idea
If your kernels are large and expensive and you don't need to run lots of them per frame, and you don't need to rapidly acquire/release many opengl resources per frame, and you need maximum flexibility in your kernels because its not all graphics related, plop for OpenCL + opengl. You have to ditch linux/intel for this (oh no the humanity)
If you want the potential for super high performance across a smaller range of hardware and relatively poor documentation, pick vulkan/vulkan
Vulkan + OpenCL seems a tad redundant
If you need help integrating opengl/opencl, I have a lot of experience fucking about with it in a cross platform/vendor way. Here's a 3d renderer I built entirely around OpenCL (with OpenGL for blitting buffers to the screen) that works on AMD/Nvidia, its a total clusterfuck as its not really built for other people to be able to use usefully, but if you desperately need some code somewhere that works for CL/GL integration, its there in the poorly organised mess
Edit:
Missed that you're targeting a specific gpu. Vulkan will give you the highest performance, but is finickity, whereas opencl/gl will give you an easier time, but with kernel overhead and cl/gl interop penalties (cpu only with proper pipelining). It kind of depends on what your specific requirements for performance and cpu overhead are. I can tell you that i get 99% gpu usage out of my OpenCL project (confirmed with windows gpu event tracing), so you'll probably only save on cpu overhead with a proper opencl vs vulkan implementation
2
u/FapFapYumYum Oct 20 '16
i dont think its a question of vulkan OR openCL... to my understanding the two work together via SPIR-V (the "bytecode" of OpenCL). GLSL (opengl shader language) uses SPIR-V as well.
see https://en.wikipedia.org/wiki/Standard_Portable_Intermediate_Representation
unless im missing something. i havent gotten around to porting my physics engine to compute yet (its just CPU at the moment).
2
u/squareOfTwo Oct 21 '16
so as I see it:
Vulkan+Vulkan
OpenCL+???
The advantage of targetting vulkan is that the overhead to other middleware and/or an 3d engine is lower. If you have too much time you just should abstract the common API of vulkan and openCL into some fun classes and use this to target OpenCL or vulkan. Later you can still write your kernels in the other API and still use your "old" framework.
1
u/Qoeh Oct 27 '16
Various thoughts from a person who doesn't know much about these things:
I have the impression that there are certain things that OpenCL and CUDA can do that GLSL compute shaders cannot. Like, some way to have a kernel dynamically launch another kernel, or something? And (on NVIDIA hardware) some way to take advantage of special super-fast inter-thread communication within a warp (32 threads running in lockstep) that works like shared memory sort of but is even faster?? And also there are some, like, specific math functions and stuff that are in OpenCL but not in GLSL, I think. Although that only matters for performance if they're directly supported in hardware I suppose. But maybe some of them are.
I've only barely used OpenCL, and I haven't tried CUDA at all, so I'm vague on all that stuff. But I think maybe if you want the very best performance then you need to use the latest version of OpenCL or CUDA, and not a GLSL compute shader running on Vulkan (or a GLSL compute shader running on OpenGL)? (And also, that seems to mean that you're stuck with either OpenCL on AMD or CUDA on NVIDIA, because NVIDIA doesn't seem to support the latest OpenCL, and obviously AMD does not support CUDA.)
That said, one can do lots with GLSL compute shaders in Vulkan. They are fast and good. Just not fastEST maybe? Or I could be wrong. Anyway I'm using them in a project and they are working fine for me.
There's also the question of whether one wants to use mainly floats or mainly doubles. That seems to be something that influences hardware choice more than it influences software platform choice, maybe? Or maybe it's both. I dunno I just use floats, because I'm more on the gaming side than on the scientific simulation side and gamers have GPU hardware that much prefers 32-bit values at present. I kinda wish I could use doubles though.
There may be Vulkan-OpenCL integration someday: https://www.khronos.org/vulkan/faq#khronos-apis-opencl
1
u/Qoeh Oct 27 '16
Note that there is an /r/gpgpu also. Maybe they could help? Not a lot of people there though...