Mneme
Mneme a tool allowing recording the execution of a GPU (CUDA/HIP) kernel and replaying that kernel as an independent executable.
Loading...
Searching...
No Matches
MnemeMemory.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <cmath>
5#include <cstdint>
6#include <cstring>
7#include <iterator>
8#include <llvm/ADT/StringRef.h>
9#include <llvm/Support/raw_ostream.h>
10#include <map>
11#include <memory>
12#include <sys/types.h>
13#include <utility>
14#include <vector>
15
21#include "mneme/MnemeLogger.hpp"
23#include "mneme/MnemeUtils.hpp"
24
25namespace mneme {
26struct ByteSpan {
27 uint64_t Offset = 0;
28 uint64_t Extent = 0;
29
30 uint64_t endOffset() const { return Offset + Extent; }
31};
32
33inline bool operator==(const ByteSpan &LHS, const ByteSpan &RHS) {
34 return LHS.Offset == RHS.Offset && LHS.Extent == RHS.Extent;
35}
36
37inline bool operator!=(const ByteSpan &LHS, const ByteSpan &RHS) {
38 return !(LHS == RHS);
39}
40
41// Metadata attached to a byte range inside one owning blob.
46
47inline bool operator==(const MemoryAnnotation &LHS,
48 const MemoryAnnotation &RHS) {
49 return LHS.Range == RHS.Range && LHS.MD == RHS.MD;
50}
51
52inline bool operator!=(const MemoryAnnotation &LHS,
53 const MemoryAnnotation &RHS) {
54 return !(LHS == RHS);
55}
56
57// Reads what writeAnnotationsToStream() writes.
58inline std::vector<MemoryAnnotation>
59readAnnotationsFromBuffer(const char *&Buffer) {
60 size_t NumAnnotations = util::extractScalar<size_t>(Buffer);
61 std::vector<MemoryAnnotation> LoadedAnnotations;
62 LoadedAnnotations.reserve(NumAnnotations);
63 for (size_t I = 0; I < NumAnnotations; ++I) {
64 MemoryAnnotation Annotation;
65 Annotation.Range.Offset = util::extractScalar<uint64_t>(Buffer);
66 Annotation.Range.Extent = util::extractScalar<uint64_t>(Buffer);
67 Annotation.MD = metadata::fromBuffer(Buffer);
68 LoadedAnnotations.push_back(std::move(Annotation));
69 }
70 return LoadedAnnotations;
71}
72
73// Writes | NumAnnotations | (Offset | Extent | Metadata) * NumAnnotations |.
74inline void
75writeAnnotationsToStream(llvm::raw_ostream &OS,
76 const std::vector<MemoryAnnotation> &Annotations) {
77 util::writeScalar(OS, Annotations.size());
78 for (const auto &Annotation : Annotations) {
79 util::writeScalar(OS, Annotation.Range.Offset);
80 util::writeScalar(OS, Annotation.Range.Extent);
81 metadata::serialize(OS, Annotation.MD);
82 }
83}
84
85// The number of bytes writeAnnotationsToStream() writes for Annotations.
86inline size_t
87annotationsSerializedSize(const std::vector<MemoryAnnotation> &Annotations) {
88 size_t Size = sizeof(size_t);
89 for (const auto &Annotation : Annotations)
90 Size += sizeof(Annotation.Range.Offset) + sizeof(Annotation.Range.Extent) +
91 metadata::serializedSize(Annotation.MD);
92 return Size;
93}
94
95// Whether a blob gave a range the metadata, or else the rule the range breaks.
104
105inline const char *describeAnnotationStatus(AnnotationStatus Status) {
106 switch (Status) {
108 return "is valid";
110 return "extends past the end of its allocation";
112 return "is empty";
114 return "has a builtin type with no element size";
116 return "starts inside an element of its type or of the annotation it "
117 "overlaps";
119 return "ends inside an element of its type or of the annotation it "
120 "overlaps";
121 }
122 return "has an unknown annotation status";
123}
124
125enum class MemoryLocation { Host, Device };
126
127// Owns a buffer of bytes that lives in either host or device memory.
128template <DeviceVendors VendorTypes> class MnemeBuffer {
129 using MnemeDeviceRT = DeviceTraits<VendorTypes>;
130
131 void *Ptr = nullptr;
132 uint64_t Size = 0;
134
135 static void *allocate(uint64_t Size, MemoryLocation Where) {
136 if (Where == MemoryLocation::Host)
137 return new uint8_t[Size];
138 void *DevPtr = nullptr;
139 if (!Size)
140 return DevPtr;
141 auto EC = MnemeDeviceRT::DeviceErrorCheck(
142 MnemeDeviceRT::DeviceMalloc(&DevPtr, Size));
143 if (EC)
144 LOG_FATAL("Could not allocate {} bytes of device memory: {}", Size,
145 EC.value());
146 return DevPtr;
147 }
148
149 static void release(void *P, MemoryLocation Where) {
150 if (!P)
151 return;
152 if (Where == MemoryLocation::Host) {
153 delete[] static_cast<uint8_t *>(P);
154 return;
155 }
156 auto EC = MnemeDeviceRT::DeviceErrorCheck(MnemeDeviceRT::DeviceFree(P));
157 if (EC)
158 LOG_WARN("Could not free the device buffer at {}: {}", P, EC.value());
159 }
160
161 void free() { release(std::exchange(Ptr, nullptr), Location); }
162
163 // Copies the bytes into new memory at Dest and frees the old memory.
164 void moveTo(MemoryLocation Dest) {
165 if (Location == Dest)
166 return;
167 void *NewPtr = allocate(Size, Dest);
168 if (Size) {
169 auto Kind = Dest == MemoryLocation::Device
170 ? MnemeDeviceRT::MemcpyHostToDeviceKind()
171 : MnemeDeviceRT::MemcpyDeviceToHostKind();
172 auto EC = MnemeDeviceRT::DeviceErrorCheck(
173 MnemeDeviceRT::DeviceCopy(NewPtr, Ptr, Size, Kind));
174 if (EC) {
175 release(NewPtr, Dest);
176 LOG_FATAL("Could not copy {} bytes to the {}: {}", Size,
177 Dest == MemoryLocation::Device ? "device" : "host",
178 EC.value());
179 }
180 }
181 free();
182 Ptr = NewPtr;
183 Location = Dest;
184 }
185
186public:
187 explicit MnemeBuffer(uint64_t Size = 0)
188 : Ptr(new uint8_t[Size]), Size(Size) {}
189 MnemeBuffer(std::unique_ptr<uint8_t[]> HostData, uint64_t Size)
190 : Ptr(HostData.release()), Size(Size) {}
191 ~MnemeBuffer() { free(); }
192
193 MnemeBuffer(const MnemeBuffer &) = delete;
195 MnemeBuffer(MnemeBuffer &&Other) noexcept
196 : Ptr(std::exchange(Other.Ptr, nullptr)), Size(Other.Size),
197 Location(Other.Location) {}
198 MnemeBuffer &operator=(MnemeBuffer &&Other) noexcept {
199 if (this != &Other) {
200 free();
201 Ptr = std::exchange(Other.Ptr, nullptr);
202 Size = Other.Size;
203 Location = Other.Location;
204 }
205 return *this;
206 }
207
208 MemoryLocation location() const { return Location; }
209
210 uint8_t *hostData() const {
211 if (Location != MemoryLocation::Host)
212 LOG_FATAL("Reading the host data of a buffer that was moved to the "
213 "device");
214 return static_cast<uint8_t *>(Ptr);
215 }
216
217 void *deviceData() const {
218 if (Location != MemoryLocation::Device)
219 LOG_FATAL("Reading the device data of a buffer that is on the host");
220 return Ptr;
221 }
222
225};
226
227template <DeviceVendors VendorTypes> class MnemeMemoryBlob {
228public:
230 using DeviceError_t = typename MnemeDeviceRT::DeviceError_t;
231 using DeviceStream_t = typename MnemeDeviceRT::DeviceStream_t;
232 using KernelFunction_t = typename MnemeDeviceRT::KernelFunction_t;
234 typename MnemeDeviceRT::MemoryAllocationHandle_t;
235
236protected:
237 static bool compareRange(const char *Actual, const char *Expected,
238 uint64_t NumBytes, const Metadata &Md) {
239 auto Compare = compareDeviceBlobs(Actual, Expected, NumBytes, Md);
240
241 // Comparator semantics:
242 // - Norm::None => per-element thresholding reports AnyFail/FirstBadIdx
243 // - Norm::L1/L2/Linf => aggregated error is reported in Agg
244 if (Md.norm == Norm::None)
245 return Compare.AnyFail == 0;
246
247 return std::isfinite(Compare.Agg) && Compare.Agg <= Md.threshold;
248 }
249
250 // Sorted subregions that cover the blob. A later annotation overrides the
251 // bytes it covers, so it can split an earlier subregion in two.
252 std::vector<MemoryAnnotation> Annotations;
253 uint64_t ActualSize;
254 void *BlobAddr;
255 uint64_t Size;
256 // The recorded bytes, on the host until replay moves them to the device.
259 // Non-zero when this blob owns the MappedSize-byte mapping at MapAddr.
260 uint64_t MappedSize = 0;
261 void *MapAddr = nullptr;
262 int DeviceID = 0;
264
265 static bool
266 areValidSubregions(const std::vector<MemoryAnnotation> &Subregions,
267 uint64_t Size) {
268 if (Subregions.empty())
269 return false;
270 uint64_t End = 0;
271 for (const auto &Subregion : Subregions) {
272 const auto &Range = Subregion.Range;
273 if (Range.Offset != End || Range.Extent > Size - Range.Offset)
274 return false;
275 // An empty blob keeps one empty subregion so that annotationAt() works.
276 if (Range.Extent == 0 && !(Size == 0 && Subregions.size() == 1))
277 return false;
278 if (!isElementBoundary(Range.Offset, Subregion.MD) ||
279 !isElementBoundary(Range.endOffset(), Subregion.MD))
280 return false;
281 End = Range.endOffset();
282 }
283 return End == Size;
284 }
285
286 static bool isElementBoundaryOfBoth(uint64_t Offset, const Metadata &Before,
287 const Metadata &After) {
288 return isElementBoundary(Offset, Before) &&
289 isElementBoundary(Offset, After);
290 }
291
292 static bool isElementBoundary(uint64_t Offset, const Metadata &Md) {
293 uint64_t Width = builtinByteWidth(Md.builtin);
294 return Width != 0 && Offset % Width == 0;
295 }
296
298 uint64_t Begin = Range.Offset;
299 uint64_t End = Range.endOffset();
300 if (Begin > Size || Range.Extent > Size - Begin)
302 if (Range.Extent == 0 && Size != 0)
304 if (builtinByteWidth(Md.builtin) == 0)
306 if (!isElementBoundaryOfBoth(Begin, annotationAt(Begin).MD, Md))
308 if (!isElementBoundaryOfBoth(End, Md, annotationAt(End).MD))
311 }
312
313 // Reads | ActualSize | Size | DevAddr | Data |, the start of a blob record.
314 static std::pair<void *, MnemeMemoryBlob<VendorTypes>>
315 readHeaderAndData(const char *&Buffer) {
316 BlobHeader Header = BlobHeader::read(Buffer);
317 auto Blob = MnemeMemoryBlob<VendorTypes>(Header.ActualSize, 0, Header.Size);
318 std::memcpy(Blob.getHostData(), Buffer, Header.Size);
319 Buffer += Header.Size;
320 LOG_DEBUG("Read memory blob at address {} SIZE: {} ActualSize:{}",
321 Header.DevAddr, Header.Size, Header.ActualSize);
322 return std::make_pair(Header.DevAddr, std::move(Blob));
323 }
324
325public:
327 auto Status = checkAnnotation(Range, Md);
328 if (Status != AnnotationStatus::Ok)
329 return Status;
330
331 uint64_t Begin = Range.Offset;
332 uint64_t End = Range.endOffset();
333 std::vector<MemoryAnnotation> Subregions;
334 Subregions.reserve(Annotations.size() + 2);
335 for (const auto &Old : Annotations) {
336 if (Old.Range.Offset >= Begin)
337 break;
338 uint64_t OldEnd = std::min(Old.Range.endOffset(), Begin);
339 Subregions.push_back(
340 {{Old.Range.Offset, OldEnd - Old.Range.Offset}, Old.MD});
341 }
342 Subregions.push_back({Range, std::move(Md)});
343 for (const auto &Old : Annotations) {
344 if (Old.Range.endOffset() <= End)
345 continue;
346 uint64_t OldBegin = std::max(Old.Range.Offset, End);
347 Subregions.push_back(
348 {{OldBegin, Old.Range.endOffset() - OldBegin}, Old.MD});
349 }
350 Annotations = std::move(Subregions);
352 }
353
354 void resetAnnotations() { Annotations = {{{0, Size}, Metadata{}}}; }
355
356 bool replaceAnnotations(std::vector<MemoryAnnotation> Subregions) {
357 if (!areValidSubregions(Subregions, Size))
358 return false;
359 Annotations = std::move(Subregions);
360 return true;
361 }
362
363 // Replaces the annotations with the list writeAnnotationsToStream() wrote at
364 // Buffer.
365 void readAnnotations(const char *&Buffer) {
367 LOG_FATAL("Invalid annotation set serialized for blob");
368 }
369
370 void readWholeBlobMetadata(const char *&Buffer) {
371 auto Status = setAnnotation({0, Size}, metadata::fromBuffer(Buffer));
372 if (Status != AnnotationStatus::Ok)
373 LOG_FATAL("Invalid metadata serialized for blob: annotation {}",
375 }
376
377 // Past the end of the blob, this is the last subregion.
378 const MemoryAnnotation &annotationAt(uint64_t ByteOffset) const {
379 auto It =
380 std::upper_bound(Annotations.begin(), Annotations.end(), ByteOffset,
381 [](uint64_t Byte, const MemoryAnnotation &Subregion) {
382 return Byte < Subregion.Range.Offset;
383 });
384 return *std::prev(It);
385 }
386
387 const std::vector<MemoryAnnotation> &getAnnotations() const {
388 return Annotations;
389 }
390
391 MnemeMemoryBlob(uint64_t ActualSize = 0, void *BlobAddr = nullptr,
392 uint64_t Size = 0)
394 IsMapped(false) {
396 }
397
398 // Maps MapSize bytes of new device memory at exactly MapVA, owned by this
399 // blob, and places the blob at VA inside it.
400 MapStatus mapFixed(void *VA, void *MapVA, uint64_t MapSize,
401 uint64_t Alignment, int DeviceID) {
402 auto Status =
403 MnemeDeviceRT::mapFixed(MapVA, MapSize, Alignment, DeviceID, Handle);
404 if (Status == MapStatus::Mapped) {
405 BlobAddr = VA;
406 IsMapped = true;
407 MappedSize = MapSize;
408 MapAddr = MapVA;
409 this->DeviceID = DeviceID;
410 }
411 return Status;
412 }
413
414 // Points this blob at VA inside a mapping it does not own.
415 void mapInto(void *VA) {
416 BlobAddr = VA;
417 IsMapped = true;
418 MappedSize = 0;
419 }
420
422 int _device;
423 auto ret = MnemeDeviceRT::DeviceMalloc(&(this->BlobAddr), Size);
424 MnemeDeviceRT::getDevice(_device);
425 LOG_DEBUG("Loading epilogue for device {}", _device);
426 this->ActualSize = Size;
427 this->Size = Size;
428 this->IsMapped = false;
429 return ret;
430 }
431
433 if (!BlobAddr)
434 return MnemeDeviceRT::DeviceSuccess;
435
436 if (!IsMapped) {
437 auto ret = MnemeDeviceRT::DeviceFree(BlobAddr);
438 BlobAddr = 0;
439 return ret;
440 }
441 if (MappedSize)
442 MnemeDeviceRT::unmapFixed(MapAddr, MappedSize, DeviceID, Handle);
443 MappedSize = 0;
444 BlobAddr = 0;
445 return MnemeDeviceRT::DeviceSuccess;
446 }
447
448 void setHostData(std::unique_ptr<uint8_t[]> HostData) {
449 Data = MnemeBuffer<VendorTypes>(std::move(HostData), Size);
450 }
451
452 // Moves the blob's recorded bytes from host to device memory.
453 void moveDataToDevice() { Data.moveToDevice(); }
454
455 // Moves the blob's recorded bytes from device to host memory.
456 void moveDataToHost() { Data.moveToHost(); }
457
459 if (BlobAddr != 0 && IsMapped) {
460 LOG_FATAL("Destroying memory descriptor without releasing device memory at addr={}, size={}",
461 (void*)BlobAddr, Size);
462 }
463 }
464
465 // Reads a blob record that carries a single whole-blob metadata:
466 // | ActualSize | Size | DevAddr | Data | Metadata |.
467 static std::pair<void *, MnemeMemoryBlob<VendorTypes>>
468 readWithMetadata(const char *&Buffer) {
469 auto Entry = readHeaderAndData(Buffer);
470 auto &Blob = Entry.second;
471 Blob.readWholeBlobMetadata(Buffer);
472 return Entry;
473 }
474
475 // Reads a blob record that carries an annotation list:
476 // | ActualSize | Size | DevAddr | Data |
477 // | NumAnnotations | (Offset | Extent | Metadata) * NumAnnotations |.
478 static std::pair<void *, MnemeMemoryBlob<VendorTypes>>
479 readWithAnnotations(const char *&Buffer) {
480 auto Entry = readHeaderAndData(Buffer);
481 Entry.second.readAnnotations(Buffer);
482 return Entry;
483 }
484
485 // Writes the blob record that readWithAnnotations() reads, copying the data
486 // from the blob's device memory.
487 void writeWithAnnotations(llvm::raw_ostream &OS) const {
489
490 LOG_DEBUG("Serializing MemoryBlob, DevAddr:{} MirroredHostAddr:{} Size:{} "
491 "ActualSize:{}",
492 (void *)BlobAddr, reinterpret_cast<void *>(getHostData()),
494
495 auto EC = MnemeDeviceRT::DeviceErrorCheck(MnemeDeviceRT::DeviceCopy(
496 static_cast<void *>(getHostData()), reinterpret_cast<void *>(BlobAddr),
497 getSize(), MnemeDeviceRT::MemcpyDeviceToHostKind()));
498 if (EC)
499 LOG_FATAL("Error in copying data from device when serializing context on "
500 "output stream\nDevice Error Msg: " +
501 EC.value() + "\n");
502 OS << llvm::StringRef(reinterpret_cast<const char *>(getHostData()), Size);
504 }
505
506 // The number of bytes writeWithAnnotations() writes.
511
512 void *ptr() { return reinterpret_cast<void *>(BlobAddr); }
513
516
518 if (this != &other) {
519 BlobAddr = other.BlobAddr;
520 Size = other.Size;
521 ActualSize = other.ActualSize;
522 Data = std::move(other.Data);
523 IsMapped = other.IsMapped;
524 MappedSize = other.MappedSize;
525 MapAddr = other.MapAddr;
526 Handle = other.Handle;
527 Annotations = std::move(other.Annotations);
528 other.BlobAddr = 0;
529 other.MappedSize = 0;
530 }
531 return *this;
532 }
533
535 : Annotations(std::move(other.Annotations)), ActualSize(other.ActualSize),
536 BlobAddr(other.BlobAddr), Size(other.Size), Data(std::move(other.Data)),
537 IsMapped(other.IsMapped), MappedSize(other.MappedSize),
538 MapAddr(other.MapAddr), Handle(other.Handle) {
539 other.BlobAddr = 0;
540 other.MappedSize = 0;
541 }
542
543 void *getBlobAddr() const { return BlobAddr; }
544 uint64_t getActualSize() const { return ActualSize; }
545 uint64_t getSize() const { return Size; }
546 MemoryLocation getDataLocation() const { return Data.location(); }
547 uint8_t *getHostData() const { return Data.hostData(); }
548 void *getDeviceData() const { return Data.deviceData(); }
549
550 bool operator==(const MnemeMemoryBlob<VendorTypes> &other) const {
551 if (getSize() != other.getSize()) {
552 LOG_WARN("Sizes Differ {} vs {}", getSize(), other.getSize());
553 return false;
554 }
555 requireSameAnnotations(other);
556 return matchesWithinTolerance(other.getBlobAddr(), getBlobAddr());
557 }
558
559 // True if the memory of Replayed matches this blob's device-resident
560 // recorded data within this blob's tolerance.
562 if (getSize() != Replayed.getSize()) {
563 LOG_WARN("Sizes Differ {} vs {}", getSize(), Replayed.getSize());
564 return false;
565 }
566 requireSameAnnotations(Replayed);
567 return matchesWithinTolerance(Replayed.getBlobAddr(), getDeviceData());
568 }
569
570 bool operator!=(const MnemeMemoryBlob<VendorTypes> &other) const {
571 return !(*this == other);
572 }
573
574private:
575 void requireSameAnnotations(const MnemeMemoryBlob<VendorTypes> &Other) const {
576 if (Annotations != Other.Annotations)
577 LOG_FATAL("Blob {} has different annotations from the blob it is "
578 "compared with",
579 Other.getBlobAddr());
580 }
581
582 bool matchesWithinTolerance(const void *Actual, const void *Expected) const {
583 const auto *ActualBytes = static_cast<const char *>(Actual);
584 const auto *ExpectedBytes = static_cast<const char *>(Expected);
585 for (const auto &Subregion : Annotations) {
586 const auto &Range = Subregion.Range;
587 const auto &Md = Subregion.MD;
588 LOG_DEBUG("Comparing blob {} bytes [{}, {}) with builtin={} threshold={} "
589 "threshold_kind={} norm={} tag={}",
590 Actual, Range.Offset, Range.endOffset(),
591 static_cast<unsigned>(Md.builtin), Md.threshold,
592 static_cast<unsigned>(Md.threshold_kind),
593 static_cast<unsigned>(Md.norm), Md.tag.value_or("no_tag"));
594 if (!compareRange(ActualBytes + Range.Offset,
595 ExpectedBytes + Range.Offset, Range.Extent, Md))
596 return false;
597 }
598 return true;
599 }
600};
601
602// Device allocations by base address, ordered so that an interior pointer
603// resolves to the allocation that contains it.
604template <DeviceVendors VendorTypes>
605using BlobsByAddress = std::map<void *, MnemeMemoryBlob<VendorTypes>>;
606
607} // namespace mneme
#define LOG_DEBUG(...)
Definition MnemeLogger.hpp:109
#define LOG_FATAL(...)
Definition MnemeLogger.hpp:113
#define LOG_WARN(...)
Definition MnemeLogger.hpp:111
Definition MnemeMemory.hpp:128
void moveToDevice()
Definition MnemeMemory.hpp:223
MnemeBuffer & operator=(const MnemeBuffer &)=delete
MnemeBuffer & operator=(MnemeBuffer &&Other) noexcept
Definition MnemeMemory.hpp:198
MnemeBuffer(uint64_t Size=0)
Definition MnemeMemory.hpp:187
MnemeBuffer(MnemeBuffer &&Other) noexcept
Definition MnemeMemory.hpp:195
MemoryLocation location() const
Definition MnemeMemory.hpp:208
MnemeBuffer(std::unique_ptr< uint8_t[]> HostData, uint64_t Size)
Definition MnemeMemory.hpp:189
void moveToHost()
Definition MnemeMemory.hpp:224
uint8_t * hostData() const
Definition MnemeMemory.hpp:210
void * deviceData() const
Definition MnemeMemory.hpp:217
MnemeBuffer(const MnemeBuffer &)=delete
~MnemeBuffer()
Definition MnemeMemory.hpp:191
Definition MnemeMemory.hpp:227
typename MnemeDeviceRT::DeviceError_t DeviceError_t
Definition MnemeMemory.hpp:230
static bool isElementBoundary(uint64_t Offset, const Metadata &Md)
Definition MnemeMemory.hpp:292
MnemeBuffer< VendorTypes > Data
Definition MnemeMemory.hpp:257
static std::pair< void *, MnemeMemoryBlob< VendorTypes > > readHeaderAndData(const char *&Buffer)
Definition MnemeMemory.hpp:315
bool recordedDataMatches(const MnemeMemoryBlob< VendorTypes > &Replayed) const
Definition MnemeMemory.hpp:561
int DeviceID
Definition MnemeMemory.hpp:262
void moveDataToHost()
Definition MnemeMemory.hpp:456
MnemeMemoryBlob & operator=(const MnemeMemoryBlob &)=delete
uint64_t MappedSize
Definition MnemeMemory.hpp:260
AnnotationStatus checkAnnotation(ByteSpan Range, const Metadata &Md) const
Definition MnemeMemory.hpp:297
void readWholeBlobMetadata(const char *&Buffer)
Definition MnemeMemory.hpp:370
void * getDeviceData() const
Definition MnemeMemory.hpp:548
size_t serializedSize() const
Definition MnemeMemory.hpp:507
MnemeMemoryBlob(const MnemeMemoryBlob &)=delete
bool operator==(const MnemeMemoryBlob< VendorTypes > &other) const
Definition MnemeMemory.hpp:550
static std::pair< void *, MnemeMemoryBlob< VendorTypes > > readWithAnnotations(const char *&Buffer)
Definition MnemeMemory.hpp:479
bool IsMapped
Definition MnemeMemory.hpp:258
DeviceTraits< VendorTypes > MnemeDeviceRT
Definition MnemeMemory.hpp:229
uint8_t * getHostData() const
Definition MnemeMemory.hpp:547
typename MnemeDeviceRT::MemoryAllocationHandle_t MemoryAllocationHandle_t
Definition MnemeMemory.hpp:233
void * ptr()
Definition MnemeMemory.hpp:512
DeviceError_t release()
Definition MnemeMemory.hpp:432
bool operator!=(const MnemeMemoryBlob< VendorTypes > &other) const
Definition MnemeMemory.hpp:570
MnemeMemoryBlob & operator=(MnemeMemoryBlob &&other) noexcept
Definition MnemeMemory.hpp:517
MnemeMemoryBlob(uint64_t ActualSize=0, void *BlobAddr=nullptr, uint64_t Size=0)
Definition MnemeMemory.hpp:391
void readAnnotations(const char *&Buffer)
Definition MnemeMemory.hpp:365
~MnemeMemoryBlob()
Definition MnemeMemory.hpp:458
DeviceError_t allocate(size_t Size)
Definition MnemeMemory.hpp:421
static std::pair< void *, MnemeMemoryBlob< VendorTypes > > readWithMetadata(const char *&Buffer)
Definition MnemeMemory.hpp:468
MemoryLocation getDataLocation() const
Definition MnemeMemory.hpp:546
const MemoryAnnotation & annotationAt(uint64_t ByteOffset) const
Definition MnemeMemory.hpp:378
void setHostData(std::unique_ptr< uint8_t[]> HostData)
Definition MnemeMemory.hpp:448
uint64_t getActualSize() const
Definition MnemeMemory.hpp:544
MapStatus mapFixed(void *VA, void *MapVA, uint64_t MapSize, uint64_t Alignment, int DeviceID)
Definition MnemeMemory.hpp:400
MemoryAllocationHandle_t Handle
Definition MnemeMemory.hpp:263
MnemeMemoryBlob(MnemeMemoryBlob &&other) noexcept
Definition MnemeMemory.hpp:534
void moveDataToDevice()
Definition MnemeMemory.hpp:453
uint64_t Size
Definition MnemeMemory.hpp:255
void writeWithAnnotations(llvm::raw_ostream &OS) const
Definition MnemeMemory.hpp:487
const std::vector< MemoryAnnotation > & getAnnotations() const
Definition MnemeMemory.hpp:387
void mapInto(void *VA)
Definition MnemeMemory.hpp:415
AnnotationStatus setAnnotation(ByteSpan Range, Metadata Md)
Definition MnemeMemory.hpp:326
static bool areValidSubregions(const std::vector< MemoryAnnotation > &Subregions, uint64_t Size)
Definition MnemeMemory.hpp:266
std::vector< MemoryAnnotation > Annotations
Definition MnemeMemory.hpp:252
void resetAnnotations()
Definition MnemeMemory.hpp:354
uint64_t ActualSize
Definition MnemeMemory.hpp:253
static bool compareRange(const char *Actual, const char *Expected, uint64_t NumBytes, const Metadata &Md)
Definition MnemeMemory.hpp:237
typename MnemeDeviceRT::KernelFunction_t KernelFunction_t
Definition MnemeMemory.hpp:232
uint64_t getSize() const
Definition MnemeMemory.hpp:545
typename MnemeDeviceRT::DeviceStream_t DeviceStream_t
Definition MnemeMemory.hpp:231
void * getBlobAddr() const
Definition MnemeMemory.hpp:543
void * BlobAddr
Definition MnemeMemory.hpp:254
static bool isElementBoundaryOfBoth(uint64_t Offset, const Metadata &Before, const Metadata &After)
Definition MnemeMemory.hpp:286
void * MapAddr
Definition MnemeMemory.hpp:261
bool replaceAnnotations(std::vector< MemoryAnnotation > Subregions)
Definition MnemeMemory.hpp:356
int64_t u64 Size
Definition cupti_profile.cpp:179
Metadata fromBuffer(const char *&Buffer)
Definition MnemeAnnotationInternal.cpp:29
void serialize(llvm::raw_ostream &OS, const Metadata &Md)
Definition MnemeAnnotationInternal.cpp:7
size_t serializedSize(const Metadata &Md)
Definition MnemeAnnotationInternal.cpp:23
Ty extractScalar(const char *&Buffer)
Definition MnemeUtils.hpp:19
void writeScalar(llvm::raw_ostream &OS, const Ty &Value)
Definition MnemeLLVMUtils.hpp:40
Definition MnemeAnnotation.cpp:3
const char * describeAnnotationStatus(AnnotationStatus Status)
Definition MnemeMemory.hpp:105
constexpr std::size_t builtinByteWidth(BuiltinDType builtin)
Definition MnemeAnnotation.hpp:54
bool operator==(const Metadata &LHS, const Metadata &RHS)
Definition MnemeAnnotation.hpp:105
void writeAnnotationsToStream(llvm::raw_ostream &OS, const std::vector< MemoryAnnotation > &Annotations)
Definition MnemeMemory.hpp:75
size_t annotationsSerializedSize(const std::vector< MemoryAnnotation > &Annotations)
Definition MnemeMemory.hpp:87
@ None
Definition MnemeAnnotation.hpp:83
bool operator!=(const Metadata &LHS, const Metadata &RHS)
Definition MnemeAnnotation.hpp:111
std::vector< MemoryAnnotation > readAnnotationsFromBuffer(const char *&Buffer)
Definition MnemeMemory.hpp:59
CompareResult compareDeviceBlobs(const char *Blob1, const char *Blob2, uint64_t NumBytes, Metadata Md)
Definition MnemeDeviceCode.cpp:237
MapStatus
Definition DeviceTraits.hpp:71
@ Mapped
Definition DeviceTraits.hpp:71
AnnotationStatus
Definition MnemeMemory.hpp:96
@ StartsInsideElement
Definition MnemeMemory.hpp:101
@ OutOfBounds
Definition MnemeMemory.hpp:98
@ UnknownElementType
Definition MnemeMemory.hpp:100
@ EndsInsideElement
Definition MnemeMemory.hpp:102
@ Ok
Definition MnemeMemory.hpp:97
@ Empty
Definition MnemeMemory.hpp:99
MemoryLocation
Definition MnemeMemory.hpp:125
@ Host
Definition MnemeMemory.hpp:125
@ Device
Definition MnemeMemory.hpp:125
std::map< void *, MnemeMemoryBlob< VendorTypes > > BlobsByAddress
Definition MnemeMemory.hpp:605
Definition MnemeSnapshotRecords.hpp:41
size_t ActualSize
Definition MnemeSnapshotRecords.hpp:42
void write(llvm::raw_ostream &OS) const
Definition MnemeSnapshotRecords.hpp:46
void * DevAddr
Definition MnemeSnapshotRecords.hpp:44
static constexpr size_t serializedSize()
Definition MnemeSnapshotRecords.hpp:59
size_t Size
Definition MnemeSnapshotRecords.hpp:43
static BlobHeader read(const char *&Buffer)
Definition MnemeSnapshotRecords.hpp:52
Definition MnemeMemory.hpp:26
uint64_t endOffset() const
Definition MnemeMemory.hpp:30
uint64_t Offset
Definition MnemeMemory.hpp:27
uint64_t Extent
Definition MnemeMemory.hpp:28
Definition DeviceTraits.hpp:73
Definition MnemeMemory.hpp:42
Metadata MD
Definition MnemeMemory.hpp:44
ByteSpan Range
Definition MnemeMemory.hpp:43
Definition MnemeAnnotation.hpp:90
BuiltinDType builtin
Definition MnemeAnnotation.hpp:92
double threshold
Definition MnemeAnnotation.hpp:95
Norm norm
Definition MnemeAnnotation.hpp:99