static gpointer run_task (TaskLocalData *tld) { UfoBuffer *inputs[tld->n_inputs]; UfoBuffer *output; UfoTaskNode *node; UfoTaskMode mode; UfoProfiler *profiler; UfoRequisition requisition; gboolean active; node = UFO_TASK_NODE (tld->task); active = TRUE; output = NULL; profiler = g_object_ref (ufo_task_node_get_profiler (node)); if (UFO_IS_REMOTE_TASK (tld->task)) { run_remote_task (tld); return NULL; } /* mode without CPU/GPU flag */ mode = tld->mode & UFO_TASK_MODE_TYPE_MASK; while (active) { UfoGroup *group; gboolean produces; group = ufo_task_node_get_out_group (node); /* Get input buffers */ active = get_inputs (tld, inputs); if (!active) { ufo_group_finish (group); break; } /* Get output buffers */ ufo_task_get_requisition (tld->task, inputs, &requisition); produces = requisition.n_dims > 0; if (produces) { output = ufo_group_pop_output_buffer (group, &requisition); g_assert (output != NULL); } if (output != NULL) ufo_buffer_discard_location (output); switch (mode) { case UFO_TASK_MODE_PROCESSOR: ufo_profiler_trace_event (profiler, UFO_TRACE_EVENT_PROCESS | UFO_TRACE_EVENT_BEGIN); active = ufo_task_process (tld->task, inputs, output, &requisition); ufo_profiler_trace_event (profiler, UFO_TRACE_EVENT_PROCESS | UFO_TRACE_EVENT_END); ufo_task_node_increase_processed (UFO_TASK_NODE (tld->task)); break; case UFO_TASK_MODE_REDUCTOR: do { ufo_profiler_trace_event (profiler, UFO_TRACE_EVENT_PROCESS | UFO_TRACE_EVENT_BEGIN); ufo_task_process (tld->task, inputs, output, &requisition); ufo_profiler_trace_event (profiler, UFO_TRACE_EVENT_PROCESS | UFO_TRACE_EVENT_END); ufo_task_node_increase_processed (UFO_TASK_NODE (tld->task)); release_inputs (tld, inputs); active = get_inputs (tld, inputs); } while (active); break; case UFO_TASK_MODE_GENERATOR: ufo_profiler_trace_event (profiler, UFO_TRACE_EVENT_GENERATE | UFO_TRACE_EVENT_BEGIN); active = ufo_task_generate (tld->task, output, &requisition); ufo_profiler_trace_event (profiler, UFO_TRACE_EVENT_GENERATE | UFO_TRACE_EVENT_END); break; default: g_warning ("Invalid task mode: %i\n", mode); } if (active && produces && (mode != UFO_TASK_MODE_REDUCTOR)) ufo_group_push_output_buffer (group, output); /* Release buffers for further consumption */ if (active) release_inputs (tld, inputs); if (mode == UFO_TASK_MODE_REDUCTOR) { do { ufo_profiler_trace_event (profiler, UFO_TRACE_EVENT_GENERATE | UFO_TRACE_EVENT_BEGIN); active = ufo_task_generate (tld->task, output, &requisition); ufo_profiler_trace_event (profiler, UFO_TRACE_EVENT_GENERATE | UFO_TRACE_EVENT_END); if (active) { ufo_group_push_output_buffer (group, output); output = ufo_group_pop_output_buffer (group, &requisition); } } while (active); } if (!active) ufo_group_finish (group); } g_object_unref (profiler); return NULL; }
static void test_create_lots_of_buffers (Fixture *fixture, gconstpointer unused) { gint num_buffers = 10000; UfoConfig *config = ufo_config_new (); UfoResources *resources = ufo_resources_new (config, NULL); gpointer context = ufo_resources_get_context (resources); UfoRequisition requisition = { .n_dims = 2, .dims[0] = 800, .dims[1] = 800 }; while (num_buffers-- > 0) { UfoBuffer *buffer = ufo_buffer_new (&requisition, NULL, context); gpointer device_array = ufo_buffer_get_device_array (buffer, NULL); ufo_buffer_discard_location (buffer); g_assert (device_array != NULL); g_object_unref (buffer); } } static void test_copy_lots_of_buffers (Fixture *fixture, gconstpointer *unused) { gint num_buffers = 10000; UfoConfig *config = ufo_config_new (); UfoResources *resources = ufo_resources_new (config, NULL); gpointer context = ufo_resources_get_context (resources); UfoRequisition requisition = { .n_dims = 2, .dims[0] = 800, .dims[1] = 800 }; // TODO enforce copy between GPUs UfoBuffer *src = ufo_buffer_new (&requisition, NULL, context); UfoBuffer *dest = ufo_buffer_new (&requisition, NULL, context); while (num_buffers-- > 0) { g_debug("copy"); ufo_buffer_copy (src, dest); } } static void test_convert_8 (Fixture *fixture, gconstpointer unused) { gfloat *host_data; host_data = ufo_buffer_get_host_array (fixture->buffer, NULL); g_memmove (host_data, fixture->data8, fixture->n_data); ufo_buffer_convert (fixture->buffer, UFO_BUFFER_DEPTH_8U); host_data = ufo_buffer_get_host_array (fixture->buffer, NULL); for (guint i = 0; i < fixture->n_data; i++) g_assert (host_data[i] == ((gfloat) fixture->data8[i])); }