在推力排序示例中崩溃
Crash in thrust sorting example
我正在尝试官方网站的例子https://developer.nvidia.com/thrust的第一个例子,并将向量大小更改为32<<23。代码如下:
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/generate.h>
#include <thrust/sort.h>
#include <thrust/copy.h>
#include <algorithm>
#include <cstdlib>
#include <time.h>
using namespace std;
int main(void){
// generate random numbers serially
thrust::host_vector<int> h_vec(32 << 23);
std::generate(h_vec.begin(), h_vec.end(), rand);
std::cout << "1." << time(NULL) << endl;
// transfer data to the device
thrust::device_vector<int> d_vec = h_vec;
cout << "2." << time(NULL) << endl;
// sort data on the device (846M keys per second on GeForce GTX 480)
thrust::sort(d_vec.begin(), d_vec.end());
// transfer data back to host
thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());
std::cout << "3." << time(NULL) << endl;
return 0;
}
但是当运行到thrust::sort行时程序崩溃了。我试着交替使用std::vector和std:sort,效果很好。
这是推力的bug吗??我使用的是Thrust 1.7 + Cuda 6.5 + Visual Studio 2013 Update 2。
我使用的是总内存为2048M的GeForce GT 740M。
我使用processsexplorer监视进程,看到它分配了1.0G内存。但我有2G GPU内存,16G主CPU内存。
错误信息是"一个问题导致程序停止正常工作。"Windows将关闭该程序,并通知您是否有可用的解决方案。[调试][关闭程序]"。点击[调试]后,我可以看到调用堆栈。问题来自这一行:
thrust::device_vector<int> d_vec = h_vec;
来自cuda的最后一个来源是:
testcuda.exe!thrust::system::cuda::detail::malloc<thrust::system::cuda::detail::tag>(thrust::system::cuda::detail::execution_policy<thrust::system::cuda::detail::tag> & __formal, unsigned __int64 n) Line 48 C++
这似乎是一个内存分配问题。但我有2G GPU内存,16G主CPU内存。为什么? ?
罗伯特•:原始示例运行良好,即使对于32<<21,32 <<22。是否有GPU内存的虚拟内存管理系统?这里的连续是指物理上连续的还是虚拟的?在这种情况下是否有任何异常,然后我可以捕获它?
我的测试代码如下:https://github.com/henrywoo/wufuheng/blob/master/testcuda.cu
在我的测试中,没有异常,但是运行时错误。
sizeof(int) * 32<<23 = 4* 2^28即您正在分配大约1 GB的GPU RAM。很可能,您的卡无法处理那么多元素。这可能是因为:
- 一般没有足够的GPU RAM
- 没有足够的连续可用的GPU RAM(这是必需的,因为矢量必须适合连续的内存)
相关文章:
- 排序时无法执行交换操作.我做的时候它会崩溃.为什么
- 排序算法问题(购买商店物品)(崩溃)
- 比较迭代器会使程序崩溃,而不会在自定义气泡排序实现中出现错误
- 智能指针的排序向量:神秘崩溃
- 带有合并排序的DLL不断崩溃
- 在STD中崩溃:: Sort-分类而没有严格的弱排序
- std::sort 以严格的弱排序崩溃 - 与垃圾值进行比较
- 当输入大小足够大时,合并排序崩溃
- C++:使用 LSD 基数排序字符串排序崩溃
- 为什么我的快速排序程序崩溃
- C++堆排序算法在4100多个数据条目后崩溃
- 递归插入排序崩溃几乎对于大 n
- 插入排序使我的程序崩溃
- C++快速排序算法崩溃
- OpenGL - 重新排序渲染方法后崩溃
- 使用"pop_front"从排序列表中删除元素会导致崩溃
- C++快速排序算法不断崩溃
- 冒泡排序崩溃程序c++
- 在推力排序示例中崩溃
- 基数排序与向量的向量在c++崩溃