2 * Copyright 2010 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,
15 #include "cuda_common.h"
18 /* Open the "input" file for reading and open the host .cu file
19 * and the kernel .hu and .cu files for writing.
20 * Add the necessary includes and copy all code from the input
21 * file up to the openscop pragma to the host .cu file.
23 void cuda_open_files(struct cuda_info
*info
, const char *input
)
30 base
= strrchr(input
, '/');
35 ext
= strrchr(base
, '.');
36 len
= ext
? ext
- base
: strlen(base
);
38 memcpy(name
, base
, len
);
39 strcpy(name
+ len
, "_host.cu");
40 info
->host_c
= fopen(name
, "w");
42 strcpy(name
+ len
, "_kernel.cu");
43 info
->kernel_c
= fopen(name
, "w");
45 strcpy(name
+ len
, "_kernel.hu");
46 info
->kernel_h
= fopen(name
, "w");
47 fprintf(info
->host_c
, "#include <assert.h>\n");
48 fprintf(info
->host_c
, "#include \"%s\"\n", name
);
49 fprintf(info
->kernel_c
, "#include \"%s\"\n", name
);
50 fprintf(info
->kernel_h
, "#include \"cuda.h\"\n\n");
52 info
->input
= fopen(input
, "r");
53 copy(info
->input
, info
->host_c
, 0, info
->start
);
56 /* Copy all code starting at the endscop pragma from the input
57 * file to the host .cu file and close all input and output files.
59 void cuda_close_files(struct cuda_info
*info
)
61 copy(info
->input
, info
->host_c
, info
->end
, -1);
63 fclose(info
->kernel_c
);
64 fclose(info
->kernel_h
);