Skip to content

Commit e4c23a5

Browse files
ritvikraoZwFinkadityapbRitvik RaoRitvik Rao
authored
Projections support (#290)
* add pairwise addition/product * add logical reductions * add tests for section-based reductions * wip * reductions are now optimized for numpy types * numpy reductions always preferred when available * added checks that single-value reductions work with sections * add section reduction test * no fstrings allowed * remove unused time import * scookies -> _scookies * add check so overflowing number of futures is not silent * cleanup * remove unused operator import * use newest import * operator import is actually required * make new code flake8 compliant * update * add EP name registration * projections support for groups * added CkRegisterMainChare to list of methods that are now correctly traced * section entry methods are now traced * added registration to ArrayMaps * add registration support for ArrayMap * Add data required for projections to registration * Removed global entryNames/entryNamesLen. Unnecessary 'emStart' parameter removed * Moved entry method name tracking inside charmlib * Do we want to free the memory? * Add '--enable-tracing' option to setup.py * Checkout the charm4py_projections branch for running tests * Temporarily disable the ctypes interface in testing * Add tracing of user events * Add object store implementation * Buffer task until object is available * Fix buffering messages on target PE * Fix segmentation fault with object store * Add some documentation for the object store * Implemented waiting for futures * Add parameter server training example * Add requested flag to futures to avoid multiple requests for the same object * Add ray.wait function * Add async parameter server * Implement ray.put function to insert object in the object store * Merge ray futures and charm futures * Add store option to futures * Check future arguments in group methods * Try ray tasks implementation using charm4py pool * pool example * Remove checking for futures from groups * Stateless tasks and exit calls work * Working stateless tasks implementation * Add more examples * Fix ray.get calls from remote functions * Add fib example to debug MPI issue * For small objects, store them at home * Revert "merge ray into projections support" This reverts commit 44acea4, reversing changes made to 4f65ec6. undo merge of ray due to compilation issues * remove generated files * merge fixes * merge fixes 2 * merge fixes 3 * add back entry names to libRegisterFunc: --------- Co-authored-by: Zane Fink <finkzane@gmail.com> Co-authored-by: Aditya Bhosale <adityapb1546@gmail.com> Co-authored-by: Ritvik Rao <rao1@dt-login01.delta.ncsa.illinois.edu> Co-authored-by: Ritvik Rao <rao1@dt-login02.delta.ncsa.illinois.edu> Co-authored-by: Ritvik Rao <ritvikrao@li-4c4c4544-0039-4610-8033-b2c04f574833.ibm.com>
1 parent 75ffdc2 commit e4c23a5

File tree

6 files changed

+96
-24
lines changed

6 files changed

+96
-24
lines changed

charm4py/charm.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,8 @@ def packMsg(self, destObj, msgArgs, header):
493493
def registerInCharmAs(self, C, charm_type, libRegisterFunc):
494494
charm_type_id = charm_type.type_id
495495
entryMethods = self.classEntryMethods[charm_type_id][C]
496-
# if self.myPe() == 0: print("charm4py:: Registering class " + C.__name__ + " in Charm with " + str(len(entryMethods)) + " entry methods " + str([e.name for e in entryMethods]))
497-
C.idx[charm_type_id], startEpIdx = libRegisterFunc(C.__name__ + str(charm_type_id), len(entryMethods))
498-
# if self.myPe() == 0: print("charm4py:: Chare idx=" + str(C.idx[charm_type_id]) + " ctor Idx=" + str(startEpIdx))
496+
entryNames = [method.name for method in entryMethods]
497+
C.idx[charm_type_id], startEpIdx = libRegisterFunc(C.__name__ + str(charm_type_id), entryNames, len(entryMethods))
499498
for i, em in enumerate(entryMethods):
500499
em.epIdx = startEpIdx + i
501500
self.entryMethods[em.epIdx] = em

charm4py/charmlib/ccharm.pxd

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ cdef extern from "charm.h":
2222
int CmiPhysicalRank(int pe);
2323

2424
void CkRegisterReadonlyExt(const char *name, const char *type, size_t msgSize, char *msg);
25-
void CkRegisterMainChareExt(const char *s, int numEntryMethods, int *chareIdx, int *startEpIdx);
26-
void CkRegisterGroupExt(const char *s, int numEntryMethods, int *chareIdx, int *startEpIdx);
27-
void CkRegisterSectionManagerExt(const char *s, int numEntryMethods, int *chareIdx, int *startEpIdx);
28-
void CkRegisterArrayExt(const char *s, int numEntryMethods, int *chareIdx, int *startEpIdx);
29-
void CkRegisterArrayMapExt(const char *s, int numEntryMethods, int *chareIdx, int *startEpIdx);
25+
void CkRegisterMainChareExt(const char *s, const char **emNames, int emNamesStart, int numEntryMethods, int *chareIdx, int *startEpIdx);
26+
void CkRegisterGroupExt(const char *s, const char **emNames, int emNamesStart, int numEntryMethods, int *chareIdx, int *startEpIdx);
27+
void CkRegisterSectionManagerExt(const char *s, const char **emNames, int emNamesStart, int numEntryMethods, int *chareIdx, int *startEpIdx);
28+
void CkRegisterArrayExt(const char *s, const char **emNames, int emNamesStart, int numEntryMethods, int *chareIdx, int *startEpIdx);
29+
void CkRegisterArrayMapExt(const char *s, const char **emNames, int emNamesStart, int numEntryMethods, int *chareIdx, int *startEpIdx);
3030

3131
int CkCreateGroupExt(int cIdx, int eIdx, int num_bufs, char **bufs, int *buf_sizes);
3232
int CkCreateArrayExt(int cIdx, int ndims, int *dims, int eIdx, int num_bufs, char **bufs, int *buf_sizes, int map_gid, char useAtSync);
@@ -72,6 +72,10 @@ cdef extern from "charm.h":
7272

7373
void CkHapiAddCallback(long stream, void (*cb)(void*, void*), int fid);
7474

75+
int CkTraceRegisterUserEvent(char *EventDesc, int eventID);
76+
void CkTraceBeginUserBracketEvent(int eventID);
77+
void CkTraceEndUserBracketEvent(int eventID);
78+
7579
cdef extern from "conv-header.h":
7680
ctypedef void (*CmiHandler)(void* )
7781
cdef const int CmiReservedHeaderSize

charm4py/charmlib/charmlib_cython.pyx

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ from cpython.ref cimport Py_INCREF
1212
from cpython.mem cimport PyMem_Malloc, PyMem_Realloc, PyMem_Free
1313
from cython.operator cimport dereference
1414

15+
cdef extern from "Python.h":
16+
char* PyUnicode_AsUTF8(object unicode)
17+
18+
from libc.string cimport strcmp
19+
1520
from ..charm import Charm4PyError
1621
from .. import reduction as red
1722
from cpython cimport array
@@ -108,6 +113,17 @@ ctypedef struct CkReductionTypesExt:
108113

109114
cdef extern CkReductionTypesExt charm_reducers
110115

116+
cdef char ** to_cstring_array(list_str):
117+
cdef char **ret = <char **>malloc(len(list_str) * sizeof(char *))
118+
for i in range(len(list_str)):
119+
ret[i] = list_str[i]
120+
return ret
121+
122+
def addStringsToList(targetList, strings):
123+
for idx, currentString in enumerate(strings):
124+
targetList.append(<char*> malloc(len(currentString)))
125+
targetList[idx] = strings[idx]
126+
111127
class CkReductionTypesExt_Wrapper:
112128

113129
def __init__(self):
@@ -347,6 +363,8 @@ class CharmLib(object):
347363
self.direct_copy_supported = (PY_MAJOR_VERSION >= 3)
348364
self.name = 'cython'
349365
self.chareNames = []
366+
self.emNames = []
367+
self.emStart = 0
350368
self.init()
351369
self.ReducerType = CkReductionTypesExt_Wrapper()
352370
#print(charm_reducers.sum_long, charm_reducers.product_ushort, charm_reducers.max_char, charm_reducers.max_float, charm_reducers.min_char)
@@ -503,34 +521,51 @@ class CharmLib(object):
503521
if msg is None: CkRegisterReadonlyExt(n1, n2, 0, NULL)
504522
else: CkRegisterReadonlyExt(n1, n2, len(msg), msg)
505523

506-
def CkRegisterMainchare(self, str name, int numEntryMethods):
524+
def CkRegisterMainchare(self, str name, list entryMethodNames, int numEntryMethods):
507525
self.chareNames.append(name.encode())
508526
cdef int chareIdx, startEpIdx
509-
CkRegisterMainChareExt(self.chareNames[-1], numEntryMethods, &chareIdx, &startEpIdx)
527+
self.emNames += [name.encode() for name in entryMethodNames]
528+
# TODO: do we want to track/free these pointers?
529+
cdef char** c1 = to_cstring_array(self.emNames)
530+
CkRegisterMainChareExt(self.chareNames[-1], c1, self.emStart, numEntryMethods, &chareIdx, &startEpIdx)
531+
self.emStart = len(self.emNames)
510532
return chareIdx, startEpIdx
511533

512-
def CkRegisterGroup(self, str name, int numEntryMethods):
534+
def CkRegisterGroup(self, str name, list entryMethodNames, int numEntryMethods):
513535
self.chareNames.append(name.encode())
514536
cdef int chareIdx, startEpIdx
515-
CkRegisterGroupExt(self.chareNames[-1], numEntryMethods, &chareIdx, &startEpIdx)
537+
self.emNames += [name.encode() for name in entryMethodNames]
538+
cdef char** c1 = to_cstring_array(self.emNames)
539+
CkRegisterGroupExt(self.chareNames[-1], c1, self.emStart, numEntryMethods, &chareIdx, &startEpIdx)
540+
self.emStart = len(self.emNames)
516541
return chareIdx, startEpIdx
517542

518-
def CkRegisterSectionManager(self, str name, int numEntryMethods):
543+
def CkRegisterSectionManager(self, str name, list entryMethodNames, int numEntryMethods):
519544
self.chareNames.append(name.encode())
520545
cdef int chareIdx, startEpIdx
521-
CkRegisterSectionManagerExt(self.chareNames[-1], numEntryMethods, &chareIdx, &startEpIdx)
546+
self.emNames += [name.encode() for name in entryMethodNames]
547+
cdef char** c1 = to_cstring_array(self.emNames)
548+
549+
CkRegisterSectionManagerExt(self.chareNames[-1], c1, self.emStart, numEntryMethods, &chareIdx, &startEpIdx)
550+
self.emStart = len(self.emNames)
522551
return chareIdx, startEpIdx
523552

524-
def CkRegisterArrayMap(self, str name, int numEntryMethods):
553+
def CkRegisterArrayMap(self, str name, list entryMethodNames, int numEntryMethods):
525554
self.chareNames.append(name.encode())
526555
cdef int chareIdx, startEpIdx
527-
CkRegisterArrayMapExt(self.chareNames[-1], numEntryMethods, &chareIdx, &startEpIdx)
556+
self.emNames += [name.encode() for name in entryMethodNames]
557+
cdef char** c1 = to_cstring_array(self.emNames)
558+
CkRegisterArrayMapExt(self.chareNames[-1], c1, self.emStart, numEntryMethods, &chareIdx, &startEpIdx)
559+
self.emStart = len(self.emNames)
528560
return chareIdx, startEpIdx
529561

530-
def CkRegisterArray(self, str name, int numEntryMethods):
562+
def CkRegisterArray(self, str name, list entryMethodNames, int numEntryMethods):
531563
self.chareNames.append(name.encode())
532564
cdef int chareIdx, startEpIdx
533-
CkRegisterArrayExt(self.chareNames[-1], numEntryMethods, &chareIdx, &startEpIdx)
565+
self.emNames += [name.encode() for name in entryMethodNames]
566+
cdef char** c1 = to_cstring_array(self.emNames)
567+
CkRegisterArrayExt(self.chareNames[-1], c1, self.emStart, numEntryMethods, &chareIdx, &startEpIdx)
568+
self.emStart = len(self.emNames)
534569
return chareIdx, startEpIdx
535570

536571
def CkCreateGroup(self, int chareIdx, int epIdx, msg not None):
@@ -852,6 +887,20 @@ class CharmLib(object):
852887
def scheduleTagAfter(self, int tag, double msecs):
853888
CcdCallFnAfter(CcdCallFnAfterCallback, <void*>tag, msecs)
854889

890+
def traceRegisterUserEvent(self, str EventDesc, int eventNum=-1):
891+
cdef bytes py_bytes = EventDesc.encode()
892+
Py_INCREF(py_bytes)
893+
# This memory needs to be managed somehow, I think
894+
cdef char* c_string = py_bytes
895+
cdef int eventID = CkTraceRegisterUserEvent(c_string, eventNum)
896+
return eventID
897+
898+
def traceBeginUserBracketEvent(self, int EventID):
899+
CkTraceBeginUserBracketEvent(EventID)
900+
901+
def traceEndUserBracketEvent(self, int EventID):
902+
CkTraceEndUserBracketEvent(EventID)
903+
855904
def CcsRegisterHandler(self, str handlername, object handler):
856905
cdef bytes handler_bytes = handlername.encode("utf-8")
857906
cdef const char* c_handlername = handler_bytes

charm4py/wait.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def is_tag_cond(root_ast):
192192
idx = idx.n
193193
elif isinstance(idx, ast.Constant):
194194
idx = idx.value
195-
195+
196196
if not isinstance(idx, int):
197197
return None
198198

examples/hello/group_hello.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ def main(args):
2626
group_proxy[0].sayHi(17)
2727

2828

29-
charm.start(main)
29+
charm.start(main)

setup.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Cython.Compiler.Options.annotate = True
1818

1919
build_mpi = False
20-
20+
enable_tracing = False
2121

2222

2323
def get_build_machine():
@@ -149,6 +149,9 @@ def build_libcharm(charm_src_dir, build_dir):
149149
build_num_cores = max(int(os.environ.get('CHARM_BUILD_PROCESSES', multiprocessing.cpu_count() // 2)), 1)
150150
extra_build_opts = os.environ.get('CHARM_EXTRA_BUILD_OPTS', '')
151151

152+
if enable_tracing:
153+
extra_build_opts += " --enable-tracing "
154+
152155
target_machine, os_target, target_layer = get_build_triple(build_mpi)
153156

154157
build_triple = f'{target_layer}-{os_target}-{target_machine}'
@@ -198,17 +201,23 @@ def build_libcharm(charm_src_dir, build_dir):
198201
class custom_install(install, object):
199202

200203
user_options = install.user_options + [
201-
('mpi', None, 'Build libcharm with MPI')
204+
('mpi', None, 'Build libcharm with MPI'),
205+
('enable-tracing', None, 'Build libcharm with tracing enabled')
202206
]
203207

204208
def initialize_options(self):
205209
install.initialize_options(self)
206210
self.mpi = False
211+
self.enable_tracing = False
207212

208213
def finalize_options(self):
209214
global build_mpi
210215
if not build_mpi:
211216
build_mpi = bool(self.mpi)
217+
218+
global enable_tracing
219+
if not enable_tracing:
220+
enable_tracing = bool(self.enable_tracing)
212221
install.finalize_options(self)
213222

214223
def run(self):
@@ -218,17 +227,22 @@ def run(self):
218227
class custom_build_py(build_py, object):
219228

220229
user_options = build_py.user_options + [
221-
('mpi', None, 'Build libcharm with MPI')
230+
('mpi', None, 'Build libcharm with MPI'),
231+
('enable-tracing', None, 'Build libcharm with tracing enabled')
222232
]
223233

224234
def initialize_options(self):
225235
build_py.initialize_options(self)
226236
self.mpi = False
237+
self.enable_tracing = False
227238

228239
def finalize_options(self):
229240
global build_mpi
230241
if not build_mpi:
231242
build_mpi = bool(self.mpi)
243+
global enable_tracing
244+
if not enable_tracing:
245+
enable_tracing = bool(self.enable_tracing)
232246
build_py.finalize_options(self)
233247

234248
def run(self):
@@ -241,17 +255,23 @@ def run(self):
241255
class custom_build_ext(build_ext, object):
242256

243257
user_options = build_ext.user_options + [
244-
('mpi', None, 'Build libcharm with MPI')
258+
('mpi', None, 'Build libcharm with MPI'),
259+
('enable-tracing', None, 'Build libcharm with tracing enabled')
245260
]
246261

247262
def initialize_options(self):
248263
build_ext.initialize_options(self)
249264
self.mpi = False
265+
self.enable_tracing = False
250266

251267
def finalize_options(self):
252268
global build_mpi
253269
if not build_mpi:
254270
build_mpi = bool(self.mpi)
271+
272+
global enable_tracing
273+
if not enable_tracing:
274+
enable_tracing = bool(self.enable_tracing)
255275
build_ext.finalize_options(self)
256276

257277
def run(self):

0 commit comments

Comments
 (0)