|
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[NumPlatforms]; clGetPlatformIDs(NumPlatforms, PlatformIDs, NULL); char platformName[64]; size_t nameLen; cl_int res = clGetPlatformInfo((PlatformIDs[0], CL_PLATFORM_NAME, 64, platformName, &nameLen); if (res != CL_SUCCESS) { fprintf(stderr, "Err: %d\n", res); exit(1); } platformName[nameLen] = 0; char openclVersion[64]; res = clGetPlatformInfo(NULL, CL_PLATFORM_VERSION, 64, openclVersion, &nameLen); if (res != CL_SUCCESS) { fprintf(stderr, "Err: %d\n", res); exit(1); } openclVersion[nameLen] = 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)
进一步参考资料:
|
|