Skip to content

Commit

Permalink
Change output file name to <input_base>.pluto.c and add -o <outfile> …
Browse files Browse the repository at this point in the history
…option

1. Pluto's default output file is now <input_basename>.pluto.c instead
of being based on command-line options (<input_basename>.tiled.c/.par.c/
.opt.c/.par2d.c). .cloog file used is named <input_basename>.pluto.cloog
(--debug  has to be provided for it not to be removed).

2. Use -o <output file> option to specify output file.

Update doc/DOC.txt, README; lose fixed size for srcfilename in main.c.
Other minor cleanup.

Signed-off-by: Uday Reddy <udayreddy@gmail.com>
  • Loading branch information
bondhugula committed Jun 12, 2011
1 parent 3be591a commit 25752c5
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 66 deletions.
5 changes: 3 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# Uday Bondhugula
# udayreddy@gmail.com
# uday@csa.iisc.ernet.in
#

INSTALLING PLUTO
Expand Down Expand Up @@ -53,7 +54,6 @@ $ ./configure [--enable-debug]
$ make
$ make test


If you do not have ICC, uncomment line 7 and comment line 8 of
examples/common.mk.

Expand Down Expand Up @@ -171,7 +171,8 @@ with orig for all examples, in the examples/ directory, run

MORE INFO

* See doc/DOC.txt for an overview of the system and more details
* See doc/DOC.txt for an overview of the system and details on all
command-line options.

* For specifying custom tile sizes through 'tile.sizes' file, see
doc/DOC.txt
Expand Down
12 changes: 11 additions & 1 deletion doc/DOC.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@ Using PLUTO
- Use '#pragma scop' and '#pragma endscop' around the section of code
you want to parallelize/optimize.

- Then, just run
- Then, run

./polycc <C source file> --parallel --tile

<C source file> should have a '.c' extension

The output file will be named <original prefix>.pluto.c unless '-o
<filename>" is supplied. When --debug is used, the .cloog used to
generate code is not deleted and is named in a similar way.


The following describe the kind of code you can put '#pragma scop' and
'#pragma endscop' around, though the polyhedral model is not restricted
to these. Most of the time, even though your program may not satisfy
Expand Down Expand Up @@ -68,6 +75,9 @@ For more details, see clan-0.5.0/doc/. Do a 'make pdf' and see clan.pdf.


COMMAND-LINE OPTIONS
-o output
Output to file 'output'. Without -o, name of the output file is
determined as described earlier (under 'Using PLUTO')

--help
List all available options with one-line summary
Expand Down
18 changes: 9 additions & 9 deletions examples/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ PLC=../../polycc

all: orig tiled par

orig: $(SRC).c decls.h util.h
$(CC) $(OPT_FLAGS) $(CFLAGS) $(SRC).c -o orig $(LDFLAGS)

orig_par: decls.h util.h $(SRC).c
$(CC) $(OPT_FLAGS) $(CFLAGS) $(PAR_FLAGS) $(SRC).c -o orig_par $(LDFLAGS)

$(SRC).opt.c:
$(PLC) $(SRC).c $(PLCFLAGS)
$(PLC) $(SRC).c $(PLCFLAGS) -o $@

$(SRC).tiled.c:
$(PLC) $(SRC).c --tile $(TILEFLAGS) $(PLCFLAGS)
$(PLC) $(SRC).c --tile $(TILEFLAGS) $(PLCFLAGS) -o $@

$(SRC).par.c:
$(PLC) $(SRC).c --tile --parallel $(TILEFLAGS) $(PLCFLAGS)
$(PLC) $(SRC).c --tile --parallel $(TILEFLAGS) $(PLCFLAGS) -o $@

orig: $(SRC).c decls.h util.h
$(CC) $(OPT_FLAGS) $(CFLAGS) $(SRC).c -o orig $(LDFLAGS)

orig_par: decls.h util.h $(SRC).c
$(CC) $(OPT_FLAGS) $(CFLAGS) $(PAR_FLAGS) $(SRC).c -o orig_par $(LDFLAGS)

opt: $(SRC).opt.c decls.h util.h
$(CC) $(OPT_FLAGS) $(CFLAGS) $(SRC).opt.c -o opt $(LDFLAGS)
Expand Down
2 changes: 2 additions & 0 deletions inscop
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# arguments
# inscop <original> <transformed_kernel> <output_file>
# transformed_kernel and output_file can be the same
#

MAXLINES=`wc -l $1 | awk '{print $1}'`

Expand Down
47 changes: 16 additions & 31 deletions polycc.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ for arg in $*; do
PARALLEL=1
elif [ $arg == "--tile" ]; then
TILE=1
elif [ $arg == "--multipipe" ]; then
MULTIPAR=1
elif [ $arg == "--unroll" ]; then
UNROLL=1
elif [ $arg == "--debug" ]; then
Expand All @@ -40,66 +38,53 @@ for arg in $*; do
INDENT=1
elif [ $arg == "--indent" ]; then
INDENT=1
elif [ $arg == "--rar" ]; then
RAR=1
elif [ $arg == "--silent" ]; then
SILENT=1
elif [ ${arg:0:1} != "-" ]; then
SOURCEFILE=$arg;
fi
done

# some special processing for linearized accesses
if [ "$SOURCEFILE" != "" ]; then
grep __SPECIAL $SOURCEFILE > .nonlinearized
grep __SPECIAL $SOURCEFILE | sed -e "s/.*__SPECIAL//" > .linearized
fi
#if [ "$SOURCEFILE" != "" ]; then
#grep __SPECIAL $SOURCEFILE > .nonlinearized
#grep __SPECIAL $SOURCEFILE | sed -e "s/.*__SPECIAL//" > .linearized
#fi

$pluto $* || exit 1

SOURCEFILE=`cat .srcfilename`
OUTFILE=`cat .outfilename`

dirname=`dirname $SOURCEFILE`
basename=`basename $SOURCEFILE`
prefix=`basename $SOURCEFILE .c`

INFILE=$prefix.pluto.c

if [ "$MULTIPAR" == "1" ]; then
OUTFILE=$prefix.par2d.c
CLOOGFILE=$prefix.par2d.cloog
elif [ "$PARALLEL" == "1" ]; then
OUTFILE=$prefix.par.c
CLOOGFILE=$prefix.par.cloog
elif [ "$TILE" == "1" ]; then
OUTFILE=$prefix.tiled.c
CLOOGFILE=$prefix.tiled.cloog
else
OUTFILE=$prefix.opt.c
CLOOGFILE=$prefix.opt.cloog
fi
CLOOGFILE=$prefix.pluto.cloog
PLUTOOUT=$OUTFILE


# run the syntactic #pragma inserter
if [ "$PARALLEL" == 1 ]; then
$ploog $INFILE || exit 1
$ploog $PLUTOOUT || exit 1
fi

# generate and insert unrolling annotations, run ancc on it,
if [ "$UNROLL" == 1 ]; then
$plorc $INFILE @SOURCE_DIR@/orio-0.1.0
$plorc $PLUTOOUT @SOURCE_DIR@/orio-0.1.0
fi

#if [ "$UNROLL" == 1 ]; then
#$plann $INFILE @SOURCE_DIR@/annotations
#$plann $PLUTOOUT @SOURCE_DIR@/annotations
#fi

# pre vectorize (#pragma ivdep and scalar bound rep for the
# vectorizable innermost loop if it was detected)
$vloog $INFILE
$vloog $PLUTOOUT

# put the original skeleton around the transformed code
@SOURCE_DIR@/inscop $SOURCEFILE $INFILE $OUTFILE
@SOURCE_DIR@/inscop $SOURCEFILE $OUTFILE $OUTFILE

if [ "$DEBUG" != 1 ]; then
rm -rf .unroll .vectorize .pragmas .params .orcc .linearized .nonlinearized $CLOOGFILE
rm -rf .unroll .vectorize .pragmas .params .orcc .linearized .nonlinearized $CLOOGFILE .srcfilename .outfilename
fi

if [ "$INDENT" == 1 ] && [ -x /usr/bin/indent ]; then
Expand Down
56 changes: 37 additions & 19 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(int argc, char *argv[])
int option;
int option_index = 0;

char srcFileName[256];
char *srcFileName;

FILE *cloogfp, *outfp;

Expand Down Expand Up @@ -105,7 +105,7 @@ int main(int argc, char *argv[])

/* Read command-line options */
while (1) {
option = getopt_long(argc, argv, "bhiqvf:l:F:L:c:", pluto_options,
option = getopt_long(argc, argv, "bhiqvf:l:F:L:c:o:", pluto_options,
&option_index);

if (option == -1) {
Expand Down Expand Up @@ -147,13 +147,16 @@ int main(int argc, char *argv[])
break;
case 'n':
break;
case 's':
case 'o':
options->out_file = strdup(optarg);
break;
case 'p':
break;
case 'q':
options->silent = 1;
break;
case 's':
break;
case 'u':
options->ufactor = atoi(optarg);
break;
Expand All @@ -173,7 +176,8 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"


if (optind <= argc-1) {
strncpy(srcFileName, argv[optind], 250);
srcFileName = alloca(strlen(argv[optind])+1);
strcpy(srcFileName, argv[optind]);
}else{
/* No non-option argument was specified */
usage_message();
Expand All @@ -186,6 +190,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"
if (!src_fp) {
fprintf(stderr, "pluto: error opening source file: '%s'\n", srcFileName);
pluto_options_free(options);
free(srcFileName);
return 6;
}

Expand All @@ -203,9 +208,15 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"
fprintf(stderr, "Error extracting polyhedra from source file: \'%s'\n",
srcFileName);
pluto_options_free(options);
free(srcFileName);
return 7;
}

FILE *srcfp = fopen(".srcfilename", "w");
if (srcfp) {
fprintf(srcfp, "%s\n", srcFileName);
fclose(srcfp);
}

/* IF_DEBUG(clan_scop_print_dot_scop(stdout, scop, clanOptions)); */

/* Convert clan scop to Pluto program */
Expand Down Expand Up @@ -336,38 +347,38 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"
}
}


char *outFileName;
char *cloogFileName;
if (options->out_file == NULL) {
/* Get basename, remove .c extension and append a new one */
char *basec, *bname;

basec = strdup(srcFileName);
bname = basename(basec);

char outFileName[strlen(bname)+strlen(".pluto.c")+1];
char cloogFileName[strlen(bname)+strlen(".tiled.cloog")+1];
/* max size when tiled.* */
outFileName = alloca(strlen(bname)+strlen(".pluto.c")+1);
cloogFileName = alloca(strlen(bname)+strlen(".pluto.cloog")+1);

if (strlen(bname) >= 2 && !strcmp(bname+strlen(bname)-2, ".c")) {
strncpy(outFileName, bname, strlen(bname)-2);
strncpy(cloogFileName, bname, strlen(bname)-2);
outFileName[strlen(bname)-2] = '\0';
cloogFileName[strlen(bname)-2] = '\0';
strcat(outFileName, ".pluto.c");
}else{
strcpy(outFileName, bname);
strcpy(cloogFileName, bname);
}
strcat(outFileName, ".pluto.c");
}
free(basec);

if (options->parallel && options->multipipe) {
strcat(cloogFileName, ".par2d.cloog");
}else if (options->parallel) {
strcat(cloogFileName, ".par.cloog");
}else if (options->tile) {
strcat(cloogFileName, ".tiled.cloog");
}else{
strcat(cloogFileName, ".opt.cloog");
outFileName = options->out_file;
cloogFileName = alloca(strlen(options->out_file)+1);
strcpy(cloogFileName, options->out_file);
}

strcat(cloogFileName, ".pluto.cloog");

outfp = fopen(outFileName, "w");
cloogfp = fopen(cloogFileName, "w+");

Expand Down Expand Up @@ -397,7 +408,14 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"
/* Generate code using Cloog and add necessary stuff before/after code */
pluto_codegen(cloogfp, outfp, prog);

FILE *tmpfp = fopen(".outfilename", "w");
if (tmpfp) {
fprintf(tmpfp, "%s\n", outFileName);
fclose(tmpfp);
}

fclose(cloogfp);
fclose(outfp);

pluto_options_free(options);

Expand All @@ -409,7 +427,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"

void usage_message(void)
{
fprintf(stdout, "Usage: polycc <input.c> [options]\n");
fprintf(stdout, "Usage: polycc <input.c> [options] [-o output]\n");
fprintf(stdout, "\nOptions:\n");
fprintf(stdout, " --tile Tile for locality\n");
fprintf(stdout, " --parallel Automatically parallelize using OpenMP pragmas\n");
Expand Down
2 changes: 2 additions & 0 deletions src/pluto.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ struct plutoOptions{

/* Use isl as ilp solver. */
int islsolve;
/* Output file name supplied from -o */
char *out_file;
};
typedef struct plutoOptions PlutoOptions;

Expand Down
5 changes: 5 additions & 0 deletions src/program.c
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,8 @@ PlutoOptions *pluto_options_alloc()

options->silent = 0;

options->out_file = NULL;

return options;
}

Expand All @@ -1145,6 +1147,9 @@ void pluto_add_parameter(PlutoProg *prog, char *param)

void pluto_options_free(PlutoOptions *options)
{
if (options->out_file != NULL) {
free(options->out_file);
}
free(options);
}

Expand Down
8 changes: 4 additions & 4 deletions vloog
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ for num in $LINE_NUMBERS; do
sed -n -e ''$(($num+5*$j))'p' $1 | tr -d ' ' | sed -e 's/for/for /' > .vecloop

# lower and upper bounds
echo -ne "{\n\tlbv="`awk '{split($2,t,";"); split(t[1],u,"="); print u[2] }' .vecloop`"; " > .lb
echo -e "\tubv="`awk '{split($2,t,";"); split(t[2],u,"="); print u[2] }' .vecloop`";" > .ub
echo -ne "{\n\tlbv="`awk '{split($2,t,";"); split(t[1],u,"="); print u[2] }' .vecloop`"; " > .lbv
echo -e "\tubv="`awk '{split($2,t,";"); split(t[2],u,"="); print u[2] }' .vecloop`";" > .ubv

cat .header .lb .ub > $1
cat .header .lbv .ubv > $1
echo -e "#pragma ivdep\n#pragma vector always\n\tfor ($VECDIM=lbv; $VECDIM<=ubv; $VECDIM++) {" >> $1
cat .body >> $1
echo "}" >> $1
Expand All @@ -101,4 +101,4 @@ for num in $LINE_NUMBERS; do
done
echo "[Vloog] added vectorization pragmas on $j loop(s)"

rm -f .header .lb .ub .header .footer .vecloop .footer .body closenum
rm -f .header .lbv .ubv .header .footer .vecloop .footer .body closenum

0 comments on commit 25752c5

Please sign in to comment.