sgemm_kernels.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. void cublas_mult(void *descr[], __attribute__((unused)) void *arg)
  39. {
  40. COMMON_CODE
  41. starpu_trace_user_event(0x42);
  42. cublasSgemm('n', 'n', nxC, nyC, nyA, 1.0f, subA, ldA, subB, ldB,
  43. 0.0f, subC, ldC);
  44. cublasStatus st;
  45. st = cublasGetError();
  46. if (st != CUBLAS_STATUS_SUCCESS)
  47. STARPU_ABORT();
  48. cudaThreadSynchronize();
  49. starpu_trace_user_event(0x43);
  50. }
  51. #endif
  52. void cpu_mult(void *descr[], __attribute__((unused)) void *arg)
  53. {
  54. COMMON_CODE
  55. starpu_trace_user_event(0x42);
  56. SGEMM("N", "N", nxC, nyC, nyA, 1.0f, subA, ldA, subB, ldB, 0.0f, subC, ldC);
  57. starpu_trace_user_event(0x43);
  58. }