• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2010      INRIA Saclay
3  *
4  * Use of this software is governed by the MIT license
5  *
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  */
10 
11 #include <ctype.h>
12 #include <limits.h>
13 #include <string.h>
14 
15 #include "cuda_common.h"
16 #include "ppcg.h"
17 
18 /* Open the host .cu file and the kernel .hu and .cu files for writing.
19  * Add the necessary includes.
20  */
cuda_open_files(struct cuda_info * info,const char * input)21 void cuda_open_files(struct cuda_info *info, const char *input)
22 {
23     char name[PATH_MAX];
24     int len;
25 
26     len = ppcg_extract_base_name(name, input);
27 
28     strcpy(name + len, "_host.cu");
29     info->host_c = fopen(name, "w");
30 
31     strcpy(name + len, "_kernel.cu");
32     info->kernel_c = fopen(name, "w");
33 
34     strcpy(name + len, "_kernel.hu");
35     info->kernel_h = fopen(name, "w");
36     fprintf(info->host_c, "#include <assert.h>\n");
37     fprintf(info->host_c, "#include <stdio.h>\n");
38     fprintf(info->host_c, "#include \"%s\"\n", name);
39     fprintf(info->kernel_c, "#include \"%s\"\n", name);
40     fprintf(info->kernel_h, "#include \"cuda.h\"\n\n");
41 }
42 
43 /* Close all output files.
44  */
cuda_close_files(struct cuda_info * info)45 void cuda_close_files(struct cuda_info *info)
46 {
47     fclose(info->kernel_c);
48     fclose(info->kernel_h);
49     fclose(info->host_c);
50 }
51