cuda - Thrust:如何返回事件数组元素的索引

标签 cuda thrust

如何使用推力返回事件数组元素的索引,即返回数组元素等于 1 的索引向量?

对此进行扩展,在给定数组维度的多维索引的情况下,这将如何工作?

编辑:目前该功能如下所示

template<class VoxelType>
void VoxelVolumeT<VoxelType>::cudaThrustReduce(VoxelType *cuda_voxels)
{
    device_ptr<VoxelType> cuda_voxels_ptr(cuda_voxels);

    int active_voxel_count = thrust::count(cuda_voxels_ptr, cuda_voxels_ptr + dim.x*dim.y*dim.z, 1);

    device_vector<VoxelType> active_voxels;

    thrust::copy_if(make_counting_iterator(0), 
                    make_counting_iterator(dim.x*dim.y*dim.z),
                    cuda_voxels_ptr,
                    active_voxels.begin(),
                    _1 == 1);
}

哪个给出了错误

Error   15  error : no instance of overloaded function "thrust::copy_if" matches the argument list

最佳答案

counting_iteratorcopy_if 组合:

#include <thrust/copy.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/functional.h>
...
using namespace thrust;
using namespace thrust::placeholders;

copy_if(make_counting_iterator<int>(0),
        make_counting_iterator<int>(array.size()), // indices from 0 to N
        array.begin(),                             // array data
        active_indices.begin(),                    // result will be written here
        _1 == 1);                                  // return when an element or array is equal to 1

关于cuda - Thrust:如何返回事件数组元素的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9728594/

相关文章:

c++ - 使用 CUDA 线程索引作为数字

CUDA:将数组复制到 GPU

cuda - 是否可以一次包含所有 Thrust header ?

c++ - 推力装置 vector 推力装置 vector <int>

python - 导入cv2错误,libcudart.so.6.5没有那个文件

algorithm - CUDA 流压缩 : understanding the concept

cuda - 使用推力 device_vector 作为全局变量

cuda - 让 CUDA Thrust 使用您选择的 CUDA 流

C 通过引用函数传递复杂结构

compiler-errors - 如何从opencv gpumat创建推力device_vector