0

尝试使用推力 zip 迭代器压缩多个 CUDA 数组时,我遇到了一个令人困惑的错误。我的情况很简单:我有一个表示对象状态的整数推力::向量,以及表示对象在 3D 中的位置和速度的六个浮点向量。当状态(整数)向量元素的值为1时,我想从所有向量中删除该元素并缩小向量。

按照这个例子,我使用了一个 7 路元组和一个谓词。

// Predicate
struct isTupleFlagged
{
    __host__ __device__ bool operator() ( const PartTuple& tup )
    {
        const int x = thrust::get<0>( tup );
        return ( x == 1 );
    }
};

void ParticleSystem::RemoveFlaggedParticles()
{
        typedef thrust::device_vector< int >::iterator  IntDIter;
        typedef thrust::device_vector< float >::iterator  FloatDIter;
        typedef thrust::tuple< IntDIter, FloatDIter, FloatDIter, FloatDIter, FloatDIter, FloatDIter, FloatDIter >     PartDIterTuple;
        typedef thrust::zip_iterator< PartDIterTuple >  ZipDIter;

        ZipDIter newEnd = thrust::remove_if(    thrust::make_zip_iterator( thrust::make_tuple( exit.begin(), x.begin(), y.begin(), z.begin(), vx.begin(), vy.begin(), vz.begin() ) ),
                                                thrust::make_zip_iterator( thrust::make_tuple( exit.end(), x.end(), y.end(), z.end(), vx.end(), vy.end(), vz.end() ) ),
                                                isTupleFlagged() );

        PartDIterTuple endTuple = newEnd.get_iterator_tuple();
        exit.erase(thrust::get<0>( endTuple ), exit.end());
        x.erase( thrust::get<1>( endTuple ), x.end() );
        y.erase( thrust::get<2>( endTuple ), y.end() );
        z.erase( thrust::get<3>( endTuple ), z.end() );
        vx.erase( thrust::get<4>( endTuple ), vx.end() );
        vy.erase( thrust::get<5>( endTuple ), vy.end() );
        vz.erase( thrust::get<6>( endTuple ), vz.end() );

}

但是,这似乎错误地删除了额外的元素。例如,当在 100 的向量中存在单个标记对象时,向量的压缩后大小为 52,而不是预期的 99。我错过了什么?

4

0 回答 0