gpt4 book ai didi

iterator - CUDA Thrust sort_by_key 当键是由 zip_iterator 用自定义比较谓词处理的元组时

转载 作者:行者123 更新时间:2023-12-04 20:51:34 25 4
gpt4 key购买 nike

我在这里查看了很多问题以寻找类似的问题,并且有很多问题,尽管有一个小改动。我正在尝试使用 zip_iterator 作为复合键对值进行排序。

具体来说,我有以下功能:

void thrustSort(    unsigned int * primaryKey,    float * secondaryKey,    unsigned int * values,    unsigned int numberOfPoints){    thrust::device_ptr dev_ptr_pkey = thrust::device_pointer_cast(primaryKey);    thrust::device_ptr dev_ptr_skey = thrust::device_pointer_cast(secondaryKey);     thrust::device_ptr dev_ptr_values = thrust::device_pointer_cast(values);    thrust::tuple,thrust::device_ptr> keytup_begin =        thrust::make_tuple,thrust::device_ptr>(dev_ptr_pkey, dev_ptr_skey);    thrust::zip_iterator, thrust::device_ptr > > first =        thrust::make_zip_iterator, thrust::device_ptr > >(keytup_begin);    thrust::sort_by_key(first, first + numberOfPoints, dev_ptr_values, ZipComparator());    }

and this custom predicate:

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 ---

任何可能导致这种情况的想法/我如何编写确实有效的谓词?

提前致谢,
弥敦道

最佳答案

比较器采用 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());
}

许多模板参数可以从参数中推断出来。

关于iterator - CUDA Thrust sort_by_key 当键是由 zip_iterator 用自定义比较谓词处理的元组时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10077449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com