Introduction to OpenCL
Upcoming SlideShare
Loading in...5
×
 

Introduction to OpenCL

on

  • 1,484 views

Brief introduction to OpenCL. Included a demo showing the source code of a vector addition.

Brief introduction to OpenCL. Included a demo showing the source code of a vector addition.

Statistics

Views

Total Views
1,484
Views on SlideShare
1,484
Embed Views
0

Actions

Likes
0
Downloads
33
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Introduction to OpenCL Introduction to OpenCL Presentation Transcript

  • INTRODUCTIONTO OPENCLUnai LopezIntelligent Systems GroupDepartment of Computer Architecture & TechnologyUniversity of the Basque Country
  • Outline1)  Introduction2)  Programming Basics3)  “Hello World”4)  Final remarks
  • OpenCL•  Standard for the development of data parallel applications•  Most used for the development of GPGPU applications: General Purpose computing on Graphics Processing Units•  A GPU is comprised of hundreds of compute cores nVidia GTX 285 (240 Compute cores) nVidia GT200b Architecture•  Specialized for massively data parallel computation View slide
  • OpenCL & GPGPU•  GPGPU: Take advantage of GPU’s computing power to make massively parallel applications•  Parallel applications with huge acceleration in Molecular Dynamics, Image Processing, Evolutionary Computation,…•  All cases based on data parallelism: each thread processes a subset of the data•  For example, a vector addition: A + B || C Thread ID 0 1 2 3 4 5 6 7 8 9 10 11 View slide
  • OpenCL•  Furthermore, OpenCL provides portability: same code can run on different architectures•  For example:Intel Core i5 CPU STICell B/E Intel Xeon Phi AMD HD 6950 GPU4 cores @ 2’5 Ghz 8 cores @ 3,2 Ghz 50 cores @ 1 Ghz 1408 cores @ 800 Mhz
  • OpenCL•  Provides the following abstraction: A compute device is composed by compute units•  OpenCL platform: Host + Compute Devices•  Each manufacturer provides an SDK: •  NVIDIA SDK for GPUs •  AMD APP for CPUs/GPU •  Intel for CPUs •  IBM for PowerPC and Cell B/E
  • Programming Basics•  Kernel: function that defines the behavior of each thread•  For example, kernel for vector addition: __kernel void sumKernel ( __global int* a, __global int* b, __global int* c) { int i = get_global_id(0); c[i] = a[i] + b[i]; }•  Written in OpenCL-C: ANSI-C + Set of kernel functions, e.g.: •  get_global_id: obtains thread index •  barrier: synchronizes threads
  • Programming Basics•  An OpenCL applications consists of: Kernel file (OpenCL-C): problem computation Host code(C): kernel management•  Basic host application flow: 1.  Load and Compilation of kernel 2.  Data copy from host to device (e.g. from CPU to GPU) 3.  Execution of kernel 4.  Data copy from device to host 5.  Release kernels and data from device memory•  Execution using command queue in each device
  • Programming Basics•  Host code: programmed using OpenCL API•  API Calls, such as: •  clCreateProgramWithSource: Load kernel from char* •  clBuildProgram: Compile kernel •  clSetKernelArgs: Set kernel arguments for the device •  clEnqueueWriteBuffer/clEnqueueRead: Copy data vector to device •  clEnqueueNDRangerKernel: Launch kernel in device•  API Types, such as: •  cl_mem: Pointer to device memory objects •  cl_program: Kernel object •  cl_float / cl_int / cl_uint: Redefinition of C types
  • Hello World•  Implementation of simple vector addition in OpenCL•  Checks for default platform and device in the system•  Modify Makefile with proper paths in each system•  Run: vectorAdd <size_of_vector>
  • Final Remarks•  OpenCL does not provide performance portability•  Alternative to NVIDIA CUDA: Programming paradigm for NVIDIA GPU cards•  Combinable with other parallel programming models: •  OpenMP for SMPs / MPI for MPPs•  Huge ecosystems for OpenCL, e.g. OpenACC: Develop GPGPU applications using directives #pragma acc kernels for(i = 0; i< N; i++) c[i] = b[i] + a[i];
  • More about OpenCL•  Before starting to develop take a look at: •  Context, command queues, events,…•  Documentation •  Khronos Group: Maintainers of OpenCL •  OpenCL Best practices guide in CUDA/AMD SDKs •  Programming Massively Parallel Processors (Book for CUDA)•  OpenCL sample applications: •  Most SDKs include example OpenCL applications •  Rodinia: http://lava.cs.virginia.edu/wiki/rodinia •  Parboil: http://impact.crhc.illinois.edu/parboil.aspx
  • INTRODUCTIONTO OPENCLUnai Lopez – ulopez009@ehu.esIntelligent Systems GroupDepartment of Computer Architecture & TechnologyUniversity of the Basque Country