Skip to content

Commit

Permalink
Merge branch 'main' into customconst
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses authored May 28, 2024
2 parents a64daca + 63a6759 commit 594626a
Show file tree
Hide file tree
Showing 15 changed files with 1,041 additions and 235 deletions.
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Enzyme"
uuid = "7da242da-08ed-463a-9acd-ee780be4f1d9"
authors = ["William Moses <[email protected]>", "Valentin Churavy <[email protected]>"]
version = "0.12.8"
version = "0.12.9"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Expand Down Expand Up @@ -29,8 +29,8 @@ EnzymeStaticArraysExt = "StaticArrays"
[compat]
CEnum = "0.4, 0.5"
ChainRulesCore = "1"
EnzymeCore = "0.7"
Enzyme_jll = "0.0.113"
EnzymeCore = "0.7.3"
Enzyme_jll = "0.0.117"
GPUCompiler = "0.21, 0.22, 0.23, 0.24, 0.25, 0.26"
LLVM = "6.1, 7"
ObjectFile = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion lib/EnzymeCore/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "EnzymeCore"
uuid = "f151be2c-9106-41f4-ab19-57ee4f262869"
authors = ["William Moses <[email protected]>", "Valentin Churavy <[email protected]>"]
version = "0.7.2"
version = "0.7.3"

[compat]
Adapt = "3, 4"
Expand Down
15 changes: 15 additions & 0 deletions lib/EnzymeCore/src/rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,21 @@ function is_inactive_noinl_from_sig(@nospecialize(TT);
return isapplicable(inactive_noinl, TT; world, method_table, caller)
end

"""
noalias(func::typeof(f), args...)
Mark a particular function as always being a fresh allocation which does not alias any other
accessible memory.
"""
function noalias end

function noalias_from_sig(@nospecialize(TT);
world::UInt=Base.get_world_counter(),
method_table::Union{Nothing,Core.Compiler.MethodTableView}=nothing,
caller::Union{Nothing,Core.MethodInstance}=nothing)
return isapplicable(noalias, TT; world, method_table, caller)
end

"""
inactive_type(::Type{Ty})
Expand Down
4 changes: 2 additions & 2 deletions src/Enzyme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ Enzyme.autodiff(ReverseWithPrimal, x->x*x, Active(3.0))
end

if A <: Active
if !allocatedinline(rt) || rt isa Union
if (!allocatedinline(rt) || rt isa Union) && rt != Union{}
forward, adjoint = Enzyme.Compiler.thunk(Val(world), FA, Duplicated{rt}, tt′, #=Split=# Val(API.DEM_ReverseModeGradient), Val(width), ModifiedBetween, #=ReturnPrimal=#Val(ReturnPrimal), #=ShadowInit=#Val(true), RABI)
res = forward(f, args...)
tape = res[1]
Expand All @@ -244,7 +244,7 @@ Enzyme.autodiff(ReverseWithPrimal, x->x*x, Active(3.0))
throw(ErrorException("Duplicated Returns not yet handled"))
end

if A <: Active && rt <: Complex
if (A <: Active && rt <: Complex) && rt != Union{}
if Holomorphic
seen = IdDict()
seen2 = IdDict()
Expand Down
21 changes: 14 additions & 7 deletions src/absint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,11 @@ function absint(arg::LLVM.Value, partial::Bool=false)
end
ptr = unsafe_load(reinterpret(Ptr{Ptr{Cvoid}}, convert(UInt, ce)))
if ptr == C_NULL
# XXX: Is this correct?
bt = GPUCompiler.backtrace(arg)
btstr = sprint() do io
Base.show_backtrace(io, bt)
end
@error "Found null pointer at\n $btstr" arg
# bt = GPUCompiler.backtrace(arg)
# btstr = sprint() do io
# Base.show_backtrace(io, bt)
# end
# @error "Found null pointer at\n $btstr" arg
return (false, nothing)
end
typ = Base.unsafe_pointer_to_objref(ptr)
Expand All @@ -144,6 +143,7 @@ function abs_typeof(arg::LLVM.Value, partial::Bool=false)::Union{Tuple{Bool, Typ
("jl_box_uint64", UInt64), ("ijl_box_uint64", UInt64),
("jl_box_int32", Int32), ("ijl_box_int32", Int32),
("jl_box_uint32", UInt32), ("ijl_box_uint32", UInt32),
("jl_box_float32", Float32), ("ijl_box_float32", Float32),
)
if nm == fname
return (true, ty)
Expand Down Expand Up @@ -221,7 +221,11 @@ function abs_typeof(arg::LLVM.Value, partial::Bool=false)::Union{Tuple{Bool, Typ
end

if nm == "jl_array_copy" || nm == "ijl_array_copy"
return abs_typeof(operands(arg)[1], partial)
legal, RT = abs_typeof(operands(arg)[1], partial)
if legal
@assert RT <: Array
end
return (legal, RT)
end

_, RT = enzyme_custom_extract_mi(arg, false)
Expand Down Expand Up @@ -284,6 +288,9 @@ function abs_typeof(arg::LLVM.Value, partial::Bool=false)::Union{Tuple{Bool, Typ
fieldoffset(typ, i+1)
end - offset
if fsize == llsz(value_type(larg))
if Base.isconcretetype(subT) && is_concrete_tuple(subT) && length(subT.parameters) == 1
subT = subT.parameters[1]
end
return (true, subT)
end
end
Expand Down
19 changes: 19 additions & 0 deletions src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,25 @@ function maxtypeoffset!(val)
ccall((:EnzymeSetCLInteger, libEnzyme), Cvoid, (Ptr{Cvoid}, Int64), ptr, val)
end

"""
maxtypedepth!(val::Bool)
Enzyme runs a type analysis to deduce the corresponding types of all values being
differentiated. This is necessary to compute correct derivatives of various values.
To ensure this analysis temrinates, it operates on a finite lattice of possible
states. This function sets the maximum depth into a type that Enzyme will consider.
A smaller value will cause type analysis to run faster, but may result in some
necessary types not being found and result in unknown type errors. A larger value
may result in unknown type errors being resolved by searching a larger space, but
may run longer. The default setting is 6.
"""
function maxtypedepth!(val)
ptr = cglobal((:EnzymeMaxTypeDepth, libEnzyme))
ccall((:EnzymeSetCLInteger, libEnzyme), Cvoid, (Ptr{Cvoid}, Int64), ptr, val)
end



"""
looseTypeAnalysis!(val::Bool)
Expand Down
Loading

0 comments on commit 594626a

Please sign in to comment.