|
@@ -17,46 +17,69 @@
|
|
|
*/
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
+#include "../src/core/workers.h"
|
|
|
#include "socl.h"
|
|
|
#include "gc.h"
|
|
|
#include "mem_objects.h"
|
|
|
|
|
|
int _starpu_init_failed;
|
|
|
-volatile int _starpu_init = 0;
|
|
|
-volatile int _starpu_initing = 0;
|
|
|
+static enum initialization _socl_init = UNINITIALIZED;
|
|
|
static starpu_pthread_mutex_t _socl_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
|
|
|
+static starpu_pthread_cond_t _socl_cond = STARPU_PTHREAD_COND_INITIALIZER;
|
|
|
+static pthread_t _socl_thread_init;
|
|
|
static struct starpu_conf conf;
|
|
|
|
|
|
int socl_init_starpu(void) {
|
|
|
- if (_starpu_initing)
|
|
|
- /* Avoid recursion when starpu_init calls hwloc initialization which uses its opencl plugin */
|
|
|
- return -1;
|
|
|
STARPU_PTHREAD_MUTEX_LOCK(&_socl_mutex);
|
|
|
- if( ! _starpu_init ){
|
|
|
- _starpu_initing = 1;
|
|
|
- starpu_conf_init(&conf);
|
|
|
- conf.ncuda = 0;
|
|
|
- conf.ncpus = 0;
|
|
|
-
|
|
|
+ if (_socl_init == INITIALIZED)
|
|
|
+ {
|
|
|
+ STARPU_PTHREAD_MUTEX_UNLOCK(&_socl_mutex);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
- _starpu_init_failed = starpu_init(&conf);
|
|
|
- if (_starpu_init_failed != 0)
|
|
|
+ if (_socl_init == CHANGING)
|
|
|
+ {
|
|
|
+ /* Avoid recursion when starpu_init calls hwloc initialization which uses its opencl plugin */
|
|
|
+ if (pthread_equal(_socl_thread_init, pthread_self()))
|
|
|
{
|
|
|
- DEBUG_MSG("Error when calling starpu_init: %d\n", _starpu_init_failed);
|
|
|
- }
|
|
|
- else {
|
|
|
- if (starpu_opencl_worker_get_count() == 0)
|
|
|
- {
|
|
|
- DEBUG_MSG("StarPU didn't find any OpenCL device. Try disabling CUDA support in StarPU (export STARPU_NCUDA=0).\n");
|
|
|
- _starpu_init_failed = -ENODEV;
|
|
|
- }
|
|
|
+ STARPU_PTHREAD_MUTEX_UNLOCK(&_socl_mutex);
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
- /* Disable dataflow implicit dependencies */
|
|
|
- starpu_data_set_default_sequential_consistency_flag(0);
|
|
|
- _starpu_init = 1;
|
|
|
- _starpu_initing = 0;
|
|
|
+ /* Somebody else is initializing already, wait for him */
|
|
|
+ while (_socl_init != INITIALIZED)
|
|
|
+ STARPU_PTHREAD_COND_WAIT(&_socl_cond, &_socl_mutex);
|
|
|
+ STARPU_PTHREAD_MUTEX_UNLOCK(&_socl_mutex);
|
|
|
+ return 0;
|
|
|
}
|
|
|
+ _socl_init = CHANGING;
|
|
|
+ _socl_thread_init = pthread_self();
|
|
|
+ STARPU_PTHREAD_MUTEX_UNLOCK(&_socl_mutex);
|
|
|
+
|
|
|
+ starpu_conf_init(&conf);
|
|
|
+ conf.ncuda = 0;
|
|
|
+ conf.ncpus = 0;
|
|
|
+
|
|
|
+
|
|
|
+ _starpu_init_failed = starpu_init(&conf);
|
|
|
+ if (_starpu_init_failed != 0)
|
|
|
+ {
|
|
|
+ DEBUG_MSG("Error when calling starpu_init: %d\n", _starpu_init_failed);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (starpu_opencl_worker_get_count() == 0)
|
|
|
+ {
|
|
|
+ DEBUG_MSG("StarPU didn't find any OpenCL device. Try disabling CUDA support in StarPU (export STARPU_NCUDA=0).\n");
|
|
|
+ _starpu_init_failed = -ENODEV;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Disable dataflow implicit dependencies */
|
|
|
+ starpu_data_set_default_sequential_consistency_flag(0);
|
|
|
+
|
|
|
+ STARPU_PTHREAD_MUTEX_LOCK(&_socl_mutex);
|
|
|
+ _socl_init = INITIALIZED;
|
|
|
+ STARPU_PTHREAD_COND_BROADCAST(&_socl_cond);
|
|
|
STARPU_PTHREAD_MUTEX_UNLOCK(&_socl_mutex);
|
|
|
|
|
|
return 0;
|
|
@@ -80,12 +103,12 @@ void soclShutdown() {
|
|
|
shutdown = 1;
|
|
|
|
|
|
STARPU_PTHREAD_MUTEX_LOCK(&_socl_mutex);
|
|
|
- if( _starpu_init )
|
|
|
+ if( _socl_init )
|
|
|
starpu_task_wait_for_all();
|
|
|
|
|
|
gc_stop();
|
|
|
|
|
|
- if( _starpu_init )
|
|
|
+ if( _socl_init )
|
|
|
starpu_task_wait_for_all();
|
|
|
|
|
|
int active_entities = gc_active_entity_count();
|
|
@@ -95,7 +118,7 @@ void soclShutdown() {
|
|
|
gc_print_remaining_entities();
|
|
|
}
|
|
|
|
|
|
- if( _starpu_init && _starpu_init_failed != -ENODEV)
|
|
|
+ if( _socl_init && _starpu_init_failed != -ENODEV)
|
|
|
starpu_shutdown();
|
|
|
STARPU_PTHREAD_MUTEX_UNLOCK(&_socl_mutex);
|
|
|
|