Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible memory leak with metaprogramming #139

Open
ultimatile opened this issue Jun 16, 2023 · 0 comments
Open

possible memory leak with metaprogramming #139

ultimatile opened this issue Jun 16, 2023 · 0 comments

Comments

@ultimatile
Copy link

ultimatile commented Jun 16, 2023

I am encountering a problem in TensorOperations.jl when using eval and Meta.parse for metaprogramming. The code runs fine without metaprogramming. However, when I use eval and Meta.parse with the @tensor macro, it appears that the memory used will grow, and eventually, all available memory will be used up and killed.

This code works fine;

using TensorOperations
for i in 1:1000
    a = 16; c = 18; b = 18; d = 16; m = 16; n = 16; u = 18; v = 18; A = rand(Float64, (a, u, v, b, c, d)); B = rand(Float64, (n, m, v, u)); @tensor C[d, a, b, m, c, n] := A[a, u, v, b, c, d] * B[n, m, v, u]
end

If only one line is executed, it takes

0.577926 seconds (17.09 k allocations: 736.200 MiB, 7.40% gc time, 31.36% compilation time)

The whole loop takes

343.437409 seconds (114.93 k allocations: 359.412 GiB, 3.63% gc time, 0.07% compilation time)

My problem happens when I use Meta.parse and eval for metaprogramming.

using TensorOperations
for i in 1:1000
    eval(Meta.parse("a = 16; c = 18; b = 18; d = 16; m = 16; n = 16; u = 18; v = 18; A = rand(Float64, (a, u, v, b, c, d));B = rand(Float64, (n, m, v, u)); @tensor C[d, a, b, m, c, n] := A[a, u, v, b, c, d] * B[n, m, v, u]"))
end

If only one line is executed, it takes

7.389352 seconds (41.43 M allocations: 2.726 GiB, 5.71% gc time, 93.99% compilation time)

However, when I run the whole for loop, the process runs out of memory on the machine, is killed, and cannot finish.
In my trial, the process died after the 179th execution.

Julia 1.8.5
TensorOperations v2.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant