Skip to content

Commit f84de69

Browse files
authored
Ensure return roots are remateralizable (#1424)
1 parent cb3776f commit f84de69

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

enzyme/Enzyme/GradientUtils.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8526,7 +8526,14 @@ void GradientUtils::computeForwardingProperties(Instruction *V) {
85268526
// If we may write to memory, we cannot promote if any values
85278527
// need the allocation or any descendants for the reverse pass.
85288528
if (!ReadOnly) {
8529-
if (primalNeededInReverse) {
8529+
// There is an exception for Julia returnRoots which will be
8530+
// separately handled in a GC postprocessing pass. Moreover these
8531+
// values are never `needed` in the reverse pass (just we need to mark
8532+
// those values as being GC'd by the function).
8533+
bool returnRoots =
8534+
CI->getAttributes().hasParamAttr(idx, "enzymejl_returnRoots") ||
8535+
CI->getAttributes().hasParamAttr(idx, "enzymejl_returnRoots_v");
8536+
if (primalNeededInReverse && !returnRoots) {
85308537
promotable = false;
85318538
EmitWarning("NotPromotable", *cur, " Could not promote allocation ",
85328539
*V, " due to unknown writing call ", *cur);

0 commit comments

Comments
 (0)