starpu_cuda.h 2.3 KB

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