From d55aae9f13e392de38bbc2087606dd4e582b633d Mon Sep 17 00:00:00 2001 From: "petro.zarytskyi" Date: Tue, 30 Apr 2024 16:57:08 +0300 Subject: [PATCH] Pass the final error argument by pointer rather than by reference and start using overloads in error estimation --- demos/ErrorEstimation/FloatSum.cpp | 2 +- demos/ErrorEstimation/PrintModel/test.cpp | 2 +- include/clad/Differentiator/Differentiator.h | 10 +- include/clad/Differentiator/FunctionTraits.h | 7 +- .../clad/Differentiator/ReverseModeVisitor.h | 4 +- lib/Differentiator/ErrorEstimator.cpp | 12 +- lib/Differentiator/ReverseModeVisitor.cpp | 21 ++-- test/ErrorEstimation/Assignments.C | 46 +++---- test/ErrorEstimation/BasicOps.C | 118 +++++++++--------- test/ErrorEstimation/ConditonalStatements.C | 42 +++---- test/ErrorEstimation/LoopsAndArrays.C | 56 ++++----- test/ErrorEstimation/LoopsAndArraysExec.C | 34 ++--- test/Misc/RunDemos.C | 24 ++-- 13 files changed, 192 insertions(+), 186 deletions(-) diff --git a/demos/ErrorEstimation/FloatSum.cpp b/demos/ErrorEstimation/FloatSum.cpp index 8c039212c..418aad168 100644 --- a/demos/ErrorEstimation/FloatSum.cpp +++ b/demos/ErrorEstimation/FloatSum.cpp @@ -106,7 +106,7 @@ int main() { finalError = 0; unsigned int dn = 0; // First execute the derived function. - df.execute(x, n, &ret[0], &dn, finalError); + df.execute(x, n, &ret[0], &dn, &finalError); double kahanResult = kahanSum(x, n); double vanillaResult = vanillaSum(x, n); diff --git a/demos/ErrorEstimation/PrintModel/test.cpp b/demos/ErrorEstimation/PrintModel/test.cpp index 29f4b7d3e..0ac09a230 100644 --- a/demos/ErrorEstimation/PrintModel/test.cpp +++ b/demos/ErrorEstimation/PrintModel/test.cpp @@ -29,5 +29,5 @@ int main() { // Calculate the error float dx, dy; double error; - df.execute(2, 3, &dx, &dy, error); + df.execute(2, 3, &dx, &dy, &error); } diff --git a/include/clad/Differentiator/Differentiator.h b/include/clad/Differentiator/Differentiator.h index 65211f24c..cb444de7c 100644 --- a/include/clad/Differentiator/Differentiator.h +++ b/include/clad/Differentiator/Differentiator.h @@ -494,14 +494,14 @@ inline CUDA_HOST_DEVICE unsigned int GetLength(const char* code) { template > - CladFunction __attribute__((annotate("E"))) + CladFunction, true> __attribute__(( + annotate("E"))) estimate_error(F f, ArgSpec args = "", DerivedFnType derivedFn = static_cast(nullptr), const char* code = "") { - assert(f && "Must pass in a non-0 argument"); - return CladFunction< - DerivedFnType>(derivedFn /* will be replaced by estimation code*/, - code); + assert(f && "Must pass in a non-0 argument"); + return CladFunction, true>( + derivedFn /* will be replaced by estimation code*/, code); } // Gradient Structure for Reverse Mode Enzyme diff --git a/include/clad/Differentiator/FunctionTraits.h b/include/clad/Differentiator/FunctionTraits.h index c15eeb270..d84ac50d7 100644 --- a/include/clad/Differentiator/FunctionTraits.h +++ b/include/clad/Differentiator/FunctionTraits.h @@ -482,8 +482,7 @@ namespace clad { // GradientDerivedEstFnTraits specializations for pure function pointer types template struct GradientDerivedEstFnTraits { - using type = void (*)(Args..., OutputParamType_t..., - double&); + using type = void (*)(Args..., OutputParamType_t..., void*); }; /// These macro expansions are used to cover all possible cases of @@ -498,8 +497,8 @@ namespace clad { #define GradientDerivedEstFnTraits_AddSPECS(var, cv, vol, ref, noex) \ template \ struct GradientDerivedEstFnTraits { \ - using type = void (C::*)(Args..., OutputParamType_t..., \ - double&) cv vol ref noex; \ + using type = void (C::*)(Args..., OutputParamType_t..., \ + void*) cv vol ref noex; \ }; #if __cpp_noexcept_function_type > 0 diff --git a/include/clad/Differentiator/ReverseModeVisitor.h b/include/clad/Differentiator/ReverseModeVisitor.h index 2b3670c45..eea971a37 100644 --- a/include/clad/Differentiator/ReverseModeVisitor.h +++ b/include/clad/Differentiator/ReverseModeVisitor.h @@ -436,7 +436,9 @@ namespace clad { /// Builds an overload for the gradient function that has derived params for /// all the arguments of the requested function and it calls the original /// gradient function internally - clang::FunctionDecl* CreateGradientOverload(); + /// \param[in] numExtraParam The number of extra parameters requested by an + /// external source (e.g. the final error in error estimation). + clang::FunctionDecl* CreateGradientOverload(unsigned numExtraParam = 0); /// Returns the type that should be used to represent the derivative of a /// variable of type `yType` with respect to a parameter variable of type diff --git a/lib/Differentiator/ErrorEstimator.cpp b/lib/Differentiator/ErrorEstimator.cpp index 4545877e5..040e54cde 100644 --- a/lib/Differentiator/ErrorEstimator.cpp +++ b/lib/Differentiator/ErrorEstimator.cpp @@ -285,7 +285,7 @@ void ErrorEstimationHandler::ActAfterCreatingDerivedFnParamTypes( // If we are performing error estimation, our gradient function // will have an extra argument which will hold the final error value paramTypes.push_back( - m_RMV->m_Context.getLValueReferenceType(m_RMV->m_Context.DoubleTy)); + m_RMV->m_Context.getPointerType(m_RMV->m_Context.DoubleTy)); } void ErrorEstimationHandler::ActAfterCreatingDerivedFnParams( @@ -307,7 +307,8 @@ void ErrorEstimationHandler::ActAfterCreatingDerivedFnParams( void ErrorEstimationHandler::ActBeforeCreatingDerivedFnBodyScope() { // Reference to the final error statement - SetFinalErrorExpr(m_RMV->BuildDeclRef(m_Params->back())); + DeclRefExpr* DRE = m_RMV->BuildDeclRef(m_Params->back()); + SetFinalErrorExpr(m_RMV->BuildOp(UO_Deref, DRE)); } void ErrorEstimationHandler::ActOnEndOfDerivedFnBody() { @@ -468,12 +469,13 @@ void ErrorEstimationHandler::ActBeforeFinalizingDifferentiateSingleExpr( void ErrorEstimationHandler::ActBeforeDifferentiatingCallExpr( llvm::SmallVectorImpl& pullbackArgs, llvm::SmallVectorImpl& ArgDecls, bool hasAssignee) { - auto errorRef = + VarDecl* errorRef = m_RMV->BuildVarDecl(m_RMV->m_Context.DoubleTy, "_t", m_RMV->getZeroInit(m_RMV->m_Context.DoubleTy)); ArgDecls.push_back(m_RMV->BuildDeclStmt(errorRef)); - auto finErr = m_RMV->BuildDeclRef(errorRef); - pullbackArgs.push_back(finErr); + Expr* finErr = m_RMV->BuildDeclRef(errorRef); + Expr* arg = m_RMV->BuildOp(UO_AddrOf, finErr); + pullbackArgs.push_back(arg); if (hasAssignee) { if (m_NestedFuncError) m_NestedFuncError = m_RMV->BuildOp(BO_Add, m_NestedFuncError, finErr); diff --git a/lib/Differentiator/ReverseModeVisitor.cpp b/lib/Differentiator/ReverseModeVisitor.cpp index 7223f5e41..fad041566 100644 --- a/lib/Differentiator/ReverseModeVisitor.cpp +++ b/lib/Differentiator/ReverseModeVisitor.cpp @@ -112,7 +112,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, } } - FunctionDecl* ReverseModeVisitor::CreateGradientOverload() { + FunctionDecl* + ReverseModeVisitor::CreateGradientOverload(unsigned numExtraParam) { auto gradientParams = m_Derivative->parameters(); auto gradientNameInfo = m_Derivative->getNameInfo(); // Calculate the total number of parameters that would be required for @@ -120,8 +121,10 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // requested. // FIXME: Here we are assuming all function parameters are of differentiable // type. Ideally, we should not make any such assumption. - std::size_t totalDerivedParamsSize = m_Function->getNumParams() * 2; - std::size_t numOfDerivativeParams = m_Function->getNumParams(); + std::size_t totalDerivedParamsSize = + m_Function->getNumParams() * 2 + numExtraParam; + std::size_t numOfDerivativeParams = + m_Function->getNumParams() + numExtraParam; // Account for the this pointer. if (isa(m_Function) && !utils::IsStaticMethod(m_Function)) @@ -273,7 +276,10 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, } else std::copy(FD->param_begin(), FD->param_end(), std::back_inserter(args)); - if (args.empty()) + // If there are no parameters to differentiate with respect to, don't + // generate the gradient. However, if an external source is attached, the + // gradient function can another purpose. + if (args.empty() && !m_ExternalSource) return {}; if (m_ExternalSource) @@ -336,9 +342,7 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // If reverse mode differentiates only part of the arguments it needs to // generate an overload that can take in all the diff variables bool shouldCreateOverload = false; - // FIXME: Gradient overload doesn't know how to handle additional parameters - // added by the plugins yet. - if (!isVectorValued && numExtraParam == 0) + if (!isVectorValued) shouldCreateOverload = true; if (request.DerivedFDPrototype) // If the overload is already created, we don't need to create it again. @@ -452,8 +456,7 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, FunctionDecl* gradientOverloadFD = nullptr; if (shouldCreateOverload) { - gradientOverloadFD = - CreateGradientOverload(); + gradientOverloadFD = CreateGradientOverload(numExtraParam); } return DerivativeAndOverload{result.first, gradientOverloadFD}; diff --git a/test/ErrorEstimation/Assignments.C b/test/ErrorEstimation/Assignments.C index f22b72e1e..4f003d364 100644 --- a/test/ErrorEstimation/Assignments.C +++ b/test/ErrorEstimation/Assignments.C @@ -12,7 +12,7 @@ float func(float x, float y) { return y; } -//CHECK: void func_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _t0; //CHECK-NEXT: float _t1; //CHECK-NEXT: _t0 = x; @@ -29,15 +29,15 @@ float func(float x, float y) { //CHECK-NEXT: *_d_x += _r_d1; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t0; //CHECK-NEXT: float _r_d0 = *_d_x; //CHECK-NEXT: *_d_x -= _r_d0; //CHECK-NEXT: *_d_x += _r_d0; //CHECK-NEXT: *_d_y += _r_d0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } float func2(float x, int y) { @@ -45,7 +45,7 @@ float func2(float x, int y) { return x; } -//CHECK: void func2_grad_0(float x, int y, float *_d_x, double &_final_error) { +//CHECK: void func2_grad_0(float x, int y, float *_d_x, double *_final_error) { //CHECK-NEXT: float _t0; //CHECK-NEXT: _t0 = x; //CHECK-NEXT: x = y * x + x * x; @@ -53,7 +53,7 @@ float func2(float x, int y) { //CHECK-NEXT: _label0: //CHECK-NEXT: *_d_x += 1; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t0; //CHECK-NEXT: float _r_d0 = *_d_x; //CHECK-NEXT: *_d_x -= _r_d0; @@ -61,7 +61,7 @@ float func2(float x, int y) { //CHECK-NEXT: *_d_x += _r_d0 * x; //CHECK-NEXT: *_d_x += x * _r_d0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: } float func3(int x, int y) { @@ -69,7 +69,7 @@ float func3(int x, int y) { return y; } -//CHECK: void func3_grad(int x, int y, double &_final_error) { +//CHECK: void func3_grad(int x, int y, double *_final_error) { //CHECK-NEXT: int _t0; //CHECK-NEXT: _t0 = x; //CHECK-NEXT: x = y; @@ -85,7 +85,7 @@ float func4(float x, float y) { return x; } -//CHECK: void func4_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func4_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: double _d_z = 0; //CHECK-NEXT: float _t0; //CHECK-NEXT: double z = y; @@ -95,7 +95,7 @@ float func4(float x, float y) { //CHECK-NEXT: _label0: //CHECK-NEXT: *_d_x += 1; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t0; //CHECK-NEXT: float _r_d0 = *_d_x; //CHECK-NEXT: *_d_x -= _r_d0; @@ -103,8 +103,8 @@ float func4(float x, float y) { //CHECK-NEXT: *_d_y += _r_d0; //CHECK-NEXT: } //CHECK-NEXT: *_d_y += _d_z; -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } float func5(float x, float y) { @@ -113,7 +113,7 @@ float func5(float x, float y) { return x; } -//CHECK: void func5_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func5_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _t0; //CHECK-NEXT: int z = 56; //CHECK-NEXT: _t0 = x; @@ -122,28 +122,28 @@ float func5(float x, float y) { //CHECK-NEXT: _label0: //CHECK-NEXT: *_d_x += 1; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t0; //CHECK-NEXT: float _r_d0 = *_d_x; //CHECK-NEXT: *_d_x -= _r_d0; //CHECK-NEXT: *_d_y += _r_d0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } float func6(float x) { return x; } -//CHECK: void func6_grad(float x, float *_d_x, double &_final_error) { +//CHECK: void func6_grad(float x, float *_d_x, double *_final_error) { //CHECK-NEXT: goto _label0; //CHECK-NEXT: _label0: //CHECK-NEXT: *_d_x += 1; -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: } float func7(float x, float y) { return (x * y); } -//CHECK: void func7_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func7_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: double _ret_value0 = 0; //CHECK-NEXT: _ret_value0 = (x * y); //CHECK-NEXT: goto _label0; @@ -152,9 +152,9 @@ float func7(float x, float y) { return (x * y); } //CHECK-NEXT: *_d_x += 1 * y; //CHECK-NEXT: *_d_y += x * 1; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } float func8(int x, int y) { @@ -162,7 +162,7 @@ float func8(int x, int y) { return x; } -//CHECK: void func8_grad(int x, int y, double &_final_error) { +//CHECK: void func8_grad(int x, int y, double *_final_error) { //CHECK-NEXT: int _t0; //CHECK-NEXT: _t0 = x; //CHECK-NEXT: x = y * y; diff --git a/test/ErrorEstimation/BasicOps.C b/test/ErrorEstimation/BasicOps.C index 734959ead..5676f4166 100644 --- a/test/ErrorEstimation/BasicOps.C +++ b/test/ErrorEstimation/BasicOps.C @@ -13,7 +13,7 @@ float func(float x, float y) { return z; } -//CHECK: void func_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _t0; //CHECK-NEXT: float _t1; //CHECK-NEXT: float _d_z = 0; @@ -26,13 +26,13 @@ float func(float x, float y) { //CHECK-NEXT: _label0: //CHECK-NEXT: _d_z += 1; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_z * z * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_z * z * {{.+}}); //CHECK-NEXT: *_d_y += _d_z * x; //CHECK-NEXT: *_d_x += y * _d_z; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: y = _t1; //CHECK-NEXT: float _r_d1 = *_d_y; //CHECK-NEXT: *_d_y -= _r_d1; @@ -42,15 +42,15 @@ float func(float x, float y) { //CHECK-NEXT: *_d_y += _r_d1; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t0; //CHECK-NEXT: float _r_d0 = *_d_x; //CHECK-NEXT: *_d_x -= _r_d0; //CHECK-NEXT: *_d_x += _r_d0; //CHECK-NEXT: *_d_y += _r_d0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } // This function may evaluate incorrectly due to absence of usage of @@ -61,7 +61,7 @@ float func2(float x, float y) { return z; } -//CHECK: void func2_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func2_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _t0; //CHECK-NEXT: float _d_z = 0; //CHECK-NEXT: _t0 = x; @@ -71,13 +71,13 @@ float func2(float x, float y) { //CHECK-NEXT: _label0: //CHECK-NEXT: _d_z += 1; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_z * z * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_z * z * {{.+}}); //CHECK-NEXT: *_d_y += _d_z / x; //CHECK-NEXT: float _r0 = _d_z * -y / (x * x); //CHECK-NEXT: *_d_x += _r0; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t0; //CHECK-NEXT: float _r_d0 = *_d_x; //CHECK-NEXT: *_d_x -= _r_d0; @@ -86,8 +86,8 @@ float func2(float x, float y) { //CHECK-NEXT: *_d_y += -_r_d0 * y; //CHECK-NEXT: *_d_y += y * -_r_d0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } @@ -99,7 +99,7 @@ float func3(float x, float y) { return t; } -//CHECK: void func3_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func3_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _t0; //CHECK-NEXT: float _d_z = 0; //CHECK-NEXT: float _t1; @@ -115,8 +115,8 @@ float func3(float x, float y) { //CHECK-NEXT: _label0: //CHECK-NEXT: _d_t += 1; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_t * t * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_t * t * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: *_d_x += _d_t * _t1 * z; //CHECK-NEXT: _d_z += x * _d_t * _t1; //CHECK-NEXT: *_d_y += x * z * _d_t; @@ -128,7 +128,7 @@ float func3(float x, float y) { //CHECK-NEXT: } //CHECK-NEXT: *_d_y += _d_z; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t0; //CHECK-NEXT: float _r_d0 = *_d_x; //CHECK-NEXT: *_d_x -= _r_d0; @@ -137,14 +137,14 @@ float func3(float x, float y) { //CHECK-NEXT: *_d_y += -_r_d0 * y; //CHECK-NEXT: *_d_y += y * -_r_d0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } // Function call custom derivative exists but no assign expr float func4(float x, float y) { return std::pow(x, y); } -//CHECK: void func4_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func4_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: double _ret_value0 = 0; //CHECK-NEXT: _ret_value0 = std::pow(x, y); //CHECK-NEXT: goto _label0; @@ -156,9 +156,9 @@ float func4(float x, float y) { return std::pow(x, y); } //CHECK-NEXT: *_d_x += _r0; //CHECK-NEXT: *_d_y += _r1; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } // Function call custom derivative exists and is assigned @@ -167,7 +167,7 @@ float func5(float x, float y) { return y * y; } -//CHECK: void func5_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func5_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _t0; //CHECK-NEXT: double _ret_value0 = 0; //CHECK-NEXT: _t0 = y; @@ -180,7 +180,7 @@ float func5(float x, float y) { //CHECK-NEXT: *_d_y += y * 1; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: y = _t0; //CHECK-NEXT: float _r_d0 = *_d_y; //CHECK-NEXT: *_d_y -= _r_d0; @@ -188,15 +188,15 @@ float func5(float x, float y) { //CHECK-NEXT: _r0 += _r_d0 * clad::custom_derivatives{{(::std)?}}::sin_pushforward(x, 1.F).pushforward; //CHECK-NEXT: *_d_x += _r0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } // Function call non custom derivative double helper(double x, double y) { return x * y; } -//CHECK: void helper_pullback(double x, double y, double _d_y0, double *_d_x, double *_d_y, double &_final_error) { +//CHECK: void helper_pullback(double x, double y, double _d_y0, double *_d_x, double *_d_y, double *_final_error) { //CHECK-NEXT: double _ret_value0 = 0; //CHECK-NEXT: _ret_value0 = x * y; //CHECK-NEXT: goto _label0; @@ -205,9 +205,9 @@ double helper(double x, double y) { return x * y; } //CHECK-NEXT: *_d_x += _d_y0 * y; //CHECK-NEXT: *_d_y += x * _d_y0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } float func6(float x, float y) { @@ -215,7 +215,7 @@ float func6(float x, float y) { return z * z; } -//CHECK: void func6_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func6_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _d_z = 0; //CHECK-NEXT: double _ret_value0 = 0; //CHECK-NEXT: float z = helper(x, y); @@ -230,14 +230,14 @@ float func6(float x, float y) { //CHECK-NEXT: double _r0 = 0; //CHECK-NEXT: double _r1 = 0; //CHECK-NEXT: double _t0 = 0; -//CHECK-NEXT: helper_pullback(x, y, _d_z, &_r0, &_r1, _t0); +//CHECK-NEXT: helper_pullback(x, y, _d_z, &_r0, &_r1, &_t0); //CHECK-NEXT: *_d_x += _r0; //CHECK-NEXT: *_d_y += _r1; -//CHECK-NEXT: _final_error += _t0; +//CHECK-NEXT: *_final_error += _t0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } float func7(float x) { @@ -245,18 +245,18 @@ float func7(float x) { return z + z; } -//CHECK: void func7_grad(float x, float *_d_x, double &_final_error) { +//CHECK: void func7_grad(float x, float *_d_x, double *_final_error) { //CHECK-NEXT: int z = x; //CHECK-NEXT: goto _label0; //CHECK-NEXT: _label0: //CHECK-NEXT: ; -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: } double helper2(float& x) { return x * x; } -//CHECK: void helper2_pullback(float &x, double _d_y, float *_d_x, double &_final_error) { +//CHECK: void helper2_pullback(float &x, double _d_y, float *_d_x, double *_final_error) { //CHECK-NEXT: double _ret_value0 = 0; //CHECK-NEXT: _ret_value0 = x * x; //CHECK-NEXT: goto _label0; @@ -265,7 +265,7 @@ double helper2(float& x) { return x * x; } //CHECK-NEXT: *_d_x += _d_y * x; //CHECK-NEXT: *_d_x += x * _d_y; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } float func8(float x, float y) { @@ -274,7 +274,7 @@ float func8(float x, float y) { return z; } -//CHECK: void func8_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func8_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _d_z = 0; //CHECK-NEXT: float _t0; //CHECK-NEXT: float _t1; @@ -292,12 +292,12 @@ float func8(float x, float y) { //CHECK-NEXT: *_d_y += _r_d0; //CHECK-NEXT: x = _t1; //CHECK-NEXT: double _t2 = 0; -//CHECK-NEXT: helper2_pullback(_t1, _r_d0, &*_d_x, _t2); -//CHECK-NEXT: _final_error += _t2; -//CHECK-NEXT: _final_error += std::abs(*_d_x * _t1 * {{.+}}); +//CHECK-NEXT: helper2_pullback(_t1, _r_d0, &*_d_x, &_t2); +//CHECK-NEXT: *_final_error += _t2; +//CHECK-NEXT: *_final_error += std::abs(*_d_x * _t1 * {{.+}}); //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } float func9(float x, float y) { @@ -306,7 +306,7 @@ float func9(float x, float y) { return z; } -//CHECK: void func9_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func9_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _t1; //CHECK-NEXT: float _d_z = 0; //CHECK-NEXT: float _t3; @@ -330,29 +330,29 @@ float func9(float x, float y) { //CHECK-NEXT: float _r_d0 = _d_z; //CHECK-NEXT: x = _t5; //CHECK-NEXT: double _t6 = 0; -//CHECK-NEXT: helper2_pullback(_t5, _r_d0 * _t4, &*_d_x, _t6); +//CHECK-NEXT: helper2_pullback(_t5, _r_d0 * _t4, &*_d_x, &_t6); //CHECK-NEXT: y = _t8; //CHECK-NEXT: double _t9 = 0; -//CHECK-NEXT: helper2_pullback(_t8, _t7 * _r_d0, &*_d_y, _t9); -//CHECK-NEXT: _final_error += _t6 + _t9; -//CHECK-NEXT: _final_error += std::abs(*_d_y * _t8 * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_x * _t5 * {{.+}}); +//CHECK-NEXT: helper2_pullback(_t8, _t7 * _r_d0, &*_d_y, &_t9); +//CHECK-NEXT: *_final_error += _t6 + _t9; +//CHECK-NEXT: *_final_error += std::abs(*_d_y * _t8 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * _t5 * {{.+}}); //CHECK-NEXT: } //CHECK-NEXT: { //CHECK-NEXT: double _r0 = 0; //CHECK-NEXT: double _r1 = 0; //CHECK-NEXT: double _t0 = 0; -//CHECK-NEXT: helper_pullback(x, y, _d_z, &_r0, &_r1, _t0); +//CHECK-NEXT: helper_pullback(x, y, _d_z, &_r0, &_r1, &_t0); //CHECK-NEXT: *_d_x += _r0; //CHECK-NEXT: *_d_y += _r1; //CHECK-NEXT: x = _t1; //CHECK-NEXT: double _t2 = 0; -//CHECK-NEXT: helper2_pullback(_t1, _d_z, &*_d_x, _t2); -//CHECK-NEXT: _final_error += _t0 + _t2; -//CHECK-NEXT: _final_error += std::abs(*_d_x * _t1 * {{.+}}); +//CHECK-NEXT: helper2_pullback(_t1, _d_z, &*_d_x, &_t2); +//CHECK-NEXT: *_final_error += _t0 + _t2; +//CHECK-NEXT: *_final_error += std::abs(*_d_x * _t1 * {{.+}}); //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } int main() { diff --git a/test/ErrorEstimation/ConditonalStatements.C b/test/ErrorEstimation/ConditonalStatements.C index 87b2e4e2b..8c31c08f9 100644 --- a/test/ErrorEstimation/ConditonalStatements.C +++ b/test/ErrorEstimation/ConditonalStatements.C @@ -17,7 +17,7 @@ float func(float x, float y) { return x + y; } -//CHECK: void func_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: bool _cond0; //CHECK-NEXT: float _t0; //CHECK-NEXT: float _d_temp = 0; @@ -45,7 +45,7 @@ float func(float x, float y) { //CHECK-NEXT: } //CHECK-NEXT: if (_cond0) { //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: y = _t0; //CHECK-NEXT: float _r_d0 = *_d_y; //CHECK-NEXT: *_d_y -= _r_d0; @@ -60,7 +60,7 @@ float func(float x, float y) { //CHECK-NEXT: *_d_y += _r_d2; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_temp * temp * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_temp * temp * {{.+}}); //CHECK-NEXT: temp = _t1; //CHECK-NEXT: float _r_d1 = _d_temp; //CHECK-NEXT: _d_temp -= _r_d1; @@ -68,13 +68,13 @@ float func(float x, float y) { //CHECK-NEXT: *_d_y += y * _r_d1; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_temp * temp * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_temp * temp * {{.+}}); //CHECK-NEXT: *_d_y += _d_temp; //CHECK-NEXT: } //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } // Single return statement if/else @@ -86,7 +86,7 @@ float func2(float x) { return x * x; } -//CHECK: void func2_grad(float x, float *_d_x, double &_final_error) { +//CHECK: void func2_grad(float x, float *_d_x, double *_final_error) { //CHECK-NEXT: float _d_z = 0; //CHECK-NEXT: bool _cond0; //CHECK-NEXT: double _ret_value0 = 0; @@ -112,17 +112,17 @@ float func2(float x) { //CHECK-NEXT: *_d_x += x * 1; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_z * z * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_z * z * {{.+}}); //CHECK-NEXT: *_d_x += _d_z * x; //CHECK-NEXT: *_d_x += x * _d_z; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } float func3(float x, float y) { return x > 30 ? x * y : x + y; } -//CHECK: void func3_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func3_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: bool _cond0; //CHECK-NEXT: double _ret_value0 = 0; //CHECK-NEXT: _cond0 = x > 30; @@ -136,9 +136,9 @@ float func3(float x, float y) { return x > 30 ? x * y : x + y; } //CHECK-NEXT: *_d_x += 1; //CHECK-NEXT: *_d_y += 1; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } float func4(float x, float y) { @@ -146,7 +146,7 @@ float func4(float x, float y) { return y / x; } -//CHECK: void func4_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func4_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: bool _cond0; //CHECK-NEXT: float _t0; //CHECK-NEXT: float _t1; @@ -166,20 +166,20 @@ float func4(float x, float y) { //CHECK-NEXT: *_d_x += _r0; //CHECK-NEXT: } //CHECK-NEXT: if (_cond0) { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t0; //CHECK-NEXT: float _r_d0 = *_d_x; //CHECK-NEXT: } else { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t1; //CHECK-NEXT: float _r_d1 = *_d_x; //CHECK-NEXT: *_d_x -= _r_d1; //CHECK-NEXT: *_d_x += _r_d1 * x; //CHECK-NEXT: *_d_x += x * _r_d1; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } int main() { diff --git a/test/ErrorEstimation/LoopsAndArrays.C b/test/ErrorEstimation/LoopsAndArrays.C index 2ec40f3a7..21d169580 100644 --- a/test/ErrorEstimation/LoopsAndArrays.C +++ b/test/ErrorEstimation/LoopsAndArrays.C @@ -14,7 +14,7 @@ float func(float* p, int n) { return sum; } -//CHECK: void func_grad_0(float *p, int n, float *_d_p, double &_final_error) { +//CHECK: void func_grad_0(float *p, int n, float *_d_p, double *_final_error) { //CHECK-NEXT: float _d_sum = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; //CHECK-NEXT: int i = 0; @@ -33,17 +33,17 @@ float func(float* p, int n) { //CHECK-NEXT: for (; _t0; _t0--) { //CHECK-NEXT: i--; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: sum = clad::pop(_t1); //CHECK-NEXT: float _r_d0 = _d_sum; //CHECK-NEXT: _d_p[i] += _r_d0; //CHECK-NEXT: p_size = std::max(p_size, i); //CHECK-NEXT: } //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: int i0 = 0; //CHECK-NEXT: for (; i0 <= p_size; i0++) -//CHECK-NEXT: _final_error += std::abs(_d_p[i0] * p[i0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_p[i0] * p[i0] * {{.+}}); //CHECK-NEXT: } @@ -56,7 +56,7 @@ float func2(float x) { return z; } -//CHECK: void func2_grad(float x, float *_d_x, double &_final_error) { +//CHECK: void func2_grad(float x, float *_d_x, double *_final_error) { //CHECK-NEXT: float _d_z = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; //CHECK-NEXT: int i = 0; @@ -78,7 +78,7 @@ float func2(float x) { //CHECK-NEXT: for (; _t0; _t0--) { //CHECK-NEXT: i--; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_z * z * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_z * z * {{.+}}); //CHECK-NEXT: z = clad::pop(_t2); //CHECK-NEXT: float _r_d0 = _d_z; //CHECK-NEXT: _d_z -= _r_d0; @@ -86,14 +86,14 @@ float func2(float x) { //CHECK-NEXT: _d_m += _r_d0; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_m * m * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_m * m * {{.+}}); //CHECK-NEXT: *_d_x += _d_m * x; //CHECK-NEXT: *_d_x += x * _d_m; //CHECK-NEXT: _d_m = 0; //CHECK-NEXT: m = clad::pop(_t1); //CHECK-NEXT: } //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: } float func3(float x, float y) { @@ -104,7 +104,7 @@ float func3(float x, float y) { return arr[2]; } -//CHECK: void func3_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func3_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: double _d_arr[3] = {0}; //CHECK-NEXT: double _t0; //CHECK-NEXT: double _t1; @@ -120,7 +120,7 @@ float func3(float x, float y) { //CHECK-NEXT: _label0: //CHECK-NEXT: _d_arr[2] += 1; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_arr[2] * arr[2] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_arr[2] * arr[2] * {{.+}}); //CHECK-NEXT: arr[2] = _t2; //CHECK-NEXT: double _r_d2 = _d_arr[2]; //CHECK-NEXT: _d_arr[2] -= _r_d2; @@ -128,7 +128,7 @@ float func3(float x, float y) { //CHECK-NEXT: _d_arr[1] += _r_d2; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_arr[1] * arr[1] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_arr[1] * arr[1] * {{.+}}); //CHECK-NEXT: arr[1] = _t1; //CHECK-NEXT: double _r_d1 = _d_arr[1]; //CHECK-NEXT: _d_arr[1] -= _r_d1; @@ -136,15 +136,15 @@ float func3(float x, float y) { //CHECK-NEXT: *_d_x += x * _r_d1; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_arr[0] * arr[0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_arr[0] * arr[0] * {{.+}}); //CHECK-NEXT: arr[0] = _t0; //CHECK-NEXT: double _r_d0 = _d_arr[0]; //CHECK-NEXT: _d_arr[0] -= _r_d0; //CHECK-NEXT: *_d_x += _r_d0; //CHECK-NEXT: *_d_y += _r_d0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } float func4(float x[10], float y[10]) { @@ -156,7 +156,7 @@ float func4(float x[10], float y[10]) { return sum; } -//CHECK: void func4_grad(float x[10], float y[10], float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func4_grad(float x[10], float y[10], float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _d_sum = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; //CHECK-NEXT: int i = 0; @@ -179,14 +179,14 @@ float func4(float x[10], float y[10]) { //CHECK-NEXT: for (; _t0; _t0--) { //CHECK-NEXT: i--; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: sum = clad::pop(_t2); //CHECK-NEXT: float _r_d1 = _d_sum; //CHECK-NEXT: _d_x[i] += _r_d1; //CHECK-NEXT: x_size = std::max(x_size, i); //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_x[i] * x[i] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_x[i] * x[i] * {{.+}}); //CHECK-NEXT: x[i] = clad::pop(_t1); //CHECK-NEXT: float _r_d0 = _d_x[i]; //CHECK-NEXT: _d_y[i] += _r_d0; @@ -194,13 +194,13 @@ float func4(float x[10], float y[10]) { //CHECK-NEXT: x_size = std::max(x_size, i); //CHECK-NEXT: } //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: int i0 = 0; //CHECK-NEXT: for (; i0 <= x_size; i0++) -//CHECK-NEXT: _final_error += std::abs(_d_x[i0] * x[i0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_x[i0] * x[i0] * {{.+}}); //CHECK-NEXT: i0 = 0; //CHECK-NEXT: for (; i0 <= y_size; i0++) -//CHECK-NEXT: _final_error += std::abs(_d_y[i0] * y[i0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_y[i0] * y[i0] * {{.+}}); //CHECK-NEXT: } @@ -211,7 +211,7 @@ double func5(double* x, double* y, double* output) { return output[0] + output[1] + output[2]; } -//CHECK: void func5_grad(double *x, double *y, double *output, double *_d_x, double *_d_y, double *_d_output, double &_final_error) { +//CHECK: void func5_grad(double *x, double *y, double *output, double *_d_x, double *_d_y, double *_d_output, double *_final_error) { //CHECK-NEXT: unsigned {{int|long}} output_size = 0; //CHECK-NEXT: double _t0; //CHECK-NEXT: unsigned {{int|long}} x_size = 0; @@ -237,7 +237,7 @@ double func5(double* x, double* y, double* output) { //CHECK-NEXT: output_size = std::max(output_size, 2); //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_output[2] * output[2] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_output[2] * output[2] * {{.+}}); //CHECK-NEXT: output[2] = _t2; //CHECK-NEXT: double _r_d2 = _d_output[2]; //CHECK-NEXT: _d_output[2] -= _r_d2; @@ -252,7 +252,7 @@ double func5(double* x, double* y, double* output) { //CHECK-NEXT: output_size = std::max(output_size, 2); //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_output[1] * output[1] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_output[1] * output[1] * {{.+}}); //CHECK-NEXT: output[1] = _t1; //CHECK-NEXT: double _r_d1 = _d_output[1]; //CHECK-NEXT: _d_output[1] -= _r_d1; @@ -267,7 +267,7 @@ double func5(double* x, double* y, double* output) { //CHECK-NEXT: output_size = std::max(output_size, 1); //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_output[0] * output[0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_output[0] * output[0] * {{.+}}); //CHECK-NEXT: output[0] = _t0; //CHECK-NEXT: double _r_d0 = _d_output[0]; //CHECK-NEXT: _d_output[0] -= _r_d0; @@ -283,14 +283,14 @@ double func5(double* x, double* y, double* output) { //CHECK-NEXT: } //CHECK-NEXT: int i = 0; //CHECK-NEXT: for (; i <= x_size; i++) -//CHECK-NEXT: _final_error += std::abs(_d_x[i] * x[i] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_x[i] * x[i] * {{.+}}); //CHECK-NEXT: i = 0; //CHECK-NEXT: for (; i <= y_size; i++) -//CHECK-NEXT: _final_error += std::abs(_d_y[i] * y[i] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_y[i] * y[i] * {{.+}}); //CHECK-NEXT: i = 0; //CHECK-NEXT: for (; i <= output_size; i++) -//CHECK-NEXT: _final_error += std::abs(_d_output[i] * output[i] * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_output[i] * output[i] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } int main() { diff --git a/test/ErrorEstimation/LoopsAndArraysExec.C b/test/ErrorEstimation/LoopsAndArraysExec.C index ed6c5a416..ca5613c69 100644 --- a/test/ErrorEstimation/LoopsAndArraysExec.C +++ b/test/ErrorEstimation/LoopsAndArraysExec.C @@ -15,7 +15,7 @@ double runningSum(float* f, int n) { return sum; } -//CHECK: void runningSum_grad_0(float *f, int n, float *_d_f, double &_final_error) { +//CHECK: void runningSum_grad_0(float *f, int n, float *_d_f, double *_final_error) { //CHECK-NEXT: double _d_sum = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; //CHECK-NEXT: int i = 0; @@ -34,7 +34,7 @@ double runningSum(float* f, int n) { //CHECK-NEXT: for (; _t0; _t0--) { //CHECK-NEXT: i--; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: sum = clad::pop(_t1); //CHECK-NEXT: double _r_d0 = _d_sum; //CHECK-NEXT: _d_f[i] += _r_d0; @@ -43,10 +43,10 @@ double runningSum(float* f, int n) { //CHECK-NEXT: f_size = std::max(f_size, i - 1); //CHECK-NEXT: } //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: int i0 = 0; //CHECK-NEXT: for (; i0 <= f_size; i0++) -//CHECK-NEXT: _final_error += std::abs(_d_f[i0] * f[i0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_f[i0] * f[i0] * {{.+}}); //CHECK-NEXT: } double mulSum(float* a, float* b, int n) { @@ -58,7 +58,7 @@ double mulSum(float* a, float* b, int n) { return sum; } -//CHECK: void mulSum_grad_0_1(float *a, float *b, int n, float *_d_a, float *_d_b, double &_final_error) { +//CHECK: void mulSum_grad_0_1(float *a, float *b, int n, float *_d_a, float *_d_b, double *_final_error) { //CHECK-NEXT: double _d_sum = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; //CHECK-NEXT: int i = 0; @@ -87,7 +87,7 @@ double mulSum(float* a, float* b, int n) { //CHECK-NEXT: { //CHECK-NEXT: for (; clad::back(_t1); clad::back(_t1)--) { //CHECK-NEXT: j--; -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: sum = clad::pop(_t3); //CHECK-NEXT: double _r_d0 = _d_sum; //CHECK-NEXT: _d_a[i] += _r_d0 * b[j]; @@ -99,13 +99,13 @@ double mulSum(float* a, float* b, int n) { //CHECK-NEXT: clad::pop(_t1); //CHECK-NEXT: } //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: int i0 = 0; //CHECK-NEXT: for (; i0 <= a_size; i0++) -//CHECK-NEXT: _final_error += std::abs(_d_a[i0] * a[i0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_a[i0] * a[i0] * {{.+}}); //CHECK-NEXT: i0 = 0; //CHECK-NEXT: for (; i0 <= b_size; i0++) -//CHECK-NEXT: _final_error += std::abs(_d_b[i0] * b[i0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_b[i0] * b[i0] * {{.+}}); //CHECK-NEXT: } double divSum(float* a, float* b, int n) { @@ -116,7 +116,7 @@ double divSum(float* a, float* b, int n) { return sum; } -//CHECK: void divSum_grad_0_1(float *a, float *b, int n, float *_d_a, float *_d_b, double &_final_error) { +//CHECK: void divSum_grad_0_1(float *a, float *b, int n, float *_d_a, float *_d_b, double *_final_error) { //CHECK-NEXT: double _d_sum = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; //CHECK-NEXT: int i = 0; @@ -136,7 +136,7 @@ double divSum(float* a, float* b, int n) { //CHECK-NEXT: for (; _t0; _t0--) { //CHECK-NEXT: i--; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: sum = clad::pop(_t1); //CHECK-NEXT: double _r_d0 = _d_sum; //CHECK-NEXT: b_size = std::max(b_size, i); @@ -147,13 +147,13 @@ double divSum(float* a, float* b, int n) { //CHECK-NEXT: b_size = std::max(b_size, i); //CHECK-NEXT: } //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: int i0 = 0; //CHECK-NEXT: for (; i0 <= a_size; i0++) -//CHECK-NEXT: _final_error += std::abs(_d_a[i0] * a[i0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_a[i0] * a[i0] * {{.+}}); //CHECK-NEXT: i0 = 0; //CHECK-NEXT: for (; i0 <= b_size; i0++) -//CHECK-NEXT: _final_error += std::abs(_d_b[i0] * b[i0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_b[i0] * b[i0] * {{.+}}); //CHECK-NEXT: } int main() { @@ -161,7 +161,7 @@ int main() { float arrf[3] = {0.456, 0.77, 0.95}; double finalError = 0; float darr[3] = {0, 0, 0}; - df.execute(arrf, 3, darr, finalError); + df.execute(arrf, 3, darr, &finalError); printf("Result (RS) = {%.2f, %.2f, %.2f} error = %.5f\n", darr[0], darr[1], darr[2], finalError); // CHECK-EXEC: Result (RS) = {1.00, 2.00, 1.00} error = 0.00000 @@ -169,7 +169,7 @@ int main() { darr[0] = darr[1] = darr[2] = 0; float darr2[3] = {0, 0, 0}; auto df2 = clad::estimate_error(mulSum); - df2.execute(arrf, arrf, 3, darr, darr2, finalError); + df2.execute(arrf, arrf, 3, darr, darr2, &finalError); printf("Result (MS) = {%.2f, %.2f, %.2f}, {%.2f, %.2f, %.2f} error = %.5f\n", darr[0], darr[1], darr[2], darr2[0], darr2[1], darr2[2], finalError); // CHECK-EXEC: Result (MS) = {2.18, 2.18, 2.18}, {2.18, 2.18, 2.18} error = 0.00000 @@ -178,7 +178,7 @@ int main() { darr[0] = darr[1] = darr[2] = 0; darr2[0] = darr2[1] = darr2[2] = 0; auto df3 = clad::estimate_error(divSum); - df3.execute(arrf, arrf, 3, darr, darr2, finalError); + df3.execute(arrf, arrf, 3, darr, darr2, &finalError); printf("Result (DS) = {%.2f, %.2f, %.2f}, {%.2f, %.2f, %.2f} error = %.5f\n", darr[0], darr[1], darr[2], darr2[0], darr2[1], darr2[2], finalError); // CHECK-EXEC: Result (DS) = {2.19, 1.30, 1.05}, {-2.19, -1.30, -1.05} error = 0.00000 diff --git a/test/Misc/RunDemos.C b/test/Misc/RunDemos.C index 7437d7872..5320533c1 100644 --- a/test/Misc/RunDemos.C +++ b/test/Misc/RunDemos.C @@ -106,7 +106,7 @@ // RUN: %cladclang %S/../../demos/ErrorEstimation/FloatSum.cpp -I%S/../../include 2>&1 | FileCheck -check-prefix CHECK_FLOAT_SUM %s //CHECK_FLOAT_SUM-NOT: {{.*error|warning|note:.*}} -//CHECK_FLOAT_SUM: void vanillaSum_grad_0(float x, unsigned int n, float *_d_x, double &_final_error) { +//CHECK_FLOAT_SUM: void vanillaSum_grad_0(float x, unsigned int n, float *_d_x, double *_final_error) { //CHECK_FLOAT_SUM: float _d_sum = 0; //CHECK_FLOAT_SUM: unsigned {{int|long}} _t0; //CHECK_FLOAT_SUM: unsigned int i = 0; @@ -124,7 +124,7 @@ //CHECK_FLOAT_SUM: for (; _t0; _t0--) { //CHECK_FLOAT_SUM: i--; //CHECK_FLOAT_SUM: { -//CHECK_FLOAT_SUM: _final_error += std::abs(_d_sum * sum * 1.1920928955078125E-7); +//CHECK_FLOAT_SUM: *_final_error += std::abs(_d_sum * sum * 1.1920928955078125E-7); //CHECK_FLOAT_SUM: sum = clad::pop(_t1); //CHECK_FLOAT_SUM: float _r_d0 = _d_sum; //CHECK_FLOAT_SUM: _d_sum -= _r_d0; @@ -132,8 +132,8 @@ //CHECK_FLOAT_SUM: *_d_x += _r_d0; //CHECK_FLOAT_SUM: } //CHECK_FLOAT_SUM: } -//CHECK_FLOAT_SUM: _final_error += std::abs(_d_sum * sum * 1.1920928955078125E-7); -//CHECK_FLOAT_SUM: _final_error += std::abs(*_d_x * x * 1.1920928955078125E-7); +//CHECK_FLOAT_SUM: *_final_error += std::abs(_d_sum * sum * 1.1920928955078125E-7); +//CHECK_FLOAT_SUM: *_final_error += std::abs(*_d_x * x * 1.1920928955078125E-7); //CHECK_FLOAT_SUM: } //-----------------------------------------------------------------------------/ @@ -149,7 +149,7 @@ // RUN: ./CustomModelTest.out | FileCheck -check-prefix CHECK_CUSTOM_MODEL_EXEC %s // CHECK_CUSTOM_MODEL_EXEC-NOT:{{.*error|warning|note:.*}} // CHECK_CUSTOM_MODEL_EXEC: The code is: -// CHECK_CUSTOM_MODEL_EXEC-NEXT: void func_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +// CHECK_CUSTOM_MODEL_EXEC-NEXT: void func_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { // CHECK_CUSTOM_MODEL_EXEC-NEXT: float _d_z = 0; // CHECK_CUSTOM_MODEL_EXEC-NEXT: float _t0; // CHECK_CUSTOM_MODEL_EXEC-NEXT: float z; @@ -159,15 +159,15 @@ // CHECK_CUSTOM_MODEL_EXEC-NEXT: _label0: // CHECK_CUSTOM_MODEL_EXEC-NEXT: _d_z += 1; // CHECK_CUSTOM_MODEL_EXEC-NEXT: { -// CHECK_CUSTOM_MODEL_EXEC-NEXT: _final_error += _d_z * z; +// CHECK_CUSTOM_MODEL_EXEC-NEXT: *_final_error += _d_z * z; // CHECK_CUSTOM_MODEL_EXEC-NEXT: z = _t0; // CHECK_CUSTOM_MODEL_EXEC-NEXT: float _r_d0 = _d_z; // CHECK_CUSTOM_MODEL_EXEC-NEXT: _d_z -= _r_d0; // CHECK_CUSTOM_MODEL_EXEC-NEXT: *_d_x += _r_d0; // CHECK_CUSTOM_MODEL_EXEC-NEXT: *_d_y += _r_d0; // CHECK_CUSTOM_MODEL_EXEC-NEXT: } -// CHECK_CUSTOM_MODEL_EXEC-NEXT: _final_error += *_d_x * x; -// CHECK_CUSTOM_MODEL_EXEC-NEXT: _final_error += *_d_y * y; +// CHECK_CUSTOM_MODEL_EXEC-NEXT: *_final_error += *_d_x * x; +// CHECK_CUSTOM_MODEL_EXEC-NEXT: *_final_error += *_d_y * y; // CHECK_CUSTOM_MODEL_EXEC-NEXT: } //-----------------------------------------------------------------------------/ @@ -183,7 +183,7 @@ // RUN: ./PrintModelTest.out | FileCheck -check-prefix CHECK_PRINT_MODEL_EXEC %s // CHECK_PRINT_MODEL_EXEC-NOT:{{.*error|warning|note:.*}} // CHECK_PRINT_MODEL_EXEC: The code is: -// CHECK_PRINT_MODEL_EXEC-NEXT: void func_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +// CHECK_PRINT_MODEL_EXEC-NEXT: void func_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { // CHECK_PRINT_MODEL_EXEC-NEXT: float _d_z = 0; // CHECK_PRINT_MODEL_EXEC-NEXT: float _t0; // CHECK_PRINT_MODEL_EXEC-NEXT: float z; @@ -193,15 +193,15 @@ // CHECK_PRINT_MODEL_EXEC-NEXT: _label0: // CHECK_PRINT_MODEL_EXEC-NEXT: _d_z += 1; // CHECK_PRINT_MODEL_EXEC-NEXT: { -// CHECK_PRINT_MODEL_EXEC-NEXT: _final_error += clad::getErrorVal(_d_z, z, "z"); +// CHECK_PRINT_MODEL_EXEC-NEXT: *_final_error += clad::getErrorVal(_d_z, z, "z"); // CHECK_PRINT_MODEL_EXEC-NEXT: z = _t0; // CHECK_PRINT_MODEL_EXEC-NEXT: float _r_d0 = _d_z; // CHECK_PRINT_MODEL_EXEC-NEXT: _d_z -= _r_d0; // CHECK_PRINT_MODEL_EXEC-NEXT: *_d_x += _r_d0; // CHECK_PRINT_MODEL_EXEC-NEXT: *_d_y += _r_d0; // CHECK_PRINT_MODEL_EXEC-NEXT: } -// CHECK_PRINT_MODEL_EXEC-NEXT: _final_error += clad::getErrorVal(*_d_x, x, "x"); -// CHECK_PRINT_MODEL_EXEC-NEXT: _final_error += clad::getErrorVal(*_d_y, y, "y"); +// CHECK_PRINT_MODEL_EXEC-NEXT: *_final_error += clad::getErrorVal(*_d_x, x, "x"); +// CHECK_PRINT_MODEL_EXEC-NEXT: *_final_error += clad::getErrorVal(*_d_y, y, "y"); // CHECK_PRINT_MODEL_EXEC-NEXT: } // CHECK_PRINT_MODEL_EXEC: Error in z : {{.+}} // CHECK_PRINT_MODEL_EXEC-NEXT: Error in x : {{.+}}