1
\$\begingroup\$

I am working on sone articles, and need a bit of clarity on following question. Is the OpenGL Shader a CUDA Kernel? When searching the web, I have seen information on differences between kernel and shader.
NVidia Developers, CUDA Kernel or Compute Shader
What's the difference between CUDA and Shader?
But my question is focusing rather on similarities than differences.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ The threads you've linked seem to show the answer is "no, an OpenGL shader is not a CUDA kernel, here are various ways in which they are two different things". What is it that you need to know that is not answered there? \$\endgroup\$
    – DMGregory
    Commented Jul 3, 2024 at 17:33
  • \$\begingroup\$ @DMGregory the threads do not show such an answer. They enumerate differences, yes. Like telling difference between a.bus and a lorry. But they do not tell if the bus is a vehicle or not. \$\endgroup\$ Commented Jul 4, 2024 at 20:13
  • \$\begingroup\$ Did you want to ask whether both OpenGL shaders and CUDA kernels are members of some broader category, analogous to "vehicles" in your example? If so, that's not how your question reads at present — want to make a clarifying edit? \$\endgroup\$
    – DMGregory
    Commented Jul 5, 2024 at 0:24
  • \$\begingroup\$ @DMGregory My question asks exactly that. CUDA kernel does same things as OpenGL shader. The only thing, shader is specialized, but kernel is not. So logically, shader is a specialized kernel. Nothing that I've consulted so far contradicts that. Moreover there is a connection between CUDA and OpenGL, buffers processed by CUDA can be processed by OpenGL directly. See following link: nvidia.com/content/GTC/documents/1055_GTC09.pdf So the question didn't arise just randomly. \$\endgroup\$ Commented Jul 5, 2024 at 5:09

1 Answer 1

3
\$\begingroup\$

No.

OpenGL and CUDA are both frameworks providing APIs that give a standardized way to program GPUs to perform various tasks. I say "framework" and not just "API" because they include other components in their respective ecosystems, like shader programming languages and tools, though the APIs are the main attraction. They differ in the ways you've already identified in your research:

  • OpenGL's API is more specialized, focused on rendering tasks. It's an open standard that can be implemented by any GPU maker.

  • CUDA's API is less restrictive, designed for general purpose computing on GPUs (GPGPU). It's a proprietary technology that works only on NVIDIA chips.

    Contrast this with OpenCL, another framework that also supports GPGPU tasks, but it's an open standard like OpenGL, so it can be implemented for sufficiently capable chips from any manufacturer.

The device driver translates either OpenGL shader code or CUDA/OpenCL kernel code into machine instructions that work on the specific GPU that will run them, so they ultimately all lead to the same types of instructions running on the same hardware. That does not mean that an OpenGL shader is actually a CUDA kernel, any more than we would say that JavaScript programs are C# programs.

An easy way to see that an OpenGL shader is not a CUDA kernel is that you can compile and run an OpenGL shader on an AMD GPU, but you cannot run a CUDA kernel on those non-NVIDIA GPUs without first transpiling it to something their drivers support, like OpenCL.

Another clue is the history: CUDA was released in 2007, fifteen years after OpenGL was released in 1992, and three years after GLSL shaders were introduced to the standard. It would be difficult for early OpenGL shaders to be CUDA kernels when CUDA had not yet been invented. 😉

\$\endgroup\$
1
  • \$\begingroup\$ I gave you a point but could not accept as the answer. As far as I know, neither CUDA, nor OpenGL are frameworks. Both are APIs. You pointed out that CUDA lack supports for some platforms, it is vendor specific. True, but when it comes to OpenGL, if there is no OpenGL provided by vendor with device drivers, then there is nothing you can do to use OpenGL, so it is vendor specific as well, as well as OpenGL implementation. Unlike OpenGL and CUDA, OpenCL is a framework. So, Shaders are clearly no OpenCL kernels. But when there is CUDA then there is always OpenGL implementation by NVidia. \$\endgroup\$ Commented Jul 5, 2024 at 16:15

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.