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 13, 2022
1 parent c9200c8 commit aa8902d
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions include/llama/mapping/SoA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,28 @@ namespace llama::mapping
}
}

private:
LLAMA_FN_HOST_ACC_INLINE static constexpr auto computeSubArrayOffsets()
{
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 @@ -113,27 +135,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 aa8902d

Please sign in to comment.