marshalling.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. .cpu_funcs = {loop_element_cpu_func},
  52. .nbuffers = 3,
  53. .modes = {STARPU_R,STARPU_RW,STARPU_R},
  54. .name = "LOOP_ELEMENT"
  55. };
  56. void loop_element_cpu_func(void *buffers[], void *cl_arg)
  57. {
  58. double coeff;
  59. double **ro = (double **) STARPU_MATRIX_GET_PTR(buffers[0]);
  60. int Neq_max = STARPU_MATRIX_GET_NX(buffers[0]);
  61. double **dro = (double **) STARPU_MATRIX_GET_PTR(buffers[1]);
  62. double **basis = (double **) STARPU_MATRIX_GET_PTR(buffers[2]);
  63. int Np = STARPU_MATRIX_GET_NX(buffers[2]);
  64. int Ng = STARPU_MATRIX_GET_NY(buffers[2]);
  65. starpu_codelet_unpack_args(cl_arg, &coeff);
  66. void *ro_ptr = &ro;
  67. void *dro_ptr = &dro;
  68. void *basis_ptr = &basis;
  69. loop_element_cpu_fortran(coeff,Neq_max,Np,Ng,
  70. ro_ptr,dro_ptr,basis_ptr,cl_arg);
  71. }
  72. void starpu_loop_element_task_c(double coeff, void **ro_h, void **dro_h, void **basis_h)
  73. {
  74. int ret;
  75. starpu_data_handle_t ro_handle = *ro_h;
  76. starpu_data_handle_t dro_handle = *dro_h;
  77. starpu_data_handle_t basis_handle = *basis_h;
  78. /* execute the task on any eligible computational ressource */
  79. ret = starpu_task_insert(&cl_loop_element,
  80. STARPU_VALUE, &coeff, sizeof(double),
  81. STARPU_R, ro_handle,
  82. STARPU_RW, dro_handle,
  83. STARPU_R, basis_handle,
  84. 0);
  85. /* verification */
  86. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  87. }
  88. //--------------------------------------------------------------//
  89. void copy_element_cpu_fortran(int Neq_max, int Np, void *ro_ptr, void *dro_ptr);
  90. void copy_element_cpu_func(void *buffers[], void *cl_arg);
  91. struct starpu_codelet cl_copy_element =
  92. {
  93. .cpu_funcs = {copy_element_cpu_func},
  94. .nbuffers = 2,
  95. .modes = {STARPU_RW,STARPU_R},
  96. .name = "COPY_ELEMENT"
  97. };
  98. void copy_element_cpu_func(void *buffers[], void *cl_arg)
  99. {
  100. double **ro = (double **) STARPU_MATRIX_GET_PTR(buffers[0]);
  101. int Neq_max = STARPU_MATRIX_GET_NX(buffers[0]);
  102. int Np = STARPU_MATRIX_GET_NY(buffers[0]);
  103. double **dro = (double **) STARPU_MATRIX_GET_PTR(buffers[1]);
  104. void *ro_ptr = &ro;
  105. void *dro_ptr = &dro;
  106. copy_element_cpu_fortran(Neq_max,Np,ro_ptr,dro_ptr);
  107. }
  108. void starpu_copy_element_task_c(void **ro_h, void **dro_h)
  109. {
  110. int ret;
  111. starpu_data_handle_t ro_handle = *ro_h;
  112. starpu_data_handle_t dro_handle = *dro_h;
  113. /* execute the task on any eligible computational ressource */
  114. ret = starpu_insert_task(&cl_copy_element,
  115. STARPU_RW, ro_handle,
  116. STARPU_R, dro_handle,
  117. 0);
  118. /* verification */
  119. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  120. }
  121. //--------------------------------------------------------------//
  122. int starpu_my_init_c()
  123. {
  124. /* Initialize StarPU with default configuration */
  125. int ret;
  126. struct starpu_conf conf;
  127. starpu_conf_init(&conf);
  128. conf.sched_policy_name = "dmda";
  129. ret = starpu_init(&conf);
  130. /* int ret = starpu_init(NULL); */
  131. return ret;
  132. }