starpu_cuda.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #ifndef __STARPU_CUDA_H__
  18. #define __STARPU_CUDA_H__
  19. #ifdef STARPU_USE_CUDA
  20. #include <cuda.h>
  21. #include <cuda_runtime.h>
  22. #include <cuda_runtime_api.h>
  23. #include <cublas.h>
  24. #include <starpu_config.h>
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. #if defined(__CUDACC__) && defined(STARPU_HAVE_WINDOWS)
  29. #define STARPU_CUBLAS_OOPS() do { \
  30. printf("oops %s \n", errormsg); \
  31. *(int*)NULL = 0; \
  32. } while (0);
  33. #else
  34. #define STARPU_CUBLAS_OOPS() do { \
  35. printf("oops in %s ... %s \n", __func__, errormsg); \
  36. assert(0); \
  37. } while (0);
  38. #endif
  39. #define STARPU_CUBLAS_REPORT_ERROR(status) \
  40. do { \
  41. char *errormsg; \
  42. switch (status) { \
  43. case CUBLAS_STATUS_SUCCESS: \
  44. errormsg = "success"; \
  45. break; \
  46. case CUBLAS_STATUS_NOT_INITIALIZED: \
  47. errormsg = "not initialized"; \
  48. break; \
  49. case CUBLAS_STATUS_ALLOC_FAILED: \
  50. errormsg = "alloc failed"; \
  51. break; \
  52. case CUBLAS_STATUS_INVALID_VALUE: \
  53. errormsg = "invalid value"; \
  54. break; \
  55. case CUBLAS_STATUS_ARCH_MISMATCH: \
  56. errormsg = "arch mismatch"; \
  57. break; \
  58. case CUBLAS_STATUS_EXECUTION_FAILED: \
  59. errormsg = "execution failed"; \
  60. break; \
  61. case CUBLAS_STATUS_INTERNAL_ERROR: \
  62. errormsg = "internal error"; \
  63. break; \
  64. default: \
  65. errormsg = "unknown error"; \
  66. break; \
  67. } \
  68. STARPU_CUBLAS_OOPS(); \
  69. } while (0)
  70. #define STARPU_CUDA_REPORT_ERROR(status) \
  71. do { \
  72. const char *errormsg = cudaGetErrorString(status); \
  73. STARPU_CUBLAS_OOPS(); \
  74. } while (0)
  75. cudaStream_t starpu_cuda_get_local_stream(void);
  76. #ifdef __cplusplus
  77. }
  78. #endif
  79. #endif // STARPU_USE_CUDA
  80. #endif // __STARPU_CUDA_H__