Browse Source

SOCL: use scheduling contexts

Sylvain Henry 13 years ago
parent
commit
fd7cdf63de
3 changed files with 57 additions and 32 deletions
  1. 12 0
      socl/src/cl_createcontext.c
  2. 12 2
      socl/src/socl.h
  3. 33 30
      socl/src/task.c

+ 12 - 0
socl/src/cl_createcontext.c

@@ -23,6 +23,9 @@ static void release_callback_context(void * e) {
   if (context->properties != NULL)
     free(context->properties);
 
+#warning TODO: to be fixed
+  //starpu_sched_ctx_finished_submit(context->sched_ctx);
+
   free(context->devices);
 }
 
@@ -100,6 +103,15 @@ soclCreateContext(const cl_context_properties * properties,
    ctx->devices = malloc(sizeof(cl_device_id) * num_devices);
    memcpy(ctx->devices, devices, sizeof(cl_device_id)*num_devices);
 
+   // Create context
+   int workers[num_devices];
+   unsigned int i;
+   for (i=0; i<num_devices; i++) {
+      workers[i] = ctx->devices[i]->worker_id;
+   }
+   //TODO use context property to set scheduling strategy and name
+   ctx->sched_ctx = starpu_sched_ctx_create("dmda", workers, num_devices, "ctx");
+
    if (errcode_ret != NULL)
       *errcode_ret = CL_SUCCESS;
 

+ 12 - 2
socl/src/socl.h

@@ -77,8 +77,15 @@ struct entity {
 
 
 
-struct _cl_platform_id {struct _cl_icd_dispatch *dispatch;};
-struct _cl_device_id {struct _cl_icd_dispatch *dispatch; int device_id; int worker_id;};
+struct _cl_platform_id {
+   struct _cl_icd_dispatch *dispatch;
+};
+
+struct _cl_device_id {
+   struct _cl_icd_dispatch *dispatch; 
+   int device_id;
+   int worker_id;
+};
 
 #define RETURN_EVENT(cmd, event) \
 	if (event != NULL) { \
@@ -122,6 +129,9 @@ struct _cl_context {
   cl_device_id * devices;
   cl_uint num_devices;
 
+  /* Scheduling context */
+  unsigned sched_ctx;
+
   /* Properties */
   cl_context_properties * properties;
   cl_uint num_properties;

+ 33 - 30
socl/src/task.c

@@ -45,57 +45,60 @@ static void task_release_callback(void *arg) {
  * Create a StarPU task
  */
 starpu_task task_create() {
-	struct starpu_task * task;
+  struct starpu_task * task;
 
-	/* Create StarPU task */
-	task = starpu_task_create();
+  /* Create StarPU task */
+  task = starpu_task_create();
 
-	/* Set task common settings */
-	task->destroy = 0;
-	task->detach = 0;
+  /* Set task common settings */
+  task->destroy = 0;
+  task->detach = 0;
 
-	task->use_tag = 1;
-	task->tag_id = event_unique_id();
+  task->use_tag = 1;
+  task->tag_id = event_unique_id();
 
-	return task;
+  return task;
 }
 
 
 void task_depends_on(starpu_task task, cl_uint num_events, cl_event *events) {
 
-	if (num_events != 0) {
-		cl_uint i;
+  if (num_events != 0) {
+    cl_uint i;
 
-		starpu_tag_t * tags = malloc(num_events * sizeof(starpu_tag_t));	
+    starpu_tag_t * tags = malloc(num_events * sizeof(starpu_tag_t));	
 
-		for (i=0; i<num_events; i++) {
-			tags[i] = events[i]->id;
-			DEBUG_MSG_NOHEAD(" %u", events[i]->id);
-		}
-		DEBUG_MSG_NOHEAD("\n");
+    for (i=0; i<num_events; i++) {
+       tags[i] = events[i]->id;
+       DEBUG_MSG_NOHEAD(" %u", events[i]->id);
+    }
+    DEBUG_MSG_NOHEAD("\n");
 
-		starpu_tag_declare_deps_array(task->tag_id, num_events, tags);
+    starpu_tag_declare_deps_array(task->tag_id, num_events, tags);
 
-		free(tags);
-	}
+    free(tags);
+  }
 }
 
 cl_int task_submit_ex(starpu_task task, cl_command cmd) {
 
-	/* Associated the task to the command */
-	cmd->task = task;
+  /* Associated the task to the command */
+  cmd->task = task;
+
+  task_depends_on(task, command_num_events_get(cmd), command_events_get(cmd));
 
-	task_depends_on(task, command_num_events_get(cmd), command_events_get(cmd));
+  task->callback_func = task_release_callback;
+  task->callback_arg = cmd;
 
-	task->callback_func = task_release_callback;
-	task->callback_arg = cmd;
+  /* Submit task */
+  int ret = (task->cl != NULL && task->cl->where == STARPU_OPENCL ?
+        starpu_task_submit_to_ctx(task, cmd->cq->context->sched_ctx) :
+        starpu_task_submit(task));
 
-	/* Submit task */
-	int ret = starpu_task_submit(task);
-	if (ret != 0)
-		DEBUG_ERROR("Unable to submit a task. Error %d\n", ret);
+  if (ret != 0)
+     DEBUG_ERROR("Unable to submit a task. Error %d\n", ret);
 
-	return CL_SUCCESS;
+  return CL_SUCCESS;
 }