Problem with moving an array pointer in the Kernel

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 :slight_smile: 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];
	
}

int height = 200;
int width = 200;
int yPos = 0;
int y = new int[widthheight];
int buff = new int[widthheight];
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[yw2+x], and buff[yget_global_size(0)+x] is OK because this is what the first code (C++ file) is doing.