sgemm_kernels.c 1.9 KB

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