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

Missing derivative rule for ptr_to_array & co. #2257

Closed
vchuravy opened this issue Jan 8, 2025 · 0 comments · Fixed by #2258
Closed

Missing derivative rule for ptr_to_array & co. #2257

vchuravy opened this issue Jan 8, 2025 · 0 comments · Fixed by #2258

Comments

@vchuravy
Copy link
Member

vchuravy commented Jan 8, 2025

julia> function f(a, i, x)
           GC.@preserve a begin
                ptr = pointer(a)
                b = Base.unsafe_wrap(Array, ptr, length(a))
                b[i] = x
           end
           a[i]
       end
f (generic function with 1 method)

julia> autodiff(Forward, f,  Duplicated(zeros(1), zeros(1)), Const(1), Duplicated(1.0, 2.0))
ERROR:
No forward mode derivative found for ijl_ptr_to_array_1d
 at context:   %12 = call nonnull "enzyme_type"="{[-1]:Pointer}" {} addrspace(10)* @ijl_ptr_to_array_1d({} addrspace(10)* noundef addrspacecast ({}* inttoptr (i64 125915773691440 to {}*) to {} addrspace(10)*), i64 %11, i64 %arraylen, i32 noundef 0) #8, !dbg !47

Stacktrace:
 [1] #unsafe_wrap#106
   @ ./pointer.jl:92
 [2] unsafe_wrap
   @ ./pointer.jl:90
 [3] f
   @ ./REPL[7]:4


Stacktrace:
  [1] #unsafe_wrap#106
    @ ./pointer.jl:92 [inlined]
  [2] unsafe_wrap
    @ ./pointer.jl:90 [inlined]
  [3] f
    @ ./REPL[7]:4 [inlined]
  [4] fwddiffejulia_f_949wrap
    @ ./REPL[7]:0
  [5] macro expansion
    @ ~/src/Enzyme/src/compiler.jl:5340 [inlined]
  [6] enzyme_call
    @ ~/src/Enzyme/src/compiler.jl:4878 [inlined]
  [7] ForwardModeThunk
    @ ~/src/Enzyme/src/compiler.jl:4766 [inlined]
  [8] autodiff
    @ ~/src/Enzyme/src/Enzyme.jl:654 [inlined]
  [9] autodiff
    @ ~/src/Enzyme/src/Enzyme.jl:544 [inlined]
 [10] autodiff(::ForwardMode{false, FFIABI, false, false}, ::typeof(f), ::Duplicated{Vector{Float64}}, ::Const{Int64}, ::Duplicated{Float64})
    @ Enzyme ~/src/Enzyme/src/Enzyme.jl:516
 [11] top-level scope
    @ REPL[8]: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

Successfully merging a pull request may close this issue.

1 participant