Browse Source

Avoid recursion when starpu_init calls hwloc initialization which uses its opencl plugin

Samuel Thibault 8 years ago
parent
commit
00df3446fd
4 changed files with 20 additions and 8 deletions
  1. 3 2
      socl/src/cl_createcontextfromtype.c
  2. 6 2
      socl/src/cl_getdeviceids.c
  3. 9 2
      socl/src/init.c
  4. 2 2
      socl/src/init.h

+ 3 - 2
socl/src/cl_createcontextfromtype.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2012 University of Bordeaux
+ * Copyright (C) 2010-2012, 2016 University of Bordeaux
  * Copyright (C) 2012 CNRS
  * Copyright (C) 2012 Vincent Danjean <Vincent.Danjean@ens-lyon.org>
  *
@@ -27,7 +27,8 @@ soclCreateContextFromType(const cl_context_properties * properties,
                         cl_int *                      errcode_ret) CL_API_SUFFIX__VERSION_1_0
 {
    if( ! _starpu_init )
-      socl_init_starpu(); 
+      if (socl_init_starpu() < 0)
+	return NULL;
 
 
    //TODO: appropriate error messages

+ 6 - 2
socl/src/cl_getdeviceids.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2012 University of Bordeaux
+ * Copyright (C) 2010-2012, 2016 University of Bordeaux
  * Copyright (C) 2012 CNRS
  * Copyright (C) 2012 Vincent Danjean <Vincent.Danjean@ens-lyon.org>
  *
@@ -32,7 +32,11 @@ soclGetDeviceIDs(cl_platform_id   platform,
                cl_uint *        num_devices) CL_API_SUFFIX__VERSION_1_0
 {
    if( ! _starpu_init )
-      socl_init_starpu();
+      if (socl_init_starpu() < 0)
+      {
+         *num_devices = 0;
+         return CL_SUCCESS;
+      }
 
    if (_starpu_init_failed) {
       *num_devices = 0;

+ 9 - 2
socl/src/init.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2012 University of Bordeaux
+ * Copyright (C) 2010-2012, 2016 University of Bordeaux
  * Copyright (C) 2012,2014,2016 CNRS
  * Copyright (C) 2012 Vincent Danjean <Vincent.Danjean@ens-lyon.org>
  *
@@ -23,12 +23,17 @@
 
 int _starpu_init_failed;
 volatile int _starpu_init = 0;
+volatile int _starpu_initing = 0;
 static starpu_pthread_mutex_t _socl_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
 static struct starpu_conf conf;
 
-void socl_init_starpu(void) {
+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;
@@ -50,9 +55,11 @@ void socl_init_starpu(void) {
     /* Disable dataflow implicit dependencies */
     starpu_data_set_default_sequential_consistency_flag(0);
     _starpu_init = 1;
+    _starpu_initing = 0;
   }
   STARPU_PTHREAD_MUTEX_UNLOCK(&_socl_mutex);
 
+  return 0;
 }
 /**
  * Initialize SOCL

+ 2 - 2
socl/src/init.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2012 University of Bordeaux
+ * Copyright (C) 2010-2012, 2016 University of Bordeaux
  * Copyright (C) 2012, 2014 CNRS
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -28,7 +28,7 @@ extern volatile int _starpu_init;
  * Initialize StarPU
  */
 
-void socl_init_starpu(void);
+int socl_init_starpu(void);
 void soclShutdown(void);
 
 #endif /* SOCL_INIT_H */