max_fpga_simple.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. 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. int size = STARPU_VECTOR_GET_NX(buffers[0]);
  31. // XXX: would rather use a scratch buffer
  32. size_t ptrCT1 = 0x00000000000000c0;
  33. size_t ptrAT2 = ptrCT1;
  34. size_t ptrBT2 = ptrCT1;
  35. size_t ptrCT2 = 0x0000000000000180;
  36. size_t ptrAT3 = ptrCT2;
  37. size_t ptrBT3 = ptrCT2;
  38. printf("Loading DFE memory.\n");
  39. /* C = A+B */
  40. MyTasks_interfaceT1(size, ptrCT1, ptrA, ptrB);
  41. printf("T1 finished\n");
  42. /* C = A*B */
  43. MyTasks_interfaceT2(size, ptrAT2, ptrBT2, ptrCT2);
  44. printf("T2 finished\n");
  45. /* C = A+B */
  46. MyTasks_interfaceT3(size, ptrAT3, ptrBT3, ptrC);
  47. printf("T3 finished\n");
  48. printf("Running DFE.\n");
  49. }
  50. static struct starpu_codelet cl =
  51. {
  52. .fpga_funcs = {fpga_impl},
  53. .nbuffers = 3,
  54. .modes = {STARPU_R, STARPU_R, STARPU_W},
  55. .specific_nodes = 1,
  56. .nodes = {STARPU_SPECIFIC_NODE_CPU, STARPU_SPECIFIC_NODE_CPU, STARPU_SPECIFIC_NODE_CPU},
  57. };
  58. void fpga_impl1(void *buffers[], void *cl_arg)
  59. {
  60. (void)cl_arg;
  61. int32_t *ptrA = (int32_t*) STARPU_VECTOR_GET_PTR(buffers[0]);
  62. int32_t *ptrB = (int32_t*) STARPU_VECTOR_GET_PTR(buffers[1]);
  63. size_t ptrC = (size_t) STARPU_VECTOR_GET_PTR(buffers[2]); /* FPGA */
  64. int size = STARPU_VECTOR_GET_NX(buffers[0]);
  65. printf("T1 with %p %p %zu\n", ptrA, ptrB, ptrC);
  66. /* C = A+B */
  67. MyTasks_interfaceT1(size, ptrC, ptrA, ptrB);
  68. printf("T1 finished\n");
  69. }
  70. static struct starpu_codelet cl1 =
  71. {
  72. .fpga_funcs = {fpga_impl1},
  73. .nbuffers = 3,
  74. .modes = {STARPU_R, STARPU_R, STARPU_W},
  75. .specific_nodes = 1,
  76. .nodes = {STARPU_SPECIFIC_NODE_CPU, STARPU_SPECIFIC_NODE_CPU, STARPU_SPECIFIC_NODE_LOCAL},
  77. };
  78. void fpga_impl2(void *buffers[], void *cl_arg)
  79. {
  80. (void)cl_arg;
  81. size_t ptrA = (size_t) STARPU_VECTOR_GET_PTR(buffers[0]); /* FPGA */
  82. size_t ptrB = (size_t) STARPU_VECTOR_GET_PTR(buffers[1]); /* FPGA */
  83. size_t ptrC = (size_t) STARPU_VECTOR_GET_PTR(buffers[2]); /* FPGA */
  84. int size = STARPU_VECTOR_GET_NX(buffers[0]);
  85. printf("T2 with %zu %zu %zu\n", ptrA, ptrB, ptrC);
  86. /* C = A*B */
  87. MyTasks_interfaceT2(size, ptrA, ptrB, ptrC);
  88. printf("T2 finished\n");
  89. }
  90. static struct starpu_codelet cl2 =
  91. {
  92. .fpga_funcs = {fpga_impl2},
  93. .nbuffers = 3,
  94. .modes = {STARPU_R, STARPU_R, STARPU_W}
  95. /* local by default */
  96. };
  97. void fpga_impl3(void *buffers[], void *cl_arg)
  98. {
  99. (void)cl_arg;
  100. size_t ptrA = (size_t) STARPU_VECTOR_GET_PTR(buffers[0]); /* FPGA */
  101. size_t ptrB = (size_t) STARPU_VECTOR_GET_PTR(buffers[1]); /* FPGA */
  102. int32_t *ptrC = (int32_t*) STARPU_VECTOR_GET_PTR(buffers[2]);
  103. int size = STARPU_VECTOR_GET_NX(buffers[0]);
  104. printf("T3 with %zu %zu %p\n", ptrA, ptrB, ptrC);
  105. /* C = A+B */
  106. MyTasks_interfaceT3(size, ptrA, ptrB, ptrC);
  107. printf("T3 finished\n");
  108. }
  109. static struct starpu_codelet cl3 =
  110. {
  111. .fpga_funcs = {fpga_impl3},
  112. .nbuffers = 3,
  113. .modes = {STARPU_R, STARPU_R, STARPU_W},
  114. .specific_nodes = 1,
  115. .nodes = {STARPU_SPECIFIC_NODE_LOCAL, STARPU_SPECIFIC_NODE_LOCAL, STARPU_SPECIFIC_NODE_CPU},
  116. };
  117. int main(int argc, char **argv)
  118. {
  119. /* Enable profiling */
  120. starpu_profiling_status_set(1);
  121. struct starpu_conf conf;
  122. starpu_data_handle_t handle_a, handle_b, handle_ct1, handle_ct2, handle_c;
  123. int ret;
  124. int size=1234;
  125. starpu_conf_init(&conf);
  126. conf.sched_policy_name = "eager";
  127. conf.calibrate = 0;
  128. ret = starpu_initialize(&conf, &argc, &argv);
  129. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  130. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  131. int32_t a[SIZE];
  132. int32_t b[SIZE];
  133. int32_t c[SIZE];
  134. int i;
  135. for(i = 0; i < SIZE; ++i)
  136. {
  137. a[i] = random() % 100;
  138. b[i] = random() % 100;
  139. }
  140. starpu_vector_data_register(&handle_a, STARPU_MAIN_RAM, (uintptr_t) &a, SIZE, sizeof(a[0]));
  141. starpu_vector_data_register(&handle_b, STARPU_MAIN_RAM, (uintptr_t) &b, SIZE, sizeof(b[0]));
  142. starpu_vector_data_register(&handle_ct1, -1, 0, SIZE, sizeof(c[0]));
  143. starpu_vector_data_register(&handle_ct2, -1, 0, SIZE, sizeof(c[0]));
  144. starpu_vector_data_register(&handle_c, STARPU_MAIN_RAM, (uintptr_t) &c, SIZE, sizeof(c[0]));
  145. #if 0
  146. ret = starpu_task_insert(&cl, STARPU_R, handle_a, STARPU_R, handle_b, STARPU_W, handle_c, STARPU_TASK_SYNCHRONOUS, 1, 0);
  147. fprintf(stderr,"task submitted %d\n", ret);
  148. #else
  149. ret = starpu_task_insert(&cl1, STARPU_R, handle_a, STARPU_R, handle_b, STARPU_W, handle_ct1, 0);
  150. fprintf(stderr,"task submitted %d\n", ret);
  151. ret = starpu_task_insert(&cl2, STARPU_R, handle_ct1, STARPU_R, handle_ct1, STARPU_W, handle_ct2, 0);
  152. fprintf(stderr,"task submitted %d\n", ret);
  153. ret = starpu_task_insert(&cl3, STARPU_R, handle_ct2, STARPU_R, handle_ct2, STARPU_W, handle_c, 0);
  154. fprintf(stderr,"task submitted %d\n", ret);
  155. #endif
  156. starpu_data_unregister(handle_a);
  157. starpu_data_unregister(handle_b);
  158. starpu_data_unregister(handle_c);
  159. ret = EXIT_SUCCESS;
  160. for (i = 0; i < SIZE; ++i)
  161. {
  162. int ct1 = a[i] + b[i];
  163. int ct2 = ct1 * ct1;
  164. int ct3 = ct2 + ct2;
  165. if (c[i] != ct3)
  166. ret = EXIT_FAILURE;
  167. if (i < 10)
  168. {
  169. printf("%d == %d\n", c[i], ct3);
  170. if (c[i] != ct3)
  171. printf("OOOPS\n");
  172. }
  173. }
  174. starpu_shutdown();
  175. if (ret == EXIT_SUCCESS)
  176. printf("OK!\n");
  177. return ret;
  178. }