Quellcode durchsuchen

simplify perfmodel API

Nathalie Furmento vor 9 Jahren
Ursprung
Commit
fb18de4cba

+ 2 - 2
doc/doxygen/chapters/api/performance_model.doxy

@@ -1,7 +1,7 @@
 /*
  * This file is part of the StarPU Handbook.
  * Copyright (C) 2009--2011  Universit@'e de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013, 2014  CNRS
+ * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015  CNRS
  * Copyright (C) 2011, 2012 INRIA
  * See the file version.doxy for copying conditions.
  */
@@ -202,7 +202,7 @@ in bytes
 \var double starpu_perfmodel_history_entry::flops
 Provided by the application
 
-\fn void starpu_perfmodel_init(FILE *f, struct starpu_perfmodel *model)
+\fn void starpu_perfmodel_init(struct starpu_perfmodel *model)
 \ingroup API_Performance_Model
 todo
 

+ 2 - 2
examples/cholesky/cholesky_models.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2009, 2010-2011, 2015  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013, 2014  CNRS
+ * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015  CNRS
  * Copyright (C) 2011  Télécom-SudParis
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -141,7 +141,7 @@ void initialize_chol_model(struct starpu_perfmodel* model, char * symbol,
 	model->symbol = symbol;
 	model->type = STARPU_HISTORY_BASED;
 
-	starpu_perfmodel_init(NULL, model);
+	starpu_perfmodel_init(model);
 
 	per_arch = starpu_perfmodel_get_model_per_devices(model, 0, STARPU_CPU_WORKER, 0, 1, -1);
         per_arch->cost_function = cpu_cost_function;

+ 2 - 2
examples/heat/lu_kernels_model.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2009, 2010-2011  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013, 2014  CNRS
+ * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015  CNRS
  * Copyright (C) 2011  Télécom-SudParis
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -222,7 +222,7 @@ void initialize_lu_kernels_model(struct starpu_perfmodel* model, char * symbol,
 	model->symbol = symbol;
 	model->type = STARPU_HISTORY_BASED;
 
-	starpu_perfmodel_init(NULL, model);
+	starpu_perfmodel_init(model);
 
 	starpu_perfmodel_set_per_devices_cost_function(model, 0, cpu_cost_function, STARPU_CPU_WORKER, 0, 1, -1);
 

+ 6 - 4
include/starpu_perfmodel.h

@@ -140,13 +140,15 @@ struct starpu_perfmodel
 	starpu_perfmodel_state_t state;
 };
 
-void starpu_perfmodel_init(FILE *f, struct starpu_perfmodel *model);
+void starpu_perfmodel_init(struct starpu_perfmodel *model);
+int starpu_perfmodel_load_file(const char *filename, struct starpu_perfmodel *model);
+int starpu_perfmodel_load_symbol(const char *symbol, struct starpu_perfmodel *model);
+int starpu_perfmodel_unload_model(struct starpu_perfmodel *model);
+void starpu_perfmodel_get_model_path(const char *symbol, char *path, size_t maxlen);
+
 void starpu_perfmodel_free_sampling_directories(void);
 
 struct starpu_perfmodel_arch *starpu_worker_get_perf_archtype(int workerid, unsigned sched_ctx_id);
-
-int starpu_perfmodel_load_symbol(const char *symbol, struct starpu_perfmodel *model);
-int starpu_perfmodel_unload_model(struct starpu_perfmodel *model);
 int starpu_perfmodel_get_narch_combs();
 int starpu_perfmodel_arch_comb_add(int ndevices, struct starpu_perfmodel_device* devices);
 int starpu_perfmodel_arch_comb_get(int ndevices, struct starpu_perfmodel_device *devices);

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

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2009-2015  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013, 2014  CNRS
+ * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015  CNRS
  * Copyright (C) 2011  Télécom-SudParis
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -137,7 +137,7 @@ void _starpu_init_and_load_perfmodel(struct starpu_perfmodel *model)
 	if (!model || model->is_loaded)
 		return;
 
-	starpu_perfmodel_init(NULL, model);
+	starpu_perfmodel_init(model);
 
 	if (model->is_loaded)
 		return;

+ 16 - 11
src/core/perfmodel/perfmodel_history.c

@@ -662,7 +662,7 @@ void _starpu_perfmodel_realloc(struct starpu_perfmodel *model, int nb)
 	model->state->ncombs_set = nb;
 }
 
-void starpu_perfmodel_init(FILE *f, struct starpu_perfmodel *model)
+void starpu_perfmodel_init(struct starpu_perfmodel *model)
 {
 	int already_init;
 	int i, ncombs;
@@ -707,8 +707,6 @@ void starpu_perfmodel_init(FILE *f, struct starpu_perfmodel *model)
 		model->state->nimpls[i] = 0;
 		model->state->nimpls_set[i] = 0;
 	}
-	if(f)
-		parse_model_file(f, model, 0);
 
 	/* add the model to a linked list */
 	struct _starpu_perfmodel_list *node = (struct _starpu_perfmodel_list *) malloc(sizeof(struct _starpu_perfmodel_list));
@@ -734,13 +732,13 @@ static void get_model_debug_path(struct starpu_perfmodel *model, const char *arc
 	snprintf(path, maxlen, "%s/%s.%s.%s.debug", _starpu_get_perf_model_dir_debug(), model->symbol, hostname, arch);
 }
 
-static void get_model_path(struct starpu_perfmodel *model, char *path, size_t maxlen)
+void starpu_perfmodel_get_model_path(const char *symbol, char *path, size_t maxlen)
 {
 	char hostname[65];
 	_starpu_gethostname(hostname, sizeof(hostname));
-	const char *dot = strrchr(model->symbol, '.');
+	const char *dot = strrchr(symbol, '.');
 
-	snprintf(path, maxlen, "%s/%s%s%s", _starpu_get_perf_model_dir_codelet(), model->symbol, dot?"":".", dot?"":hostname);
+	snprintf(path, maxlen, "%s/%s%s%s", _starpu_get_perf_model_dir_codelet(), symbol, dot?"":".", dot?"":hostname);
 }
 
 #ifndef STARPU_SIMGRID
@@ -753,7 +751,7 @@ static void save_history_based_model(struct starpu_perfmodel *model)
 
 	/* filename = $STARPU_PERF_MODEL_DIR/codelets/symbol.hostname */
 	char path[256];
-	get_model_path(model, path, 256);
+	starpu_perfmodel_get_model_path(model->symbol, path, 256);
 
 	_STARPU_DEBUG("Opening performance model file %s for model %s\n", path, model->symbol);
 
@@ -931,7 +929,7 @@ void _starpu_load_history_based_model(struct starpu_perfmodel *model, unsigned s
 	if(!model->is_loaded)
 	{
 		char path[256];
-		get_model_path(model, path, 256);
+		starpu_perfmodel_get_model_path(model->symbol, path, 256);
 
 		// Check if a symbol is defined before trying to load the model from a file
 		STARPU_ASSERT_MSG(model->symbol, "history-based performance models must have a symbol");
@@ -1025,7 +1023,7 @@ int starpu_perfmodel_load_symbol(const char *symbol, struct starpu_perfmodel *mo
 
 	/* where is the file if it exists ? */
 	char path[256];
-	get_model_path(model, path, 256);
+	starpu_perfmodel_get_model_path(model->symbol, path, 256);
 
 	//	_STARPU_DEBUG("get_model_path -> %s\n", path);
 
@@ -1049,10 +1047,17 @@ int starpu_perfmodel_load_symbol(const char *symbol, struct starpu_perfmodel *mo
 		return 1;
 	}
 
-	FILE *f = fopen(path, "r");
+	return starpu_perfmodel_load_file(path, model);
+}
+
+int starpu_perfmodel_load_file(const char *filename, struct starpu_perfmodel *model)
+{
+	int res;
+	FILE *f = fopen(filename, "r");
+
 	STARPU_ASSERT(f);
 
-	starpu_perfmodel_init(NULL, model);
+	starpu_perfmodel_init(model);
 
 	_starpu_frdlock(f);
 	parse_model_file(f, model, 1);