I am writing a program using cuda. The problem is the following: I have two arrays in *cu file:
particle* particles;
int* grid_ind;
Place on GPU is allocated for them:
void mallocCUDA(int particlesNumber) {
cudaMalloc((void**)&particles, particlesNumber * sizeof(particle));
cudaMalloc((void**)&grid_ind, particlesNumber * sizeof(int));
}
Both arrays are filled (confirmed). particles in its own init method and grid_ind :
__global__ void findParticleCell(particle* particles, int particlesNumber, int* grid_ind) {
int index = blockDim.x*blockIdx.x + threadIdx.x;
if (index < particlesNumber) {
int x, y, z;
x = (int)(2.0f * (particles[index].predicted_p.x + 2));
y = (int)(2.0f * (particles[index].predicted_p.y + 2));
z = (int)(2.0f * (particles[index].predicted_p.z + 2));
int grid_index = (BOX_X + 2) * 2 * (BOX_Y + 2) * 2 * z + y * 2 * (BOX_X + 2) + x;
grid_ind[index] = grid_index;
}
}
It is called in the following method:
void findNeighbors(int particlesNumber) {
dim3 blocks = dim3((particlesNumber + threadsPerBlock - 1) / threadsPerBlock); // threadsPerBlock = 128 if that matters at all
dim3 threads = dim3(threadsPerBlock);
findParticleCell << <blocks, threads >> > (particles, particlesNumber, grid_ind);
thrust::device_ptr<int> t_grid_ind = thrust::device_pointer_cast(grid_ind);
thrust::device_ptr<particle> t_particles = thrust::device_pointer_cast(particles);
thrust::sort_by_key(t_grid_ind, t_grid_ind + particlesNumber, t_particles);
}
The problem is that the sort method is causing
Microsoft C++ exception: thrust::system::system_error at memory location
for some reason. I have tried to resolve this for a couple of days now without any luck. Why does that exception occur?
So I tried this code on the other PC and it worked without any problem. Other people suggested that the problem on my PC might be in CUDA version / Video driver and whatever else. Anyway, thats crazy... I am sorry that I won't try to reinstall those things to check, since I found out that a custom sort method works not much longer than thrust::sort.