From 64d10867dd251b4fca90a6eda0d526ef6c3b9d0e Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Mon, 18 Jan 2021 19:00:12 +0100 Subject: [PATCH] finish parts of auto-vectorization --- src/include/arith.h | 8 +- src/include/dynamic_operation.h | 7 ++ src/include/multi_array_operation.cc.h | 63 ++++++++----- src/include/multi_array_operation.h | 117 ++++++++++++++++++++----- src/include/type_operations.h | 31 ++++++- 5 files changed, 180 insertions(+), 46 deletions(-) diff --git a/src/include/arith.h b/src/include/arith.h index db34d75..e9339d8 100644 --- a/src/include/arith.h +++ b/src/include/arith.h @@ -48,7 +48,8 @@ namespace MultiArrayTools { static constexpr bool FISSTATIC = true; typedef T value_type; - + typedef F function; + template static auto mk(const Ops&... ops) -> Operation @@ -74,6 +75,11 @@ namespace MultiArrayTools { return a; } + + static inline T selfApply(T& a1, const T& a2) + { + return a1 = a2; + } }; template diff --git a/src/include/dynamic_operation.h b/src/include/dynamic_operation.h index 12c1936..3835019 100644 --- a/src/include/dynamic_operation.h +++ b/src/include/dynamic_operation.h @@ -17,6 +17,7 @@ namespace MultiArrayTools static constexpr size_t SIZE = 1; static constexpr bool CONT = true; + static constexpr bool VABLE = false; DynamicOperationBase() = default; DynamicOperationBase(const DynamicOperationBase& in) = default; @@ -125,6 +126,7 @@ namespace MultiArrayTools static constexpr size_t SIZE = 1; static constexpr bool CONT = true; + static constexpr bool VABLE = false; DynamicO() = default; DynamicO(const DynamicO& in) : mOp(in.mOp ? in.mOp->deepCopy() : nullptr) {} @@ -144,6 +146,11 @@ namespace MultiArrayTools template inline T get(const DExtTX& pos) const { return mOp->get(pos.reduce()); } + + template + inline auto vget(const DExtTX& pos) const + { return mOp->template vget(pos.reduce()); } + template inline DynamicO& set(const DExtTX& pos) { mOp->set(pos.reduce()); return *this; } inline DExtT rootSteps(std::intptr_t iPtrNum = 0) const { return mOp->rootSteps(iPtrNum); } diff --git a/src/include/multi_array_operation.cc.h b/src/include/multi_array_operation.cc.h index b9d0207..0f1fa41 100644 --- a/src/include/multi_array_operation.cc.h +++ b/src/include/multi_array_operation.cc.h @@ -555,55 +555,78 @@ namespace MultiArrayTools template template auto OperationRoot::assign(const OpClass& in) const - -> decltype(this->template asx(in)) + -> decltype(this->template asx>(in)) { - return this->template asx(in); + return this->template asx>(in); } template template auto OperationRoot::assignExpr(const OpClass& in) const - -> decltype(this->template asxExpr(in)) + -> decltype(this->template asxExpr>(in)) { - return this->template asxExpr(in); + return this->template asxExpr>(in); } template template auto OperationRoot::assign(const OpClass& in, const std::shared_ptr& i) const - -> decltype(this->template asx(in,i)) + -> decltype(this->template asx>(in,i)) { - return this->template asx(in,i); + return this->template asx>(in,i); } template template auto OperationRoot::plus(const OpClass& in) const - -> decltype(this->template asx(in)) + -> decltype(this->template asx>(in)) { - return this->template asx(in); + return this->template asx>(in); } template template auto OperationRoot::plus(const OpClass& in, const std::shared_ptr& i) const - -> decltype(this->template asx(in,i)) + -> decltype(this->template asx>(in,i)) { - return this->template asx(in,i); + return this->template asx>(in,i); } - + + template + struct VExec + { + template + static inline void exec(TarOp& th, const OpClass& in) + { + th.assign(in)(); + } + }; + + template <> + struct VExec + { + template + static inline void exec(TarOp& th, const OpClass& in) + { + CHECK; + typedef typename TarOp::value_type T; + auto x = th.template asx::type,T>>(in); + const size_t inum = x.vec(VType::MULT); + if(x.rootSteps(inum) == 1){ + CHECK; + x(); + } + else { + th.assign(in)(); + } + } + }; + template template OperationRoot& OperationRoot::operator=(const OpClass& in) { - auto x = this->template asx::type>>(in); - const size_t inum = x.vec(VType::MULT); - if(x.rootSteps(inum) == 1){ - x(); - } - else { - assign(in)(); - } + VExec::exec(*this,in); return *this; } @@ -896,7 +919,7 @@ namespace MultiArrayTools { typedef std::tuple OpTuple; return PackNum:: - template mkVOpExpr(mF, pos, mOps); // implement!!! + template mkVOpExpr>(mkVFuncPtr(mF), pos, mOps); // implement!!! } template diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index 53e284b..bc35d0e 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -204,12 +204,74 @@ namespace MultiArrayTools TARGET = 1 }; + template + struct VType + { + typedef T type; + static constexpr size_t MULT = sizeof(type)/sizeof(T); + }; + + template <> + struct VType + { + typedef v256 type; + static constexpr size_t MULT = sizeof(type)/sizeof(double); + }; + + template