max_fpga.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. #include "StreamFMA.max"
  8. #include "MaxSLiCInterface.h"
  9. #include "StreamFMA.h"
  10. #define SIZE 128
  11. static max_engine_t *engine ;
  12. static max_actions_t*act;
  13. static max_file_t *maxfile;
  14. void cpu_func(void *buffers[], void *cl_arg)
  15. {
  16. int *a = (int*) STARPU_VECTOR_GET_PTR(buffers[0]);
  17. int *b = (int*) STARPU_VECTOR_GET_PTR(buffers[1]);
  18. int *c = (int*) STARPU_VECTOR_GET_PTR(buffers[2]);
  19. int size = STARPU_VECTOR_GET_NX(buffers[0]);
  20. (void)buffers;
  21. (void)cl_arg;
  22. int i;
  23. for (i = 0; i < size; i++)
  24. c[i] = a[i] + b[i];
  25. }
  26. void fpga_mult(void *buffers[], void *cl_arg)
  27. {
  28. (void)cl_arg;
  29. int *a = (int*) STARPU_VECTOR_GET_PTR(buffers[0]);
  30. int *b = (int*) STARPU_VECTOR_GET_PTR(buffers[1]);
  31. int *c = (int*) STARPU_VECTOR_GET_PTR(buffers[2]);
  32. int size = STARPU_VECTOR_GET_NX(buffers[0]);
  33. //Actions to run on an engine
  34. act = max_actions_init(maxfile, NULL);
  35. //set the number of ticks for a kernel
  36. max_set_ticks (act, "StreamFMAKernel", size);
  37. #if 1
  38. // sera remplacé par le transfert fait par le copy_fpga_to_ram/ram_to_fpga
  39. //add data to an input stream
  40. //max_set_param_uint64t(act, "address", 0);
  41. //max_set_param_uint64t(act, "nbytes", size *sizeof(a[0]));
  42. max_queue_input(act, "a", a, size *sizeof(a[0]));
  43. max_queue_input(act, "b", b, size*sizeof(b[0]));
  44. max_queue_output(act,"output", c, size*sizeof(c[0]));
  45. // et à la place, ici on récupère le pointeur dans la mémoire FPGA avec STARPU_VECTOR_GET_PTR(descr[0]), et c'est ça qu'on donne à l'implémentation fpga
  46. #endif
  47. //run actions on the engine
  48. printf("Running on DFE using dynamic interface ...\n");
  49. printf("**** Run actions in non blocking mode **** \n");
  50. //run actions in non_blocking mode
  51. max_run_t *run0= max_run_nonblock(engine, act);
  52. printf("*** wait for the actions on DFE to complete *** \n");
  53. //wait for the actions to complete
  54. max_wait(run0);
  55. }
  56. static struct starpu_codelet cl =
  57. {
  58. .cpu_funcs = {cpu_func},
  59. .cpu_funcs_name = {"cpu_func"},
  60. //#ifdef STARPU_USE_FPGA
  61. .fpga_funcs = {fpga_mult},
  62. .fpga_funcs_name={"fpga_mult"},
  63. //#endif
  64. .nbuffers = 3,
  65. .modes = {STARPU_R, STARPU_R, STARPU_W}
  66. };
  67. int main(int argc, char **argv)
  68. {
  69. /* Enable profiling */
  70. starpu_profiling_status_set(1);
  71. struct starpu_conf conf;
  72. starpu_data_handle_t handle_a, handle_b, handle_c;
  73. int ret;
  74. int size=1234;
  75. starpu_conf_init(&conf);
  76. conf.sched_policy_name = "eager";
  77. conf.calibrate = 0;
  78. ret = starpu_initialize(&conf, &argc, &argv);
  79. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  80. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  81. //Implementation of a maxfile
  82. maxfile = StreamFMA_init();
  83. //Implementation of an engine
  84. engine = max_load(maxfile, "*");
  85. int a[SIZE];
  86. int b[SIZE];
  87. int c[SIZE];
  88. int i;
  89. for(i = 0; i < SIZE; ++i)
  90. {
  91. a[i] = random() % 100;
  92. b[i] = random() % 100;
  93. }
  94. starpu_vector_data_register(&handle_a, STARPU_MAIN_RAM, (uintptr_t) &a, SIZE, sizeof(int));
  95. starpu_vector_data_register(&handle_b, STARPU_MAIN_RAM, (uintptr_t) &b, SIZE, sizeof(int));
  96. starpu_vector_data_register(&handle_c, STARPU_MAIN_RAM, (uintptr_t) &c, SIZE, sizeof(int));
  97. struct starpu_task *task = starpu_task_create();
  98. task->cl = &cl;
  99. task->handles[0] = handle_a;
  100. task->handles[1] = handle_b;
  101. task->handles[2] = handle_c;
  102. task->synchronous = 1;
  103. task->destroy = 0;
  104. /* submit the task to StarPU */
  105. //starpu_task_destroy(task);
  106. ret = starpu_task_submit(task);
  107. fprintf(stderr,"task submitted %d\n", ret);
  108. starpu_data_unregister(handle_a);
  109. starpu_data_unregister(handle_b);
  110. starpu_data_unregister(handle_c);
  111. int mysize = SIZE;
  112. if (mysize > 10)
  113. mysize = 10;
  114. for (i = 0; i < mysize; ++i)
  115. {
  116. printf("%d == %d\n", c[i], a[i] + b[i]);
  117. }
  118. #if 1
  119. // -> main
  120. //deallocate the set of actions
  121. max_actions_free(act);
  122. //unload and deallocate an engine obtained by way of max_load
  123. max_unload(engine);
  124. #endif
  125. starpu_shutdown();
  126. return EXIT_SUCCESS;
  127. }