EnzymeAD / EnzymeAD/Enzyme

Unable to differentiate a function adding three values with -enzyme-auto-sparsity=1

Open
#2,627 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
LLVM
Stars
1.7k
Forks
188
Avg merge
1d 22h
Merged PRs (30d)
26

Description

@wsmoses I went back to a simple example adding three entries of a vector and tried, unsuccessfully, to generate the derivative with `-enzyme-auto-sparsity=1`. This is the simplest example I can think of.
The function to differentiate is:
`f[0] = y[0] + y[1] + y[2];`

Here is the Enzyme explorer reproducer: https://fwd.gymni.ch/bqPzQv

The `cannot tell if depends on loop iv: (zext i1 %20 to i64)` error does come from the `if (val == 0.0)` boolean in `sparse_store`, but that is precisely what should help with the sparsity detection, and it works in most other cases. Adding two entries instead, or flipping one of the signs in the ternary operation works. The underlying issue has to be elsewhere.

For reference, I came across the issue in a larger function evaluation: https://fwd.gymni.ch/X7pLQp.
cc @pelesh

Contributor guide

Open the contributing guide

Research direction

Start with the Enzyme explorer reproducer and inspect the sparse_store path, especially the `if (val == 0.0)` condition associated with the loop-IV error. Compare the three-entry case with the working two-entry and sign-flipped cases; done means the three-value addition produces a derivative without the sparsity-detection error.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.