-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpi.py
More file actions
180 lines (149 loc) · 5.71 KB
/
gpi.py
File metadata and controls
180 lines (149 loc) · 5.71 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import ctypes
import os
import numpy as np
import numpy.ctypeslib as npct
from common import Gettable, Subscribable
script_dir = os.path.dirname(__file__)
lib_dir = os.path.join(script_dir,'./lib/libPyGPI.so')
data_t = ctypes.c_float
np_data_t_p = npct.ndpointer(dtype=np.float32, ndim=1, flags='CONTIGUOUS')
libgpi = npct.load_library(lib_dir, ".")
#########################
### GaspiCxx Runtime
#########################
# gaspi::Runtime* Gaspi_Runtime_new()
libgpi.Gaspi_Runtime_new.argtypes = []
libgpi.Gaspi_Runtime_new.restype = ctypes.c_void_p
# void Gaspi_Runtime_del(gaspi::Runtime* self)
libgpi.Gaspi_Runtime_del.argtypes = [ctypes.c_void_p]
libgpi.Gaspi_Runtime_del.restype = ctypes.c_void_p
# int Gaspi_Runtime_getGlobalRank(gaspi::Runtime* self)
libgpi.Gaspi_Runtime_getGlobalRank.argtypes = [ctypes.c_void_p]
libgpi.Gaspi_Runtime_getGlobalRank.restype = ctypes.c_int
# int Gaspi_Runtime_getGlobalSize(gaspi::Runtime* self)
libgpi.Gaspi_Runtime_getGlobalSize.argtypes = [ctypes.c_void_p]
libgpi.Gaspi_Runtime_getGlobalSize.restype = ctypes.c_int
# void Gaspi_Runtime_barrier(gaspi::Runtime* self)
libgpi.Gaspi_Runtime_barrier.argtypes = [ctypes.c_void_p]
libgpi.Gaspi_Runtime_barrier.restype = ctypes.c_void_p
# void Gaspi_Runtime_flush(gaspi::Runtime* self)
libgpi.Gaspi_Runtime_flush.argtypes = [ctypes.c_void_p]
libgpi.Gaspi_Runtime_flush.restype = ctypes.c_void_p
#########################
### GaspiCxx Segment
#########################
# gaspi::segment::Segment* Gaspi_Segment_new(int size)
libgpi.Gaspi_Segment_new.argtypes = [ctypes.c_int]
libgpi.Gaspi_Segment_new.restype = ctypes.c_void_p
# void Gaspi_Segment_del(gaspi::segment::Segment* self)
libgpi.Gaspi_Segment_del.argtypes = [ctypes.c_void_p]
libgpi.Gaspi_Segment_del.restype = ctypes.c_void_p
############################
### GaspiCxx initGaspiCxx()
############################
# void Gaspi_initGaspiCxx()
libgpi.Gaspi_initGaspiCxx.argtypes = []
libgpi.Gaspi_initGaspiCxx.restype = ctypes.c_void_p
#########################
### GaspiEnvironment
#########################
# GaspiEnvironment* GaspiEnvironment_new(int segment_size)
libgpi.GaspiEnvironment_new.argtypes = [ctypes.c_int]
libgpi.GaspiEnvironment_new.restype = ctypes.c_void_p
# void GaspiEnvironment_del(GaspiEnvironment* self)
libgpi.GaspiEnvironment_del.argtypes = [ctypes.c_void_p]
libgpi.GaspiEnvironment_del.restype = ctypes.c_void_p
# int GaspiEnvironment_get_rank(GaspiEnvironment* self)
libgpi.GaspiEnvironment_get_rank.argtypes = [ctypes.c_void_p]
libgpi.GaspiEnvironment_get_rank.restype = ctypes.c_int
# int GaspiEnvironment_get_ranks(GaspiEnvironment* self)
libgpi.GaspiEnvironment_get_ranks.argtypes = [ctypes.c_void_p]
libgpi.GaspiEnvironment_get_ranks.restype = ctypes.c_int
# void GaspiEnvironment_barrier(GaspiEnvironment* self)
libgpi.GaspiEnvironment_barrier.argtypes = [ctypes.c_void_p]
libgpi.GaspiEnvironment_barrier.restype = ctypes.c_void_p
# void GaspiEnvironment_flush(GaspiEnvironment* self)
libgpi.GaspiEnvironment_flush.argtypes = [ctypes.c_void_p]
libgpi.GaspiEnvironment_flush.restype = ctypes.c_void_p
#########################
### GPI Functions
#########################
# void Gaspi_Printf(const char* msg)
libgpi.Gaspi_Printf.argtypes = [ctypes.c_char_p]
libgpi.Gaspi_Printf.restype = ctypes.c_void_p
###########################
# Gaspi_Runtime
###########################
class Gaspi_Runtime(Gettable, Subscribable):
def __init__(self):
super().__init__()
self.obj = libgpi.Gaspi_Runtime_new()
def __enter__(self):
return self
def __del__(self):
super().__del__()
libgpi.Gaspi_Runtime_del(self.obj)
self.obj = None
def __exit__(self, exception_type, exception_value, traceback):
super().__del__()
libgpi.Gaspi_Runtime_del(self.obj)
self.obj=None
def getGlobalRank(self):
return libgpi.Gaspi_Runtime_getGlobalRank(self.obj)
def getGlobalSize(self):
return libgpi.Gaspi_Runtime_getGlobalSize(self.obj)
def barrier(self):
libgpi.Gaspi_Runtime_barrier(self.obj)
def flush(self):
libgpi.Gaspi_Runtime_flush(self.obj)
###########################
# Gaspi_Segment
###########################
class Gaspi_Segment(Gettable, Subscribable):
def __init__(self, size):
super().__init__()
self.obj = libgpi.Gaspi_Segment_new(size)
def __enter__(self):
return self
def __del__(self):
if self.obj is not None:
super().__del__()
libgpi.Gaspi_Segment_del(self.obj)
self.obj=None
def __exit__(self, exception_type, exception_value, traceback):
libgpi.Gaspi_Segment_del(self.obj)
self.obj=None
############################
### GaspiCxx initGaspiCxx()
############################
def initGaspiCxx():
libgpi.Gaspi_initGaspiCxx()
###########################
# GaspiEnvironment
###########################
class GaspiEnvironment(Gettable):
def __init__(self, size):
super().__init__()
self.obj = libgpi.GaspiEnvironment_new(size)
def __enter__(self):
return self
def __del__(self):
if self.obj is not None:
libgpi.GaspiEnvironment_del(self.obj)
self.obj=None
def __exit__(self, exception_type, exception_value, traceback):
libgpi.GaspiEnvironment_del(self.obj)
self.obj=None
def get_rank(self):
return libgpi.GaspiEnvironment_get_rank(self.obj)
def get_ranks(self):
return libgpi.GaspiEnvironment_get_ranks(self.obj)
def barrier(self):
libgpi.GaspiEnvironment_barrier(self.obj)
def flush(self):
libgpi.GaspiEnvironment_flush(self.obj)
###########################
# GPI
###########################
def gaspi_printf(message):
libgpi.Gaspi_Printf(bytes(message,encoding="utf-8"))