Exemple #1
0
def make_ilp(computation, system, startmachine, M=10,
             runtime=None, commtime=None, **kwargs):
    machines = system.machines
    network = system.comm

    #Jobs = map(name, computation.jobs)
    Jobs = computation.jobs
    Agents = machines
    PP = computation.precedence()
    P = defaultdict(lambda:0)
    for a,b in PP:
        P[name(a), name(b)] = PP[a,b]
    B = B_machine_ability(computation, system, startmachine)
    # runtimes  =  compute_runtimes(computation, system, **kwargs)
    # commtimes = compute_commtimes(computation, system, **kwargs)
    runtime  = runtime  or make_runtime_fn(computation, system, **kwargs)
    commtime = commtime or make_commtime_fn(computation, system, **kwargs)
    D = FunctionDict(runtime)
    C = FunctionDict(commtime)
    R = defaultdict(lambda:0)
    prob, X, S, Cmax = schedule(Jobs, Agents, D, C, R, B, P, M)

    prob.solver = pulp.LpSolverDefault
    prob.solver.maxSeconds = M

    return prob, X, S, Cmax#, runtimes, commtimes
Exemple #2
0
c = AXPY(1, X, Y)
d = AXPY(1, X+Y, Z)
e = AXPY(1, A+B+C, X+Y+Z)

# a -> b -> c
# d -> e --/

comp = a+b+c+d+e
agents = (0, 1)

compcost = lambda j, a: 1.0
commcost = lambda j, a, b: 0 if a==b else 1.5

from tompkins import schedule

dags, sched, makespan = schedule(comp.dict_io(), agents, compcost, commcost,
        send=isend, recv=irecv)

jobson = {s[0]: s[2] for s in sched}
times  = {s[0]: s[1] for s in sched}

def test_makespan():
    assert makespan == 4.5

def test_sched():
    assert jobson[a] != jobson[c]
    assert jobson[b] != jobson[d]

    assert times[c] == 0
    assert times[a] <= 1.5
    assert 1.0 in (times[b], times[d])
Exemple #3
0
def distribute(inputs, outputs, input_shapes, machines, commtime, comptime, makespan=100):
    known_shapes = shape_of_variables(inputs, outputs, input_shapes)
    variables = theano.gof.graph.variables(inputs, outputs)

    dag, dinputs, doutputs = dicdag.theano.theano_graph_to_dag(inputs, outputs)
    vars = set.union(set(dinputs), set(doutputs), set(dag.keys()),
            {v for value in dag.values() for v in value['args']})
    assert len(vars) == len(map(str, vars))

    unidag = dicdag.unidag.dag_to_unidag(dag)

    # TODO: This should be an input
    is_gpu       = lambda    m: machines[m]['type'] == 'gpu'
    can_start_on = lambda v, m: not is_gpu(m)
    can_end_on   = lambda v, m: not is_gpu(m)

    def dag_commtime(job, a, b):
        inputs, op, output = job
        return commtime(output, a, b)
    def dag_comptime(job, a):
        if job[1]==dicdag.index:
            return 0
        return comptime(make_apply(*job), a)

    # Compute Schedule
    dags, sched, makespan = tompkins.schedule(
            unidag, machines, dag_comptime, dag_commtime,
            lambda j:0, lambda j,a:1, makespan)

    cleaner_dags = fmap(replace_send_recvs, dags)

    full_dags  = fmap(dicdag.unidag.unidag_to_dag, cleaner_dags)
    check_send_recv(full_dags)

    merge_dags = merge_gpu_dags(full_dags, machines)
    check_send_recv(merge_dags)

    rankfile = {machine: i for i, machine in enumerate(sorted(merge_dags))}

    theano_graphs = {machine: dag_to_theano_graph(dag,
                     make_ith_output(rankfile, tagof, known_shapes, machine))
                            for machine, dag in merge_dags.items()}

    # Check that all inputs and outputs are inputs/outputs to the computation
    # or mpi
    def valid_inp(x):
        return x.name in map(str, inputs)
    def valid_out(x):
        return x.name in map(str, outputs) or 'mpi_token' in str(x)
    assert all(valid_inp(x) for g in theano_graphs.values()
                            for x in g[0])
    assert all(valid_out(x) for g in theano_graphs.values()
                            for x in g[1])

    if not all(count == 2 for count in tagof.counts.values()):
        print "issue with tag counts"
        for x in tagof.counts:          print x
        for x in tagof.cache:           print x

    scheds = tompkins_to_theano_scheds(sched, machines)

    return theano_graphs, scheds, rankfile, makespan