예제 #1
0
static void
handle_stream_json (UfoDaemon *daemon, UfoMessage *msg)
{
    UfoDaemonPrivate *priv = UFO_DAEMON_GET_PRIVATE (daemon);
    gchar *json;
    GList *roots;
    GList *leaves;
    UfoNode *first;
    UfoNode *last;
    GError *error = NULL;

    json = read_json (daemon, msg);
    // send ack
    UfoMessage *response = ufo_message_new (UFO_MESSAGE_ACK, 0);
    ufo_messenger_send_blocking (priv->msger, response, NULL);
    ufo_message_free (response);

    /* Setup local task graph */
    priv->task_graph = UFO_TASK_GRAPH (ufo_task_graph_new ());
    ufo_task_graph_read_from_data (priv->task_graph, priv->manager, json, &error);

#ifdef DEBUG
    ufo_graph_dump_dot (UFO_GRAPH (priv->task_graph), "task_graph_received.dot");
#endif

    if (error != NULL) {
        g_printerr ("%s\n", error->message);
        /* Send error to master */
        return;
    }

    roots = ufo_graph_get_roots (UFO_GRAPH (priv->task_graph));
    g_assert (g_list_length (roots) == 1);

    leaves = ufo_graph_get_leaves (UFO_GRAPH (priv->task_graph));
    g_assert (g_list_length (leaves) == 1);

    first = UFO_NODE (g_list_nth_data (roots, 0));
    last = UFO_NODE (g_list_nth_data (leaves, 0));

    first = remove_dummy_if_present (UFO_GRAPH (priv->task_graph), first);

    priv->input_task = ufo_input_task_new ();
    priv->output_task = ufo_output_task_new (2);

    ufo_graph_connect_nodes (UFO_GRAPH (priv->task_graph),
                             priv->input_task, first,
                             GINT_TO_POINTER (0));

    ufo_graph_connect_nodes (UFO_GRAPH (priv->task_graph),
                             last, priv->output_task,
                             GINT_TO_POINTER (0));

    priv->scheduler_thread = g_thread_create ((GThreadFunc) run_scheduler, daemon, TRUE, NULL);
    g_free (json);
}
예제 #2
0
static void
copy_properties (GObject *dst,
                 GObject *src)
{
    GParamSpec **props;
    guint n_props;

    props = g_object_class_list_properties (G_OBJECT_GET_CLASS (src), &n_props);

    for (guint i = 0; i < n_props; i++) {
        if (props[i]->flags & G_PARAM_WRITABLE) {
            GValue value = {0};

            g_value_init (&value, props[i]->value_type);
            g_object_get_property (src, props[i]->name, &value);

            if (UFO_IS_NODE_CLASS (&(props[i]->value_type))) {
                g_value_set_object (&value, ufo_node_copy_real (UFO_NODE(g_value_get_object(&value)), NULL));
            }

            g_object_set_property (dst, props[i]->name, &value);
        }
    }

    g_free (props);
}
예제 #3
0
static GHashTable *
build_task_groups (UfoBaseScheduler *scheduler, UfoTaskGraph *graph, UfoResources *resources, GList *nodes)
{
    GHashTable *tasks_to_groups;
    GList *it;

    tasks_to_groups = g_hash_table_new (g_direct_hash, g_direct_equal);

    /* Create a group with a single member for each node */
    g_list_for (nodes, it) {
        TaskGroup *group;
        UfoNode *task;
        UfoNode *node;

        task = UFO_NODE (it->data);
        group = g_new0 (TaskGroup, 1);
        group->context = ufo_resources_get_context (resources);
        group->parents = NULL;
        group->tasks = g_list_append (NULL, it->data);
        group->queue = ufo_two_way_queue_new (NULL);
        group->is_leaf = ufo_graph_get_num_successors (UFO_GRAPH (graph), task) == 0;

        if (ufo_task_get_mode (UFO_TASK (task)) & UFO_TASK_MODE_SHARE_DATA) {
            group->mode = TASK_GROUP_SHARED;
        }
        else {
            group->mode = TASK_GROUP_ROUND_ROBIN;
        }

        node = ufo_node_new (group);
        g_hash_table_insert (tasks_to_groups, it->data, node);
    }
예제 #4
0
static gboolean
check_target_connections (UfoTaskGraph *graph,
                          UfoNode *target,
                          guint n_inputs,
                          GError **error)
{
    GList *predecessors;
    GList *it;
    guint16 connection_bitmap;
    guint16 mask;
    gboolean result = TRUE;

    if (n_inputs == 0)
        return TRUE;

    predecessors = ufo_graph_get_predecessors (UFO_GRAPH (graph), target);
    connection_bitmap = 0;

    /* Check all edges and enable bit number for edge label */
    g_list_for (predecessors, it) {
        gpointer label;
        gint input;

        label = ufo_graph_get_edge_label (UFO_GRAPH (graph),
                                          UFO_NODE (it->data), target);
        input = GPOINTER_TO_INT (label);
        g_assert (input >= 0 && input < 16);
        connection_bitmap |= 1 << input;
    }
예제 #5
0
UfoNode *
ufo_node_new (gpointer label)
{
    UfoNode *node;

    node = UFO_NODE (g_object_new (UFO_TYPE_NODE, NULL));
    node->priv->label = label;
    return node;
}
예제 #6
0
UfoNode *
ufo_cpu_node_new (gpointer mask)
{
    UfoCpuNode *node;

    g_return_val_if_fail (mask != NULL, NULL);
    node = UFO_CPU_NODE (g_object_new (UFO_TYPE_CPU_NODE, NULL));
    node->priv->mask = g_memdup (mask, sizeof(cpu_set_t));
    return UFO_NODE (node);
}
예제 #7
0
UfoNode *
ufo_gpu_node_new (gpointer cmd_queue)
{
    UfoGpuNode *node;

    g_return_val_if_fail (cmd_queue != NULL, NULL);
    node = UFO_GPU_NODE (g_object_new (UFO_TYPE_GPU_NODE, NULL));
    node->priv->cmd_queue = cmd_queue;
    clRetainCommandQueue (cmd_queue);

    return UFO_NODE (node);
}
예제 #8
0
static gboolean
expand_group_graph (UfoResources *resources, UfoGraph *graph, GError **error)
{
    GList *nodes;
    GList *it;
    GList *gpu_nodes;
    guint n_gpus;
    gboolean success = TRUE;

    gpu_nodes = ufo_resources_get_gpu_nodes (resources);
    n_gpus = g_list_length (gpu_nodes);

    nodes = ufo_graph_get_nodes (graph);

    g_list_for (nodes, it) {
        TaskGroup *group;
        UfoTaskNode *node;

        group = ufo_node_get_label (UFO_NODE (it->data));
        node = UFO_TASK_NODE (group->tasks->data);

        if (ufo_task_uses_gpu (UFO_TASK (node))) {
            ufo_task_node_set_proc_node (node, g_list_first (gpu_nodes)->data);

            for (guint i = 1; i < n_gpus; i++) {
                UfoTaskNode *copy;

                copy = UFO_TASK_NODE (ufo_node_copy (UFO_NODE (node), error));

                if (copy == NULL) {
                    success = FALSE;
                    goto cleanup;
                }

                ufo_task_node_set_proc_node (copy, g_list_nth_data (gpu_nodes, i));
                group->tasks = g_list_append (group->tasks, copy);
            }
        }
    }
예제 #9
0
static UfoNode *
ufo_node_copy_real (UfoNode *node,
                    GError **error)
{
    UfoNode *orig;
    UfoNode *copy;

    copy = UFO_NODE (g_object_new (G_OBJECT_TYPE (node), NULL));
    orig = node->priv->orig;

    copy_properties (G_OBJECT (copy), G_OBJECT (orig));

    copy->priv->orig = orig;
    copy->priv->label = orig->priv->label;
    copy->priv->index = orig->priv->total;
    orig->priv->total++;

    return copy;
}
예제 #10
0
static UfoNode *
ufo_task_node_copy (UfoNode *node,
                    GError **error)
{
    UfoTaskNode *orig;
    UfoTaskNode *copy;

    copy = UFO_TASK_NODE (UFO_NODE_CLASS (ufo_task_node_parent_class)->copy (node, error));
    orig = UFO_TASK_NODE (node);

    copy->priv->pattern = orig->priv->pattern;

    for (guint i = 0; i < 16; i++)
        copy->priv->n_expected[i] = orig->priv->n_expected[i];

    ufo_task_node_set_plugin_name (copy, orig->priv->plugin);

    return UFO_NODE (copy);
}
예제 #11
0
static UfoNode *
remove_dummy_if_present (UfoGraph *graph,
                         UfoNode *first)
{
    UfoNode *real = first;

    if (UFO_IS_DUMMY_TASK (first)) {
        UfoNode *dummy;
        GList *successors;

        dummy = first;
        successors = ufo_graph_get_successors (graph, dummy);
        g_assert (g_list_length (successors) == 1);
        real = UFO_NODE (successors->data);
        g_list_free (successors);
        ufo_graph_remove_edge (graph, dummy, real);
    }

    return real;
}
예제 #12
0
UfoNode *
ufo_gpu_node_new (gpointer context, gpointer device)
{
    UfoGpuNode *node;
    cl_int errcode;
    cl_command_queue_properties queue_properties;

    g_return_val_if_fail (context != NULL && device != NULL, NULL);

    queue_properties = CL_QUEUE_PROFILING_ENABLE;

    node = UFO_GPU_NODE (g_object_new (UFO_TYPE_GPU_NODE, NULL));
    node->priv->context = context;
    node->priv->device = device;
    node->priv->cmd_queue = clCreateCommandQueue (context, device, queue_properties, &errcode);

    UFO_RESOURCES_CHECK_CLERR (errcode);
    UFO_RESOURCES_CHECK_CLERR (clRetainContext (context));

    return UFO_NODE (node);
}
예제 #13
0
UfoNode *
ufo_null_task_new (void)
{
    return UFO_NODE (g_object_new (UFO_TYPE_NULL_TASK, NULL));
}
예제 #14
0
UfoNode *
ufo_fftmult_task_new (void)
{
    return UFO_NODE (g_object_new (UFO_TYPE_FFTMULT_TASK, NULL));
}
예제 #15
0
static UfoNode *
ufo_cpu_node_copy_real (UfoNode *node,
                        GError **error)
{
    return UFO_NODE (ufo_cpu_node_new (UFO_CPU_NODE (node)->priv->mask));
}
예제 #16
0
UfoNode *
ufo_averager_task_new (void)
{
    return UFO_NODE (g_object_new (UFO_TYPE_AVERAGER_TASK, NULL));
}
예제 #17
0
UfoNode *
ufo_reduce_task_new (void)
{
    return UFO_NODE (g_object_new (UFO_TYPE_REDUCE_TASK, NULL));
}
예제 #18
0
UfoNode *
ufo_transpose_task_new (void)
{
    return UFO_NODE (g_object_new (UFO_TYPE_TRANSPOSE_TASK, NULL));
}
예제 #19
0
UfoNode *
ufo_refeed_task_new (void)
{
    return UFO_NODE (g_object_new (UFO_TYPE_REFEED_TASK, NULL));
}
예제 #20
0
static UfoNode *
ufo_gpu_node_copy_real (UfoNode *node,
                        GError **error)
{
    return UFO_NODE (ufo_gpu_node_new (UFO_GPU_NODE (node)->priv->cmd_queue));
}