max_fpga.c 8.0 KB

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