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 https://github.com/mitsuba-renderer/drjit/issues/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:
the first commit changes the semantics of 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 function ad_var_copy_ref() (see the description of this commit for details). This already fixes 80% of the problems.
Parts 2 and 3 fix dr.if_stmt() and dr.while_loop(), respectively.
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 https://github.com/mitsuba-renderer/drjit/issues/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: https://github.com/mitsuba-renderer/drjit-core/pull/104