max_riffa.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include <starpu.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <fpga.h>
  5. #include <starpu_scheduler.h>
  6. #include "../helper.h"
  7. void cpu_func(void *buffers[], void *cl_arg)
  8. {
  9. (void)buffers;
  10. (void)cl_arg;
  11. printf("Hello world\n");
  12. }
  13. void fpga_mult(void *d[])
  14. {
  15. /* Ask Fpga for a channel, or
  16. * equivalently for a hardware task
  17. */
  18. int chnl = fpga_reserve_a_chanel();
  19. /* Get inputs from STARPU */
  20. int* subA = STARPU_MATRIX_GET_PTR(d[0]);
  21. int* subB = STARPU_MATRIX_GET_PTR(d[1]);
  22. int* subC = STARPU_MATRIX_GET_PTR(d[2]);
  23. /* Get info on which part of the
  24. * inputs the task must operate
  25. */
  26. uint32_t nyA= STARPU_MATRIX_GET_NY(d[0]);
  27. uint32_t ldA= STARPU_MATRIX_GET_LD(d[0]);
  28. uint32_t nyB= STARPU_MATRIX_GET_NY(d[1]);
  29. uint32_t ldB= STARPU_MATRIX_GET_LD(d[1]);
  30. uint32_t nyC= STARPU_MATRIX_GET_NY(d[2]);
  31. uint32_t ldC= STARPU_MATRIX_GET_LD(d[2]);
  32. uint32_t nxC= STARPU_MATRIX_GET_NX(d[2]);
  33. /* Send A and B */
  34. int buf_s[nyA], buf_r[nxC*nyC];
  35. fpga_trans sent, recv;
  36. for (uint32_t j = 0; j < nxC; j++)
  37. {
  38. for (uint32_t k = 0; k < nyA; k++)
  39. buf_s[k] = subA[j+k*ldA];
  40. fpga_data_send(chnl, buf_s, nyA);
  41. }
  42. for (uint32_t i = 0; i < nyC; i++)
  43. {
  44. for (uint32_t k = 0; k < nyA; k++)
  45. buf_s[k] = subB[k+i*ldB];
  46. fpga_data_send(chnl, buf_s, nyA);
  47. }
  48. /* Receive C. This is blocking */
  49. fpga_data_recv(chnl, buf_r, nxC*nyC);
  50. for (uint32_t i = 0; i < nxC; i++)
  51. {
  52. for (uint32_t j = 0; j < nyC; j++)
  53. subC[j + i*ldC] = buf_r[i*nyC+j];
  54. }
  55. fpga_release_chanel(chnl);
  56. }
  57. static struct starpu_codelet cl =
  58. {
  59. .cpu_funcs = {cpu_func},
  60. .cpu_funcs_name = {"cpu_func"},
  61. //.fpga_funcs = {fpga_mult},
  62. .fpga_funcs = {fpga_mult},
  63. .fpga_funcs_name={"fpga_mult"},
  64. .nbuffers = 3,
  65. .modes = {STARPU_R, STARPU_R, STARPU_W}
  66. };
  67. int main(int argc, char **argv)
  68. {
  69. starpu_profiling_status_set(1);
  70. struct starpu_conf conf;
  71. starpu_data_handle_t A_handle, B_handle, C_handle;
  72. int ret;
  73. starpu_conf_init(&conf);
  74. ret = starpu_initialize(&conf, &argc, &argv);
  75. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  76. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  77. /* initialize StarPU */
  78. starpu_init(NULL);
  79. for (uint32_t x = 0; x < 9; x++)
  80. {
  81. for (uint32_t y = 0; y < 9; y++)
  82. {
  83. struct starpu_task *task = starpu_task_create();
  84. task->cl = &cl; /* Pointer to the codelet defined above */
  85. /* Get handlers for each block */
  86. task->handles[0] = starpu_data_get_sub_data( A_handle, 1, y);
  87. task->handles[1] = starpu_data_get_sub_data( B_handle, 1, x);
  88. task->handles[2] = starpu_data_get_sub_data( C_handle, 2, x, y);
  89. /* submit the task to StarPU */
  90. starpu_task_submit(task);
  91. }
  92. }
  93. starpu_data_unregister(A_handle);
  94. starpu_data_unregister(B_handle);
  95. starpu_data_unregister(C_handle);
  96. starpu_task_wait_for_all();
  97. /* terminate StarPU */
  98. starpu_shutdown();
  99. return 0;
  100. }