Skip to content

Commit

Permalink
add a fast path when left/right record dim is the same in virtual rec…
Browse files Browse the repository at this point in the history
…ord operators
  • Loading branch information
bernhardmgruber committed May 17, 2021
1 parent 5f363ad commit 2c89742
Showing 1 changed file with 58 additions and 34 deletions.
92 changes: 58 additions & 34 deletions include/llama/VirtualRecord.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,36 @@ namespace llama
const VirtualRecord<RightView, RightBoundRecordDim, RightOwnView>& right) -> LeftRecord&
{
using RightRecord = VirtualRecord<RightView, RightBoundRecordDim, RightOwnView>;
forEachLeaf<typename LeftRecord::AccessibleRecordDim>(
[&](auto leftCoord)
{
using LeftInnerCoord = decltype(leftCoord);
forEachLeaf<typename RightRecord::AccessibleRecordDim>(
[&](auto rightCoord)
{
using RightInnerCoord = decltype(rightCoord);
if constexpr (hasSameTags<
typename LeftRecord::AccessibleRecordDim,
LeftInnerCoord,
typename RightRecord::AccessibleRecordDim,
RightInnerCoord>)
// if the record dimension left and right is the same, a single loop is enough and no tag check is needed.
// this safes a lot of compilation time.
if constexpr (std::is_same_v<
typename LeftRecord::AccessibleRecordDim,
typename RightRecord::AccessibleRecordDim>)
{
forEachLeaf<typename LeftRecord::AccessibleRecordDim>([&](auto coord)
{ Functor{}(left(coord), right(coord)); });
}
else
{
forEachLeaf<typename LeftRecord::AccessibleRecordDim>(
[&](auto leftCoord)
{
using LeftInnerCoord = decltype(leftCoord);
forEachLeaf<typename RightRecord::AccessibleRecordDim>(
[&](auto rightCoord)
{
Functor{}(left(leftCoord), right(rightCoord));
}
});
});
using RightInnerCoord = decltype(rightCoord);
if constexpr (hasSameTags<
typename LeftRecord::AccessibleRecordDim,
LeftInnerCoord,
typename RightRecord::AccessibleRecordDim,
RightInnerCoord>)
{
Functor{}(left(leftCoord), right(rightCoord));
}
});
});
}
return left;
}

Expand All @@ -86,24 +98,36 @@ namespace llama
{
using RightRecord = VirtualRecord<RightView, RightBoundRecordDim, RightOwnView>;
bool result = true;
forEachLeaf<typename LeftRecord::AccessibleRecordDim>(
[&](auto leftCoord)
{
using LeftInnerCoord = decltype(leftCoord);
forEachLeaf<typename RightRecord::AccessibleRecordDim>(
[&](auto rightCoord)
{
using RightInnerCoord = decltype(rightCoord);
if constexpr (hasSameTags<
typename LeftRecord::AccessibleRecordDim,
LeftInnerCoord,
typename RightRecord::AccessibleRecordDim,
RightInnerCoord>)
// if the record dimension left and right is the same, a single loop is enough and no tag check is needed.
// this safes a lot of compilation time.
if constexpr (std::is_same_v<
typename LeftRecord::AccessibleRecordDim,
typename RightRecord::AccessibleRecordDim>)
{
forEachLeaf<typename LeftRecord::AccessibleRecordDim>(
[&](auto coord) { result &= Functor{}(left(coord), right(coord)); });
}
else
{
forEachLeaf<typename LeftRecord::AccessibleRecordDim>(
[&](auto leftCoord)
{
using LeftInnerCoord = decltype(leftCoord);
forEachLeaf<typename RightRecord::AccessibleRecordDim>(
[&](auto rightCoord)
{
result &= Functor{}(left(leftCoord), right(rightCoord));
}
});
});
using RightInnerCoord = decltype(rightCoord);
if constexpr (hasSameTags<
typename LeftRecord::AccessibleRecordDim,
LeftInnerCoord,
typename RightRecord::AccessibleRecordDim,
RightInnerCoord>)
{
result &= Functor{}(left(leftCoord), right(rightCoord));
}
});
});
}
return result;
}

Expand Down

0 comments on commit 2c89742

Please sign in to comment.