C++ 推力/cuda减少按键错误?

C++ 推力/cuda减少按键错误?,c++,cuda,thrust,C++,Cuda,Thrust,我在推力库的按_键减少功能方面遇到问题。在我看来这是一个bug,但我想在报告之前确定一下 首先,我的设置:CUDA 7.0、Windows 8、NIVIDA GeForce 820m。整个过程是使用VisualStudio2010和nvcc在发布模式下编译的,64位 现在,这个练习说明了这个问题 我在设备上生成了一个名为devData的随机数向量。 我将称为偏差的指数向量制成表格,其大小定义如下: 设备=[0,0,0,1,1,1,1,1,…K-1,K-1,K-1,K-1,K-1] devDat

我在推力库的按_键减少功能方面遇到问题。在我看来这是一个bug,但我想在报告之前确定一下

首先,我的设置:CUDA 7.0、Windows 8、NIVIDA GeForce 820m。整个过程是使用VisualStudio2010和nvcc在发布模式下编译的,64位

现在,这个练习说明了这个问题

我在设备上生成了一个名为devData的随机数向量。 我将称为偏差的指数向量制成表格,其大小定义如下:

  • 设备=[0,0,0,1,1,1,1,1,…K-1,K-1,K-1,K-1,K-1]
  • devData=[1,4,5,7,5,8,9,6,…7,8,9,6]
因此,在本例中,设备中的每个值在mod=4时间内重复

然后,我只想使用设备通过_keydevData减少_,以获得以下减少的向量:

  • 设备=[0,1,…,K-1]
  • devData=[17,28,…,30]
(如果我的算术正确:)

现在,我可以肯定地知道,设备的元素应该加起来等于由以下关系式给出的值T:

  • T=[(K-1)*K/2](例如:[01123]>6=(K-1)*K/2=3*4/2)
我试着在我的机器上这样做,它对少量元素很好,但对大型元素却失败了。(100000次失败…)

下面是我用来操作上述两个向量的代码,并在最后输出偏差之和。您可以使用基本上设置元素数量的参数k

#include <cuda.h>
#include <thrust/random.h>
#include <thrust/device_vector.h>
#include <thrust/sort.h>
#include <thrust/iterator/counting_iterator.h>
#include <fstream>
typedef typename thrust::device_vector<int>     tDevVecInt;
typedef typename thrust::device_vector<float>   tDevVecFlt;

struct rando : public thrust::unary_function<unsigned int, float>
{
    unsigned int mainSeed;
    rando(unsigned int _mainSeed):mainSeed(_mainSeed) {}
    __host__ __device__ float operator()(unsigned int x) 
    {
        unsigned int seed = x * mainSeed;
        thrust::random::taus88 mac(seed);
        thrust::uniform_real_distribution<float> dist(0,1);
        return dist(mac);
    }
};

struct modSim : public thrust::unary_function<int, int>  
{
    int sz;
    modSim(int in)
    {
        this->sz = in;
    }
    __host__ __device__ int operator()(const int &x) 
    {
        return x/sz;
    }
};

int main() 
{
    int mod = 10;
    int k = 10000;
    int szData = k*mod;

    tDevVecFlt devData(szData, 0.);
    tDevVecInt devIndices(szData, 0.);

    thrust::transform(thrust::make_counting_iterator(0), thrust::make_counting_iterator(0) + szData, devData.begin(), rando(123456789));    
    thrust::tabulate(devIndices.begin(), devIndices.end(), modSim(mod)); 
    thrust::reduce_by_key(devIndices.begin(), devIndices.end(), devData.begin(), devIndices.begin(), devData.begin());
    std::cout << thrust::reduce(devIndices.begin(), devIndices.begin()+ k, 0) << std::endl;
    return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
typedef typename推力::设备_向量tDevVecInt;
typedef typename推力::设备\矢量tDevVecFlt;
struct rando:公共推力::一元函数
{
无符号整数;
rando(unsigned int_mainSeed):mainSeed(_mainSeed){}
__主机\设备\浮点运算符()(无符号整数x)
{
无符号整数种子=x*mainSeed;
推力::随机::taus88 mac(种子);
推力:均匀实分布距离(0,1);
返回距离(mac);
}
};
struct modSim:公共推力::一元函数
{
int sz;
modSim(int-in)
{
这->sz=in;
}
__主机\uuuuuuuuuuuuuuuuuuuuuuu设备\uuuuuuuuuu int运算符()(常量int&x)
{
返回x/sz;
}
};
int main()
{
int mod=10;
int k=10000;
int szData=k*mod;
tDevVecFlt devData(szData,0.);
tDevVecInt设备(szData,0.);
推力::变换(推力::生成计数迭代器(0),推力::生成计数迭代器(0)+szData,devData.begin(),rando(123456789));
推力:制表(devices.begin()、devices.end()、modSim(mod));
推力::按键(Devices.begin()、Devices.end()、devData.begin()、Devices.begin()、devData.begin())减少_;
标准::cout
我哪里错了

推力::减少推力键状态:

前提条件输入范围不得与输出范围重叠

您已在代码中破坏了该前提条件:

thrust::reduce_by_key(devIndices.begin(), devIndices.end(), devData.begin(), devIndices.begin(), devData.begin());

因此,您的代码已损坏,无法代表任何显示推力错误的内容。
推力::按_键减少
不是一个可以就地完成的推力操作。

“我看不到任何东西可以提供您代码中的设备总数。”这里有一个
推力::reduce
,它总结了reduces指标谢谢你的帮助!你说得对。关于设备的总和,我在末尾又做了一个我输出的减速。哎呀。我错过了上一个推力::reduce