Browse Source

mic (perfmodels): merge trunk + Correction

Thibaud Lambert 11 years ago
parent
commit
65d83f8779

+ 7 - 0
ChangeLog

@@ -40,6 +40,13 @@ New features:
     handle (sequential consistency will be enabled or disabled based
     handle (sequential consistency will be enabled or disabled based
     on the value of the function parameter and the value of the
     on the value of the function parameter and the value of the
     sequential consistency defined for the given data)
     sequential consistency defined for the given data)
+  * Performance models files are now stored in a directory whose name
+    include the version of the performance model format. The version
+    number is also written in the file itself.
+    When updating the format, the internal variable
+    _STARPU_PERFMODEL_VERSION should be updated. It is then possible
+    to switch easily between differents versions of StarPU having
+    different performance model formats.
 
 
 Small features:
 Small features:
   * Add cl_arg_free field to enable automatic free(cl_arg) on task
   * Add cl_arg_free field to enable automatic free(cl_arg) on task

+ 5 - 5
include/starpu_thread.h

@@ -18,6 +18,11 @@
 #ifndef __STARPU_THREAD_H__
 #ifndef __STARPU_THREAD_H__
 #define __STARPU_THREAD_H__
 #define __STARPU_THREAD_H__
 
 
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
 #ifdef STARPU_SIMGRID
 #ifdef STARPU_SIMGRID
 #include <xbt/synchro_core.h>
 #include <xbt/synchro_core.h>
 #include <msg/msg.h>
 #include <msg/msg.h>
@@ -25,11 +30,6 @@
 #include <pthread.h>
 #include <pthread.h>
 #endif
 #endif
 
 
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
 /*
 /*
  * Encapsulation of the pthread_create function.
  * Encapsulation of the pthread_create function.
  */
  */

+ 2 - 2
include/starpu_util.h

@@ -80,10 +80,10 @@ extern "C"
 #else
 #else
 #  if defined(__CUDACC__) && defined(STARPU_HAVE_WINDOWS)
 #  if defined(__CUDACC__) && defined(STARPU_HAVE_WINDOWS)
 #    define STARPU_ASSERT(x)		do { if (STARPU_UNLIKELY(!(x))) *(int*)NULL = 0; } while(0)
 #    define STARPU_ASSERT(x)		do { if (STARPU_UNLIKELY(!(x))) *(int*)NULL = 0; } while(0)
-#    define STARPU_ASSERT_MSG(x, msg, ...)	do { if (STARPU_UNLIKELY(!(x))) { fprintf(stderr, "\n[starpu][%s][assert failure] " msg "\n", __starpu_func__, ## __VA_ARGS__); *(int*)NULL = 0; }} while(0)
+#    define STARPU_ASSERT_MSG(x, msg, ...)	do { if (STARPU_UNLIKELY(!(x))) { fprintf(stderr, "\n[starpu][%s][assert failure] " msg "\n\n", __starpu_func__, ## __VA_ARGS__); *(int*)NULL = 0; }} while(0)
 #  else
 #  else
 #    define STARPU_ASSERT(x)		assert(x)
 #    define STARPU_ASSERT(x)		assert(x)
-#    define STARPU_ASSERT_MSG(x, msg, ...)	do { if (STARPU_UNLIKELY(!(x))) { fprintf(stderr, "\n[starpu][%s][assert failure] " msg "\n", __starpu_func__, ## __VA_ARGS__); } ; assert(x); } while(0)
+#    define STARPU_ASSERT_MSG(x, msg, ...)	do { if (STARPU_UNLIKELY(!(x))) { fprintf(stderr, "\n[starpu][%s][assert failure] " msg "\n\n", __starpu_func__, ## __VA_ARGS__); } ; assert(x); } while(0)
 
 
 #  endif
 #  endif
 #endif
 #endif

+ 3 - 2
src/core/perfmodel/perfmodel.c

@@ -445,8 +445,9 @@ void _starpu_get_perf_model_dir(char *path, size_t maxlen)
 
 
 void _starpu_get_perf_model_dir_codelets(char *path, size_t maxlen)
 void _starpu_get_perf_model_dir_codelets(char *path, size_t maxlen)
 {
 {
-	_starpu_get_perf_model_dir(path, maxlen);
-	strncat(path, "/codelets/", maxlen);
+	char perf_model_path[256];
+	_starpu_get_perf_model_dir(perf_model_path, maxlen);
+	snprintf(path, maxlen, "%s/codelets/%d/", perf_model_path, _STARPU_PERFMODEL_VERSION);
 }
 }
 
 
 void _starpu_get_perf_model_dir_bus(char *path, size_t maxlen)
 void _starpu_get_perf_model_dir_bus(char *path, size_t maxlen)

+ 11 - 0
src/core/perfmodel/perfmodel.h

@@ -29,6 +29,17 @@ extern "C"
 {
 {
 #endif
 #endif
 
 
+/**
+ * Performance models files are stored in a directory whose name
+ * include the version of the performance model format. The version
+ * number is also written in the file itself.
+ * When updating the format, the variable _STARPU_PERFMODEL_VERSION
+ * should be updated. It is then possible to switch easily between
+ * differents versions of StarPU having different performance model
+ * formats.
+ */
+#define _STARPU_PERFMODEL_VERSION 42
+
 struct _starpu_perfmodel_list
 struct _starpu_perfmodel_list
 {
 {
 	struct _starpu_perfmodel_list *next;
 	struct _starpu_perfmodel_list *next;

+ 62 - 31
src/core/perfmodel/perfmodel_history.c

@@ -392,8 +392,17 @@ static void parse_archtype(FILE *f, struct starpu_perfmodel *model, unsigned sca
 static void parse_model_file(FILE *f, struct starpu_perfmodel *model, unsigned scan_history)
 static void parse_model_file(FILE *f, struct starpu_perfmodel *model, unsigned scan_history)
 {
 {
 	unsigned archtype;
 	unsigned archtype;
+	int ret, version;
+
 	_STARPU_DEBUG("Start parsing\n");
 	_STARPU_DEBUG("Start parsing\n");
 
 
+	/* Parsing performance model version */
+	_starpu_drop_comments(f);
+	ret = fscanf(f, "%d\n", &version);
+	STARPU_ASSERT_MSG(version == _STARPU_PERFMODEL_VERSION, "Incorrect performance model file with a model version %d not being the current model version (%d)\n",
+			  version, _STARPU_PERFMODEL_VERSION);
+	STARPU_ASSERT_MSG(ret == 1, "Incorrect performance model file");
+
 	/* Parsing each kind of archtype */
 	/* Parsing each kind of archtype */
 	for(archtype=0; archtype<STARPU_NARCH; archtype++)
 	for(archtype=0; archtype<STARPU_NARCH; archtype++)
 		parse_archtype(f, model, scan_history, archtype);
 		parse_archtype(f, model, scan_history, archtype);
@@ -472,6 +481,10 @@ static void dump_model_file(FILE *f, struct starpu_perfmodel *model)
 	unsigned archtype, ndevice, *ncore, devid, nc, nimpl;
 	unsigned archtype, ndevice, *ncore, devid, nc, nimpl;
 	struct starpu_perfmodel_arch arch;
 	struct starpu_perfmodel_arch arch;
 
 
+	fprintf(f, "##################\n");
+	fprintf(f, "# Performance Model Version\n");
+	fprintf(f, "%d\n\n", _STARPU_PERFMODEL_VERSION);
+
 	for(archtype=0; archtype<STARPU_NARCH; archtype++)
 	for(archtype=0; archtype<STARPU_NARCH; archtype++)
 	{
 	{
 		arch.type = archtype;
 		arch.type = archtype;
@@ -544,7 +557,6 @@ static void dump_model_file(FILE *f, struct starpu_perfmodel *model)
 				else
 				else
 					STARPU_ASSERT_MSG(0, "Unknown history-based performance model %u", archtype);
 					STARPU_ASSERT_MSG(0, "Unknown history-based performance model %u", archtype);
 
 
-
 				fprintf(f, "##########\n");
 				fprintf(f, "##########\n");
 				fprintf(f, "# %u worker(s) in parallel\n", nc+1);
 				fprintf(f, "# %u worker(s) in parallel\n", nc+1);
 
 
@@ -623,7 +635,16 @@ void initialize_model_with_file(FILE*f, struct starpu_perfmodel *model)
 {
 {
 	unsigned ret, archtype, devid, i, ndevice, * maxncore;
 	unsigned ret, archtype, devid, i, ndevice, * maxncore;
 	struct starpu_perfmodel_arch arch;
 	struct starpu_perfmodel_arch arch;
+	int version;
+
+	/* Parsing performance model version */
+	_starpu_drop_comments(f);
+	ret = fscanf(f, "%d\n", &version);
+	STARPU_ASSERT_MSG(version == _STARPU_PERFMODEL_VERSION, "Incorrect performance model file with a model version %d not being the current model version (%d)\n",
+			version, _STARPU_PERFMODEL_VERSION);
+	STARPU_ASSERT_MSG(ret == 1, "Incorrect performance model file");
 
 
+	model->per_arch = malloc(sizeof(*model->per_arch)*(STARPU_NARCH));
 	for(archtype=0; archtype<STARPU_NARCH; archtype++)
 	for(archtype=0; archtype<STARPU_NARCH; archtype++)
 	{
 	{
 		arch.type = archtype;
 		arch.type = archtype;
@@ -801,43 +822,53 @@ void _starpu_deinitialize_performance_model(struct starpu_perfmodel *model)
 {
 {
 	unsigned arch, devid, ncore, nimpl;
 	unsigned arch, devid, ncore, nimpl;
 
 
-	for (arch = 0; arch < STARPU_NARCH; arch++)
+	_STARPU_DEBUG("\n\n#####\nDeinit:%p\n#####\n\n",model);
+		
+	if(model->per_arch != NULL)
 	{
 	{
-		if( model->per_arch[arch] != NULL)
+		for (arch = 0; arch < STARPU_NARCH; arch++)
 		{
 		{
-			for(devid=0; model->per_arch[arch][devid] != NULL; devid++)
+			if( model->per_arch[arch] != NULL)
 			{
 			{
-				for(ncore=0; model->per_arch[arch][devid][ncore] != NULL; ncore++)
+				for(devid=0; model->per_arch[arch][devid] != NULL; devid++)
 				{
 				{
-					for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
-					{	
-						struct starpu_perfmodel_per_arch *archmodel = &model->per_arch[arch][devid][ncore][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);
+					for(ncore=0; model->per_arch[arch][devid][ncore] != NULL; ncore++)
+					{
+						for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
+						{	
+							struct starpu_perfmodel_per_arch *archmodel = &model->per_arch[arch][devid][ncore][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;
 						}
 						}
-						archmodel->list = NULL;
+						free(model->per_arch[arch][devid][ncore]);
+						model->per_arch[arch][devid][ncore] = NULL;
 					}
 					}
-					free(model->per_arch[arch][devid][ncore]);
+					free(model->per_arch[arch][devid]);
+					model->per_arch[arch][devid] = NULL;
 				}
 				}
-				free(model->per_arch[arch][devid]);
+				free(model->per_arch[arch]);
+				model->per_arch[arch] = NULL;
 			}
 			}
-			free(model->per_arch[arch]);
 		}
 		}
+		free(model->per_arch);
+		model->per_arch = NULL;
 	}
 	}
 
 
 	model->is_loaded = 0;
 	model->is_loaded = 0;
@@ -996,7 +1027,7 @@ void _starpu_load_history_based_model(struct starpu_perfmodel *model, unsigned s
 		else
 		else
 		{
 		{
 			/* We load the available file */
 			/* We load the available file */
-			_STARPU_DEBUG("File exists\n");
+                        _STARPU_DEBUG("File exists\n");
 			FILE *f;
 			FILE *f;
 			f = fopen(path, "r");
 			f = fopen(path, "r");
 			STARPU_ASSERT(f);
 			STARPU_ASSERT(f);
@@ -1031,7 +1062,7 @@ void _starpu_load_history_based_model(struct starpu_perfmodel *model, unsigned s
 void starpu_perfmodel_directory(FILE *output)
 void starpu_perfmodel_directory(FILE *output)
 {
 {
 	char perf_model_dir[256];
 	char perf_model_dir[256];
-	_starpu_get_perf_model_dir(perf_model_dir, 256);
+	_starpu_get_perf_model_dir_codelets(perf_model_dir, 256);
 	fprintf(output, "directory: <%s>\n", perf_model_dir);
 	fprintf(output, "directory: <%s>\n", perf_model_dir);
 }
 }
 
 

+ 3 - 3
src/sched_policies/eager_central_priority_policy.c

@@ -134,9 +134,9 @@ static int _starpu_priority_push_task(struct starpu_task *task)
 		starpu_pthread_mutex_t *sched_mutex;
 		starpu_pthread_mutex_t *sched_mutex;
 		starpu_pthread_cond_t *sched_cond;
 		starpu_pthread_cond_t *sched_cond;
 		starpu_worker_get_sched_condition(worker, &sched_mutex, &sched_cond);
 		starpu_worker_get_sched_condition(worker, &sched_mutex, &sched_cond);
-		STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
-		STARPU_PTHREAD_COND_SIGNAL(sched_cond);
-		STARPU_PTHREAD_MUTEX_UNLOCK(sched_mutex);
+
+		if (starpu_wakeup_worker(worker, sched_cond, sched_mutex))
+		    break; // wake up a single worker
 	}
 	}
 
 
 	return 0;
 	return 0;

+ 0 - 1
tests/perfmodels/valid_model.c

@@ -66,7 +66,6 @@ static int submit(struct starpu_codelet *codelet, struct starpu_perfmodel *model
 	conf.sched_policy_name = "eager";
 	conf.sched_policy_name = "eager";
 	conf.calibrate = 1;
 	conf.calibrate = 1;
 
 
-	initialize_model(model);
 
 
 	ret = starpu_init(&conf);
 	ret = starpu_init(&conf);
 	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
 	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;