GPU Programming – Exercise 1: Getting started
1 Introduction
This exercise gives a gentle introduction to CUDA programming using a very simple code. The main objectives in this exercise are to learn about:
• thewayinwhichanapplicationconsistsofahostcodetobeexecutedontheCPU,withkernelcode executed on the GPU,
Copyright By PowCoder代写 加微信 powcoder
• howtocopydatabetweenthegraphicscard(device)andtheCPU(host),
• howtoincludeerrorchecking,andprintingfromakernel.
The exercise can be done either on the GPU cluster or on a local machine, assuming that you have a GNU (linux) environment with CUDA drivers properly installed.
1. Read through the exercise1a.cu source file and compare it to the exercise1b.cu source file which includes error checking.
2. Try introducing errors into both exercise1a.cu and exercise1b.cu, such as trying to allocate too much memory, or setting nblocks=0, and see what happens.
3. Add a printf statement to the kernel routine my first kernel, for example to print out the value of tid. Note that the new output may be written to the screen after the existing output from the main code, because it gets put into a write buffer which is flushed only intermittently.
4. Modify exercise1b.cu to add together two vectors which you initialize on the host and then copy to the device. This will require additional memory allocation and two memcpy operations to transfer the vector data from the host to the device.
5. There is a third version of the original code, exercise1c.cu, which uses managed Unified Memory. Read through the code to see what it does, and try compiling and running it.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com