From 8da47c460df01fad6f1d0614210a770f4781edb1 Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Sat, 25 Jun 2022 15:45:34 -0400 Subject: Added basic auto-diff capabilities for local load/store and simple arithmetic. Also added type-checking during the semantic stage. (#2303) * Added JVPTranscriber to handle differentiation of load, store, var, param and return instructions, as well as conversion of data and function types * Changed class names to be more in line with convention. Added correct type checking for __jvp() and verified that simple calls with only loads and stores are processed correctly * Added logic to differentiate basic arithmetic and literals inside IRConstruct and fixed the way parameters are differentiated Co-authored-by: Yong He --- source/slang/slang-ir.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'source/slang/slang-ir.cpp') diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 950061d4f..dd71ae782 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -3027,11 +3027,11 @@ namespace Slang return inst; } - IRInst* IRBuilder::emitJVPDerivativeOfInst(IRType* type, IRInst* baseFn) + IRInst* IRBuilder::emitJVPDifferentiateInst(IRType* type, IRInst* baseFn) { - auto inst = createInst( + auto inst = createInst( this, - kIROp_JVPDerivativeOf, + kIROp_JVPDifferentiate, type, baseFn); addInst(inst); @@ -4370,6 +4370,18 @@ namespace Slang return inst; } + IRInst* IRBuilder::emitSub(IRType* type, IRInst* left, IRInst* right) + { + auto inst = createInst( + this, + kIROp_Sub, + type, + left, + right); + addInst(inst); + return inst; + } + IRInst* IRBuilder::emitEql(IRInst* left, IRInst* right) { auto inst = createInst(this, kIROp_Eql, getBoolType(), left, right); @@ -4403,6 +4415,18 @@ namespace Slang return inst; } + IRInst* IRBuilder::emitDiv(IRType* type, IRInst* numerator, IRInst* denominator) + { + auto inst = createInst( + this, + kIROp_Div, + type, + numerator, + denominator); + addInst(inst); + return inst; + } + IRInst* IRBuilder::emitShr(IRType* type, IRInst* left, IRInst* right) { auto inst = createInst(this, kIROp_Rsh, type, left, right); -- cgit v1.2.3