Exemplo n.º 1
0
/**
 * ufo_op_gradient_descent:
 * @arg: A #UfoBuffer
 * @out: A #UfoBuffer
 * @resources: #UfoResources object
 * @command_queue: A valid cl_command_queue
 *
 * Returns: (transfer full): Event of the POSC operation
 */
gpointer
ufo_op_gradient_descent (UfoBuffer *arg,
                         UfoBuffer *out,
                         UfoResources *resources,
                         gpointer command_queue)
{
    UfoRequisition arg_requisition;
    cl_event event;
    GError *error = NULL;
    static GMutex mutex;

    ufo_buffer_get_requisition (arg, &arg_requisition);
    ufo_buffer_resize (out, &arg_requisition);

    cl_mem d_arg = ufo_buffer_get_device_image (arg, command_queue);
    cl_mem d_out = ufo_buffer_get_device_image (out, command_queue);

    cl_kernel kernel = ufo_resources_get_cached_kernel (resources, OPS_FILENAME, "descent_grad", &error);

    if (error) {
        g_error ("%s\n", error->message);
    }

    g_mutex_lock (&mutex);
    UFO_RESOURCES_CHECK_CLERR (clSetKernelArg(kernel, 0, sizeof(void *), (void *) &d_arg));
    UFO_RESOURCES_CHECK_CLERR (clSetKernelArg(kernel, 1, sizeof(void *), (void *) &d_out));

    UFO_RESOURCES_CHECK_CLERR (clEnqueueNDRangeKernel (command_queue, kernel,
                                                       arg_requisition.n_dims, NULL, arg_requisition.dims,
                                                       NULL, 0, NULL, &event));
    g_mutex_unlock (&mutex);

    return event;
}
Exemplo n.º 2
0
static void
handle_send_inputs (UfoDaemon *daemon, UfoMessage *request)
{
    UfoDaemonPrivate *priv = UFO_DAEMON_GET_PRIVATE (daemon);
    gpointer context = ufo_scheduler_get_context (priv->scheduler);

    UfoRequisition *requisition = (UfoRequisition *) request->data;
   
    // send the ack for that 
    UfoMessage *response = ufo_message_new (UFO_MESSAGE_ACK, 0);
    ufo_messenger_send_blocking (priv->msger, response, NULL);
    ufo_message_free (response);

    if (priv->input == NULL) {
        priv->input = ufo_buffer_new (requisition, NULL, context);
    }
    else {
        if (ufo_buffer_cmp_dimensions (priv->input, requisition))
            ufo_buffer_resize (priv->input, requisition);
    }
    
    UfoMessage *data_msg = ufo_messenger_recv_blocking (priv->msger, NULL);
    response = ufo_message_new (UFO_MESSAGE_ACK, 0);
    ufo_messenger_send_blocking (priv->msger, response, NULL);
    ufo_message_free (response);

    g_assert (ufo_buffer_get_size (priv->input) == data_msg->data_size);
    ufo_buffer_set_host_array (priv->input, data_msg->data);

    ufo_input_task_release_input_buffer (UFO_INPUT_TASK (priv->input_task), priv->input);
    g_free (data_msg);
}
Exemplo n.º 3
0
static gboolean
ufo_ir_sart_process_real (UfoMethod *method,
                          UfoBuffer *input,
                          UfoBuffer *output)
{
    UfoIrSARTPrivate *priv = UFO_IR_SART_GET_PRIVATE (method);

    UfoResources *resources = NULL;
    UfoProjector *projector = NULL;
    gpointer     *cmd_queue = NULL;
    gfloat        relaxation_factor = 0;
    guint         max_iterations = 0;
    g_object_get (method,
                  "ufo-resources", &resources,
                  "command-queue", &cmd_queue,
                  "projection-model", &projector,
                  "relaxation-factor", &relaxation_factor,
                  "max-iterations", &max_iterations,
                  NULL);

    UfoGeometry *geometry = NULL;
    g_object_get (projector, "geometry", &geometry, NULL);

    //
    // resize
    UfoBuffer **method_buffers[4] = {
        &priv->singular_volume,
        &priv->singular_sino,
        &priv->ray_weights,
        &priv->b_temp
    };
    UfoBuffer *ref_buffers[4] = {
        output,
        input,
        input,
        input
    };
    for (guint i = 0; i < 4; ++i) {
        UfoRequisition _req;
        if (*method_buffers[i]) {
            ufo_buffer_get_requisition (ref_buffers[i], &_req);
            ufo_buffer_resize (*method_buffers[i], &_req);
        } else {
            *method_buffers[i] = ufo_buffer_dup (ref_buffers [i]);
        }
    }
    ufo_op_set (priv->singular_volume, 1.0f, resources, cmd_queue);
    ufo_op_set (priv->singular_sino, 1.0f, resources, cmd_queue);
    ufo_op_set (priv->ray_weights, 0, resources, cmd_queue);

    guint n_subsets = 0;
    UfoProjectionsSubset *subset = generate_subsets (geometry, &n_subsets);

    for (guint i = 0 ; i < n_subsets; ++i) {
        ufo_projector_FP (projector,
                          priv->singular_volume,
                          priv->ray_weights,
                          &subset[i],
                          1.0f,
                          NULL);
    }

    ufo_op_inv (priv->ray_weights, resources, cmd_queue);

    guint iteration = 0;
    while (iteration < max_iterations) {
        ufo_buffer_copy (input, priv->b_temp);
        for (guint i = 0 ; i < n_subsets; i++) {
            ufo_projector_FP (projector,
                              output,
                              priv->b_temp,
                              &subset[i],
                              -1.0f,
                              NULL);

            ufo_op_mul_rows (priv->b_temp,
                             priv->ray_weights,
                             priv->b_temp,
                             subset[i].offset,
                             subset[i].n,
                             resources,
                             cmd_queue);

            ufo_projector_BP (projector,
                              output,
                              priv->b_temp,
                              &subset[i],
                              relaxation_factor,
                              NULL);
        }
        iteration++;
    }

    return TRUE;
}