Skip to content

Commit

Permalink
Workaround MSVC bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Dec 13, 2022
1 parent d0013f7 commit 78d38bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions include/llama/View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,19 +372,19 @@ namespace llama
/// Using a mapping, maps the given array index and record coordinate to a memory reference onto the given blobs.
/// \return Either an l-value reference if the record coord maps to a physical field or a proxy reference if mapped
/// to a computed field.
template<typename Mapping, std::size_t... Coords, typename Blobs>
template<typename Mapping, typename RecordCoord, typename Blobs>
LLAMA_FN_HOST_ACC_INLINE auto mapToMemory(
Mapping& mapping,
typename Mapping::ArrayIndex ai,
RecordCoord<Coords...> rc,
RecordCoord rc,
Blobs& blobs) -> decltype(auto)
{
if constexpr(llama::isComputed<Mapping, RecordCoord<Coords...>>)
if constexpr(llama::isComputed<Mapping, RecordCoord>)
return mapping.compute(ai, rc, blobs);
else
{
const auto [nr, offset] = mapping.blobNrAndOffset(ai, rc);
using Type = GetType<typename Mapping::RecordDim, RecordCoord<Coords...>>;
using Type = GetType<typename Mapping::RecordDim, RecordCoord>;
LLAMA_BEGIN_SUPPRESS_HOST_DEVICE_WARNING
return reinterpret_cast<CopyConst<std::remove_reference_t<decltype(blobs[nr][offset])>, Type>&>(
blobs[nr][offset]);
Expand Down
12 changes: 12 additions & 0 deletions include/llama/mapping/Bytesplit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,37 @@ namespace llama::mapping
// NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
LLAMA_FN_HOST_ACC_INLINE operator value_type() const
{
#ifdef _MSC_VER
// MSVC workaround. Without this, MSVC deduces the last template parameter of mapToMemory wrongly
BlobArray& blobs = this->blobs;
#endif

value_type v;
auto* p = reinterpret_cast<std::byte*>(&v);
boost::mp11::mp_for_each<boost::mp11::mp_iota_c<sizeof(value_type)>>(
[&](auto ic)
{
constexpr auto i = decltype(ic)::value;
auto&& ref = mapToMemory(inner, ai, Cat<RC, RecordCoord<i>>{}, blobs);

p[i] = ref;
});
return v;
}

LLAMA_FN_HOST_ACC_INLINE auto operator=(value_type v) -> Reference&
{
#ifdef _MSC_VER
// MSVC workaround. Without this, MSVC deduces the last template parameter of mapToMemory wrongly
BlobArray& blobs = this->blobs;
#endif

auto* p = reinterpret_cast<std::byte*>(&v);
boost::mp11::mp_for_each<boost::mp11::mp_iota_c<sizeof(value_type)>>(
[&](auto ic)
{
constexpr auto i = decltype(ic)::value;

auto&& ref = mapToMemory(inner, ai, Cat<RC, RecordCoord<i>>{}, blobs);
ref = p[i];
});
Expand Down

0 comments on commit 78d38bd

Please sign in to comment.