3

我目前正在开发一个涉及大量调用 blas 例程的应用程序。定期检查我发现的内存泄漏,我在dgemm调用中丢失了字节。调用如下所示:

// 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 和 C 是大小为 n*n 的双字段。valgrind 输出为:

==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)

我检查了矩阵的尺寸。它们与预期的一样。我不明白 dgemm_ 调用如何造成这样的泄漏。我可以理解非法写入或读取。但我不明白 dgemm_ 如何导致泄漏。

4

1 回答 1

3

查看堆栈跟踪,泄漏(如果确实是泄漏,valgrind 会产生误报)不在 BLAS 调用本身中,而是在Accelerate 框架用于多的OS X Grand Central Dispatch用户空间库中-这些 BLAS 调用中的线程支持。你真的无能为力。如果泄漏影响了应用程序的性能或稳定性,请将其作为错误报告给 Apple。

于 2012-01-06T01:21:16.910 回答