C++ 推力::按\u键排序\u上的配置参数无效

C++ 推力::按\u键排序\u上的配置参数无效,c++,cuda,thrust,C++,Cuda,Thrust,尝试使用按键排序时出现问题: 我在终端中发现以下错误: 在抛出“推力::系统::系统_错误”的实例后调用terminate 内容:在cub_u2;::DeviceRadixSort::SortPairs1之后:配置参数无效 CUDA代码:real=浮点/双精度 //Declare and populate device vectors //--------------------------------------------- thrust::device_vector<real>

尝试使用按键排序时出现问题:

我在终端中发现以下错误:

在抛出“推力::系统::系统_错误”的实例后调用terminate 内容:在cub_u2;::DeviceRadixSort::SortPairs1之后:配置参数无效

CUDA代码:real=浮点/双精度

//Declare and populate device vectors
//---------------------------------------------
thrust::device_vector<real> d_cellXPositions(h_cellXPositions);
real * d_cellXPositions_ptr = thrust::raw_pointer_cast(&d_cellXPositions[0]);

thrust::device_vector<real> d_cellYPositions(h_cellYPositions);
real * d_cellYPositions_ptr = thrust::raw_pointer_cast(&d_cellYPositions[0]);

thrust::device_vector<uint> d_results(_w * _h);
uint * d_results_ptr = thrust::raw_pointer_cast(&d_results[0]);
//---------------------------------------------

//Declare hash and cell occ containers
//---------------------------------------------
thrust::device_vector<uint> d_cellOcc(GRID_RES*GRID_RES, 0);
uint * d_cellOcc_ptr = thrust::raw_pointer_cast(&d_cellOcc[0]);

thrust::device_vector<uint> d_hash(_cellCount, 0);
uint * d_hash_ptr = thrust::raw_pointer_cast(&d_hash[0]);
//---------------------------------------------


//Launch kernels
//---------------------------------------------
uint blockCount = std::ceil(_w*_h)/1024;
uint threadCount = (_w*_h)/blockCount + 1;

printf("Cell count = %d; Hash Size = %d; xPosCount = %d; yPosCount = %d\n",_cellCount, d_hash.size(), d_cellXPositions.size(), d_cellYPositions.size());

std::cout << "Starting kernels \n";

g_pointHash<<<blockCount, threadCount>>>(d_hash_ptr, d_cellXPositions_ptr, d_cellYPositions_ptr, GRID_RES, _w, _h);
cudaThreadSynchronize();
checkCUDAErr();

g_countCellOcc<<<blockCount, threadCount>>>(d_hash_ptr, d_cellOcc_ptr, _w*_h);
cudaThreadSynchronize();
thrust::copy(d_hash.begin(), d_hash.end(), std::ostream_iterator<uint>(std::cout, " "));
std::cout << "~ \n";

//Exclusive scan the cell occ to get the starting indicies

auto tuple = thrust::make_tuple(d_cellXPositions.begin(), d_cellYPositions.begin());
auto zipit = thrust::make_zip_iterator(tuple);
thrust::sort_by_key(d_hash.begin(), d_hash.end(), zipit);
cudaThreadSynchronize();
有点信息过载,但如果您需要更多信息,请告诉我

此类问题应包括第1项所述的MCVE

对于我来说,无论使用什么样的CUDA错误检查都很有价值,这是值得怀疑的,因为OP在评论中确认的错误与CUDA代码有关,而不是推力。无论这条线在做什么:

checkCUDAErr();
似乎不足以防止这里出现混乱

OP在评论中指出,此处的主要问题似乎是该网格/螺纹尺寸计算存在缺陷:

uint blockCount = std::ceil(_w*_h)/1024;
uint threadCount = (_w*_h)/blockCount + 1;
我相信任何1024的整数倍的_w*_h乘积都会产生不正确的threadCount大小。一个具体的例子是_w*_h为1024。那么blockCount将是1。当blockCount为1时,threadCount变量将结束于1025,这是CUDA的非法块大小。这里一个可能的解决方案可能是简单地将threadCount设置为1024,硬编码。这显然是blockCount计算中使用的块大小,尽管没有显示内核代码,但它似乎有一个正确的线程检查,因为当前blockCount和threadCount计算都涉及四舍五入

推力通常有很好的错误检查,当您调用推力算法时,与推力无关的代码中的先前错误可能会出现,因为它将指示尚未清除的任何先前错误。然而,上面3中的错误与推力无关

我鼓励任何使用Pascal GPU的人升级到至少CUDA 8 CUDA 7.5。我鼓励任何使用Volta GPU的人升级到至少CUDA9


您是否为正确的GPU体系结构编译代码?CUDA和推力使用的是什么版本?根据CUDA memcheck输出显示的程序输出,CUDA版本似乎是7.5。我怀疑这是一个重点问题。线程数的计算在我看来是可疑的。如果_w*_h恰好可以被1024整除,则threadblock大小的选择将无效,这将导致无效的配置参数与cuda memcheck输出对齐。这个问题应该有一个答案,根据第一项,注意单词must的用法。此代码不完整。@我使用的Talonmes:NVCCFLAGS=-ccbin$$HOST\u COMPILER-m64-g-g \-arch=sm\u 30 \-gencode=arch=compute\u 20,code=sm\u 20 \-gencode=arch=compute\u 30,code=sm\u 30 \-gencode=arch=compute\u 50,code=sm\u 50 \-gencode=arch=compute\u 52,code=sm\u 52 \-gencode=arch=compute\CUDA\u,code=sm\uu$$CUDA\u COMPUTE\u ARCH-编译器选项-fno严格别名-编译器选项-fPIC-使用\u fast\u math-std=c++11-ptxas选项=-vmakefile@RobertCrovella计算就是问题所在,谢谢!
uint blockCount = std::ceil(_w*_h)/1024;
uint threadCount = (_w*_h)/blockCount + 1;