Exemplo n.º 1
0
def _make_thread_init(threads, tfunc, isdata, sdata, sregistry):
    d = threads.index
    if threads.size == 1:
        callback = lambda body: body
    else:
        callback = lambda body: Iteration(body, d, threads.size - 1)

    # A unique identifier for each created pthread
    pthreadid = d + threads.base_id

    # Initialize `sdata`
    arguments = list(isdata.parameters)
    arguments[-3] = sdata.symbolic_base + d
    arguments[-2] = pthreadid
    arguments[-1] = sregistry.deviceid
    call0 = Call(isdata.name, arguments)

    # Create pthreads
    call1 = Call('pthread_create', (threads.symbolic_base + d,
                                    Macro('NULL'),
                                    Call(tfunc.name, [], is_indirect=True),
                                    sdata.symbolic_base + d))

    threadsinit = List(
        header=c.Comment("Fire up and initialize `%s`" % threads.name),
        body=callback([call0, call1])
    )

    return threadsinit
Exemplo n.º 2
0
 def merge(self, iter1, iter2):
     """Creates a new merged :class:`Iteration` object from two
     loops along the same dimension.
     """
     newexpr = iter1.nodes + iter2.nodes
     return Iteration(newexpr,
                      dimension=iter1.dim,
                      limits=iter1.limits,
                      offsets=iter1.offsets)
Exemplo n.º 3
0
def _make_thread_finalize(threads, sdata):
    d = threads.index
    if threads.size == 1:
        callback = lambda body: body
    else:
        callback = lambda body: Iteration(body, d, threads.size - 1)

    threadswait = List(
        header=c.Comment("Wait for completion of `%s`" % threads.name),
        body=callback([
            While(CondEq(FieldFromComposite(sdata._field_flag, sdata[d]), 2)),
            DummyExpr(FieldFromComposite(sdata._field_flag, sdata[d]), 0),
            Call('pthread_join', (threads[d], Macro('NULL')))
        ]))

    return threadswait