你好我在C +中有这个循环,我试图将它转换为推力但没有得到相同的结果......任何想法?谢谢
C++代码
for (i=0;i<n;i++)
for (j=0;j<n;j++)
values[i]=values[i]+(binv[i*n+j]*d[j]);
Run Code Online (Sandbox Code Playgroud)
推力代码
thrust::fill(values.begin(), values.end(), 0);
thrust::transform(make_zip_iterator(make_tuple(
thrust::make_permutation_iterator(values.begin(), thrust::make_transform_iterator(thrust::make_counting_iterator(0), IndexDivFunctor(n))),
binv.begin(),
thrust::make_permutation_iterator(d.begin(), thrust::make_transform_iterator(thrust::make_counting_iterator(0), IndexModFunctor(n))))),
make_zip_iterator(make_tuple(
thrust::make_permutation_iterator(values.begin(), thrust::make_transform_iterator(thrust::make_counting_iterator(0), IndexDivFunctor(n))) + n,
binv.end(),
thrust::make_permutation_iterator(d.begin(), thrust::make_transform_iterator(thrust::make_counting_iterator(0), IndexModFunctor(n))) + n)),
thrust::make_permutation_iterator(values.begin(), thrust::make_transform_iterator(thrust::make_counting_iterator(0), IndexDivFunctor(n))),
function1()
);
Run Code Online (Sandbox Code Playgroud)
推力功能
struct IndexDivFunctor: thrust::unary_function<int, int>
{
int n;
IndexDivFunctor(int n_) : n(n_) {}
__host__ __device__
int operator()(int idx)
{
return idx / n;
}
};
struct IndexModFunctor: thrust::unary_function<int, int>
{
int n;
IndexModFunctor(int n_) : n(n_) {}
__host__ __device__
int operator()(int idx)
{ …Run Code Online (Sandbox Code Playgroud) 我正在使用CUDA/Thrust/CUDPP.据我所知,在Stream压缩中,数组中的某些项被标记为无效,然后被"删除".
现在"删除"究竟意味着什么?假设原始数组A并且长度为6.如果2个元素无效(根据我们可能提供的任何条件)那么
系统是否在GPU内存中创建一个大小为4 的新数组来存储有效元素以获得最终结果?
或者它是否从内存中物理删除了无效元素,并将原始数组A缩小到4,只保留有效元素?
对于任何一种情况,这是否意味着动态内存分配正在引擎盖下?但我听说在CUDA世界中不可能进行动态内存分配.
在我的项目中,我已经实现了一个自定义内存分配器,以避免cudaMalloc在应用程序"预热"后不必要的调用.此外,我使用自定义内核进行基本数组填充,数组之间的算术运算等,并希望通过使用Thrust和删除这些内核来简化我的代码.设备上的每个数组都是通过原始指针创建和访问的(现在),我想在这些对象上使用 device_vector和Thrust方法,但我发现自己在原始指针和device_ptr<>所有时间之间进行转换,这有点使我的代码混乱.
我的相当模糊的问题:如何Thrust以最可读的方式组织自定义内存管理,数组方法和调用自定义内核的用法?
我是新手使用Thrust,有一件事我不明白.Thrust是异步还是同步?
如果我写下面的代码,所用的时间不是0.但在其他标签中,其他用户报告的结果0.真相是什么?
clock_t start,end;
start=clock();
thrust::sort_by_key(vettore.begin(), vettore.end(), counter.begin());
end=clock();
double time=((double)(end-start))/CLOCKS_PER_SEC;
cout<<"execution time"<<time<<endl;// the result is 0.327
Run Code Online (Sandbox Code Playgroud) 对于在GPU上使用CUDA的数据并行算法,有两个标准库,CUDPP和Thrust,它们实现了排序,缩减,前缀和等.
那么在性能和功能方面,库之间的主要区别是什么?
是否可以将push_back与Thrust库一起使用?那些矢量矢量呢?我想在GPU中使用CPu中的内容:
vector< vector<int> > MyVector( 100 );
...
MyVector[i].push_back(j);
Run Code Online (Sandbox Code Playgroud)
有没有办法使用它,例如:
thrust::device_vector<thrust::device_vector<int>> d_vec(4);
Run Code Online (Sandbox Code Playgroud)
那么创建一个device_vectors数组呢?可能吗?
是否可以使用Thrust创建一个device_vectors数组?我知道我无法创建device_vector的device_vector,但是如何创建device_vectors数组呢?
我正在为CUDA中的项目寻找高性能多扫描/多前缀和(一个内核执行中的许多行)函数.
我尝试过Thrust库中的那个但是它太慢了.使用nvcc调试标志(-g -G)编译后也会导致崩溃.
在我与Thrust失败之后,我专注于cuDPP库,它曾经是CUDA工具包的一部分.cuDPP性能非常好但是库没有最新的cuda 5.5,并且在使用内存检查器进行调试时,cudppMultiScan()函数中存在一些全局内存冲突问题.(cuda 5.5,nsight 3.1,visual studio 2010,gtx 260 cc 1.3)
有没有人知道使用什么而不是这两个库?
R.
我正在优化pycuda /推力计划.在其中,我使用thrust :: min_element来识别设备上的数组中的最小元素的索引.
使用Nvidia的可视化分析器,似乎每当我打电话时thrust::min_element,都有一个DtoH(设备到主机)memcpy.我想要的只是在设备上进行的一切.换句话说,min_element()的输出应存储在设备上,我可以在以后使用它,而不会花费小DtoH memcpy的成本.有没有办法做到这一点?还是我错误地思考问题?
我的尝试是在下面,其中的想法是将指向的数组中最小元素的索引input_ptr放入指向的数组的第一个元素中output_ptr.一切都应该在设备上完成,主机上没有任何东西.
此代码生成正确的答案,但涉及不需要的memcpys.非常感谢您提供的任何帮助.
#include <thrust/extrema.h>
#include <thrust/device_vector.h>
#include <cuda.h>
void my_min_element(CUdeviceptr input_ptr, int length, CUdeviceptr output_ptr)
{
thrust::device_ptr<float> i_ptr((float*)input_ptr);
thrust::device_ptr<int> o_ptr((int*)output_ptr);
o_ptr[0] = thrust::distance(i_ptr,thrust::min_element(i_ptr, i_ptr+length));
}
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来使用该thrust::counting_iterator函数来并行化以下for循环:
for (int stride = 0 ; stride < N * M ; stride+=M) // N iterations
{
// Body of the loop
}
Run Code Online (Sandbox Code Playgroud)
以下是代码的外观:
struct functor ()
{
__host__ __device__ void operator() (const int i)
{
// Body of the loop
}
}
thrust::counting_iterator<int> it1(0);
thrust::counting_iterator<int> it2 = it1 + N * M;
thrust::for_each (it1 , it2 , functor());
Run Code Online (Sandbox Code Playgroud)
我知道将counting_iterator迭代器增加1,那么有没有办法增加M?