Improve the behavior of control flow operations (dr.if_stmt(), drjit.while_loop()
) in AD-suspended scopes
#299
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Dr.Jit control flow operations (
dr.if_stmt(), drjit.while_loop()
) currently disable gradient tracking of all variable state when the operation takes place within an AD-disabled scope.This can be surprising when a
@dr.syntax
transformation silently passes local variables to such an operation, which then become non-differentiable. @dvicini reported this in issue #253.This commit carves out an exception: when variables aren't actually modified by the control flow operation, they can retain their AD identity.
The PR has 3 parts:
ad_var_inc_ref
so that it only does reference counting. The old behavior (drop ref if variable is currently non-differentiable) is moved to a new functionad_var_copy_ref()
(see the description of this commit for details). This already fixes 80% of the problems.dr.if_stmt()
anddr.while_loop()
, respectively.The PR depends on a Dr.Jit-Core PR: mitsuba-renderer/drjit-core#104