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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ATI</strong> STREAM COMPUTINGpY = (cl_float *) malloc(sizeInBytes);if(pY == NULL)throw(string("Error: Failed to allocate input memory on host\n"));for(int i = 0; i < length; i++){pX[i] = cl_float(i);pY[i] = cl_float(length-1-i);}}printVector("X", pX, length);printVector("Y", pY, length);/////////////////////////////////////////////////////////////////// Release host memory/////////////////////////////////////////////////////////////////void cleanupHost(){if(pX){free(pX);pX = NULL;}if(pY != NULL){free(pY);pY = NULL;}}voidmain(int argc, char * argv[]){try{/////////////////////////////////////////////////////////////////// Allocate and initialize memory on the host/////////////////////////////////////////////////////////////////initHost();/////////////////////////////////////////////////////////////////// Find the platform/////////////////////////////////////////////////////////////////cl::Platform::get(&platforms);std::vector::iterator iter;for(iter = platforms.begin(); iter != platforms.end(); ++iter){if((*iter).getInfo() == "Advanced MicroDevices, Inc.")break;}/////////////////////////////////////////////////////////////////// Create an <strong>OpenCL</strong> context/////////////////////////////////////////////////////////////////cl_context_properties cps[3] = { CL_CONTEXT_PLATFORM,(cl_context_properties)(*iter)(), 0 };context = cl::Context(CL_DEVICE_TYPE_GPU, cps);1.9 Example Programs 1-25Copyright © 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!