浏览代码

- with STARPU_CALIBRATE=2, StarPU calibrates performance models, but overwrites
existing ones.
- bug fix: when the user gives a non NULL argument to starpu_init, we don't
ignore the .calibrate field anymore.

Cédric Augonnet 15 年之前
父节点
当前提交
710e89d51f

+ 18 - 8
src/core/perfmodel/perfmodel.c

@@ -22,6 +22,23 @@
 #include <core/workers.h>
 #include <core/workers.h>
 #include <datawizard/datawizard.h>
 #include <datawizard/datawizard.h>
 
 
+/* This flag indicates whether performance models should be calibrated or not.
+ *	0: models need not be calibrated
+ *	1: models must be calibrated
+ *	2: models must be calibrated, existing models are overwritten.
+ */
+static unsigned calibrate_flag = 0;
+
+void _starpu_set_calibrate_flag(unsigned val)
+{
+	calibrate_flag = val;
+}
+
+unsigned _starpu_get_calibrate_flag(void)
+{
+	return calibrate_flag;
+}
+
 /*
 /*
  * PER ARCH model
  * PER ARCH model
  */
  */
@@ -33,14 +50,7 @@ static double per_arch_task_expected_length(struct starpu_perfmodel_t *model, en
 	
 	
 	if (!model->is_loaded)
 	if (!model->is_loaded)
 	{
 	{
-		if (starpu_get_env_number("STARPU_CALIBRATE") != -1)
-		{
-			fprintf(stderr, "STARPU_CALIBRATE model %s\n", model->symbol);
-			model->benchmarking = 1;
-		}
-		else {
-			model->benchmarking = 0;
-		}
+		model->benchmarking = _starpu_get_calibrate_flag();
 		
 		
 		_starpu_register_model(model);
 		_starpu_register_model(model);
 		model->is_loaded = 1;
 		model->is_loaded = 1;

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

@@ -103,6 +103,9 @@ void _starpu_create_sampling_directory_if_needed(void);
 void _starpu_load_bus_performance_files(void);
 void _starpu_load_bus_performance_files(void);
 double _starpu_predict_transfer_time(unsigned src_node, unsigned dst_node, size_t size);
 double _starpu_predict_transfer_time(unsigned src_node, unsigned dst_node, size_t size);
 
 
+void _starpu_set_calibrate_flag(unsigned val);
+unsigned _starpu_get_calibrate_flag(void);
+
 #ifdef STARPU_USE_CUDA
 #ifdef STARPU_USE_CUDA
 int *_starpu_get_gpu_affinity_vector(unsigned gpuid);
 int *_starpu_get_gpu_affinity_vector(unsigned gpuid);
 #endif
 #endif

+ 26 - 20
src/core/perfmodel/perfmodel_history.c

@@ -345,39 +345,45 @@ static void load_history_based_model(struct starpu_perfmodel_t *model, unsigned
 #ifdef STARPU_VERBOSE
 #ifdef STARPU_VERBOSE
 	fprintf(stderr, "Opening performance model file %s for model %s ... ", path, model->symbol);
 	fprintf(stderr, "Opening performance model file %s for model %s ... ", path, model->symbol);
 #endif
 #endif
+	unsigned calibrate_flag = _starpu_get_calibrate_flag();
+	model->benchmarking = calibrate_flag; 
 	
 	
 	/* try to open an existing file and load it */
 	/* try to open an existing file and load it */
 	res = access(path, F_OK); 
 	res = access(path, F_OK); 
 	if (res == 0) {
 	if (res == 0) {
+		if (calibrate_flag == 2)
+		{
+			/* The user specified that the performance model should
+			 * be overwritten, so we don't load the existing file !
+			 * */
 #ifdef STARPU_VERBOSE
 #ifdef STARPU_VERBOSE
-		fprintf(stderr, "File exists !\n");
+			fprintf(stderr, "Overwrite existing file\n");
 #endif
 #endif
-
-		FILE *f;
-		f = fopen(path, "r");
-		STARPU_ASSERT(f);
-
-		parse_model_file(f, model, scan_history);
-
-		fclose(f);
+	
+			initialize_model(model);
+		}
+		else {
+			/* We load the available file */
+#ifdef STARPU_VERBOSE
+			fprintf(stderr, "File exists\n");
+#endif
+	
+			FILE *f;
+			f = fopen(path, "r");
+			STARPU_ASSERT(f);
+	
+			parse_model_file(f, model, scan_history);
+	
+			fclose(f);
+		}
 	}
 	}
 	else {
 	else {
 #ifdef STARPU_VERBOSE
 #ifdef STARPU_VERBOSE
-		fprintf(stderr, "File does not exists !\n");
+		fprintf(stderr, "File does not exists\n");
 #endif
 #endif
 		initialize_model(model);
 		initialize_model(model);
 	}
 	}
 
 
-
-	if (starpu_get_env_number("STARPU_CALIBRATE") != -1)
-	{
-		fprintf(stderr, "STARPU_CALIBRATE model %s\n", model->symbol);
-		model->benchmarking = 1;
-	}
-	else {
-		model->benchmarking = 0;
-	}
-
 	model->is_loaded = STARPU_PERFMODEL_LOADED;
 	model->is_loaded = STARPU_PERFMODEL_LOADED;
 
 
 	res = pthread_rwlock_unlock(&model->model_rwlock);
 	res = pthread_rwlock_unlock(&model->model_rwlock);

+ 13 - 0
src/core/policies/sched_policy.c

@@ -164,6 +164,19 @@ void _starpu_init_sched_policy(struct starpu_machine_config_s *config)
 	if (use_prefetch == -1)
 	if (use_prefetch == -1)
 		use_prefetch = 0;
 		use_prefetch = 0;
 
 
+	/* By default, we don't calibrate */
+	unsigned do_calibrate = 0;
+	if (config->user_conf)
+	{
+		do_calibrate = config->user_conf->calibrate;
+	}
+	else {
+		int res = starpu_get_env_number("STARPU_CALIBRATE");
+		do_calibrate =  (res < 0)?0:(unsigned)res;
+	}
+
+	_starpu_set_calibrate_flag(do_calibrate);
+
 	struct starpu_sched_policy_s *selected_policy;
 	struct starpu_sched_policy_s *selected_policy;
 	selected_policy = select_sched_policy(config);
 	selected_policy = select_sched_policy(config);
 
 

+ 1 - 1
src/core/workers.c

@@ -479,7 +479,7 @@ void starpu_shutdown(void)
 	_starpu_display_comm_amounts();
 	_starpu_display_comm_amounts();
 #endif
 #endif
 
 
-	if (starpu_get_env_number("STARPU_CALIBRATE") != -1)
+	if (_starpu_get_calibrate_flag())
 		_starpu_dump_registered_models();
 		_starpu_dump_registered_models();
 
 
 	/* wait for their termination */
 	/* wait for their termination */