如何同时使用推力和 valgrind 来检测内存泄漏?

问题描述

有没有办法将 CUDA 推力库与 Valgrind 内存泄漏检查器一起使用?

我问的原因是因为这个简单的程序:

#include <thrust/device_vector.h>

int main(){
    thrust::device_vector<int> D(5);
    assert( D.size() == 5 );
}

编译:

$ /usr/local/cuda-11.1/bin/nvcc device_vector.cu -o device_vector.cu.x

让 Valgrind 相信存在多种可能的内存泄漏。

我知道它们一定是误报,并且 valgrind 不是用来检测 GPU 内存泄漏的,但我想知道是否有标志或标准方法可以使这两种工具协同工作(例如检测 CPU 内存泄漏) .

如果周围有一套标准的 Valgrind 例外,我很乐意使用它们,但我想在玩 wack-a-mole 之前问一下。

$ valgrind ./device_vector.cu.x 
==765561== Memcheck,a memory error detector
==765561== Copyright (C) 2002-2017,and GNU GPL'd,by Julian Seward et al.
==765561== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==765561== Command: ./device_vector.cu.x
==765561== 
==765561== Warning: noted but unhandled ioctl 0x30000001 with no size/direction hints.
==765561==    This could cause spurious value errors to appear.
==765561==    See README_MISSING_SYSCALL_OR_IOCTL for guidance on writing a proper wrapper.
==765561== Warning: noted but unhandled ioctl 0x27 with no size/direction hints.
==765561==    This could cause spurious value errors to appear.
==765561==    See README_MISSING_SYSCALL_OR_IOCTL for guidance on writing a proper wrapper.
==765561== Warning: noted but unhandled ioctl 0x25 with no size/direction hints.
==765561==    This could cause spurious value errors to appear.
==765561==    See README_MISSING_SYSCALL_OR_IOCTL for guidance on writing a proper wrapper.
==765561== Warning: noted but unhandled ioctl 0x37 with no size/direction hints.
==765561==    This could cause spurious value errors to appear.
==765561==    See README_MISSING_SYSCALL_OR_IOCTL for guidance on writing a proper wrapper.
==765561== Warning: noted but unhandled ioctl 0x17 with no size/direction hints.
==765561==    This could cause spurious value errors to appear.
==765561==    See README_MISSING_SYSCALL_OR_IOCTL for guidance on writing a proper wrapper.
==765561== Warning: set address range perms: large range [0x200000000,0x300200000) (noaccess)
==765561== Warning: set address range perms: large range [0x681f000,0x2681e000) (noaccess)
==765561== Warning: noted but unhandled ioctl 0x19 with no size/direction hints.
==765561==    This could cause spurious value errors to appear.
==765561==    See README_MISSING_SYSCALL_OR_IOCTL for guidance on writing a proper wrapper.
==765561== Warning: set address range perms: large range [0x10006000000,0x10106000000) (noaccess)
==765561== Warning: noted but unhandled ioctl 0x49 with no size/direction hints.
==765561==    This could cause spurious value errors to appear.
==765561==    See README_MISSING_SYSCALL_OR_IOCTL for guidance on writing a proper wrapper.
==765561== Warning: noted but unhandled ioctl 0x21 with no size/direction hints.
==765561==    This could cause spurious value errors to appear.
==765561==    See README_MISSING_SYSCALL_OR_IOCTL for guidance on writing a proper wrapper.
==765561== Warning: noted but unhandled ioctl 0x1b with no size/direction hints.
==765561==    This could cause spurious value errors to appear.
==765561==    See README_MISSING_SYSCALL_OR_IOCTL for guidance on writing a proper wrapper.
==765561== Warning: noted but unhandled ioctl 0x44 with no size/direction hints.
==765561==    This could cause spurious value errors to appear.
==765561==    See README_MISSING_SYSCALL_OR_IOCTL for guidance on writing a proper wrapper.
==765561== 
==765561== HEAP SUMMARY:
==765561==     in use at exit: 6,678,624 bytes in 8,647 blocks
==765561==   total heap usage: 11,448 allocs,2,801 frees,40,718,174 bytes allocated
==765561== 
==765561== LEAK SUMMARY:
==765561==    definitely lost: 0 bytes in 0 blocks
==765561==    indirectly lost: 0 bytes in 0 blocks
==765561==      possibly lost: 22,216 bytes in 187 blocks
==765561==    still reachable: 6,656,408 bytes in 8,460 blocks
==765561==         suppressed: 0 bytes in 0 blocks
==765561== Rerun with --leak-check=full to see details of leaked memory
==765561== 
==765561== For lists of detected and suppressed errors,rerun with: -s
==765561== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

提到的自述文件 README_MISSING_SYSCALL_OR_IOCTL 对我帮助不大。


注意添加:CUDA 带有一个名为 cuda-memcheck 的 memchecker,它不会报告上述程序中的内存泄漏,但它似乎不能替代 valgrind,因为它不会在一个简单的 cpu 程序中检测到实际的内存泄漏:

#include <thrust/device_vector.h>

int main(){
//  thrust::device_vector<int> D(5);
//  assert( D.size() == 5 );
    
//  cudaDeviceSynchronize();
    std::allocator<int> alloc;
    int* p = alloc.allocate(10);
    p[0] = 2;
    return p[0];
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...