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

Type analysis depth limit / task switch not allowed from inside staged nor pure functions #1354

Closed
gdalle opened this issue Mar 20, 2024 · 3 comments · Fixed by JuliaDiff/ReverseDiff.jl#252

Comments

@gdalle
Copy link
Contributor

gdalle commented Mar 20, 2024

I have some code in DifferentiationInterface for second-order differentiation with mixed backends.
My current issue is with Enzyme (forward mode) over ReverseDiff. I get these HUGE printed warnings from Enzyme, saying

Warning: TypeAnalysisDepthLimit

followed by an equally obscure error

ERROR: task switch not allowed from inside staged nor pure functions

Is there any way to understand or solve either of those?

MWE

julia> import Enzyme, ReverseDiff

julia> f1(x) = sum(abs2.(x))
f1 (generic function with 1 method)

julia> f2(x) = sum(abs2, x)  # different from f1
f2 (generic function with 1 method)

julia> g1(x) = ReverseDiff.gradient(f1, x)
g1 (generic function with 1 method)

julia> g2(x) = ReverseDiff.gradient(f2, x)
g2 (generic function with 1 method)

julia> H1(x) = Enzyme.jacobian(Enzyme.Forward, g1, x)
H1 (generic function with 1 method)

julia> H2(x) = Enzyme.jacobian(Enzyme.Forward, g2, x)
H2 (generic function with 1 method)

julia> H1([1.0])
1-element Vector{Float64}:
 2.0

julia> H2([1.0])
[a lot of the same]
┌ Warning: TypeAnalysisDepthLimit
│ LLVM.StoreInst(store atomic {} addrspace(10)* %box468, {} addrspace(10)* addrspace(13)* %201 release, align 8, !dbg !308, !tbaa !297, !alias.scope !87, !noalias !88)
│ {[]:Pointer, [0]:Pointer, [0,0]:Pointer, [0,0,0]:Float@double, [0,0,8]:Float@double, [0,0,16]:Pointer, [0,0,16,0]:Pointer, [0,0,16,0,0]:Pointer, [0,0,16,8]:Integer, [0,0,16,9]:Integer, [0,0,16,10]:Integer, [0,0,16,11]:Integer, [0,0,16,12]:Integer, [0,0,16,13]:Integer, [0,0,16,14]:Integer, [0,0,16,15]:Integer, [0,0,16,16]:Integer, [0,0,16,17]:Integer, [0,0,16,18]:Integer, [0,0,16,19]:Integer, [0,0,16,20]:Integer, [0,0,16,21]:Integer, [0,0,16,22]:Integer, [0,0,16,23]:Integer, [0,0,16,24]:Integer, [0,0,16,25]:Integer, [0,0,16,26]:Integer, [0,0,16,27]:Integer, [0,0,16,28]:Integer, [0,0,16,29]:Integer, [0,0,16,30]:Integer, [0,0,16,31]:Integer, [0,0,16,32]:Integer, [0,0,16,33]:Integer, [0,0,16,34]:Integer, [0,0,16,35]:Integer, [0,0,16,36]:Integer, [0,0,16,37]:Integer, [0,0,16,38]:Integer, [0,0,16,39]:Integer, [0,0,24]:Integer, [0,0,25]:Integer, [0,0,26]:Integer, [0,0,27]:Integer, [0,0,28]:Integer, [0,0,29]:Integer, [0,0,30]:Integer, [0,0,31]:Integer, [0,0,32]:Pointer, [0,0,32,0]:Pointer, [0,0,32,0,0]:Pointer, [0,0,32,0,0,0]:Float@double, [0,0,32,0,8]:Integer, [0,0,32,0,9]:Integer, [0,0,32,0,10]:Integer, [0,0,32,0,11]:Integer, [0,0,32,0,12]:Integer, [0,0,32,0,13]:Integer, [0,0,32,0,14]:Integer, [0,0,32,0,15]:Integer, [0,0,32,0,16]:Integer, [0,0,32,0,17]:Integer, [0,0,32,0,18]:Integer, [0,0,32,0,19]:Integer, [0,0,32,0,20]:Integer, [0,0,32,0,21]:Integer, [0,0,32,0,22]:Integer, [0,0,32,0,23]:Integer, [0,0,32,0,24]:Integer, [0,0,32,0,25]:Integer, [0,0,32,0,26]:Integer, [0,0,32,0,27]:Integer, [0,0,32,0,28]:Integer, [0,0,32,0,29]:Integer, [0,0,32,0,30]:Integer, [0,0,32,0,31]:Integer, [0,0,32,0,32]:Integer, [0,0,32,0,33]:Integer, [0,0,32,0,34]:Integer, [0,0,32,0,35]:Integer, [0,0,32,0,36]:Integer, [0,0,32,0,37]:Integer, [0,0,32,0,38]:Integer, [0,0,32,0,39]:Integer, [0,0,32,8,0,0]:Float@double, [0,0,32,16,0,0]:Pointer, [0,1,0]:Float@double, [0,1,8]:Float@double, [0,1,16]:Pointer, [0,1,16,0]:Pointer, [0,1,16,0,0]:Pointer, [0,1,16,8]:Integer, [0,1,16,9]:Integer, [0,1,16,10]:Integer, [0,1,16,11]:Integer, [0,1,16,12]:Integer, [0,1,16,13]:Integer, [0,1,16,14]:Integer, [0,1,16,15]:Integer, [0,1,16,16]:Integer, [0,1,16,17]:Integer, [0,1,16,18]:Integer, [0,1,16,19]:Integer, [0,1,16,20]:Integer, [0,1,16,21]:Integer, [0,1,16,22]:Integer, [0,1,16,23]:Integer, [0,1,16,24]:Integer, [0,1,16,25]:Integer, [0,1,16,26]:Integer, [0,1,16,27]:Integer, [0,1,16,28]:Integer, [0,1,16,29]:Integer, [0,1,16,30]:Integer, [0,1,16,31]:Integer, [0,1,16,32]:Integer, [0,1,16,33]:Integer, [0,1,16,34]:Integer, [0,1,16,35]:Integer, [0,1,16,36]:Integer, [0,1,16,37]:Integer, [0,1,16,38]:Integer, [0,1,16,39]:Integer, [0,1,24]:Integer, [0,1,25]:Integer, [0,1,26]:Integer, [0,1,27]:Integer, [0,1,28]:Integer, [0,1,29]:Integer, [0,1,30]:Integer, [0,1,31]:Integer, [0,1,32]:Pointer, [0,1,32,0]:Pointer, [0,1,32,0,0]:Pointer, [0,1,32,0,0,0]:Float@double, [0,1,32,0,8]:Integer, [0,1,32,0,9]:Integer, [0,1,32,0,10]:Integer, [0,1,32,0,11]:Integer, [0,1,32,0,12]:Integer, [0,1,32,0,13]:Integer, [0,1,32,0,14]:Integer, [0,1,32,0,15]:Integer, [0,1,32,0,16]:Integer, [0,1,32,0,17]:Integer, [0,1,32,0,18]:Integer, [0,1,32,0,19]:Integer, [0,1,32,0,20]:Integer, [0,1,32,0,21]:Integer, [0,1,32,0,22]:Integer, [0,1,32,0,23]:Integer, [0,1,32,0,24]:Integer, [0,1,32,0,25]:Integer, [0,1,32,0,26]:Integer, [0,1,32,0,27]:Integer, [0,1,32,0,28]:Integer, [0,1,32,0,29]:Integer, [0,1,32,0,30]:Integer, [0,1,32,0,31]:Integer, [0,1,32,0,32]:Integer, [0,1,32,0,33]:Integer, [0,1,32,0,34]:Integer, [0,1,32,0,35]:Integer, [0,1,32,0,36]:Integer, [0,1,32,0,37]:Integer, [0,1,32,0,38]:Integer, [0,1,32,0,39]:Integer, [0,1,32,8,0,0]:Float@double, [0,1,32,16,0,0]:Pointer, [0,2,0]:Float@double, [0,2,8]:Float@double, [0,2,16]:Pointer, [0,2,16,0]:Pointer, [0,2,16,0,0]:Pointer, [0,2,16,8]:Integer, [0,2,16,9]:Integer, [0,2,16,10]:Integer, [0,2,16,11]:Integer, [0,2,16,12]:Integer, [0,2,16,13]:Integer, [0,2,16,14]:Integer, [0,2,16,15]:Integer, [0,2,16,16]:Integer, [0,2,16,17]:Integer, [0,2,16,18]:Integer, [0,2,16,19]:Integer, [0,2,16,20]:Integer, [0,2,16,21]:Integer, [0,2,16,22]:Integer, [0,2,16,23]:Integer, [0,2,16,24]:Integer, [0,2,16,25]:Integer, [0,2,16,26]:Integer, [0,2,16,27]:Integer, [0,2,16,28]:Integer, [0,2,16,29]:Integer, [0,2,16,30]:Integer, [0,2,16,31]:Integer, [0,2,16,32]:Integer, [0,2,16,33]:Integer, [0,2,16,34]:Integer, [0,2,16,35]:Integer, [0,2,16,36]:Integer, [0,2,16,37]:Integer, [0,2,16,38]:Integer, [0,2,16,39]:Integer, [0,2,24]:Integer, [0,2,25]:Integer, [0,2,26]:Integer, [0,2,27]:Integer, [0,2,28]:Integer, [0,2,29]:Integer, [0,2,30]:Integer, [0,2,31]:Integer, [0,2,32]:Pointer, [0,2,32,0]:Pointer, [0,2,32,0,0]:Pointer, [0,2,32,0,0,0]:Float@double, [0,2,32,0,8]:Integer, [0,2,32,0,9]:Integer, [0,2,32,0,10]:Integer, [0,2,32,0,11]:Integer, [0,2,32,0,12]:Integer, [0,2,32,0,13]:Integer, [0,2,32,0,14]:Integer, [0,2,32,0,15]:Integer, [0,2,32,0,16]:Integer, [0,2,32,0,17]:Integer, [0,2,32,0,18]:Integer, [0,2,32,0,19]:Integer, [0,2,32,0,20]:Integer, [0,2,32,0,21]:Integer, [0,2,32,0,22]:Integer, [0,2,32,0,23]:Integer, [0,2,32,0,24]:Integer, [0,2,32,0,25]:Integer, [0,2,32,0,26]:Integer, [0,2,32,0,27]:Integer, [0,2,32,0,28]:Integer, [0,2,32,0,29]:Integer, [0,2,32,0,30]:Integer, [0,2,32,0,31]:Integer, [0,2,32,0,32]:Integer, [0,2,32,0,33]:Integer, [0,2,32,0,34]:Integer, [0,2,32,0,35]:Integer, [0,2,32,0,36]:Integer, [0,2,32,0,37]:Integer, [0,2,32,0,38]:Integer, [0,2,32,0,39]:Integer, [0,2,32,8,0,0]:Float@double, [0,2,32,16,0,0]:Pointer, [0,3,0]:Float@double, [0,3,8]:Float@double, [0,3,16]:Pointer, [0,3,16,0]:Pointer, [0,3,16,0,0]:Pointer, [0,3,16,8]:Integer, [0,3,16,9]:Integer, [0,3,16,10]:Integer, [0,3,16,11]:Integer, [0,3,16,12]:Integer, [0,3,16,13]:Integer, [0,3,16,14]:Integer, [0,3,16,15]:Integer, [0,3,16,16]:Integer, [0,3,16,17]:Integer, [0,3,16,18]:Integer, [0,3,16,19]:Integer, [0,3,16,20]:Integer, [0,3,16,21]:Integer, [0,3,16,22]:Integer, [0,3,16,23]:Integer, [0,3,16,24]:Integer, [0,3,16,25]:Integer, [0,3,16,26]:Integer, [0,3,16,27]:Integer, [0,3,16,28]:Integer, [0,3,16,29]:Integer, [0,3,16,30]:Integer, [0,3,16,31]:Integer, [0,3,16,32]:Integer, [0,3,16,33]:Integer, [0,3,16,34]:Integer, [0,3,16,35]:Integer, [0,3,16,36]:Integer, [0,3,16,37]:Integer, [0,3,16,38]:Integer, [0,3,16,39]:Integer, [0,3,24]:Integer, [0,3,25]:Integer, [0,3,26]:Integer, [0,3,27]:Integer, [0,3,28]:Integer, [0,3,29]:Integer, [0,3,30]:Integer, [0,3,31]:Integer, [0,3,32]:Pointer, [0,3,32,0]:Pointer, [0,3,32,0,0]:Pointer, [0,3,32,0,0,0]:Float@double, [0,3,32,0,8]:Integer, [0,3,32,0,9]:Integer, [0,3,32,0,10]:Integer, [0,3,32,0,11]:Integer, [0,3,32,0,12]:Integer, [0,3,32,0,13]:Integer, [0,3,32,0,14]:Integer, [0,3,32,0,15]:Integer, [0,3,32,0,16]:Integer, [0,3,32,0,17]:Integer, [0,3,32,0,18]:Integer, [0,3,32,0,19]:Integer, [0,3,32,0,20]:Integer, [0,3,32,0,21]:Integer, [0,3,32,0,22]:Integer, [0,3,32,0,23]:Integer, [0,3,32,0,24]:Integer, [0,3,32,0,25]:Integer, [0,3,32,0,26]:Integer, [0,3,32,0,27]:Integer, [0,3,32,0,28]:Integer, [0,3,32,0,29]:Integer, [0,3,32,0,30]:Integer, [0,3,32,0,31]:Integer, [0,3,32,0,32]:Integer, [0,3,32,0,33]:Integer, [0,3,32,0,34]:Integer, [0,3,32,0,35]:Integer, [0,3,32,0,36]:Integer, [0,3,32,0,37]:Integer, [0,3,32,0,38]:Integer, [0,3,32,0,39]:Integer, [0,3,32,8,0,0]:Float@double, [0,3,32,16,0,0]:Pointer, [0,4,0]:Float@double, [0,4,8]:Float@double, [0,4,16]:Pointer, [0,4,16,0]:Pointer, [0,4,16,0,0]:Pointer, [0,4,16,8]:Integer, [0,4,16,9]:Integer, [0,4,16,10]:Integer, [0,4,16,11]:Integer, [0,4,16,12]:Integer, [0,4,16,13]:Integer, [0,4,16,14]:Integer, [0,4,16,15]:Integer, [0,4,16,16]:Integer, [0,4,16,17]:Integer, [0,4,16,18]:Integer, [0,4,16,19]:Integer, [0,4,16,20]:Integer, [0,4,16,21]:Integer, [0,4,16,22]:Integer, [0,4,16,23]:Integer, [0,4,16,24]:Integer, [0,4,16,25]:Integer, [0,4,16,26]:Integer, [0,4,16,27]:Integer, [0,4,16,28]:Integer, [0,4,16,29]:Integer, [0,4,16,30]:Integer, [0,4,16,31]:Integer, [0,4,16,32]:Integer, [0,4,16,33]:Integer, [0,4,16,34]:Integer, [0,4,16,35]:Integer, [0,4,16,36]:Integer, [0,4,16,37]:Integer, [0,4,16,38]:Integer, [0,4,16,39]:Integer, [0,4,24]:Integer, [0,4,25]:Integer, [0,4,26]:Integer, [0,4,27]:Integer, [0,4,28]:Integer, [0,4,29]:Integer, [0,4,30]:Integer, [0,4,31]:Integer, [0,4,32]:Pointer, [0,4,32,0]:Pointer, [0,4,32,0,0]:Pointer, [0,4,32,0,0,0]:Float@double, [0,4,32,0,8]:Integer, [0,4,32,0,9]:Integer, [0,4,32,0,10]:Integer, [0,4,32,0,11]:Integer, [0,4,32,0,12]:Integer, [0,4,32,0,13]:Integer, [0,4,32,0,14]:Integer, [0,4,32,0,15]:Integer, [0,4,32,0,16]:Integer, [0,4,32,0,17]:Integer, [0,4,32,0,18]:Integer, [0,4,32,0,19]:Integer, [0,4,32,0,20]:Integer, [0,4,32,0,21]:Integer, [0,4,32,0,22]:Integer, [0,4,32,0,23]:Integer, [0,4,32,0,24]:Integer, [0,4,32,0,25]:Integer, [0,4,32,0,26]:Integer, [0,4,32,0,27]:Integer, [0,4,32,0,28]:Integer, [0,4,32,0,29]:Integer, [0,4,32,0,30]:Integer, [0,4,32,0,31]:Integer, [0,4,32,0,32]:Integer, [0,4,32,0,33]:Integer, [0,4,32,0,34]:Integer, [0,4,32,0,35]:Integer, [0,4,32,0,36]:Integer, [0,4,32,0,37]:Integer, [0,4,32,0,38]:Integer, [0,4,32,0,39]:Integer, [0,4,32,8,0,0]:Float@double, [0,4,32,16,0,0]:Pointer, [0,5,0]:Float@double, [0,5,8]:Float@double, [0,5,16]:Pointer, [0,5,16,0]:Pointer, [0,5,16,0,0]:Pointer, [0,5,16,8]:Integer, [0,5,16,9]:Integer, [0,5,16,10]:Integer, [0,5,16,11]:Integer, [0,5,16,12]:Integer, [0,5,16,13]:Integer, [0,5,16,14]:Integer, [0,5,16,15]:Integer, [0,5,16,16]:Integer, [0,5,16,17]:Integer, [0,5,16,18]:Integer, [0,5,16,19]:Integer, [0,5,16,20]:Integer, [0,5,16,21]:Integer, [0,5,16,22]:Integer, [0,5,16,23]:Integer, [0,5,16,24]:Integer, [0,5,16,25]:Integer, [0,5,16,26]:Integer, [0,5,16,27]:Integer, [0,5,16,28]:Integer, [0,5,16,29]:Integer, [0,5,16,30]:Integer, [0,5,16,31]:Integer, [0,5,16,32]:Integer, [0,5,16,33]:Integer, [0,5,16,34]:Integer, [0,5,16,35]:Integer, [0,5,16,36]:Integer, [0,5,16,37]:Integer, [0,5,16,38]:Integer, [0,5,16,39]:Integer, [0,5,24]:Integer, [0,5,25]:Integer, [0,5,26]:Integer, [0,5,27]:Integer, [0,5,28]:Integer, [0,5,29]:Integer, [0,5,30]:Integer, [0,5,31]:Integer, [0,5,32]:Pointer, [0,5,32,0]:Pointer, [0,5,32,0,0]:Pointer, [0,5,32,0,0,0]:Float@double, [0,5,32,0,8]:Integer, [0,5,32,0,9]:Integer, [0,5,32,0,10]:Integer, [0,5,32,0,11]:Integer, [0,5,32,0,12]:Integer, [0,5,32,0,13]:Integer, [0,5,32,0,14]:Integer, [0,5,32,0,15]:Integer, [0,5,32,0,16]:Integer, [0,5,32,0,17]:Integer, [0,5,32,0,18]:Integer, [0,5,32,0,19]:Integer, [0,5,32,0,20]:Integer, [0,5,32,0,21]:Integer, [0,5,32,0,22]:Integer, [0,5,32,0,23]:Integer, [0,5,32,0,24]:Integer, [0,5,32,0,25]:Integer, [0,5,32,0,26]:Integer, [0,5,32,0,27]:Integer, [0,5,32,0,28]:Integer, [0,5,32,0,29]:Integer, [0,5,32,0,30]:Integer, [0,5,32,0,31]:Integer, [0,5,32,0,32]:Integer, [0,5,32,0,33]:Integer, [0,5,32,0,34]:Integer, [0,5,32,0,35]:Integer, [0,5,32,0,36]:Integer, [0,5,32,0,37]:Integer, [0,5,32,0,38]:Integer, [0,5,32,0,39]:Integer, [0,5,32,8,0,0]:Float@double, [0,5,32,16,0,0]:Pointer, [0,6,0]:Float@double, [0,6,8]:Float@double, [0,6,16]:Pointer, [0,6,16,0]:Pointer, [0,6,16,0,0]:Pointer, [0,6,16,8]:Integer, [0,6,16,9]:Integer, [0,6,16,10]:Integer, [0,6,16,11]:Integer, [0,6,16,12]:Integer, [0,6,16,13]:Integer, [0,6,16,14]:Integer, [0,6,16,15]:Integer, [0,6,16,16]:Integer, [0,6,16,17]:Integer, [0,6,16,18]:Integer, [0,6,16,19]:Integer, [0,6,16,20]:Integer, [0,6,16,21]:Integer, [0,6,16,22]:Integer, [0,6,16,23]:Integer, [0,6,16,24]:Integer, [0,6,16,25]:Integer, [0,6,16,26]:Integer, [0,6,16,27]:Integer, [0,6,16,28]:Integer, [0,6,16,29]:Integer, [0,6,16,30]:Integer, [0,6,16,31]:Integer, [0,6,16,32]:Integer, [0,6,16,33]:Integer, [0,6,16,34]:Integer, [0,6,16,35]:Integer, [0,6,16,36]:Integer, [0,6,16,37]:Integer, [0,6,16,38]:Integer, [0,6,16,39]:Integer, [0,6,24]:Integer, [0,6,25]:Integer, [0,6,26]:Integer, [0,6,27]:Integer, [0,6,28]:Integer, [0,6,29]:Integer, [0,6,30]:Integer, [0,6,31]:Integer, [0,6,32]:Pointer, [0,6,32,0]:Pointer, [0,6,32,0,0]:Pointer, [0,6,32,0,0,0]:Float@double, [0,6,32,0,8]:Integer, [0,6,32,0,9]:Integer, [0,6,32,0,10]:Integer, [0,6,32,0,11]:Integer, [0,6,32,0,12]:Integer, [0,6,32,0,13]:Integer, [0,6,32,0,14]:Integer, [0,6,32,0,15]:Integer, [0,6,32,0,16]:Integer, [0,6,32,0,17]:Integer, [0,6,32,0,18]:Integer, [0,6,32,0,19]:Integer, [0,6,32,0,20]:Integer, [0,6,32,0,21]:Integer, [0,6,32,0,22]:Integer, [0,6,32,0,23]:Integer, [0,6,32,0,24]:Integer, [0,6,32,0,25]:Integer, [0,6,32,0,26]:Integer, [0,6,32,0,27]:Integer, [0,6,32,0,28]:Integer, [0,6,32,0,29]:Integer, [0,6,32,0,30]:Integer, [0,6,32,0,31]:Integer, [0,6,32,0,32]:Integer, [0,6,32,0,33]:Integer, [0,6,32,0,34]:Integer, [0,6,32,0,35]:Integer, [0,6,32,0,36]:Integer, [0,6,32,0,37]:Integer, [0,6,32,0,38]:Integer, [0,6,32,0,39]:Integer, [0,6,32,8,0,0]:Float@double, [0,6,32,16,0,0]:Pointer, [0,7,0]:Float@double, [0,7,8]:Float@double, [0,7,16]:Pointer, [0,7,16,0]:Pointer, [0,7,16,0,0]:Pointer, [0,7,16,8]:Integer, [0,7,16,9]:Integer, [0,7,16,10]:Integer, [0,7,16,11]:Integer, [0,7,16,12]:Integer, [0,7,16,13]:Integer, [0,7,16,14]:Integer, [0,7,16,15]:Integer, [0,7,16,16]:Integer, [0,7,16,17]:Integer, [0,7,16,18]:Integer, [0,7,16,19]:Integer, [0,7,16,20]:Integer, [0,7,16,21]:Integer, [0,7,16,22]:Integer, [0,7,16,23]:Integer, [0,7,16,24]:Integer, [0,7,16,25]:Integer, [0,7,16,26]:Integer, [0,7,16,27]:Integer, [0,7,16,28]:Integer, [0,7,16,29]:Integer, [0,7,16,30]:Integer, [0,7,16,31]:Integer, [0,7,16,32]:Integer, [0,7,16,33]:Integer, [0,7,16,34]:Integer, [0,7,16,35]:Integer, [0,7,16,36]:Integer, [0,7,16,37]:Integer, [0,7,16,38]:Integer, [0,7,16,39]:Integer, [0,7,24]:Integer, [0,7,25]:Integer, [0,7,26]:Integer, [0,7,27]:Integer, [0,7,28]:Integer, [0,7,29]:Integer, [0,7,30]:Integer, [0,7,31]:Integer, [0,7,32]:Pointer, [0,7,32,0]:Pointer, [0,7,32,0,0]:Pointer, [0,7,32,0,0,0]:Float@double, [0,7,32,0,8]:Integer, [0,7,32,0,9]:Integer, [0,7,32,0,10]:Integer, [0,7,32,0,11]:Integer, [0,7,32,0,12]:Integer, [0,7,32,0,13]:Integer, [0,7,32,0,14]:Integer, [0,7,32,0,15]:Integer, [0,7,32,0,16]:Integer, [0,7,32,0,17]:Integer, [0,7,32,0,18]:Integer, [0,7,32,0,19]:Integer, [0,7,32,0,20]:Integer, [0,7,32,0,21]:Integer, [0,7,32,0,22]:Integer, [0,7,32,0,23]:Integer, [0,7,32,0,24]:Integer, [0,7,32,0,25]:Integer, [0,7,32,0,26]:Integer, [0,7,32,0,27]:Integer, [0,7,32,0,28]:Integer, [0,7,32,0,29]:Integer, [0,7,32,0,30]:Integer, [0,7,32,0,31]:Integer, [0,7,32,0,32]:Integer, [0,7,32,0,33]:Integer, [0,7,32,0,34]:Integer, [0,7,32,0,35]:Integer, [0,7,32,0,36]:Integer, [0,7,32,0,37]:Integer, [0,7,32,0,38]:Integer, [0,7,32,0,39]:Integer, [0,7,32,8,0,0]:Float@double, [0,7,32,16,0,0]:Pointer, [0,8,0]:Float@double, [0,8,8]:Float@double, [0,8,16]:Pointer, [0,8,16,0]:Pointer, [0,8,16,0,0]:Pointer, [0,8,16,8]:Integer, [0,8,16,9]:Integer, [0,8,16,10]:Integer, [0,8,16,11]:Integer, [0,8,16,12]:Integer, [0,8,16,13]:Integer, [0,8,16,14]:Integer, [0,8,16,15]:Integer, [0,8,16,16]:Integer, [0,8,16,17]:Integer, [0,8,16,18]:Integer, [0,8,16,19]:Integer, [0,8,16,20]:Integer, [0,8,16,21]:Integer, [0,8,16,22]:Integer, [0,8,16,23]:Integer, [0,8,16,24]:Integer, [0,8,16,25]:Integer, [0,8,16,26]:Integer, [0,8,16,27]:Integer, [0,8,16,28]:Integer, [0,8,16,29]:Integer, [0,8,16,30]:Integer, [0,8,16,31]:Integer, [0,8,16,32]:Integer, [0,8,16,33]:Integer, [0,8,16,34]:Integer, [0,8,16,35]:Integer, [0,8,16,36]:Integer, [0,8,16,37]:Integer, [0,8,16,38]:Integer, [0,8,16,39]:Integer, [0,8,24]:Integer, [0,8,25]:Integer, [0,8,26]:Integer, [0,8,27]:Integer, [0,8,28]:Integer, [0,8,29]:Integer, [0,8,30]:Integer, [0,8,31]:Integer, [0,16,0]:Float@double, [0,17,0]:Float@double, [0,18,0]:Float@double, [0,19,0]:Float@double, [0,20,0]:Float@double, [0,21,0]:Float@double, [0,22,0]:Float@double, [0,23,0]:Float@double}
│ 
│ Stacktrace:
│  [1] __inbounds_setindex!
│    @ ./array.jl:1026
│  [2] push!
│    @ ./array.jl:1120
│  [3] record!
│    @ ~/.julia/packages/ReverseDiff/UJhiD/src/tape.jl:10
│  [4] ForwardOptimize
│    @ ~/.julia/packages/ReverseDiff/UJhiD/src/macros.jl:91
│  [5] abs2
│    @ ~/.julia/packages/ReverseDiff/UJhiD/src/derivatives/scalars.jl:12
│  [6] _mapreduce
│    @ ./reduce.jl:443
└ @ Enzyme.Compiler ~/.julia/packages/GPUCompiler/U36Ed/src/utils.jl:59
0-element InstructionTape:ERROR: task switch not allowed from inside staged nor pure functions
Stacktrace:
  [1] try_yieldto(undo::typeof(Base.ensure_rescheduled))
    @ Base ./task.jl:921
  [2] wait()
    @ Base ./task.jl:995
  [3] uv_write(s::Base.TTY, p::Ptr{UInt8}, n::UInt64)
    @ Base ./stream.jl:1048
  [4] unsafe_write(s::Base.TTY, p::Ptr{UInt8}, n::UInt64)
    @ Base ./stream.jl:1120
  [5] write
    @ ./strings/io.jl:248 [inlined]
  [6] print
    @ ./strings/io.jl:250 [inlined]
  [7] print(::Base.TTY, ::String, ::String, ::Vararg{String})
    @ Base ./strings/io.jl:46
  [8] println(::Base.TTY, ::String, ::Vararg{String})
    @ Base ./strings/io.jl:75
  [9] println(xs::String)
    @ Base ./coreio.jl:4
 [10] show(io::IOBuffer, tp::Vector{ReverseDiff.AbstractInstruction})
    @ ReverseDiff ~/.julia/packages/ReverseDiff/UJhiD/src/tape.jl:113
 [11] print(io::IOBuffer, x::Vector{ReverseDiff.AbstractInstruction})
    @ Base ./strings/io.jl:35
 [12] print_to_string(xs::Vector{ReverseDiff.AbstractInstruction})
    @ Base ./strings/io.jl:148
 [13] string(xs::Vector{ReverseDiff.AbstractInstruction})
    @ Base ./strings/io.jl:189
 [14] julia_error(cstr::Cstring, val::Ptr{…}, errtype::Enzyme.API.ErrorType, data::Ptr{…}, data2::Ptr{…}, B::Ptr{…})
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:1746
 [15] EnzymeCreateForwardDiff(logic::Enzyme.Logic, todiff::LLVM.Function, retType::Enzyme.API.CDIFFE_TYPE, constant_args::Vector{…}, TA::Enzyme.TypeAnalysis, returnValue::Bool, mode::Enzyme.API.CDerivativeMode, width::Int64, additionalArg::Ptr{…}, typeInfo::Enzyme.FnTypeInfo, uncacheable_args::Vector{…})
    @ Enzyme.API ~/.julia/packages/Enzyme/wR2t7/src/api.jl:168
 [16] enzyme!(job::GPUCompiler.CompilerJob{…}, mod::LLVM.Module, primalf::LLVM.Function, TT::Type, mode::Enzyme.API.CDerivativeMode, width::Int64, parallel::Bool, actualRetType::Type, wrap::Bool, modifiedBetween::NTuple{…}, returnPrimal::Bool, jlrules::Vector{…}, expectedTapeType::Type, loweredArgs::Set{…}, boxedArgs::Set{…})
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:3125
 [17] codegen(output::Symbol, job::GPUCompiler.CompilerJob{…}; libraries::Bool, deferred_codegen::Bool, optimize::Bool, toplevel::Bool, strip::Bool, validate::Bool, only_entry::Bool, parent_job::Nothing)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:4825
 [18] codegen
    @ ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:4340 [inlined]
 [19] _thunk(job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams}, postopt::Bool)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:5430
 [20] _thunk
    @ ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:5430 [inlined]
 [21] cached_compilation
    @ ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:5464 [inlined]
 [22] (::Enzyme.Compiler.var"#532#533"{})(ctx::LLVM.Context)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:5530
 [23] JuliaContext(f::Enzyme.Compiler.var"#532#533"{})
    @ GPUCompiler ~/.julia/packages/GPUCompiler/U36Ed/src/driver.jl:47
 [24] #s1883#531
    @ ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:5482 [inlined]
 [25] 
    @ Enzyme.Compiler ./none:0
 [26] (::Core.GeneratedFunctionStub)(::UInt64, ::LineNumberNode, ::Any, ::Vararg{Any})
    @ Core ./boot.jl:602
 [27] runtime_generic_fwd(activity::Type{…}, width::Val{…}, RT::Val{…}, f::typeof(ReverseDiff.gradient), df::Nothing, primal_1::typeof(f2), shadow_1_1::Nothing, primal_2::Vector{…}, shadow_2_1::Vector{…}, primal_3::ReverseDiff.GradientConfig{…}, shadow_3_1::ReverseDiff.GradientConfig{…})
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/wR2t7/src/rules/jitrules.jl:114
 [28] gradient
    @ ~/.julia/packages/ReverseDiff/UJhiD/src/api/gradients.jl:22 [inlined]
 [29] g2
    @ ./REPL[11]:1 [inlined]
 [30] fwddiffejulia_g2_10238wrap
    @ ./REPL[11]:0
 [31] macro expansion
    @ ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:5378 [inlined]
 [32] enzyme_call
    @ ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:5056 [inlined]
 [33] ForwardModeThunk
    @ ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:5001 [inlined]
 [34] autodiff(::EnzymeCore.ForwardMode{…}, f::EnzymeCore.Const{…}, ::Type{…}, args::EnzymeCore.BatchDuplicated{…})
    @ Enzyme ~/.julia/packages/Enzyme/wR2t7/src/Enzyme.jl:324
 [35] autodiff
    @ ~/.julia/packages/Enzyme/wR2t7/src/Enzyme.jl:224 [inlined]
 [36] jacobian(::EnzymeCore.ForwardMode{EnzymeCore.FFIABI}, f::Function, x::Vector{Float64}; shadow::Tuple{Vector{Float64}})
    @ Enzyme ~/.julia/packages/Enzyme/wR2t7/src/Enzyme.jl:939
 [37] jacobian
    @ ~/.julia/packages/Enzyme/wR2t7/src/Enzyme.jl:935 [inlined]
 [38] H2(x::Vector{Float64})
    @ Main ./REPL[13]:1
 [39] top-level scope
    @ REPL[15]:1
Some type information was truncated. Use `show(err)` to see complete types.
@gdalle gdalle changed the title Type analysis depth limit Type analysis depth limit / task switch not allowed from inside staged nor pure functions Mar 20, 2024
@gdalle
Copy link
Contributor Author

gdalle commented Mar 20, 2024

@wsmoses
Copy link
Member

wsmoses commented Apr 14, 2024

@gdalle so this is a bug in ReverseDiff.jl's printing function:

https://github.com/JuliaDiff/ReverseDiff.jl/blob/c982cde5494fc166965a9d04691f390d9e3073fd/src/tape.jl#L113

This line. What should be a print to io, actually is printing to stdout.

That should be println(io, "$(length(tp))-element InstructionTape:")

The backtrace points to the inside of Reversediff.

Closing here

@gdalle
Copy link
Contributor Author

gdalle commented Apr 14, 2024

Good catch! I have opened a PR over in ReverseDiff to fix it

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.

2 participants