OpenCL提供了主机和加速器设备交互的界面,允许在异构设备上并行(CPU, GPU, FPGA, DSP)
ICD(installable client driver)模型,允许不同厂商的平台同时存在,如libcudart.so
是NVIDIA的,lib.amdocl64.so
是AMD的,只需对应链接即可
地址空间对象声明
__global
:全局地址空间__constant
:只读内存__local
:被work-group共享内存__private
:对于每个work-item私有__read_only/__write_only
:用户图片__kernel void vecadd(__global int* A, __global int* B, __global int* C){
int tid = get_global_id(0);
C[tid] = A[tid] + B[tid];
}
export LD_LIBRARY_PATH=/opt/AMDAPP/lib/x86_64
gcc -o vecadd vecadd.c 0I/opt/AMDAPP/include -l/opt/AMDAPP/lib/x86_64 -lOpenCL