Open CL - Sum of array entries

Good Evening,

I try to write a simple program which will sum up all numbers of a matrix and return the number. So far I know that OpenCL Kernels can not return itself a value, so I thought of this:

__kernel void sum(__global float *inputmatrix,int N,__global float *summe){
int i;
float test;
test = 0.0f;
for(i=0;i.lt.N*N;i++){
test = test + inputmatrix[i];
}
summe = test;}

but now, which arguments should I fill in in my main for this.
More precisley I´m confused about cl_mem vs cl_float, I tried (very naive I know) a cl_float variable for my summe but it didn´t work.
Please can someone explain the cl_mem vs cl_float in more detail ? (I need sums of matrixes in a further program and there I also have to calculate with these numbers in main again ...)

best regards

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Open CL - Sum of array entries

This won't actually do what you want (at least not efficiently). Each work-item will perform the exact same sum. There is an example on the Apple developer website (called Reduction, something or other), that shows how to do this efficiently.

Dave