Bladeren bron

SOCL: Fix ICD

Sylvain Henry 12 jaren geleden
bovenliggende
commit
366dbf3033

+ 13 - 4
socl/src/cl_createcontextfromtype.c

@@ -21,14 +21,23 @@
 
 CL_API_ENTRY cl_context CL_API_CALL
 soclCreateContextFromType(const cl_context_properties * properties,
-                        cl_device_type                UNUSED(device_type),
+                        cl_device_type                device_type,
                         void (*pfn_notify)(const char *, const void *, size_t, void *),
                         void *                        user_data,
                         cl_int *                      errcode_ret) CL_API_SUFFIX__VERSION_1_0
 {
    if( ! _starpu_init )
       socl_init_starpu(); 
-   //We assume clCreateContext doesn't support devices
-   //TODO:use devices
-   return soclCreateContext(properties, 0, NULL, pfn_notify, user_data, errcode_ret);
+
+
+   //TODO: appropriate error messages
+
+   int num_devices;
+
+   soclGetDeviceIDs(&socl_platform, device_type, 0, NULL, &num_devices);
+
+   cl_device_id devices[num_devices];
+   soclGetDeviceIDs(&socl_platform, device_type, num_devices, devices, NULL);
+   
+   return soclCreateContext(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
 }

+ 1 - 1
socl/src/cl_enqueuecopybuffer.c

@@ -87,7 +87,7 @@ cl_int command_copy_buffer_submit(command_copy_buffer cmd) {
 	/* Execute the task on a specific worker? */
 	if (cmd->_command.cq->device != NULL) {
 	  task->execute_on_a_specific_worker = 1;
-	  task->workerid = (int)(intptr_t)cmd->_command.cq->device;
+	  task->workerid = cmd->_command.cq->device->worker_id;
 	}
 
 	arg = (struct arg_copybuffer*)malloc(sizeof(struct arg_copybuffer));

+ 1 - 1
socl/src/cl_enqueuendrangekernel.c

@@ -130,7 +130,7 @@ cl_int command_ndrange_kernel_submit(command_ndrange_kernel cmd) {
 	/* Execute the task on a specific worker? */
 	if (cmd->_command.cq->device != NULL) {
 	  task->execute_on_a_specific_worker = 1;
-	  task->workerid = (int)(intptr_t)cmd->_command.cq->device;
+	  task->workerid = cmd->_command.cq->device->worker_id;
 	}
 
 	struct starpu_codelet * codelet = cmd->codelet;

+ 1 - 1
socl/src/cl_enqueuereadbuffer.c

@@ -85,7 +85,7 @@ cl_int command_read_buffer_submit(command_read_buffer cmd) {
 	/* Execute the task on a specific worker? */
 	if (cmd->_command.cq->device != NULL) {
 	  task->execute_on_a_specific_worker = 1;
-	  task->workerid = (int)(intptr_t)cmd->_command.cq->device;
+	  task->workerid = cmd->_command.cq->device->worker_id;
 	}
 
 	arg = (struct arg_readbuffer*)malloc(sizeof(struct arg_readbuffer));

+ 1 - 1
socl/src/cl_enqueuewritebuffer.c

@@ -107,7 +107,7 @@ cl_int command_write_buffer_submit(command_write_buffer cmd) {
 	/* Execute the task on a specific worker? */
 	if (cmd->_command.cq->device != NULL) {
 	  task->execute_on_a_specific_worker = 1;
-	  task->workerid = (int)(intptr_t)cmd->_command.cq->device;
+	  task->workerid = cmd->_command.cq->device->worker_id;
 	}
 
 	gc_entity_store(&arg->buffer, buffer);

+ 14 - 2
socl/src/cl_getdeviceids.c

@@ -55,16 +55,28 @@ soclGetDeviceIDs(cl_platform_id   platform,
    int workers[ndevs];
    starpu_worker_get_ids_by_type(STARPU_OPENCL_WORKER, workers, ndevs);
 
+   if (socl_devices == NULL) {
+      socl_devices = malloc(sizeof(struct _cl_device_id) * ndevs);
+      int i;
+      for (i=0; i < ndevs; i++) {
+         int devid = starpu_worker_get_devid(workers[i]);
+         socl_devices[i].dispatch = &socl_master_dispatch;
+         socl_devices[i].worker_id = workers[i];
+         socl_devices[i].device_id = devid;
+      }
+   }
+  
+
    int i;
    unsigned int num = 0;
    for (i=0; i < ndevs; i++) {
-      int devid = starpu_worker_get_devid(workers[i]);
+      int devid = socl_devices[i].device_id;
       cl_device_id dev;
       starpu_opencl_get_device(devid, &dev);
       cl_device_type typ;
       clGetDeviceInfo(dev, CL_DEVICE_TYPE, sizeof(typ), &typ, NULL);
       if (typ & device_type) {
-         if (devices != NULL && num < num_entries) devices[num] = (cl_device_id)(intptr_t)workers[i];
+         if (devices != NULL && num < num_entries) devices[num] = &socl_devices[i];
          num++;
       }
    }

+ 3 - 2
socl/src/cl_getdeviceinfo.c

@@ -30,10 +30,11 @@ soclGetDeviceInfo(cl_device_id    device,
    /* if (device != &socl_virtual_device && device is not a valid StarPU worker identifier)
       return CL_INVALID_DEVICE;*/
 
-  int devid = starpu_worker_get_devid((int)(intptr_t)device);
+  int devid = device->device_id;
+
   cl_device_id dev;
-  
   starpu_opencl_get_device(devid, &dev);
+
   int ret = clGetDeviceInfo(dev, param_name, param_value_size, param_value, param_value_size_ret);
 
   return ret;

+ 27 - 18
socl/src/command_list.c

@@ -17,25 +17,34 @@
 #include "socl.h"
 
 command_list command_list_cons(cl_command cmd, command_list ls) {
-	command_list e = malloc(sizeof(struct command_list_t));
-	e->cmd = cmd;
-	e->next = ls;
-	if (ls != NULL)
-		ls->prev = e;
-	return e;
+   command_list e = malloc(sizeof(struct command_list_t));
+   e->cmd = cmd;
+   e->next = ls;
+   e->prev = NULL;
+   if (ls != NULL)
+      ls->prev = e;
+   return e;
 }
 
+/**
+ * Remove every occurence of cmd in the list l
+ */
 command_list command_list_remove(command_list l, cl_command cmd) {
-	command_list e = l;
-	while (e != NULL) {
-		if (e->cmd == cmd) {
-			if (e->prev != NULL) e->prev->next = e->next;
-			if (e->next != NULL) e->next->prev = e->prev;
-			command_list next = e->next;
-			free(e);
-			if (e == l) return next;
-		}
-		e = e->next;
-	}
-	return l;
+   command_list e = l;
+   while (e != NULL) {
+      if (e->cmd == cmd) {
+         if (e->prev != NULL) e->prev->next = e->next;
+         if (e->next != NULL) e->next->prev = e->prev;
+         command_list old = e;
+         if (l == old) { // list head has been removed
+            l = old->next;
+         }
+         e = old->next;
+         free(old);
+      }
+      else {
+         e = e->next;
+      }
+   }
+   return l;
 }

+ 5 - 1
socl/src/event.c

@@ -73,7 +73,11 @@ static void release_callback_event(void * e) {
   cmd->num_events = 0;
 
   /* Destruct object */
-  //FIXME: we cannot release tag because it makes StarPU crash
+  //FIXME
   //starpu_tag_remove(event->id);
+  if (event->profiling_info != NULL) {
+    free(event->profiling_info);
+    event->profiling_info = NULL;
+  }
 }
 

+ 2 - 2
socl/src/getinfo.h

@@ -30,12 +30,12 @@
    INFO_CASE_EX2(var)
 
 #define INFO_CASE_STRING_EX2(var) if (param_value != NULL) { \
-      if (param_value_size < strlen(var)) \
+      if (param_value_size < strlen(var)+1) \
          return CL_INVALID_VALUE; \
       strcpy(param_value, var); \
    } \
    if (param_value_size_ret != NULL) \
-      *param_value_size_ret = strlen(var); \
+      *param_value_size_ret = strlen(var)+1; \
    break;
 
 #define INFO_CASE_STRING(param, var) case param: \

+ 5 - 0
socl/src/init.c

@@ -90,4 +90,9 @@ __attribute__((destructor)) static void socl_shutdown() {
   if( _starpu_init )
     starpu_shutdown();
   pthread_mutex_unlock(&_socl_mutex);
+
+  if (socl_devices != NULL) {
+    free(socl_devices);
+    socl_devices = NULL;
+  }
 }

+ 2 - 0
socl/src/socl.c

@@ -159,3 +159,5 @@ const char * __attribute__ ((aligned (16))) SOCL_PLATFORM_ICD_SUFFIX_KHR ="SOCL"
  * is equal to 0
  */
 int __attribute__ ((aligned (16))) profiling_queue_count = 0;
+
+struct _cl_device_id * socl_devices = NULL;

+ 3 - 0
socl/src/socl.h

@@ -77,6 +77,7 @@ 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;};
 
 #define RETURN_EVENT(cmd, event) \
 	if (event != NULL) { \
@@ -748,4 +749,6 @@ soclIcdGetPlatformIDsKHR(cl_uint          /* num_entries */,
 
 struct _cl_icd_dispatch socl_master_dispatch;
 struct _cl_platform_id socl_platform;
+struct _cl_device_id * socl_devices;
+
 #endif /* SOCL_H */

+ 5 - 4
socl/src/task.c

@@ -19,8 +19,8 @@
 #include "event.h"
 
 static void task_release_callback(void *arg) {
-  starpu_task task = starpu_task_get_current();
   cl_command cmd = (cl_command)arg;
+  starpu_task task = cmd->task;
   
   cl_event ev = command_event_get(cmd);
   ev->status = CL_COMPLETE;
@@ -36,7 +36,8 @@ static void task_release_callback(void *arg) {
   gc_entity_release(ev);
 
   /* Release the command */
-  //TODO
+  //FIXME
+  //free(cmd);
 }
 
 
@@ -50,8 +51,8 @@ starpu_task task_create() {
 	task = starpu_task_create();
 
 	/* Set task common settings */
-	task->destroy = 1;
-	task->detach = 1;
+	task->destroy = 0;
+	task->detach = 0;
 
 	task->use_tag = 1;
 	task->tag_id = event_unique_id();