25 #include <OpenCLFramework/clfContext.hh>
42 const int LIST_SIZE = 1000;
43 int *A =
new int[LIST_SIZE];
44 int *B =
new int[LIST_SIZE];
45 for(
int i = 0; i < LIST_SIZE; i++) {
50 int *C =
new int[LIST_SIZE];
65 "__kernel void vector_add(__global const int *A, __global const int *B, __global int *C) {\n"
67 " size_t v = get_global_id(0);\n"
68 " C[v] = A[v]+B[v];\n"
80 bufferA->
Allocate(LIST_SIZE *
sizeof(
int),
true,
false);
82 bufferB->
Allocate(LIST_SIZE *
sizeof(
int),
true,
false);
84 bufferC->
Allocate(LIST_SIZE *
sizeof(
int),
false,
true);
97 context.
RunOn1DRange( *program,
"vector_add", LIST_SIZE);
104 for(
int i = 0; i < LIST_SIZE; i ++) {
110 cout <<
"computation successful." << endl;
112 cout <<
"error in computation!" << endl;
void PrintPlatformsInfo(std::ostream &out=std::cout)
print info on available platforms
clfBuffer * CreateBuffer()
create buffer object
void PrintDeviceInfo(unsigned int device=0, bool verbose=false, std::ostream &out=std::cout)
print info on computing device
void Build(int deviceNr=0, std::string options="")
builds the sources added by AddSource and AddSourceFromString
const std::string & GetDetailedString() const
detailed combination of all info available
clfProgram * CreateProgram()
create program object
void AddSourceFromString(std::string sourceCode)
adds source code from a string
void ReadFromBuffer(void *data, unsigned int offset=0, unsigned int size=0)
read from buffer object to host memory
clf Exception wrapper, is thrown in case of most clf errors
void Allocate(unsigned int bufsize, bool readonly=false, bool writeonly=false, void *hostptr=NULL, bool copy=false)
Allocation of a memory buffer A memory buffer can be created on device or host, it can be initialized...
void KernelSetArgument(std::string kernelname, unsigned int argnumber, clfBuffer &buffer)
set kernel argument
void AddKernel(std::string kernelname)
adds a kernel to the program.
void WriteToBuffer(const void *data, unsigned int offset=0, unsigned int size=0)
write from host memory to buffer object
void RunOn1DRange(clfProgram &program, std::string kernelname, unsigned int globalrange, unsigned int localrange=0)
run a kernel on a 1D memory range