Example #1
0
 def buildMainchare(onPe, objPtr, ep, argc, argv):
     try:
         objPtr = int(ffi.cast("uintptr_t", objPtr))
         charm.buildMainchare(
             onPe, objPtr, ep,
             [ffi.string(argv[i]).decode() for i in range(argc)])
     except:
         charm.handleGeneralError()
Example #2
0
 def recvChareMsg_py3(onPe, objPtr, ep, msgSize, msg, dcopy_start):
     try:
         t0 = None
         if charm.opts.PROFILING:
             t0 = time.time()
             charm.msg_recv_sizes.append(msgSize)
         objPtr = int(ffi.cast("uintptr_t", objPtr))
         charm.recvChareMsg((onPe, objPtr), ep, ffi.buffer(msg, msgSize),
                            t0, dcopy_start)
     except:
         charm.handleGeneralError()
Example #3
0
 def recvArrayMsg_py3(aid, ndims, arrayIndex, ep, msgSize, msg,
                      dcopy_start):
     try:
         t0 = None
         if charm.opts.PROFILING:
             t0 = time.time()
             charm.msg_recv_sizes.append(msgSize)
         arrIndex = tuple(ffi.cast(index_ctype[ndims], arrayIndex))
         charm.recvArrayMsg(aid, arrIndex, ep, ffi.buffer(msg, msgSize), t0,
                            dcopy_start)
     except:
         charm.handleGeneralError()
Example #4
0
 def resumeFromSync(aid, ndims, arrayIndex):
     try:
         t0 = None
         if charm.opts.PROFILING: t0 = time.time()
         arrIndex = tuple(ffi.cast(index_ctype[ndims], arrayIndex))
         charm.recvArrayMsg(aid,
                            arrIndex,
                            -1,
                            None,
                            t0,
                            -1,
                            resumeFromSync=True)
     except:
         charm.handleGeneralError()
Example #5
0
 def CkChareSend(self, chare_id, ep, msg):
     msg0, dcopy = msg
     objPtr = ffi.cast("void*", chare_id[1])
     if len(dcopy) == 0:
         lib.CkChareExtSend(chare_id[0], objPtr, ep, msg0, len(msg0))
     else:
         self.send_bufs[0] = ffi.from_buffer(msg0)
         self.send_buf_sizes[0] = len(msg0)
         for i, buf in enumerate(dcopy):
             self.send_bufs[i + 1] = ffi.from_buffer(buf)
             self.send_buf_sizes[i + 1] = buf.nbytes
         lib.CkChareExtSend_multi(chare_id[0], objPtr, ep,
                                  len(dcopy) + 1, self.send_bufs,
                                  self.send_buf_sizes)
Example #6
0
 def arrayElemJoin_py3(aid, ndims, arrayIndex, ep, msg, msgSize):
     try:
         t0 = None
         if charm.opts.PROFILING:
             t0 = time.time()
             charm.msg_recv_sizes.append(msgSize)
         arrIndex = tuple(ffi.cast(index_ctype[ndims], arrayIndex))
         charm.recvArrayMsg(aid,
                            arrIndex,
                            ep,
                            ffi.buffer(msg, msgSize),
                            t0,
                            -1,
                            migration=True)
     except:
         charm.handleGeneralError()
Example #7
0
 def arrayElemLeave(aid, ndims, arrayIndex, pdata, sizing):
     try:
         if charm.opts.PROFILING: t0 = time.time()
         arrIndex = tuple(ffi.cast(index_ctype[ndims], arrayIndex))
         msg = charm.arrayElemLeave(aid, arrIndex, bool(sizing))
         if sizing:
             pdata[0] = ffi.NULL
         else:
             CharmLib.tempData = msg  # save msg, else it might be deleted before returning control to libcharm
             pdata[0] = ffi.from_buffer(CharmLib.tempData)
         if charm.opts.PROFILING:
             global times
             times[2] += (time.time() - t0)
         return len(msg)
     except:
         charm.handleGeneralError()
Example #8
0
 def __init__(self, _charm, opts, libcharm_path):
     global charm, ReducerType, c_type_table, times
     self.direct_copy_supported = (sys.version_info[0] >= 3
                                   )  # requires Python 3
     charm = _charm
     self.name = 'cffi'
     self.chareNames = []
     self.init()
     ReducerType = ffi.cast('struct CkReductionTypesExt*',
                            lib.getReducersStruct())
     self.ReducerType = ReducerType
     times = [
         0.0
     ] * 3  # track time in [charm reduction callbacks, custom reduction, outgoing object migration]
     self.times = times
     self.send_bufs = ffi.new(
         "char*[]",
         60)  # supports up to 60 direct-copy entry method arguments
     self.send_buf_sizes = ffi.new("int[]", [0] * 60)
     c_type_table = [None] * 10
     c_type_table[red.C_CHAR] = ('char', 'char[]', 'char*',
                                 ffi.sizeof('char'))
     c_type_table[red.C_SHORT] = ('short', 'short[]', 'short*',
                                  ffi.sizeof('short'))
     c_type_table[red.C_INT] = ('int', 'int[]', 'int*', ffi.sizeof('int'))
     c_type_table[red.C_LONG] = ('long', 'long[]', 'long*',
                                 ffi.sizeof('long'))
     c_type_table[red.C_UCHAR] = ('unsigned char', 'unsigned char[]',
                                  'unsigned char*',
                                  ffi.sizeof('unsigned char'))
     c_type_table[red.C_USHORT] = ('unsigned short', 'unsigned short[]',
                                   'unsigned short*',
                                   ffi.sizeof('unsigned short'))
     c_type_table[red.C_UINT] = ('unsigned int',
                                 'unsigned int[]', 'unsigned int*',
                                 ffi.sizeof('unsigned int'))
     c_type_table[red.C_ULONG] = ('unsigned long', 'unsigned long[]',
                                  'unsigned long*',
                                  ffi.sizeof('unsigned long'))
     c_type_table[red.C_FLOAT] = ('float', 'float[]', 'float*',
                                  ffi.sizeof('float'))
     c_type_table[red.C_DOUBLE] = ('double', 'double[]', 'double*',
                                   ffi.sizeof('double'))
Example #9
0
    def cpickleData_py3(data, dataSize, reducerType, returnBuffers,
                        returnBufferSizes):
        try:
            if charm.opts.PROFILING: t0 = time.time()
            header = {}
            if reducerType != ReducerType.nop:
                ctype = charm.redMgr.charm_reducer_to_ctype[reducerType]
                dataTypeTuple = c_type_table[ctype]
                numElems = dataSize // dataTypeTuple[3]
                if numElems == 1:
                    pyData = [ffi.cast(dataTypeTuple[2], data)[0]]
                else:
                    if haveNumpy:
                        dtype = charm.redMgr.rev_np_array_type_map[ctype]
                        header[b'dcopy'] = [(0, 2, (numElems, dtype), dataSize)
                                            ]
                    else:
                        array_typecode = charm.redMgr.rev_array_type_map[ctype]
                        header[b'dcopy'] = [(0, 1, (array_typecode), dataSize)]
                    returnBuffers[1] = data
                    returnBufferSizes[1] = dataSize
                    pyData = [None]
            else:
                pyData = []

            msg = (header, pyData)
            # save msg, else it might be deleted before returning control to libcharm
            CharmLib.tempData = cPickle.dumps(msg, charm.opts.PICKLE_PROTOCOL)
            returnBuffers[0] = ffi.from_buffer(CharmLib.tempData)
            returnBufferSizes[0] = len(CharmLib.tempData)

            if charm.opts.PROFILING:
                global times
                times[0] += (time.time() - t0)

        except:
            charm.handleGeneralError()
Example #10
0
 def CkContributeToChare(self, contributeInfo, cid):
     objPtr = ffi.cast("void*", cid[1])
     lib.CkExtContributeToChare(contributeInfo.data, cid[0], objPtr)