-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tweak to reference counting semantics
The AD layer exposes a function named ``ad_var_inc_ref()`` that increases the reference count of a variable analogous to ``jit_var_inc_ref()``. However, one difference between the two is that the former detaches AD variables when the underlying index has derivative tracking disabled. For example, this ensures that code like ```python x = Float(0) dr.enable_grad(x) with dr.suspend_grad(): y = Float(y) ``` creates a non-differentiable copy. However, since there are many other operations throughout the Dr.Jit codebase that require reference counting, there were quite a few places that exhibited this detaching behavior, which is not always wanted. (see issue #253). This commit provides two reference counting functions: - ``ad_var_inc_ref()`` which increases the reference count *without* detaching, and - ``ad_var_copy_ref()``, which detaches (i.e., reproducing the former behavior) Following this split, only the constructor of AD arrays uses the detaching ``ad_var_copy_ref()``, while all other operations use the new ``ad_var_inc_ref()``.
- Loading branch information
Showing
4 changed files
with
56 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters