Probelm with _device__ fct

Hello,

I have a problem with a __device__function

device int getMedianValue(int * Values){
//bubble sort
int length = sizeof(Values)/sizeof(int);
int temp;
int flag = 1;
while(flag){
flag = 0;
for(int i =0; i < length-1;i++){
if(Values[i] > Values[i+1]){ // swap elements
temp = Values[i];
Values[i] = Values[i+1];
Values[i+1] = temp;
flag =1;
}
}
}
return Values[4];
}

calculates the median from a 9 field array, which is after being sorted the 5 element

I pass over the parameter in my kernel

idx = (blockIdx.x + 1) * Width + 1 + threadIdx.x;

//Get the Neighborhood

int pix00 = blockIdx.x * Width  + threadIdx.x; // Upper left
int pix10 = blockIdx.x * Width + 1 + threadIdx.x; // Upper middle
int pix20 = blockIdx.x * Width + 2 + threadIdx.x; // Upper right
int pix01 = (blockIdx.x + 1)  * Width + threadIdx.x; // left
int pix21 = (blockIdx.x + 1)  * Width + 2 + threadIdx.x; // right
int pix02 = (blockIdx.x + 2)  * Width + threadIdx.x; // lower left
int pix12 = (blockIdx.x + 2)  * Width + 1 + threadIdx.x; // lower middle
int pix22 = (blockIdx.x + 2)  * Width + 2 + threadIdx.x;// lower Right

int values[9];
values[8]=data_orig[pix00];
values[7]=data_orig[pix10];
values[6]=data_orig[pix20];
values[5]=data_orig[pix01];
values[4]=data_orig[pix21];
values[3]=data_orig[idx];
values[2]=data_orig[pix02];
values[1]=data_orig[pix12];
values[0]=data_orig[pix22];

int MedianValue = getMedianValue(values);
data_d[idx] = (int)MedianValue;

Now the problem i am facing is, that the device function doesnt really what it is intended to

i have tested this median calculation method in host code, and it works just fine, the device fkt however doesnt sort my array, which means that my output
values[4] will in fact return values[4]=data_orig[pix21], as it is passed over

I dont know why this happens, has someone got any ideas?

Regards

maz

I solved the problem myself!