From 33fb95980b0120cdd4d4f2d51f5f116e808dd4aa Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 6 Jan 2023 13:39:06 -0800 Subject: Split bwd_diff op into separate ops for primal and propagate func. (#2582) * Split bwd_diff op into separate ops for primal and propagate func. * Fix. * Download swiftshader with github actions instead of curl on linux. * Fix github action. Co-authored-by: Yong He --- source/slang/slang-lower-to-ir.cpp | 53 +++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) (limited to 'source/slang/slang-lower-to-ir.cpp') diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index a84cf9b8d..6803e1cb4 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -1407,6 +1407,33 @@ struct ValLoweringVisitor : ValVisitorfunc, context->irBuilder->getTypeKind()); + SLANG_RELEASE_ASSERT(funcVal.flavor == LoweredValInfo::Flavor::Simple); + + auto diff = getBuilder()->emitBackwardDifferentiatePropagateInst(getBuilder()->getTypeKind(), funcVal.val); + return LoweredValInfo::simple(diff); + } + + LoweredValInfo visitBackwardDifferentiatePrimalVal(BackwardDifferentiatePrimalVal* val) + { + auto funcVal = emitDeclRef(context, val->func, context->irBuilder->getTypeKind()); + SLANG_RELEASE_ASSERT(funcVal.flavor == LoweredValInfo::Flavor::Simple); + + auto diff = getBuilder()->emitBackwardDifferentiatePrimalInst(getBuilder()->getTypeKind(), funcVal.val); + return LoweredValInfo::simple(diff); + } + + LoweredValInfo visitBackwardDifferentiateIntermediateTypeVal(BackwardDifferentiateIntermediateTypeVal* val) + { + auto funcVal = emitDeclRef(context, val->func, context->irBuilder->getTypeKind()); + SLANG_RELEASE_ASSERT(funcVal.flavor == LoweredValInfo::Flavor::Simple); + + auto diff = getBuilder()->getBackwardDiffIntermediateContextType(funcVal.val); + return LoweredValInfo::simple(diff); + } + LoweredValInfo visitDifferentialBottomSubtypeWitness(DifferentialBottomSubtypeWitness*) { return LoweredValInfo(); @@ -6816,9 +6843,23 @@ struct DeclLoweringVisitor : DeclVisitor context->irBuilder->addDecoration( interfaceType, kIROp_DifferentiableMethodRequirementDictionaryDecoration); } - auto op = as(requirementDecl) - ? kIROp_ForwardDifferentiableMethodRequirementDictionaryItem - : kIROp_BackwardDifferentiableMethodRequirementDictionaryItem; + IROp op = kIROp_ForwardDifferentiableMethodRequirementDictionaryItem; + if (as(requirementDecl)) + { + op = kIROp_BackwardDifferentiableMethodRequirementDictionaryItem; + } + else if (as(requirementDecl)) + { + op = kIROp_BackwardDifferentiablePropagateMethodRequirementDictionaryItem; + } + else if (as(requirementDecl)) + { + op = kIROp_BackwardDifferentiablePrimalMethodRequirementDictionaryItem; + } + else if (as(requirementDecl)) + { + op = kIROp_BackwardDifferentiableIntermediateTypeRequirementDictionaryItem; + } IRInst* args[] = {originalKey, associatedKey}; auto assoc = context->irBuilder->emitIntrinsicInst(nullptr, op, 2, args); assoc->insertAtEnd(decor); @@ -8405,6 +8446,12 @@ struct DeclLoweringVisitor : DeclVisitor UNREACHABLE_RETURN(LoweredValInfo()); } + LoweredValInfo visitBackwardDerivativeIntermediateTypeRequirementDecl(BackwardDerivativeIntermediateTypeRequirementDecl* decl) + { + SLANG_UNUSED(decl); + return LoweredValInfo(getBuilder()->getTypeKind()); + } + LoweredValInfo visitFunctionDeclBase(FunctionDeclBase* decl) { // A function declaration may have multiple, target-specific -- cgit v1.2.3