[Openmp-commits] [openmp] 75492e2 - [libomptarget][nfc] Accept callable for hsa iterate_symbols
Jon Chesterfield via Openmp-commits
openmp-commits at lists.llvm.org
Tue May 25 01:29:27 PDT 2021
Author: Jon Chesterfield
Date: 2021-05-25T09:29:11+01:00
New Revision: 75492e20fb7c8e3fc4bc0ff8a5eda844056652cb
URL: https://github.com/llvm/llvm-project/commit/75492e20fb7c8e3fc4bc0ff8a5eda844056652cb
DIFF: https://github.com/llvm/llvm-project/commit/75492e20fb7c8e3fc4bc0ff8a5eda844056652cb.diff
LOG: [libomptarget][nfc] Accept callable for hsa iterate_symbols
[libomptarget][nfc] Accept callable for hsa iterate_symbols
Candidate refactor to simplify D102692
Reviewed By: pdhaliwal
Differential Revision: https://reviews.llvm.org/D103030
Added:
Modified:
openmp/libomptarget/plugins/amdgpu/impl/system.cpp
Removed:
################################################################################
diff --git a/openmp/libomptarget/plugins/amdgpu/impl/system.cpp b/openmp/libomptarget/plugins/amdgpu/impl/system.cpp
index 92b7d72cfbcf7..c8cd1537617e3 100644
--- a/openmp/libomptarget/plugins/amdgpu/impl/system.cpp
+++ b/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.
@@ -996,10 +1010,8 @@ static hsa_status_t get_code_object_custom_metadata(void *binary,
return HSA_STATUS_SUCCESS;
}
-static hsa_status_t populate_InfoTables(hsa_executable_t executable,
- hsa_executable_symbol_t symbol,
- void *data) {
- int gpu = *static_cast<int *>(data);
+static hsa_status_t populate_InfoTables(hsa_executable_symbol_t symbol,
+ int gpu) {
hsa_symbol_kind_t type;
uint32_t name_length;
@@ -1228,8 +1240,12 @@ atmi_status_t Runtime::RegisterModuleFromMemory(
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, hsa_executable_symbol_t symbol) -> hsa_status_t {
+ return populate_InfoTables(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));
More information about the Openmp-commits
mailing list