sgemm_kernels.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #include <starpu.h>
  17. #include <starpu_cuda.h>
  18. #include <common/blas.h>
  19. #define COMMON_CODE \
  20. uint32_t nxC, nyC, nyA; \
  21. uint32_t ldA, ldB, ldC; \
  22. \
  23. float *subA; \
  24. float *subB; \
  25. float *subC; \
  26. \
  27. subA = (float *)STARPU_MATRIX_GET_PTR(descr[0]); \
  28. subB = (float *)STARPU_MATRIX_GET_PTR(descr[1]); \
  29. subC = (float *)STARPU_MATRIX_GET_PTR(descr[2]); \
  30. \
  31. nxC = STARPU_MATRIX_GET_NX(descr[2]); \
  32. nyC = STARPU_MATRIX_GET_NY(descr[2]); \
  33. nyA = STARPU_MATRIX_GET_NY(descr[0]); \
  34. \
  35. ldA = STARPU_MATRIX_GET_LD(descr[0]); \
  36. ldB = STARPU_MATRIX_GET_LD(descr[1]); \
  37. ldC = STARPU_MATRIX_GET_LD(descr[2]);
  38. #ifdef STARPU_USE_CUDA
  39. #ifdef STARPU_HAVE_MAGMA
  40. #define GPU_SGEMM magmablas_sgemm
  41. #else
  42. #define GPU_SGEMM cublasSgemm
  43. #endif
  44. void cublas_mult(void *descr[], __attribute__((unused)) void *arg)
  45. {
  46. COMMON_CODE
  47. starpu_trace_user_event(0x42);
  48. GPU_SGEMM('n', 'n', nxC, nyC, nyA, 1.0f, subA, ldA, subB, ldB,
  49. 0.0f, subC, ldC);
  50. cublasStatus st;
  51. st = cublasGetError();
  52. if (st != CUBLAS_STATUS_SUCCESS)
  53. STARPU_ABORT();
  54. cudaThreadSynchronize();
  55. starpu_trace_user_event(0x43);
  56. }
  57. #endif
  58. void cpu_mult(void *descr[], __attribute__((unused)) void *arg)
  59. {
  60. COMMON_CODE
  61. starpu_trace_user_event(0x42);
  62. SGEMM("N", "N", nxC, nyC, nyA, 1.0f, subA, ldA, subB, ldB, 0.0f, subC, ldC);
  63. starpu_trace_user_event(0x43);
  64. }