Community
cancel
Showing results for 
Search instead for 
Did you mean: 
missing__zlw
Beginner
88 Views

Why MKL_Mem_Stat just returns 0?

Hi,
I am using mkl example from the manual. However, the values returned from MKL_Mem_stat is just 0. Why?
Code is here:

double *a, *b, *c;

int n, i;

double alpha, beta;

MKL_INT64 AllocatedBytes;

int N_AllocatedBuffers;

alpha = 1.1; beta = -1.2;

n = 1000;

a = (double*)MKL_malloc(n*n*sizeof(double),128);

b = (double*)MKL_malloc(n*n*sizeof(double),128);

c = (double*)MKL_malloc(n*n*sizeof(double),128);

for (i=0;i<(n*n);i++) {

a = (double)(i+1);

b = (double)(-i-1);

c = 0.0;

}

//dgemm("N","N",&n,&n,&n,α,a,&n,b,&n,β,c,&n);

AllocatedBytes = MKL_Mem_Stat(&N_AllocatedBuffers);

printf("\\nDGEMM uses %ld bytes in %d buffers \\n",(long)AllocatedBytes,N_AllocatedBuffers);

MKL_FreeBuffers();

AllocatedBytes = MKL_Mem_Stat(&N_AllocatedBuffers);

printf("MKL_FreeBuffers uses %ld bytes in %d buffers \\n",(long)AllocatedBytes,N_AllocatedBuffers);

if (AllocatedBytes > 0) {

printf("\\nMKL memory leak!");

printf("\\nAfter MKL_FreeBuffers there are %ld bytes in %d buffers",

(long)AllocatedBytes,N_AllocatedBuffers);

}

MKL_free(a);

MKL_free(b);

MKL_free(c);

return 0;

0 Kudos
4 Replies
Chao_Y_Intel
Employee
88 Views

Hello,

I noticed this following line is commented:

//dgemm("N","N",&n,&n,&n,α,a,&n,b,&n,β,c,&n);

MKL_Mem_Stat() will compuate the internal MKL buffer (when call dgemm()) it will use. To improve the performance, MKL has memory manager that may allocate some memory buffers used by MKL functions. MKL_Mem_Stat() will return the memory used the the memory buffer.

Thanks,
Chao

missing__zlw
Beginner
88 Views

Thank you for your explanation. So the MKL_Mem_stat doesn't report the real allicated memory size after MKL_malloc?
Or MKL_malloc doesn't really allocat until it is used?
Chao_Y_Intel
Employee
88 Views

MKL_Mem_Stat tracks the internal memory allocate by the MKL computation functions. These memory buffers are not visible to the users. For MKL_malloc, it is used by user to allocate the memory externally. Users can this call to allocate the memory by themselves, and use MKL_free the free these memory. It is actually allocate the memory.

Thanks,
Chao

Julia_S_Intel1
Employee
88 Views

From MKL 10.3 Update 4MKL_Mem_stat returns whole memory, including MKL_malloc. But thetest should be modified, becauseMKL_FreeBuffers freesmemory used only inside MKL, so user's memory allocated by MKL_malloc should be freed before calling MKL_Mem_stat and checking
if (AllocatedBytes > 0) { printf("\nMKL memory leak!");
..
Reply