Error in gradient when using map! on Julia 1.9.4
Problem
I am getting a randomly incorrect gradient in Julia 1.9.4 using the main version of Enzyme. The MWE is
using Enzyme
function inplace_map(out, inner, a, b)
map!(out, inner, a, b) do vi, ai, bi
ai*vi*bi'
end
return nothing
end
n = 32
Δout = randn(Float64, n)
a = randn(Float64, n)
Δa = zero(a)
b = randn(Float64, n)
Δb = zero(b)
inner = randn(Float64, n)
Δinner = zero(inner)
out = similar(inner)
autodiff(Reverse, inplace_map, Const, Duplicated(out, copy(Δout)), Duplicated(inner, fill!(Δinner,0)), Duplicated(a, fill!(Δa,0)), Duplicated(b, fill!(Δb,0)))
Δinner
Δa
Δb
When I run this, it looks like none of the gradients are correct. Interestingly, the size of the array seems to matter here. Everything seems fine on my machine if n<32. It is only for arrays with size >31 that the result is wrong.
Computing version
Julia Version 1.9.4
Commit 8e5136fa297 (2023-11-14 08:46 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 32 × AMD Ryzen 9 7950X 16-Core Processor
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, znver3)
Threads: 1 on 32 virtual cores
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS = 1
Project
Status `~/Research/EnzymeTest/Project.toml`
[7da242da] Enzyme v0.11.11 `https://github.com/EnzymeAD/Enzyme.jl.git#main`
@ptiede can you show an example of a fixed input and what you'd expect. I tried to reproduce on my system and got what I expected.
wmoses@beast:~/git/Enzyme.jl (sptrr) $ cat maperr.jl
using Enzyme
function inplace_map(out, inner, a, b)
map!(out, inner, a, b) do vi, ai, bi
ai*vi*bi'
end
return nothing
end
n = 32
Δout = zeros(n)
a = ones(n)
Δa = zero(a)
b = zeros(n)
Δb = zero(b)
inner = zeros(n)
Δinner = zero(inner)
out = similar(inner)
for i in 1:n
Δout[i] = i
b[i] = 1/(1+3*i)
inner[i] = 3 - 2 * i
end
autodiff(Reverse, inplace_map, Const, Duplicated(out, copy(Δout)), Duplicated(inner, fill!(Δinner,0)), Duplicated(a, fill!(Δa,0)), Duplicated(b, fill!(Δb,0)))
@show Δinner, (Δout .* a .* b)
@show Δa, (Δout .* inner .* b)
@show Δb, (Δout .* a .* inner)
@show out
(Δinner, (Δout .* a) .* b) = (
[0.25, 0.2857142857142857, 0.30000000000000004, 0.3076923076923077, 0.3125, 0.3157894736842105, 0.3181818181818182, 0.32, 0.3214285714285714, 0.3225806451612903, 0.3235294117647059, 0.32432432432432434, 0.325, 0.32558139534883723, 0.32608695652173914, 0.32653061224489793, 0.3269230769230769, 0.32727272727272727, 0.3275862068965517, 0.3278688524590164, 0.328125, 0.3283582089552239, 0.32857142857142857, 0.3287671232876712, 0.3289473684210526, 0.3291139240506329, 0.32926829268292684, 0.32941176470588235, 0.32954545454545453, 0.3296703296703297, 0.32978723404255317, 0.32989690721649484],
[0.25, 0.2857142857142857, 0.30000000000000004, 0.3076923076923077, 0.3125, 0.3157894736842105, 0.3181818181818182, 0.32, 0.3214285714285714, 0.3225806451612903, 0.3235294117647059, 0.32432432432432434, 0.325, 0.32558139534883723, 0.32608695652173914, 0.32653061224489793, 0.3269230769230769, 0.32727272727272727, 0.3275862068965517, 0.3278688524590164, 0.328125, 0.3283582089552239, 0.32857142857142857, 0.3287671232876712, 0.3289473684210526, 0.3291139240506329, 0.32926829268292684, 0.32941176470588235, 0.32954545454545453, 0.3296703296703297, 0.32978723404255317, 0.32989690721649484]
)
(Δa, (Δout .* inner) .* b) = (
[0.25, -0.2857142857142857, -0.9000000000000001, -1.5384615384615385, -2.1875, -2.8421052631578947, -3.5, -4.16, -4.821428571428571, -5.483870967741935, -6.147058823529412, -6.810810810810811, -7.4750000000000005, -8.13953488372093, -8.804347826086957, -9.46938775510204, -10.134615384615385, -10.8, -11.46551724137931, -12.131147540983608, -12.796875, -13.462686567164178, -14.128571428571428, -14.794520547945204, -15.460526315789473, -16.12658227848101, -16.79268292682927, -17.458823529411763, -18.125, -18.791208791208796, -19.457446808510635, -20.123711340206185], [0.25, -0.2857142857142857, -0.9, -1.5384615384615385, -2.1875, -2.8421052631578947, -3.5, -4.16, -4.821428571428571, -5.483870967741935, -6.147058823529411, -6.810810810810811, -7.4750000000000005, -8.13953488372093, -8.804347826086957, -9.46938775510204, -10.134615384615385, -10.799999999999999, -11.46551724137931, -12.131147540983607, -12.796875, -13.462686567164178, -14.128571428571428, -14.794520547945204, -15.460526315789473, -16.126582278481013, -16.79268292682927, -17.458823529411763, -18.125, -18.791208791208792, -19.45744680851064, -20.123711340206185])
(Δb, (Δout .* a) .* inner) = (
[1.0, -2.0, -9.0, -20.0, -35.0, -54.0, -77.0, -104.0, -135.0, -170.0, -209.0, -252.0, -299.0, -350.0, -405.0, -464.0, -527.0, -594.0, -665.0, -740.0, -819.0, -902.0, -989.0, -1080.0, -1175.0, -1274.0, -1377.0, -1484.0, -1595.0, -1710.0, -1829.0, -1952.0],
[1.0, -2.0, -9.0, -20.0, -35.0, -54.0, -77.0, -104.0, -135.0, -170.0, -209.0, -252.0, -299.0, -350.0, -405.0, -464.0, -527.0, -594.0, -665.0, -740.0, -819.0, -902.0, -989.0, -1080.0, -1175.0, -1274.0, -1377.0, -1484.0, -1595.0, -1710.0, -1829.0, -1952.0]
)
out = [0.25, -0.14285714285714285, -0.30000000000000004, -0.38461538461538464, -0.4375, -0.47368421052631576, -0.5, -0.52, -0.5357142857142857, -0.5483870967741935, -0.5588235294117647, -0.5675675675675675, -0.5750000000000001, -0.5813953488372093, -0.5869565217391304, -0.5918367346938775, -0.5961538461538461, -0.6, -0.603448275862069, -0.6065573770491803, -0.609375, -0.6119402985074627, -0.6142857142857142, -0.6164383561643836, -0.6184210526315789, -0.620253164556962, -0.6219512195121951, -0.6235294117647059, -0.625, -0.6263736263736264, -0.6276595744680851, -0.6288659793814433]
That is weird. For fixed inputs I get the following:
using Enzyme
function inplace_map(out, inner, a, b)
map!(out, inner, a, b) do vi, ai, bi
ai*vi*bi
end
return nothing
end
n = 32
Δout = ones(Float64, n)
a = 2*ones(Float64, n)
Δa = zero(a)
b = 2*ones(Float64, n)
Δb = zero(b)
inner = 3*ones(Float64, n)
Δinner = zero(inner)
out = similar(inner)
autodiff(Reverse, inplace_map, Const, Duplicated(out, copy(Δout)), Duplicated(inner, fill!(Δinner,0)), Duplicated(a, fill!(Δa,0)), Duplicated(b, fill!(Δb,0)))
@show Δinner, (Δout .* a .* b)
@show Δa, (Δout .* inner .* b)
@show Δb, (Δout .* a .* inner)
@show out
(Δinner, (Δout .* a) .* b) = ([1.634225976e-315, 8.87507204e-316, 1.299582089461033e-309, 6.62907857e-316, 1.438373344e-315, 3.3476e-319, 8.39606463e-316, 2.5641173e-316, 7.0553256e-316, 6.41462266e-316, 1.299582089461033e-309, 1.384256743e-315, 8.3455158e-316, 1.74405e-319, 1.562859093e-315, 6.58458766e-316, 6.55801375e-316, 7.27555803e-316, 1.299582089461033e-309, 6.34846895e-316, 1.281850413e-315, 3.86023e-319, 6.77737386e-316, 1.53969769e-315, 8.9523461e-316, 1.396451756e-315, 1.299582089461033e-309, 1.40303785e-315, 1.55054272e-315, 2.03446e-319, 6.664145e-316, 1.27842575e-315], [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0])
(Δa, (Δout .* inner) .* b) = ([1.14566118e-315, 7.6729113e-316, 3.806e-319, 1.38297503e-315, 1.38190831e-315, 1.371058185e-315, 8.17586856e-316, 1.299582089461033e-309, 8.69902124e-316, 1.573298907e-315, 1.70433e-319, 6.96121805e-316, 8.4954398e-316, 7.1445103e-316, 1.036309747e-315, 1.299582089461033e-309, 1.570014853e-315, 8.28873826e-316, 3.46646e-319, 3.4854343e-316, 1.60060294e-315, 1.581384065e-315, 1.37943481e-315, 1.299582089461033e-309, 1.08451583e-315, 1.508364956e-315, 3.90094e-319, 1.079541924e-315, 1.5337693e-315, 8.32988533e-316, 8.52762473e-316, 1.299582089461033e-309], [6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0])
(Δb, (Δout .* a) .* inner) = ([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0])
out = [12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0]
julia> versioninfo()
Julia Version 1.9.4
Commit 8e5136fa297 (2023-11-14 08:46 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 32 × AMD Ryzen 9 7950X 16-Core Processor
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, znver3)
Threads: 1 on 32 virtual cores
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS = 1
Can you show ] st and maybe try the latest 0.11.12 release of Enzyme?
I cannot reproduce your issue.
wmoses@beast:~/git/Enzyme.jl ((HEAD detached at origin/main)) $ ./julia-1.9.1/bin/julia --project maperr.jl
(Δinner, (Δout .* a) .* b) = ([4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0], [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0])
(Δa, (Δout .* inner) .* b) = ([6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0], [6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0])
(Δb, (Δout .* a) .* inner) = ([6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0], [6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0])
out = [12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0]
wmoses@beast:~/git/Enzyme.jl ((HEAD detached at origin/main)) $ ./julia-1.9.4/bin/julia --project maperr.jl
(Δinner, (Δout .* a) .* b) = ([4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0], [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0])
(Δa, (Δout .* inner) .* b) = ([6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0], [6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0])
(Δb, (Δout .* a) .* inner) = ([6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0], [6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0])
out = [12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0]
Here is my status. I think I am using the current version of Enzyme.
Status `~/Research/EnzymeTest/Project.toml`
[7da242da] Enzyme v0.11.12 `https://github.com/EnzymeAD/Enzyme.jl.git#main
and st -m
Status `~/Research/EnzymeTest/Manifest.toml`
⌅ [79e6a3ab] Adapt v3.7.2
[fa961155] CEnum v0.5.0
[7da242da] Enzyme v0.11.12 `https://github.com/EnzymeAD/Enzyme.jl.git#main`
[f151be2c] EnzymeCore v0.6.4
[e2ba6199] ExprTools v0.1.10
[61eb1bfa] GPUCompiler v0.25.0
[692b3bcd] JLLWrappers v1.5.0
[929cbde3] LLVM v6.4.1
[d8793406] ObjectFile v0.4.1
[21216c6a] Preferences v1.4.1
[189a3867] Reexport v1.2.2
[ae029012] Requires v1.3.0
[6c6a2e73] Scratch v1.2.1
[53d494c1] StructIO v0.3.0
[a759f4b9] TimerOutputs v0.5.23
[7cc45869] Enzyme_jll v0.0.98+0
[dad2f222] LLVMExtra_jll v0.0.27+1
[0dad84c5] ArgTools v1.1.1
[56f22d72] Artifacts
[2a0f44e3] Base64
[ade2ca70] Dates
[f43a241f] Downloads v1.6.0
[7b1f6079] FileWatching
[b77e0a4c] InteractiveUtils
[4af54fe1] LazyArtifacts
[b27032c2] LibCURL v0.6.4
[76f85450] LibGit2
[8f399da3] Libdl
[37e2e46d] LinearAlgebra
[56ddb016] Logging
[d6f4376e] Markdown
[ca575930] NetworkOptions v1.2.0
[44cfe95a] Pkg v1.9.2
[de0858da] Printf
[3fa0cd96] REPL
[9a3f8284] Random
[ea8e919c] SHA v0.7.0
[9e88b42a] Serialization
[6462fe0b] Sockets
[fa267f1f] TOML v1.0.3
[a4e569a6] Tar v1.10.0
[8dfed614] Test
[cf7118a7] UUIDs
[4ec0a83e] Unicode
[e66e0078] CompilerSupportLibraries_jll v1.0.5+0
[deac9b47] LibCURL_jll v8.4.0+0
[29816b5a] LibSSH2_jll v1.11.0+1
[c8ffd9c3] MbedTLS_jll v2.28.2+0
[14a3606d] MozillaCACerts_jll v2022.10.11
[4536629a] OpenBLAS_jll v0.3.21+4
[83775a58] Zlib_jll v1.2.13+0
[8e850b90] libblastrampoline_jll v5.8.0+0
[8e850ede] nghttp2_jll v1.52.0+1
[3f19e933] p7zip_jll v17.4.0+0
Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated -m`
I get this error reliably on my machine and my unit tests on github for some of my repos. If you change the size of the array, e.g., make it larger, do you see an error appear? I know for my machine, I see this issue only for larger vectors.
Can you link one of the repos? If you give me acces, I can try to maybe debug it in CI.
Alternatively if perhaps [over DM in slack] you give me ssh access to a machine with it failing, I can take a look?
The easiest is probably SSH. I messaged you in slack.
Here is the latest map file
using Enzyme
Enzyme.API.printall!(true)
@noinline function my_map_n!(dest::AbstractArray, As)
n = length(As[1])
i = 0
while i < 70
i+=1
@inbounds dest[i] = @inbounds As[1][i] * As[2][]
end
end
function inplace_map(out, inner, a)
my_map_n!(out, (inner, a))
return nothing
end
n = 70
Δout = ones(Float64, n)
a = 2*ones(Float64, n)
Δa = zero(a)
a = Ref(2.0)
Δa = Ref(0.0)
b = zeros(n)
db = zeros(n)
inner = collect(Float64, 3*(1:n)) #ones(Float64, n)
Δinner = zero(inner)
out = similar(inner)
out = 7 * ones(Float64, n)
autodiff(Reverse, inplace_map, Const, Duplicated(out, copy(Δout)), Duplicated(inner, fill!(Δinner,0)), Duplicated(a, Δa))
@show Δinner, (Δout .* a );
@show Δa, (Δout .* inner )
# @show Δb, (Δout .* a .* inner)
@show out
And the Enzyme output https://gist.github.com/ptiede/8c7246f6c0013aafbe8d366cd4c0677c
New version of issue
using Enzyme
Enzyme.API.printall!(true)
@noinline function my_map_n!(dest, As)
n = length(As[1])
i = 0
ptr = Base.unsafe_convert(Ptr{Float64}, As[1])
d = Base.unsafe_convert(Ptr{Float64}, dest)
while i < n
i+=1
Base.unsafe_store!(d, unsafe_load(ptr) * As[2][], i)
end
end
function inplace_map(out, inner, a)
my_map_n!(out, (inner, a))
return nothing
end
n = 64
dout = ones(Float64, n)
a = 2*ones(Float64, n)
Δa = zero(a)
a = Ref(2.0)
Δa = Ref(0.0)
b = zeros(n)
db = zeros(n)
inner = collect(Float64, 3*(1:n)) #ones(Float64, n)
dinner = zero(inner)
out = similar(inner)
out = 7 * ones(Float64, n)
# i = Base.unsafe_convert(Ptr{Float64}, inner)
# di = Base.unsafe_convert(Ptr{Float64}, dinner)
i = inner
di = dinner
o = Base.unsafe_convert(Ptr{Float64}, out)
cout = copy(dout)
ddo = Base.unsafe_convert(Ptr{Float64}, cout)
inplace_map(o, i, a)
autodiff(Reverse, inplace_map, Const, Duplicated(o, ddo), Duplicated(i, di), Duplicated(a, Δa))
@show dinner, (dout .* a );
@show Δa, (dout .* inner )
# @show Δb, (Δout .* a .* inner)
@show out, dout, cout
And new output file https://gist.github.com/ptiede/8954786719baa4f91c91c9c472ebe8aa
Trying to isolate, this doesn't fail sadly: https://fwd.gymni.ch/2SBMep
Okay this shows the error (post diff on your machine): https://fwd.gymni.ch/a5Eecl
wmoses@beast:~/git/Enzyme/enzyme/build14 ((HEAD detached at origin/main)) $ ~/llvms/llvm14/buildD/bin/opt -load-pass-plugin=Enzyme/LLVMEnzyme-14.so inp2.ll -load=Enzyme/LLVMEnzyme-14.so -enzyme-preopt=0 -passes="enzyme,module(require<asan-globals-md>,sancov-module,asan-module)" -o out.ll && ~/llvms/llvm14/buildD/bin/clang out.ll -o out.exe -fsanitize=address && ./out.exe
warning: overriding the module target triple with x86_64-unknown-linux-gnu [-Woverride-module]
1 warning generated.
AddressSanitizer:DEADLYSIGNAL
=================================================================
==4186710==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000001 (pc 0x000000516ae8 bp 0x7ffd501ff7a0 sp 0x7ffd501fe0c0 T0)
==4186710==The signal is caused by a READ memory access.
==4186710==Hint: address points to the zero page.
#0 0x516ae8 (/home/wmoses/git/Enzyme/enzyme/build14/out.exe+0x516ae8)
#1 0x512245 (/home/wmoses/git/Enzyme/enzyme/build14/out.exe+0x512245)
#2 0x7fd6811ebd8f (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
#3 0x7fd6811ebe3f (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
#4 0x41c354 (/home/wmoses/git/Enzyme/enzyme/build14/out.exe+0x41c354)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/home/wmoses/git/Enzyme/enzyme/build14/out.exe+0x516ae8)
==4186710==ABORTING
And now preopt: https://fwd.gymni.ch/FgBvNa
wmoses@beast:~/git/Enzyme/enzyme/build14 ((HEAD detached at origin/main)) $ ~/llvms/llvm14/buildD/bin/opt -load-pass-plugin=Enzyme/LLVMEnzyme-14.so inp3.ll -load=Enzyme/LLVMEnzyme-14.so -enzyme-preopt=0 -passes="enzyme,module(require<asan-globals-md>,sancov-module,asan-module)" -o out.ll && ~/llvms/llvm14/buildD/bin/clang out.ll -o out.exe -fsanitize=address && ./out.exe
warning: overriding the module target triple with x86_64-unknown-linux-gnu [-Woverride-module]
1 warning generated.
AddressSanitizer:DEADLYSIGNAL
=================================================================
==4187919==ERROR: AddressSanitizer: SEGV on unknown address 0x71b71fae6970 (pc 0x71b71fae6970 bp 0x7ffdfcb4fa10 sp 0x7ffdfcb4ef18 T0)
==4187919==The signal is caused by a READ memory access.
AddressSanitizer:DEADLYSIGNAL
AddressSanitizer: nested bug in the same thread, aborting.
wmoses@beast:~/git/Enzyme/enzyme/build14 ((HEAD detached at origin/main)) $ gdb --args ~/llvms/llvm14/buildD/bin/lli --jit-kind=mcjit --force-interpreter inp3.ll
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/wmoses/llvms/llvm14/buildD/bin/lli...
(gdb) r
Starting program: /home/wmoses/llvms/llvm14/buildD/bin/lli --jit-kind=mcjit --force-interpreter inp3.ll
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x0000555556723c2f in llvm::ExecutionEngine::LoadValueFromMemory (this=0x55555a9a84f0, Result=..., Ptr=0x0, Ty=0x55555a97fda0) at /home/wmoses/llvms/llvm14/llvm/lib/ExecutionEngine/ExecutionEngine.cpp:1083
1083 Result.DoubleVal = *((double*)Ptr);
(gdb) p Ptr
$1 = (llvm::GenericValue *) 0x0
(gdb) up
#1 0x000055555674a3ef in llvm::Interpreter::visitLoadInst (this=0x55555a9a84f0, I=...) at /home/wmoses/llvms/llvm14/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp:1098
1098 LoadValueFromMemory(Result, Ptr, I.getType());
(gdb) p I.dump()
%i2317 = load double, double addrspace(11)* %"i18'ipc_unwrap104", align 8, !dbg !286, !tbaa !292, !alias.scope !429, !noalias !430
$2 = void
@ptiede out of curiousity does this still fail on the same machine/julia version/etc (but modern enzyme)?
bumping this @ptiede
I can no longer reproduce this on my machine so I think it is fixed!