max_fpga.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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 "StreamFMA.h"
  22. #include "MaxSLiCInterface.h"
  23. #define SIZE (192/sizeof(int32_t))
  24. void fpga_impl(void *buffers[], void *cl_arg)
  25. {
  26. (void)cl_arg;
  27. int32_t *ptrA = (int32_t*) STARPU_VECTOR_GET_PTR(buffers[0]);
  28. int32_t *ptrB = (int32_t*) STARPU_VECTOR_GET_PTR(buffers[1]);
  29. int32_t *ptrC = (int32_t*) STARPU_VECTOR_GET_PTR(buffers[2]);
  30. int32_t *poubelle_cpu = malloc(SIZE * sizeof(int32_t));
  31. int size = STARPU_VECTOR_GET_NX(buffers[0]);
  32. int sizeBytes=SIZE *sizeof(int32_t);
  33. size_t LMemsize= SIZE *sizeof(int32_t);
  34. size_t poubelle = 0xc0000;
  35. size_t ptrCT1 = 0x00000000000000c0;
  36. size_t ptrAT2 = ptrCT1;
  37. size_t ptrBT2 = ptrCT1;
  38. size_t ptrCT2 = 0x0000000000000180;
  39. size_t ptrAT3 = ptrCT2;
  40. size_t ptrBT3 = ptrCT2;
  41. printf("Loading DFE memory.\n");
  42. /* C = A+B */
  43. StreamFMA(SIZE, ptrA, sizeBytes, ptrB, sizeBytes, poubelle_cpu, sizeBytes,
  44. poubelle, LMemsize,
  45. poubelle, LMemsize,
  46. poubelle, LMemsize,
  47. poubelle, LMemsize,
  48. ptrCT1, LMemsize,
  49. poubelle, LMemsize);
  50. printf("T1 finished\n");
  51. /* C = A*B */
  52. StreamFMA(SIZE, poubelle_cpu, sizeBytes, poubelle_cpu, sizeBytes, poubelle_cpu, sizeBytes,
  53. ptrAT2, LMemsize,
  54. poubelle, LMemsize,
  55. ptrBT2, LMemsize,
  56. poubelle, LMemsize,
  57. poubelle, LMemsize,
  58. ptrCT2, LMemsize);
  59. printf("T2 finished\n");
  60. /* C = A+B */
  61. StreamFMA(SIZE, poubelle_cpu, sizeBytes, poubelle_cpu, sizeBytes, ptrC, sizeBytes,
  62. poubelle, LMemsize,
  63. ptrAT3, LMemsize,
  64. poubelle, LMemsize,
  65. ptrBT3, LMemsize,
  66. poubelle, LMemsize,
  67. poubelle, LMemsize);
  68. printf("T3 finished\n");
  69. printf("Running DFE.\n");
  70. }
  71. static struct starpu_codelet cl =
  72. {
  73. .fpga_funcs = {fpga_impl},
  74. .nbuffers = 3,
  75. .modes = {STARPU_R, STARPU_R, STARPU_W}
  76. };
  77. void fpga_impl1(void *buffers[], void *cl_arg)
  78. {
  79. (void)cl_arg;
  80. int32_t *ptrA = (int32_t*) STARPU_VECTOR_GET_PTR(buffers[0]);
  81. int32_t *ptrB = (int32_t*) STARPU_VECTOR_GET_PTR(buffers[1]);
  82. size_t ptrC = (size_t) STARPU_VECTOR_GET_PTR(buffers[2]); /* FPGA */
  83. int32_t *poubelle_cpu = malloc(SIZE * sizeof(int32_t));
  84. int size = STARPU_VECTOR_GET_NX(buffers[0]);
  85. int sizeBytes=SIZE *sizeof(int32_t);
  86. size_t LMemsize= SIZE *sizeof(int32_t);
  87. size_t poubelle = 0xc0000;
  88. #if 0
  89. printf("T1 with %p %p %zu\n", ptrA, ptrB, ptrC);
  90. //XXX
  91. ptrC = 0x00000000000000c0;
  92. #endif
  93. printf("T1 with %p %p %zu\n", ptrA, ptrB, ptrC);
  94. /* C = A+B */
  95. StreamFMA(SIZE, ptrA, sizeBytes, ptrB, sizeBytes, poubelle_cpu, sizeBytes,
  96. poubelle, LMemsize,
  97. poubelle, LMemsize,
  98. poubelle, LMemsize,
  99. poubelle, LMemsize,
  100. ptrC, LMemsize,
  101. poubelle, LMemsize);
  102. printf("T1 finished\n");
  103. }
  104. static struct starpu_codelet cl1 =
  105. {
  106. .fpga_funcs = {fpga_impl1},
  107. .nbuffers = 3,
  108. .modes = {STARPU_R, STARPU_R, STARPU_W},
  109. .specific_nodes = 1,
  110. .nodes = {STARPU_SPECIFIC_NODE_CPU, STARPU_SPECIFIC_NODE_CPU, STARPU_SPECIFIC_NODE_LOCAL},
  111. };
  112. void fpga_impl2(void *buffers[], void *cl_arg)
  113. {
  114. (void)cl_arg;
  115. size_t ptrA = (size_t) STARPU_VECTOR_GET_PTR(buffers[0]); /* FPGA */
  116. size_t ptrB = (size_t) STARPU_VECTOR_GET_PTR(buffers[1]); /* FPGA */
  117. size_t ptrC = (size_t) STARPU_VECTOR_GET_PTR(buffers[2]); /* FPGA */
  118. int32_t *poubelle_cpu = malloc(SIZE * sizeof(int32_t));
  119. int size = STARPU_VECTOR_GET_NX(buffers[0]);
  120. int sizeBytes=SIZE *sizeof(int32_t);
  121. size_t LMemsize= SIZE *sizeof(int32_t);
  122. size_t poubelle = 0xc0000;
  123. #if 0
  124. printf("T2 with %zu %zu %zu\n", ptrA, ptrB, ptrC);
  125. //XXX
  126. ptrA = 0x00000000000000c0;
  127. ptrB = 0x00000000000000c0;
  128. ptrC = 0x0000000000000180;
  129. #endif
  130. printf("T2 with %zu %zu %zu\n", ptrA, ptrB, ptrC);
  131. /* C = A*B */
  132. StreamFMA(SIZE, poubelle_cpu, sizeBytes, poubelle_cpu, sizeBytes, poubelle_cpu, sizeBytes,
  133. ptrA, LMemsize,
  134. poubelle, LMemsize,
  135. ptrB, LMemsize,
  136. poubelle, LMemsize,
  137. poubelle, LMemsize,
  138. ptrC, LMemsize);
  139. printf("T2 finished\n");
  140. }
  141. static struct starpu_codelet cl2 =
  142. {
  143. .fpga_funcs = {fpga_impl2},
  144. .nbuffers = 3,
  145. .modes = {STARPU_R, STARPU_R, STARPU_W}
  146. /* local by default */
  147. };
  148. void fpga_impl3(void *buffers[], void *cl_arg)
  149. {
  150. (void)cl_arg;
  151. size_t ptrA = (size_t) STARPU_VECTOR_GET_PTR(buffers[0]); /* FPGA */
  152. size_t ptrB = (size_t) STARPU_VECTOR_GET_PTR(buffers[1]); /* FPGA */
  153. int32_t *ptrC = (int32_t*) STARPU_VECTOR_GET_PTR(buffers[2]);
  154. int32_t *poubelle_cpu = malloc(SIZE * sizeof(int32_t));
  155. int size = STARPU_VECTOR_GET_NX(buffers[0]);
  156. int sizeBytes=SIZE *sizeof(int32_t);
  157. size_t LMemsize= SIZE *sizeof(int32_t);
  158. size_t poubelle = 0xc0000;
  159. #if 0
  160. printf("T3 with %zu %zu %p\n", ptrA, ptrB, ptrC);
  161. //XXX
  162. ptrA = 0x0000000000000180;
  163. ptrB = 0x0000000000000180;
  164. #endif
  165. printf("T3 with %zu %zu %p\n", ptrA, ptrB, ptrC);
  166. /* C = A+B */
  167. StreamFMA(SIZE, poubelle_cpu, sizeBytes, poubelle_cpu, sizeBytes, ptrC, sizeBytes,
  168. poubelle, LMemsize,
  169. ptrA, LMemsize,
  170. poubelle, LMemsize,
  171. ptrB, LMemsize,
  172. poubelle, LMemsize,
  173. poubelle, LMemsize);
  174. printf("T3 finished\n");
  175. }
  176. static struct starpu_codelet cl3 =
  177. {
  178. .fpga_funcs = {fpga_impl3},
  179. .nbuffers = 3,
  180. .modes = {STARPU_R, STARPU_R, STARPU_W},
  181. .specific_nodes = 1,
  182. .nodes = {STARPU_SPECIFIC_NODE_LOCAL, STARPU_SPECIFIC_NODE_LOCAL, STARPU_SPECIFIC_NODE_CPU},
  183. };
  184. int main(int argc, char **argv)
  185. {
  186. /* Enable profiling */
  187. starpu_profiling_status_set(1);
  188. struct starpu_conf conf;
  189. starpu_data_handle_t handle_a, handle_b, handle_ct1, handle_ct2, handle_c;
  190. int ret;
  191. int size=1234;
  192. starpu_conf_init(&conf);
  193. conf.sched_policy_name = "eager";
  194. conf.calibrate = 0;
  195. ret = starpu_initialize(&conf, &argc, &argv);
  196. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  197. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  198. int32_t a[SIZE];
  199. int32_t b[SIZE];
  200. int32_t c[SIZE];
  201. int i;
  202. for(i = 0; i < SIZE; ++i)
  203. {
  204. a[i] = random() % 100;
  205. b[i] = random() % 100;
  206. }
  207. starpu_vector_data_register(&handle_a, STARPU_MAIN_RAM, (uintptr_t) &a, SIZE, sizeof(a[0]));
  208. starpu_vector_data_register(&handle_b, STARPU_MAIN_RAM, (uintptr_t) &b, SIZE, sizeof(b[0]));
  209. starpu_vector_data_register(&handle_ct1, -1, 0, SIZE, sizeof(c[0]));
  210. starpu_vector_data_register(&handle_ct2, -1, 0, SIZE, sizeof(c[0]));
  211. starpu_vector_data_register(&handle_c, STARPU_MAIN_RAM, (uintptr_t) &c, SIZE, sizeof(c[0]));
  212. #if 0
  213. ret = starpu_task_insert(&cl, STARPU_R, handle_a, STARPU_R, handle_b, STARPU_W, handle_c, STARPU_TASK_SYNCHRONOUS, 1, 0);
  214. fprintf(stderr,"task submitted %d\n", ret);
  215. #else
  216. ret = starpu_task_insert(&cl1, STARPU_R, handle_a, STARPU_R, handle_b, STARPU_W, handle_ct1, 0);
  217. fprintf(stderr,"task submitted %d\n", ret);
  218. ret = starpu_task_insert(&cl2, STARPU_R, handle_ct1, STARPU_R, handle_ct1, STARPU_W, handle_ct2, 0);
  219. fprintf(stderr,"task submitted %d\n", ret);
  220. ret = starpu_task_insert(&cl3, STARPU_R, handle_ct2, STARPU_R, handle_ct2, STARPU_W, handle_c, 0);
  221. fprintf(stderr,"task submitted %d\n", ret);
  222. #endif
  223. starpu_data_unregister(handle_a);
  224. starpu_data_unregister(handle_b);
  225. starpu_data_unregister(handle_c);
  226. ret = EXIT_SUCCESS;
  227. for (i = 0; i < SIZE; ++i)
  228. {
  229. int ct1 = a[i] + b[i];
  230. int ct2 = ct1 * ct1;
  231. int ct3 = ct2 + ct2;
  232. if (c[i] != ct3)
  233. ret = EXIT_FAILURE;
  234. if (i < 10)
  235. {
  236. printf("%d == %d\n", c[i], ct3);
  237. if (c[i] != ct3)
  238. printf("OOOPS\n");
  239. }
  240. }
  241. starpu_shutdown();
  242. if (ret == EXIT_SUCCESS)
  243. printf("OK!\n");
  244. return ret;
  245. }