Simple examples of OpenCL code, which I am using to learn heterogeneous and GPU computing with OpenCL.
add_numbers: add a list of numbers together. Includes detailed error handling which makes the code harder to read and understandsquare_array: computes array^2 (I am playing mostly with this one)sum_array: sums two arrayscf4cl: testing OpenCL C wrapperHello_World: OpenCL "Hello World" by Applemandelbrot: my attempt at a simple Mandelbrot set calculationN-BodySimulation: Apple's N-body simulator which clearly illustrates the speedup gained by using the GPU. Requires XcodeRayTraced_Quaternion_Julia-Set_Example: Applerng: Illustrates how to generate random numbers in the host and in the GPU using the libraryclRNGauger: generates random cosmic rays on an isotropic sky
The examples that clearly demonstrate the computational advantage of using a GPU for processing are N-BodySimulation, RayTraced_Quaternion_Julia-Set_Example (both developed by Apple programmers) and auger. For auger, I got impressive speedups of >200x compared to a serial code on the CPU.
To learn about your OpenCL devices, try:
clinfo
To install clinfo on MacOS:
brew install homebrew/science/clinfo
- OpenCL introduction, S. Grauer-Gray
- OpenCL introduction, F. Desprez
- Vector addition in OpenCL (Oak Ridge National Lab)
- Getting started with OpenCL and GPU computing, by E. Smistad
- A gentle introduction to OpenCL, Dr. Dobbs. Includes interesting analogies, but may be too hard as a first read
- Hands-on OpenCL
- AMD OpenCL course
- Introduction to OpenCL, Manchester
- get workgroup size automatically