max_fpga.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013,2015,2017 CNRS
  4. * Copyright (C) 2010,2011,2013,2014,2016-2018 Université de Bordeaux
  5. * Copyright (C) 2012,2017 Inria
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. /*
  19. * Test using the specific_nodes field by forcing the data to main memory
  20. * even if the task is run on a GPU (and actually doing the computation from
  21. * the CPU driving the GPU). It mixes such accesses and normal accesses from
  22. * the GPU
  23. */
  24. #include <starpu.h>
  25. #include <stdlib.h>
  26. #include <unistd.h>
  27. #include <errno.h>
  28. #include <stdio.h>
  29. #include <starpu_scheduler.h>
  30. #include "../helper.h"
  31. #include "StreamFMA.h"
  32. #include "MaxSLiCInterface.h"
  33. #define SIZE 128
  34. static max_engine_t *engine ;
  35. static max_actions_t*act;
  36. static max_file_t *maxfile;
  37. void specific_kernel(void *descr[], void *arg)
  38. {
  39. (void)arg;
  40. int *a = (int*) STARPU_VECTOR_GET_PTR(descr[0]);
  41. int *b = (int*) STARPU_VECTOR_GET_PTR(descr[1]);
  42. int *c = (int*) STARPU_VECTOR_GET_PTR(descr[2]);
  43. int node = starpu_task_get_current_data_node(0);
  44. STARPU_ASSERT(node >= 0);
  45. STARPU_ASSERT(starpu_node_get_kind(node) == STARPU_CPU_RAM);
  46. unsigned *dataptr = (unsigned*) STARPU_VARIABLE_GET_PTR(descr[0]);
  47. // int i;
  48. // for (i = 0; i < size; i++)
  49. // c[i] = a[i]+b[i];
  50. if (node == STARPU_MAIN_RAM)
  51. STARPU_ASSERT(dataptr == &c);
  52. (*dataptr)++;
  53. }
  54. void fpga_mult(void *descr[], void *arg)
  55. {
  56. (void)arg;
  57. int *a = (int*) STARPU_VECTOR_GET_PTR(descr[0]);
  58. int *b = (int*) STARPU_VECTOR_GET_PTR(descr[1]);
  59. int *c = (int*) STARPU_VECTOR_GET_PTR(descr[2]);
  60. int size = STARPU_VECTOR_GET_NX(descr[0]);
  61. int node = starpu_task_get_current_data_node(2);
  62. if (node == STARPU_MAIN_RAM)
  63. {
  64. printf("hellooooo ...\n");
  65. }
  66. else {
  67. printf("byeee....\n");
  68. }
  69. //Actions to run on an engine
  70. act = max_actions_init(maxfile, NULL);
  71. //set the number of ticks for a kernel
  72. max_set_ticks (act, "StreamFMAKernel", size);
  73. max_queue_input(act, "a", a, size *sizeof(a[0]));
  74. max_queue_input(act, "b", b, size*sizeof(b[0]));
  75. max_queue_output(act,"output", c, size*sizeof(c[0]));
  76. //run actions on the engine
  77. printf("Running on DFE using dynamic interface ...\n");
  78. printf("**** Run actions in non blocking mode **** \n");
  79. //run actions in non_blocking mode
  80. max_run_t *run0= max_run_nonblock(engine, act);
  81. printf("*** wait for the actions on DFE to complete *** \n");
  82. //wait for the actions to complete
  83. max_wait(run0);
  84. }
  85. static struct starpu_codelet specific_cl =
  86. {
  87. .cpu_funcs = {specific_kernel},
  88. .fpga_funcs = {fpga_mult},
  89. .nbuffers = 3,
  90. .modes = {STARPU_R,STARPU_R, STARPU_W},
  91. .specific_nodes = 1,
  92. .nodes = {STARPU_SPECIFIC_NODE_CPU, STARPU_SPECIFIC_NODE_CPU, STARPU_SPECIFIC_NODE_LOCAL_OR_CPU},
  93. };
  94. int main(int argc, char **argv)
  95. {
  96. /* Enable profiling */
  97. starpu_profiling_status_set(1);
  98. struct starpu_conf conf;
  99. starpu_data_handle_t handle_a, handle_b, handle_c;
  100. int ret;
  101. int size=1234;
  102. starpu_conf_init(&conf);
  103. conf.sched_policy_name = "eager";
  104. conf.calibrate = 0;
  105. ret = starpu_initialize(&conf, &argc, &argv);
  106. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  107. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  108. //Implementation of a maxfile
  109. maxfile = StreamFMA_init();
  110. //Implementation of an engine
  111. engine = max_load(maxfile, "*");
  112. int a[SIZE];
  113. int b[SIZE];
  114. int c[SIZE];
  115. int i;
  116. for(i = 0; i < SIZE; ++i)
  117. {
  118. a[i] = random() % 100;
  119. b[i] = random() % 100;
  120. }
  121. starpu_vector_data_register(&handle_a, STARPU_MAIN_RAM, (uintptr_t) &a, SIZE, sizeof(int));
  122. starpu_vector_data_register(&handle_b, STARPU_MAIN_RAM, (uintptr_t) &b, SIZE, sizeof(int));
  123. starpu_vector_data_register(&handle_c, STARPU_MAIN_RAM, (uintptr_t) &c, SIZE, sizeof(int));
  124. struct starpu_task *task = starpu_task_create();
  125. task->cl = &specific_cl;
  126. task->handles[0] = handle_a;
  127. task->handles[1] = handle_b;
  128. task->handles[2] = handle_c;
  129. task->synchronous = 1;
  130. task->destroy = 0;
  131. ret = starpu_task_submit(task);
  132. fprintf(stderr,"task submitted %d\n", ret);
  133. starpu_data_unregister(handle_a);
  134. starpu_data_unregister(handle_b);
  135. starpu_data_unregister(handle_c);
  136. int mysize = SIZE;
  137. if (mysize > 10)
  138. mysize = 10;
  139. for (i = 0; i < mysize; ++i)
  140. {
  141. printf("%d == %d\n", c[i], a[i] + b[i]);
  142. }
  143. max_actions_free(act);
  144. //unload and deallocate an engine obtained by way of max_load
  145. max_unload(engine);
  146. starpu_shutdown();
  147. return EXIT_SUCCESS;
  148. }