use_starpu_cublas_report_error.cocci 2.7 KB

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