marshalling.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015 ONERA
  4. * Copyright (C) 2015 Inria
  5. * Copyright (C) 2015 CNRS
  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. /* Helper functions to initialize StarPU and register element matrices */
  19. #include <starpu.h>
  20. //--------------------------------------------------------------//
  21. void starpu_register_element_c(int Neq_max,int Np, int Ng,double **ro, double **dro,
  22. double **basis, void **ro_h, void **dro_h, void **basis_h)
  23. {
  24. starpu_data_handle_t ro_handle;
  25. starpu_data_handle_t dro_handle;
  26. starpu_data_handle_t basis_handle;
  27. starpu_matrix_data_register(&ro_handle, 0,
  28. (uintptr_t)ro,Neq_max,Neq_max,Np, sizeof(double));
  29. starpu_matrix_data_register(&dro_handle, 0,
  30. (uintptr_t)dro,Neq_max,Neq_max,Np, sizeof(double));
  31. starpu_matrix_data_register(&basis_handle, 0,
  32. (uintptr_t)basis,Np,Np,Ng, sizeof(double));
  33. *ro_h = ro_handle;
  34. *dro_h = dro_handle;
  35. *basis_h = basis_handle;
  36. }
  37. void starpu_unregister_element_c(void **ro_h, void **dro_h, void **basis_h)
  38. {
  39. starpu_data_handle_t ro_handle = *ro_h;
  40. starpu_data_handle_t dro_handle = *dro_h;
  41. starpu_data_handle_t basis_handle = *basis_h;
  42. starpu_data_unregister(ro_handle);
  43. starpu_data_unregister(dro_handle);
  44. starpu_data_unregister(basis_handle);
  45. }
  46. //--------------------------------------------------------------//
  47. void loop_element_cpu_fortran(double coeff, int Neq_max, int Np, int Ng, void *ro_ptr, void *dro_ptr, void *basis_ptr, void *cl_arg);
  48. void loop_element_cpu_func(void *buffers[], void *cl_arg);
  49. struct starpu_codelet cl_loop_element =
  50. {
  51. .where = STARPU_CPU,
  52. .cpu_funcs = {loop_element_cpu_func, NULL},
  53. .nbuffers = 3,
  54. .modes = {STARPU_R,STARPU_RW,STARPU_R},
  55. .name = "LOOP_ELEMENT"
  56. };
  57. void loop_element_cpu_func(void *buffers[], void *cl_arg)
  58. {
  59. double coeff;
  60. double **ro = (double **) STARPU_MATRIX_GET_PTR(buffers[0]);
  61. int Neq_max = STARPU_MATRIX_GET_NX(buffers[0]);
  62. double **dro = (double **) STARPU_MATRIX_GET_PTR(buffers[1]);
  63. double **basis = (double **) STARPU_MATRIX_GET_PTR(buffers[2]);
  64. int Np = STARPU_MATRIX_GET_NX(buffers[2]);
  65. int Ng = STARPU_MATRIX_GET_NY(buffers[2]);
  66. starpu_codelet_unpack_args(cl_arg, &coeff);
  67. void *ro_ptr = &ro;
  68. void *dro_ptr = &dro;
  69. void *basis_ptr = &basis;
  70. loop_element_cpu_fortran(coeff,Neq_max,Np,Ng,
  71. ro_ptr,dro_ptr,basis_ptr,cl_arg);
  72. }
  73. void starpu_loop_element_task_c(double coeff, void **ro_h, void **dro_h, void **basis_h)
  74. {
  75. int ret;
  76. starpu_data_handle_t ro_handle = *ro_h;
  77. starpu_data_handle_t dro_handle = *dro_h;
  78. starpu_data_handle_t basis_handle = *basis_h;
  79. /* execute the task on any eligible computational ressource */
  80. ret = starpu_task_insert(&cl_loop_element,
  81. STARPU_VALUE, &coeff, sizeof(double),
  82. STARPU_R, ro_handle,
  83. STARPU_RW, dro_handle,
  84. STARPU_R, basis_handle,
  85. 0);
  86. /* verification */
  87. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  88. }
  89. //--------------------------------------------------------------//
  90. void copy_element_cpu_fortran(int Neq_max, int Np, void *ro_ptr, void *dro_ptr);
  91. void copy_element_cpu_func(void *buffers[], void *cl_arg);
  92. struct starpu_codelet cl_copy_element =
  93. {
  94. .where = STARPU_CPU,
  95. .cpu_funcs = {copy_element_cpu_func, NULL},
  96. .nbuffers = 2,
  97. .modes = {STARPU_RW,STARPU_R},
  98. .name = "COPY_ELEMENT"
  99. };
  100. void copy_element_cpu_func(void *buffers[], void *cl_arg)
  101. {
  102. double **ro = (double **) STARPU_MATRIX_GET_PTR(buffers[0]);
  103. int Neq_max = STARPU_MATRIX_GET_NX(buffers[0]);
  104. int Np = STARPU_MATRIX_GET_NY(buffers[0]);
  105. double **dro = (double **) STARPU_MATRIX_GET_PTR(buffers[1]);
  106. void *ro_ptr = &ro;
  107. void *dro_ptr = &dro;
  108. copy_element_cpu_fortran(Neq_max,Np,ro_ptr,dro_ptr);
  109. }
  110. void starpu_copy_element_task_c(void **ro_h, void **dro_h)
  111. {
  112. int ret;
  113. starpu_data_handle_t ro_handle = *ro_h;
  114. starpu_data_handle_t dro_handle = *dro_h;
  115. /* execute the task on any eligible computational ressource */
  116. ret = starpu_insert_task(&cl_copy_element,
  117. STARPU_RW, ro_handle,
  118. STARPU_R, dro_handle,
  119. 0);
  120. /* verification */
  121. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  122. }
  123. //--------------------------------------------------------------//
  124. int starpu_my_init_c()
  125. {
  126. /* Initialize StarPU with default configuration */
  127. int ret;
  128. struct starpu_conf conf;
  129. starpu_conf_init(&conf);
  130. conf.sched_policy_name = "dmda";
  131. ret = starpu_init(&conf);
  132. /* int ret = starpu_init(NULL); */
  133. return ret;
  134. }