opencl入门程序

今天搞了很久opencl上手真的很麻烦,主要觉得是开发的平台相关性比较强吧。不对请指正

网上搞了几个门程序,居然有错不能运行,也太不负责任了吧,至少能编译通过才拿出来啊,

少个括号什么的,太不厚道


以下公布我修改过的入门程序

//系统库
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
//OpenCL库
#include <CL/cl.h>

int main()
{
	//第一步,获取平台ID
	//    先填充平台数
	cl_uint NumPlatforms=0;
	clGetPlatformIDs (0, NULL, &NumPlatforms);
	//    再获得ID
	cl_platform_id* PlatformIDs;
	PlatformIDs = (cl_platform_id*)malloc(sizeof(cl_platform_id)*NumPlatforms);
	clGetPlatformIDs(NumPlatforms, PlatformIDs, NULL);

	//第二步,获得平台名
	char platformName[1024];
	size_t nameLen1;
	cl_int res = clGetPlatformInfo(PlatformIDs[0], CL_PLATFORM_NAME, 64, platformName, &nameLen1);
	if (res != CL_SUCCESS) {
		fprintf(stderr, "Err: %d\n", res);
		exit(1);
	}   
	platformName[nameLen1] = 0;//断行
	printf("Platform Name: %s\n", platformName);

	//第三步,获得平台版本
	char openclVersion[1024];
	size_t nameLen2;
	res = clGetPlatformInfo(PlatformIDs[0], CL_PLATFORM_VERSION, 64, openclVersion, &nameLen2);
	if (res != CL_SUCCESS) {
		fprintf(stderr, "Err: %d\n", res);
		getchar();
		exit(1);
	}   
	openclVersion[nameLen2] = 0;
	printf("Platform Vision : %s\n", openclVersion);

	getchar();
	return 0;
}


如果不能运行并显示信息,请确认SDK安装信息,及库等配置情况

见帖子http://blog.csdn.net/jzaicn/article/details/7997968


官方提供关于get Info的函数调用说明

http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clGetPlatformInfo.html

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值