[llvm] [offload] Verify replay config of teams/threads is allowed (PR #192784)

Kevin Sala Penades via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 18 14:17:21 PDT 2026


================
@@ -167,81 +271,89 @@ int main(int argc, char **argv) {
   Desc.HostEntriesEnd = &OffloadEntries[OffloadEntries.size() - 1] + 1;
   Desc.DeviceImages = &DeviceImage;
 
-  auto DeviceIdJson = JsonKernelInfo->getAsObject()->getInteger("DeviceId");
-  // TODO: Print warning if the user overrides the device id in the json file.
-  int32_t DeviceId = (DeviceIdOpt > -1 ? DeviceIdOpt : DeviceIdJson.value());
-
-  // TODO: do we need requires?
-  //__tgt_register_requires(/*Flags=*/1);
-
+  // Register the image and the offload entries.
   __tgt_register_lib(&Desc);
 
   int Rc = __tgt_activate_record_replay(
-      DeviceId, VAllocSize, VAllocAddr, /*IsRecord=*/false, VerifyOpt,
+      DeviceId, VAllocSize, VAllocAddr, /*IsRecord=*/false,
+      VerifyOpt || SaveOutputOpt,
       /*EmitReport=*/false, Directory.c_str());
   if (Rc != OMP_TGT_SUCCESS)
-    reportFatalUsageError("Error activating record replay");
+    return createErr("failed to activate record replay");
 
+  // Load the record input file.
   Filepath.replace_extension("record_input");
-  ErrorOr<std::unique_ptr<MemoryBuffer>> DeviceMemoryMB =
+  auto RecordInputBufferOrErr =
       MemoryBuffer::getFile(Filepath.string(), /*isText=*/false,
                             /*RequiresNullTerminator=*/false);
-
-  if (!DeviceMemoryMB)
-    reportFatalUsageError("Error reading the kernel record input file");
+  if (!RecordInputBufferOrErr)
+    return createErr("failed to read the kernel record input file");
+  auto RecordInputBuffer = std::move(RecordInputBufferOrErr.get());
 
   // On AMD for currently unknown reasons we cannot copy memory mapped data to
   // device. This is a work-around.
-  uint8_t *RecordedData = new uint8_t[DeviceMemoryMB.get()->getBufferSize()];
+  uint8_t *RecordedData = new uint8_t[RecordInputBuffer->getBufferSize()];
----------------
kevinsala wrote:

In the amdgpu plugin, there is a path for data transfers (>= 1MB) where the (unpinned) host buffer is pinned before the data transfer to avoid using intermediate buffer. If the host buffer is memory mapped to a file, the pinning procedure may fail for some reason.

I'll check whether it's still happening.

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


More information about the llvm-commits mailing list