cuda_common.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #include <ctype.h>
  11. #include <limits.h>
  12. #include <string.h>
  13. #include "cuda_common.h"
  14. #include "ppcg.h"
  15. /* Open the host .cu file and the kernel .hu and .cu files for writing.
  16. * Add the necessary includes.
  17. */
  18. void cuda_open_files(struct cuda_info *info, const char *input)
  19. {
  20. char name[PATH_MAX];
  21. int len;
  22. len = ppcg_extract_base_name(name, input);
  23. strcpy(name + len, "_host.cu");
  24. info->host_c = fopen(name, "w");
  25. strcpy(name + len, "_kernel.cu");
  26. info->kernel_c = fopen(name, "w");
  27. strcpy(name + len, "_kernel.hu");
  28. info->kernel_h = fopen(name, "w");
  29. fprintf(info->host_c, "#include <assert.h>\n");
  30. fprintf(info->host_c, "#include <stdio.h>\n");
  31. fprintf(info->host_c, "#include \"%s\"\n", name);
  32. fprintf(info->kernel_c, "#include \"%s\"\n", name);
  33. fprintf(info->kernel_h, "#include \"cuda.h\"\n\n");
  34. }
  35. /* Close all output files.
  36. */
  37. void cuda_close_files(struct cuda_info *info)
  38. {
  39. fclose(info->kernel_c);
  40. fclose(info->kernel_h);
  41. fclose(info->host_c);
  42. }