update isl for __isl_null memory management annotation
[ppcg.git] / ppcg.c
bloba25a66af7650148d4e866701cd2cabe2f86f46e7
1 /*
2 * Copyright 2011 INRIA Saclay
3 * Copyright 2013 Ecole Normale Superieure
5 * Use of this software is governed by the MIT license
7 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
8 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
9 * 91893 Orsay, France
10 * and Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
13 #include <assert.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <isl/ctx.h>
18 #include <isl/flow.h>
19 #include <isl/options.h>
20 #include <isl/schedule.h>
21 #include <isl/ast_build.h>
22 #include <isl/schedule.h>
23 #include <pet.h>
24 #include "ppcg.h"
25 #include "ppcg_options.h"
26 #include "cuda.h"
27 #include "opencl.h"
28 #include "cpu.h"
30 struct options {
31 struct isl_options *isl;
32 struct pet_options *pet;
33 struct ppcg_options *ppcg;
34 char *input;
35 char *output;
38 const char *ppcg_version(void);
39 static void print_version(void)
41 printf("%s", ppcg_version());
44 ISL_ARGS_START(struct options, options_args)
45 ISL_ARG_CHILD(struct options, isl, "isl", &isl_options_args, "isl options")
46 ISL_ARG_CHILD(struct options, pet, "pet", &pet_options_args, "pet options")
47 ISL_ARG_CHILD(struct options, ppcg, NULL, &ppcg_options_args, "ppcg options")
48 ISL_ARG_STR(struct options, output, 'o', NULL,
49 "filename", NULL, "output filename (c and opencl targets)")
50 ISL_ARG_ARG(struct options, input, "input", NULL)
51 ISL_ARG_VERSION(print_version)
52 ISL_ARGS_END
54 ISL_ARG_DEF(options, struct options, options_args)
56 /* Copy the base name of "input" to "name" and return its length.
57 * "name" is not NULL terminated.
59 * In particular, remove all leading directory components and
60 * the final extension, if any.
62 int ppcg_extract_base_name(char *name, const char *input)
64 const char *base;
65 const char *ext;
66 int len;
68 base = strrchr(input, '/');
69 if (base)
70 base++;
71 else
72 base = input;
73 ext = strrchr(base, '.');
74 len = ext ? ext - base : strlen(base);
76 memcpy(name, base, len);
78 return len;
81 /* Is "stmt" not a kill statement?
83 static int is_not_kill(struct pet_stmt *stmt)
85 return !pet_stmt_is_kill(stmt);
88 /* Collect the iteration domains of the statements in "scop" that
89 * satisfy "pred".
91 static __isl_give isl_union_set *collect_domains(struct pet_scop *scop,
92 int (*pred)(struct pet_stmt *stmt))
94 int i;
95 isl_set *domain_i;
96 isl_union_set *domain;
98 if (!scop)
99 return NULL;
101 domain = isl_union_set_empty(isl_set_get_space(scop->context));
103 for (i = 0; i < scop->n_stmt; ++i) {
104 struct pet_stmt *stmt = scop->stmts[i];
106 if (!pred(stmt))
107 continue;
109 if (stmt->n_arg > 0)
110 isl_die(isl_union_set_get_ctx(domain),
111 isl_error_unsupported,
112 "data dependent conditions not supported",
113 return isl_union_set_free(domain));
115 domain_i = isl_set_copy(scop->stmts[i]->domain);
116 domain = isl_union_set_add_set(domain, domain_i);
119 return domain;
122 /* Collect the iteration domains of the statements in "scop",
123 * skipping kill statements.
125 static __isl_give isl_union_set *collect_non_kill_domains(struct pet_scop *scop)
127 return collect_domains(scop, &is_not_kill);
130 /* This function is used as a callback to pet_expr_foreach_call_expr
131 * to detect if there is any call expression in the input expression.
132 * Assign the value 1 to the integer that "user" points to and
133 * abort the search since we have found what we were looking for.
135 static int set_has_call(struct pet_expr *expr, void *user)
137 int *has_call = user;
139 *has_call = 1;
141 return -1;
144 /* Does "expr" contain any call expressions?
146 static int expr_has_call(struct pet_expr *expr)
148 int has_call = 0;
150 if (pet_expr_foreach_call_expr(expr, &set_has_call, &has_call) < 0 &&
151 !has_call)
152 return -1;
154 return has_call;
157 /* Does "stmt" contain any call expressions?
159 static int has_call(struct pet_stmt *stmt)
161 return expr_has_call(stmt->body);
164 /* Collect the iteration domains of the statements in "scop"
165 * that contain a call expression.
167 static __isl_give isl_union_set *collect_call_domains(struct pet_scop *scop)
169 return collect_domains(scop, &has_call);
172 /* Given a union of "tagged" access relations of the form
174 * [S_i[...] -> R_j[]] -> A_k[...]
176 * project out the "tags" (R_j[]).
177 * That is, return a union of relations of the form
179 * S_i[...] -> A_k[...]
181 static __isl_give isl_union_map *project_out_tags(
182 __isl_take isl_union_map *umap)
184 isl_union_map *proj;
186 proj = isl_union_map_universe(isl_union_map_copy(umap));
187 proj = isl_union_set_unwrap(isl_union_map_domain(proj));
188 proj = isl_union_map_domain_map(proj);
190 umap = isl_union_map_apply_domain(umap, proj);
192 return umap;
195 /* Construct a relation from the iteration domains to tagged iteration
196 * domains with as range the reference tags that appear
197 * in any of the reads, writes or kills.
198 * Store the result in ps->tagger.
200 * For example, if the statement with iteration space S[i,j]
201 * contains two array references R_1[] and R_2[], then ps->tagger will contain
203 * { S[i,j] -> [S[i,j] -> R_1[]]; S[i,j] -> [S[i,j] -> R_2[]] }
205 static void compute_tagger(struct ppcg_scop *ps)
207 isl_union_map *tagged, *tagger;
209 tagged = isl_union_map_copy(ps->tagged_reads);
210 tagged = isl_union_map_union(tagged,
211 isl_union_map_copy(ps->tagged_may_writes));
212 tagged = isl_union_map_union(tagged,
213 isl_union_map_copy(ps->tagged_must_kills));
215 tagger = isl_union_map_universe(tagged);
216 tagger = isl_union_set_unwrap(isl_union_map_domain(tagger));
217 tagger = isl_union_map_reverse(isl_union_map_domain_map(tagger));
219 ps->tagger = tagger;
222 /* Compute the live out accesses, i.e., the writes that are
223 * potentially not killed by any kills or any other writes, and
224 * store them in ps->live_out.
226 * We compute the "dependence" of any "kill" (an explicit kill
227 * or a must write) on any may write.
228 * The may writes with a "depending" kill are definitely killed.
229 * The remaining may writes can potentially be live out.
231 static void compute_live_out(struct ppcg_scop *ps)
233 isl_union_map *tagger;
234 isl_union_map *schedule;
235 isl_union_map *empty;
236 isl_union_map *kills;
237 isl_union_map *exposed;
238 isl_union_map *covering;
240 tagger = isl_union_map_copy(ps->tagger);
241 schedule = isl_union_map_copy(ps->schedule);
242 schedule = isl_union_map_apply_domain(schedule,
243 isl_union_map_copy(tagger));
244 empty = isl_union_map_empty(isl_union_set_get_space(ps->domain));
245 kills = isl_union_map_union(isl_union_map_copy(ps->tagged_must_writes),
246 isl_union_map_copy(ps->tagged_must_kills));
247 isl_union_map_compute_flow(kills, empty,
248 isl_union_map_copy(ps->tagged_may_writes),
249 schedule, NULL, &covering, NULL, NULL);
250 exposed = isl_union_map_copy(ps->tagged_may_writes);
251 exposed = isl_union_map_subtract_domain(exposed,
252 isl_union_map_domain(covering));
253 exposed = isl_union_map_apply_range(tagger, exposed);
254 ps->live_out = exposed;
257 /* Compute the flow dependences and the live_in accesses and store
258 * the results in ps->dep_flow and ps->live_in.
259 * A copy of the flow dependences, tagged with the reference tags
260 * is stored in ps->tagged_dep_flow.
262 * We first compute ps->tagged_dep_flow, i.e., the tagged flow dependences
263 * and then project out the tags.
265 static void compute_tagged_flow_dep(struct ppcg_scop *ps)
267 isl_union_map *tagger;
268 isl_union_map *schedule;
269 isl_union_map *may_flow;
270 isl_union_map *live_in, *may_live_in;
272 tagger = isl_union_map_copy(ps->tagger);
273 schedule = isl_union_map_copy(ps->schedule);
274 schedule = isl_union_map_apply_domain(schedule, tagger);
275 isl_union_map_compute_flow(isl_union_map_copy(ps->tagged_reads),
276 isl_union_map_copy(ps->tagged_must_writes),
277 isl_union_map_copy(ps->tagged_may_writes),
278 schedule, &ps->tagged_dep_flow, &may_flow,
279 &live_in, &may_live_in);
280 ps->tagged_dep_flow = isl_union_map_union(ps->tagged_dep_flow,
281 may_flow);
282 ps->dep_flow = isl_union_map_copy(ps->tagged_dep_flow);
283 ps->dep_flow = isl_union_map_zip(ps->dep_flow);
284 ps->dep_flow = isl_union_set_unwrap(isl_union_map_domain(ps->dep_flow));
285 live_in = isl_union_map_union(live_in, may_live_in);
286 ps->live_in = project_out_tags(live_in);
289 /* Compute the order dependences that prevent the potential live ranges
290 * from overlapping.
291 * "before" contains all pairs of statement iterations where
292 * the first is executed before the second according to the original schedule.
294 * In particular, construct a union of relations
296 * [R[...] -> R_1[]] -> [W[...] -> R_2[]]
298 * where [R[...] -> R_1[]] is the range of one or more live ranges
299 * (i.e., a read) and [W[...] -> R_2[]] is the domain of one or more
300 * live ranges (i.e., a write). Moreover, the read and the write
301 * access the same memory element and the read occurs before the write
302 * in the original schedule.
303 * The scheduler allows some of these dependences to be violated, provided
304 * the adjacent live ranges are all local (i.e., their domain and range
305 * are mapped to the same point by the current schedule band).
307 * Note that if a live range is not local, then we need to make
308 * sure it does not overlap with _any_ other live range, and not
309 * just with the "previous" and/or the "next" live range.
310 * We therefore add order dependences between reads and
311 * _any_ later potential write.
313 * We also need to be careful about writes without a corresponding read.
314 * They are already prevented from moving past non-local preceding
315 * intervals, but we also need to prevent them from moving past non-local
316 * following intervals. We therefore also add order dependences from
317 * potential writes that do not appear in any intervals
318 * to all later potential writes.
319 * Note that dead code elimination should have removed most of these
320 * dead writes, but the dead code elimination may not remove all dead writes,
321 * so we need to consider them to be safe.
323 static void compute_order_dependences(struct ppcg_scop *ps,
324 __isl_take isl_union_map *before)
326 isl_union_map *reads;
327 isl_union_map *shared_access;
328 isl_union_set *matched;
329 isl_union_map *unmatched;
330 isl_union_set *domain;
332 reads = isl_union_map_copy(ps->tagged_reads);
333 matched = isl_union_map_domain(isl_union_map_copy(ps->tagged_dep_flow));
334 unmatched = isl_union_map_copy(ps->tagged_may_writes);
335 unmatched = isl_union_map_subtract_domain(unmatched, matched);
336 reads = isl_union_map_union(reads, unmatched);
337 shared_access = isl_union_map_copy(ps->tagged_may_writes);
338 shared_access = isl_union_map_reverse(shared_access);
339 shared_access = isl_union_map_apply_range(reads, shared_access);
340 shared_access = isl_union_map_zip(shared_access);
341 shared_access = isl_union_map_intersect_domain(shared_access,
342 isl_union_map_wrap(before));
343 domain = isl_union_map_domain(isl_union_map_copy(shared_access));
344 shared_access = isl_union_map_zip(shared_access);
345 ps->dep_order = isl_union_set_unwrap(domain);
346 ps->tagged_dep_order = shared_access;
349 /* Compute the external false dependences of the program represented by "scop"
350 * in case live range reordering is allowed.
351 * "before" contains all pairs of statement iterations where
352 * the first is executed before the second according to the original schedule.
354 * The anti-dependences are already taken care of by the order dependences.
355 * The external false dependences are only used to ensure that live-in and
356 * live-out data is not overwritten by any writes inside the scop.
358 * In particular, the reads from live-in data need to precede any
359 * later write to the same memory element.
360 * As to live-out data, the last writes need to remain the last writes.
361 * That is, any earlier write in the original schedule needs to precede
362 * the last write to the same memory element in the computed schedule.
363 * The possible last writes have been computed by compute_live_out.
364 * They may include kills, but if the last access is a kill,
365 * then the corresponding dependences will effectively be ignored
366 * since we do not schedule any kill statements.
368 * Note that the set of live-in and live-out accesses may be
369 * an overapproximation. There may therefore be potential writes
370 * before a live-in access and after a live-out access.
372 static void compute_external_false_dependences(struct ppcg_scop *ps,
373 __isl_take isl_union_map *before)
375 isl_union_map *shared_access;
376 isl_union_map *exposed;
377 isl_union_map *live_in;
379 exposed = isl_union_map_copy(ps->live_out);
381 exposed = isl_union_map_reverse(exposed);
382 shared_access = isl_union_map_copy(ps->may_writes);
383 shared_access = isl_union_map_apply_range(shared_access, exposed);
385 ps->dep_external = shared_access;
387 live_in = isl_union_map_apply_range(isl_union_map_copy(ps->live_in),
388 isl_union_map_reverse(isl_union_map_copy(ps->may_writes)));
390 ps->dep_external = isl_union_map_union(ps->dep_external, live_in);
391 ps->dep_external = isl_union_map_intersect(ps->dep_external, before);
394 /* Compute the dependences of the program represented by "scop"
395 * in case live range reordering is allowed.
397 * We compute the actual live ranges and the corresponding order
398 * false dependences.
400 static void compute_live_range_reordering_dependences(struct ppcg_scop *ps)
402 isl_union_map *before;
404 before = isl_union_map_lex_lt_union_map(
405 isl_union_map_copy(ps->schedule),
406 isl_union_map_copy(ps->schedule));
408 compute_tagged_flow_dep(ps);
409 compute_order_dependences(ps, isl_union_map_copy(before));
410 compute_external_false_dependences(ps, before);
413 /* Compute the potential flow dependences and the potential live in
414 * accesses.
416 static void compute_flow_dep(struct ppcg_scop *ps)
418 isl_union_map *may_flow;
419 isl_union_map *may_live_in;
421 isl_union_map_compute_flow(isl_union_map_copy(ps->reads),
422 isl_union_map_copy(ps->must_writes),
423 isl_union_map_copy(ps->may_writes),
424 isl_union_map_copy(ps->schedule),
425 &ps->dep_flow, &may_flow,
426 &ps->live_in, &may_live_in);
428 ps->dep_flow = isl_union_map_union(ps->dep_flow, may_flow);
429 ps->live_in = isl_union_map_union(ps->live_in, may_live_in);
432 /* Compute the dependences of the program represented by "scop".
433 * Store the computed potential flow dependences
434 * in scop->dep_flow and the reads with potentially no corresponding writes in
435 * scop->live_in.
436 * Store the potential live out accesses in scop->live_out.
437 * Store the potential false (anti and output) dependences in scop->dep_false.
439 * If live range reordering is allowed, then we compute a separate
440 * set of order dependences and a set of external false dependences
441 * in compute_live_range_reordering_dependences.
443 static void compute_dependences(struct ppcg_scop *scop)
445 isl_union_map *dep1, *dep2;
446 isl_union_map *may_source;
448 if (!scop)
449 return;
451 compute_live_out(scop);
453 if (scop->options->live_range_reordering)
454 compute_live_range_reordering_dependences(scop);
455 else if (scop->options->target != PPCG_TARGET_C)
456 compute_tagged_flow_dep(scop);
457 else
458 compute_flow_dep(scop);
460 may_source = isl_union_map_union(isl_union_map_copy(scop->may_writes),
461 isl_union_map_copy(scop->reads));
462 isl_union_map_compute_flow(isl_union_map_copy(scop->may_writes),
463 isl_union_map_copy(scop->must_writes),
464 may_source, isl_union_map_copy(scop->schedule),
465 &dep1, &dep2, NULL, NULL);
467 scop->dep_false = isl_union_map_union(dep1, dep2);
468 scop->dep_false = isl_union_map_coalesce(scop->dep_false);
471 /* Eliminate dead code from ps->domain.
473 * In particular, intersect ps->domain with the (parts of) iteration
474 * domains that are needed to produce the output or for statement
475 * iterations that call functions.
477 * We start with the iteration domains that call functions
478 * and the set of iterations that last write to an array
479 * (except those that are later killed).
481 * Then we add those statement iterations that produce
482 * something needed by the "live" statements iterations.
483 * We keep doing this until no more statement iterations can be added.
484 * To ensure that the procedure terminates, we compute the affine
485 * hull of the live iterations (bounded to the original iteration
486 * domains) each time we have added extra iterations.
488 static void eliminate_dead_code(struct ppcg_scop *ps)
490 isl_union_set *live;
491 isl_union_map *dep;
493 live = isl_union_map_domain(isl_union_map_copy(ps->live_out));
494 if (!isl_union_set_is_empty(ps->call)) {
495 live = isl_union_set_union(live, isl_union_set_copy(ps->call));
496 live = isl_union_set_coalesce(live);
499 dep = isl_union_map_copy(ps->dep_flow);
500 dep = isl_union_map_reverse(dep);
502 for (;;) {
503 isl_union_set *extra;
505 extra = isl_union_set_apply(isl_union_set_copy(live),
506 isl_union_map_copy(dep));
507 if (isl_union_set_is_subset(extra, live)) {
508 isl_union_set_free(extra);
509 break;
512 live = isl_union_set_union(live, extra);
513 live = isl_union_set_affine_hull(live);
514 live = isl_union_set_intersect(live,
515 isl_union_set_copy(ps->domain));
518 isl_union_map_free(dep);
520 ps->domain = isl_union_set_intersect(ps->domain, live);
523 /* Intersect "set" with the set described by "str", taking the NULL
524 * string to represent the universal set.
526 static __isl_give isl_set *set_intersect_str(__isl_take isl_set *set,
527 const char *str)
529 isl_ctx *ctx;
530 isl_set *set2;
532 if (!str)
533 return set;
535 ctx = isl_set_get_ctx(set);
536 set2 = isl_set_read_from_str(ctx, str);
537 set = isl_set_intersect(set, set2);
539 return set;
542 static void *ppcg_scop_free(struct ppcg_scop *ps)
544 if (!ps)
545 return NULL;
547 isl_set_free(ps->context);
548 isl_union_set_free(ps->domain);
549 isl_union_set_free(ps->call);
550 isl_union_map_free(ps->tagged_reads);
551 isl_union_map_free(ps->reads);
552 isl_union_map_free(ps->live_in);
553 isl_union_map_free(ps->tagged_may_writes);
554 isl_union_map_free(ps->tagged_must_writes);
555 isl_union_map_free(ps->may_writes);
556 isl_union_map_free(ps->must_writes);
557 isl_union_map_free(ps->live_out);
558 isl_union_map_free(ps->tagged_must_kills);
559 isl_union_map_free(ps->tagged_dep_flow);
560 isl_union_map_free(ps->dep_flow);
561 isl_union_map_free(ps->dep_false);
562 isl_union_map_free(ps->dep_external);
563 isl_union_map_free(ps->tagged_dep_order);
564 isl_union_map_free(ps->dep_order);
565 isl_union_map_free(ps->schedule);
566 isl_union_map_free(ps->tagger);
568 free(ps);
570 return NULL;
573 /* Extract a ppcg_scop from a pet_scop.
575 * The constructed ppcg_scop refers to elements from the pet_scop
576 * so the pet_scop should not be freed before the ppcg_scop.
578 static struct ppcg_scop *ppcg_scop_from_pet_scop(struct pet_scop *scop,
579 struct ppcg_options *options)
581 isl_ctx *ctx;
582 struct ppcg_scop *ps;
584 if (!scop)
585 return NULL;
587 ctx = isl_set_get_ctx(scop->context);
589 ps = isl_calloc_type(ctx, struct ppcg_scop);
590 if (!ps)
591 return NULL;
593 ps->options = options;
594 ps->start = scop->start;
595 ps->end = scop->end;
596 ps->context = isl_set_copy(scop->context);
597 ps->context = set_intersect_str(ps->context, options->ctx);
598 ps->domain = collect_non_kill_domains(scop);
599 ps->call = collect_call_domains(scop);
600 ps->tagged_reads = pet_scop_collect_tagged_may_reads(scop);
601 ps->reads = pet_scop_collect_may_reads(scop);
602 ps->tagged_may_writes = pet_scop_collect_tagged_may_writes(scop);
603 ps->may_writes = pet_scop_collect_may_writes(scop);
604 ps->tagged_must_writes = pet_scop_collect_tagged_must_writes(scop);
605 ps->must_writes = pet_scop_collect_must_writes(scop);
606 ps->tagged_must_kills = pet_scop_collect_tagged_must_kills(scop);
607 ps->schedule = pet_scop_collect_schedule(scop);
608 ps->n_type = scop->n_type;
609 ps->types = scop->types;
610 ps->n_array = scop->n_array;
611 ps->arrays = scop->arrays;
612 ps->n_stmt = scop->n_stmt;
613 ps->stmts = scop->stmts;
615 compute_tagger(ps);
616 compute_dependences(ps);
617 eliminate_dead_code(ps);
619 if (!ps->context || !ps->domain || !ps->call || !ps->reads ||
620 !ps->may_writes || !ps->must_writes || !ps->tagged_must_kills ||
621 !ps->schedule)
622 return ppcg_scop_free(ps);
624 return ps;
627 /* Internal data structure for ppcg_transform.
629 struct ppcg_transform_data {
630 struct ppcg_options *options;
631 __isl_give isl_printer *(*transform)(__isl_take isl_printer *p,
632 struct ppcg_scop *scop, void *user);
633 void *user;
636 /* Callback for pet_transform_C_source that transforms
637 * the given pet_scop to a ppcg_scop before calling the
638 * ppcg_transform callback.
640 static __isl_give isl_printer *transform(__isl_take isl_printer *p,
641 struct pet_scop *scop, void *user)
643 struct ppcg_transform_data *data = user;
644 struct ppcg_scop *ps;
646 if (pet_scop_has_data_dependent_conditions(scop)) {
647 p = pet_scop_print_original(scop, p);
648 pet_scop_free(scop);
649 return p;
652 scop = pet_scop_align_params(scop);
653 ps = ppcg_scop_from_pet_scop(scop, data->options);
655 p = data->transform(p, ps, data->user);
657 ppcg_scop_free(ps);
658 pet_scop_free(scop);
660 return p;
663 /* Transform the C source file "input" by rewriting each scop
664 * through a call to "transform".
665 * The transformed C code is written to "out".
667 * This is a wrapper around pet_transform_C_source that transforms
668 * the pet_scop to a ppcg_scop before calling "fn".
670 int ppcg_transform(isl_ctx *ctx, const char *input, FILE *out,
671 struct ppcg_options *options,
672 __isl_give isl_printer *(*fn)(__isl_take isl_printer *p,
673 struct ppcg_scop *scop, void *user), void *user)
675 struct ppcg_transform_data data = { options, fn, user };
676 return pet_transform_C_source(ctx, input, out, &transform, &data);
679 /* Check consistency of options.
681 * Return -1 on error.
683 static int check_options(isl_ctx *ctx)
685 struct options *options;
687 options = isl_ctx_peek_options(ctx, &options_args);
688 if (!options)
689 isl_die(ctx, isl_error_internal,
690 "unable to find options", return -1);
692 if (options->ppcg->openmp &&
693 !isl_options_get_ast_build_atomic_upper_bound(ctx))
694 isl_die(ctx, isl_error_invalid,
695 "OpenMP requires atomic bounds", return -1);
697 return 0;
700 int main(int argc, char **argv)
702 int r;
703 isl_ctx *ctx;
704 struct options *options;
706 options = options_new_with_defaults();
707 assert(options);
709 ctx = isl_ctx_alloc_with_options(&options_args, options);
710 isl_options_set_schedule_outer_coincidence(ctx, 1);
711 isl_options_set_schedule_maximize_band_depth(ctx, 1);
712 argc = options_parse(options, argc, argv, ISL_ARG_ALL);
714 if (check_options(ctx) < 0)
715 r = EXIT_FAILURE;
716 else if (options->ppcg->target == PPCG_TARGET_CUDA)
717 r = generate_cuda(ctx, options->ppcg, options->input);
718 else if (options->ppcg->target == PPCG_TARGET_OPENCL)
719 r = generate_opencl(ctx, options->ppcg, options->input,
720 options->output);
721 else
722 r = generate_cpu(ctx, options->ppcg, options->input,
723 options->output);
725 isl_ctx_free(ctx);
727 return r;