Procházet zdrojové kódy

SOCL: dependency management clean up

Sylvain Henry před 13 roky
rodič
revize
7da8aaf3ea
1 změnil soubory, kde provedl 34 přidání a 111 odebrání
  1. 34 111
      socl/src/command_queue.c

+ 34 - 111
socl/src/command_queue.c

@@ -27,21 +27,20 @@
  */
 
 
-/**
- * Returned implicit dependencies for a task
- * Command queue must be locked!
- */
-void command_queue_dependencies_implicit(
-	cl_command_queue cq, 	/* Command queue */
-	char is_barrier,	/* Is the task a barrier */
-	cl_int * ret_num_events,	/* Returned number of dependencies */
-	cl_event ** ret_events	/* Returned dependencies */
-) {
-
-	/*********************
-	 * Count dependencies
-	 *********************/
-	int ndeps = 0;
+void command_queue_enqueue_ex(cl_command_queue cq, cl_command cmd, cl_uint num_events, const cl_event * events) {
+
+	/* Check if the command is a barrier */
+	int is_barrier = (cmd->typ == CL_COMMAND_BARRIER || !(cq->properties & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE));
+
+	/* Add references to the command queue */
+	gc_entity_store(&cmd->cq, cq);
+	gc_entity_store(&cmd->event->cq, cq);
+
+	/* Lock command queue */
+	pthread_mutex_lock(&cq->mutex);
+
+	/*** Number of dependencies ***/
+	int ndeps = num_events;
 
 	/* Add dependency to last barrier if applicable */
 	if (cq->barrier != NULL)
@@ -56,123 +55,47 @@ void command_queue_dependencies_implicit(
 		}
 	}
 
-	/*********************
-	 * Return dependencies
-	 *********************/
+	/*** Dependencies ***/
+	cl_event * deps = malloc(ndeps * sizeof(cl_event));
 
 	int n = 0;
-	cl_event * evs = NULL;
-	if (ndeps > 0)
-		evs = malloc(ndeps * sizeof(cl_event));
-
 
 	/* Add dependency to last barrier if applicable */
-	if (cq->barrier != NULL)
-		evs[n++] = cq->barrier->event;
+	if (cq->barrier != NULL) deps[n++] = cq->barrier->event;
 
 	/* Add dependencies to out-of-order events (if any) */
 	if (is_barrier) {
 		command_list cl = cq->commands;
 		while (cl != NULL) {
-			evs[n++] = cl->cmd->event;
+			deps[n++] = cl->cmd->event;
 			cl = cl->next;
 		}
 	}
 
-	*ret_num_events = ndeps;
-	*ret_events = evs;
-}
-	
-/**
- * Insert a command in the command queue
- * The command queue must be locked!
- */
-void command_queue_insert(
-	cl_command_queue 	cq, 	/* Command queue */
-	cl_command 		cmd,	/* Command */
-	int 			is_barrier		/* Is the task a barrier */
-) {
-
-	int in_order = !(cq->properties & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE);
-
-	if (is_barrier)
-		cq->commands = NULL;
-
-	/* Add command to the list of out-of-order commands */
-	if (!in_order)
-		cq->commands = command_list_cons(cmd, cq->commands);
-
-	/* Register this event as last barrier */
-	if (is_barrier || in_order)
-		cq->barrier = cmd;
-
-	/* Add reference to the command queue */
-	gc_entity_store(&cmd->event->cq, cq);
-}
-
-/**
- * Return implicit and explicit dependencies for a task
- * The command queue must be locked!
- */
-void command_queue_dependencies(
-	cl_command_queue 	cq,		/* Command queue */
-	int 			is_barrier,	/* Is the task a barrier */
-	cl_int 			num_events,	/* Number of explicit dependencies */
-	const cl_event *	events,		/* Explicit dependencies */
-	cl_int * 		ret_num_events,	/* Returned number of dependencies */
-	cl_event ** 		ret_events	/* Returned dependencies */
-) {
-	cl_int implicit_num_events;
-	cl_event * implicit_events;
-
-	/* Implicit dependencies */
-	command_queue_dependencies_implicit(cq, is_barrier, &implicit_num_events, &implicit_events);
-
-	/* Explicit dependencies */
-	cl_int ndeps = implicit_num_events + num_events;
-	cl_event * evs = malloc(sizeof(cl_event) * ndeps);
-	memcpy(evs, implicit_events, sizeof(cl_event) * implicit_num_events);
-	memcpy(&evs[implicit_num_events], events, sizeof(cl_event) * num_events);
-
-	free(implicit_events);
-
-	*ret_num_events = ndeps;
-	*ret_events = evs;
-}
-
-void command_queue_enqueue_ex(cl_command_queue cq, cl_command cmd, cl_uint num_events, const cl_event * events) {
-
-	/* Check if the command is a barrier */
-	int is_barrier = 0;
-	if (cmd->typ == CL_COMMAND_BARRIER) {
-		is_barrier = 1;
-		/* OpenCL has no CL_COMMAND_BARRIER type, so we fall back on CL_COMMAND_MARKER 
-                   WARNING OpenCL has CL_COMMAND_BARRIER in 1.2*/
-		cmd->typ = CL_COMMAND_MARKER;
+	/* Add explicit dependencies */
+	unsigned i;
+	for (i=0; i<num_events; i++) {
+		deps[n++] = events[i];
 	}
 
-	/* Set command queue field */
-	cmd->cq = cq;
-
-	/* Lock command queue */
-	pthread_mutex_lock(&cq->mutex);
-
-	//FIXME: crappy separation (command_queue_dependencies + command_queue_insert)
-
-	/* Get all (explicit + implicit) dependencies */
-	cl_int all_num_events;
-	cl_event * all_events;
-	command_queue_dependencies(cq, is_barrier, num_events, events, &all_num_events, &all_events);
-
 	/* Make all dependencies explicit for the command */
-	cmd->num_events = all_num_events;
-	cmd->events = all_events;
+	cmd->num_events = ndeps;
+	cmd->events = deps;
 
 	/* Increment event ref count */
 	gc_entity_retain(cmd->event);
 
 	/* Insert command in the queue */
-	command_queue_insert(cq, cmd, is_barrier);
+	if (is_barrier) {
+		/* Remove out-of-order commands */
+		cq->commands = NULL;
+		/* Register the command as the last barrier */
+		cq->barrier = cmd;
+	}
+	else {
+		/* Add command to the list of out-of-order commands */
+		cq->commands = command_list_cons(cmd, cq->commands);
+	}
 
 	/* Unlock command queue */
 	pthread_mutex_unlock(&cq->mutex);