hello OpenCL——设备信息查询及编译(1)
Ubuntu下,NVIDIA的驱动和Open CL安装后,就可以开发OpenCL程序了。Mac OS X 10.6下,直接可用
这两个平台上使用的差别有两个:
[*]include头文件的位置不同(这个本来可以不是问题的,抱怨一下)
[*]编译的不同
在Ubuntu 9.10中,缺省情况下:
[*]头文件都放在/usr/include/CL目录下,
[*]动态链接库libOpenCL.so放在/usr/lib目录下
写一个C语言的Hello程序opencl_hello.c试试
#include <stdio.h>#include <stdlib.h>#ifdef __APPLE__ #include <OpenCL/cl.h>#elif defined(__linux__) #include <CL/cl.h>#endifint main(){ cl_uint NumPlatforms; clGetPlatformIDs (0, NULL, &NumPlatforms); cl_platform_id PlatformIDs; clGetPlatformIDs(NumPlatforms, PlatformIDs, NULL); char platformName; size_t nameLen; cl_int res = clGetPlatformInfo((PlatformIDs, CL_PLATFORM_NAME, 64, platformName, &nameLen); if (res != CL_SUCCESS) { fprintf(stderr, "Err: %d\n", res); exit(1); } platformName = 0; char openclVersion; res = clGetPlatformInfo(NULL, CL_PLATFORM_VERSION, 64, openclVersion, &nameLen); if (res != CL_SUCCESS) { fprintf(stderr, "Err: %d\n", res); exit(1); } openclVersion = 0; printf("hello, %s's %s\n", platformName, openclVersion); return 0;}
编译:
Linux:
gcc opencl_hello.c -lOpenCL
Mac OS X:
gcc opencl_hello.c -framework OpenCL
执行:
Linux$ ./a.out
hello, NVIDIA's OpenCL 1.0
MacOSX$./a.out
hello, Apple's OpenCL 1.0 (Oct 16 2009 04:12:08)
进一步参考资料:
[*]OpenCL规范
[*]OpenCL API 1.0 quick reference card
[*]OpenCL Programming Guide
[*]OpenCL Jump Start: 比较了OpenCL和CUDA
[*]OpenCL Programming Guide for Mac OS X
页:
[1]