From e0de8e7010563e01ce22c698ff8a8a794d8af06e Mon Sep 17 00:00:00 2001 From: "petro.zarytskyi" Date: Wed, 24 Jan 2024 00:18:17 +0200 Subject: [PATCH] Make all declarations function global. When we produce a gradient function we generally have a forward and reverse sweep. In the forward sweep we accumulate the state and in the reverse sweep we use that state to invert the program execution. The forward sweep generally follows the sematics of the primal function and when neccessary stores the state which would be needed but lost for the reverse sweep. However, to minimize the stores onto the tape we need to reuse some of the variables between the forward and the reverse sweeps which requires some variables to be promoted to the enclosing lexical scope of both sweeps. Fixes #659, fixes #681. --- include/clad/Differentiator/Array.h | 10 +- include/clad/Differentiator/VisitorBase.h | 26 ++- lib/Differentiator/ReverseModeVisitor.cpp | 212 ++++++++++---------- lib/Differentiator/StmtClone.cpp | 6 +- lib/Differentiator/VisitorBase.cpp | 35 +++- test/Arrays/ArrayInputsReverseMode.C | 77 ++++--- test/CUDA/GradientCuda.cu | 3 +- test/ErrorEstimation/ConditonalStatements.C | 8 +- test/ErrorEstimation/LoopsAndArrays.C | 33 +-- test/ErrorEstimation/LoopsAndArraysExec.C | 49 ++--- test/Gradient/Assignments.C | 6 +- test/Gradient/FunctionCalls.C | 6 +- test/Gradient/Gradients.C | 3 +- test/Gradient/Loops.C | 59 ++++-- test/Gradient/Pointers.C | 26 ++- test/Gradient/TestTypeConversion.C | 3 +- test/Gradient/UserDefinedTypes.C | 12 +- test/Misc/RunDemos.C | 3 +- test/NumericalDiff/NumDiff.C | 45 ++++- 19 files changed, 401 insertions(+), 221 deletions(-) diff --git a/include/clad/Differentiator/Array.h b/include/clad/Differentiator/Array.h index a78083b64..48c02f776 100644 --- a/include/clad/Differentiator/Array.h +++ b/include/clad/Differentiator/Array.h @@ -23,8 +23,8 @@ template class array { std::size_t m_size = 0; public: - /// Delete default constructor - array() = delete; + /// Default constructor + array() = default; /// Constructor to create an array of the specified size CUDA_HOST_DEVICE array(std::size_t size) : m_arr(new T[size]{static_cast(0)}), m_size(size) {} @@ -81,6 +81,12 @@ template class array { } CUDA_HOST_DEVICE array& operator=(const array& arr) { + if (m_size < arr.m_size) { + delete[] m_arr; + // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) + m_arr = new T[arr.m_size]; + m_size = arr.m_size; + } (*this) = arr.m_arr; return *this; } diff --git a/include/clad/Differentiator/VisitorBase.h b/include/clad/Differentiator/VisitorBase.h index f85085a86..b6c95662a 100644 --- a/include/clad/Differentiator/VisitorBase.h +++ b/include/clad/Differentiator/VisitorBase.h @@ -277,7 +277,23 @@ namespace clad { clang::Expr* R, clang::SourceLocation OpLoc = noLoc); clang::Expr* BuildParens(clang::Expr* E); - + /// Builds variable declaration to be used inside the derivative + /// body. + /// \param[in] Type The type of variable declaration to build. + /// \param[in] Identifier The identifier information for the variable + /// declaration. + /// \param[in] Init The initalization expression to assign to the variable + /// declaration. + /// \param[in] DirectInit A check for if the initialization expression is a + /// C style initalization. + /// \param[in] TSI The type source information of the variable declaration. + /// \returns The newly built variable declaration. + clang::VarDecl* + BuildVarDecl(clang::QualType Type, clang::IdentifierInfo* Identifier, + clang::Scope* scope, clang::Expr* Init = nullptr, + bool DirectInit = false, clang::TypeSourceInfo* TSI = nullptr, + clang::VarDecl::InitializationStyle IS = + clang::VarDecl::InitializationStyle::CInit); /// Builds variable declaration to be used inside the derivative /// body. /// \param[in] Type The type of variable declaration to build. @@ -311,6 +327,14 @@ namespace clad { clang::TypeSourceInfo* TSI = nullptr, clang::VarDecl::InitializationStyle IS = clang::VarDecl::InitializationStyle::CInit); + /// Builds variable declaration to be used inside the derivative + /// body in the derivative function global scope. + clang::VarDecl* + BuildGlobalVarDecl(clang::QualType Type, llvm::StringRef prefix = "_t", + clang::Expr* Init = nullptr, bool DirectInit = false, + clang::TypeSourceInfo* TSI = nullptr, + clang::VarDecl::InitializationStyle IS = + clang::VarDecl::InitializationStyle::CInit); /// Creates a namespace declaration and enters its context. All subsequent /// Stmts are built inside that namespace, until /// m_Sema.PopDeclContextIsUsed. diff --git a/lib/Differentiator/ReverseModeVisitor.cpp b/lib/Differentiator/ReverseModeVisitor.cpp index d0ec52a6c..11d875990 100644 --- a/lib/Differentiator/ReverseModeVisitor.cpp +++ b/lib/Differentiator/ReverseModeVisitor.cpp @@ -215,8 +215,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, auto* gradientParam = gradientParams[i]; auto* gradientVD = - BuildVarDecl(gradientParam->getType(), gradientParam->getName(), - BuildDeclRef(overloadParam)); + BuildGlobalVarDecl(gradientParam->getType(), gradientParam->getName(), + BuildDeclRef(overloadParam)); callArgs.push_back(BuildDeclRef(gradientVD)); addToCurrentBlock(BuildDeclStmt(gradientVD)); } @@ -581,8 +581,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, if (utils::isArrayOrPointerType(VDDerivedType)) continue; auto* VDDerived = - BuildVarDecl(VDDerivedType, "_d_" + param->getNameAsString(), - getZeroInit(VDDerivedType)); + BuildGlobalVarDecl(VDDerivedType, "_d_" + param->getNameAsString(), + getZeroInit(VDDerivedType)); m_Variables[param] = BuildDeclRef(VDDerived); addToBlock(BuildDeclStmt(VDDerived), m_Globals); } @@ -746,7 +746,12 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, } StmtDiff ReverseModeVisitor::VisitCompoundStmt(const CompoundStmt* CS) { - beginScope(Scope::DeclScope); + int scopeFlags = Scope::DeclScope; + // If this is the outermost compound statement of the function, + // propagate the function scope. + if (getCurrentScope() == m_DerivativeFnScope) + scopeFlags |= Scope::FnScope; + beginScope(scopeFlags); beginBlock(direction::forward); beginBlock(direction::reverse); for (Stmt* S : CS->body()) { @@ -1271,26 +1276,10 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, return cloned; Expr* result = nullptr; Expr* forwSweepDerivative = nullptr; - if (utils::isArrayOrPointerType(target->getType())) { - // Create the target[idx] expression. - result = BuildArraySubscript(target, reverseIndices); - forwSweepDerivative = - BuildArraySubscript(target, forwSweepDerivativeIndices); - } - else if (isCladArrayType(target->getType())) { - result = m_Sema - .ActOnArraySubscriptExpr(getCurrentScope(), target, - ASE->getExprLoc(), - reverseIndices.back(), noLoc) - .get(); - forwSweepDerivative = - m_Sema - .ActOnArraySubscriptExpr(getCurrentScope(), target, - ASE->getExprLoc(), - forwSweepDerivativeIndices.back(), noLoc) - .get(); - } else - result = target; + // Create the target[idx] expression. + result = BuildArraySubscript(target, reverseIndices); + forwSweepDerivative = + BuildArraySubscript(target, forwSweepDerivativeIndices); // Create the (target += dfdx) statement. if (dfdx()) { auto* add_assign = BuildOp(BO_AddAssign, result, dfdx()); @@ -1301,10 +1290,10 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, } StmtDiff ReverseModeVisitor::VisitDeclRefExpr(const DeclRefExpr* DRE) { - auto* clonedDRE = cast(Clone(DRE)); + Expr* clonedDRE = Clone(DRE); // Check if referenced Decl was "replaced" with another identifier inside // the derivative - if (auto* VD = dyn_cast(clonedDRE->getDecl())) { + if (auto* VD = dyn_cast(cast(clonedDRE)->getDecl())) { // If current context is different than the context of the original // declaration (e.g. we are inside lambda), rebuild the DeclRefExpr // with Sema::BuildDeclRefExpr. This is required in some cases, e.g. @@ -1312,7 +1301,12 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // to the underlying struct of a lambda. if (VD->getDeclContext() != m_Sema.CurContext) clonedDRE = cast(BuildDeclRef(VD)); - + // This case happens when ref-type variables have to become function + // global. Ref-type declarations cannot be moved to the function global + // scope because they can't be separated from their inits. + if (DRE->getDecl()->getType()->isReferenceType() && + clonedDRE->getType()->isPointerType()) + clonedDRE = BuildOp(UO_Deref, clonedDRE); if (isVectorValued) { if (m_VectorOutput.size() <= outputArrayCursor) return StmtDiff(clonedDRE); @@ -2530,7 +2524,18 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, VarDeclDiff ReverseModeVisitor::DifferentiateVarDecl(const VarDecl* VD) { StmtDiff initDiff; Expr* VDDerivedInit = nullptr; + // Local declarations are promoted to the function global scope. This + // procedure is done to make declarations visible in the reverse sweep. + // The reverse_mode_forward_pass mode does not have a reverse pass so + // declarations don't have to be moved to the function global scope. + bool promoteToFnScope = !getCurrentScope()->isFunctionScope() && + m_Mode != DiffMode::reverse_mode_forward_pass; auto VDDerivedType = ComputeAdjointType(VD->getType()); + auto VDCloneType = CloneType(VD->getType()); + // If the cloned declaration is moved to the function global scope, + // change its type for the corresponding adjoint type. + if (promoteToFnScope) + VDCloneType = VDDerivedType; bool isDerivativeOfRefType = VD->getType()->isReferenceType(); VarDecl* VDDerived = nullptr; bool isPointerType = VD->getType()->isPointerType(); @@ -2538,11 +2543,16 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // VDDerivedInit now serves two purposes -- as the initial derivative value // or the size of the derivative array -- depending on the primal type. if (const auto* AT = dyn_cast(VD->getType())) { - Expr* init = getArraySizeExpr(AT, m_Context, *this); - VDDerivedInit = init; - VDDerived = BuildVarDecl(VDDerivedType, "_d_" + VD->getNameAsString(), - VDDerivedInit, false, nullptr, - clang::VarDecl::InitializationStyle::CallInit); + VDDerivedInit = getArraySizeExpr(AT, m_Context, *this); + VDDerived = BuildGlobalVarDecl( + VDDerivedType, "_d_" + VD->getNameAsString(), VDDerivedInit, false, + nullptr, clang::VarDecl::InitializationStyle::CallInit); + // If an array-type declaration is promoted to function global, + // its type is changed for clad::array. In that case we should + // initialize it with its size the same way the derived variable + // is initialized. + if (promoteToFnScope) + initDiff = VDDerivedInit; } else { // If VD is a reference to a local variable, then the initial value is set // to the derived variable of the corresponding local variable. @@ -2610,17 +2620,9 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, } VDDerivedInit = getZeroInit(VDDerivedType); } - // Here separate behaviour for record and non-record types is only - // necessary to preserve the old tests. - if (VDDerivedType->isRecordType()) - VDDerived = - BuildVarDecl(VDDerivedType, "_d_" + VD->getNameAsString(), - VDDerivedInit, VD->isDirectInit(), - m_Context.getTrivialTypeSourceInfo(VDDerivedType), - VD->getInitStyle()); - else - VDDerived = BuildVarDecl(VDDerivedType, "_d_" + VD->getNameAsString(), - VDDerivedInit); + VDDerived = + BuildGlobalVarDecl(VDDerivedType, "_d_" + VD->getNameAsString(), + VDDerivedInit, false, nullptr, VD->getInitStyle()); } // If `VD` is a reference to a local variable, then it is already @@ -2629,7 +2631,6 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // need to call `Visit` since non-local variables are not differentiated. if (!isDerivativeOfRefType && !isPointerType) { Expr* derivedE = BuildDeclRef(VDDerived); - initDiff = StmtDiff{}; if (VD->getInit()) { if (isa(VD->getInit())) initDiff = Visit(VD->getInit()); @@ -2658,16 +2659,6 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, } } VarDecl* VDClone = nullptr; - // Here separate behaviour for record and non-record types is only - // necessary to preserve the old tests. - if (VD->getType()->isRecordType()) { - VDClone = BuildVarDecl(VD->getType(), VD->getNameAsString(), - initDiff.getExpr(), VD->isDirectInit(), - VD->getTypeSourceInfo(), VD->getInitStyle()); - } else { - VDClone = BuildVarDecl(CloneType(VD->getType()), VD->getNameAsString(), - initDiff.getExpr(), VD->isDirectInit()); - } Expr* derivedVDE = BuildDeclRef(VDDerived); // FIXME: Add extra parantheses if derived variable pointer is pointing to a @@ -2679,20 +2670,30 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, initDiff.getForwSweepExpr_dx())); addToCurrentBlock(assignDerivativeE); if (isInsideLoop) { - auto tape = MakeCladTapeFor(derivedVDE); - addToCurrentBlock(tape.Push); - auto* reverseSweepDerivativePointerE = - BuildVarDecl(derivedVDE->getType(), "_t", tape.Pop); - m_LoopBlock.back().push_back( - BuildDeclStmt(reverseSweepDerivativePointerE)); - auto* revSweepDerPointerRef = - BuildDeclRef(reverseSweepDerivativePointerE); - derivedVDE = - BuildOp(UnaryOperatorKind::UO_Deref, revSweepDerPointerRef); - } else { - derivedVDE = BuildOp(UnaryOperatorKind::UO_Deref, derivedVDE); + StmtDiff pushPop = + StoreAndRestore(derivedVDE, /*prefix=*/"_t", /*force=*/true); + addToCurrentBlock(pushPop.getExpr(), direction::forward); + m_LoopBlock.back().push_back(pushPop.getExpr_dx()); } + derivedVDE = BuildOp(UnaryOperatorKind::UO_Deref, derivedVDE); } + + // If a ref-type declaration is promoted to function global scope, + // it's replaced with a pointer and should be initialized with the + // address of the cloned init. e.g. + // double& ref = x; + // -> + // double* ref; + // ref = &x; + if (isDerivativeOfRefType && promoteToFnScope) + VDClone = BuildGlobalVarDecl( + VDCloneType, VD->getNameAsString(), + BuildOp(UnaryOperatorKind::UO_AddrOf, initDiff.getExpr()), + VD->isDirectInit()); + else + VDClone = BuildGlobalVarDecl(VDCloneType, VD->getNameAsString(), + initDiff.getExpr(), VD->isDirectInit(), + nullptr, VD->getInitStyle()); if (isPointerType) { Expr* assignDerivativeE = BuildOp(BinaryOperatorKind::BO_Assign, derivedVDE, initDiff.getExpr_dx()); @@ -2752,6 +2753,10 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, llvm::SmallVector declsDiff; // Need to put array decls inlined. llvm::SmallVector localDeclsDiff; + // reverse_mode_forward_pass does not have a reverse pass so declarations + // don't have to be moved to the function global scope. + bool promoteToFnScope = !getCurrentScope()->isFunctionScope() && + m_Mode != DiffMode::reverse_mode_forward_pass; // For each variable declaration v, create another declaration _d_v to // store derivatives for potential reassignments. E.g. // double y = x; @@ -2776,36 +2781,47 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // double _d_y = _d_x; // produced as a derivative for y // double y = x; // double _d__d_y = _d_x; - // double _d_y = x; // copied from original funcion, collides with + // double _d_y = x; // copied from original function, collides with // _d_y // } - if (VDDiff.getDecl()->getDeclName() != VD->getDeclName()) + if (VDDiff.getDecl()->getDeclName() != VD->getDeclName() || + VD->getType() != VDDiff.getDecl()->getType()) m_DeclReplacements[VD] = VDDiff.getDecl(); - // FIXME: This part in necessary to replace local variables inside loops - // with function globals and replace initializations with - // assignments. This is a temporary measure to avoid the bug that arises - // from overwriting local variables on different loop passes. - if (isInsideLoop) { - if (VD->getType()->isBuiltinType()) { - auto* decl = VDDiff.getDecl(); - /// The same variable will be assigned with new values every - /// loop iteration so the const qualifier must be dropped. - if (decl->getType().isConstQualified()) { - QualType nonConstType = - getNonConstType(decl->getType(), m_Context, m_Sema); - decl->setType(nonConstType); - } - if (decl->getInit()) { - auto* declRef = BuildDeclRef(decl); + // Here, we move the declaration to the function global scope. + // Initialization is replaced with an assignment operation at the same + // place as the original declaration. This procedure is done to make the + // declaration visible in the reverse sweep. The variable is stored + // before the assignment in case its value is overwritten in a loop. + // e.g. + // while (cond) { + // double x = k * n; + // ... + // -> + // double x; + // clad::tape _t0 = {}; + // while (cond) { + // clad::push(_t0, x), x = k * n; + // ... + if (promoteToFnScope) { + auto* decl = VDDiff.getDecl(); + if (VD->getInit()) { + auto* declRef = BuildDeclRef(decl); + auto* assignment = BuildOp(BO_Assign, declRef, decl->getInit()); + if (isInsideLoop) { auto pushPop = StoreAndRestore(declRef, /*prefix=*/"_t", /*force=*/true); if (pushPop.getExpr() != declRef) addToCurrentBlock(pushPop.getExpr_dx(), direction::reverse); - auto* assignment = BuildOp(BO_Assign, declRef, decl->getInit()); - inits.push_back(BuildOp(BO_Comma, pushPop.getExpr(), assignment)); + assignment = BuildOp(BO_Comma, pushPop.getExpr(), assignment); + } + inits.push_back(assignment); + if (isa(VD->getType())) { + decl->setInitStyle(VarDecl::InitializationStyle::CallInit); + decl->setInit(Clone(VDDiff.getDecl_dx()->getInit())); + } else { + decl->setInit(getZeroInit(VD->getType())); } - decl->setInit(getZeroInit(VD->getType())); } } @@ -2839,19 +2855,13 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, m_ExternalSource->ActBeforeFinalizingVisitDeclStmt(decls, declsDiff); } - /// FIXME: This part in necessary to replace local variables inside loops - /// with function globals and replace initializations with assignments. - /// This is a temporary measure to avoid the bug that arises from - /// overwriting local variables on different loop passes. - if (isInsideLoop) { - if (auto* VD = dyn_cast(decls[0])) { - if (VD->getType()->isBuiltinType()) { - addToBlock(DSClone, m_Globals); - Stmt* initAssignments = MakeCompoundStmt(inits); - initAssignments = unwrapIfSingleStmt(initAssignments); - return StmtDiff(initAssignments); - } - } + // This part in necessary to replace local variables inside loops + // with function globals and replace initializations with assignments. + if (promoteToFnScope) { + addToBlock(DSClone, m_Globals); + Stmt* initAssignments = MakeCompoundStmt(inits); + initAssignments = unwrapIfSingleStmt(initAssignments); + return StmtDiff(initAssignments); } return StmtDiff(DSClone); diff --git a/lib/Differentiator/StmtClone.cpp b/lib/Differentiator/StmtClone.cpp index b176577bb..af3e95023 100644 --- a/lib/Differentiator/StmtClone.cpp +++ b/lib/Differentiator/StmtClone.cpp @@ -520,8 +520,12 @@ bool ReferencesUpdater::VisitDeclRefExpr(DeclRefExpr* DRE) { // Replace the declaration if it is present in `m_DeclReplacements`. if (VarDecl* VD = dyn_cast(DRE->getDecl())) { auto it = m_DeclReplacements.find(VD); - if (it != std::end(m_DeclReplacements)) + if (it != std::end(m_DeclReplacements)) { DRE->setDecl(it->second); + QualType NonRefQT = it->second->getType().getNonReferenceType(); + if (NonRefQT != DRE->getType()) + DRE->setType(NonRefQT); + } } DeclarationNameInfo DNI = DRE->getNameInfo(); diff --git a/lib/Differentiator/VisitorBase.cpp b/lib/Differentiator/VisitorBase.cpp index fc0857fb8..b7c553a1c 100644 --- a/lib/Differentiator/VisitorBase.cpp +++ b/lib/Differentiator/VisitorBase.cpp @@ -123,12 +123,17 @@ namespace clad { // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) delete oldScope; } - VarDecl* VisitorBase::BuildVarDecl(QualType Type, IdentifierInfo* Identifier, Expr* Init, bool DirectInit, TypeSourceInfo* TSI, VarDecl::InitializationStyle IS) { - + return BuildVarDecl(Type, Identifier, getCurrentScope(), Init, DirectInit, + TSI, IS); + } + VarDecl* VisitorBase::BuildVarDecl(QualType Type, IdentifierInfo* Identifier, + Scope* Scope, Expr* Init, bool DirectInit, + TypeSourceInfo* TSI, + VarDecl::InitializationStyle IS) { // add namespace specifier in variable declaration if needed. Type = utils::AddNamespaceSpecifier(m_Sema, m_Context, Type); auto VD = @@ -144,7 +149,7 @@ namespace clad { } m_Sema.FinalizeDeclaration(VD); // Add the identifier to the scope and IdResolver - m_Sema.PushOnScopeChains(VD, getCurrentScope(), /*AddToContext*/ false); + m_Sema.PushOnScopeChains(VD, Scope, /*AddToContext*/ false); return VD; } @@ -162,6 +167,14 @@ namespace clad { TSI, IS); } + VarDecl* VisitorBase::BuildGlobalVarDecl(QualType Type, + llvm::StringRef prefix, Expr* Init, + bool DirectInit, TypeSourceInfo* TSI, + VarDecl::InitializationStyle IS) { + return BuildVarDecl(Type, CreateUniqueIdentifier(prefix), + m_DerivativeFnScope, Init, DirectInit, TSI, IS); + } + NamespaceDecl* VisitorBase::BuildNamespaceDecl(IdentifierInfo* II, bool isInline) { // Check if the namespace is being redeclared. @@ -409,9 +422,19 @@ namespace clad { Expr* VisitorBase::BuildArraySubscript( Expr* Base, const llvm::SmallVectorImpl& Indices) { Expr* result = Base; - for (Expr* I : Indices) - result = - m_Sema.CreateBuiltinArraySubscriptExpr(result, noLoc, I, noLoc).get(); + SourceLocation fakeLoc = utils::GetValidSLoc(m_Sema); + if (utils::isArrayOrPointerType(Base->getType())) { + for (Expr* I : Indices) + result = + m_Sema.CreateBuiltinArraySubscriptExpr(result, fakeLoc, I, fakeLoc) + .get(); + } else { + Expr* idx = Indices.back(); + result = m_Sema + .ActOnArraySubscriptExpr(getCurrentScope(), Base, fakeLoc, + idx, fakeLoc) + .get(); + } return result; } diff --git a/test/Arrays/ArrayInputsReverseMode.C b/test/Arrays/ArrayInputsReverseMode.C index 2137a4fe7..c8135e207 100644 --- a/test/Arrays/ArrayInputsReverseMode.C +++ b/test/Arrays/ArrayInputsReverseMode.C @@ -19,10 +19,11 @@ double addArr(const double *arr, int n) { //CHECK-NEXT: double _d_ret = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double ret = 0; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < n; i++) { +//CHECK-NEXT: for (i = 0; i < n; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, ret); //CHECK-NEXT: ret += arr[i]; @@ -71,11 +72,12 @@ float func(float* a, float* b) { //CHECK-NEXT: float _d_sum = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: clad::tape _t2 = {}; //CHECK-NEXT: float sum = 0; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < 3; i++) { +//CHECK-NEXT: for (i = 0; i < 3; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, a[i]); //CHECK-NEXT: a[i] *= b[i]; @@ -123,10 +125,11 @@ float func2(float* a) { //CHECK-NEXT: float _d_sum = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: float sum = 0; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < 3; i++) { +//CHECK-NEXT: for (i = 0; i < 3; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, sum); //CHECK-NEXT: sum += helper(a[i]); @@ -156,11 +159,12 @@ float func3(float* a, float* b) { //CHECK-NEXT: float _d_sum = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: clad::tape _t2 = {}; //CHECK-NEXT: float sum = 0; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < 3; i++) { +//CHECK-NEXT: for (i = 0; i < 3; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, sum); //CHECK-NEXT: clad::push(_t2, a[i]); @@ -194,11 +198,12 @@ double func4(double x) { //CHECK-NEXT: double _d_sum = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double arr[3] = {x, 2 * x, x * x}; //CHECK-NEXT: double sum = 0; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < 3; i++) { +//CHECK-NEXT: for (i = 0; i < 3; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, sum); //CHECK-NEXT: sum += addArr(arr, 3); @@ -242,23 +247,25 @@ double func5(int k) { //CHECK-NEXT: int _d_n = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double _d_sum = 0; //CHECK-NEXT: unsigned long _t2; -//CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int _d_i0 = 0; +//CHECK-NEXT: int i0 = 0; //CHECK-NEXT: clad::tape _t3 = {}; //CHECK-NEXT: int n = k; //CHECK-NEXT: clad::array _d_arr(n); //CHECK-NEXT: double arr[n]; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < n; i++) { +//CHECK-NEXT: for (i = 0; i < n; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, arr[i]); //CHECK-NEXT: arr[i] = k; //CHECK-NEXT: } //CHECK-NEXT: double sum = 0; //CHECK-NEXT: _t2 = 0; -//CHECK-NEXT: for (int i = 0; i < 3; i++) { +//CHECK-NEXT: for (i0 = 0; i0 < 3; i0++) { //CHECK-NEXT: _t2++; //CHECK-NEXT: clad::push(_t3, sum); //CHECK-NEXT: sum += addArr(arr, n); @@ -267,7 +274,7 @@ double func5(int k) { //CHECK-NEXT: _label0: //CHECK-NEXT: _d_sum += 1; //CHECK-NEXT: for (; _t2; _t2--) { -//CHECK-NEXT: i--; +//CHECK-NEXT: i0--; //CHECK-NEXT: { //CHECK-NEXT: sum = clad::pop(_t3); //CHECK-NEXT: double _r_d1 = _d_sum; @@ -304,14 +311,19 @@ double func6(double seed) { //CHECK-NEXT: double _d_sum = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; +//CHECK-NEXT: clad::tape > _t1 = {}; //CHECK-NEXT: clad::array _d_arr(3UL); -//CHECK-NEXT: clad::tape _t1 = {}; +//CHECK-NEXT: clad::array arr(3UL); +//CHECK-NEXT: clad::tape _t2 = {}; +//CHECK-NEXT: clad::tape > _t3 = {}; //CHECK-NEXT: double sum = 0; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < 3; i++) { +//CHECK-NEXT: for (i = 0; i < 3; i++) { //CHECK-NEXT: _t0++; -//CHECK-NEXT: double arr[3] = {seed, seed * i, seed + i}; -//CHECK-NEXT: clad::push(_t1, sum); +//CHECK-NEXT: clad::push(_t1, arr) , arr = {seed, seed * i, seed + i}; +//CHECK-NEXT: clad::push(_t2, sum); +//CHECK-NEXT: clad::push(_t3, arr); //CHECK-NEXT: sum += addArr(arr, 3); //CHECK-NEXT: } //CHECK-NEXT: goto _label0; @@ -320,12 +332,14 @@ double func6(double seed) { //CHECK-NEXT: for (; _t0; _t0--) { //CHECK-NEXT: i--; //CHECK-NEXT: { -//CHECK-NEXT: sum = clad::pop(_t1); +//CHECK-NEXT: sum = clad::pop(_t2); //CHECK-NEXT: double _r_d0 = _d_sum; +//CHECK-NEXT: clad::array _r1 = clad::pop(_t3); +//CHECK-NEXT: arr = _r1; //CHECK-NEXT: int _grad1 = 0; -//CHECK-NEXT: addArr_pullback(arr, 3, _r_d0, _d_arr, &_grad1); -//CHECK-NEXT: clad::array _r0(_d_arr); -//CHECK-NEXT: int _r1 = _grad1; +//CHECK-NEXT: addArr_pullback(_r1, 3, _r_d0, _d_arr, &_grad1); +//CHECK-NEXT: clad::array _r0 = _d_arr; +//CHECK-NEXT: int _r2 = _grad1; //CHECK-NEXT: } //CHECK-NEXT: { //CHECK-NEXT: * _d_seed += _d_arr[0]; @@ -334,6 +348,7 @@ double func6(double seed) { //CHECK-NEXT: * _d_seed += _d_arr[2]; //CHECK-NEXT: _d_i += _d_arr[2]; //CHECK-NEXT: _d_arr = {}; +//CHECK-NEXT: arr = clad::pop(_t1); //CHECK-NEXT: } //CHECK-NEXT: } //CHECK-NEXT: } @@ -367,14 +382,19 @@ double func7(double *params) { //CHECK-NEXT: double _d_out = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: std::size_t _d_i = 0; +//CHECK-NEXT: std::size_t i = 0; +//CHECK-NEXT: clad::tape > _t1 = {}; //CHECK-NEXT: clad::array _d_paramsPrime(1UL); -//CHECK-NEXT: clad::tape _t1 = {}; +//CHECK-NEXT: clad::array paramsPrime(1UL); +//CHECK-NEXT: clad::tape _t2 = {}; +//CHECK-NEXT: clad::tape > _t3 = {}; //CHECK-NEXT: double out = 0.; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (std::size_t i = 0; i < 1; ++i) { +//CHECK-NEXT: for (i = 0; i < 1; ++i) { //CHECK-NEXT: _t0++; -//CHECK-NEXT: double paramsPrime[1] = {params[0]}; -//CHECK-NEXT: clad::push(_t1, out); +//CHECK-NEXT: clad::push(_t1, paramsPrime) , paramsPrime = {params[0]}; +//CHECK-NEXT: clad::push(_t2, out); +//CHECK-NEXT: clad::push(_t3, paramsPrime); //CHECK-NEXT: out = out + inv_square(paramsPrime); //CHECK-NEXT: } //CHECK-NEXT: goto _label0; @@ -383,16 +403,19 @@ double func7(double *params) { //CHECK-NEXT: for (; _t0; _t0--) { //CHECK-NEXT: --i; //CHECK-NEXT: { -//CHECK-NEXT: out = clad::pop(_t1); +//CHECK-NEXT: out = clad::pop(_t2); //CHECK-NEXT: double _r_d0 = _d_out; //CHECK-NEXT: _d_out -= _r_d0; //CHECK-NEXT: _d_out += _r_d0; -//CHECK-NEXT: inv_square_pullback(paramsPrime, _r_d0, _d_paramsPrime); -//CHECK-NEXT: clad::array _r0(_d_paramsPrime); +//CHECK-NEXT: clad::array _r1 = clad::pop(_t3); +//CHECK-NEXT: paramsPrime = _r1; +//CHECK-NEXT: inv_square_pullback(_r1, _r_d0, _d_paramsPrime); +//CHECK-NEXT: clad::array _r0 = _d_paramsPrime; //CHECK-NEXT: } //CHECK-NEXT: { //CHECK-NEXT: _d_params[0] += _d_paramsPrime[0]; //CHECK-NEXT: _d_paramsPrime = {}; +//CHECK-NEXT: paramsPrime = clad::pop(_t1); //CHECK-NEXT: } //CHECK-NEXT: } //CHECK-NEXT: } @@ -491,10 +514,11 @@ double func9(double i, double j) { //CHECK-NEXT: clad::array _d_arr(5UL); //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_idx = 0; +//CHECK-NEXT: int idx = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double arr[5] = {}; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int idx = 0; idx < 5; ++idx) { +//CHECK-NEXT: for (idx = 0; idx < 5; ++idx) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, arr[idx]); //CHECK-NEXT: modify(arr[idx], i); @@ -557,11 +581,12 @@ double func10(double *arr, int n) { //CHECK-NEXT: double _d_res = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: clad::tape _t2 = {}; //CHECK-NEXT: double res = 0; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < n; ++i) { +//CHECK-NEXT: for (i = 0; i < n; ++i) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, res); //CHECK-NEXT: clad::push(_t2, arr[i]); diff --git a/test/CUDA/GradientCuda.cu b/test/CUDA/GradientCuda.cu index ab6067243..8d8d59b72 100644 --- a/test/CUDA/GradientCuda.cu +++ b/test/CUDA/GradientCuda.cu @@ -34,6 +34,7 @@ auto gauss_g = clad::gradient(gauss, "p"); //CHECK-NEXT: double _d_t = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double _t2; //CHECK-NEXT: double _t3; @@ -42,7 +43,7 @@ auto gauss_g = clad::gradient(gauss, "p"); //CHECK-NEXT: double _t6; //CHECK-NEXT: double t = 0; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < dim; i++) { +//CHECK-NEXT: for (i = 0; i < dim; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, t); //CHECK-NEXT: t += (x[i] - p[i]) * (x[i] - p[i]); diff --git a/test/ErrorEstimation/ConditonalStatements.C b/test/ErrorEstimation/ConditonalStatements.C index ea9acae55..24c88ad99 100644 --- a/test/ErrorEstimation/ConditonalStatements.C +++ b/test/ErrorEstimation/ConditonalStatements.C @@ -26,6 +26,7 @@ float func(float x, float y) { //CHECK-NEXT: float _d_temp = 0; //CHECK-NEXT: double _delta_temp = 0; //CHECK-NEXT: float _EERepl_temp0; +//CHECK-NEXT: float temp = 0; //CHECK-NEXT: float _t1; //CHECK-NEXT: float _EERepl_temp1; //CHECK-NEXT: float _t2; @@ -36,7 +37,7 @@ float func(float x, float y) { //CHECK-NEXT: y = y * x; //CHECK-NEXT: _EERepl_y1 = y; //CHECK-NEXT: } else { -//CHECK-NEXT: float temp = y; +//CHECK-NEXT: temp = y; //CHECK-NEXT: _EERepl_temp0 = temp; //CHECK-NEXT: _t1 = temp; //CHECK-NEXT: temp = y * y; @@ -77,7 +78,10 @@ float func(float x, float y) { //CHECK-NEXT: * _d_y += y * _r_d1; //CHECK-NEXT: _delta_temp += std::abs(_r_d1 * _EERepl_temp1 * {{.+}}); //CHECK-NEXT: } -//CHECK-NEXT: * _d_y += _d_temp; +//CHECK-NEXT: { +//CHECK-NEXT: * _d_y += _d_temp; +//CHECK-NEXT: _delta_temp += std::abs(_d_temp * _EERepl_temp0 * {{.+}}); +//CHECK-NEXT: } //CHECK-NEXT: } //CHECK-NEXT: double _delta_x = 0; //CHECK-NEXT: _delta_x += std::abs(* _d_x * x * {{.+}}); diff --git a/test/ErrorEstimation/LoopsAndArrays.C b/test/ErrorEstimation/LoopsAndArrays.C index ab033c3f6..0290ebefc 100644 --- a/test/ErrorEstimation/LoopsAndArrays.C +++ b/test/ErrorEstimation/LoopsAndArrays.C @@ -20,12 +20,13 @@ float func(float* p, int n) { //CHECK-NEXT: float _EERepl_sum0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: clad::tape _EERepl_sum1 = {}; //CHECK-NEXT: float sum = 0; //CHECK-NEXT: _EERepl_sum0 = sum; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < n; i++) { +//CHECK-NEXT: for (i = 0; i < n; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, sum); //CHECK-NEXT: sum += p[i]; @@ -46,10 +47,10 @@ float func(float* p, int n) { //CHECK-NEXT: } //CHECK-NEXT: _delta_sum += std::abs(_d_sum * _EERepl_sum0 * {{.+}}); //CHECK-NEXT: clad::array _delta_p(_d_p.size()); -//CHECK-NEXT: int i = 0; -//CHECK-NEXT: for (; i < _d_p.size(); i++) { -//CHECK-NEXT: double _t2 = std::abs(_d_p[i] * p[i] * {{.+}}); -//CHECK-NEXT: _delta_p[i] += _t2; +//CHECK-NEXT: int i0 = 0; +//CHECK-NEXT: for (; i0 < _d_p.size(); i0++) { +//CHECK-NEXT: double _t2 = std::abs(_d_p[i0] * p[i0] * {{.+}}); +//CHECK-NEXT: _delta_p[i0] += _t2; //CHECK-NEXT: _final_error += _t2; //CHECK-NEXT: } //CHECK-NEXT: _final_error += _delta_sum; @@ -71,6 +72,7 @@ float func2(float x) { //CHECK-NEXT: float _EERepl_z0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: float _d_m = 0; //CHECK-NEXT: double _delta_m = 0; @@ -81,7 +83,7 @@ float func2(float x) { //CHECK-NEXT: float z; //CHECK-NEXT: _EERepl_z0 = z; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < 9; i++) { +//CHECK-NEXT: for (i = 0; i < 9; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, m) , m = x * x; //CHECK-NEXT: clad::push(_EERepl_m0, m); @@ -199,6 +201,7 @@ float func4(float x[10], float y[10]) { //CHECK-NEXT: float _EERepl_sum0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: clad::array _delta_x(_d_x.size()); //CHECK-NEXT: clad::array _EERepl_x0(_d_x.size()); @@ -211,7 +214,7 @@ float func4(float x[10], float y[10]) { //CHECK-NEXT: float sum = 0; //CHECK-NEXT: _EERepl_sum0 = sum; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < 10; i++) { +//CHECK-NEXT: for (i = 0; i < 10; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, x[i]); //CHECK-NEXT: x[i] += y[i]; @@ -242,17 +245,17 @@ float func4(float x[10], float y[10]) { //CHECK-NEXT: } //CHECK-NEXT: } //CHECK-NEXT: _delta_sum += std::abs(_d_sum * _EERepl_sum0 * {{.+}}); -//CHECK-NEXT: int i = 0; -//CHECK-NEXT: for (; i < _d_x.size(); i++) { -//CHECK-NEXT: double _t3 = std::abs(_d_x[i] * _EERepl_x0[i] * {{.+}}); -//CHECK-NEXT: _delta_x[i] += _t3; +//CHECK-NEXT: int i0 = 0; +//CHECK-NEXT: for (; i0 < _d_x.size(); i0++) { +//CHECK-NEXT: double _t3 = std::abs(_d_x[i0] * _EERepl_x0[i0] * {{.+}}); +//CHECK-NEXT: _delta_x[i0] += _t3; //CHECK-NEXT: _final_error += _t3; //CHECK-NEXT: } //CHECK-NEXT: clad::array _delta_y(_d_y.size()); -//CHECK-NEXT: i = 0; -//CHECK-NEXT: for (; i < _d_y.size(); i++) { -//CHECK-NEXT: double _t4 = std::abs(_d_y[i] * y[i] * {{.+}}); -//CHECK-NEXT: _delta_y[i] += _t4; +//CHECK-NEXT: i0 = 0; +//CHECK-NEXT: for (; i0 < _d_y.size(); i0++) { +//CHECK-NEXT: double _t4 = std::abs(_d_y[i0] * y[i0] * {{.+}}); +//CHECK-NEXT: _delta_y[i0] += _t4; //CHECK-NEXT: _final_error += _t4; //CHECK-NEXT: } //CHECK-NEXT: _final_error += _delta_sum; diff --git a/test/ErrorEstimation/LoopsAndArraysExec.C b/test/ErrorEstimation/LoopsAndArraysExec.C index caa79678f..5bc4f2daa 100644 --- a/test/ErrorEstimation/LoopsAndArraysExec.C +++ b/test/ErrorEstimation/LoopsAndArraysExec.C @@ -21,12 +21,13 @@ double runningSum(float* f, int n) { //CHECK-NEXT: double _EERepl_sum0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: clad::tape _EERepl_sum1 = {}; //CHECK-NEXT: double sum = 0; //CHECK-NEXT: _EERepl_sum0 = sum; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 1; i < n; i++) { +//CHECK-NEXT: for (i = 1; i < n; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, sum); //CHECK-NEXT: sum += f[i] + f[i - 1]; @@ -48,10 +49,10 @@ double runningSum(float* f, int n) { //CHECK-NEXT: } //CHECK-NEXT: _delta_sum += std::abs(_d_sum * _EERepl_sum0 * {{.+}}); //CHECK-NEXT: clad::array _delta_f(_d_f.size()); -//CHECK-NEXT: int i = 0; -//CHECK-NEXT: for (; i < _d_f.size(); i++) { -//CHECK-NEXT: double _t2 = std::abs(_d_f[i] * f[i] * {{.+}}); -//CHECK-NEXT: _delta_f[i] += _t2; +//CHECK-NEXT: int i0 = 0; +//CHECK-NEXT: for (; i0 < _d_f.size(); i0++) { +//CHECK-NEXT: double _t2 = std::abs(_d_f[i0] * f[i0] * {{.+}}); +//CHECK-NEXT: _delta_f[i0] += _t2; //CHECK-NEXT: _final_error += _t2; //CHECK-NEXT: } //CHECK-NEXT: _final_error += _delta_sum; @@ -72,6 +73,7 @@ double mulSum(float* a, float* b, int n) { //CHECK-NEXT: double _EERepl_sum0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: clad::tape _t2 = {}; //CHECK-NEXT: int _d_j = 0; @@ -81,7 +83,7 @@ double mulSum(float* a, float* b, int n) { //CHECK-NEXT: double sum = 0; //CHECK-NEXT: _EERepl_sum0 = sum; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < n; i++) { +//CHECK-NEXT: for (i = 0; i < n; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, 0UL); //CHECK-NEXT: for (clad::push(_t2, j) , j = 0; j < n; j++) { @@ -115,17 +117,17 @@ double mulSum(float* a, float* b, int n) { //CHECK-NEXT: } //CHECK-NEXT: _delta_sum += std::abs(_d_sum * _EERepl_sum0 * {{.+}}); //CHECK-NEXT: clad::array _delta_a(_d_a.size()); -//CHECK-NEXT: int i = 0; -//CHECK-NEXT: for (; i < _d_a.size(); i++) { -//CHECK-NEXT: double _t4 = std::abs(_d_a[i] * a[i] * {{.+}}); -//CHECK-NEXT: _delta_a[i] += _t4; +//CHECK-NEXT: int i0 = 0; +//CHECK-NEXT: for (; i0 < _d_a.size(); i0++) { +//CHECK-NEXT: double _t4 = std::abs(_d_a[i0] * a[i0] * {{.+}}); +//CHECK-NEXT: _delta_a[i0] += _t4; //CHECK-NEXT: _final_error += _t4; //CHECK-NEXT: } //CHECK-NEXT: clad::array _delta_b(_d_b.size()); -//CHECK-NEXT: i = 0; -//CHECK-NEXT: for (; i < _d_b.size(); i++) { -//CHECK-NEXT: double _t5 = std::abs(_d_b[i] * b[i] * {{.+}}); -//CHECK-NEXT: _delta_b[i] += _t5; +//CHECK-NEXT: i0 = 0; +//CHECK-NEXT: for (; i0 < _d_b.size(); i0++) { +//CHECK-NEXT: double _t5 = std::abs(_d_b[i0] * b[i0] * {{.+}}); +//CHECK-NEXT: _delta_b[i0] += _t5; //CHECK-NEXT: _final_error += _t5; //CHECK-NEXT: } //CHECK-NEXT: _final_error += _delta_sum; @@ -145,12 +147,13 @@ double divSum(float* a, float* b, int n) { //CHECK-NEXT: double _EERepl_sum0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: clad::tape _EERepl_sum1 = {}; //CHECK-NEXT: double sum = 0; //CHECK-NEXT: _EERepl_sum0 = sum; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < n; i++) { +//CHECK-NEXT: for (i = 0; i < n; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, sum); //CHECK-NEXT: sum += a[i] / b[i]; @@ -173,17 +176,17 @@ double divSum(float* a, float* b, int n) { //CHECK-NEXT: } //CHECK-NEXT: _delta_sum += std::abs(_d_sum * _EERepl_sum0 * {{.+}}); //CHECK-NEXT: clad::array _delta_a(_d_a.size()); -//CHECK-NEXT: int i = 0; -//CHECK-NEXT: for (; i < _d_a.size(); i++) { -//CHECK-NEXT: double _t2 = std::abs(_d_a[i] * a[i] * {{.+}}); -//CHECK-NEXT: _delta_a[i] += _t2; +//CHECK-NEXT: int i0 = 0; +//CHECK-NEXT: for (; i0 < _d_a.size(); i0++) { +//CHECK-NEXT: double _t2 = std::abs(_d_a[i0] * a[i0] * {{.+}}); +//CHECK-NEXT: _delta_a[i0] += _t2; //CHECK-NEXT: _final_error += _t2; //CHECK-NEXT: } //CHECK-NEXT: clad::array _delta_b(_d_b.size()); -//CHECK-NEXT: i = 0; -//CHECK-NEXT: for (; i < _d_b.size(); i++) { -//CHECK-NEXT: double _t3 = std::abs(_d_b[i] * b[i] * {{.+}}); -//CHECK-NEXT: _delta_b[i] += _t3; +//CHECK-NEXT: i0 = 0; +//CHECK-NEXT: for (; i0 < _d_b.size(); i0++) { +//CHECK-NEXT: double _t3 = std::abs(_d_b[i0] * b[i0] * {{.+}}); +//CHECK-NEXT: _delta_b[i0] += _t3; //CHECK-NEXT: _final_error += _t3; //CHECK-NEXT: } //CHECK-NEXT: _final_error += _delta_sum; diff --git a/test/Gradient/Assignments.C b/test/Gradient/Assignments.C index 1ae831911..a30da99cb 100644 --- a/test/Gradient/Assignments.C +++ b/test/Gradient/Assignments.C @@ -165,6 +165,7 @@ double f5(double x, double y) { //CHECK-NEXT: double _t0; //CHECK-NEXT: bool _cond1; //CHECK-NEXT: double _d_z = 0; +//CHECK-NEXT: double z = 0; //CHECK-NEXT: double _t1; //CHECK-NEXT: double t = x * x; //CHECK-NEXT: _cond0 = x < 0; @@ -175,7 +176,7 @@ double f5(double x, double y) { //CHECK-NEXT: } //CHECK-NEXT: _cond1 = y < 0; //CHECK-NEXT: if (_cond1) { -//CHECK-NEXT: double z = t; +//CHECK-NEXT: z = t; //CHECK-NEXT: _t1 = t; //CHECK-NEXT: t = -t; //CHECK-NEXT: } @@ -227,6 +228,7 @@ double f6(double x, double y) { //CHECK-NEXT: double _t0; //CHECK-NEXT: bool _cond1; //CHECK-NEXT: double _d_z = 0; +//CHECK-NEXT: double z = 0; //CHECK-NEXT: double _t1; //CHECK-NEXT: double t = x * x; //CHECK-NEXT: _cond0 = x < 0; @@ -237,7 +239,7 @@ double f6(double x, double y) { //CHECK-NEXT: } //CHECK-NEXT: _cond1 = y < 0; //CHECK-NEXT: if (_cond1) { -//CHECK-NEXT: double z = t; +//CHECK-NEXT: z = t; //CHECK-NEXT: _t1 = t; //CHECK-NEXT: t = -t; //CHECK-NEXT: } diff --git a/test/Gradient/FunctionCalls.C b/test/Gradient/FunctionCalls.C index b15f2ab74..d29a7ce41 100644 --- a/test/Gradient/FunctionCalls.C +++ b/test/Gradient/FunctionCalls.C @@ -206,11 +206,12 @@ float sum(double* arr, int n) { // CHECK-NEXT: float _d_res = 0; // CHECK-NEXT: unsigned long _t0; // CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: double _t2; // CHECK-NEXT: float res = 0; // CHECK-NEXT: _t0 = 0; -// CHECK-NEXT: for (int i = 0; i < n; ++i) { +// CHECK-NEXT: for (i = 0; i < n; ++i) { // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, res); // CHECK-NEXT: res += arr[i]; @@ -266,6 +267,7 @@ double fn4(double* arr, int n) { // CHECK-NEXT: double *_t1; // CHECK-NEXT: unsigned long _t2; // CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t3 = {}; // CHECK-NEXT: clad::tape _t4 = {}; // CHECK-NEXT: double res = 0; @@ -273,7 +275,7 @@ double fn4(double* arr, int n) { // CHECK-NEXT: _t1 = arr; // CHECK-NEXT: res += sum(arr, n); // CHECK-NEXT: _t2 = 0; -// CHECK-NEXT: for (int i = 0; i < n; ++i) { +// CHECK-NEXT: for (i = 0; i < n; ++i) { // CHECK-NEXT: _t2++; // CHECK-NEXT: clad::push(_t3, arr[i]); // CHECK-NEXT: twice(arr[i]); diff --git a/test/Gradient/Gradients.C b/test/Gradient/Gradients.C index fb215d31f..5a6a8cb52 100644 --- a/test/Gradient/Gradients.C +++ b/test/Gradient/Gradients.C @@ -701,9 +701,10 @@ float running_sum(float* p, int n) { // CHECK: void running_sum_grad(float *p, int n, clad::array_ref _d_p, clad::array_ref _d_n) { // CHECK-NEXT: unsigned long _t0; // CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: _t0 = 0; -// CHECK-NEXT: for (int i = 1; i < n; i++) { +// CHECK-NEXT: for (i = 1; i < n; i++) { // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, p[i]); // CHECK-NEXT: p[i] += p[i - 1]; diff --git a/test/Gradient/Loops.C b/test/Gradient/Loops.C index 1fdae65ba..27c54bee0 100644 --- a/test/Gradient/Loops.C +++ b/test/Gradient/Loops.C @@ -20,10 +20,11 @@ double f1(double x) { //CHECK-NEXT: double _d_t = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double t = 1; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < 3; i++) { +//CHECK-NEXT: for (i = 0; i < 3; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, t); //CHECK-NEXT: t *= x; @@ -53,6 +54,7 @@ double f2(double x) { //CHECK-NEXT: double _d_t = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: clad::tape _t2 = {}; //CHECK-NEXT: int _d_j = 0; @@ -60,7 +62,7 @@ double f2(double x) { //CHECK-NEXT: clad::tape _t3 = {}; //CHECK-NEXT: double t = 1; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < 3; i++) { +//CHECK-NEXT: for (i = 0; i < 3; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, 0UL); //CHECK-NEXT: for (clad::push(_t2, j) , j = 0; j < 3; j++) { @@ -104,11 +106,12 @@ double f3(double x) { //CHECK-NEXT: double _d_t = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: clad::tape _t3 = {}; //CHECK-NEXT: double t = 1; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < 3; i++) { +//CHECK-NEXT: for (i = 0; i < 3; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, t); //CHECK-NEXT: t *= x; @@ -148,10 +151,11 @@ double f4(double x) { //CHECK-NEXT: double _d_t = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double t = 1; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < 3; clad::push(_t1, t) , (t *= x)) { +//CHECK-NEXT: for (i = 0; i < 3; clad::push(_t1, t) , (t *= x)) { //CHECK-NEXT: _t0++; //CHECK-NEXT: i++; //CHECK-NEXT: } @@ -179,8 +183,9 @@ double f5(double x){ //CHECK: void f5_grad(double x, clad::array_ref _d_x) { //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < 10; i++) { +//CHECK-NEXT: for (i = 0; i < 10; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: x++; //CHECK-NEXT: } @@ -207,13 +212,14 @@ double f_const_local(double x) { //CHECK-NEXT: double _d_res = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double _d_n = 0; //CHECK-NEXT: double n = 0; //CHECK-NEXT: clad::tape _t2 = {}; //CHECK-NEXT: double res = 0; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < 3; ++i) { +//CHECK-NEXT: for (i = 0; i < 3; ++i) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, n) , n = x + i; //CHECK-NEXT: clad::push(_t2, res); @@ -251,10 +257,11 @@ double f_sum(double *p, int n) { //CHECK-NEXT: double _d_s = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double s = 0; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < n; i++) { +//CHECK-NEXT: for (i = 0; i < n; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, s); //CHECK-NEXT: s += p[i]; @@ -292,10 +299,11 @@ double f_sum_squares(double *p, int n) { //CHECK-NEXT: double _d_s = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double s = 0; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < n; i++) { +//CHECK-NEXT: for (i = 0; i < n; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, s); //CHECK-NEXT: s += sq(p[i]); @@ -329,6 +337,7 @@ double f_log_gaus(double* x, double* p /*means*/, double n, double sigma) { //CHECK-NEXT: double _d_power = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double _t2; //CHECK-NEXT: double _t3; @@ -339,7 +348,7 @@ double f_log_gaus(double* x, double* p /*means*/, double n, double sigma) { //CHECK-NEXT: double _d_gaus = 0; //CHECK-NEXT: double power = 0; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < n; i++) { +//CHECK-NEXT: for (i = 0; i < n; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, power); //CHECK-NEXT: power += sq(x[i] - p[i]); @@ -407,13 +416,14 @@ void f_const_grad(const double, const double, clad::array_ref, clad::arr //CHECK-NEXT: int _d_r = 0; //CHECK-NEXT: unsigned long _t0; //CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: int _d_sq = 0; //CHECK-NEXT: int sq0 = 0; //CHECK-NEXT: clad::tape _t2 = {}; //CHECK-NEXT: int r = 0; //CHECK-NEXT: _t0 = 0; -//CHECK-NEXT: for (int i = 0; i < a; i++) { +//CHECK-NEXT: for (i = 0; i < a; i++) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, sq0) , sq0 = b * b; //CHECK-NEXT: clad::push(_t2, r); @@ -453,6 +463,7 @@ double f6 (double i, double j) { // CHECK-NEXT: double _d_a = 0; // CHECK-NEXT: unsigned long _t0; // CHECK-NEXT: int _d_counter = 0; +// CHECK-NEXT: int counter = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: double _d_b = 0; // CHECK-NEXT: double b = 0; @@ -463,7 +474,7 @@ double f6 (double i, double j) { // CHECK-NEXT: clad::tape _t4 = {}; // CHECK-NEXT: double a = 0; // CHECK-NEXT: _t0 = 0; -// CHECK-NEXT: for (int counter = 0; counter < 3; ++counter) { +// CHECK-NEXT: for (counter = 0; counter < 3; ++counter) { // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, b) , b = i * i; // CHECK-NEXT: clad::push(_t2, c) , c = j * j; @@ -1224,6 +1235,7 @@ double fn16(double i, double j) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned long _t0; // CHECK-NEXT: int _d_ii = 0; +// CHECK-NEXT: int ii = 0; // CHECK-NEXT: clad::tape _t2 = {}; // CHECK-NEXT: clad::tape _t3 = {}; // CHECK-NEXT: clad::tape _t4 = {}; @@ -1233,7 +1245,7 @@ double fn16(double i, double j) { // CHECK-NEXT: int counter = 5; // CHECK-NEXT: double res = 0; // CHECK-NEXT: _t0 = 0; -// CHECK-NEXT: for (int ii = 0; ii < counter; ++ii) { +// CHECK-NEXT: for (ii = 0; ii < counter; ++ii) { // CHECK-NEXT: _t0++; // CHECK-NEXT: bool _t1 = ii == 4; // CHECK-NEXT: { @@ -1324,6 +1336,7 @@ double fn17(double i, double j) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned long _t0; // CHECK-NEXT: int _d_ii = 0; +// CHECK-NEXT: int ii = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: int _d_jj = 0; // CHECK-NEXT: int jj = 0; @@ -1337,7 +1350,7 @@ double fn17(double i, double j) { // CHECK-NEXT: int counter = 5; // CHECK-NEXT: double res = 0; // CHECK-NEXT: _t0 = 0; -// CHECK-NEXT: for (int ii = 0; ii < counter; ++ii) { +// CHECK-NEXT: for (ii = 0; ii < counter; ++ii) { // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, jj) , jj = ii; // CHECK-NEXT: bool _t2 = ii < 2; @@ -1446,6 +1459,7 @@ double fn18(double i, double j) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned long _t0; // CHECK-NEXT: int _d_counter = 0; +// CHECK-NEXT: int counter = 0; // CHECK-NEXT: clad::tape _t2 = {}; // CHECK-NEXT: clad::tape _t3 = {}; // CHECK-NEXT: clad::tape _t5 = {}; @@ -1454,7 +1468,7 @@ double fn18(double i, double j) { // CHECK-NEXT: int choice = 5; // CHECK-NEXT: double res = 0; // CHECK-NEXT: _t0 = 0; -// CHECK-NEXT: for (int counter = 0; counter < choice; ++counter) { +// CHECK-NEXT: for (counter = 0; counter < choice; ++counter) { // CHECK-NEXT: _t0++; // CHECK-NEXT: bool _t1 = counter < 2; // CHECK-NEXT: { @@ -1525,30 +1539,34 @@ double fn19(double* arr, int n) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned long _t0; // CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: clad::tape _t2 = {}; // CHECK-NEXT: double *_d_ref = 0; +// CHECK-NEXT: double *ref = {}; // CHECK-NEXT: clad::tape _t3 = {}; // CHECK-NEXT: double res = 0; // CHECK-NEXT: _t0 = 0; -// CHECK-NEXT: for (int i = 0; i < n; ++i) { +// CHECK-NEXT: for (i = 0; i < n; ++i) { // CHECK-NEXT: _t0++; // CHECK-NEXT: _d_ref = &_d_arr[i]; // CHECK-NEXT: clad::push(_t1, _d_ref); -// CHECK-NEXT: double &ref = arr[i]; +// CHECK-NEXT: clad::push(_t2, ref) , ref = &arr[i]; // CHECK-NEXT: clad::push(_t3, res); -// CHECK-NEXT: res += ref; +// CHECK-NEXT: res += *ref; // CHECK-NEXT: } // CHECK-NEXT: goto _label0; // CHECK-NEXT: _label0: // CHECK-NEXT: _d_res += 1; // CHECK-NEXT: for (; _t0; _t0--) { // CHECK-NEXT: --i; -// CHECK-NEXT: double *_t2 = clad::pop(_t1); +// CHECK-NEXT: _d_ref = clad::pop(_t1); // CHECK-NEXT: { // CHECK-NEXT: res = clad::pop(_t3); // CHECK-NEXT: double _r_d0 = _d_res; -// CHECK-NEXT: *_t2 += _r_d0; +// CHECK-NEXT: *_d_ref += _r_d0; // CHECK-NEXT: } +// CHECK-NEXT: ref = clad::pop(_t2); // CHECK-NEXT: } // CHECK-NEXT: } @@ -1568,13 +1586,14 @@ double f_loop_init_var(double lower, double upper) { // CHECK-NEXT: double _d_interval = 0; // CHECK-NEXT: unsigned long _t0; // CHECK-NEXT: double _d_x = 0; +// CHECK-NEXT: double x = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: clad::tape _t2 = {}; // CHECK-NEXT: double sum = 0; // CHECK-NEXT: double num_points = 10000; // CHECK-NEXT: double interval = (upper - lower) / num_points; // CHECK-NEXT: _t0 = 0; -// CHECK-NEXT: for (double x = lower; x <= upper; clad::push(_t1, x) , (x += interval)) { +// CHECK-NEXT: for (x = lower; x <= upper; clad::push(_t1, x) , (x += interval)) { // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t2, sum); // CHECK-NEXT: sum += x * x * interval; diff --git a/test/Gradient/Pointers.C b/test/Gradient/Pointers.C index fbc4f34eb..107254ae0 100644 --- a/test/Gradient/Pointers.C +++ b/test/Gradient/Pointers.C @@ -171,22 +171,25 @@ double pointerParam(const double* arr, size_t n) { // CHECK-NEXT: double _d_sum = 0; // CHECK-NEXT: unsigned long _t0; // CHECK-NEXT: size_t _d_i = 0; +// CHECK-NEXT: size_t i = 0; // CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: clad::tape _t3 = {}; // CHECK-NEXT: size_t *_d_j = 0; -// CHECK-NEXT: clad::tape _t3 = {}; -// CHECK-NEXT: clad::tape _t4 = {}; -// CHECK-NEXT: clad::tape > _t5 = {}; +// CHECK-NEXT: size_t *j = 0; +// CHECK-NEXT: clad::tape _t4 = {}; +// CHECK-NEXT: clad::tape _t5 = {}; +// CHECK-NEXT: clad::tape > _t6 = {}; // CHECK-NEXT: double sum = 0; // CHECK-NEXT: _t0 = 0; -// CHECK-NEXT: for (size_t i = 0; i < n; ++i) { +// CHECK-NEXT: for (i = 0; i < n; ++i) { // CHECK-NEXT: _t0++; // CHECK-NEXT: _d_j = &_d_i; // CHECK-NEXT: clad::push(_t1, _d_j); -// CHECK-NEXT: size_t *j = &i; -// CHECK-NEXT: clad::push(_t3, sum); +// CHECK-NEXT: clad::push(_t3, j) , j = &i; +// CHECK-NEXT: clad::push(_t4, sum); // CHECK-NEXT: sum += arr[0] * (*j); -// CHECK-NEXT: clad::push(_t4, arr); -// CHECK-NEXT: clad::push(_t5, _d_arr); +// CHECK-NEXT: clad::push(_t5, arr); +// CHECK-NEXT: clad::push(_t6, _d_arr); // CHECK-NEXT: _d_arr.ptr_ref() = _d_arr.ptr_ref() + 1; // CHECK-NEXT: arr = arr + 1; // CHECK-NEXT: } @@ -197,15 +200,16 @@ double pointerParam(const double* arr, size_t n) { // CHECK-NEXT: --i; // CHECK-NEXT: size_t *_t2 = clad::pop(_t1); // CHECK-NEXT: { -// CHECK-NEXT: arr = clad::pop(_t4); -// CHECK-NEXT: _d_arr = clad::pop(_t5); +// CHECK-NEXT: arr = clad::pop(_t5); +// CHECK-NEXT: _d_arr = clad::pop(_t6); // CHECK-NEXT: } // CHECK-NEXT: { -// CHECK-NEXT: sum = clad::pop(_t3); +// CHECK-NEXT: sum = clad::pop(_t4); // CHECK-NEXT: double _r_d0 = _d_sum; // CHECK-NEXT: _d_arr[0] += _r_d0 * (*j); // CHECK-NEXT: *_t2 += arr[0] * _r_d0; // CHECK-NEXT: } +// CHECK-NEXT: j = clad::pop(_t3); // CHECK-NEXT: } // CHECK-NEXT: } diff --git a/test/Gradient/TestTypeConversion.C b/test/Gradient/TestTypeConversion.C index 4576f83d7..20582e35b 100644 --- a/test/Gradient/TestTypeConversion.C +++ b/test/Gradient/TestTypeConversion.C @@ -21,9 +21,10 @@ void fn_type_conversion_grad(float z, int a, clad::array_ref _d_z, clad:: // CHECK: void fn_type_conversion_grad(float z, int a, clad::array_ref _d_z, clad::array_ref _d_a) { // CHECK-NEXT: unsigned long _t0; // CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: _t0 = 0; -// CHECK-NEXT: for (int i = 1; i < a; i++) { +// CHECK-NEXT: for (i = 1; i < a; i++) { // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, z); // CHECK-NEXT: z = z * a; diff --git a/test/Gradient/UserDefinedTypes.C b/test/Gradient/UserDefinedTypes.C index 71af7f53a..7df32651a 100644 --- a/test/Gradient/UserDefinedTypes.C +++ b/test/Gradient/UserDefinedTypes.C @@ -60,10 +60,11 @@ double sum(Tangent& t) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned long _t0; // CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: double res = 0; // CHECK-NEXT: _t0 = 0; -// CHECK-NEXT: for (int i = 0; i < 5; ++i) { +// CHECK-NEXT: for (i = 0; i < 5; ++i) { // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, res); // CHECK-NEXT: res += t.data[i]; @@ -90,10 +91,11 @@ double sum(double *data) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned long _t0; // CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: double res = 0; // CHECK-NEXT: _t0 = 0; -// CHECK-NEXT: for (int i = 0; i < 5; ++i) { +// CHECK-NEXT: for (i = 0; i < 5; ++i) { // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, res); // CHECK-NEXT: res += data[i]; @@ -369,9 +371,10 @@ double fn8(Tangent t, dcomplex c) { // CHECK: void updateTo_pullback(double d, clad::array_ref _d_this, clad::array_ref _d_d) { // CHECK-NEXT: unsigned long _t0; // CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: _t0 = 0; -// CHECK-NEXT: for (int i = 0; i < 5; ++i) { +// CHECK-NEXT: for (i = 0; i < 5; ++i) { // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, this->data[i]); // CHECK-NEXT: this->data[i] = d; @@ -421,6 +424,7 @@ double fn9(Tangent t, dcomplex c) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned long _t0; // CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: clad::tape _t2 = {}; // CHECK-NEXT: clad::tape _t3 = {}; @@ -429,7 +433,7 @@ double fn9(Tangent t, dcomplex c) { // CHECK-NEXT: Tangent _t6; // CHECK-NEXT: double res = 0; // CHECK-NEXT: _t0 = 0; -// CHECK-NEXT: for (int i = 0; i < 5; ++i) { +// CHECK-NEXT: for (i = 0; i < 5; ++i) { // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, res); // CHECK-NEXT: clad::push(_t2, c); diff --git a/test/Misc/RunDemos.C b/test/Misc/RunDemos.C index 5a0ecfec3..3830821d7 100644 --- a/test/Misc/RunDemos.C +++ b/test/Misc/RunDemos.C @@ -112,12 +112,13 @@ //CHECK_FLOAT_SUM: float _EERepl_sum0; //CHECK_FLOAT_SUM: unsigned long _t0; //CHECK_FLOAT_SUM: unsigned int _d_i = 0; +//CHECK_FLOAT_SUM: unsigned int i = 0; //CHECK_FLOAT_SUM: clad::tape _t1 = {}; //CHECK_FLOAT_SUM: clad::tape _EERepl_sum1 = {}; //CHECK_FLOAT_SUM: float sum = 0.; //CHECK_FLOAT_SUM: _EERepl_sum0 = sum; //CHECK_FLOAT_SUM: _t0 = 0; -//CHECK_FLOAT_SUM: for (unsigned int i = 0; i < n; i++) { +//CHECK_FLOAT_SUM: for (i = 0; i < n; i++) { //CHECK_FLOAT_SUM: _t0++; //CHECK_FLOAT_SUM: clad::push(_t1, sum); //CHECK_FLOAT_SUM: sum = sum + x; diff --git a/test/NumericalDiff/NumDiff.C b/test/NumericalDiff/NumDiff.C index e4d46f263..2860ab4ab 100644 --- a/test/NumericalDiff/NumDiff.C +++ b/test/NumericalDiff/NumDiff.C @@ -1,5 +1,7 @@ // RUN: %cladnumdiffclang %s -I%S/../../include -oNumDiff.out 2>&1 | FileCheck -check-prefix=CHECK %s - +// RUN: ./NumDiff.out | FileCheck -check-prefix=CHECK-EXEC %s +// RUN: %cladnumdiffclang -Xclang -plugin-arg-clad -Xclang -enable-tbr %s -I%S/../../include -oNumDiff.out +// RUN: ./NumDiff.out | FileCheck -check-prefix=CHECK-EXEC %s //CHECK-NOT: {{.*error|warning|note:.*}} #include "clad/Differentiator/Differentiator.h" @@ -28,7 +30,48 @@ double test_2(double x){ //CHECK-NEXT: return numerical_diff::forward_central_difference(std::log10, x, 0, 0, x) * _d_x; //CHECK-NEXT: } + +double test_3(double x) { + if (x > 0) { + double constant = 11.; + return std::hypot(x, constant); + } + return 0; +} +//CHECK: void test_3_grad(double x, clad::array_ref _d_x) { +//CHECK-NEXT: bool _cond0; +//CHECK-NEXT: double _d_constant = 0; +//CHECK-NEXT: double constant = 0; +//CHECK-NEXT: _cond0 = x > 0; +//CHECK-NEXT: if (_cond0) { +//CHECK-NEXT: constant = 11.; +//CHECK-NEXT: goto _label0; +//CHECK-NEXT: } +//CHECK-NEXT: goto _label1; +//CHECK-NEXT: _label1: +//CHECK-NEXT: ; +//CHECK-NEXT: if (_cond0) { +//CHECK-NEXT: _label0: +//CHECK-NEXT: { +//CHECK-NEXT: double _grad0 = 0.; +//CHECK-NEXT: double _grad1 = 0.; +//CHECK-NEXT: clad::tape > _t0 = {}; +//CHECK-NEXT: clad::push(_t0, &_grad0); +//CHECK-NEXT: clad::push(_t0, &_grad1); +//CHECK-NEXT: numerical_diff::central_difference(std::hypot, _t0, 0, x, constant); +//CHECK-NEXT: double _r0 = 1 * _grad0; +//CHECK-NEXT: * _d_x += _r0; +//CHECK-NEXT: double _r1 = 1 * _grad1; +//CHECK-NEXT: _d_constant += _r1; +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: } + int main(){ clad::gradient(test_1); clad::differentiate(test_2, 0); + auto dtest_3 = clad::gradient(test_3); + double dx = 0; + dtest_3.execute(5, &dx); + printf("Result is = %f\n", dx); // CHECK-EXEC: Result is = 0.413803 }