max_fpga.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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.h"
  8. #include "MaxSLiCInterface.h"
  9. void cpu_func(void *buffers[], void *cl_arg)
  10. {
  11. (void)buffers;
  12. (void)cl_arg;
  13. printf("///******Hello world**********//////\n");
  14. }
  15. void fpga_mult(void *buffers[], void *cl_arg)
  16. {
  17. (void)buffers;
  18. (void)cl_arg;
  19. const int size = 384;
  20. int sizeBytes = size * sizeof(int32_t);
  21. int32_t *a = (int32_t*) malloc(sizeBytes);
  22. int32_t *b = (int32_t*) malloc(sizeBytes);
  23. int32_t *c = (int32_t*) malloc(sizeBytes);
  24. // TODO Generate input data
  25. for(int i = 0; i < size; ++i)
  26. {
  27. a[i] = random() % 100;
  28. b[i] = random() % 100;
  29. }
  30. //Implementation of a maxfile
  31. //max_file_t *maxfile = StreamFMA_init();
  32. //Implementation of an engine
  33. //max_engine_t *engine = max_load(maxfile, "*");
  34. //Actions to run on an engine
  35. //max_actions_t* act = max_actions_init(maxfile, NULL);
  36. //set the number of ticks for a kernel
  37. //max_set_ticks (act, "StreamFMAKernel", size);
  38. //add data to an input stream
  39. //max_queue_input(act, "a", a, sizeBytes);
  40. //max_queue_input(act, "b", b, sizeBytes);
  41. //max_queue_output(act,"output", c, sizeBytes);
  42. //run actions on the engine
  43. printf("Running on DFE using dynamic interface ...\n");
  44. printf("**** Run actions in non blocking mode **** \n");
  45. //run actions in non_blocking mode
  46. //max_run_t *run0= max_run_nonblock(engine, act);
  47. printf("*** wait for the actions on DFE to complete *** \n");
  48. //wait for the actions to complete
  49. //max_wait(run0);
  50. //deallocate the set of actions
  51. //max_actions_free(act);
  52. //unload and deallocate an engine obtained by way of max_load
  53. //max_unload(engine);
  54. }
  55. static struct starpu_codelet cl =
  56. {
  57. .cpu_funcs = {cpu_func},
  58. .cpu_funcs_name = {"cpu_func"},
  59. #ifdef STARPU_USE_FPGA
  60. .fpga_funcs = {fpga_mult},
  61. .fpga_funcs_name={"fpga_mult"},
  62. #endif
  63. .nbuffers = 1,
  64. .modes = {STARPU_W}
  65. };
  66. int main(int argc, char **argv)
  67. {
  68. /* Enable profiling */
  69. starpu_profiling_status_set(1);
  70. struct starpu_conf conf;
  71. starpu_data_handle_t handle;
  72. int ret;
  73. int size=1234;
  74. starpu_conf_init(&conf);
  75. conf.sched_policy_name = "eager";
  76. conf.calibrate = 0;
  77. ret = starpu_initialize(&conf, &argc, &argv);
  78. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  79. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  80. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, size, sizeof(int));
  81. struct starpu_task *task = starpu_task_create();
  82. task->cl = &cl;
  83. task->handles[0] = handle;
  84. task->synchronous = 1;
  85. task->destroy = 0;
  86. /* submit the task to StarPU */
  87. //starpu_task_destroy(task);
  88. starpu_task_submit(task);
  89. starpu_data_unregister(handle);
  90. starpu_shutdown();
  91. return EXIT_SUCCESS;
  92. }