High Performance Computing with OpenCL
Introduction
This project explores the use of OpenCL in high performance computing for heterogenous platforms (i.e., CPU/GPU). We present updated C/C++ code adhering to OpenCL 2.0 standard for the exercises in the “OpenCL in Action” book by Matthew Scarpino. Read the book. It is a good comprehensive book, suitable for beginners, which teaches OpenCL beginning from the basics.
The following tools will be used in this project:
- C/C++
- OpenCL
- CMake
- Intel CPU - we can test our OpenCL code on a CPU without the need to have a GPU
Code
Find the source code in the repository.
Learning Outcome
At the end of this project, we should be able to:
- Use OpenCL in C/C++ for high performance computing.
- Build C/C++ code with CMake.
Project Structure
The project structure is as follows:
opencl # Repository root
├── apps # Source code
| ├── Ch1
| | ├── matvec.c # C source file
| | └── matvec.cl # Cl source file
| ├── Ch2
| | ├── context_count.c # C source file
| | ├── device_ext_test.c
| | ...
| .
| .
| .
| ├── Ch8
| | ├── buffer_test.cl # Cl source file
| | ├── buffer_test.cpp # C++ source file
| | ...
| └── CMakeLists.txt # CMake build file
├── assets # Reference materials
| ├── libpng-1.4.0-manual.pdf
| ├── OpenCL device model.jpg
| ├── OpenCL operators.jpg
| ├── OpenCL scalar data types.jpg
| └── OpenCL vector data types.jpg
├── bin # Executables
| ├── ...
| ...
├── libs # Local libraries
│ └── util
| ├── CMakeLists.txt # Library-level CMake build file
| ├── util.c
| ├── util.cpp
| ├── util.h
| └── util.hpp
├── .dockerignore
├── .gitignore
├── CMakeLists.txt # Top-level CMake build file
└── README.md
Steps to get started with OpenCL
- Install OpenCL SDK
- For Intel processors: website
- Install and run
clinfo
to show complete information of OpenCL platforms and devices.$ sudo apt install clinfo $ clinfo
Exercise list
For easy reference, the solution code is organised by chapter and named according to the exercise.
Build the C/C++ code using:
$ cd /path/to/repository/root/opencl
$ cmake -E make_directory build
$ cmake -E chdir ./build cmake -DCMAKE_BUILD_TYPE=Release ..
$ cmake --build ./build
Run the desired code as follows. Assuming the desired code is callback_8_6
, then run:
$ cd /path/to/repository/root/opencl
$ ./bin/callback_8_6
The complete code listing is given in the table below.
Chapter | Exercise | Name |
---|---|---|
1 Introducing OpenCL |
1.1 | matvec |
2 Host programming: fundamental data structures |
2.1 | platform_ext_test |
2.2 | device_ext_test | |
2.3 | context_count | |
3 Host programming: data transfer and partitioning |
3.2 | buffer_test |
3.3 | map_copy | |
4 Kernel programming: data types and device memory |
4.1 | hello_kernel |
4.2 | double_test | |
4.3 | float_config | |
4.4 | vector_widths | |
4.5 | vector_bytes | |
5 Kernel programming: operators and functions |
5.1 | op_test |
5.2 | id_check | |
5.3 | mod_round | |
5.4 | polar_rect | |
5.5 | mad_test | |
5.6 | shuffle_test | |
5.7 | select_test | |
7 Events, profiling, and synchronization |
7.2 | callback |
7.3 | user_event | |
7.6 | profile_read | |
7.7 | profile_items | |
7.8 | atomic | |
7.9 | mutex | |
8 Development with C++ |
8.1 | full_context_8_1 |
8.2 | create_kernels_8_2 | |
8.4 | buffer_test_8_4 | |
8.5 | map_copy_8_5 | |
8.6 | callback_8_6 | |
8.7 | user_event_8_7 | |
8.8 | profile_8_8 |
Leave a comment