Browse Source

SOCL: rewrite cpu_task_submit helper function

Sylvain Henry 13 years ago
parent
commit
762bbf4eea

+ 4 - 2
socl/src/cl_enqueuemapbuffer.c

@@ -32,9 +32,11 @@ static void mapbuffer_task(void *args) {
 }
 
 cl_int command_map_buffer_submit(command_map_buffer cmd) {
-	starpu_task task = task_create_cpu(mapbuffer_task, cmd, 0);
+	static struct starpu_codelet codelet = {
+		.name = "SOCL_MAP_BUFFER"
+	};
 
-	task_submit(task, cmd);
+	cpu_task_submit(cmd, mapbuffer_task, cmd, 0, &codelet, 0, NULL);
 
 	return CL_SUCCESS;
 }

+ 5 - 3
socl/src/cl_enqueuendrangekernel.c

@@ -174,10 +174,12 @@ cl_int command_ndrange_kernel_submit(command_ndrange_kernel cmd) {
 
 	/* Enqueue a cleaning task */
 	//FIXME: execute this in the callback?
-	starpu_task cleaning_task = task_create_cpu(cleaning_task_callback, cmd,0);
 	cl_event ev = command_event_get(cmd);
-	task_depends_on(cleaning_task, 1, &ev);
-	task_submit(cleaning_task, cmd);
+
+	static struct starpu_codelet cdl = {
+		.name = "SOCL_NDRANGE_CLEANING_TASK"
+	};
+	cpu_task_submit(cmd, cleaning_task_callback, cmd, 0, &cdl, 1, &ev);
 
 	return CL_SUCCESS;
 }

+ 4 - 3
socl/src/cl_enqueueunmapmemobject.c

@@ -21,9 +21,10 @@ cl_int command_unmap_mem_object_submit(command_unmap_mem_object cmd) {
 	cl_mem buffer = cmd->buffer;
 
 	//FIXME: use a callback
-	starpu_task task = task_create_cpu((void(*)(void*))starpu_data_release, buffer->handle, 0);
-
-	task_submit(task, cmd);
+	static struct starpu_codelet codelet = {
+		.name = "SOCL_UNMAP_MEM_OBJECT"
+	};
+	cpu_task_submit(cmd, (void(*)(void*))starpu_data_release, buffer->handle, 0, &codelet, 0, NULL);
 
 	return CL_SUCCESS;
 }

+ 10 - 9
socl/src/task.c

@@ -124,23 +124,24 @@ static void cputask_task(__attribute__((unused)) void *descr[], void *args) {
 
 }
 
-static struct starpu_codelet cputask_codelet = {
-   .where = STARPU_CPU,
-   .model = NULL,
-   .cpu_funcs = { &cputask_task, NULL }
-};
-
-starpu_task task_create_cpu(void (*callback)(void*), void *arg, int free_arg) {
+void cpu_task_submit_ex(cl_command cmd, void (*callback)(void*), void *arg, int free_arg, struct starpu_codelet * codelet, unsigned num_events, cl_event * events) {
   
   struct cputask_arg * a = malloc(sizeof(struct cputask_arg));
   a->callback = callback;
   a->arg = arg;
   a->free_arg = free_arg;
 
+  codelet->where = STARPU_CPU;
+  codelet->cpu_funcs[0] = &cputask_task;
+
   starpu_task task = task_create();
-  task->cl = &cputask_codelet;
+  task->cl = codelet;
   task->cl_arg = a;
 
-  return task;
+  if (num_events != 0) {
+     task_depends_on(task, num_events, events);
+  }
+
+  task_submit(task, cmd);
 }
 

+ 9 - 1
socl/src/task.h

@@ -22,7 +22,15 @@
 starpu_task task_create();
 void task_dependency_add(starpu_task task, cl_uint num_events, cl_event *events);
 
-starpu_task task_create_cpu(void (*callback)(void*), void *arg, int free_arg);
+/* Execute callback(arg) in a CPU task (with no buffer)
+ * Associate this task to the command cmd (i.e. when this task completes, the command is completed)
+ * Additional dependencies can be specified (num_events, events).
+ * The codelet is used to give a fixed name to the task without allocating a
+ * new codelet structure each time. This function will fill the other fields
+ * as appropriate */
+void cpu_task_submit_ex(cl_command cmd, void (*callback)(void*), void *arg, int free_arg, struct starpu_codelet *, unsigned num_events, cl_event * events); 
+
+#define cpu_task_submit(cmd, args...) cpu_task_submit_ex((cl_command)cmd, args)
 
 /**
  * Associate a StarPU task to a command and submit it