From afad88a8fd4e8c070c7a70e7a4e148af7232d06c Mon Sep 17 00:00:00 2001 From: Roshan Dathathri Date: Thu, 2 Jan 2014 14:31:23 +0530 Subject: [PATCH] Loop execution time reporting Set clast_for->time_var_name to the name of the variable which will accumulate execution time of the body inside this loop (in seconds double precision floating-point) if macro TIME is defined (-DTIME). The code is linked to cloog_util_rtclock() that relies on gettimeofday and is part of the CLooG library. Signed-off-by: Uday Bondhugula Signed-off-by: Cedric Bastoul --- Makefile.am | 2 ++ include/cloog/clast.h | 3 ++ include/cloog/cloog.h | 1 + include/cloog/{cloog.h => util.h} | 38 +++++++++----------------- source/clast.c | 2 ++ source/pprint.c | 12 ++++++++ source/program.c | 2 ++ include/cloog/cloog.h => source/util.c | 50 +++++++++++++++------------------- 8 files changed, 57 insertions(+), 53 deletions(-) copy include/cloog/{cloog.h => util.h} (73%) copy include/cloog/cloog.h => source/util.c (71%) diff --git a/Makefile.am b/Makefile.am index 49b413d..edf4fdb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -85,6 +85,7 @@ SOURCES_CORE = \ source/statement.c \ source/stride.c \ source/union_domain.c \ + source/util.c \ source/version.c AM_CPPFLAGS = -I. -I$(top_builddir)/include -I$(top_srcdir)/include @@ -120,6 +121,7 @@ pkginclude_HEADERS = \ include/cloog/statement.h \ include/cloog/stride.h \ include/cloog/union_domain.h \ + include/cloog/util.h \ include/cloog/version.h pkgmatrixincludedir = $(pkgincludedir)/matrix diff --git a/include/cloog/clast.h b/include/cloog/clast.h index fd56dd7..3348aa8 100644 --- a/include/cloog/clast.h +++ b/include/cloog/clast.h @@ -108,6 +108,9 @@ struct clast_for { char *private_vars; /* Comma separated list of reduction variable/operators for OpenMP parallelization */ char *reduction_vars; + /* Enable execution time reporting for this loop */ + /* Variable name to accumulate execution time this loop */ + char *time_var_name; }; struct clast_equation { diff --git a/include/cloog/cloog.h b/include/cloog/cloog.h index a8c3f28..a7fdef7 100644 --- a/include/cloog/cloog.h +++ b/include/cloog/cloog.h @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include diff --git a/include/cloog/cloog.h b/include/cloog/util.h similarity index 73% copy from include/cloog/cloog.h copy to include/cloog/util.h index a8c3f28..b978823 100644 --- a/include/cloog/cloog.h +++ b/include/cloog/util.h @@ -2,9 +2,9 @@ /**-------------------------------------------------------------------** ** CLooG ** **-------------------------------------------------------------------** - ** cloog.h ** + ** util.h ** **-------------------------------------------------------------------** - ** First version: july 25th 2002 ** + ** First version: January 8th 2014 ** **-------------------------------------------------------------------**/ @@ -34,29 +34,17 @@ * * ******************************************************************************/ -/****************************************************************************** - * THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM clooh.h.in BY configure * - ******************************************************************************/ -#ifndef CLOOG_H -#define CLOOG_H +#ifndef CLOOG_UTIL_H +#define CLOOG_UTIL_H +#if defined(__cplusplus) +extern "C" + { +#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +double cloog_util_rtclock(); -#endif /* !CLOOG_H */ +#if defined(__cplusplus) + } +#endif +#endif /* !CLOOG_UTIL_H */ diff --git a/source/clast.c b/source/clast.c index 78143c3..a4fb958 100644 --- a/source/clast.c +++ b/source/clast.c @@ -213,6 +213,7 @@ static void free_clast_for(struct clast_stmt *s) cloog_clast_free(f->body); if (f->private_vars) free(f->private_vars); if (f->reduction_vars) free(f->reduction_vars); + if (f->time_var_name) free(f->time_var_name); free(f); } @@ -231,6 +232,7 @@ struct clast_for *new_clast_for(CloogDomain *domain, const char *it, f->parallel = CLAST_PARALLEL_NOT; f->private_vars = NULL; f->reduction_vars = NULL; + f->time_var_name = NULL; cloog_int_init(f->stride); if (stride) cloog_int_set(f->stride, stride->stride); diff --git a/source/pprint.c b/source/pprint.c index f5fcfc7..83fcc32 100644 --- a/source/pprint.c +++ b/source/pprint.c @@ -449,6 +449,10 @@ void pprint_for(struct cloogoptions *options, FILE *dst, int indent, struct clast_for *f) { if (options->language == CLOOG_LANGUAGE_C) { + if (f->time_var_name) { + fprintf(dst, "IF_TIME(%s_start = cloog_util_rtclock());\n", + (f->time_var_name) ? f->time_var_name : ""); + } if ((f->parallel & CLAST_PARALLEL_OMP) && !(f->parallel & CLAST_PARALLEL_MPI)) { if (f->LB) { fprintf(dst, "lbp="); @@ -572,6 +576,14 @@ void pprint_for(struct cloogoptions *options, FILE *dst, int indent, fprintf(dst,"END DO\n") ; else fprintf(dst,"}\n") ; + + if (options->language == CLOOG_LANGUAGE_C) { + if (f->time_var_name) { + fprintf(dst, "IF_TIME(%s += cloog_util_rtclock() - %s_start);\n", + (f->time_var_name) ? f->time_var_name : "", + (f->time_var_name) ? f->time_var_name : ""); + } + } } void pprint_stmt_list(struct cloogoptions *options, FILE *dst, int indent, diff --git a/source/program.c b/source/program.c index 2e31147..40ae449 100644 --- a/source/program.c +++ b/source/program.c @@ -289,6 +289,8 @@ static void print_macros(FILE *file) "#define ceild(n,d) (((n)<0) ? -((-(n))/(d)) : ((n)+(d)-1)/(d))\n"); fprintf(file, "#define max(x,y) ((x) > (y) ? (x) : (y))\n") ; fprintf(file, "#define min(x,y) ((x) < (y) ? (x) : (y))\n\n") ; + fprintf(file, "#ifdef TIME \n#define IF_TIME(foo) foo; \n" + "#else\n#define IF_TIME(foo)\n#endif\n"); } static void print_declarations(FILE *file, int n, char **names) diff --git a/include/cloog/cloog.h b/source/util.c similarity index 71% copy from include/cloog/cloog.h copy to source/util.c index a8c3f28..1b60978 100644 --- a/include/cloog/cloog.h +++ b/source/util.c @@ -2,9 +2,9 @@ /**-------------------------------------------------------------------** ** CLooG ** **-------------------------------------------------------------------** - ** cloog.h ** + ** util.c ** **-------------------------------------------------------------------** - ** First version: july 25th 2002 ** + ** First version: January 8th 2014 ** **-------------------------------------------------------------------**/ @@ -12,7 +12,7 @@ * CLooG : the Chunky Loop Generator (experimental) * ****************************************************************************** * * - * Copyright (C) 2001-2005 Cedric Bastoul * + * Copyright (C) 2002-2005 Cedric Bastoul * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * @@ -34,29 +34,23 @@ * * ******************************************************************************/ -/****************************************************************************** - * THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM clooh.h.in BY configure * - ******************************************************************************/ - -#ifndef CLOOG_H -#define CLOOG_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include "../include/cloog/cloog.h" -#endif /* !CLOOG_H */ +/** + * cloog_util_rtclock function: + * this function returns the value, in seconds, of the real time clock of + * the operating system. The reference point between calls is consistent, + * making time comparison possible. + * \return The real time clock of the operating system in seconds. + */ +double cloog_util_rtclock() { + struct timezone Tzp; + struct timeval Tp; + int stat = gettimeofday(&Tp, &Tzp); + if (stat != 0) + cloog_msg(NULL, CLOOG_WARNING, "Error return from gettimeofday: %d", stat); + return (Tp.tv_sec + Tp.tv_usec*1.0e-6); +} -- 2.11.4.GIT