PDA

View Full Version : Problem with moving an array pointer in the Kernel



mihailo
05-16-2010, 05:26 AM
Hello @all,

iam working with OpenCL since around 2 months. I already solved a lot or problems by moving existing code
from c++ to OpenCL. But no i stuck on a relay simple operation by moving a array-pointer ????

Maybe somebody was already dealing with the same problem :) and can help me !!

The Existing C++ Code :



int height = 200;
int width = 200;
int yPos = 0;
int *y = new int[width*height];
int *buff = new int[width*height];
int pich = width;

w2 = (width + 7) / 8; // 25

for (int h=0; h < height; h++) {
for (int w=0; w < w2; w++) {
y[yPos++] = buff[w];
}
buff += pitch;
}


My OpenCL implementation currently "Not Working" :!:
In the original implementation every filed up to height*w2 of "y" is filled, done
by increasing yPos.
The OpenCL implementation leaves fields empty :(, and i can just not find the workaround :roll: :oops:



__kernel void convert(__global const unsigned char* buff,__global unsigned char* y) {


int x = get_global_id(0); // width globalWorkSize[0] = 200;
int y = get_global_id(1); // height globalWorkSize[1] = 200;

int w2 = (get_global_size(0) + 7) / 8;
long pos = y * get_global_size(0) + ( x ) ;

if ( x < w2 )
y[pos] = buff[pos];

}

santtt
05-16-2010, 09:24 AM
int height = 200;
int width = 200;
int yPos = 0;
int *y = new int[width*height];
int *buff = new int[width*height];
int pich = width;

w2 = (width + 7) / 8; // 25

for (int h=0; h < height; h++) {
for (int w=0; w < w2; w++) {
y[yPos++] = buff[w];
}
buff += pitch;
}


Well in this code it seems that you are concatenating height times the first w2 values of buff, in the middle you do buff += pitch but buff is an array and pitch is a value, this is not possible.....




__kernel void convert(__global const unsigned char* buff,__global unsigned char* y) {


int x = get_global_id(0); // width globalWorkSize[0] = 200;
int y = get_global_id(1); // height globalWorkSize[1] = 200;

int w2 = (get_global_size(0) + 7) / 8;
long pos = y * get_global_size(0) + ( x ) ;

if ( x < w2 )
y[pos] = buff[pos];

}

First, i suggest calculate only one time w2. Then, i think y[pos] is y[y*w2+x], and buff[y*get_global_size(0)+x] is OK because this is what the first code (C++ file) is doing.