Prechádzať zdrojové kódy

Allow starpu_free() to use cudaFreeHost if starpu has already been shut down.

This comes in handy when running the GCC plugin : it avoids submitting a task after calling starpu_shutdown().
Cyril Roelandt 13 rokov pred
rodič
commit
5f775a450f
3 zmenil súbory, kde vykonal 17 pridanie a 3 odobranie
  1. 5 0
      src/core/workers.c
  2. 2 0
      src/core/workers.h
  3. 10 3
      src/util/malloc.c

+ 5 - 0
src/core/workers.c

@@ -41,6 +41,11 @@ static pthread_key_t worker_key;
 
 static struct _starpu_machine_config config;
 
+int _starpu_is_initialized(void)
+{
+	return initialized == INITIALIZED;
+}
+
 struct _starpu_machine_config *_starpu_get_machine_config(void)
 {
 	return &config;

+ 2 - 0
src/core/workers.h

@@ -197,6 +197,8 @@ struct _starpu_worker *_starpu_get_worker_struct(unsigned id);
 
 struct _starpu_combined_worker *_starpu_get_combined_worker_struct(unsigned id);
 
+int _starpu_is_initialized(void);
+
 /* Returns the structure that describes the overall machine configuration (eg.
  * all workers and topology). */
 struct _starpu_machine_config *_starpu_get_machine_config(void);

+ 10 - 3
src/util/malloc.c

@@ -179,9 +179,16 @@ int starpu_free(void *A)
 	if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
 		return -EDEADLK;
 
-	if (_starpu_can_submit_cuda_task())
-	{
 #ifdef STARPU_USE_CUDA
+	if (!_starpu_is_initialized())
+	{
+		/* This is especially useful when starpu_free is called from
+ 		 * the GCC-plugin. starpu_shutdown will probably have already
+		 * been called, so we will not be able to submit a task. */
+		cudaFreeHost(A);
+	}
+	else if (_starpu_can_submit_cuda_task())
+	{
 		int push_res;
 
                 free_pinned_cl.where = STARPU_CUDA;
@@ -196,7 +203,6 @@ int starpu_free(void *A)
 
 		push_res = starpu_task_submit(task);
 		STARPU_ASSERT(push_res != -ENODEV);
-#endif
 	}
 //	else if (_starpu_can_submit_opencl_task())
 //	{
@@ -218,6 +224,7 @@ int starpu_free(void *A)
 //#endif
 //	}
 	else
+#endif
 	{
 		free(A);
 	}