ispc / ispc

Intel® Implicit SPMD Program Compiler
BSD 3-Clause "New" or "Revised" License
2.48k stars 311 forks source link

Memory leak in ISPCAlloc #1293

Open tkoziara opened 7 years ago

tkoziara commented 7 years ago

Dear All,

The code I work on experiences significant memory leak, reported as follows by valgrind:

16,384 bytes in 2 blocks are definitely lost in loss record 2,246 of 2,367
==2110==    at 0x10041B3B1: malloc (vg_replace_malloc.c:303)
==2110==    by 0x1009367C7: operator new(unsigned long) (in /usr/local/lib/libstdc++.6.dylib)
==2110==    by 0x10002DF95: ISPCAlloc (tasksys.cpp:1191)
==2110==    by 0x100201D8C: forces_sse4 (forces.ispc:1287)
==2110==    by 0x3F8000003F7FFFFF: ???
==2110==    by 0x10364286F: ???

The forces function is called many times (every time step during a simulation) and it launches several taks: here is the reported line 1287.

The ISPC version is 1.9.1 and the tasksys.cpp file used here comes from this version. The line 1191 in tasksys.cpp can be viewed here.

I hope that you would be able to comment about why there could be a memory leak like this. The software is indeed eating up memory when the "springs_task" at line 1287 is being called -- and not doing this when this line is commented out. There is not memory allocation within the task function.

Best regards, Tomek

dbabokin commented 7 years ago

All memory should be released by ISPCSync(). Could you trace what allocation is causing troubles? You can basically hack ISPCAlloc/ISPCLaunch/ISPCSync in tasksys.cpp and add printf tracing to see what memory locations were allocated and which were released.

tkoziara commented 6 years ago

I just did little debugging: 8192 bytes keep getting allocated at tasksys.cpp:363 and reassigned to index 1 memBuffers[] array at tasksys.cpp:365; they never get released --> the deallocation in at tasksys.cpp:305 is never invoked; I am guessing: this shows up due to the long argument list of the tasking function causing allocation of memBuffers[1] at launch not matched by a deallocation at sync;