Skip to content

Commit

Permalink
Disable attributor on known failing llvm versions (#986)
Browse files Browse the repository at this point in the history
* Disable attributor on known failing llvm versions

* wrap in runtime activity

* fquant

* extend non decayed phi undef
  • Loading branch information
wsmoses authored Aug 7, 2023
1 parent 3dd859d commit 8b23eb8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ function nodecayed_phis!(mod::LLVM.Module)
for (i, gp) in enumerate(gty)
push!(geps[i], (LLVM.ConstantInt(gp, 0), pb))
end
elseif isa(v, LLVM.UndefValue)
for (i, gp) in enumerate(gty)
push!(geps[i], (LLVM.ConstantInt(gp, 0), pb))
end
else
@show f
@show gty, inst, v
Expand Down Expand Up @@ -949,16 +953,20 @@ function removeDeadArgs!(mod::LLVM.Module)
end
propagate_returned!(mod)
pre_attr!(mod)
ModulePassManager() do pm
API.EnzymeAddAttributorLegacyPass(pm)
run!(pm, mod)
if LLVM.version().major >= 13
ModulePassManager() do pm
API.EnzymeAddAttributorLegacyPass(pm)
run!(pm, mod)
end
end
propagate_returned!(mod)
ModulePassManager() do pm
instruction_combining!(pm)
alloc_opt!(pm)
scalar_repl_aggregates_ssa!(pm) # SSA variant?
API.EnzymeAddAttributorLegacyPass(pm)
if LLVM.version().major >= 13
API.EnzymeAddAttributorLegacyPass(pm)
end
run!(pm, mod)
end
post_attr!(mod)
Expand Down Expand Up @@ -1067,7 +1075,7 @@ end
gvn!(pm) # Exxtra
run!(pm, mod)
end

removeDeadArgs!(mod)
detect_writeonly!(mod)
nodecayed_phis!(mod)
Expand Down
4 changes: 2 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function codegen_world_age_generator(world::UInt, source, self, ft::Type, tt::Ty
tt = tt.parameters[1]

# validation
ft <: Core.Builtin && error("$(unsafe_function_from_type(ft)) is not a generic function")
ft <: Core.Builtin && error("$(GPUCompiler.unsafe_function_from_type(ft)) is not a generic function")

# look up the method
method_error = :(throw(MethodError(ft, tt, $world)))
Expand Down Expand Up @@ -155,7 +155,7 @@ function codegen_world_age_generator(self, ft::Type, tt::Type)
tt = tt.parameters[1]

# validation
ft <: Core.Builtin && error("$(unsafe_function_from_type(ft)) is not a generic function")
ft <: Core.Builtin && error("$(GPUCompiler.unsafe_function_from_type(ft)) is not a generic function")

# look up the method
method_error = :(throw(MethodError(ft, tt)))
Expand Down
32 changes: 32 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,38 @@ end
Enzyme.API.runtimeActivity!(false)
end

@inline function myquantile(v::AbstractVector, p::Real; alpha)
n = length(v)

m = 1.0 + p * (1.0 - alpha - 1.0)
aleph = n*p + oftype(p, m)
j = clamp(trunc(Int, aleph), 1, n-1)
γ = clamp(aleph - j, 0, 1)

if n == 1
a = @inbounds v[1]
b = @inbounds v[1]
else
a = @inbounds v[j]
b = @inbounds v[j + 1]
end

return a + γ*(b-a)
end

function fquantile(x)
v = [1.0, x]
return @inbounds (map(y->myquantile(v, y, alpha=1.), [0.7]))[1]
end

@testset "Attributor issues" begin

cor = fquantile(2.0)
res = autodiff(Forward, fquantile, Duplicated,Duplicated(2.0, 1.0))
@test cor res[1]
@test 0.7 res[2]

end

## https://github.com/JuliaDiff/ChainRules.jl/tree/master/test/rulesets
if !Sys.iswindows()
Expand Down

2 comments on commit 8b23eb8

@wsmoses
Copy link
Member Author

@wsmoses wsmoses commented on 8b23eb8 Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: "Tag with name v0.11.6 already exists and points to a different commit"

Please sign in to comment.