Download presentation
Presentation is loading. Please wait.
Published byMeryl Nichols Modified over 9 years ago
1
Open CL Hucai Huang
2
Introduction Today's computing environments are becoming more multifaceted, exploiting the capabilities of a range of multi-core microprocessors, central processing units(CPUs), digital signal processors, reconfigurable hardware, and Graphic processing units(GPUs).
3
Introduction Because of the importance of multi-core, many-core, the need to unified language between all kind of GPUs and CPUs became the most important issue for programmers.
4
Introduction OpenCL stands for Open Computing Language. It supported by Apple & AMD NVIDIA and other several vendors. The Khronos group who made OpenGL made OpenCL. And needed only 6 months to come up with the specifications.
5
OpenCL 1. Royally-free. 2. Support both task and data parallel programing modes. 3. Works for all kinds of GPGPUs 4. Works for all kind of multi cores CPUs 5. Works on Cell processors. 6. Works on handhelds and mobile devices. 7. Works with C language under C99.
7
OpenCL Can make query on available devices and build an context of the available devices. Thats mean the programmers would be able to program more freely for any kind of device. Also there application would survive even if the hardware changed in the future.
8
OpenCL Is a low level language. Even lower than CUDA. Some high level languages such as RapidMind planing to implement OpenCL in their programming language. RapidMind is already within OpenCL working group
9
OpenCL Platform Model
10
OpenCL Memory Model
11
Basic OpenCL Program Structure
12
Matrix addition __kernel void vec_add (__global const float *a, __global const float *b, __global float *c) { int gid = get_global_id(0); c[gid] = a[gid] + b[gid]; }
13
VecAdd: Context, Devices and Queue // create the OpenCL context on a GPU device cl_context context = clCreateContextFromType(0, // (must be 0) CL_DEVIC_TYPE_GPU, NULL, //error callback NULL, // user data NULL); // error code // get the list of GPU devices associated with context size_t cb; clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &cb); cl_device_id *devices = malloc(cb); clGetContextInfo(context, CL_CONTEXT_DEVICES, cb, devices, NULL); // create a command-queue cl_cmd_queue cmd_queue = clCreateCommandQueue(context, devices[0], 0, // default options NULL); // error code
14
VecAdd: Creat Memory Object cl_mem memobjs[3]; // allocate input buffer memory objects memobjs[0] = clCreateBuffer(context, CL_MEM_READ_ONLY | // flags CL_MEM_COPY_HOST_PTR, sizeof(cl_float)*n, // size srcA, // host pointer NULL); // error code memobjs[1] = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(cl_float)*n, srcB, NULL); // allocate input buffer memory object memobjs[2] = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(cl_float)*n, NULL, NULL);
15
VecAdd: Program and Kernel // create the program cl_program program = clCreateProgramWithSource( context, 1, // string count &program_source, // program strings NULL, // string lengths NULL); // error code // build the program cl_int err = clBuildProgram(program, 0, // num devices in device list NULL, // device list NULL, // options NULL, // notifier callback function ptr NULL); // error code // create the kernel cl_kernel kernel = clCreateKernel(program, “vec_add”, NULL);
16
VecAdd: set Kernel Arguments // set “a” vector argument err = clSetKernelArg(kernel, 0, // argument index (void *)&memobjs[0], // argument data sizeof(cl_mem)); // argument data size // set “b” vector argument err |= clSetKernelArg(kernel, 1, (void *)&memobjs[1], sizeof(cl_mem)); // set “c” vector argument err |= clSetKernelArg(kernel, 2, (void *)&memobjs[2], sizeof(cl_mem));
17
VecAdd: invoke kernel, read output size_t global_work_size[1] = n; // set work-item dimensions // execute kernel err = clEnqueueNDRangeKernel(cmd_queue, kernel, 1, // Work dimensions NULL, // must be NULL (work offset) global_work_size, NULL, // automatic local work size 0, // no events to wait on NULL, // event list NULL); // event for this kernel // read output array err = clEnqueueReadBuffer( context, memobjs[2], CL_TRUE, // blocking 0, // offset n*sizeof(cl_float), // size dst, // pointer 0, NULL, NULL); // events
18
Conclusion OpenCL would attract HPC programmers because it is long term strategy with GPUs and other accelerators.
19
Conclusion It might be complicated language for the short application, but it is very useful with more complicated application (look over N-Body example)
20
Conclusion There are some restrictions on OpenCL. But it won't affect the language reliability.
21
Conclusion There will be other implementations for OpenCL in other high end language where would be easy for the normal programmers.
22
Conclusion In the end, you might find OpenCL very difficult. But when you master it, you will be the master of parallel computing
23
Sources Takizawa, Hiroyuki and Kobayashi, Hiroaki. Hierarchical parallel processing of larg scale data clustering on a PC cluster with GPU co-processing. Soringer science 2006. Nickson, Christopher. HPC Wire. Apple Planning Snow Leopard Surprise?. Degital Trends - Computing News. Dec 18th, 2008..http://news.digitaltrends.com/news-article/18693/apple-planning-snow-leopard Sutter, Herb. The Free Lunch is Over: A Fundamental Turn Toward Concurrency in Software.March 30, 2005..http://www.gotw.ca/publications/concurrency-ddj.htm HPC Wire. OpenCL on the Fast Track. Nov 4th, 2008..http://www.hpcwire.com/blogs/OpenCL_On_the_Fast_Track_33608199.html HPC Wire. OpenCL makes it Official. Dec 9th, 2008..http://www.hpcwire.com/blogs/OpenCL-Makes-It-Official- 35841524.html West, John. OpenCL: To GPGPU and Beyond. HPC Wire. Dec 11th, 2008..http://www.hpcwire.com/features/OpenCL-To-GPGPU-and-Beyond-36016144.html Wolfe, Michael. Compilers and More: A GPU and Accelerator Programming Model. HPC Wire. Dec 9th, 2008..http://www.hpcwire.com/specialfeatures/sc08/features/Compilers_and_More_A_GPU_and_Accelerator_Programmin g_Model.html?viewAll=y McCool D, Michael and Du Toit, Stefanus. OpenCL Updates. HPC Wire. Nov 21st, 2008..http://www.hpcwire.com/specialfeatures/sc08/features/OpenCL_Update_34860779.html
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.