6 #include "../StructName.hpp"
16 template<
typename CountType>
29 template<
typename Value,
typename Ref,
typename Count>
34 template<
typename RefFwd>
36 : r(std::forward<RefFwd>(r))
39 static_assert(std::is_same_v<std::remove_reference_t<Ref>, std::remove_reference_t<RefFwd>>);
84 template<
typename Mapping,
typename TCountType = std::
size_t,
bool MyCodeHandlesProxyReferences = true>
88 using size_type =
typename Mapping::ArrayExtents::value_type;
100 for(
const auto& ac : *
this)
102 if constexpr(MyCodeHandlesProxyReferences)
104 total.reads += ac.reads;
105 total.writes += ac.writes;
108 total.memLocsComputed += ac.memLocsComputed;
125 forEachLeafCoord<RecordDim>(
130 if constexpr(MyCodeHandlesProxyReferences)
132 r += (*this)[i].reads * fieldSize;
133 w += (*this)[i].writes * fieldSize;
136 r += (*this)[i].memLocsComputed * fieldSize;
138 if constexpr(MyCodeHandlesProxyReferences)
145 inline static constexpr
auto blobCount = Mapping::blobCount + 1;
154 template<
typename... Args>
156 : Mapping(std::forward<Args>(innerArgs)...)
161 constexpr
auto blobSize(size_type blobIndex)
const -> size_type
163 if(blobIndex < size_type{Mapping::blobCount})
164 return inner().blobSize(blobIndex);
168 template<std::size_t... RecordCoords>
174 template<std::size_t... RecordCoords,
typename Blobs>
176 typename Mapping::ArrayExtents::Index ai,
178 Blobs& blobs)
const -> decltype(
auto)
181 !std::is_const_v<Blobs>,
182 "Cannot access (even just reading) data through FieldAccessCount from const blobs/view, since we need "
184 "the access counts");
187 decltype(
auto) ref =
mapToMemory(inner(), ai, rc, blobs);
188 if constexpr(MyCodeHandlesProxyReferences)
191 using Ref = decltype(ref);
202 template<
typename Blobs>
209 template<
typename Blobs>
215 template<
typename Blobs>
224 printFieldHitsDevice(hits);
226 printFieldHitsHost(hits);
231 static constexpr
auto columnWidth = 10;
232 static constexpr
auto sizeColumnWidth = 5;
234 void printFieldHitsHost(
const FieldHitsArray& hits)
const
236 if constexpr(MyCodeHandlesProxyReferences)
237 std::cout << std::left << std::setw(columnWidth) <<
"Field" <<
' ' << std::right
238 << std::setw(sizeColumnWidth) <<
"Size" << std::right << std::setw(columnWidth) <<
"Reads"
239 <<
' ' << std::right << std::setw(columnWidth) <<
"Writes" <<
'\n';
241 std::cout << std::left << std::setw(columnWidth) <<
"Field" <<
' ' << std::right
242 << std::setw(sizeColumnWidth) <<
"Size" << std::right << std::setw(columnWidth)
243 <<
"Mlocs cmp" <<
'\n';
244 forEachLeafCoord<RecordDim>(
249 if constexpr(MyCodeHandlesProxyReferences)
250 std::cout << std::left << std::setw(columnWidth) << prettyRecordCoord<RecordDim>(rc) <<
' '
251 << std::right << std::setw(sizeColumnWidth) << fieldSize << std::right
252 << std::setw(columnWidth) << hits[i].reads <<
' ' << std::right
253 << std::setw(columnWidth) << hits[i].writes <<
'\n';
255 std::cout << std::left << std::setw(columnWidth) << prettyRecordCoord<RecordDim>(rc) <<
' '
256 << std::right << std::setw(sizeColumnWidth) << fieldSize << std::right
257 << std::setw(columnWidth) << hits[i].memLocsComputed <<
'\n';
259 const auto total = hits.totalBytes();
260 if constexpr(MyCodeHandlesProxyReferences)
262 const auto [rsize, runit] =
prettySize(total.totalRead);
263 const auto [wsize, wunit] =
prettySize(total.totalWritten);
264 std::cout << std::left << std::setw(columnWidth) <<
"Total" <<
' ' << std::right
265 << std::setw(sizeColumnWidth) <<
' ' << std::right << std::setw(columnWidth) << rsize
266 << runit <<
' ' << std::right << std::setw(columnWidth - 2) << wsize << wunit <<
'\n';
271 std::cout << std::left << std::setw(columnWidth) <<
"Total" <<
' ' << std::right
272 << std::setw(sizeColumnWidth) <<
' ' << std::right << std::setw(columnWidth) << size << unit
275 std::cout << std::internal;
278 LLAMA_ACC void printFieldHitsDevice(
const FieldHitsArray& hits)
const
280 if constexpr(MyCodeHandlesProxyReferences)
297 printf(
"%*s %*s %*s\n", columnWidth,
"Field", sizeColumnWidth,
"Size", columnWidth,
"Mlocs cmp");
299 forEachLeafCoord<RecordDim>(
304 constexpr
auto fieldName = prettyRecordCoord<RecordDim>(rc);
305 char fieldNameZT[fieldName.size() + 1]{};
307 if constexpr(MyCodeHandlesProxyReferences)
311 "%*.s %*lu %*lu %*lu\n",
317 static_cast<unsigned long>(hits[i].reads),
319 static_cast<unsigned long>(hits[i].writes));
331 static_cast<unsigned long>(hits[i].memLocsComputed));
335 const auto total = hits.totalBytes();
336 if constexpr(MyCodeHandlesProxyReferences)
338 const auto [rsize, runit] =
prettySize(total.totalRead);
339 const auto [wsize, wunit] =
prettySize(total.totalWritten);
342 "%*s %*s %*f%s %*f%s\n",
358 printf(
"%*s %*s %*f%s\n", columnWidth,
"Total", sizeColumnWidth,
"", columnWidth, size, unit);
364 return static_cast<const Mapping&
>(*this);
369 template<
typename Mapping>
373 template<
typename Mapping,
typename CountType,
bool MyCodeHandlesProxyReferences>
374 inline constexpr
bool isFieldAccessCount<FieldAccessCount<Mapping, CountType, MyCodeHandlesProxyReferences>>
#define LLAMA_LAMBDA_INLINE
Gives strong indication to the compiler to inline the attributed lambda.
#define LLAMA_SUPPRESS_HOST_DEVICE_WARNING
#define LLAMA_FN_HOST_ACC_INLINE
constexpr auto constexprCopy(In f, In l, Out d) -> Out
void atomicInc(CountType &i)
constexpr bool isFieldAccessCount
constexpr std::size_t flatRecordCoord
typename internal::GetTypeImpl< RecordDim, RecordCoordOrTags... >::type GetType
auto mapToMemory(Mapping &mapping, typename Mapping::ArrayExtents::Index ai, RecordCoord rc, Blobs &blobs) -> decltype(auto)
auto prettySize(double size) -> PrettySize
CRTP mixin for proxy reference types to support all compound assignment and increment/decrement opera...
CountType memLocsComputed
auto total() const -> AccessCounts< CountType >
auto fieldHits(Blobs &blobs) const -> FieldHitsArray &
typename Mapping::RecordDim RecordDim
auto compute(typename Mapping::ArrayExtents::Index ai, RecordCoord< RecordCoords... > rc, Blobs &blobs) const -> decltype(auto)
void printFieldHits(const Blobs &blobs) const
constexpr FieldAccessCount()=default
static constexpr bool myCodeHandlesProxyReferences
static constexpr auto isComputed(RecordCoord< RecordCoords... >)
auto fieldHits(const Blobs &blobs) const -> const FieldHitsArray &
FieldAccessCount(Args &&... innerArgs)
constexpr auto blobSize(size_type blobIndex) const -> size_type
FieldAccessCount(Mapping mapping)
void printFieldHits(const FieldHitsArray &hits) const
static constexpr auto blobCount
auto operator=(value_type value) -> FieldAccessCountReference &
constexpr FieldAccessCountReference(RefFwd &&r, AccessCounts< Count > *hits)
FieldAccessCountReference(const FieldAccessCountReference &)=default
FieldAccessCountReference(FieldAccessCountReference &&) noexcept=default