14
14
#include < cstdint>
15
15
#include < cstdlib>
16
16
#include < cstring>
17
+ #include < list>
17
18
#include < optional>
18
19
#include < string>
19
- #include < list>
20
20
21
+ #include " Shared/Debug.h"
22
+ #include " Utils/ELF.h"
23
+
24
+ #include " EventSystem.h"
21
25
#include " GlobalHandler.h"
22
26
#include " OpenMP/OMPT/Callback.h"
23
27
#include " PluginInterface.h"
24
- #include " Shared/Debug .h"
28
+ #include " omptarget .h"
25
29
26
30
#include " llvm/ADT/SmallVector.h"
27
31
#include " llvm/BinaryFormat/ELF.h"
28
32
#include " llvm/Frontend/OpenMP/OMPDeviceConstants.h"
29
33
#include " llvm/Support/Error.h"
30
- #include " llvm/TargetParser/Triple.h"
31
34
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
33
45
34
46
namespace llvm ::omp::target::plugin {
35
47
@@ -643,53 +655,67 @@ struct MPIPluginTy : GenericPluginTy {
643
655
644
656
// / Initialize the plugin and return the number of devices.
645
657
Expected<int32_t > initImpl () override {
646
- #ifdef OMPT_SUPPORT
647
- ompt::connectLibrary ();
648
- #endif
649
-
650
658
EventSystem.initialize ();
651
659
return EventSystem.getNumWorkers ();
652
660
}
653
661
662
+ // / Deinitialize the plugin.
654
663
Error deinitImpl () override {
655
664
EventSystem.deinitialize ();
656
665
return Plugin::success ();
657
666
}
658
667
659
- // / Create a MPI device.
668
+ // / Creates a MPI device.
660
669
GenericDeviceTy *createDevice (GenericPluginTy &Plugin, int32_t DeviceId,
661
670
int32_t NumDevices) override {
662
671
return new MPIDeviceTy (Plugin, DeviceId, NumDevices, EventSystem);
663
672
}
664
673
674
+ // / Creates a MPI global handler.
665
675
GenericGlobalHandlerTy *createGlobalHandler () override {
666
676
return new MPIGlobalHandlerTy ();
667
677
}
668
678
669
679
// / 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 ();
674
682
}
675
683
676
684
// / All images (ELF-compatible) should be compatible with this plugin.
677
685
Expected<bool > isELFCompatible (StringRef) const override { return true ; }
678
686
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
+ }
680
708
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:
684
712
EventSystemTy EventSystem;
685
713
};
686
714
687
- GenericPluginTy *PluginTy::createPlugin () { return new MPIPluginTy (); }
688
-
689
715
template <typename ... ArgsTy>
690
716
static Error Plugin::check (int32_t ErrorCode, const char *ErrFmt,
691
717
ArgsTy... Args) {
692
- if (ErrorCode == 0 )
718
+ if (ErrorCode == OFFLOAD_SUCCESS )
693
719
return Error::success ();
694
720
695
721
return createStringError<ArgsTy..., const char *>(
@@ -698,3 +724,9 @@ static Error Plugin::check(int32_t ErrorCode, const char *ErrFmt,
698
724
}
699
725
700
726
} // 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