如何使用推力返回活动数组元素的索引,即返回数组元素等于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发布于 2012-03-16 06:55:03
将counting_iterator与copy_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 1https://stackoverflow.com/questions/9728594
复制相似问题