marshalling.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015 ONERA
  4. * Copyright (C) 2015 Inria
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. //--------------------------------------------------------------//
  19. void starpu_register_element_c(int Neq_max,int Np, int Ng,double **ro, double **dro,
  20. double **basis, void **ro_h, void **dro_h, void **basis_h){
  21. starpu_data_handle_t ro_handle;
  22. starpu_data_handle_t dro_handle;
  23. starpu_data_handle_t basis_handle;
  24. starpu_matrix_data_register(&ro_handle, 0,
  25. (uintptr_t)ro,Neq_max,Neq_max,Np, sizeof(double));
  26. starpu_matrix_data_register(&dro_handle, 0,
  27. (uintptr_t)dro,Neq_max,Neq_max,Np, sizeof(double));
  28. starpu_matrix_data_register(&basis_handle, 0,
  29. (uintptr_t)basis,Np,Np,Ng, sizeof(double));
  30. *ro_h = ro_handle;
  31. *dro_h = dro_handle;
  32. *basis_h = basis_handle;
  33. }
  34. void starpu_unregister_element_c(void **ro_h, void **dro_h, void **basis_h){
  35. starpu_data_handle_t ro_handle = *ro_h;
  36. starpu_data_handle_t dro_handle = *dro_h;
  37. starpu_data_handle_t basis_handle = *basis_h;
  38. starpu_data_unregister(ro_handle);
  39. starpu_data_unregister(dro_handle);
  40. starpu_data_unregister(basis_handle);
  41. }
  42. //--------------------------------------------------------------//
  43. void loop_element_cpu_fortran(double coeff, int Neq_max, int Np,
  44. int Ng, void *ro_ptr, void *dro_ptr, void *basis_ptr, void *cl_arg);
  45. void loop_element_cpu_func(void *buffers[], void *cl_arg);
  46. struct starpu_codelet cl_loop_element =
  47. {
  48. .where = STARPU_CPU,
  49. .cpu_funcs = {loop_element_cpu_func, NULL},
  50. .nbuffers = 3,
  51. .modes = {STARPU_R,STARPU_RW,STARPU_R},
  52. .name = "LOOP_ELEMENT"
  53. };
  54. void loop_element_cpu_func(void *buffers[], void *cl_arg)
  55. {
  56. double coeff;
  57. double **ro = (double **) STARPU_MATRIX_GET_PTR(buffers[0]);
  58. int Neq_max = STARPU_MATRIX_GET_NX(buffers[0]);
  59. double **dro = (double **) STARPU_MATRIX_GET_PTR(buffers[1]);
  60. double **basis = (double **) STARPU_MATRIX_GET_PTR(buffers[2]);
  61. int Np = STARPU_MATRIX_GET_NX(buffers[2]);
  62. int Ng = STARPU_MATRIX_GET_NY(buffers[2]);
  63. starpu_codelet_unpack_args(cl_arg, &coeff);
  64. void *ro_ptr = &ro;
  65. void *dro_ptr = &dro;
  66. void *basis_ptr = &basis;
  67. loop_element_cpu_fortran(coeff,Neq_max,Np,Ng,
  68. ro_ptr,dro_ptr,basis_ptr,cl_arg);
  69. }
  70. void starpu_loop_element_task_c(double coeff, void **ro_h, void **dro_h, void **basis_h)
  71. {
  72. int ret;
  73. starpu_data_handle_t ro_handle = *ro_h;
  74. starpu_data_handle_t dro_handle = *dro_h;
  75. starpu_data_handle_t basis_handle = *basis_h;
  76. struct starpu_task *task = starpu_task_create();
  77. /* execute the task on any eligible computational ressource */
  78. ret = starpu_insert_task(&cl_loop_element,
  79. STARPU_VALUE, &coeff, sizeof(double),
  80. STARPU_R, ro_handle,
  81. STARPU_RW, dro_handle,
  82. STARPU_R, basis_handle,
  83. 0);
  84. /* verification */
  85. if (ret != -ENODEV) STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  86. }
  87. //--------------------------------------------------------------//
  88. void copy_element_cpu_fortran(int Neq_max, int Np,
  89. 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. struct starpu_task *task = starpu_task_create();
  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. if (ret != -ENODEV) STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  122. }
  123. //--------------------------------------------------------------//
  124. int starpu_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. if (ret == -ENODEV) goto enodev;
  134. return ret;
  135. enodev:
  136. return 77;
  137. }