OpenCL Open Computing Language#
- Open specification 开放架构/规范
- Proposed by Apple in 2008
- Specification developed by a number of companies(Nvidia AMD Intel)
- Specificaton is maintained by the Khronos Group(Also OpenGL)
- Multiple CUPs and Programmable GPUs
- Supports general purpose parallel computations
- OpenCL is device agnostic(设备兼容)
OpenCL devices
- Commonly CPUs and GPUs
- Could be ant type of hardware that is compliant(兼容):多媒体芯片、FPGA、嵌入式处理器等
Goals of OpenCL
- Simple computing model - clean API
- ANSI-C99 language support. Additional qualifiers,data types and built-in functions
- Thread management framework. Application and thread-level synchronization(同步)
- Easy to use and needs to be lightweight and efficient
- Need to be able to use all computational resources in computer
- IEEE-754 compliant in rounding behavior(舍入行为)
- Minimum errors for math functions
- Provides guidelines for new hardware requirements
Uses of OpenCL
Data-parallel algorithms that are computationally significant.
Where OpenCL can be used :
- Image, video and audio processing
- Simulations and scientific calculations
- Medical imaging
- Financial models
OpenCL入门
OpenCL程序主要是分两部分,一部分是在设备上执行(GPU),另一部分是在主机上运行(CPU)。在设备上执行需要写一个Kernel函数,由OpenCL语言编写;OpenCL语言在C语言的基础上加了一些约束、关键字和数据类型。在主机运行的程序提供了API,主机程序可以用C/C++编写,控制OpenCL的环境(上下文,指令队列等)。
基本概念
Kernel 是设备程序执行的入口点,即唯一可以从主机上调用执行的函数。
SIMT 单指令多线程(Single Instruction Multi Thread),相同代码在不同线程中并行执行,每个线程使用不同的数据来执行同一段代码。
Work-item 工作项,类似CUDA Threads,是最小的执行单元。 Work-group 工作组,允许工作项之间通信和协作,类似于CUDA Thread Blocks
ND-Range 是下一个组织级别,定义了工作组的组织形式。