c++ - Determine max length of thrust::device_vector -
is there way determine maximum size of thrust::device_vector<t>
can safely allocate?
there isn't straightforward way aware of. usual approach has been 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 total free memory returned cudamemgetinfo
, decrements "reasonable" size (as best tell in gt200 era, gpu mmu has couple of different page sizes, 1mb being largest). loop continues until either allocation, or memory fragmented or exhausted single page fail. not pretty, seems work 99.999% of time.
Comments
Post a Comment