Debian Codegraph @

prov/psm3/inc/ofi_shm_p2p.h

raw symbols SCIP
1 /*
2 * (C) Copyright 2023 UT-Battelle, LLC. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
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 /* _OFI_SHM_P2P_H_ */
134