Open Yihao-Shi opened 2 years ago
@Yihao-Shi On my computer the CPU memory used increased from around 14.6G-> 14.8G in a few minutes, does this match what you see on your end?
If so I believe this is kinda expected in the current implementation as if you turn on kernel_profiler=True, it starts recording some metrics for each run and that's the main source of memory increase. In the future we should consider giving finer control over profiler start/end to users (like context manager).
Btw you can clear those memory usage by calling ti.profiler.clear_kernel_profiler_info()
for now.
@ailzhang However the CPU memory on my computer increased from 4.2G to 6.0G, almost 2G consumption. My CPU is AMD5800X. So I think it might be wired. I have simplified my code in 22 lines:
import taichi as ti
ti.init(arch=ti.cpu, default_fp=ti.f32, debug=True, kernel_profiler=True)
@ti.data_oriented
class DEM:
def __init__(self, timeStep):
self.Dt = ti.field(float, shape=())
self.Dt[None] = timeStep
def Solver(dem, TIME):
t, step, printNum = 0., 0, 0
while t <= TIME:
t += dem.Dt[None]
if __name__ == "__main__":
dem = DEM(timeStep=1.e-6)
TIME: float = 10 # Total simulation time
Solver(dem, TIME)
ti.profiler.print_kernel_profiler_info()
It is interesting to find that when replace the line 14 by t += 1, the CPU memory consumption stays in 4.2G in the whole process of simulation.
@Yihao-Shi Just to double check, what taichi version do you have?
@ailzhang This is my Taichi version [Taichi] version 1.1.0, llvm 10.0.0, commit f5bb6464, linux, python 3.7.5 [Taichi] Starting on arch=x64
@Yihao-Shi I couldn't repro the stable memory consumption usage when replacing line 14 by t += 1
, it error out in my case complaining about divide by zero.
But I can reproduce the case where CPU memory consumption increases when kernel_profiler is on. And the memory consumption stops increasing if I add ti.profiler.clear_kernel_profiler_info()
at the end of the while loop. So I'm mostly certain that this memory consumption comes from CPU kernel profiler. We should definitely look into it later when revamping the profiler design. Thanks for reporting!
The demo progressively consumes CPU memory in the process of simulation When '_kernelprofiler=True'.