Browse Source

perfmodel: new function starpu_perfmodel_unload_model

 It unloads a model which has been previously loaded through the
 function starpu_perfmodel_load_symbol
Nathalie Furmento 12 years ago
parent
commit
f87b2a7389
3 changed files with 49 additions and 30 deletions
  1. 4 0
      doc/chapters/basic-api.texi
  2. 2 0
      include/starpu_perfmodel.h
  3. 43 30
      src/core/perfmodel/perfmodel_history.c

+ 4 - 0
doc/chapters/basic-api.texi

@@ -2286,6 +2286,10 @@ regression.
 loads a given performance model. The @var{model} structure has to be completely zero, and will be filled with the information saved in @code{$STARPU_HOME/.starpu}.
 @end deftypefun
 
+@deftypefun int starpu_perfmodel_unload_model ({struct starpu_perfmodel} *@var{model})
+unloads the given model which has been previously loaded through the function @code{starpu_perfmodel_load_symbol}
+@end deftypefun
+
 @deftypefun void starpu_perfmodel_debugfilepath ({struct starpu_perfmodel} *@var{model}, {enum starpu_perf_archtype} @var{arch}, char *@var{path}, size_t @var{maxlen}, unsigned nimpl)
 returns the path to the debugging information for the performance model.
 @end deftypefun

+ 2 - 0
include/starpu_perfmodel.h

@@ -201,6 +201,8 @@ enum starpu_perf_archtype starpu_worker_get_perf_archtype(int workerid);
 /* This function is intended to be used by external tools that should read the
  * performance model files */
 int starpu_perfmodel_load_symbol(const char *symbol, struct starpu_perfmodel *model);
+int starpu_perfmodel_unload_model(struct starpu_perfmodel *model);
+
 void starpu_perfmodel_debugfilepath(struct starpu_perfmodel *model, enum starpu_perf_archtype arch, char *path, size_t maxlen, unsigned nimpl);
 void starpu_perfmodel_get_arch_name(enum starpu_perf_archtype arch, char *archname, size_t maxlen, unsigned nimpl);
 

+ 43 - 30
src/core/perfmodel/perfmodel_history.c

@@ -699,6 +699,41 @@ void _starpu_initialize_registered_performance_models(void)
 	_STARPU_PTHREAD_RWLOCK_INIT(&registered_models_rwlock, NULL);
 }
 
+void _starpu_deinitialize_performance_model(struct starpu_perfmodel *model)
+{
+	unsigned arch;
+	unsigned nimpl;
+
+	for (arch = 0; arch < STARPU_NARCH_VARIATIONS; arch++)
+	{
+		for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
+		{
+			struct starpu_perfmodel_per_arch *archmodel = &model->per_arch[arch][nimpl];
+			struct starpu_perfmodel_history_list *list, *plist;
+			struct starpu_perfmodel_history_table *entry, *tmp;
+
+			HASH_ITER(hh, archmodel->history, entry, tmp)
+			{
+				HASH_DEL(archmodel->history, entry);
+				free(entry);
+			}
+			archmodel->history = NULL;
+
+			list = archmodel->list;
+			while (list)
+			{
+				free(list->entry);
+				plist = list;
+				list = list->next;
+				free(plist);
+			}
+			archmodel->list = NULL;
+		}
+	}
+
+	model->is_loaded = 0;
+}
+
 void _starpu_deinitialize_registered_performance_models(void)
 {
 	if (_starpu_get_calibrate_flag())
@@ -714,38 +749,9 @@ void _starpu_deinitialize_registered_performance_models(void)
 	while (node)
 	{
 		struct starpu_perfmodel *model = node->model;
-		unsigned arch;
-		unsigned nimpl;
 
 		_STARPU_PTHREAD_RWLOCK_WRLOCK(&model->model_rwlock);
-		for (arch = 0; arch < STARPU_NARCH_VARIATIONS; arch++)
-		{
-			for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
-			{
-				struct starpu_perfmodel_per_arch *archmodel = &model->per_arch[arch][nimpl];
-				struct starpu_perfmodel_history_list *list, *plist;
-				struct starpu_perfmodel_history_table *entry, *tmp;
-
-				HASH_ITER(hh, archmodel->history, entry, tmp)
-				{
-					HASH_DEL(archmodel->history, entry);
-					free(entry);
-				}
-				archmodel->history = NULL;
-
-				list = archmodel->list;
-				while (list)
-				{
-					free(list->entry);
-					plist = list;
-					list = list->next;
-					free(plist);
-				}
-				archmodel->list = NULL;
-			}
-		}
-
-		model->is_loaded = 0;
+		_starpu_deinitialize_performance_model(model);
 		_STARPU_PTHREAD_RWLOCK_UNLOCK(&model->model_rwlock);
 
 		pnode = node;
@@ -984,6 +990,13 @@ int starpu_perfmodel_load_symbol(const char *symbol, struct starpu_perfmodel *mo
 	return 0;
 }
 
+int starpu_perfmodel_unload_model(struct starpu_perfmodel *model)
+{
+	free((char *)model->symbol);
+	_starpu_deinitialize_performance_model(model);
+	return 0;
+}
+
 void starpu_perfmodel_get_arch_name(enum starpu_perf_archtype arch, char *archname, size_t maxlen,unsigned nimpl)
 {
 	if (arch < STARPU_CUDA_DEFAULT)