GPU programming?

I am new to the GPU programming world, I tried reading on Wikipedia and Googling, but I still have a few questions:

  • I downloaded some GPU examples, for CUDA, there were some .cu files and some CPP files, but all the code was normal C / C ++ Code, only some weird functions like cudaMemcpyToSymbol , and the rest was pure c code. The question is, is .cu code compiled with nvcc and then linked to gcc? Or how is it programmed?

  • If I encoded something that needed to be run on the GPU, would it work on ALL GPUs? or just CUDA? or is there a recording method for CUDA and a recording method for ATI and a recording method for both?

+6
source share
5 answers

To answer the second question:

OpenCL is the (only) way if you want to write platform-independent GPGPU code.

The ATI website actually has a lot of resources for OpenCL, if you are a little fit, and their sample projects are very easy to modify in what you need, or just understand the code.

The OpenCL specification and man pages are also a very good source of knowledge: http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/ http://www.khronos.org/registry/cl/ specs / opencl-1.1.pdf

There are a lot of conversations that explain some basic concepts, and also explain how to write fast code that I would recommend (which also applies to CUDA).

To almost answer your first question: In OpenCL, the code is compiled at run time to the specific GPU that you are using (to guarantee speed).

+10
source

You probably want to do some background reading on CUDA - this is not something you can just pick up by looking at a few code samples. There are now about 3 different CUDA books on Amazon, and at http://developer.nvidia.com .

To answer your questions:

  • yes, .cu files are compiled using nvcc to an intermediate form (PTX) - this is subsequently converted to GPU-specific code at runtime

  • the generated code will work on a subset of nVidia GPUs, the size of the subset depends on what features of CUDA you use in your code

+5
source

Concluding the answer received by @nulvinge, I would say that OpenCL for programming it on a GPU, such as OpenGL, refers to GPU rendering. But this is not the only option for developing several architectures, you can also use DirectCompute, but I would not say that this is the best option, just if you want your code to work on all DirectX11 compatible GPUs, including some GPUs Intel cards correct too?

But even if you are thinking of GPU programming with OpenCL, don't forget to study the architecture of the platforms you use. ATI processors, GPUs, and NVIDIA GPUs have big differences, and your code is needed to configure for each platform you use if you want to get the most out of it ...

Fortunately, NVIDIA and AMD have programming guides to help you :)

+3
source

In addition to the previous answers for CUDA, you will need an NVIDIA / GPU board if you do not have remote access, which I would recommend this course from Coursera:

Heterogeneous concurrent programming

It not only provides an introduction to CUDA and OpenCL, a memory model, tiles, handling boundary conditions and performance considerations, but also directive-based languages ​​such as OpenACC, a high-level language for expressing parallelism in your code, leaving it mostly to work parallel programming for the compiler (good for a start). In addition, this course has an online platform where you can use your GPU, which is nice to start programming on the GPU without touching the software / hardware settings.

+1
source

If you want to write portable code that you can run on different GPU devices as well as processors. You need to use OpenCL.

In fact, in order to configure your kernel, you need to write the host code in C. The configuration file may be shorter if you want to write it for CUDA cores compared to OpenCL one.

0
source

Source: https://habr.com/ru/post/897182/


All Articles