use_starpu_cublas_report_error.cocci 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 Inria
  4. * Copyright (C) 2012,2015,2017 CNRS
  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. // When using the CUBLAS library, we call cublasGetError() from times to times.
  18. // If it does not return CUBLAS_STATUS_SUCCESS, we should not immediatly abort:
  19. // first, we need to print a useful piece of information to make it easier to
  20. // debug the program.
  21. virtual context
  22. virtual org
  23. virtual patch
  24. virtual report
  25. // Pattern:
  26. // status = cubalsGetError();
  27. // if (status != CUBLAS_STATUS_SUCCESS)
  28. // STARPU_ABORT();
  29. //
  30. @starpu_abort@
  31. cublasStatus status;
  32. position p;
  33. @@
  34. status = cublasGetError();
  35. (
  36. if (status != CUBLAS_STATUS_SUCCESS)
  37. STARPU_ABORT@p();
  38. |
  39. if (STARPU_UNLIKELY(status != CUBLAS_STATUS_SUCCESS))
  40. STARPU_ABORT@p();
  41. )
  42. @depends on starpu_abort && context@
  43. position starpu_abort.p;
  44. @@
  45. * STARPU_ABORT@p();
  46. @script:python depends on starpu_abort && org@
  47. p << starpu_abort.p;
  48. @@
  49. coccilib.org.print_todo(p[0], "Use STARPU_CUBLAS_REPORT_ERROR() instead of STARPU_ABORT().")
  50. @depends on starpu_abort && patch@
  51. cublasStatus starpu_abort.status;
  52. position starpu_abort.p;
  53. @@
  54. - STARPU_ABORT@p();
  55. + STARPU_CUBLAS_REPORT_ERROR(status);
  56. @script:python depends on starpu_abort && report@
  57. p << starpu_abort.p;
  58. @@
  59. coccilib.report.print_report(p[0], "Use STARPU_CUBLAS_REPORT_ERROR() instead of STARPU_ABORT().")
  60. // Pattern:
  61. // status = cublasGetError();
  62. // STARPU_ASSERT(!status);
  63. @starpu_assert@
  64. cublasStatus status;
  65. position p;
  66. @@
  67. status = cublasGetError();
  68. STARPU_ASSERT@p(!status);
  69. @depends on starpu_assert && context@
  70. position starpu_assert.p;
  71. @@
  72. * STARPU_ASSERT@p(...);
  73. @script:python depends on starpu_assert && org@
  74. p << starpu_assert.p;
  75. @@
  76. coccilib.org.print_todo(p[0], "Use STARPU_CUBLAS_REPORT_ERROR() instead of STARPU_ASSERT().")
  77. @depends on starpu_assert && patch@
  78. position starpu_assert.p;
  79. cublasStatus starpu_assert.status;
  80. @@
  81. - STARPU_ASSERT@p(!status);
  82. + if (STARPU_UNLIKELY(status != CUBLAS_STATUS_SUCCESS))
  83. + STARPU_CUBLAS_REPORT_ERROR(status);
  84. @script:python depends on starpu_assert && report@
  85. p << starpu_assert.p;
  86. @@
  87. coccilib.report.print_report(p[0], "Use STARPU_CUBLAS_REPORT_ERROR() instead of STARPU_ASSERT().")