matmul_pragma.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2013,2015,2017 CNRS
  4. * Copyright (C) 2010-2014 Université de Bordeaux
  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. //! [To be included. You should update doxygen if you see this text.]
  18. /* This program is valid, whether or not StarPU's GCC plug-in
  19. is being used. */
  20. #include <stdlib.h>
  21. /* The attribute below is ignored when GCC is not used. */
  22. static void matmul (const float *A, const float *B, float * C,
  23. unsigned nx, unsigned ny, unsigned nz)
  24. __attribute__ ((task));
  25. static void
  26. matmul (const float *A, const float *B, float * C,
  27. unsigned nx, unsigned ny, unsigned nz)
  28. {
  29. /* Code of the CPU kernel here... */
  30. }
  31. #ifdef STARPU_GCC_PLUGIN
  32. /* Optional OpenCL task implementation. */
  33. static void matmul_opencl (const float *A, const float *B, float * C,
  34. unsigned nx, unsigned ny, unsigned nz)
  35. __attribute__ ((task_implementation ("opencl", matmul)));
  36. static void
  37. matmul_opencl (const float *A, const float *B, float * C,
  38. unsigned nx, unsigned ny, unsigned nz)
  39. {
  40. /* Code that invokes the OpenCL kernel here... */
  41. }
  42. #endif
  43. int
  44. main (int argc, char *argv[])
  45. {
  46. /* The pragmas below are simply ignored when StarPU-GCC
  47. is not used. */
  48. #pragma starpu initialize
  49. float A[123][42][7], B[123][42][7], C[123][42][7];
  50. #pragma starpu register A
  51. #pragma starpu register B
  52. #pragma starpu register C
  53. /* When StarPU-GCC is used, the call below is asynchronous;
  54. otherwise, it is synchronous. */
  55. matmul ((float *) A, (float *) B, (float *) C, 123, 42, 7);
  56. #pragma starpu wait
  57. #pragma starpu shutdown
  58. return EXIT_SUCCESS;
  59. }
  60. //! [To be included. You should update doxygen if you see this text.]