简体   繁体   中英

Is there a limit size of malloc?

I have a problem when I try to run my cuda program in TITAN BLACK which something like this (i simplified it so it doesn't looks complicated)

    int DIMX, DIMZ,DIMXM, DIMZM;

    DIMXM=5700;
    DIMZM=5700;

    DIMX=DIMXM+20;
    DIMZ=DIMZM+10;

    float *temptxz = (float*)malloc( sizeof(float)*(DIMX*DIMZ));    
    float *temptxx = (float*)malloc( sizeof(float)*(DIMX*DIMZ));        
    float *temptzz = (float*)malloc( sizeof(float)*(DIMX*DIMZ));        
    float *tempvz = (float*)malloc( sizeof(float)*(DIMX*DIMZ)); 
    float *tempvx = (float*)malloc( sizeof(float)*(DIMX*DIMZ));

    for (int ij=0; ij<DIMX*DIMZ; ij++)
    {
    temptxz[ij]=0.0;                
    temptxx[ij]=0.0;
    temptzz[ij]=0.0;
    tempvx[ij]=0.0;
    tempvz[ij]=0.0;
    } 

it is ok for NX=4700; NZ=4700; but if I increase it a little more (making the memory size above 2 gb), the compiling went fine, but when i run the program it crashed and the warning is "0xC0000005: Access violation writing location 0x00000000."

is that beacause there is some kind of limitation size in malloc? or something about pitch memory that said in TITAN black it's only 2 GB?

sorry for my awful english. Thanks

Check your pointers once you've malloced. Malloc ATTEMPTS to make room on the heap for a variable, but it can't guarantee the variable is made. This would usually be due to a memory limit imposed by your environment. You can always check to see if a pointer is created properly by checking the value after you malloc.

x = malloc(SIZE);
if(x == NULL) //error

This validation is always important, because otherwise you'll be attempting to write to a memory address that doesn't exist (0x0)

For CUDA specifically, you can set the heap size explicitly using

cudaDeviceSetLimit()

It's in the documentation .

On windows a 32-bit process has 2GB user VA space limit by default. See this MSDN page for limits on different windows OS versions and options to potentially increase the limits. The best solution is to compile the application as a 64-bit application which has a 8TB user space VA limit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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