[Openmp-commits] [PATCH] D103030: [libomptarget][nfc] Accept callable for hsa iterate_symbols

Jon Chesterfield via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon May 24 08:43:31 PDT 2021


JonChesterfield created this revision.
JonChesterfield added a reviewer: pdhaliwal.
Herald added subscribers: foad, kerbowa, nhaehnle, jvesely.
JonChesterfield requested review of this revision.
Herald added a project: OpenMP.
Herald added a subscriber: openmp-commits.

[libomptarget][nfc] Accept callable for hsa iterate_symbols
Candidate refactor to simplify D102692 <https://reviews.llvm.org/D102692>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103030

Files:
  openmp/libomptarget/plugins/amdgpu/impl/system.cpp


Index: openmp/libomptarget/plugins/amdgpu/impl/system.cpp
===================================================================
--- openmp/libomptarget/plugins/amdgpu/impl/system.cpp
+++ openmp/libomptarget/plugins/amdgpu/impl/system.cpp
@@ -20,6 +20,20 @@
 
 #include "msgpack.h"
 
+namespace hsa {
+// Wrap HSA iterate API in a shim that allows passing general callables
+template <typename C>
+hsa_status_t executable_iterate_symbols(hsa_executable_t executable, C cb) {
+  auto L = [](hsa_executable_t executable, hsa_executable_symbol_t symbol,
+              void *data) -> hsa_status_t {
+    C *unwrapped = static_cast<C *>(data);
+    return (*unwrapped)(executable, symbol);
+  };
+  return hsa_executable_iterate_symbols(executable, L,
+                                        static_cast<void *>(&cb));
+}
+} // namespace hsa
+
 typedef unsigned char *address;
 /*
  * Note descriptors.
@@ -998,8 +1012,7 @@
 
 static hsa_status_t populate_InfoTables(hsa_executable_t executable,
                                         hsa_executable_symbol_t symbol,
-                                        void *data) {
-  int gpu = *static_cast<int *>(data);
+                                        int gpu) {
   hsa_symbol_kind_t type;
 
   uint32_t name_length;
@@ -1228,8 +1241,11 @@
       return ATMI_STATUS_ERROR;
     }
 
-    err = hsa_executable_iterate_symbols(executable, populate_InfoTables,
-                                         static_cast<void *>(&gpu));
+    err = hsa::executable_iterate_symbols(
+        executable,
+        [&](hsa_executable_t ex, hsa_executable_symbol_t symbol)
+            -> hsa_status_t { return populate_InfoTables(ex, symbol, gpu); });
+
     if (err != HSA_STATUS_SUCCESS) {
       printf("[%s:%d] %s failed: %s\n", __FILE__, __LINE__,
              "Iterating over symbols for execuatable", get_error_string(err));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103030.347409.patch
Type: text/x-patch
Size: 1866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210524/6f20d504/attachment.bin>


More information about the Openmp-commits mailing list