marshalling.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. #include <starpu.h>
  19. //--------------------------------------------------------------//
  20. void starpu_register_element_c(int Neq_max,int Np, int Ng,double **ro, double **dro,
  21. double **basis, void **ro_h, void **dro_h, void **basis_h)
  22. {
  23. starpu_data_handle_t ro_handle;
  24. starpu_data_handle_t dro_handle;
  25. starpu_data_handle_t basis_handle;
  26. starpu_matrix_data_register(&ro_handle, 0,
  27. (uintptr_t)ro,Neq_max,Neq_max,Np, sizeof(double));
  28. starpu_matrix_data_register(&dro_handle, 0,
  29. (uintptr_t)dro,Neq_max,Neq_max,Np, sizeof(double));
  30. starpu_matrix_data_register(&basis_handle, 0,
  31. (uintptr_t)basis,Np,Np,Ng, sizeof(double));
  32. *ro_h = ro_handle;
  33. *dro_h = dro_handle;
  34. *basis_h = basis_handle;
  35. }
  36. void starpu_unregister_element_c(void **ro_h, void **dro_h, void **basis_h)
  37. {
  38. starpu_data_handle_t ro_handle = *ro_h;
  39. starpu_data_handle_t dro_handle = *dro_h;
  40. starpu_data_handle_t basis_handle = *basis_h;
  41. starpu_data_unregister(ro_handle);
  42. starpu_data_unregister(dro_handle);
  43. starpu_data_unregister(basis_handle);
  44. }
  45. //--------------------------------------------------------------//
  46. 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);
  47. void loop_element_cpu_func(void *buffers[], void *cl_arg);
  48. struct starpu_codelet cl_loop_element =
  49. {
  50. .where = STARPU_CPU,
  51. .cpu_funcs = {loop_element_cpu_func, NULL},
  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. .where = STARPU_CPU,
  94. .cpu_funcs = {copy_element_cpu_func, NULL},
  95. .nbuffers = 2,
  96. .modes = {STARPU_RW,STARPU_R},
  97. .name = "COPY_ELEMENT"
  98. };
  99. void copy_element_cpu_func(void *buffers[], void *cl_arg)
  100. {
  101. double **ro = (double **) STARPU_MATRIX_GET_PTR(buffers[0]);
  102. int Neq_max = STARPU_MATRIX_GET_NX(buffers[0]);
  103. int Np = STARPU_MATRIX_GET_NY(buffers[0]);
  104. double **dro = (double **) STARPU_MATRIX_GET_PTR(buffers[1]);
  105. void *ro_ptr = &ro;
  106. void *dro_ptr = &dro;
  107. copy_element_cpu_fortran(Neq_max,Np,ro_ptr,dro_ptr);
  108. }
  109. void starpu_copy_element_task_c(void **ro_h, void **dro_h)
  110. {
  111. int ret;
  112. starpu_data_handle_t ro_handle = *ro_h;
  113. starpu_data_handle_t dro_handle = *dro_h;
  114. /* execute the task on any eligible computational ressource */
  115. ret = starpu_insert_task(&cl_copy_element,
  116. STARPU_RW, ro_handle,
  117. STARPU_R, dro_handle,
  118. 0);
  119. /* verification */
  120. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  121. }
  122. //--------------------------------------------------------------//
  123. int starpu_my_init_c()
  124. {
  125. /* Initialize StarPU with default configuration */
  126. int ret;
  127. struct starpu_conf conf;
  128. starpu_conf_init(&conf);
  129. conf.sched_policy_name = "dmda";
  130. ret = starpu_init(&conf);
  131. /* int ret = starpu_init(NULL); */
  132. if (ret == -ENODEV) goto enodev;
  133. return ret;
  134. enodev:
  135. return 77;
  136. }