| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
#if HAVE_CONFIG_H |
| 34 |
#include <config.h> |
| 35 |
#endif |
| 36 |
|
| 37 |
#include <ofi_cma.h> |
| 38 |
#include <ofi_xpmem.h> |
| 39 |
#include <ofi.h> |
| 40 |
#include <ofi_iov.h> |
| 41 |
|
| 42 |
#ifndef _OFI_SHM_P2P_H_ |
| 43 |
#define _OFI_SHM_P2P_H_ |
| 44 |
|
| 45 |
enum ofi_shm_p2p_type { |
| 46 |
FI_SHM_P2P_XPMEM, |
| 47 |
FI_SHM_P2P_CMA, |
| 48 |
FI_SHM_P2P_DSA, |
| 49 |
}; |
| 50 |
|
| 51 |
struct ofi_shm_p2p_ops { |
| 52 |
bool initialized; |
| 53 |
int (*init)(void); |
| 54 |
int (*cleanup)(void); |
| 55 |
int (*copy)(struct iovec *local, unsigned long local_cnt, |
| 56 |
struct iovec *remote, unsigned long remote_cnt, |
| 57 |
size_t total, pid_t pid, bool write, void *user_data); |
| 58 |
}; |
| 59 |
|
| 60 |
static inline int ofi_shm_p2p_no_init(void) |
| 61 |
{ |
| 62 |
return FI_SUCCESS; |
| 63 |
} |
| 64 |
|
| 65 |
static inline int ofi_shm_p2p_no_cleanup(void) |
| 66 |
{ |
| 67 |
return FI_SUCCESS; |
| 68 |
} |
| 69 |
|
| 70 |
static inline int |
| 71 |
ofi_shm_p2p_no_copy(struct iovec *local, unsigned long local_cnt, |
| 72 |
struct iovec *remote, unsigned long remote_cnt, |
| 73 |
size_t total, pid_t pid, bool write, void *user_data) |
| 74 |
{ |
| 75 |
return -FI_ENOSYS; |
| 76 |
} |
| 77 |
|
| 78 |
static struct ofi_shm_p2p_ops p2p_ops[] = { |
| 79 |
[FI_SHM_P2P_XPMEM] = { |
| 80 |
.initialized = false, |
| 81 |
.init = ofi_xpmem_init, |
| 82 |
.cleanup = ofi_xpmem_cleanup, |
| 83 |
.copy = ofi_xpmem_copy, |
| 84 |
}, |
| 85 |
[FI_SHM_P2P_CMA] = { |
| 86 |
.initialized = false, |
| 87 |
.init = ofi_shm_p2p_no_init, |
| 88 |
.cleanup = ofi_shm_p2p_no_cleanup, |
| 89 |
.copy = cma_copy, |
| 90 |
}, |
| 91 |
[FI_SHM_P2P_DSA] = { |
| 92 |
.initialized = false, |
| 93 |
.init = ofi_shm_p2p_no_init, |
| 94 |
.cleanup = ofi_shm_p2p_no_cleanup, |
| 95 |
.copy = ofi_shm_p2p_no_copy, |
| 96 |
}, |
| 97 |
}; |
| 98 |
|
| 99 |
static inline void ofi_shm_p2p_init(void) |
| 100 |
{ |
| 101 |
int rc; |
| 102 |
enum ofi_shm_p2p_type p2p_type; |
| 103 |
|
| 104 |
for (p2p_type = 0; p2p_type < ARRAY_SIZE(p2p_ops); p2p_type++) { |
| 105 |
rc = p2p_ops[p2p_type].init(); |
| 106 |
if (!rc) |
| 107 |
p2p_ops[p2p_type].initialized = true; |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
static inline void ofi_shm_p2p_cleanup(void) |
| 112 |
{ |
| 113 |
int rc; |
| 114 |
enum ofi_shm_p2p_type p2p_type; |
| 115 |
|
| 116 |
for (p2p_type = 0; p2p_type < ARRAY_SIZE(p2p_ops); p2p_type++) { |
| 117 |
rc = p2p_ops[p2p_type].cleanup(); |
| 118 |
if (!rc) |
| 119 |
p2p_ops[p2p_type].initialized = false; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
static inline int |
| 124 |
ofi_shm_p2p_copy(enum ofi_shm_p2p_type p2p_type, struct iovec *local, |
| 125 |
unsigned long local_cnt, struct iovec *remote, |
| 126 |
unsigned long remote_cnt, size_t total, int64_t id, |
| 127 |
bool write, void *user_data) |
| 128 |
{ |
| 129 |
return p2p_ops[p2p_type].copy(local, local_cnt, remote, |
| 130 |
remote_cnt, total, id, write, user_data); |
| 131 |
} |
| 132 |
|
| 133 |
#endif |
| 134 |
|