引用:http://bbs.csdn.net/topics/390899158(概念问题)
http://blog.csdn.net/hermittt/article/details/50668850(平台搭建及示例)
硬件:intel(R) HD Graphics 4400
win7_x64+vs2010+opencl_sdk1.2
前提:Gpu或者cpu支持OpenCL
方法:GPU_Caps_Viewer
1. 去intel官网下载openclSdk(opencl是跨平台的标准而非跨平台的工具)AMD,Intel,Nvd都有不同的sdk,但接口都是根据Khronos上发布接口标准
2.安装intel版的sdk,然后提取其中的include和lib
3.vs2010,新建项目,在属性中->vc++目录->包含目录中添加Include的路径,链接器->附加库目录->添加x86_lib的目录(x64不能用,还没有找到原因),
链接器->输入->附加依赖项中添加OpenCl.lib
4.添加如下代码
// newTutorial1.cpp : Defines the entrypoint for the console application.
//
//#include "stdafx.h"(mfc的头文件,此处不需要)
#include <CL/cl.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <fstream>
using namespace std;
#define NWITEMS 62144
#pragma comment(lib,"OpenCL.lib")
//把文本文件读入一个string中
int convertToString(const char *filename,std::string& s)
{
size_t size;
char* str;
std::fstream f(filename, (std::fstream::in | std::fstream::binary));
if(f.is_open())
{
size_t fileSize;
f.seekg(0, std::fstream::end);
size = fileSize = (size_t)f.tellg();
f.seekg(0, std::fstream::beg);
str = new char[size+1];
if(!str)
{
f.close();
return NULL;
}
f.read(str, fileSize);
f.close();
str[