matmul_pragma.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* This program is valid, whether or not StarPU's GCC plug-in
  2. is being used. */
  3. #include <stdlib.h>
  4. /* The attribute below is ignored when GCC is not used. */
  5. static void matmul (const float *A, const float *B, float * C,
  6. unsigned nx, unsigned ny, unsigned nz)
  7. __attribute__ ((task));
  8. static void
  9. matmul (const float *A, const float *B, float * C,
  10. unsigned nx, unsigned ny, unsigned nz)
  11. {
  12. /* Code of the CPU kernel here... */
  13. }
  14. #ifdef STARPU_GCC_PLUGIN
  15. /* Optional OpenCL task implementation. */
  16. static void matmul_opencl (const float *A, const float *B, float * C,
  17. unsigned nx, unsigned ny, unsigned nz)
  18. __attribute__ ((task_implementation ("opencl", matmul)));
  19. static void
  20. matmul_opencl (const float *A, const float *B, float * C,
  21. unsigned nx, unsigned ny, unsigned nz)
  22. {
  23. /* Code that invokes the OpenCL kernel here... */
  24. }
  25. #endif
  26. int
  27. main (int argc, char *argv[])
  28. {
  29. /* The pragmas below are simply ignored when StarPU-GCC
  30. is not used. */
  31. #pragma starpu initialize
  32. float A[123][42][7], B[123][42][7], C[123][42][7];
  33. #pragma starpu register A
  34. #pragma starpu register B
  35. #pragma starpu register C
  36. /* When StarPU-GCC is used, the call below is asynchronous;
  37. otherwise, it is synchronous. */
  38. matmul ((float *) A, (float *) B, (float *) C, 123, 42, 7);
  39. #pragma starpu wait
  40. #pragma starpu shutdown
  41. return EXIT_SUCCESS;
  42. }