xgemm_kernels.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010 Centre National de la Recherche Scientifique
  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. #include <starpu.h>
  18. #include <starpu_cuda.h>
  19. #include <common/blas.h>
  20. #define COMMON_CODE \
  21. uint32_t nxC, nyC, nyA; \
  22. uint32_t ldA, ldB, ldC; \
  23. \
  24. TYPE *subA; \
  25. TYPE *subB; \
  26. TYPE *subC; \
  27. \
  28. subA = (TYPE *)STARPU_MATRIX_GET_PTR(descr[0]); \
  29. subB = (TYPE *)STARPU_MATRIX_GET_PTR(descr[1]); \
  30. subC = (TYPE *)STARPU_MATRIX_GET_PTR(descr[2]); \
  31. \
  32. nxC = STARPU_MATRIX_GET_NX(descr[2]); \
  33. nyC = STARPU_MATRIX_GET_NY(descr[2]); \
  34. nyA = STARPU_MATRIX_GET_NY(descr[0]); \
  35. \
  36. ldA = STARPU_MATRIX_GET_LD(descr[0]); \
  37. ldB = STARPU_MATRIX_GET_LD(descr[1]); \
  38. ldC = STARPU_MATRIX_GET_LD(descr[2]);
  39. #ifdef STARPU_USE_CUDA
  40. #ifdef STARPU_HAVE_MAGMA
  41. #define GPU_GEMM MAGMABLAS_GEMM
  42. #else
  43. #define GPU_GEMM CUBLAS_GEMM
  44. #endif
  45. void STARPU_GEMM(cublas_mult)(void *descr[], __attribute__((unused)) void *arg)
  46. {
  47. COMMON_CODE
  48. starpu_trace_user_event(0x42);
  49. GPU_GEMM('n', 'n', nxC, nyC, nyA, (TYPE)1.0, subA, ldA, subB, ldB,
  50. (TYPE)0.0, subC, ldC);
  51. cublasStatus st;
  52. st = cublasGetError();
  53. if (st != CUBLAS_STATUS_SUCCESS)
  54. STARPU_ABORT();
  55. cudaThreadSynchronize();
  56. starpu_trace_user_event(0x42);
  57. }
  58. #endif
  59. void STARPU_GEMM(cpu_mult)(void *descr[], __attribute__((unused)) void *arg)
  60. {
  61. COMMON_CODE
  62. starpu_trace_user_event(0x42);
  63. CPU_GEMM("N", "N", nxC, nyC, nyA, (TYPE)1.0, subA, ldA, subB, ldB, (TYPE)0.0, subC, ldC);
  64. starpu_trace_user_event(0x43);
  65. }