这是AMD异构大赛发的书上的例子,我自己加了一些东西,实现了一下。不过还没有学会如何分析运行的时间,先贴上代码
这是第一次用amd APP KernelAnalyzer感觉还可以吧,
simpleMultiply.cl
// Enter your kernel in this window
__kernel
void simpleMultiply(__global float* outPutC,
int widthA,
int heightA,
int widthB ,
int heightB ,
__global float* inputA ,
__global float* inputB
)
{
int row = get_global_id(1);
int col = get_global_id(0);
float sum = 0.0f ;
for(int i=0;i<widthA; i++)
{
sum += inputA[row*widthA+i] * inputB[i*widthB+col];
}
outPutC[row*widthB+col] = sum;
} ;
main.cpp
/*
项目:openCL的矩阵相乘
作者:刘荣
时间:2012.11.20
*/
#include <iostream>
#include<time.h>
#include <string>
#include<math.h>
#include <vector>
#include <CL/cl.h>
#include <fstream>
using namespace std;
//kernel函数
std::string
convertToString(const char *filename)//将kernel源码,即自己写的并行化的函数,转化成字符串
{
size_t size;
char* str;
std::string s;
std::fstream f(filename, (std::fstream::in | std::fstream::binary));
if(f.is_op