Skip to content

Conversation

@fineg74
Copy link

@fineg74 fineg74 commented Dec 20, 2025

Add liboffload memory data locking API for libomptarget migration

This PR adds liboffload memory data locking API that needed to make libomptarget to use liboffload

@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Dec 20, 2025

@llvm/pr-subscribers-offload

Author: None (fineg74)

Changes

Add liboffload memory data locking API for libomptarget migration

This PR adds liboffload memory data locking API that needed to make libomptarget to use liboffload


Full diff: https://github.com/llvm/llvm-project/pull/173138.diff

2 Files Affected:

  • (modified) offload/liboffload/API/Memory.td (+24)
  • (modified) offload/liboffload/src/OffloadImpl.cpp (+15)
diff --git a/offload/liboffload/API/Memory.td b/offload/liboffload/API/Memory.td
index 79e8038330048..cf77055837155 100644
--- a/offload/liboffload/API/Memory.td
+++ b/offload/liboffload/API/Memory.td
@@ -131,3 +131,27 @@ def olMemFill : Function {
     Return<"OL_ERRC_INVALID_SIZE", ["`FillSize % PatternSize != 0`"]>
   ];
 }
+
+def olMemDataLock : Function {
+  let desc = "Locks / pins host memory using the plugin runtime.";
+  let params = [
+    Param<"ol_device_handle_t", "Device", "handle of the device to allocate on", PARAM_IN>,
+    Param<"void *", "Ptr", "Host Pointer", PARAM_IN>,
+    Param<"size_t", "Size", "size of the allocation in bytes", PARAM_IN>,
+    Param<"void**", "LockedPtr", "output for the allocated pointer", PARAM_OUT>
+  ];
+  let returns = [
+    Return<"OL_ERRC_INVALID_SIZE", [
+      "`Size == 0`"
+    ]>
+  ];
+}
+
+def olMemDataUnLock : Function {
+  let desc = "Unlocks / unpins host memory using the plugin runtime.";
+  let params = [
+    Param<"ol_device_handle_t", "Device", "handle of the device to allocate on", PARAM_IN>,
+    Param<"void *", "Ptr", "Host Pointer", PARAM_IN>
+  ];
+  let returns = [];
+}
diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp
index eab9627217ca8..f17a2e7c5a7e8 100644
--- a/offload/liboffload/src/OffloadImpl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -1214,5 +1214,20 @@ Error olLaunchHostFunction_impl(ol_queue_handle_t Queue,
                                                 Queue->AsyncInfo);
 }
 
+Error olMemDataLock_impl(ol_device_handle_t Device, void *Ptr, size_t Size,
+                         void** LockedPtr) {
+  Expected<void*> LockedPtrOrErr = Device->Device->dataLock(Ptr, Size);
+  if (!LockedPtrOrErr)
+    return LockedPtrOrErr.takeError();
+
+  *LockedPtr = *LockedPtrOrErr;
+
+  return Error::success();
+}
+
+Error olMemDataUnLock_impl(ol_device_handle_t Device, void *Ptr) {
+  return Device->Device->dataUnlock(Ptr);
+}
+
 } // namespace offload
 } // namespace llvm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants