Pregunta

I am currently working on an application which involves lots and lots of calls to blas routines. Routinely checking for memory leaks I discovered, that I am loosing bytes in a dgemm call. The call looks like this:

// I want to multiply 2 nxn matrices and put the result into C - an nxn matrix
double zero = 0.0;
double one = 1.0;
double n; // matrix dimension
char N = 'N';
dgemm_(&N, &N, &n, &n, &n, &one, A, &n, B, &n, &zero, C, &n);

A,B and C are double fields of size n*n. The valgrind output is:

==78182== 18 bytes in 1 blocks are definitely lost in loss record 2 of 30
==78182==    at 0xB936: malloc_zone_malloc (vg_replace_malloc.c:267)
==78182==    by 0xF0B8C6: malloc_set_zone_name (in /usr/lib/system/libsystem_c.dylib)
==78182==    by 0xF0BDF2: _malloc_initialize (in /usr/lib/system/libsystem_c.dylib)
==78182==    by 0xF0C201: malloc_create_zone (in /usr/lib/system/libsystem_c.dylib)
==78182==    by 0xE0533B: _dispatch_ccache_init (in /usr/lib/system/libdispatch.dylib)
==78182==    by 0xE08223: dispatch_once_f (in /usr/lib/system/libdispatch.dylib)
==78182==    by 0xE05305: _dispatch_continuation_alloc_from_heap (in /usr/lib/system/libdispatch.dylib)
==78182==    by 0xE072C8: dispatch_group_async_f (in /usr/lib/system/libdispatch.dylib)
==78182==    by 0x96465F: dgemmGCD (in /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib)
==78182==    by 0x4F1A47: cblas_dgemm (in /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib)
==78182==    by 0x4B8914: DGEMM (in /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib)
==78182==    by 0x100035587: nrg::NRGFD::buildDM() (NRGFD.cpp:1785)
==78182== 
==78182== 22 bytes in 1 blocks are definitely lost in loss record 3 of 30
==78182==    at 0xB936: malloc_zone_malloc (vg_replace_malloc.c:267)
==78182==    by 0xF0B8C6: malloc_set_zone_name (in /usr/lib/system/libsystem_c.dylib)
==78182==    by 0xE08223: dispatch_once_f (in /usr/lib/system/libdispatch.dylib)
==78182==    by 0xE05305: _dispatch_continuation_alloc_from_heap (in /usr/lib/system/libdispatch.dylib)
==78182==    by 0xE072C8: dispatch_group_async_f (in /usr/lib/system/libdispatch.dylib)
==78182==    by 0x96465F: dgemmGCD (in /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib)
==78182==    by 0x4F1A47: cblas_dgemm (in /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib)
==78182==    by 0x4B8914: DGEMM (in /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib)
==78182==    by 0x100035587: nrg::NRGFD::buildDM() (NRGFD.cpp:1785)
==78182==    by 0x10003C5E6: nrg::NRGFD::solve() (NRGFD.cpp:147)
==78182==    by 0x10001AC83: main (main.cpp:63)

I checked the dimensions of the matrizes. They are as expected. I don't get how a dgemm_ call could create such a leak. I could understand illegal writes or reads. But I don't understand how dgemm_ could cause a leak.

¿Fue útil?

Solución

Looking at the stack trace, the leak (if it really is a leak, valgrind can generate false positives) isn't in the BLAS call itself, it is in the OS X Grand Central Dispatch userspace library which the Accelerate framework is using for multi-threading support in those BLAS calls. There isn't really anything you can do about it. If the leak effects the performance or stability of your application, then report it as a bug to Apple.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top