From 4a49769c5b6b351b3c1c9a9968b3926839504606 Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Mon, 8 Jul 2024 18:48:08 -0400 Subject: Treat global variables and parameters as non-differentiable when checking derivative data-flow (#4526) Global parameters are by-default not differentiable (even if they are of a differentiable type), because our auto-diff passes do not touch anything outside of function bodies. The solution is to use wrapper objects with differentiable getter/setter methods (and we should provide a few such objects in the stdlib). Fixes: #3289 This is a potentially breaking change: User code that was previously working with global variables of a differentiable type will now throw an error (previously the gradient would be dropped without warning). The solution is to use `detach()` to keep same behavior as before or rewrite the access using differentiable getter/setter methods. --- source/slang/slang-ir-check-differentiability.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'source') diff --git a/source/slang/slang-ir-check-differentiability.cpp b/source/slang/slang-ir-check-differentiability.cpp index c5c03f7da..8b4886a2c 100644 --- a/source/slang/slang-ir-check-differentiability.cpp +++ b/source/slang/slang-ir-check-differentiability.cpp @@ -169,9 +169,7 @@ public: switch (addr->getOp()) { case kIROp_Var: - case kIROp_GlobalVar: case kIROp_Param: - case kIROp_GlobalParam: return isDifferentiableType(diffTypeContext, addr->getDataType()); case kIROp_FieldAddress: if (!as(addr)->getField() || -- cgit v1.2.3