查询OpenCL平台

直接上代码
OpenCl的函数基本都是根据功能命名代码注释,还是比较容易理解的
查询平台信息

#include<iostream>
#include <stdio.h>

#include <stdlib.h>
#include<CL/cl.h>

using namespace std;
/*displayprogram 传入了平台id,平台信息,保存平台信息的字符串*/
void displayprogram(cl_platform_id id, cl_platform_info param_name, const char* paramnameastr)
{
	cl_int error = 0;
	size_t parasize = 0;

	error = clGetPlatformInfo(id, param_name, 0, nullptr, &parasize);

	char* moreinfo = (char*)malloc(sizeof(char) * parasize);
	error = clGetPlatformInfo(id, param_name, parasize, moreinfo, nullptr);

	if (error != CL_SUCCESS)
	{
		perror("unable to find any opencl platform information");
		exit(1);
	}
	cout << paramnameastr << " :  " << moreinfo << endl;

}

int main()
{
	cl_platform_id* platforms = nullptr;
	cl_uint numofplatforms = 0;
	cl_int error;

	// Get the number of available platforms
	error = clGetPlatformIDs(0, nullptr, &numofplatforms);
	if (error != CL_SUCCESS) {
		perror("Unable to find any platform");
		exit(1);
	}

	platforms = (cl_platform_id*)malloc(sizeof(cl_platform_id) * numofplatforms);
	cout << "number of opencl platforms find : " << numofplatforms << endl;
	//初始化paltforms
	 error = clGetPlatformIDs(numofplatforms, platforms, nullptr);

	for (int i = 0; i < numofplatforms; i++)
	{
		displayprogram(platforms[i], CL_PLATFORM_PROFILE, "CL_PLATFORM_PROFILE");
		displayprogram(platforms[i], CL_PLATFORM_VERSION, "CL_PLATFORM_VERSION");
		displayprogram(platforms[i], CL_PLATFORM_NAME, "CL_PLATFORM_NAME");
		displayprogram(platforms[i], CL_PLATFORM_VENDOR, "CL_PLATFORM_VENDOR");
		displayprogram(platforms[i], CL_PLATFORM_EXTENSIONS, "CL_PLATFORM_EXTENSIONS");
	}
	/*CL_PLATFORM_PROFILE这种只是想要获取平台信息类型的一种参数*/
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值