8

I'm new to the GPU Programming world, I've tried reading on Wikipedia and Googling, but I still have several 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 just some weird functions like cudaMemcpyToSymbol and the rest was pure c code. The question is, is the .cu code compiled with nvcc and then linked with gcc? Or how is it programmed?

  • if I coded something to be run on GPU, will it run on ALL GPUs? or just CUDA? or is there a method to write for CUDA and a Method to write for ATI and a method to write for both?

user229044
241k41 gold badges348 silver badges350 bronze badges
asked Sep 12, 2011 at 20:25
0

5 Answers 5

10

To answer your second question:

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

ATIs website actually has a lot of resources for OpenCL if you search a little, and their example projects are very easy to modify into what you need, or just to understand the code.

The OpenCL spec and reference pages is 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 talks that explain some of the core concepts, and also that explain how to write fast code that I would recommend (that is applicable to CUDA too).

To almost answer your first question: In OpenCL, the code is compiled at runtime to the specific GPU you're using (to guarantee speed).

answered Sep 12, 2011 at 20:51
Sign up to request clarification or add additional context in comments.

2 Comments

Compiled at runtime? will my code be like a byte code thats copied to memory during runtime and executed from there?
Your GPGPU code will be a source code string that is compiled att runtime to a code object on the GPU
5

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

To answer your questions:

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

  • the generated code will run on a subset of nVidia GPUs, the size of the subset depending on what CUDA capabilities you use in your code

answered Sep 12, 2011 at 20:43

1 Comment

Addition about linking: yes, you can link .o-files generated by nvcc with gcc or other C(++) compiler. However, in most cases it's easier to do linking with nvcc, since it automatically links your program to all necessary cuda libraries (if you use gcc, you would have to specify them manually).
3

completing the answer given by @nulvinge, I'd say that OpenCL its to GPU Programming like OpenGL is to GPU Rendering. But its not the only option for multi-architecture development, you could also use DirectCompute, but I wouldn't say that its the best option, just if you want your code running on every DirectX11 compatible GPUs, that includes some intel graphics cards chips too right?

But even if you are thinking in doing some GPU programming with OpenCL, do not forget to study the architecture of the platforms that you're using. ATI CPUs, GPUs and NVIDIA GPUs have big differences and your code is needed to be tuned for each platform that you're using if you want to get the most of it...

Fortunately both NVIDIA and AMD have Programming Guides to help you:)

answered Sep 13, 2011 at 12:24

Comments

1

In addition to previous answers, for CUDA you would need a NVIDIA card/GPU, unless you have access for a remote one, which I would recommend this course from Coursera:

Heterogeneous Parallel Programming

It not just gives an introduction to CUDA and OpenCL, memory model, tiling, handling boundary conditions and performance considerations, but also directive-based languages such as OpenACC, a high level language for expressing parallelism into your code, leaving mostly of the parallel programming work for the compiler (good to start with). Also, this course has a online platform where you can use their GPU, which is good to start GPU programming without concerning about software/hardware setup.

answered Jul 7, 2015 at 15:32

Comments

0

If you want to write a portable code which you can execute on different GPU devices and also on CPUs. You need to use OpenCL.

Actually, to configure your kernel you need to write a host code in C. The configuration file might be shorter if you want to write it for CUDA kernels comparing to OpenCL one.

answered Sep 18, 2015 at 9:56

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.