Exemple #1
0
def _compute_time_on_machine(runfile, i, o, input_shapes, machine, niter):
    """ Computes computation time of funciton graph on a remote machine

    Returns average duration of the computation (time)

    inputs:
        runfile - The program to run on the remote machine
        i       - A Theano graph
        o       - A Theano graph
        input_shapes - A dict mapping input variable to array shape
        machine - A machine on which to run the graph
        niter - The number of times to run the computation in sampling

    outputs:
        A dict mapping apply node to average runtime

    >>> _compute_time_on_machine(runfile, i, o, {x: (10, 10)}, 'receiver.univ.edu', 10)
    {dot(x, Add(x, y)): 0.133, Add(x, y): .0012}

    See Also
    --------
        comptime_dict_cpu
        comptime_dict_gpu
    """

    file = open('_machinefile.txt', 'w')
    file.write(machine)
    file.close()

    # stringify the keys

    variables = theano.gof.graph.variables(i, o)
    if len(set(map(str, variables))) != len(variables):
        raise ValueError("Not all variables have unique names"
                         "Look into theano.gof.utils.give_variables_names")

    known_shapes = shape_of_variables(i, o, input_shapes)

    known_shapes_str = str({str(k): v for k, v in known_shapes.items()})

    stdin, stdout, stderr = os.popen3(
        '''mpiexec -np 1 -machinefile _machinefile.txt python %s%s "%s" %d''' %
        (ape_dir, runfile, known_shapes_str, niter))

    # Send the fgraphs as strings (they will be unpacked on the other end)

    nodes = theano.gof.graph.list_of_nodes(i, o)
    fgraphs = graph_iter(nodes)
    pack_many(fgraphs, stdin)  # This writes to stdin
    stdin.close()  # send termination signal

    # Receive the output from the compute node
    # return stdout.read() + stderr.read()
    message = stdout.read()
    times = ast.literal_eval(message)
    return dict(zip(map(str, nodes), times))
Exemple #2
0
def _compute_time_on_machine(runfile, i, o, input_shapes, machine, niter):
    """ Computes computation time of funciton graph on a remote machine

    Returns average duration of the computation (time)

    inputs:
        runfile - The program to run on the remote machine
        i       - A Theano graph
        o       - A Theano graph
        input_shapes - A dict mapping input variable to array shape
        machine - A machine on which to run the graph
        niter - The number of times to run the computation in sampling

    outputs:
        A dict mapping apply node to average runtime

    >>> _compute_time_on_machine(runfile, i, o, {x: (10, 10)}, 'receiver.univ.edu', 10)
    {dot(x, Add(x, y)): 0.133, Add(x, y): .0012}

    See Also
    --------
        comptime_dict_cpu
        comptime_dict_gpu
    """

    file = open('_machinefile.txt', 'w')
    file.write(machine)
    file.close()

    # stringify the keys

    variables = theano.gof.graph.variables(i, o)
    if len(set(map(str, variables))) != len(variables):
        raise ValueError("Not all variables have unique names"
                         "Look into theano.gof.utils.give_variables_names")


    known_shapes = shape_of_variables(i, o, input_shapes)

    known_shapes_str = str({str(k):v for k,v in known_shapes.items()})

    stdin, stdout, stderr = os.popen3('''mpiexec -np 1 -machinefile _machinefile.txt python %s%s "%s" %d'''%(ape_dir, runfile, known_shapes_str, niter))

    # Send the fgraphs as strings (they will be unpacked on the other end)

    nodes = theano.gof.graph.list_of_nodes(i, o)
    fgraphs = graph_iter(nodes)
    pack_many(fgraphs, stdin) # This writes to stdin
    stdin.close() # send termination signal

    # Receive the output from the compute node
    # return stdout.read() + stderr.read()
    message = stdout.read()
    times = ast.literal_eval(message)
    return  dict(zip(map(str, nodes), times))
Exemple #3
0
def test_comptime_run():
    x = theano.tensor.matrix('x')
    y = theano.tensor.matrix('y')
    z = theano.tensor.dot(x, y)
    inputs, outputs = (x, y), (z,)
    variables = theano.gof.graph.variables(inputs, outputs)

    nodes = theano.gof.graph.list_of_nodes(inputs, outputs)

    theano.gof.utils.give_variables_names(variables)
    map(clean_variable, variables)

    input_shapes = {x: (10, 10), y: (10, 10)}
    known_shapes = shape_of_variables(inputs, outputs, input_shapes)
    known_shapes = {str(k): v for k,v in known_shapes.items()}

    time_comp_fn = lambda ins, outs, num_ins, niter: 1

    fgraphs = list(graph_iter(nodes))
    niter = 3

    results = comptime_run(known_shapes, niter, fgraphs, time_comp_fn)
    assert results == [1]*len(fgraphs)