[Openmp-commits] [openmp] 763fdb1 - [OpenMP][Plugin] Update the global address calculation

Shilei Tian via Openmp-commits openmp-commits at lists.llvm.org
Sun Jul 23 14:41:11 PDT 2023


Author: Shilei Tian
Date: 2023-07-23T17:41:06-04:00
New Revision: 763fdb1ffa31dda85d27bfdd4940e62ab560734f

URL: https://github.com/llvm/llvm-project/commit/763fdb1ffa31dda85d27bfdd4940e62ab560734f
DIFF: https://github.com/llvm/llvm-project/commit/763fdb1ffa31dda85d27bfdd4940e62ab560734f.diff

LOG: [OpenMP][Plugin] Update the global address calculation

Current global address caculation doesn't work for AMDGPU in some cases (https://reviews.llvm.org/D142569#4506212).
The root cause is the `sh_addr` is not substracted when caculating the address.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D155886

Added: 
    

Modified: 
    openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
    openmp/libomptarget/plugins-nextgen/common/PluginInterface/GlobalHandler.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp b/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
index fbe50127526a5f..6ca57ddadd930a 100644
--- a/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
+++ b/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
@@ -2583,22 +2583,6 @@ struct AMDGPUGlobalHandlerTy final : public GenericGlobalHandlerTy {
     // Store the symbol address on the device global metadata.
     DeviceGlobal.setPtr(reinterpret_cast<void *>(SymbolAddr));
 
-    return Plugin::success();
-  }
-
-private:
-  /// Extract the global's information from the ELF image, section, and symbol.
-  Error getGlobalMetadataFromELF(const DeviceImageTy &Image,
-                                 const ELF64LE::Sym &Symbol,
-                                 const ELF64LE::Shdr &Section,
-                                 GlobalTy &ImageGlobal) override {
-    // The global's address in AMDGPU is computed as the image begin + the ELF
-    // symbol value. Notice we do not add the ELF section offset.
-    ImageGlobal.setPtr(advanceVoidPtr(Image.getStart(), Symbol.st_value));
-
-    // Set the global's size.
-    ImageGlobal.setSize(Symbol.st_size);
-
     return Plugin::success();
   }
 };

diff  --git a/openmp/libomptarget/plugins-nextgen/common/PluginInterface/GlobalHandler.cpp b/openmp/libomptarget/plugins-nextgen/common/PluginInterface/GlobalHandler.cpp
index a7664f0d232119..0408c757483c4f 100644
--- a/openmp/libomptarget/plugins-nextgen/common/PluginInterface/GlobalHandler.cpp
+++ b/openmp/libomptarget/plugins-nextgen/common/PluginInterface/GlobalHandler.cpp
@@ -53,8 +53,8 @@ Error GenericGlobalHandlerTy::getGlobalMetadataFromELF(
 
   // The global's address is computed as the image begin + the ELF section
   // offset + the ELF symbol value.
-  ImageGlobal.setPtr(
-      advanceVoidPtr(Image.getStart(), Section.sh_offset + Symbol.st_value));
+  ImageGlobal.setPtr(advanceVoidPtr(
+      Image.getStart(), Section.sh_offset - Section.sh_addr + Symbol.st_value));
 
   // Set the global's size.
   ImageGlobal.setSize(Symbol.st_size);


        


More information about the Openmp-commits mailing list