10.07.2015 Views

ATI Stream Computing OpenCL Programming Guide - CiteSeerX

ATI Stream Computing OpenCL Programming Guide - CiteSeerX

ATI Stream Computing OpenCL Programming Guide - CiteSeerX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ATI</strong> STREAM COMPUTING1.9 Example Programsmemory, is done using a corresponding command queue. A command queue isassociated with a single device and a given context; all work for a specific deviceis done through this interface. Note that while a single command queue can beassociated with only a single device, there is no limit to the number of commandqueues that can point to the same device. For example, it is possible to haveone command queue for executing kernels and a command queue for managingdata transfers between the host and the device.Most <strong>OpenCL</strong> programs follow the same pattern. Given a specific platform, selecta device or devices to create a context, allocate memory, create device-specificcommand queues, and perform data transfers and computations. Generally, theplatform is the gateway to accessing specific devices, given these devices and acorresponding context, the application is independent of the platform. Given acontext, the application can:• Create one or more command queues.• Create programs to run on one or more associated devices.• Create kernels within those programs.• Allocate memory buffers or images, either on the host or on the device(s).(Memory can be copied between the host and device.)• Write data to the device.• Submit the kernel (with appropriate arguments) to the command queue forexecution.• Read data back to the host from the device.The relationship between context(s), device(s), buffer(s), program(s), kernel(s),and command queue(s) is best seen by looking at sample code.The following subsections provide simple programming examples withexplanatory comments.1.9.1 First Example: Simple Buffer WriteThis sample shows a minimalist <strong>OpenCL</strong> C program that sets a given buffer tosome value. It illustrates the basic programming steps with a minimum amountof code. This sample contains no error checks and the code is not generalized.Yet, many simple test programs might look very similar. The entire code for thissample is provided at the end of this section.1. The host program must select a platform, which is an abstraction for a given<strong>OpenCL</strong> implementation. Implementations by multiple vendors can coexist ona host, and the sample uses the first one available.2. A device id for a GPU device is requested. A CPU device could be requestedby using CL_DEVICE_TYPE_CPU instead. The device can be a physical device,1.9 Example Programs 1-19Copyright © 2010 Advanced Micro Devices, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!