From 368ec3116ea0f10f44acbf76b5dc9e34d6ff3d32 Mon Sep 17 00:00:00 2001 From: Edward Liu Date: Mon, 14 Nov 2022 12:08:01 -0800 Subject: Minimum binary arithmetic reverse autodiff working. (#2514) * Initial plumbing of backward autodiff in the frontend. * More plumbing. * Initial reverse autodiff working. * Bug fixes. * Misc. * Remove redundant code. * More clean up. * Misc. * Rebase and add backward diff test. * Disable test. * Clean up. * Minor fix. Co-authored-by: Yong He --- source/slang/slang-parser.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-parser.cpp') diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 78edd4deb..d3dc5964e 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -2109,6 +2109,26 @@ namespace Slang return parseForwardDifferentiate(parser); } + /// Parse an expression of the form __bwd_diff(fn) where fn is an + /// identifier pointing to a function. + static Expr* parseBackwardDifferentiate(Parser* parser) + { + BackwardDifferentiateExpr* bwdDiffExpr = parser->astBuilder->create(); + + parser->ReadToken(TokenType::LParent); + + bwdDiffExpr->baseFunction = parser->ParseExpression(); + + parser->ReadToken(TokenType::RParent); + + return bwdDiffExpr; + } + + static NodeBase* parseBackwardDifferentiate(Parser* parser, void* /* unused */) + { + return parseBackwardDifferentiate(parser); + } + /// Parse a `This` type expression static Expr* parseThisTypeExpr(Parser* parser) { @@ -6646,7 +6666,8 @@ namespace Slang _makeParseExpr("none", parseNoneExpr), _makeParseExpr("try", parseTryExpr), _makeParseExpr("__TaggedUnion", parseTaggedUnionType), - _makeParseExpr("__fwd_diff", parseForwardDifferentiate) + _makeParseExpr("__fwd_diff", parseForwardDifferentiate), + _makeParseExpr("__bwd_diff", parseBackwardDifferentiate) }; ConstArrayView getSyntaxParseInfos() -- cgit v1.2.3