[llvm] [Offload] Add GenericProfilerTy abstraction and APITypes extensions (PR #225639)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 03:24:37 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- offload/plugins-nextgen/common/include/GenericProfiler.h offload/plugins-nextgen/common/src/GenericProfiler.cpp offload/include/Shared/APITypes.h offload/plugins-nextgen/amdgpu/src/rtl.cpp offload/plugins-nextgen/common/include/PluginInterface.h offload/plugins-nextgen/common/src/PluginInterface.cpp offload/plugins-nextgen/cuda/src/rtl.cpp offload/plugins-nextgen/host/src/rtl.cpp offload/plugins-nextgen/level_zero/include/L0Device.h offload/plugins-nextgen/level_zero/src/L0Device.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/offload/plugins-nextgen/amdgpu/src/rtl.cpp b/offload/plugins-nextgen/amdgpu/src/rtl.cpp
index 82baa7153..888830f7d 100644
--- a/offload/plugins-nextgen/amdgpu/src/rtl.cpp
+++ b/offload/plugins-nextgen/amdgpu/src/rtl.cpp
@@ -3989,10 +3989,10 @@ struct AMDGPUPluginContextTy final : public PluginContextTy {
   }
 
   Expected<void *> allocate(GenericDeviceTy &Device, int64_t Size,
-                            void *HostPtr, TargetAllocTy Kind,
-                            size_t Alignment, GenericProfilerTy *ProfilerPtr) override;
-  Error deallocate(GenericDeviceTy &Device, void *Ptr,
-                   TargetAllocTy Kind, GenericProfilerTy *ProfilerPtr) override;
+                            void *HostPtr, TargetAllocTy Kind, size_t Alignment,
+                            GenericProfilerTy *ProfilerPtr) override;
+  Error deallocate(GenericDeviceTy &Device, void *Ptr, TargetAllocTy Kind,
+                   GenericProfilerTy *ProfilerPtr) override;
   Expected<PluginAllocInfoTy> getAllocInfo(const void *Ptr) override;
 
 private:
@@ -4314,12 +4314,11 @@ private:
   AMDHostDeviceTy *HostDevice;
 };
 
-Expected<void *> AMDGPUPluginContextTy::allocate(GenericDeviceTy &Device,
-                                                 int64_t Size, void *HostPtr,
-                                                 TargetAllocTy Kind,
-                                                 size_t Alignment, GenericProfilerTy *ProfilerPtr) {
-  auto PtrOrErr =
-      PluginContextTy::allocate(Device, Size, HostPtr, Kind, Alignment, ProfilerPtr);
+Expected<void *> AMDGPUPluginContextTy::allocate(
+    GenericDeviceTy &Device, int64_t Size, void *HostPtr, TargetAllocTy Kind,
+    size_t Alignment, GenericProfilerTy *ProfilerPtr) {
+  auto PtrOrErr = PluginContextTy::allocate(Device, Size, HostPtr, Kind,
+                                            Alignment, ProfilerPtr);
   if (!PtrOrErr || !*PtrOrErr)
     return PtrOrErr;
   std::lock_guard<std::mutex> Lock(AllocationsMutex);
@@ -4328,7 +4327,8 @@ Expected<void *> AMDGPUPluginContextTy::allocate(GenericDeviceTy &Device,
 }
 
 Error AMDGPUPluginContextTy::deallocate(GenericDeviceTy &Device, void *Ptr,
-                                        TargetAllocTy Kind, GenericProfilerTy *ProfilerPtr) {
+                                        TargetAllocTy Kind,
+                                        GenericProfilerTy *ProfilerPtr) {
   // Erase before base deallocate: once Ptr returns to the MM freelist a
   // concurrent alloc could reuse it and re-populate Allocations. On failure
   // Ptr is in an undetermined state (maybe freed, maybe not) so we don't
diff --git a/offload/plugins-nextgen/common/include/PluginInterface.h b/offload/plugins-nextgen/common/include/PluginInterface.h
index b78135d77..17f698d0e 100644
--- a/offload/plugins-nextgen/common/include/PluginInterface.h
+++ b/offload/plugins-nextgen/common/include/PluginInterface.h
@@ -939,19 +939,22 @@ struct PluginContextTy {
   /// Allocate Size bytes of Kind memory accessible from Device. HostPtr is an
   /// optional hint (e.g. for pinned-buffer registration); pass nullptr when
   /// unused.
-  virtual llvm::Expected<void *> allocate(GenericDeviceTy &Device, int64_t Size,
-                                          void *HostPtr, TargetAllocTy Kind,
-                                          size_t Alignment, GenericProfilerTy *ProfilerPtr = nullptr);
+  virtual llvm::Expected<void *>
+  allocate(GenericDeviceTy &Device, int64_t Size, void *HostPtr,
+           TargetAllocTy Kind, size_t Alignment,
+           GenericProfilerTy *ProfilerPtr = nullptr);
 
   /// Free a pointer returned by allocate; resolves owner/kind via
   /// getAllocInfo. Requires a non-empty device set, so this is only valid on
   /// user-created contexts (not on the per-plugin default context, which
   /// carries no devices).
-  virtual llvm::Error deallocate(void *Ptr, GenericProfilerTy *ProfilerPtr = nullptr);
+  virtual llvm::Error deallocate(void *Ptr,
+                                 GenericProfilerTy *ProfilerPtr = nullptr);
 
   /// Free a pointer when the caller already knows the owning device and kind.
   virtual llvm::Error deallocate(GenericDeviceTy &Device, void *Ptr,
-                                 TargetAllocTy Kind, GenericProfilerTy *ProfilerPtr = nullptr);
+                                 TargetAllocTy Kind,
+                                 GenericProfilerTy *ProfilerPtr = nullptr);
 
   /// Look up the allocation containing Ptr. Returns NOT_FOUND when Ptr is not
   /// known to this context. Only valid on user-created contexts.
diff --git a/offload/plugins-nextgen/common/src/PluginInterface.cpp b/offload/plugins-nextgen/common/src/PluginInterface.cpp
index dc75d75a8..281ecc775 100644
--- a/offload/plugins-nextgen/common/src/PluginInterface.cpp
+++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp
@@ -1266,8 +1266,8 @@ MemoryManagerTy *PluginContextTy::getHostMemoryManager() {
 
 Expected<void *> PluginContextTy::allocate(GenericDeviceTy &Device,
                                            int64_t Size, void *HostPtr,
-                                           TargetAllocTy Kind,
-                                           size_t Alignment, GenericProfilerTy *ProfilerPtr) {
+                                           TargetAllocTy Kind, size_t Alignment,
+                                           GenericProfilerTy *ProfilerPtr) {
   // Record-replay hands out interior pointers into a preallocated slab so
   // recorded kernels can re-execute at their original addresses; the MM pool
   // must be bypassed for those allocations to reach the RR bump allocator.
@@ -1294,7 +1294,8 @@ Error PluginContextTy::deallocate(void *Ptr, GenericProfilerTy *ProfilerPtr) {
 }
 
 Error PluginContextTy::deallocate(GenericDeviceTy &Device, void *Ptr,
-                                  TargetAllocTy Kind, GenericProfilerTy *ProfilerPtr) {
+                                  TargetAllocTy Kind,
+                                  GenericProfilerTy *ProfilerPtr) {
   // Symmetric with allocate: record-replay allocations never entered the MM
   // pool, so route their free through dataDelete's RR shortcut.
   if (auto *RR = Device.getRecordReplay(); RR && RR->isRecordingOrReplaying())
@@ -1687,7 +1688,8 @@ int32_t GenericPluginTy::load_binary(int32_t DeviceId,
 }
 
 void *GenericPluginTy::data_alloc(int32_t DeviceId, int64_t Size, void *HostPtr,
-                                  int32_t Kind, GenericProfilerTy *ProfilerPtr) {
+                                  int32_t Kind,
+                                  GenericProfilerTy *ProfilerPtr) {
   auto &Device = getDevice(DeviceId);
   auto AllocOrErr = getDefaultContext(Device).allocate(
       Device, Size, HostPtr, static_cast<TargetAllocTy>(Kind),
@@ -1703,7 +1705,8 @@ void *GenericPluginTy::data_alloc(int32_t DeviceId, int64_t Size, void *HostPtr,
 }
 
 int32_t GenericPluginTy::data_delete(int32_t DeviceId, void *TgtPtr,
-                                     int32_t Kind, GenericProfilerTy *ProfilerPtr) {
+                                     int32_t Kind,
+                                     GenericProfilerTy *ProfilerPtr) {
   auto &Device = getDevice(DeviceId);
   if (auto Err = getDefaultContext(Device).deallocate(
           Device, TgtPtr, static_cast<TargetAllocTy>(Kind), ProfilerPtr)) {
diff --git a/offload/plugins-nextgen/host/src/rtl.cpp b/offload/plugins-nextgen/host/src/rtl.cpp
index 55264eed1..54e8c2e6e 100644
--- a/offload/plugins-nextgen/host/src/rtl.cpp
+++ b/offload/plugins-nextgen/host/src/rtl.cpp
@@ -495,10 +495,10 @@ struct GenELF64PluginContextTy final : public PluginContextTy {
   }
 
   Expected<void *> allocate(GenericDeviceTy &Device, int64_t Size,
-                            void *HostPtr, TargetAllocTy Kind,
-                            size_t Alignment, GenericProfilerTy *ProfilerPtr) override {
-    auto PtrOrErr =
-        PluginContextTy::allocate(Device, Size, HostPtr, Kind, Alignment, ProfilerPtr);
+                            void *HostPtr, TargetAllocTy Kind, size_t Alignment,
+                            GenericProfilerTy *ProfilerPtr) override {
+    auto PtrOrErr = PluginContextTy::allocate(Device, Size, HostPtr, Kind,
+                                              Alignment, ProfilerPtr);
     if (!PtrOrErr)
       return PtrOrErr.takeError();
     void *Ptr = *PtrOrErr;
@@ -507,8 +507,8 @@ struct GenELF64PluginContextTy final : public PluginContextTy {
     return Ptr;
   }
 
-  Error deallocate(GenericDeviceTy &Device, void *Ptr,
-                   TargetAllocTy Kind, GenericProfilerTy *ProfilerPtr) override {
+  Error deallocate(GenericDeviceTy &Device, void *Ptr, TargetAllocTy Kind,
+                   GenericProfilerTy *ProfilerPtr) override {
     {
       std::lock_guard<std::mutex> Lock(AllocsMutex);
       Allocs.erase(Ptr);

``````````

</details>


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


More information about the llvm-commits mailing list