5

私はここで似たようなものについて多くの質問を調べました.1つの小さな変更はありますが、かなりの数があります. 複合キーとして zip_iterator を使用して値を並べ替えようとしています。

具体的には、次の機能があります。

void スラストソート(
    unsigned int * 主キー、
    float * セカンダリ キー、
    unsigned int * 値、
    unsigned int numberOfPoints)
{
    スラスト::device_ptr dev_ptr_pkey = スラスト::device_pointer_cast(primaryKey);
    スラスト::device_ptr dev_ptr_skey = スラスト::device_pointer_cast(secondaryKey);
    スラスト::device_ptr dev_ptr_values = スラスト::device_pointer_cast(値);

    スラスト::タプル,スラスト::device_ptr> keytup_begin =
        スラスト::make_tuple,スラスト::device_ptr>(dev_ptr_pkey, dev_ptr_skey);

    スラスト::zip_iterator、スラスト::device_ptr > > 最初 =
        スラスト::make_zip_iterator、スラスト::device_ptr > >(keytup_begin);

    スラスト::sort_by_key(first, first + numberOfPoints, dev_ptr_values, ZipComparator());    
}

そして、このカスタム述語:

typedef thrust::device_ptr<unsigned int> tdp_uint ;
typedef thrust::device_ptr<float> tdp_float ;
typedef thrust::tuple<tdp_uint, tdp_float> tdp_uif_tuple ;

struct ZipComparator
{
    __host__ __device__
    inline bool operator() (const tdp_uif_tuple &a, const tdp_uif_tuple &b)
    {
        if(a.head < b.head) return true;
        if(a.head == b.head) return a.tail < b.tail;
        return false;

    }
};

私が得ているエラーは次のとおりです。

エラー 1 エラー: コンストラクター「thrust::device_ptr::device_ptr [with T=unsigned int]」のインスタンスが引数リスト C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include\thrust\detail と一致しません\tuple.inl 309 1 ---
エラー 2 エラー: コンストラクター「thrust::device_ptr::device_ptr [with T=float]」のインスタンスが引数リスト C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include\thrust\detail\ と一致しませんtuple.inl 401 1 ---

これを引き起こす可能性のあるアイデア/実際に機能する述語を作成するにはどうすればよいですか?

前もって感謝します、 ネイサン

4

2 に答える 2

2

コンパレータは、 type の引数を取りますconst thrust::tuple<unsigned int, float>&const tdp_uif_tuple&定義したタイプは展開されますconst thrust::tuple<thrust::device_ptr<unsigned int>, thrust:device_ptr<float> >&

以下のコードは私のためにコンパイルされます:

struct ZipComparator
{
    __host__ __device__
    inline bool operator() (const thrust::tuple<unsigned int, float> &a, const thrust::tuple<unsigned int, float> &b)
    {
        if(a.head < b.head) return true;
        if(a.head == b.head) return a.tail < b.tail;
        return false;

    }
};

それがあなたにとってもうまくいくことを願っています:)

http://code.google.com/p/thrust/wiki/QuickStartGuide#zip_iteratorには、zip イテレータの詳細が記載されています。

必須ではありませんが、これらのテンプレートの長さをクリーンアップしたい場合は、次のようにすることができます。

void thrustSort(
    unsigned int * primaryKey,
    float * secondaryKey,
    unsigned int * values,
    unsigned int numberOfPoints)
{
    tdp_uint dev_ptr_pkey(primaryKey);
    tdp_float dev_ptr_skey(secondaryKey);   
    tdp_uint dev_ptr_values(values);

    thrust::tuple<tdp_uint, tdp_float> keytup_begin = thrust::make_tuple(dev_ptr_pkey, dev_ptr_skey);

    thrust::zip_iterator<thrust::tuple<tdp_uint, tdp_float> > first =
    thrust::make_zip_iterator(keytup_begin);

    thrust::sort_by_key(first, first + numberOfPoints, dev_ptr_values, ZipComparator());    
}

多くのテンプレート引数は、引数から推測できます。

于 2012-04-18T00:40:59.887 に答える