/builds/2mk6rsew/0/parcoach/parcoach/src/include/parcoach/Collectives.h
Line | Count | Source |
1 | | #pragma once |
2 | | |
3 | | #include "parcoach/Paradigms.h" |
4 | | |
5 | | #include "llvm/ADT/StringRef.h" |
6 | | |
7 | | #include <string> |
8 | | |
9 | | namespace llvm { |
10 | | class Function; |
11 | | class Value; |
12 | | class CallInst; |
13 | | } // namespace llvm |
14 | | |
15 | | namespace parcoach { |
16 | | // Naive implementation for now, we may want to introduce a real class hierarchy |
17 | | // if we need more feature on this. |
18 | | struct Collective { |
19 | | enum class Kind { |
20 | | #define COLLECTIVE(Name) C_##Name, |
21 | | #define MPI_COLLECTIVE(Name, CommArgId) COLLECTIVE(Name) |
22 | | #include "MPIRegistry.def" |
23 | | #ifdef PARCOACH_ENABLE_OPENMP |
24 | | #define OMP_COLLECTIVE(Name) COLLECTIVE(Name) |
25 | | #include "OMPRegistry.def" |
26 | | #endif |
27 | | #ifdef PARCOACH_ENABLE_UPC |
28 | | #define UPC_COLLECTIVE(Name) COLLECTIVE(Name) |
29 | | #include "UPCRegistry.def" |
30 | | #endif |
31 | | #ifdef PARCOACH_ENABLE_CUDA |
32 | | #define CUDA_COLLECTIVE(Name, FunctionName) COLLECTIVE(Name) |
33 | | #include "CUDARegistry.def" |
34 | | #endif |
35 | | #undef COLLECTIVE |
36 | | C_Last |
37 | | }; |
38 | | std::string const Name; |
39 | | // Unique collective identifier |
40 | | Kind const K; |
41 | | bool enabled() const; |
42 | 32.1k | Paradigm getParadigm() const { return P_; } |
43 | | static bool isCollective(llvm::Function const &); |
44 | | static Collective const *find(llvm::Function const &); |
45 | | Collective(Collective const &) = default; |
46 | | |
47 | | protected: |
48 | | Collective(Paradigm P, Kind K, llvm::StringRef Name) |
49 | 70.4k | : Name(Name), K(K), P_(P) {} |
50 | | |
51 | | private: |
52 | | Paradigm const P_; |
53 | | }; |
54 | | |
55 | | struct MPICollective : Collective { |
56 | | MPICollective(Kind K, llvm::StringRef Name, size_t ArgId) |
57 | 68.6k | : Collective(Paradigm::MPI, K, Name), CommArgId(ArgId) {} |
58 | | int const CommArgId; |
59 | 18.4k | static bool classof(Collective const *C) { |
60 | 18.4k | return C->getParadigm() == Paradigm::MPI; |
61 | 18.4k | } |
62 | | llvm::Value *getCommunicator(llvm::CallInst const &CI) const; |
63 | | }; |
64 | | |
65 | | #ifdef PARCOACH_ENABLE_OPENMP |
66 | | struct OMPCollective : Collective { |
67 | | OMPCollective(Kind K, llvm::StringRef Name) |
68 | 1.76k | : Collective(Paradigm::OMP, K, Name) {} |
69 | 13.7k | static bool classof(Collective const *C) { |
70 | 13.7k | return C->getParadigm() == Paradigm::OMP; |
71 | 13.7k | } |
72 | | }; |
73 | | #endif |
74 | | |
75 | | #ifdef PARCOACH_ENABLE_CUDA |
76 | | struct CudaCollective : Collective { |
77 | | CudaCollective(Kind K, llvm::StringRef Name) |
78 | | : Collective(Paradigm::CUDA, K, Name) {} |
79 | | static bool classof(Collective const *C) { |
80 | | return C->getParadigm() == Paradigm::CUDA; |
81 | | } |
82 | | }; |
83 | | #endif |
84 | | |
85 | | #ifdef PARCOACH_ENABLE_UPC |
86 | | struct UPCCollective : Collective { |
87 | | UPCCollective(Kind K, llvm::StringRef Name) |
88 | | : Collective(Paradigm::UPC, K, Name) {} |
89 | | static bool classof(Collective const *C) { |
90 | | return C->getParadigm() == Paradigm::UPC; |
91 | | } |
92 | | }; |
93 | | #endif |
94 | | } // namespace parcoach |