OpenCL学习(1)--- 配置Windows环境

OpenCL在PC上目前Navida以及AMD都支持的比较好,Navida推出的Cuda,使用比较广。

不过在手机上,目前支持不够好,主要是Andriod想推出自己的RenderScript,不过有些GPU还是支持的,比如Arm的Mali_OpenCL_SDK   http://malideveloper.arm.com/resources/sdks/mali-opencl-sdk/

配置跟openGL类似,都是在属性--设置include path,lib path以及链接器输入opencl.lib

我的机器是Navida,所以使用的是Cuda的opencl

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\include

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\lib\Win32



配置完成后 测试:

#include <iostream>
#include <CL/cl.h>
using namespace std;

const char* GetDeviceType(cl_device_type it)
{
	if (it == CL_DEVICE_TYPE_CPU)
		return "CPU";
	else if (it == CL_DEVICE_TYPE_GPU)
		return "GPU";
	else if (it == CL_DEVICE_TYPE_ACCELERATOR)
		return "ACCELERATOR";
	else
		return "DEFAULT";

}

int main()
{
	char dname[512];
	cl_uint num_platform;
	cl_device_id devices[20];
	cl_platform_id platform_id = NULL;
	cl_device_type int_type;
	cl_uint num_devices;
	cl_ulong long_entries;

	cl_int err;

	//获取系统上可用的计算平台,可以理解为初始化
	clGetPlatformIDs(0, NULL, &num_platform);
	cout << "CL_PLATFORM_NUM:" << num_platform << endl;

	
	err = clGetPlatformIDs(1, &platform_id, NULL);
	if (err != CL_SUCCESS)
	{
		cout << "clGetPlatform NUMerror" << endl;
		return 0;
	}

	//获取可用计算平台的名称
	clGetPlatformInfo(platform_id, CL_PLATFORM_NAME, 512, dname, NULL);
	cout << "CL_PLATFORM_NAME:" << dname << endl;

	//获取可用计算平台的版本号,即OpenCL的版本号
	clGetPlatformInfo(platform_id, CL_PLATFORM_VERSION, 512, dname, NULL);
	cout << "CL_PLATFORM_VERSION:" << dname << endl;

	//获取可用计算平台的设备数目
	clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_ALL, 20, devices, &num_devices);
	cout << "Device  num:" << num_devices << endl;

	clGetDeviceInfo(devices[0], CL_DEVICE_NAME, 512, dname, NULL);
	cout << "Device 1 Name:" << dname << endl;

	clGetDeviceInfo(devices[0], CL_DEVICE_TYPE, sizeof(cl_device_type), &int_type, NULL);
	cout << "Device Type:" << GetDeviceType(int_type) << endl;

	return 0;
}
输出:

CL_PLATFORM_NUM:1
CL_PLATFORM_NAME:NVIDIA CUDA
CL_PLATFORM_VERSION:OpenCL 1.2 CUDA 7.5.18
Device  num:1
Device 1 Name:GeForce GTX 750 Ti
Device Type:GPU
请按任意键继续. . .

你可能感兴趣的:(OpenCL学习(1)--- 配置Windows环境)