Explorar el Código

src: avoid using hard-coded numbers

Nathalie Furmento hace 7 años
padre
commit
1112e8f712
Se han modificado 2 ficheros con 43 adiciones y 37 borrados
  1. 19 17
      src/core/perfmodel/perfmodel_bus.c
  2. 24 20
      src/core/perfmodel/perfmodel_history.c

+ 19 - 17
src/core/perfmodel/perfmodel_bus.c

@@ -55,6 +55,8 @@
 #define SIZE	(32*1024*1024*sizeof(char))
 #define NITER	32
 
+#define PATH_LENGTH 256
+
 #ifndef STARPU_SIMGRID
 static void _starpu_bus_force_sampling(void);
 #endif
@@ -854,7 +856,7 @@ static void load_bus_affinity_file_content(void)
 	FILE *f;
 	int locked;
 
-	char path[256];
+	char path[PATH_LENGTH];
 	get_affinity_path(path, sizeof(path));
 
 	_STARPU_DEBUG("loading affinities from %s\n", path);
@@ -929,7 +931,7 @@ static void write_bus_affinity_file_content(void)
 
 #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
 	FILE *f;
-	char path[256];
+	char path[PATH_LENGTH];
 	int locked;
 
 	get_affinity_path(path, sizeof(path));
@@ -1026,7 +1028,7 @@ static int check_bus_affinity_file(void)
 	int locked;
 	unsigned dummy;
 
-	char path[256];
+	char path[PATH_LENGTH];
 	get_affinity_path(path, sizeof(path));
 
 	_STARPU_DEBUG("loading affinities from %s\n", path);
@@ -1053,7 +1055,7 @@ static void load_bus_affinity_file(void)
 {
 	int exist, check = 1;
 
-	char path[256];
+	char path[PATH_LENGTH];
 	get_affinity_path(path, sizeof(path));
 
 	/* access return 0 if file exists */
@@ -1142,7 +1144,7 @@ static int load_bus_latency_file_content(void)
 	double latency;
 	int locked;
 
-	char path[256];
+	char path[PATH_LENGTH];
 	get_latency_path(path, sizeof(path));
 
 	_STARPU_DEBUG("loading latencies from %s\n", path);
@@ -1286,7 +1288,7 @@ static void write_bus_latency_file_content(void)
 
 	STARPU_ASSERT(was_benchmarked);
 
-	char path[256];
+	char path[PATH_LENGTH];
 	get_latency_path(path, sizeof(path));
 
 	_STARPU_DEBUG("writing latencies to %s\n", path);
@@ -1454,7 +1456,7 @@ static void load_bus_latency_file(void)
 {
 	int res;
 
-	char path[256];
+	char path[PATH_LENGTH];
 	get_latency_path(path, sizeof(path));
 
 	res = access(path, F_OK);
@@ -1483,7 +1485,7 @@ static int load_bus_bandwidth_file_content(void)
 	double bandwidth;
 	int locked;
 
-	char path[256];
+	char path[PATH_LENGTH];
 	get_bandwidth_path(path, sizeof(path));
 
 	_STARPU_DEBUG("loading bandwidth from %s\n", path);
@@ -1626,7 +1628,7 @@ static void write_bus_bandwidth_file_content(void)
 
 	STARPU_ASSERT(was_benchmarked);
 
-	char path[256];
+	char path[PATH_LENGTH];
 	get_bandwidth_path(path, sizeof(path));
 
 	_STARPU_DEBUG("writing bandwidth to %s\n", path);
@@ -1777,9 +1779,9 @@ static void write_bus_bandwidth_file_content(void)
 
 void starpu_bus_print_filenames(FILE *output)
 {
-	char bandwidth_path[256];
-	char affinity_path[256];
-	char latency_path[256];
+	char bandwidth_path[PATH_LENGTH];
+	char affinity_path[PATH_LENGTH];
+	char latency_path[PATH_LENGTH];
 
 	get_bandwidth_path(bandwidth_path, sizeof(bandwidth_path));
 	get_affinity_path(affinity_path, sizeof(affinity_path));
@@ -1923,7 +1925,7 @@ static void load_bus_bandwidth_file(void)
 {
 	int res;
 
-	char path[256];
+	char path[PATH_LENGTH];
 	get_bandwidth_path(path, sizeof(path));
 
 	res = access(path, F_OK);
@@ -1995,7 +1997,7 @@ static void compare_value_and_recalibrate(char * msg, unsigned val_file, unsigne
 static void check_bus_config_file(void)
 {
 	int res;
-	char path[256];
+	char path[PATH_LENGTH];
 	struct _starpu_machine_config *config = _starpu_get_machine_config();
 	int recalibrate = 0;
 
@@ -2091,7 +2093,7 @@ static void check_bus_config_file(void)
 static void write_bus_config_file_content(void)
 {
 	FILE *f;
-	char path[256];
+	char path[PATH_LENGTH];
 	int locked;
 
 	STARPU_ASSERT(was_benchmarked);
@@ -2566,7 +2568,7 @@ static void clean_topology(hwloc_obj_t obj)
 static void write_bus_platform_file_content(int version)
 {
 	FILE *f;
-	char path[256];
+	char path[PATH_LENGTH];
 	unsigned i;
 	const char *speed, *flops, *Bps, *s;
 	char dash;
@@ -2882,7 +2884,7 @@ static void check_bus_platform_file(void)
 {
 	int res;
 
-	char path[256];
+	char path[PATH_LENGTH];
 	_starpu_simgrid_get_platform_path(4, path, sizeof(path));
 
 	res = access(path, F_OK);

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

@@ -46,6 +46,10 @@
 #define HASH_ADD_UINT32_T(head,field,add) HASH_ADD(hh,head,field,sizeof(uint32_t),add)
 #define HASH_FIND_UINT32_T(head,find,out) HASH_FIND(hh,head,find,sizeof(uint32_t),out)
 
+#define STR_SHORT_LENGTH 32
+#define STR_LONG_LENGTH 256
+#define STR_VERY_LONG_LENGTH 1024
+
 static struct starpu_perfmodel_arch **arch_combs;
 static int current_arch_comb;
 static int nb_arch_combs;
@@ -505,7 +509,7 @@ static void scan_history_entry(FILE *f, const char *path, struct starpu_perfmode
 	double sum;
 	double sum2;
 
-	char line[256];
+	char line[STR_LONG_LENGTH];
 	char *ret;
 
 	ret = fgets(line, sizeof(line), f);
@@ -753,8 +757,8 @@ static void check_per_arch_model(struct starpu_perfmodel *model, int comb, unsig
 	}
 
 	/* header */
-	char archname[32];
-	starpu_perfmodel_get_arch_name(arch_combs[comb], archname,  32, impl);
+	char archname[STR_SHORT_LENGTH];
+	starpu_perfmodel_get_arch_name(arch_combs[comb], archname,  sizeof(archname), impl);
 	STARPU_ASSERT(strlen(archname)>0);
 	check_reg_model(model, comb, impl);
 
@@ -790,8 +794,8 @@ static void dump_per_arch_model_file(FILE *f, struct starpu_perfmodel *model, in
 	}
 
 	/* header */
-	char archname[32];
-	starpu_perfmodel_get_arch_name(arch_combs[comb], archname,  32, impl);
+	char archname[STR_SHORT_LENGTH];
+	starpu_perfmodel_get_arch_name(arch_combs[comb], archname,  sizeof(archname), impl);
 	fprintf(f, "#####\n");
 	fprintf(f, "# Model for %s\n", archname);
 	fprintf(f, "# number of entries\n%u\n", nentries);
@@ -1004,8 +1008,8 @@ static void save_history_based_model(struct starpu_perfmodel *model)
 	/* TODO checks */
 
 	/* filename = $STARPU_PERF_MODEL_DIR/codelets/symbol.hostname */
-	char path[256];
-	starpu_perfmodel_get_model_path(model->symbol, path, 256);
+	char path[STR_LONG_LENGTH];
+	starpu_perfmodel_get_model_path(model->symbol, path, sizeof(path));
 
 	_STARPU_DEBUG("Opening performance model file %s for model %s\n", path, model->symbol);
 
@@ -1195,11 +1199,11 @@ void _starpu_load_history_based_model(struct starpu_perfmodel *model, unsigned s
 
 	if(!model->is_loaded)
 	{
-		char path[256];
+		char path[STR_LONG_LENGTH];
 		// 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");
 
-		starpu_perfmodel_get_model_path(model->symbol, path, 256);
+		starpu_perfmodel_get_model_path(model->symbol, path, sizeof(path));
 
 		_STARPU_DEBUG("Opening performance model file %s for model %s ...\n", path, model->symbol);
 
@@ -1284,8 +1288,8 @@ int starpu_perfmodel_load_symbol(const char *symbol, struct starpu_perfmodel *mo
 	model->symbol = strdup(symbol);
 
 	/* where is the file if it exists ? */
-	char path[256];
-	starpu_perfmodel_get_model_path(model->symbol, path, 256);
+	char path[STR_LONG_LENGTH];
+	starpu_perfmodel_get_model_path(model->symbol, path, sizeof(path));
 
 	//	_STARPU_DEBUG("get_model_path -> %s\n", path);
 
@@ -1378,7 +1382,7 @@ void starpu_perfmodel_get_arch_name(struct starpu_perfmodel_arch* arch, char *ar
 	int comb = _starpu_perfmodel_create_comb_if_needed(arch);
 
 	STARPU_ASSERT(comb != -1);
-	char devices[1024];
+	char devices[STR_VERY_LONG_LENGTH];
 	int written = 0;
 	strcpy(devices, "");
 	for(i=0 ; i<arch->ndevices ; i++)
@@ -1393,8 +1397,8 @@ void starpu_perfmodel_debugfilepath(struct starpu_perfmodel *model,
 {
 	int comb = starpu_perfmodel_arch_comb_get(arch->ndevices, arch->devices);
 	STARPU_ASSERT(comb != -1);
-	char archname[32];
-	starpu_perfmodel_get_arch_name(arch, archname, 32, nimpl);
+	char archname[STR_SHORT_LENGTH];
+	starpu_perfmodel_get_arch_name(arch, archname, sizeof(archname), nimpl);
 
 	STARPU_ASSERT(path);
 
@@ -1426,7 +1430,7 @@ docal:
 	STARPU_HG_DISABLE_CHECKING(model->benchmarking);
 	if (isnan(exp) && !model->benchmarking)
 	{
-		char archname[32];
+		char archname[STR_SHORT_LENGTH];
 
 		starpu_perfmodel_get_arch_name(arch, archname, sizeof(archname), nimpl);
 		_STARPU_DISP("Warning: model %s is not calibrated enough for %s size %lu (only %u measurements from size %lu to %lu), forcing calibration for this run. Use the STARPU_CALIBRATE environment variable to control this.\n", model->symbol, archname, (unsigned long) size, regmodel?regmodel->nsample:0, regmodel?regmodel->minx:0, regmodel?regmodel->maxx:0);
@@ -1479,7 +1483,7 @@ docal:
 		STARPU_HG_DISABLE_CHECKING(model->benchmarking);
 		if (isnan(exp) && !model->benchmarking)
 		{
-			char archname[32];
+			char archname[STR_SHORT_LENGTH];
 
 			starpu_perfmodel_get_arch_name(arch, archname, sizeof(archname), nimpl);
 			_STARPU_DISP("Warning: model %s is not calibrated enough for %s size %lu (only %u measurements), forcing calibration for this run. Use the STARPU_CALIBRATE environment variable to control this.\n", model->symbol, archname, (unsigned long) size, entry && entry->history_entry ? entry->history_entry->nsample : 0);
@@ -1526,7 +1530,7 @@ docal:
 	STARPU_HG_DISABLE_CHECKING(model->benchmarking);
 	if (isnan(expected_duration) && !model->benchmarking)
 	{
-		char archname[32];
+		char archname[STR_SHORT_LENGTH];
 
 		starpu_perfmodel_get_arch_name(arch, archname, sizeof(archname), nimpl);
 		_STARPU_DISP("Warning: model %s is not calibrated enough for %s, forcing calibration for this run. Use the STARPU_CALIBRATE environment variable to control this.\n", model->symbol, archname);
@@ -1586,7 +1590,7 @@ docal:
 	STARPU_HG_DISABLE_CHECKING(model->benchmarking);
 	if (isnan(exp) && !model->benchmarking)
 	{
-		char archname[32];
+		char archname[STR_SHORT_LENGTH];
 
 		starpu_perfmodel_get_arch_name(arch, archname, sizeof(archname), nimpl);
 		_STARPU_DISP("Warning: model %s is not calibrated enough for %s size %ld (only %u measurements), forcing calibration for this run. Use the STARPU_CALIBRATE environment variable to control this.\n", model->symbol, archname, j->task?(long int)_starpu_job_get_data_size(model, arch, nimpl, j):-1, entry ? entry->nsample : 0);
@@ -1715,7 +1719,7 @@ void _starpu_update_perfmodel_history(struct _starpu_job *j, struct starpu_perfm
 					/* More errors than measurements, we're most probably completely wrong, we flush out all the entries */
 					if (entry->nerror >= entry->nsample)
 					{
-						char archname[32];
+						char archname[STR_SHORT_LENGTH];
 						starpu_perfmodel_get_arch_name(arch, archname, sizeof(archname), impl);
 						_STARPU_DISP("Too big deviation for model %s on %s: %f vs average %f, %u such errors against %u samples (%+f%%), flushing the performance model. Use the STARPU_HISTORY_MAX_ERROR environement variable to control the threshold (currently %d%%)\n", model->symbol, archname, measured, entry->mean, entry->nerror, entry->nsample, measured * 100. / entry->mean - 100, historymaxerror);
 						entry->sum = 0.0;
@@ -1806,7 +1810,7 @@ void _starpu_update_perfmodel_history(struct _starpu_job *j, struct starpu_perfm
 
 #ifdef STARPU_MODEL_DEBUG
 		struct starpu_task *task = j->task;
-		starpu_perfmodel_debugfilepath(model, arch_combs[comb], per_arch_model->debug_path, 256, impl);
+		starpu_perfmodel_debugfilepath(model, arch_combs[comb], per_arch_model->debug_path, STR_LONG_LENGTH, impl);
 		FILE *f = fopen(per_arch_model->debug_path, "a+");
 		int locked;
 		if (f == NULL)