使用 thrust 使用 sort_by_key 对两个 OpenGL 缓冲区进行排序?

Use thrust to sort two OpenGL buffers using sort_by_key?

我有两个用无符号整数填充的 ShaderStorageBufferObject。 我正在尝试使用推力按键对这些进行排序(这两个缓冲区配对在一起) 这是我正在做的


    struct cudaGraphicsResource *cuda_keys, *cuda_values;
    thrust::device_ptr<uint> keys_device_ptr, values_device_ptr;


//CellIndexList and ParticleIndexList are my buffers and ID being their uint handle
cudaGraphicsGLRegisterBuffer(&cuda_keys, CellIndexList->GetID(), cudaGraphicsMapFlagsNone);
cudaGraphicsGLRegisterBuffer(&cuda_values, ParticleIndexList->GetID(), cudaGraphicsMapFlagsNone);


uint* keys_ptr, *values_ptr;
size_t keys_size, values_size;
{
//this code is being executed in a loop
    cudaGraphicsMapResources(1, &cuda_keys, 0);
    cudaGraphicsResourceGetMappedPointer((void **)&keys_ptr, &keys_size, cuda_keys);
    cudaGraphicsMapResources(1, &cuda_values,0);
    cudaGraphicsResourceGetMappedPointer((void**)&values_ptr, &values_size, cuda_values);

    keys_device_ptr = thrust::device_pointer_cast(keys_ptr);
    values_device_ptr = thrust::device_pointer_cast(values_ptr);

    thrust::sort_by_key(keys_device_ptr, keys_device_ptr + nParticles, values_device_ptr, thrust::less<uint>());

    cudaGraphicsUnmapResources(1, &cuda_keys, 0);
    cudaGraphicsUnmapResources(1, &cuda_values, 0);
}

我在编译器输出中得到这个 "thrust::detail::STATIC_ASSERTION_FAILURE"。

我修正了它,一个愚蠢的错误。我将此文件编译为 c/c++ 文件而不是 CUDA 文件。这就是推力给我静态断言的原因。