Skip to content

Commit 8eaedc4

Browse files
committed
[Offload] Update MPI Plugin
Update the MPI Plugin to fit the recent changes in Plugin Interface
1 parent 2546ba4 commit 8eaedc4

File tree

2 files changed

+52
-27
lines changed

2 files changed

+52
-27
lines changed

offload/plugins-nextgen/mpi/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,6 @@ target_link_libraries(omptarget.rtl.mpi PRIVATE
4949
target_include_directories(omptarget.rtl.mpi PRIVATE
5050
${LIBOMPTARGET_INCLUDE_DIR})
5151

52-
# Install plugin under the lib destination folder.
53-
install(TARGETS omptarget.rtl.mpi
54-
LIBRARY DESTINATION "${OFFLOAD_INSTALL_LIBDIR}")
55-
set_target_properties(omptarget.rtl.mpi PROPERTIES
56-
INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
57-
58-
5952
# Set C++20 as the target standard for this plugin.
6053
set_target_properties(omptarget.rtl.mpi
6154
PROPERTIES

offload/plugins-nextgen/mpi/src/rtl.cpp

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,34 @@
1414
#include <cstdint>
1515
#include <cstdlib>
1616
#include <cstring>
17+
#include <list>
1718
#include <optional>
1819
#include <string>
19-
#include <list>
2020

21+
#include "Shared/Debug.h"
22+
#include "Utils/ELF.h"
23+
24+
#include "EventSystem.h"
2125
#include "GlobalHandler.h"
2226
#include "OpenMP/OMPT/Callback.h"
2327
#include "PluginInterface.h"
24-
#include "Shared/Debug.h"
28+
#include "omptarget.h"
2529

2630
#include "llvm/ADT/SmallVector.h"
2731
#include "llvm/BinaryFormat/ELF.h"
2832
#include "llvm/Frontend/OpenMP/OMPDeviceConstants.h"
2933
#include "llvm/Support/Error.h"
30-
#include "llvm/TargetParser/Triple.h"
3134

32-
#include "EventSystem.h"
35+
#if !defined(__BYTE_ORDER__) || !defined(__ORDER_LITTLE_ENDIAN__) || \
36+
!defined(__ORDER_BIG_ENDIAN__)
37+
#error "Missing preprocessor definitions for endianness detection."
38+
#endif
39+
40+
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
41+
#define LITTLEENDIAN_CPU
42+
#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
43+
#define BIGENDIAN_CPU
44+
#endif
3345

3446
namespace llvm::omp::target::plugin {
3547

@@ -643,53 +655,67 @@ struct MPIPluginTy : GenericPluginTy {
643655

644656
/// Initialize the plugin and return the number of devices.
645657
Expected<int32_t> initImpl() override {
646-
#ifdef OMPT_SUPPORT
647-
ompt::connectLibrary();
648-
#endif
649-
650658
EventSystem.initialize();
651659
return EventSystem.getNumWorkers();
652660
}
653661

662+
/// Deinitialize the plugin.
654663
Error deinitImpl() override {
655664
EventSystem.deinitialize();
656665
return Plugin::success();
657666
}
658667

659-
/// Create a MPI device.
668+
/// Creates a MPI device.
660669
GenericDeviceTy *createDevice(GenericPluginTy &Plugin, int32_t DeviceId,
661670
int32_t NumDevices) override {
662671
return new MPIDeviceTy(Plugin, DeviceId, NumDevices, EventSystem);
663672
}
664673

674+
/// Creates a MPI global handler.
665675
GenericGlobalHandlerTy *createGlobalHandler() override {
666676
return new MPIGlobalHandlerTy();
667677
}
668678

669679
/// Get the ELF code to recognize the compatible binary images.
670-
uint16_t getMagicElfBits() const override { return ELF::EM_X86_64; }
671-
672-
bool isDataExchangable(int32_t SrcDeviceId, int32_t DstDeviceId) override {
673-
return isValidDeviceId(SrcDeviceId) && isValidDeviceId(DstDeviceId);
680+
uint16_t getMagicElfBits() const override {
681+
return utils::elf::getTargetMachine();
674682
}
675683

676684
/// All images (ELF-compatible) should be compatible with this plugin.
677685
Expected<bool> isELFCompatible(StringRef) const override { return true; }
678686

679-
Triple::ArchType getTripleArch() const override { return Triple::x86_64; }
687+
Triple::ArchType getTripleArch() const override {
688+
#if defined(__x86_64__)
689+
return llvm::Triple::x86_64;
690+
#elif defined(__s390x__)
691+
return llvm::Triple::systemz;
692+
#elif defined(__aarch64__)
693+
#ifdef LITTLEENDIAN_CPU
694+
return llvm::Triple::aarch64;
695+
#else
696+
return llvm::Triple::aarch64_be;
697+
#endif
698+
#elif defined(__powerpc64__)
699+
#ifdef LITTLEENDIAN_CPU
700+
return llvm::Triple::ppc64le;
701+
#else
702+
return llvm::Triple::ppc64;
703+
#endif
704+
#else
705+
return llvm::Triple::UnknownArch;
706+
#endif
707+
}
680708

681-
// private:
682-
// TODO: How to mantain the EventSystem private and still allow the device to
683-
// access it?
709+
const char *getName() const override { return GETNAME(TARGET_NAME); }
710+
711+
private:
684712
EventSystemTy EventSystem;
685713
};
686714

687-
GenericPluginTy *PluginTy::createPlugin() { return new MPIPluginTy(); }
688-
689715
template <typename... ArgsTy>
690716
static Error Plugin::check(int32_t ErrorCode, const char *ErrFmt,
691717
ArgsTy... Args) {
692-
if (ErrorCode == 0)
718+
if (ErrorCode == OFFLOAD_SUCCESS)
693719
return Error::success();
694720

695721
return createStringError<ArgsTy..., const char *>(
@@ -698,3 +724,9 @@ static Error Plugin::check(int32_t ErrorCode, const char *ErrFmt,
698724
}
699725

700726
} // namespace llvm::omp::target::plugin
727+
728+
extern "C" {
729+
llvm::omp::target::plugin::GenericPluginTy *createPlugin_mpi() {
730+
return new llvm::omp::target::plugin::MPIPluginTy();
731+
}
732+
}

0 commit comments

Comments
 (0)