소스 검색

src: update double values usage

      - use fpclassify to test if double values are equal to 0
      - use NAN as a special marker value instead of -1.0 and test value with isnan()
Nathalie Furmento 13 년 전
부모
커밋
e5f68ad9d6

+ 4 - 1
src/common/utils.h

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010  Université de Bordeaux 1
- * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -25,6 +25,7 @@
 #include <pthread.h>
 #include <common/barrier.h>
 #include <stdlib.h>
+#include <math.h>
 
 #ifdef STARPU_VERBOSE
 #  define _STARPU_DEBUG(fmt, args ...) do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, "[starpu][%s] " fmt ,__func__ ,##args); fflush(stderr); }} while(0)
@@ -50,6 +51,8 @@
 	} while (0)
 
 
+#define _STARPU_IS_ZERO(a) (fpclassify(a) == FP_ZERO)
+
 int _starpu_mkpath(const char *s, mode_t mode);
 int _starpu_check_mutex_deadlock(pthread_mutex_t *mutex);
 

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

@@ -70,7 +70,7 @@ enum starpu_perf_archtype starpu_worker_get_perf_archtype(int workerid)
 
 static double per_arch_task_expected_perf(struct starpu_perfmodel *model, enum starpu_perf_archtype arch, struct starpu_task *task, unsigned nimpl)
 {
-	double exp = -1.0;
+	double exp = NAN;
 	double (*per_arch_cost_function)(struct starpu_task *task, enum starpu_perf_archtype arch, unsigned nimpl);
 	double (*per_arch_cost_model)(struct starpu_buffer_descr *);
 
@@ -112,7 +112,7 @@ double starpu_worker_get_relative_speedup(enum starpu_perf_archtype perf_archtyp
 	STARPU_ABORT();
 
 	/* Never reached ! */
-	return -1.0;
+	return NAN;
 }
 
 static double common_task_expected_perf(struct starpu_perfmodel *model, enum starpu_perf_archtype arch, struct starpu_task *task, unsigned nimpl)
@@ -125,7 +125,7 @@ static double common_task_expected_perf(struct starpu_perfmodel *model, enum sta
 		exp = model->cost_function(task, nimpl);
 		alpha = starpu_worker_get_relative_speedup(arch);
 
-		STARPU_ASSERT(alpha != 0.0f);
+		STARPU_ASSERT(!_STARPU_IS_ZERO(alpha));
 
 		return (exp/alpha);
 	}
@@ -134,12 +134,12 @@ static double common_task_expected_perf(struct starpu_perfmodel *model, enum sta
 		exp = model->cost_model(task->buffers);
 		alpha = starpu_worker_get_relative_speedup(arch);
 
-		STARPU_ASSERT(alpha != 0.0f);
+		STARPU_ASSERT(!_STARPU_IS_ZERO(alpha));
 
 		return (exp/alpha);
 	}
 
-	return -1.0;
+	return NAN;
 }
 
 void _starpu_load_perfmodel(struct starpu_perfmodel *model)

+ 4 - 4
src/core/perfmodel/perfmodel_bus.c

@@ -54,8 +54,8 @@ struct dev_timing
 	double timing_dtoh;
 };
 
-static double bandwidth_matrix[STARPU_MAXNODES][STARPU_MAXNODES] = {{-1.0}};
-static double latency_matrix[STARPU_MAXNODES][STARPU_MAXNODES] = {{ -1.0}};
+static double bandwidth_matrix[STARPU_MAXNODES][STARPU_MAXNODES] = {{NAN}};
+static double latency_matrix[STARPU_MAXNODES][STARPU_MAXNODES] = {{NAN}};
 static unsigned was_benchmarked = 0;
 static unsigned ncpus = 0;
 static int ncuda = 0;
@@ -850,7 +850,7 @@ static void write_bus_latency_file_content(void)
 			if ((src > maxnode) || (dst > maxnode))
 			{
 				/* convention */
-				latency = -1.0;
+				latency = NAN;
 			}
 			else if (src == dst)
 			{
@@ -988,7 +988,7 @@ static void write_bus_bandwidth_file_content(void)
 
 			if ((src > maxnode) || (dst > maxnode))
 			{
-				bandwidth = -1.0;
+				bandwidth = NAN;
 			}
 #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
 			else if (src != dst)

+ 7 - 6
src/core/perfmodel/perfmodel_history.c

@@ -21,6 +21,7 @@
 #include <sys/stat.h>
 #include <errno.h>
 #include <common/config.h>
+#include <common/utils.h>
 #include <core/perfmodel/perfmodel.h>
 #include <core/jobs.h>
 #include <core/workers.h>
@@ -889,7 +890,7 @@ void starpu_perfmodel_debugfilepath(struct starpu_perfmodel *model,
 
 double _starpu_regression_based_job_expected_perf(struct starpu_perfmodel *model, enum starpu_perf_archtype arch, struct _starpu_job *j, unsigned nimpl)
 {
-	double exp = -1.0;
+	double exp = NAN;
 	size_t size = _starpu_job_get_data_size(model, arch, nimpl, j);
 	struct starpu_regression_model *regmodel;
 
@@ -903,7 +904,7 @@ double _starpu_regression_based_job_expected_perf(struct starpu_perfmodel *model
 
 double _starpu_non_linear_regression_based_job_expected_perf(struct starpu_perfmodel *model, enum starpu_perf_archtype arch, struct _starpu_job *j,unsigned nimpl)
 {
-	double exp = -1.0;
+	double exp = NAN;
 	size_t size = _starpu_job_get_data_size(model, arch, nimpl, j);
 	struct starpu_regression_model *regmodel;
 
@@ -948,21 +949,21 @@ double _starpu_history_based_job_expected_perf(struct starpu_perfmodel *model, e
 
 	history = per_arch_model->history;
 	if (!history)
-		return -1.0;
+		return NAN;
 
 	_STARPU_PTHREAD_RWLOCK_RDLOCK(&model->model_rwlock);
 	entry = (struct starpu_history_entry *) _starpu_htbl_search_32(history, key);
 	_STARPU_PTHREAD_RWLOCK_UNLOCK(&model->model_rwlock);
 
-	exp = entry?entry->mean:-1.0;
+	exp = entry?entry->mean:NAN;
 
 	if (entry && entry->nsample < _STARPU_CALIBRATION_MINIMUM)
 		/* TODO: report differently if we've scheduled really enough
 		 * of that task and the scheduler should perhaps put it aside */
 		/* Not calibrated enough */
-		exp = -1.0;
+		exp = NAN;
 
-	if (exp == -1.0 && !model->benchmarking)
+	if (isnan(exp) && !model->benchmarking)
 	{
 		_STARPU_DISP("Warning: model %s is not calibrated enough, forcing calibration for this run. Use the STARPU_CALIBRATE environment variable to control this.\n", model->symbol);
 		_starpu_set_calibrate_flag(1);

+ 3 - 2
src/core/task.c

@@ -26,6 +26,7 @@
 #include <common/utils.h>
 #include <profiling/profiling.h>
 #include <profiling/bound.h>
+#include <math.h>
 
 /* XXX this should be reinitialized when StarPU is shutdown (or we should make
  * sure that no task remains !) */
@@ -74,8 +75,8 @@ void starpu_task_init(struct starpu_task *task)
 
 	task->profiling_info = NULL;
 
-	task->predicted = -1.0;
-	task->predicted_transfer = -1.0;
+	task->predicted = NAN;
+	task->predicted_transfer = NAN;
 
 	task->starpu_private = NULL;
 	task->magic = 42;

+ 2 - 2
src/datawizard/coherency.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2009-2011  Université de Bordeaux 1
- * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -67,7 +67,7 @@ uint32_t _starpu_select_src_node(starpu_data_handle_t handle, unsigned destinati
 				if (!link_supports_direct_transfers(handle, i, destination, &handling_node))
 					continue;
 
-				if (time == 0.0)
+				if (_STARPU_IS_ZERO(time))
 				{
 					/* No estimation, will have to revert to dumb strategy */
 					cost = 0.0;

+ 14 - 14
src/profiling/bound.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  * Copyright (C) 2010, 2011  Université de Bordeaux 1
  * Copyright (C) 2011  Télécom-SudParis
  *
@@ -353,8 +353,8 @@ static void _starpu_get_tasks_times(int nw, int nt, double *times)
 			};
 			enum starpu_perf_archtype arch = starpu_worker_get_perf_archtype(w);
 			double length = _starpu_history_based_job_expected_perf(tp->cl->model, arch, &j, j.nimpl);
-			if (length == -1.0)
-				times[w*nt+t] = -1.0;
+			if (isnan(length))
+				times[w*nt+t] = NAN;
 			else
 				times[w*nt+t] = length / 1000.;
 		}
@@ -429,12 +429,12 @@ void starpu_bound_print_lp(FILE *output)
 			for (w = 0; w < nw; w++)
 			{
 				enum starpu_perf_archtype arch = starpu_worker_get_perf_archtype(w);
-				if (t1->duration[arch] == 0.)
+				if (_STARPU_IS_ZERO(t1->duration[arch]))
 				{
 					double length = _starpu_history_based_job_expected_perf(t1->cl->model, arch, &j,j.nimpl);
-					if (length == -1.0)
+					if (isnan(length))
 						/* Avoid problems with binary coding of doubles */
-						t1->duration[arch] = -1.0;
+						t1->duration[arch] = NAN;
 					else
 						t1->duration[arch] = length / 1000.;
 				}
@@ -456,7 +456,7 @@ void starpu_bound_print_lp(FILE *output)
 			for (w = 0; w < nw; w++)
 			{
 				enum starpu_perf_archtype arch = starpu_worker_get_perf_archtype(w);
-				if (t1->duration[arch] != -1.0)
+				if (!isnan(t1->duration[arch]))
 					fprintf(output, " +t%luw%d", t1->id, w);
 			}
 			fprintf(output, " = 1;\n");
@@ -470,7 +470,7 @@ void starpu_bound_print_lp(FILE *output)
 			for (w = 0; w < nw; w++)
 			{
 				enum starpu_perf_archtype arch = starpu_worker_get_perf_archtype(w);
-				if (t1->duration[arch] != -1.0)
+				if (!isnan(t1->duration[arch]))
 					fprintf(output, " + %f t%luw%d", t1->duration[arch], t1->id, w);
 			}
 			fprintf(output, ";\n");
@@ -506,7 +506,7 @@ void starpu_bound_print_lp(FILE *output)
 					for (w = 0; w < nw; w++)
 					{
 						enum starpu_perf_archtype arch = starpu_worker_get_perf_archtype(w);
-						if (t1->duration[arch] != -1.0)
+						if (!isnan(t1->duration[arch]))
 						{
 							fprintf(output, "s%lu - c%lu >= -3e5 + 1e5 t%luw%d + 1e5 t%luw%d + 1e5 t%luafter%lu;\n",
 									t1->id, t2->id, t1->id, w, t2->id, w, t1->id, t2->id);
@@ -651,7 +651,7 @@ void starpu_bound_print_lp(FILE *output)
 				fprintf(output, "/* worker %s */\n0", name);
 				for (t = 0, tp = task_pools; tp; t++, tp = tp->next)
 				{
-					if (times[w*nt+t] != -1.0)
+					if (!isnan(times[w*nt+t]))
 						fprintf(output, "\t%+f * w%dt%dn", (float) times[w*nt+t], w, t);
 				}
 				fprintf(output, " <= tmax;\n");
@@ -663,7 +663,7 @@ void starpu_bound_print_lp(FILE *output)
 			{
 				fprintf(output, "/* task %s key %x */\n0", tp->cl->name, (unsigned) tp->footprint);
 				for (w = 0; w < nw; w++)
-					if (times[w*nt+t] != -1.0)
+					if (!isnan(times[w*nt+t]))
 						fprintf(output, "\t+w%dt%dn", w, t);
 				fprintf(output, " = %lu;\n", tp->n);
 				/* Show actual values */
@@ -747,7 +747,7 @@ void starpu_bound_print_mps(FILE *output)
 		fprintf(output, "\n* Execution times and completion of all tasks\n");
 		for (w = 0; w < nw; w++)
 			for (t = 0, tp = task_pools; tp; t++, tp = tp->next)
-				if (times[w*nt+t] != -1.0)
+				if (!isnan(times[w*nt+t]))
 				{
 					char name[9];
 					snprintf(name, sizeof(name), "W%dT%d", w, t);
@@ -830,7 +830,7 @@ static glp_prob *_starpu_bound_glp_resolve(int integer)
 		{
 			int someone = 0;
 			for (w = 0; w < nw; w++)
-				if (times[w*nt+t] != -1.)
+				if (!isnan(times[w*nt+t]))
 					someone = 1;
 			if (!someone)
 			{
@@ -849,7 +849,7 @@ static glp_prob *_starpu_bound_glp_resolve(int integer)
 			{
 				ia[n] = w+1;
 				ja[n] = colnum(w, t);
-				if (times[w*nt+t] == -1.)
+				if (isnan(times[w*nt+t]))
 					ar[n] = 1000000000.;
 				else
 					ar[n] = times[w*nt+t];

+ 12 - 12
src/sched_policies/deque_modeling_policy_data_aware.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010, 2011-2012  Université de Bordeaux 1
- * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  * Copyright (C) 2011  Télécom-SudParis
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -344,17 +344,17 @@ static int _dm_push_task(struct starpu_task *task, unsigned prio)
 			//_STARPU_DEBUG("Scheduler dm: task length (%lf) worker (%u) kernel (%u) \n", local_length,worker,nimpl);
 
 			if (ntasks_best == -1
-					|| (!calibrating && ntasks_end < ntasks_best_end) /* Not calibrating, take better task */
-					|| (!calibrating && local_length == -1.0) /* Not calibrating but this worker is being calibrated */
-					|| (calibrating && local_length == -1.0 && ntasks_end < ntasks_best_end) /* Calibrating, compete this worker with other non-calibrated */
-					)
+			    || (!calibrating && ntasks_end < ntasks_best_end) /* Not calibrating, take better task */
+			    || (!calibrating && isnan(local_length)) /* Not calibrating but this worker is being calibrated */
+			    || (calibrating && isnan(local_length) && ntasks_end < ntasks_best_end) /* Calibrating, compete this worker with other non-calibrated */
+				)
 			{
 				ntasks_best_end = ntasks_end;
 				ntasks_best = worker;
 				best_impl = nimpl;
 			}
 
-			if (local_length == -1.0)
+			if (isnan(local_length))
 				/* we are calibrating, we want to speed-up calibration time
 				 * so we privilege non-calibrated tasks (but still
 				 * greedily distribute them to avoid dumb schedules) */
@@ -457,17 +457,17 @@ static int _dmda_push_task(struct starpu_task *task, unsigned prio)
 			double ntasks_end = fifo->ntasks / starpu_worker_get_relative_speedup(perf_arch);
 
 			if (ntasks_best == -1
-					|| (!calibrating && ntasks_end < ntasks_best_end) /* Not calibrating, take better task */
-					|| (!calibrating && local_task_length[worker][nimpl] == -1.0) /* Not calibrating but this worker is being calibrated */
-					|| (calibrating && local_task_length[worker][nimpl] == -1.0 && ntasks_end < ntasks_best_end) /* Calibrating, compete this worker with other non-calibrated */
-					)
+			    || (!calibrating && ntasks_end < ntasks_best_end) /* Not calibrating, take better task */
+			    || (!calibrating && isnan(local_task_length[worker][nimpl])) /* Not calibrating but this worker is being calibrated */
+			    || (calibrating && isnan(local_task_length[worker][nimpl]) && ntasks_end < ntasks_best_end) /* Calibrating, compete this worker with other non-calibrated */
+				)
 			{
 				ntasks_best_end = ntasks_end;
 				ntasks_best = worker;
 				best_impl = nimpl;
 			}
 
-			if (local_task_length[worker][nimpl] == -1.0)
+			if (isnan(local_task_length[worker][nimpl]))
 				/* we are calibrating, we want to speed-up calibration time
 				 * so we privilege non-calibrated tasks (but still
 				 * greedily distribute them to avoid dumb schedules) */
@@ -491,7 +491,7 @@ static int _dmda_push_task(struct starpu_task *task, unsigned prio)
 			}
 
 			local_power[worker][nimpl] = starpu_task_expected_power(task, perf_arch, nimpl);
-			if (local_power[worker][nimpl] == -1.0)
+			if (isnan(local_power[worker][nimpl]))
 				local_power[worker][nimpl] = 0.;
 
 		 }

+ 7 - 7
src/sched_policies/heft.c

@@ -139,7 +139,7 @@ static void heft_push_task_notify(struct starpu_task *task, int workerid)
 	exp_end[workerid] = exp_start[workerid] + exp_len[workerid];
 
 	/* If there is no prediction available, we consider the task has a null length */
-	if (predicted != -1.0)
+	if (!isnan(predicted))
 	{
 		task->predicted = predicted;
 		exp_end[workerid] += predicted;
@@ -147,7 +147,7 @@ static void heft_push_task_notify(struct starpu_task *task, int workerid)
 	}
 
 	/* If there is no prediction available, we consider the task has a null length */
-	if (predicted_transfer != -1.0)
+	if (!isnan(predicted_transfer))
 	{
 		if (starpu_timing_now() + predicted_transfer < exp_end[workerid])
 		{
@@ -289,9 +289,9 @@ static void compute_all_performance_predictions(struct starpu_task *task,
 			double ntasks_end = ntasks[worker] / starpu_worker_get_relative_speedup(perf_arch);
 
 			if (ntasks_best == -1
-				|| (!calibrating && ntasks_end < ntasks_best_end) /* Not calibrating, take better task */
-				|| (!calibrating && local_task_length[worker][nimpl] == -1.0) /* Not calibrating but this worker is being calibrated */
-				|| (calibrating && local_task_length[worker][nimpl] == -1.0 && ntasks_end < ntasks_best_end) /* Calibrating, compete this worker with other non-calibrated */
+			    || (!calibrating && ntasks_end < ntasks_best_end) /* Not calibrating, take better task */
+			    || (!calibrating && isnan(local_task_length[worker][nimpl])) /* Not calibrating but this worker is being calibrated */
+			    || (calibrating && isnan(local_task_length[worker][nimpl]) && ntasks_end < ntasks_best_end) /* Calibrating, compete this worker with other non-calibrated */
 				)
 			{
 				ntasks_best_end = ntasks_end;
@@ -299,7 +299,7 @@ static void compute_all_performance_predictions(struct starpu_task *task,
 				nimpl_best = nimpl;
 			}
 
-			if (local_task_length[worker][nimpl] == -1.0)
+			if (isnan(local_task_length[worker][nimpl]))
 				/* we are calibrating, we want to speed-up calibration time
 				 * so we privilege non-calibrated tasks (but still
 				 * greedily distribute them to avoid dumb schedules) */
@@ -322,7 +322,7 @@ static void compute_all_performance_predictions(struct starpu_task *task,
 				nimpl_best = nimpl;
 			}
 
-			if (local_power[worker][nimpl] == -1.0)
+			if (isnan(local_power[worker][nimpl]))
 				local_power[worker][nimpl] = 0.;
 
 		}

+ 5 - 5
src/sched_policies/parallel_heft.c

@@ -262,16 +262,16 @@ static int _parallel_heft_push_task(struct starpu_task *task, unsigned prio)
 			double ntasks_end = compute_ntasks_end(worker);
 
 			if (ntasks_best == -1
-					|| (!calibrating && ntasks_end < ntasks_best_end) /* Not calibrating, take better task */
-					|| (!calibrating && local_task_length[worker][nimpl] == -1.0) /* Not calibrating but this worker is being calibrated */
-					|| (calibrating && local_task_length[worker][nimpl] == -1.0 && ntasks_end < ntasks_best_end) /* Calibrating, compete this worker with other non-calibrated */
+			    || (!calibrating && ntasks_end < ntasks_best_end) /* Not calibrating, take better task */
+			    || (!calibrating && isnan(local_task_length[worker][nimpl])) /* Not calibrating but this worker is being calibrated */
+			    || (calibrating && isnan(local_task_length[worker][nimpl]) && ntasks_end < ntasks_best_end) /* Calibrating, compete this worker with other non-calibrated */
 					)
 			{
 				ntasks_best_end = ntasks_end;
 				ntasks_best = worker;
 			}
 
-			if (local_task_length[worker][nimpl] == -1.0)
+			if (isnan(local_task_length[worker][nimpl]))
 				/* we are calibrating, we want to speed-up calibration time
 				 * so we privilege non-calibrated tasks (but still
 				 * greedily distribute them to avoid dumb schedules) */
@@ -300,7 +300,7 @@ static int _parallel_heft_push_task(struct starpu_task *task, unsigned prio)
 			local_power[worker][nimpl] = starpu_task_expected_power(task, perf_arch,nimpl);
 			//_STARPU_DEBUG("Scheduler parallel heft: task length (%lf) local power (%lf) worker (%u) kernel (%u) \n", local_task_length[worker][nimpl],local_power[worker][nimpl],worker,nimpl);
 
-			if (local_power[worker][nimpl] == -1.0)
+			if (isnan(local_power[worker][nimpl]))
 				local_power[worker][nimpl] = 0.;
 
 		} //end for