I encountered a problem on GpuMat.
I wrote the following code to change the value in GpuMat in a kernel function and then failed.
__global__ void testKer(uint8_t* src, int size)
{
int x = blockIdx.x;
int offset = x ;
if (offset >= size) return;
src[offset] = offset;
}
void test(GpuMat src)
{
int size = src.cols * src.rows;
testKer << <size, 1 >> > (src.data, total);
}
void main()
{
GpuMat src(10, 10, CV_8U, Scalar::all(0));
test(src);
Mat host;
src.download(host);
cout << host;
}
Then I got the following output
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
only the first row data changed.
What's the problem? Thank you all.