六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 21|回复: 0

hello OpenCL——设备信息查询及编译(1)

[复制链接]

升级  81.33%

48

主题

48

主题

48

主题

秀才

Rank: 2

积分
172
 楼主| 发表于 2013-1-28 19:09:56 | 显示全部楼层 |阅读模式
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)

进一步参考资料:
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表