[flang-commits] [llvm] [clang-tools-extra] [openmp] [clang] [libcxx] [lldb] [compiler-rt] [flang] [OpenMP] Add memory diff dump for kernel record-replay (PR #70667)

Giorgis Georgakoudis via flang-commits flang-commits at lists.llvm.org
Sat Nov 4 07:34:23 PDT 2023


================
@@ -151,6 +151,74 @@ struct RecordReplayTy {
     OS.close();
   }
 
+  void dumpDeviceMemoryDiff(StringRef Filename) {
+    ErrorOr<std::unique_ptr<WritableMemoryBuffer>> DeviceMemoryMB =
+        WritableMemoryBuffer::getNewUninitMemBuffer(MemorySize);
+    if (!DeviceMemoryMB)
+      report_fatal_error("Error creating MemoryBuffer for device memory");
+
+    auto Err = Device->dataRetrieve(DeviceMemoryMB.get()->getBufferStart(),
+                                    MemoryStart, MemorySize, nullptr);
+    if (Err)
+      report_fatal_error("Error retrieving data for target pointer");
+
+    // Get the pre-record memory filename
+    SmallString<128> InputFilename = {Filename.split('.').first, ".memory"};
+
+    // Read the pre-record memorydump
+    auto InputFileBuffer = MemoryBuffer::getFileOrSTDIN(InputFilename);
+    if (std::error_code EC = InputFileBuffer.getError())
+      report_fatal_error("Error reading pre-record device memory");
+
+    StringRef InputBufferContents = (*InputFileBuffer)->getBuffer();
+    if (InputBufferContents.size() != MemorySize)
+      report_fatal_error("Error: Pre-record device memory size mismatch");
+
+    std::error_code EC;
+    raw_fd_ostream OS(Filename, EC);
+    if (EC)
+      report_fatal_error("Error dumping memory to file " + Filename + " :" +
+                         EC.message());
+
+    // Get current memory contents
+    StringRef DeviceMemoryContents(DeviceMemoryMB.get()->getBuffer().data(),
+                                   DeviceMemoryMB.get()->getBuffer().size());
+
+    for (size_t I = 0; I < MemorySize; ++I) {
+      // If buffers are same, continue
+      if (InputBufferContents[I] == DeviceMemoryContents[I])
+        continue;
+
+      // If mismatch is found create a new diff line
+      // Current format: location, size, differences
+      OS << I << " "; // Marks the start offset
----------------
ggeorgakoudis wrote:

Move comment above

https://github.com/llvm/llvm-project/pull/70667


More information about the flang-commits mailing list