How thrust sorting works ?

Hi, I works on a stereovision app and I have a problem with the sorting in a global function.
Without sorting the program runs without error. But with sorting I have a problem of memory stack and I don’t understand why.
This is my line, with dif a float * and window an integer

thrust::sort(thrust::seq, dif, dif + window);

In my main function I call with 70 blocks and 50 threads but I don’t think number have a link.

Thanks

The one line of code that you have given is too little to help. Can you create a small/minimal example that demonstrates the problem?

Yes sorry, follow an exemple

__constant__ int widthWindow2 = 9;

__device__
void makeVector(float *mat, float *vec, int col, int x, int y) {
	int ind = 0;
	for (int i = x; i < x + widthWindow2; i++) {
		for (int j = y; j < y + widthWindow2; j++) {
			vec[ind] = mat[col * i + j];
			ind++;
		}
	}
}

__global__
void computeSMAD2(int minX, float *d_mL, float *d_mR, float *dif, float *windowL, float *windowR, float  *d_disparity, int colmLO, int colmL, int seachWindow) {
	
	int mini;
	int pOiX(threadIdx.x + minX); // + minX
	int pOiY(blockIdx.x + minX);
	int newPoIx(max(minX, pOiX - searchWindow));
	int newPoIy(pOiY);
	int minPoIx(newPoIx);
	int smad = 0;
	int bMax = (int)(correlationWindow / 2);

	makeVector(d_mL, windowL, colmL, pOiY, pOiX); // ATTENTION ligne / colonne
	makeVector(d_mR, windowR, colmL, newPoIy, newPoIx);

	for (int h = 0; h < correlationWindow; h++) {
		dif[h] = windowL[h] - windowR[h];
	}
	
        thrust::sort(thrust::seq, dif, dif + correlationWindow);

	int median = dif[(correlationWindow - 1) / 2];

	for (int h = 0; h < correlationWindow; h++) {
		dif[h] = abs(dif[h] - median);
	}

	thrust::sort(thrust::seq, dif, dif + correlationWindow);

	for (int i = 0; i <= bMax - 1; i++) {
		smad = smad + pow(dif[i], 2);
	}

	mini = smad;
	
	newPoIx++;

	for (int i = newPoIx; i <= pOiX; i++) {
		smad = 0;
		makeVector(d_mR, windowR, colmL, newPoIy, i);

		for (int h = 0; h < correlationWindow; h++) {
			dif[h] = windowL[h] - windowR[h];
		}

		thrust::sort(thrust::seq, dif, dif + correlationWindow);

		median = dif[(correlationWindow - 1) / 2];

		for (int h = 0; h < correlationWindow; h++) {
			dif[h] = abs(dif[h] - median);
		}

		thrust::sort(thrust::seq, dif, dif + correlationWindow);

		for (int j = 0; j <= bMax - 1; j++) {
			if (smad < mini) {
				smad = smad + pow(dif[j], 2);
			}
			else {
				break;
			}
		}

		if (smad < mini) {
			mini = smad;
			minPoIx = i;
		}
	}
	int distance = pOiX - minPoIx;

	d_disparity[colmLO * (pOiY - minX) + (pOiX - minX)] = ((255 / searchWindow) * distance);
	
}

Thank you