openCl环境搭建及示例

引用: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[

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值