max_fpga.c 3.7 KB

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