From 782e8555cf2c5e7f5a4bac5f04f6e92010bdb73a Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sun, 30 Aug 2020 14:43:53 +0200 Subject: [PATCH] dynamic hybrid contraction works --- src/include/dynamic_operation.cc.h | 20 ++++++++++++++++--- src/include/dynamic_operation.h | 23 +++++++++++++++++----- src/tests/op4_unit_test.cc | 31 +++++++++++++++++++++++------- 3 files changed, 59 insertions(+), 15 deletions(-) diff --git a/src/include/dynamic_operation.cc.h b/src/include/dynamic_operation.cc.h index ffdf697..fcb579a 100644 --- a/src/include/dynamic_operation.cc.h +++ b/src/include/dynamic_operation.cc.h @@ -131,10 +131,24 @@ namespace MultiArrayTools std::array({1}), std::array({0})) {} + /* + DynamicOuterOp(const std::shared_ptr>>>& dyn, + const Operation& op, const std::shared_ptr&... inds ) + : mThreadId(omp_get_thread_num()), + //mDyn(dyn), + mOp(op), mIndices(inds...), + mMa(std::make_shared>(mkArray(inds->range()...))), + mProto(OperationRoot(*mMa,inds...)), + mL(std::make_tuple(*mProto.mOp,mOp), std::make_tuple(inds...), + std::make_tuple(mMa), std::make_tuple(mProto.mOp->assign( mOp, mkMIndex(inds...) )), + std::array({1}), std::array({0})) + {} + */ + template OpH> DynamicOuterOp::get(const DExtT& pos) const { - if(mPrev) mPrev.get(pos.expl()); + //if(mPrev) mPrev.get(pos.expl()); mL(0,pos.expl()); return mProto; // empty } @@ -164,7 +178,7 @@ namespace MultiArrayTools { return &mProto; } - + /* template template inline T TwoOp::get(const ET& pos) const @@ -173,7 +187,7 @@ namespace MultiArrayTools } - + */ template std::shared_ptr>>> DynamicOuterOp::deepCopy() const diff --git a/src/include/dynamic_operation.h b/src/include/dynamic_operation.h index b8f8a75..15bd07e 100644 --- a/src/include/dynamic_operation.h +++ b/src/include/dynamic_operation.h @@ -72,12 +72,12 @@ namespace MultiArrayTools { private: size_t mThreadId; + //std::shared_ptr>>> mDyn; Operation mOp; //OperationRoot mProto; std::tuple...> mIndices; std::shared_ptr> mMa; OpH> mProto; - std::shared_ptr>>> mPrev; typedef ILoop,Operation>, @@ -100,7 +100,10 @@ namespace MultiArrayTools DynamicOuterOp& operator=(DynamicOuterOp&& in); DynamicOuterOp(const Operation& op, const std::shared_ptr&... inds); - + /* + DynamicOuterOp(const std::shared_ptr>>>& dyn, + const Operation& op, const std::shared_ptr&... inds ); + */ virtual OpH> get(const DExtT& pos) const override final; virtual DynamicOperationBase>>& set(const DExtT& pos) override final; virtual DExtT rootSteps(std::intptr_t iPtrNum = 0) const override final; @@ -143,7 +146,7 @@ namespace MultiArrayTools inline DynamicExpression loop(const DynamicExpression& exp) const { return mOp->loop(exp); } inline const T* data() const { return mOp->data(); } }; - + /* template class TwoOp : public OperationTemplate> { @@ -162,7 +165,7 @@ namespace MultiArrayTools template inline T get(const ET& pos) const; }; - + */ template auto mkDynOutOp(const Operation& op, const std::shared_ptr&... inds) { @@ -171,7 +174,17 @@ namespace MultiArrayTools (DynamicOuterOp(op, inds...)); } - + /* + template + auto mkDynOutOp(const std::shared_ptr>>>& dyn, + const Operation& op, const std::shared_ptr&... inds) + { + return DynamicO>> + (DynamicOuterOp(dyn, op, inds...)); + } + */ // Build plan /* template diff --git a/src/tests/op4_unit_test.cc b/src/tests/op4_unit_test.cc index c674f0e..44a807e 100644 --- a/src/tests/op4_unit_test.cc +++ b/src/tests/op4_unit_test.cc @@ -71,9 +71,11 @@ namespace cr1 = createRangeE(5); auto cr2 = createRangeE(7); + //auto cr2 = createRangeE(2); auto cr3 = createRangeE(11); auto cr4 = createRangeE(3); auto cr5 = createRangeE(13); + //auto cr5 = createRangeE(1); dr1 = createRangeE(cr2,cr2,cr3,cr4); //dr1a = createRangeE(cr2,cr2,cr3); @@ -81,7 +83,7 @@ namespace dr3 = createRangeE(cr2,cr5); dr5 = createRangeE(cr5); dr6 = createRangeE(cr3,cr4); - dr6a = createRangeE(cr3); + dr6a = createRangeE(cr3,cr2,cr5); dr4 = createRangeE(cr2,cr3,cr4,cr4); dr4a = createRangeE(cr2,cr3); @@ -200,7 +202,7 @@ namespace (*di3)({imap["i2_1"],imap["i5_1"]}); (*di5)({imap["i5_1"]}); (*di6)({imap["i3_1"],imap["i4_1"]}); - (*di6a)({imap["i3_1"]}); + (*di6a)({imap["i3_1"],imap["i2_1"],imap["i5_1"]}); auto resx1 = res2; auto resx2 = res2; @@ -211,15 +213,28 @@ namespace resx2(i1,di6) += mkDynOp((ma1(i1,di1) * ma5(di5)).c(di3)); resx3(i1,di6) += mkDynOp((mkDynOp(ma1(i1,di1)) * mkDynOp(ma5(di5))).c(di3)); + auto xx = std::make_shared(resx4); + auto mi = mkMIndex(i1,di6a); auto op1 = ma1(i1,di1); auto op2 = ma5(di5); - auto dop1 = mkDynOutOp(op1 * op2, ci4_1); - auto op3 = *dop1.data()->mOp; - auto dop2 = mkDynOutOp( dop1.c(di3), op3.c(di3), ci4_1 ); auto opr = resx4(i1,di6); - //resx2(i1,di6) += mkDynOp((ma1(i1,di1) * ma5(di5)).c(di3)); + + auto loop = mkPILoop + ( [&opr,&op1,&op2,&xx,&di3,this](){ + auto dop1 = mkDynOutOp(op1 * op2, ci4_1); + auto op3 = *dop1.data()->mOp; + auto dop2 = mkDynOutOp( op3, ci4_1 ); + return mkGetExpr + (dop1,mkGetExpr + (dop2,mkILoop + (std::make_tuple(opr,*dop2.data()->mOp), std::make_tuple(ci4_1), + std::make_tuple(xx), + std::make_tuple(opr.plus( *dop2.data()->mOp, mkMIndex(ci4_1) )), + std::array({1}), std::array({0})))); } ); + + mi->pifor(1,loop)(); auto i2_1 = imap.at("i2_1"); auto i3_1 = imap.at("i3_1"); @@ -238,16 +253,18 @@ namespace vv += ma1.vdata()[j1] * ma5.vdata()[j2]; } } - + auto resv = xround(res2.vdata()[jr]); auto resx1v = xround(resx1.vdata()[jr]); auto resx2v = xround(resx2.vdata()[jr]); auto resx3v = xround(resx3.vdata()[jr]); + auto resx4v = xround(resx4.vdata()[jr]); auto x12 = xround(vv); EXPECT_EQ( resv, x12 ); EXPECT_EQ( resx1v, x12 ); EXPECT_EQ( resx2v, x12 ); EXPECT_EQ( resx3v, x12 ); + EXPECT_EQ( resx4v, x12 ); } } //std::cout << std::endl;