thrust::sort_by_key system_error 在内存位置

thrust::sort_by_key system_error at memory location

我正在用cuda写程序。 问题如下: 我在 *cu 文件中有两个数组:

particle* particles;
int* grid_ind;

为他们分配了 GPU 位置:

void mallocCUDA(int particlesNumber) {
    cudaMalloc((void**)&particles, particlesNumber * sizeof(particle));
    cudaMalloc((void**)&grid_ind, particlesNumber * sizeof(int));
}

两个数组都已填充(已确认)。粒子在它自己的 init 方法和 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;
    }
}

调用方法如下:

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);
}

问题是排序方法导致

Microsoft C++ exception: thrust::system::system_error at memory location

出于某种原因。我已经尝试解决这个问题几天了,但没有任何运气。为什么会出现该异常?

所以我在另一台 PC 上尝试了这段代码,它没有任何问题。 其他人建议我的 PC 上的问题可能出在 CUDA 版本/视频驱动程序和其他任何方面。 无论如何,这太疯狂了…… 很抱歉,我不会尝试重新安装这些东西来检查,因为我发现自定义排序方法的工作时间不会超过 thrust::sort.