cuda.c: extract out ppcg_start_block and ppcg_end_block
[ppcg.git] / ppcg.c
blobe72c0944a52b65736d043c0caba77ee66bb0f5e3
1 /*
2 * Copyright 2011 INRIA Saclay
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
8 * 91893 Orsay, France
9 */
11 #include <assert.h>
12 #include <stdio.h>
13 #include <isl/ctx.h>
14 #include <isl/options.h>
15 #include <isl/schedule.h>
16 #include <pet.h>
17 #include "ppcg.h"
18 #include "ppcg_options.h"
19 #include "cuda.h"
20 #include "cpu.h"
22 struct options {
23 struct isl_options *isl;
24 struct pet_options *pet;
25 struct ppcg_options *ppcg;
26 char *input;
29 const char *ppcg_version(void);
30 static void print_version(void)
32 printf("%s", ppcg_version());
35 ISL_ARGS_START(struct options, options_args)
36 ISL_ARG_CHILD(struct options, isl, "isl", &isl_options_args, "isl options")
37 ISL_ARG_CHILD(struct options, pet, "pet", &pet_options_args, "pet options")
38 ISL_ARG_CHILD(struct options, ppcg, NULL, &ppcg_options_args, "ppcg options")
39 ISL_ARG_ARG(struct options, input, "input", NULL)
40 ISL_ARG_VERSION(print_version)
41 ISL_ARGS_END
43 ISL_ARG_DEF(options, struct options, options_args)
45 /* Extract a ppcg_scop from a pet_scop.
47 * The constructed ppcg_scop refers to elements from the pet_scop
48 * so the pet_scop should not be freed before the ppcg_scop.
50 static struct ppcg_scop *ppcg_scop_from_pet_scop(struct pet_scop *scop)
52 isl_ctx *ctx;
53 struct ppcg_scop *ps;
55 if (!scop)
56 return NULL;
58 ctx = isl_set_get_ctx(scop->context);
60 ps = isl_calloc_type(ctx, struct ppcg_scop);
61 if (!ps)
62 return NULL;
64 ps->context = isl_set_copy(scop->context);
65 ps->domain = pet_scop_collect_domains(scop);
66 ps->reads = pet_scop_collect_reads(scop);
67 ps->writes = pet_scop_collect_writes(scop);
68 ps->schedule = pet_scop_collect_schedule(scop);
69 ps->n_array = scop->n_array;
70 ps->arrays = scop->arrays;
71 ps->n_stmt = scop->n_stmt;
72 ps->stmts = scop->stmts;
74 return ps;
77 static void ppcg_scop_free(struct ppcg_scop *ps)
79 if (!ps)
80 return;
82 isl_set_free(ps->context);
83 isl_union_set_free(ps->domain);
84 isl_union_map_free(ps->reads);
85 isl_union_map_free(ps->writes);
86 isl_union_map_free(ps->schedule);
88 free(ps);
91 int main(int argc, char **argv)
93 int r;
94 isl_ctx *ctx;
95 struct options *options;
96 struct pet_scop *scop;
97 struct ppcg_scop *ps;
99 options = options_new_with_defaults();
100 assert(options);
102 ctx = isl_ctx_alloc_with_options(&options_args, options);
103 isl_options_set_schedule_outer_zero_distance(ctx, 1);
104 argc = options_parse(options, argc, argv, ISL_ARG_ALL);
106 scop = pet_scop_extract_from_C_source(ctx, options->input, NULL);
107 scop = pet_scop_align_params(scop);
108 ps = ppcg_scop_from_pet_scop(scop);
110 if (options->ppcg->target == PPCG_TARGET_CUDA)
111 r = generate_cuda(ctx, ps, options->ppcg, options->input);
112 else
113 r = generate_cpu(ctx, ps, options->ppcg, options->input);
115 ppcg_scop_free(ps);
116 pet_scop_free(scop);
118 isl_ctx_free(ctx);
120 return r;