Skip to content

gshi/CUMA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CUMA (CUda Memory Analysis) is a simpel tool I created to detect memory leaks in GPUs.
The idea is to intercept the cudaMalloc and cudaFree and records the memory allocation
information, such as size, pointer, the calling stack and dumps out the un-free-ed
GPU memory in the exit. So far I have only implemented the cudaMalloc/cudaFree pair,
but other memory allocation/free calls can be implemented as well should that be needed.
This library is only needed if the application is getting complicated enough that
you cannot spot the GPU memory leak by reading the code. The usage of the library is 
non-instrusive, by using LD_PRELOAD

Sampe code (test.cu) provided:
------------------------------------------------------------------------------
int testfunc()
{
    float* A;
    float* B;
    float* C;
    cudaMalloc((void**)&A, sizeof(float)*N);
    cudaMalloc((void**)&B, sizeof(float)*N);
    cudaMalloc((void**)&C, sizeof(float)*N);

    //cudaFree(A);
    //cudaFree(B);
    cudaFree(C);

    return 0;

}

int main()
{
        testfunc();

        return 0;
}
--------------------------------------------------------------------------------
% LD_PRELOAD=./libcma.so ./test
Summary of GPU memory usage
Memory usage: 3 alloc, 1 free, peak_memory_usage=192, current memory in usage: 128
There are 2 entries in the hash table
entry 0: ptr=0x200100000, size=64. The calling backtrace is
        cuda_mem_analysis.c:207 cudaMalloc()
        test.cu:13      testfunc()
        test.cu:28      main()
        ??:0    __libc_start_main()
        ??:0    _start()
entry 1: ptr=0x200100200, size=64. The calling backtrace is
        cuda_mem_analysis.c:207 cudaMalloc()
        test.cu:14      testfunc()
        test.cu:28      main()
        ??:0    __libc_start_main()
        ??:0    _start()
-----------------------------------------------------------------------------------

Software requirement:
	CUMA needs glib2-devel to compile.

Credit:
The backtrace-symbols.c is from Jeff Muizelaar
(http://opensource.apple.com/source/X11libs/X11libs-40.2/cairo/cairo-1.8.6/util/backtrace-symbols.c)
I modified it slightly to demangle the C++ symbols.

Questions: 
Guochun Shi (gshi at ncsa.illinois.edu)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published