move copying of code before and after scop from print_cuda to generate_gpu
[ppcg.git] / cuda_common.c
blob7a1c22eeaa79b0c4af3ac2aeed183b7b232098de
1 /*
2 * Copyright 2010 INRIA Saclay
4 * Use of this software is governed by the MIT 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 <ctype.h>
12 #include <limits.h>
13 #include <string.h>
15 #include "cuda_common.h"
17 /* Open the host .cu file and the kernel .hu and .cu files for writing.
18 * Add the necessary includes.
20 void cuda_open_files(struct cuda_info *info, const char *input)
22 char name[PATH_MAX];
23 const char *base;
24 const char *ext;
25 int len;
27 base = strrchr(input, '/');
28 if (base)
29 base++;
30 else
31 base = input;
32 ext = strrchr(base, '.');
33 len = ext ? ext - base : strlen(base);
35 memcpy(name, base, len);
36 strcpy(name + len, "_host.cu");
37 info->host_c = fopen(name, "w");
39 strcpy(name + len, "_kernel.cu");
40 info->kernel_c = fopen(name, "w");
42 strcpy(name + len, "_kernel.hu");
43 info->kernel_h = fopen(name, "w");
44 fprintf(info->host_c, "#include <assert.h>\n");
45 fprintf(info->host_c, "#include \"%s\"\n", name);
46 fprintf(info->kernel_c, "#include \"%s\"\n", name);
47 fprintf(info->kernel_h, "#include \"cuda.h\"\n\n");
50 /* Close all output files.
52 void cuda_close_files(struct cuda_info *info)
54 fclose(info->kernel_c);
55 fclose(info->kernel_h);
56 fclose(info->host_c);