简体   繁体   English

确定最大推力长度::device_vector

[英]Determine max length of thrust::device_vector

Is there a way to determine the maximum size of thrust::device_vector<T> that you can safely allocate?有没有办法确定可以安全分配的最大thrust::device_vector<T>大小?

There isn't a straightforward way that I am aware of.我知道没有一种直接的方法。 My usual approach has been to do something like this:我通常的做法是做这样的事情:

const size_t MB = 1<<20;

size_t reserved, total;
cudaMemGetInfo( &reserved, &total );
char fail = 0;
while( cudaMalloc( (void**)&pool, reserved ) != cudaSuccess )
{
    reserved -= MB;
    if( reserved < MB )
    {
        fail = 1;
        break;
    }
}

which starts with the total free memory returned from cudaMemGetInfo , then decrements it my a "reasonable" size (as best as I could tell in the GT200 era, the GPU MMU has a couple of different page sizes, with 1Mb being the largest).cudaMemGetInfo返回的总免费 memory 开始,然后将其递减为“合理”大小(据我所知,在 GT200 时代,GPU MMU 有几种不同的页面大小,最大的是 1Mb)。 The loop continues until you either get an allocation, or memory is so fragmented or exhausted that even a single page will fail.循环继续,直到您获得分配,或者 memory 如此碎片化或用尽,甚至单个页面都会失败。 Not very pretty, but it seems to work 99.999% of the time.不是很漂亮,但它似乎在 99.999% 的时间里都有效。

use cudaMemGetInfo .使用cudaMemGetInfo

docs here 文档在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM