Skip to content

Commit

Permalink
Move SB SoA offset table computation into separate function
Browse files Browse the repository at this point in the history
This works around an MSVC bug.
  • Loading branch information
bernhardmgruber committed Dec 14, 2022
1 parent 3029318 commit e3c32eb
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions include/llama/mapping/SoA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,29 @@ namespace llama::mapping
}
}

private:
LLAMA_FN_HOST_ACC_INLINE static constexpr auto computeSubArrayOffsets()
{
using namespace boost::mp11;
using FRD = typename Flattener::FlatRecordDim;
constexpr auto staticFlatSize = LinearizeArrayDimsFunctor{}.size(TArrayExtents{});
constexpr auto subArrays = mp_size<FRD>::value;
Array<size_type, subArrays> r{};
// r[0] == 0, only compute the following offsets
mp_for_each<mp_iota_c<subArrays - 1>>(
[&](auto ic)
{
constexpr auto i = decltype(ic)::value;
r[i + 1] = r[i];
using ThisFieldType = mp_at_c<FRD, i>;
r[i + 1] += static_cast<size_type>(sizeof(ThisFieldType)) * staticFlatSize;
using NextFieldType = mp_at_c<FRD, i + 1>;
r[i + 1] = roundUpToMultiple(r[i + 1], static_cast<size_type>(alignof(NextFieldType)));
});
return r;
}

public:
template<std::size_t... RecordCoords>
LLAMA_FN_HOST_ACC_INLINE constexpr auto blobNrAndOffset(
typename Base::ArrayIndex ai,
Expand Down Expand Up @@ -128,27 +151,7 @@ namespace llama::mapping
if constexpr(TArrayExtents::rankStatic == TArrayExtents::rank)
{
// full array extents are known statically, we can precompute the sub array offsets
constexpr auto subArrayOffsets = []() constexpr
{
constexpr auto staticFlatSize = LinearizeArrayDimsFunctor{}.size(TArrayExtents{});
constexpr auto subArrays = mp_size<FRD>::value;
Array<size_type, subArrays> r{};
// r[0] == 0, only compute the following offsets
mp_for_each<mp_iota_c<subArrays - 1>>(
[&](auto ic)
{
constexpr auto i = decltype(ic)::value;
r[i + 1] = r[i];
using ThisFieldType = mp_at_c<FRD, i>;
r[i + 1] += static_cast<size_type>(sizeof(ThisFieldType)) * staticFlatSize;
using NextFieldType = mp_at_c<FRD, i + 1>;
r[i + 1]
= roundUpToMultiple(r[i + 1], static_cast<size_type>(alignof(NextFieldType)));
});
return r;
}
();

constexpr auto subArrayOffsets = computeSubArrayOffsets();
size_type offset = subArrayOffsets[flatFieldIndex];
offset += elementOffset;
return {0, offset};
Expand Down

0 comments on commit e3c32eb

Please sign in to comment.