2

推力を使用してアクティブな配列要素のインデックスを返すにはどうすればよいですか?つまり、配列要素が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
4

1 に答える 1

3

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 1
于 2012-03-15T22:55:02.793 に答える