cpp文件
// OpenCl-1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <CL/cl.h>
#include <iostream>
#include <fstream>
using namespace std;
#define ARRAY_SIZE 128
cl_int ConvertToString(const char *pFileName, std::string &str);
int _tmain(int argc, _TCHAR* argv[])
{
cl_int iStatus = 0; // 函数返回状态
cl_uint uiNumPlatforms = 0; // 平台个数
cl_platform_id Platform = NULL; // 选择的平台
size_t uiSize = 0; // 平台版本名字字节数
cl_int iErr = 0; // 返回参数
char *pName = NULL; // 平台版本名
cl_uint uiNumDevices = 0; // 设备数量
cl_device_id *pDevices = NULL; // 设备
cl_context Context = NULL; // 设备环境
cl_command_queue CommandQueue = NULL; // 命令队列
const char *pFileName = "ArrayAdd.cl"; // cl文件名
string strSource = ""; // 用于存储cl文件中的代码
const char *pSource = NULL; // 代码字符串指针
size_t uiArrSourceSize[]= {0}; // 代码字符串长度
cl_program Program = NULL; // 程序对象
int arrInA[ARRAY_SIZE]; // 输入数组A
int arrInB[ARRAY_SIZE]; // 输入数组B
int arrOut[ARRAY_SIZE]; // 输出数组
cl_mem memInutBufferA = NULL; // 输入内存对象A
cl_mem memInutBufferB = NULL; // 输入内存对象B
cl_mem memOutputBuffer = NULL; // 输出内存对象
cl_kernel Kernel = NULL; // 内核对象
size_t uiGlobal_Work_Size[1]= {0}; // 用于设定内核分布
//-------------------1. 获得并选择可用平台-----------------------------
// 获得平台数量
iStatus = clGetPlatformIDs(0, NULL, &uiNumPlatforms); // 查询可用的平台个数,并返回状态
if (CL_SUCCESS != iStatus)
{
cout << "Error: Getting platforms error" << endl;
return 0;
}
// 获得平台地址
if (uiNumPlatforms > 0) // 如果有可用平台
{
// 根据平台数为平台分配内存空间
cl_platform_id *pPlatforms = (cl_platform_id *)malloc(uiNumPlatforms * sizeof(cl_platfo