max_fpga_dynamic.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2019-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu.h>
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include <starpu_scheduler.h>
  20. #include "../helper.h"
  21. #include "MyTasks.h"
  22. #include "MaxSLiCInterface.h"
  23. #define SIZE (192/sizeof(int32_t))
  24. static max_file_t *maxfile;
  25. static max_engine_t *engine;
  26. void fpga_impl1(void *buffers[], void *cl_arg)
  27. {
  28. (void)cl_arg;
  29. int32_t *ptrA = (int32_t*) STARPU_VECTOR_GET_PTR(buffers[0]);
  30. int32_t *ptrB = (int32_t*) STARPU_VECTOR_GET_PTR(buffers[1]);
  31. size_t ptrC = (size_t) STARPU_VECTOR_GET_PTR(buffers[2]); /* FPGA */
  32. int size = STARPU_VECTOR_GET_NX(buffers[0]);
  33. printf("T1 with %p %p %zu\n", ptrA, ptrB, ptrC);
  34. /* C = A+B */
  35. max_actions_t *acts = max_actions_init(maxfile, NULL);
  36. max_set_ticks(acts, "Task1", size);
  37. max_ignore_scalar(acts, "Task2", "run_cycle_count");
  38. max_ignore_scalar(acts, "Task3", "run_cycle_count");
  39. max_queue_input(acts, "inAT1", ptrA, size * sizeof(uint32_t));
  40. max_queue_input(acts, "inBT1", ptrB, size * sizeof(uint32_t));
  41. max_memctl_linear(acts, "MemoryControllerPro0", "outCT1", ptrC, size * sizeof(uint32_t));
  42. max_ignore_memctl(acts, "MemoryControllerPro0", "inAT2");
  43. max_ignore_memctl(acts, "MemoryControllerPro0", "inBT2");
  44. max_ignore_memctl(acts, "MemoryControllerPro0", "outCT2");
  45. max_ignore_memctl(acts, "MemoryControllerPro0", "inAT3");
  46. max_ignore_memctl(acts, "MemoryControllerPro0", "inBT3");
  47. max_ignore_stream(acts, "outCT3");
  48. max_run(engine, acts);
  49. max_actions_free(acts);
  50. printf("T1 finished\n");
  51. }
  52. static struct starpu_codelet cl1 =
  53. {
  54. .fpga_funcs = {fpga_impl1},
  55. .nbuffers = 3,
  56. .modes = {STARPU_R, STARPU_R, STARPU_W},
  57. .specific_nodes = 1,
  58. .nodes = {STARPU_SPECIFIC_NODE_CPU, STARPU_SPECIFIC_NODE_CPU, STARPU_SPECIFIC_NODE_LOCAL},
  59. };
  60. void fpga_impl2(void *buffers[], void *cl_arg)
  61. {
  62. (void)cl_arg;
  63. size_t ptrA = (size_t) STARPU_VECTOR_GET_PTR(buffers[0]); /* FPGA */
  64. size_t ptrB = (size_t) STARPU_VECTOR_GET_PTR(buffers[1]); /* FPGA */
  65. size_t ptrC = (size_t) STARPU_VECTOR_GET_PTR(buffers[2]); /* FPGA */
  66. int size = STARPU_VECTOR_GET_NX(buffers[0]);
  67. printf("T2 with %zu %zu %zu\n", ptrA, ptrB, ptrC);
  68. /* C = A*B */
  69. max_actions_t *acts = max_actions_init(maxfile, NULL);
  70. max_ignore_scalar(acts, "Task1", "run_cycle_count");
  71. max_set_ticks(acts, "Task2", size);
  72. max_ignore_scalar(acts, "Task3", "run_cycle_count");
  73. max_ignore_stream(acts, "inAT1");
  74. max_ignore_stream(acts, "inBT1");
  75. max_ignore_memctl(acts, "MemoryControllerPro0", "outCT1");
  76. max_memctl_linear(acts, "MemoryControllerPro0", "inAT2", ptrA, size * sizeof(uint32_t));
  77. max_memctl_linear(acts, "MemoryControllerPro0", "inBT2", ptrB, size * sizeof(uint32_t));
  78. max_memctl_linear(acts, "MemoryControllerPro0", "outCT2", ptrC, size * sizeof(uint32_t));
  79. max_ignore_memctl(acts, "MemoryControllerPro0", "inAT3");
  80. max_ignore_memctl(acts, "MemoryControllerPro0", "inBT3");
  81. max_ignore_stream(acts, "outCT3");
  82. max_run(engine, acts);
  83. max_actions_free(acts);
  84. printf("T2 finished\n");
  85. }
  86. static struct starpu_codelet cl2 =
  87. {
  88. .fpga_funcs = {fpga_impl2},
  89. .nbuffers = 3,
  90. .modes = {STARPU_R, STARPU_R, STARPU_W}
  91. /* local by default */
  92. };
  93. void fpga_impl3(void *buffers[], void *cl_arg)
  94. {
  95. (void)cl_arg;
  96. size_t ptrA = (size_t) STARPU_VECTOR_GET_PTR(buffers[0]); /* FPGA */
  97. size_t ptrB = (size_t) STARPU_VECTOR_GET_PTR(buffers[1]); /* FPGA */
  98. int32_t *ptrC = (int32_t*) STARPU_VECTOR_GET_PTR(buffers[2]);
  99. int size = STARPU_VECTOR_GET_NX(buffers[0]);
  100. printf("T3 with %zu %zu %p\n", ptrA, ptrB, ptrC);
  101. /* C = A+B */
  102. max_actions_t *acts = max_actions_init(maxfile, NULL);
  103. max_ignore_scalar(acts, "Task1", "run_cycle_count");
  104. max_ignore_scalar(acts, "Task2", "run_cycle_count");
  105. max_set_ticks(acts, "Task3", size);
  106. max_ignore_stream(acts, "inAT1");
  107. max_ignore_stream(acts, "inBT1");
  108. max_ignore_memctl(acts, "MemoryControllerPro0", "outCT1");
  109. max_ignore_memctl(acts, "MemoryControllerPro0", "inAT2");
  110. max_ignore_memctl(acts, "MemoryControllerPro0", "inBT2");
  111. max_ignore_memctl(acts, "MemoryControllerPro0", "outCT2");
  112. max_memctl_linear(acts, "MemoryControllerPro0", "inAT3", ptrA, size * sizeof(uint32_t));
  113. max_memctl_linear(acts, "MemoryControllerPro0", "inBT3", ptrB, size * sizeof(uint32_t));
  114. max_queue_output(acts, "outCT3", ptrC, size * sizeof(uint32_t));
  115. max_run(engine, acts);
  116. max_actions_free(acts);
  117. printf("T3 finished\n");
  118. }
  119. static struct starpu_codelet cl3 =
  120. {
  121. .fpga_funcs = {fpga_impl3},
  122. .nbuffers = 3,
  123. .modes = {STARPU_R, STARPU_R, STARPU_W},
  124. .specific_nodes = 1,
  125. .nodes = {STARPU_SPECIFIC_NODE_LOCAL, STARPU_SPECIFIC_NODE_LOCAL, STARPU_SPECIFIC_NODE_CPU},
  126. };
  127. int main(int argc, char **argv)
  128. {
  129. /* Enable profiling */
  130. starpu_profiling_status_set(1);
  131. struct starpu_conf conf;
  132. starpu_data_handle_t handle_a, handle_b, handle_ct1, handle_ct2, handle_c;
  133. int ret;
  134. int size=1234;
  135. maxfile = MyTasks_init();
  136. engine = max_load(maxfile, "*");
  137. starpu_conf_init(&conf);
  138. conf.sched_policy_name = "eager";
  139. conf.calibrate = 0;
  140. ret = starpu_initialize(&conf, &argc, &argv);
  141. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  142. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  143. int32_t a[SIZE];
  144. int32_t b[SIZE];
  145. int32_t c[SIZE];
  146. int i;
  147. for(i = 0; i < SIZE; ++i)
  148. {
  149. a[i] = random() % 100;
  150. b[i] = random() % 100;
  151. }
  152. starpu_vector_data_register(&handle_a, STARPU_MAIN_RAM, (uintptr_t) &a, SIZE, sizeof(a[0]));
  153. starpu_vector_data_register(&handle_b, STARPU_MAIN_RAM, (uintptr_t) &b, SIZE, sizeof(b[0]));
  154. starpu_vector_data_register(&handle_ct1, -1, 0, SIZE, sizeof(c[0]));
  155. starpu_vector_data_register(&handle_ct2, -1, 0, SIZE, sizeof(c[0]));
  156. starpu_vector_data_register(&handle_c, STARPU_MAIN_RAM, (uintptr_t) &c, SIZE, sizeof(c[0]));
  157. ret = starpu_task_insert(&cl1, STARPU_R, handle_a, STARPU_R, handle_b, STARPU_W, handle_ct1, 0);
  158. fprintf(stderr,"task submitted %d\n", ret);
  159. ret = starpu_task_insert(&cl2, STARPU_R, handle_ct1, STARPU_R, handle_ct1, STARPU_W, handle_ct2, 0);
  160. fprintf(stderr,"task submitted %d\n", ret);
  161. ret = starpu_task_insert(&cl3, STARPU_R, handle_ct2, STARPU_R, handle_ct2, STARPU_W, handle_c, 0);
  162. fprintf(stderr,"task submitted %d\n", ret);
  163. starpu_data_unregister(handle_a);
  164. starpu_data_unregister(handle_b);
  165. starpu_data_unregister(handle_c);
  166. ret = EXIT_SUCCESS;
  167. for (i = 0; i < SIZE; ++i)
  168. {
  169. int ct1 = a[i] + b[i];
  170. int ct2 = ct1 * ct1;
  171. int ct3 = ct2 + ct2;
  172. if (c[i] != ct3)
  173. ret = EXIT_FAILURE;
  174. if (i < 10)
  175. {
  176. printf("%d == %d\n", c[i], ct3);
  177. if (c[i] != ct3)
  178. printf("OOOPS\n");
  179. }
  180. }
  181. starpu_shutdown();
  182. if (ret == EXIT_SUCCESS)
  183. printf("OK!\n");
  184. max_unload(engine);
  185. return ret;
  186. }