Ver código fonte

socl: use starpu_pthread API

Nathalie Furmento 11 anos atrás
pai
commit
4c5e4997e2

+ 2 - 2
socl/src/cl_createcommandqueue.c

@@ -30,7 +30,7 @@ static void release_callback_command_queue(void * e) {
   gc_entity_unstore(&cq->context);
 
   /* Destruct object */
-  pthread_mutex_destroy(&cq->mutex);
+  starpu_pthread_mutex_destroy(&cq->mutex);
 }
 
 
@@ -73,7 +73,7 @@ soclCreateCommandQueue(cl_context                   context,
 
    cq->commands = NULL;
    cq->barrier = NULL;
-   pthread_mutex_init(&cq->mutex, NULL);
+   starpu_pthread_mutex_init(&cq->mutex, NULL);
 
    if (errcode_ret != NULL)
       *errcode_ret = CL_SUCCESS;

+ 1 - 1
socl/src/cl_createkernel.c

@@ -143,7 +143,7 @@ soclCreateKernel(cl_program    program,
    k->split_space = 0;
    k->split_data = NULL;
    k->split_perfs = NULL;
-   pthread_mutex_init(&k->split_lock, NULL);
+   starpu_pthread_mutex_init(&k->split_lock, NULL);
 
    #ifdef DEBUG
    static int id = 0;

+ 2 - 2
socl/src/cl_enqueuendrangekernel.c

@@ -159,7 +159,7 @@ soclEnqueueNDRangeKernel(cl_command_queue cq,
 		cl_event *       event) CL_API_SUFFIX__VERSION_1_1
 {
 
-   if (kernel->split_func != NULL && !pthread_mutex_trylock(&kernel->split_lock)) {
+   if (kernel->split_func != NULL && !starpu_pthread_mutex_trylock(&kernel->split_lock)) {
 
       cl_event beforeEvent, afterEvent, totalEvent;
 
@@ -199,7 +199,7 @@ soclEnqueueNDRangeKernel(cl_command_queue cq,
 
          kernel->split_perfs[iter] = end-start;
 
-         pthread_mutex_unlock(&kernel->split_lock);
+         starpu_pthread_mutex_unlock(&kernel->split_lock);
 
          event_complete(totalEvent);
 

+ 2 - 2
socl/src/command.c

@@ -45,7 +45,7 @@ static void command_release_callback(void *a) {
   cl_command_queue cq = cmd->event->cq;
   if (cq != NULL) {
     /* Lock command queue */
-    pthread_mutex_lock(&cq->mutex);
+    starpu_pthread_mutex_lock(&cq->mutex);
 
     /* Remove barrier if applicable */
     if (cq->barrier == cmd)
@@ -55,7 +55,7 @@ static void command_release_callback(void *a) {
     cq->commands = command_list_remove(cq->commands, cmd);
 
     /* Unlock command queue */
-    pthread_mutex_unlock(&cq->mutex);
+    starpu_pthread_mutex_unlock(&cq->mutex);
   }
 
   // Events may survive to commands that created them

+ 8 - 8
socl/src/command_queue.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2012 University of Bordeaux
- * Copyright (C) 2012 CNRS
+ * Copyright (C) 2012 Centre National de la Recherche Scientifique
  * Copyright (C) 2012 Vincent Danjean <Vincent.Danjean@ens-lyon.org>
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -40,7 +40,7 @@ void command_queue_enqueue_ex(cl_command_queue cq, cl_command cmd, cl_uint num_e
 	gc_entity_store(&cmd->event->cq, cq);
 
 	/* Lock command queue */
-	pthread_mutex_lock(&cq->mutex);
+	starpu_pthread_mutex_lock(&cq->mutex);
 
 	/*** Number of dependencies ***/
 	int ndeps = num_events;
@@ -99,13 +99,13 @@ void command_queue_enqueue_ex(cl_command_queue cq, cl_command cmd, cl_uint num_e
 	}
 
 	/* Submit command 
-    * We need to do it before unlocking because we don't want events to get
-    * released while we use them to set dependencies
-    */
-   command_submit_ex(cmd);
+	 * We need to do it before unlocking because we don't want events to get
+	 * released while we use them to set dependencies
+	 */
+	command_submit_ex(cmd);
 
 	/* Unlock command queue */
-	pthread_mutex_unlock(&cq->mutex);
+	starpu_pthread_mutex_unlock(&cq->mutex);
 
-   gc_entity_release(cmd);
+	gc_entity_release(cmd);
 }

+ 12 - 12
socl/src/gc.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2012 University of Bordeaux
- * Copyright (C) 2012 CNRS
+ * Copyright (C) 2012, 2014 Centre National de la Recherche Scientifique
  * Copyright (C) 2012 Vincent Danjean <Vincent.Danjean@ens-lyon.org>
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -31,16 +31,16 @@ static volatile entity gc_list = NULL;
 static volatile entity entities = NULL;
 
 /* Mutex and cond for release */
-static pthread_mutex_t gc_mutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t  gc_cond = PTHREAD_COND_INITIALIZER;
+static starpu_pthread_mutex_t gc_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
+static starpu_pthread_cond_t  gc_cond = STARPU_PTHREAD_COND_INITIALIZER;
 
 /* Set to 1 to stop release thread execution */
 static volatile int gc_stop_required = 0;
 
-#define GC_LOCK pthread_mutex_lock(&gc_mutex)
-#define GC_UNLOCK { pthread_cond_signal(&gc_cond); \
-                    pthread_mutex_unlock(&gc_mutex);}
-#define GC_UNLOCK_NO_SIGNAL pthread_mutex_unlock(&gc_mutex)
+#define GC_LOCK starpu_pthread_mutex_lock(&gc_mutex)
+#define GC_UNLOCK { starpu_pthread_cond_signal(&gc_cond); \
+                    starpu_pthread_mutex_unlock(&gc_mutex);}
+#define GC_UNLOCK_NO_SIGNAL starpu_pthread_mutex_unlock(&gc_mutex)
 
 /* Thread routine */
 static void * gc_thread_routine(void *UNUSED(arg)) {
@@ -81,18 +81,18 @@ static void * gc_thread_routine(void *UNUSED(arg)) {
     }
 
     /* Otherwise we sleep */
-    pthread_cond_wait(&gc_cond, &gc_mutex);
+    starpu_pthread_cond_wait(&gc_cond, &gc_mutex);
 
   } while (1);
 
-  pthread_exit(NULL);
+  starpu_pthread_exit(NULL);
 }
 
-static pthread_t gc_thread;
+static starpu_pthread_t gc_thread;
 
 /* Start garbage collection */
 void gc_start(void) {
-  pthread_create(&gc_thread, NULL, gc_thread_routine, NULL);
+  starpu_pthread_create(&gc_thread, NULL, gc_thread_routine, NULL);
 }
 
 /* Stop garbage collection */
@@ -103,7 +103,7 @@ void gc_stop(void) {
 
   GC_UNLOCK;
 
-  pthread_join(gc_thread, NULL);
+  starpu_pthread_join(gc_thread, NULL);
 }
 
 int gc_entity_release_ex(entity e, const char * DEBUG_PARAM(caller)) {

+ 6 - 7
socl/src/init.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2012 University of Bordeaux
- * Copyright (C) 2012 CNRS
+ * Copyright (C) 2012,2014 Centre National de la Recherche Scientifique
  * Copyright (C) 2012 Vincent Danjean <Vincent.Danjean@ens-lyon.org>
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -16,7 +16,6 @@
  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  */
 
-#include <pthread.h>
 #include <stdlib.h>
 #include "socl.h"
 #include "gc.h"
@@ -24,11 +23,11 @@
 
 int _starpu_init_failed;
 volatile int _starpu_init = 0;
-static pthread_mutex_t _socl_mutex = PTHREAD_MUTEX_INITIALIZER;
+static starpu_pthread_mutex_t _socl_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
 static struct starpu_conf conf;
 
 void socl_init_starpu(void) {
-  pthread_mutex_lock(&_socl_mutex);
+  starpu_pthread_mutex_lock(&_socl_mutex);
   if( ! _starpu_init ){
     starpu_conf_init(&conf);
     conf.ncuda = 0;
@@ -52,7 +51,7 @@ void socl_init_starpu(void) {
     starpu_data_set_default_sequential_consistency_flag(0);
     _starpu_init = 1;
   }
-  pthread_mutex_unlock(&_socl_mutex);
+  starpu_pthread_mutex_unlock(&_socl_mutex);
 
 }
 /**
@@ -73,7 +72,7 @@ void soclShutdown() {
    if (!shutdown) {
       shutdown = 1;
 
-      pthread_mutex_lock(&_socl_mutex);
+      starpu_pthread_mutex_lock(&_socl_mutex);
       if( _starpu_init )
          starpu_task_wait_for_all();
 
@@ -91,7 +90,7 @@ void soclShutdown() {
 
       if( _starpu_init )
          starpu_shutdown();
-      pthread_mutex_unlock(&_socl_mutex);
+      starpu_pthread_mutex_unlock(&_socl_mutex);
 
       if (socl_devices != NULL) {
          free(socl_devices);

+ 1 - 2
socl/src/init.h

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2012 University of Bordeaux
- * Copyright (C) 2012 CNRS
+ * Copyright (C) 2012, 2014 Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -15,7 +15,6 @@
  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  */
 
-#include <pthread.h>
 #include "socl.h"
 #include "gc.h"
 #include "mem_objects.h"

+ 4 - 4
socl/src/mem_objects.c

@@ -20,15 +20,15 @@
 #define mem_object_hash_key 257
 
 static cl_mem p_mem_objects[mem_object_hash_key] = {NULL};
-static volatile pthread_spinlock_t p_mem_objects_spinlock[mem_object_hash_key];
+static starpu_pthread_spinlock_t p_mem_objects_spinlock[mem_object_hash_key];
 
-#define LOCK(i) pthread_spin_lock(&p_mem_objects_spinlock[i]);
-#define UNLOCK(i) pthread_spin_unlock(&p_mem_objects_spinlock[i]);
+#define LOCK(i) starpu_pthread_spin_lock(&p_mem_objects_spinlock[i]);
+#define UNLOCK(i) starpu_pthread_spin_unlock(&p_mem_objects_spinlock[i]);
 
 void mem_object_init(void) {
   int i;
   for (i=0; i<mem_object_hash_key; i++) {
-    pthread_spin_init(&p_mem_objects_spinlock[i], 0);
+    starpu_pthread_spin_init(&p_mem_objects_spinlock[i], 0);
   }
 }
 

+ 3 - 8
socl/src/socl.h

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2012 University of Bordeaux
- * Copyright (C) 2012 CNRS
+ * Copyright (C) 2012,2014 Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -25,15 +25,10 @@
 #include <stdlib.h>
 #include <stdint.h>
 #include <unistd.h>
-#include <pthread.h>
 #include "CL/cl.h"
 #include "ocl_icd.h"
 
 #include <starpu.h>
-#include <starpu_opencl.h>
-#include <starpu_data_interfaces.h>
-#include <starpu_profiling.h>
-#include <starpu_task.h>
 
 typedef struct starpu_task * starpu_task;
 
@@ -153,7 +148,7 @@ struct _cl_command_queue {
   cl_command barrier;
 
   /* Mutex */
-  pthread_mutex_t mutex;
+  starpu_pthread_mutex_t mutex;
 
   /* ID  */
 #ifdef DEBUG
@@ -280,7 +275,7 @@ struct _cl_kernel {
   split_func_t split_func;
   cl_ulong * split_perfs;
   void * split_data;
-  pthread_mutex_t split_lock;
+  starpu_pthread_mutex_t split_lock;
 
   /* ID  */
 #ifdef DEBUG