almost remove index_info dependency -> performance lack down to factor 1.15

This commit is contained in:
Christian Zimmermann 2018-03-02 16:37:11 +01:00
parent 219a267995
commit b045b2d7e1
7 changed files with 109 additions and 28 deletions

View file

@ -117,7 +117,7 @@ namespace MultiArrayTools
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
T* mDataPtr;
IndexType mIndex;
IndexInfo mIInfo;
//IndexInfo mIInfo;
};
@ -152,7 +152,7 @@ namespace MultiArrayTools
const T* mDataPtr;
//std::shared_ptr<IndexType> mIndex;
IndexType mIndex;
IndexInfo mIInfo;
//IndexInfo mIInfo;
};
template <typename T, class... Ranges>
@ -187,7 +187,7 @@ namespace MultiArrayTools
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
T* mDataPtr;
IndexType mIndex;
IndexInfo mIInfo;
//IndexInfo mIInfo;
};
template <class Op>
@ -383,7 +383,7 @@ namespace MultiArrayTools
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
IndexType& index) :
mSecond(second), mArrayRef(ma), mDataPtr(mArrayRef.data()),
mIndex(index), mIInfo(mIndex)
mIndex(index)
{
performAssignment(0);
}
@ -394,7 +394,7 @@ namespace MultiArrayTools
IndexType& index,
const IndexInfo* blockIndex) :
mSecond(second), mArrayRef(ma), mDataPtr(mArrayRef.data()),
mIndex(index), mIInfo(mIndex)
mIndex(index)
{
performAssignment(0);
}
@ -424,8 +424,8 @@ namespace MultiArrayTools
ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
mArrayRef(ma), mDataPtr(mArrayRef.data()),
//mIndex( mkIndex(ma,indices...) ), mIInfo(*mIndex)
mIndex( ma.begin() ), mIInfo(mIndex)
//mIndex( mkIndex(ma,indices...) ), mIInfo(mIndex)
mIndex( ma.begin() )
{
mIndex(indices...);
}
@ -440,7 +440,7 @@ namespace MultiArrayTools
template <typename T, class... Ranges>
MExt<void> ConstOperationRoot<T,Ranges...>::rootSteps(std::intptr_t iPtrNum) const
{
return MExt<void>(getStepSize( mIndex.info(), iPtrNum ));
return MExt<void>(getStepSize( mIndex, iPtrNum ));
//return MExt<void>(getStepSize( getRootIndices( mIndex->info() ), iPtrNum ));
}
@ -461,7 +461,7 @@ namespace MultiArrayTools
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
mArrayRef(ma), mDataPtr(mArrayRef.data()),
mIndex( ma.begin() ), mIInfo(mIndex)
mIndex( ma.begin() )
{
mIndex(indices...);
}
@ -483,8 +483,8 @@ namespace MultiArrayTools
template <typename T, class... Ranges>
MExt<void> OperationRoot<T,Ranges...>::rootSteps(std::intptr_t iPtrNum) const
{
return MExt<void>(getStepSize( mIndex.info(), iPtrNum ));
//return MExt<void>(getStepSize( getRootIndices( mIndex->info() ), iPtrNum ));
return MExt<void>(getStepSize( mIndex, iPtrNum ));
//return MExt<void>(getStepSize( mIndex.info(), iPtrNum ));
}
template <typename T, class... Ranges>

View file

@ -28,9 +28,9 @@ namespace MultiArrayTools
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
typedef ContainerRange<T,typename Indices::RangeType...> RangeType;
static IndexType sType() { return IndexType::CONT; }
static size_t sDim() { return sizeof...(Indices); }
static size_t totalDim() { return mkTotalDim<Indices...>(); }
static constexpr IndexType sType() { return IndexType::CONT; }
static constexpr size_t sDim() { return sizeof...(Indices); }
static constexpr size_t totalDim() { return mkTotalDim<Indices...>(); }
private:

View file

@ -32,7 +32,7 @@ namespace MultiArrayTools
~IndexInterface() = default;
IndexType type() const { return THIS().type(); }
constexpr IndexType type() const { return THIS().type(); }
I& operator=(size_t pos) { return THIS() = pos; }
I& operator++() { return THIS()++; }
@ -78,11 +78,13 @@ namespace MultiArrayTools
auto iforh(const Expr ex) const -> decltype(THIS().template iforh<Expr>(ex))
{ return THIS().template iforh<Expr>(ex); }
std::intptr_t ptrNum() const;
private:
friend I;
IndexInterface() { mId = indexId(); }
IndexInterface();
IndexInterface(const IndexInterface& in) = default;
IndexInterface& operator=(const IndexInterface& in) = default;
IndexInterface(IndexInterface&& in) = default;
@ -91,11 +93,13 @@ namespace MultiArrayTools
IndexInterface(const std::shared_ptr<RangeBase>& range, size_t pos);
std::shared_ptr<RangeBase> mRangePtr;
size_t mPos;
size_t mPos = 0;
size_t mId;
size_t mMax;
size_t mMax = 0;
std::intptr_t mPtrNum;
};
}
/* ========================= *
@ -108,6 +112,12 @@ namespace MultiArrayTools
* IndexInterface *
**********************/
template <class I, typename MetaType>
IndexInterface<I,MetaType>::IndexInterface() : mId(indexId())
{
mPtrNum = reinterpret_cast<std::intptr_t>(this);
}
template <class I, typename MetaType>
IndexInterface<I,MetaType>::IndexInterface(const std::shared_ptr<RangeBase>& range,
size_t pos) : mRangePtr(range),
@ -115,6 +125,7 @@ namespace MultiArrayTools
mMax(mRangePtr->size())
{
mId = indexId();
mPtrNum = reinterpret_cast<std::intptr_t>(this);
}
template <class I, typename MetaType>
@ -146,6 +157,12 @@ namespace MultiArrayTools
{
return pos();
}
template <class I, typename MetaType>
std::intptr_t IndexInterface<I,MetaType>::ptrNum() const
{
return mPtrNum;
}
}
#endif

View file

@ -77,6 +77,7 @@ namespace MultiArrayTools
std::vector<IndexInfo> getRootIndices(const IndexInfo& info);
/*
inline size_t getStepSize(const IndexInfo& ii, std::intptr_t j)
{
if(ii.type() == IndexType::SINGLE){
@ -91,12 +92,13 @@ namespace MultiArrayTools
const size_t tmp = getStepSize(itmp, j);
ss += tmp * sx;
sx *= max;
VCHECK(ss);
}
return ss;
}
}
size_t getStepSize(const std::vector<IndexInfo>& iv, std::intptr_t j);
*/
//size_t getStepSize(const std::vector<IndexInfo>& iv, std::intptr_t j);
} // end namespace MultiArrayTools
#endif

View file

@ -32,9 +32,9 @@ namespace MultiArrayTools
typedef std::tuple<typename Indices::MetaType...> MetaType;
typedef MultiRange<typename Indices::RangeType...> RangeType;
static IndexType sType() { return IndexType::MULTI; }
static size_t sDim() { return sizeof...(Indices); }
static size_t totalDim() { return mkTotalDim<Indices...>(); }
static constexpr IndexType sType() { return IndexType::MULTI; }
static constexpr size_t sDim() { return sizeof...(Indices); }
static constexpr size_t totalDim() { return mkTotalDim<Indices...>(); }
private:

View file

@ -36,6 +36,9 @@ namespace MultiArrayHelper
static constexpr size_t ISSTATIC = 1;
static constexpr size_t SIZE = 1;
};
template <class Index>
inline size_t getStepSize(const Index& ii, std::intptr_t j);
template <size_t N>
struct RPackNum
@ -249,6 +252,19 @@ namespace MultiArrayHelper
->iforh( RPackNum<N-1>::mkForh(ipack, exs) );
}
template <class Index>
static inline void getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx)
{
//constexpr size_t DIM = Index::sDim();
const auto& ni = ii.template get<N>();
const size_t max = ni.max();
const size_t tmp = getStepSize(ni, j);
//VCHECK(tmp);
ss += tmp * sx;
//VCHECK(ss);
sx *= max;
RPackNum<N-1>::getStepSizeX(ii, j, ss, sx);
}
};
@ -424,8 +440,53 @@ namespace MultiArrayHelper
return std::get<std::tuple_size<IndexPack>::value-1>(ipack)->iforh(exs);
}
template <class Index>
static inline void getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx)
{
//constexpr size_t DIM = Index::sDim();
const auto& ni = ii.template get<0>();
const size_t max = ni.max();
const size_t tmp = getStepSize(ni, j);
//VCHECK(tmp);
ss += tmp * sx;
//VCHECK(ss);
sx *= max;
}
};
template <IndexType IT>
struct SSG
{
template <class Index>
static inline size_t getStepSize(const Index& ii, std::intptr_t j)
{
size_t ss = 0;
size_t sx = 1;
constexpr size_t DIM = Index::sDim();
RPackNum<DIM-1>::getStepSizeX(ii, j, ss, sx);
return ss;
}
};
template <>
struct SSG<IndexType::SINGLE>
{
template <class Index>
static inline size_t getStepSize(const Index& ii, std::intptr_t j)
{
//VCHECK(ii.ptrNum());
//VCHECK(j);
return ii.ptrNum() == j ? 1 : 0;
}
};
template <class Index>
inline size_t getStepSize(const Index& ii, std::intptr_t j)
{
constexpr IndexType IT = Index::sType();
return SSG<IT>::getStepSize(ii, j);
}
} // end namespace MultiArrayHelper

View file

@ -31,9 +31,10 @@ namespace MultiArrayTools
SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range);
static IndexType sType() { return IndexType::SINGLE; }
static size_t totalDim() { return 1; }
static constexpr IndexType sType() { return IndexType::SINGLE; }
static constexpr size_t totalDim() { return 1; }
static constexpr size_t sDim() { return 1; }
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
IndexType type() const;