Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
10 Views

mkl_mem_stat gives wrong statistics?

Hello,

We were using MKL_MemStat in MKL 10.1.1 . The system is Linux. If we use 1 thread, it works fine on all machines. But when we use 8 threads, it works on some machines and crashes on others.

I recently downloaded MKL 10.3.7 and MKL 10.2. I tested it using the example on the website/manual. I noticed thatthe corresponding function mkl_mem_stat() gives thewhole memorythat has been allocates, which is not written any where...(The official example is quitemisleading now.)

Whenweuseit in our program, it does not give the correct number of memory that's being used. For example, when we see the program is using 2G memory, mkl_mem_stat() says it uses 20M. We will do further test. Do you have any idea about this?

Peng

0 Kudos
4 Replies
Highlighted
Moderator
10 Views

I don't see problem with the latest 10.3 update9. using the snip code below:

int allocated_buffers;

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

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

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

call dgemm .

allocated_bytes = MKL_Mem_Stat(&allocated_buffers);

printf(" Allocated MKL memory :%8ld bytes in%3d buffers.\n",(long)allocated_bytes,(int)allocated_buffers);

=========
I 've got
Allocated MKL memory :2400000432 bytes in 3 buffers.
when n == 10000
and
wnen n == 1000
Allocated MKL memory :24000432 bytes in 3 buffers.
.....................
1)You can give us the example of your case for reproducing the problem?
2)what do you mean "The official example is quitemisleading now"?
Whic example do you mean? what is your suggestion to improve this example?
--Gennady
0 Kudos
Highlighted
Beginner
10 Views

Hi Gennady,

Thanks so much for the quick reply!

1) It is a little hard to give you an example to reproduce the bug, since it only appears when we run in in our program. I will try to find one example.

2) I found the following example on Intel's website. The second part will display "Memory leak!" when it is not true. In MKL10.1, after mkl_free_buffers(),mkl_mem_stat() will give zero. But now it is non-zero. Also, inthe hearder file mkl_service.h, it says MKL_MenStat() will return the amount of the memory allocatd by Memory Manager, which I think is not accurate now.

-----------------

#include

#include

int main(void) {

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',(long)AllocatedBytes,N_AllocatedBuffers);

mkl_free_buffers();

AllocatedBytes = mkl_mem_stat(&N_AllocatedBuffers);

if (AllocatedBytes > 0) {

printf("\nMKL memory leak!");

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

(long)AllocatedBytes,N_AllocatedBuffers);

}

mkl_free(a);

mkl_free(b);

mkl_free(c);

return 0;

}



-----------------
0 Kudos
Highlighted
Valued Contributor I
10 Views

Hi,

In MKL 10.3 MKL_Mem_Stat() returns the amount of the memory allocated by MKL Memory allocator.
This includes memory allocated for internal buffers plus buffers allocatedvia mkl_malloc() calls.
But mkl_free_buffers() just frees internally allocated buffers.

So, pleasesee correctedtail of yourprogram:

mkl_free_buffers();

AllocatedBytes = mkl_mem_stat(&N_AllocatedBuffers);
printf("\nAfter mkl_free_buffers: %ld bytes in %d buffers",
(long)AllocatedBytes,N_AllocatedBuffers);

mkl_free(a);
mkl_free(b);
mkl_free(c);

AllocatedBytes = mkl_mem_stat(&N_AllocatedBuffers);

if (AllocatedBytes > 0) {
printf("\nMKL memory leak!");
printf("\nAfter mkl_free_buffers there are %ld bytes in %d buffers",
(long)AllocatedBytes,N_AllocatedBuffers);
} else
printf("\nMKL memory OK!");

return 0;
}

As a result the program output is as follows on my machine:

% ./a.out

DGEMM uses 32434736 bytes in 16 buffers
After mkl_free_buffers: 24000432 bytes in 3 buffers
MKL memory OK!

0 Kudos
Highlighted
Beginner
10 Views

I talked to my colleagues about our program. There is no envidence in our program showing it is wrong.

The MKL_Mem_Stat() function should be right. Thanks for the replies!
0 Kudos