plugin-host.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /* OpenACC Runtime Library: acc_device_host, acc_device_host_nonshm.
  2. Copyright (C) 2013-2015 Free Software Foundation, Inc.
  3. Contributed by Mentor Embedded.
  4. This file is part of the GNU Offloading and Multi Processing Library
  5. (libgomp).
  6. Libgomp is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3, or (at your option)
  9. any later version.
  10. Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. more details.
  14. Under Section 7 of GPL version 3, you are granted additional
  15. permissions described in the GCC Runtime Library Exception, version
  16. 3.1, as published by the Free Software Foundation.
  17. You should have received a copy of the GNU General Public License and
  18. a copy of the GCC Runtime Library Exception along with this program;
  19. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  20. <http://www.gnu.org/licenses/>. */
  21. /* Simple implementation of support routines for a shared-memory
  22. acc_device_host, and a non-shared memory acc_device_host_nonshm, with the
  23. latter built as a plugin. */
  24. #include "openacc.h"
  25. #include "config.h"
  26. #ifdef HOST_NONSHM_PLUGIN
  27. #include "libgomp-plugin.h"
  28. #include "oacc-plugin.h"
  29. #else
  30. #include "libgomp.h"
  31. #include "oacc-int.h"
  32. #endif
  33. #include <stdint.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include <stdio.h>
  37. #include <stdbool.h>
  38. #ifdef HOST_NONSHM_PLUGIN
  39. #define STATIC
  40. #define GOMP(X) GOMP_PLUGIN_##X
  41. #define SELF "host_nonshm plugin: "
  42. #else
  43. #define STATIC static
  44. #define GOMP(X) gomp_##X
  45. #define SELF "host: "
  46. #endif
  47. #ifdef HOST_NONSHM_PLUGIN
  48. #include "plugin-host.h"
  49. #endif
  50. STATIC const char *
  51. GOMP_OFFLOAD_get_name (void)
  52. {
  53. #ifdef HOST_NONSHM_PLUGIN
  54. return "host_nonshm";
  55. #else
  56. return "host";
  57. #endif
  58. }
  59. STATIC unsigned int
  60. GOMP_OFFLOAD_get_caps (void)
  61. {
  62. unsigned int caps = (GOMP_OFFLOAD_CAP_OPENACC_200
  63. | GOMP_OFFLOAD_CAP_NATIVE_EXEC);
  64. #ifndef HOST_NONSHM_PLUGIN
  65. caps |= GOMP_OFFLOAD_CAP_SHARED_MEM;
  66. #endif
  67. return caps;
  68. }
  69. STATIC int
  70. GOMP_OFFLOAD_get_type (void)
  71. {
  72. #ifdef HOST_NONSHM_PLUGIN
  73. return OFFLOAD_TARGET_TYPE_HOST_NONSHM;
  74. #else
  75. return OFFLOAD_TARGET_TYPE_HOST;
  76. #endif
  77. }
  78. STATIC int
  79. GOMP_OFFLOAD_get_num_devices (void)
  80. {
  81. return 1;
  82. }
  83. STATIC void
  84. GOMP_OFFLOAD_init_device (int n __attribute__ ((unused)))
  85. {
  86. }
  87. STATIC void
  88. GOMP_OFFLOAD_fini_device (int n __attribute__ ((unused)))
  89. {
  90. }
  91. STATIC int
  92. GOMP_OFFLOAD_load_image (int n __attribute__ ((unused)),
  93. void *i __attribute__ ((unused)),
  94. struct addr_pair **r __attribute__ ((unused)))
  95. {
  96. return 0;
  97. }
  98. STATIC void
  99. GOMP_OFFLOAD_unload_image (int n __attribute__ ((unused)),
  100. void *i __attribute__ ((unused)))
  101. {
  102. }
  103. STATIC void *
  104. GOMP_OFFLOAD_alloc (int n __attribute__ ((unused)), size_t s)
  105. {
  106. return GOMP (malloc) (s);
  107. }
  108. STATIC void
  109. GOMP_OFFLOAD_free (int n __attribute__ ((unused)), void *p)
  110. {
  111. free (p);
  112. }
  113. STATIC void *
  114. GOMP_OFFLOAD_host2dev (int n __attribute__ ((unused)), void *d, const void *h,
  115. size_t s)
  116. {
  117. #ifdef HOST_NONSHM_PLUGIN
  118. memcpy (d, h, s);
  119. #endif
  120. return 0;
  121. }
  122. STATIC void *
  123. GOMP_OFFLOAD_dev2host (int n __attribute__ ((unused)), void *h, const void *d,
  124. size_t s)
  125. {
  126. #ifdef HOST_NONSHM_PLUGIN
  127. memcpy (h, d, s);
  128. #endif
  129. return 0;
  130. }
  131. STATIC void
  132. GOMP_OFFLOAD_run (int n __attribute__ ((unused)), void *fn_ptr, void *vars)
  133. {
  134. void (*fn)(void *) = (void (*)(void *)) fn_ptr;
  135. fn (vars);
  136. }
  137. STATIC void
  138. GOMP_OFFLOAD_openacc_parallel (void (*fn) (void *),
  139. size_t mapnum __attribute__ ((unused)),
  140. void **hostaddrs __attribute__ ((unused)),
  141. void **devaddrs __attribute__ ((unused)),
  142. size_t *sizes __attribute__ ((unused)),
  143. unsigned short *kinds __attribute__ ((unused)),
  144. int num_gangs __attribute__ ((unused)),
  145. int num_workers __attribute__ ((unused)),
  146. int vector_length __attribute__ ((unused)),
  147. int async __attribute__ ((unused)),
  148. void *targ_mem_desc __attribute__ ((unused)))
  149. {
  150. #ifdef HOST_NONSHM_PLUGIN
  151. struct nonshm_thread *thd = GOMP_PLUGIN_acc_thread ();
  152. thd->nonshm_exec = true;
  153. fn (devaddrs);
  154. thd->nonshm_exec = false;
  155. #else
  156. fn (hostaddrs);
  157. #endif
  158. }
  159. STATIC void
  160. GOMP_OFFLOAD_openacc_register_async_cleanup (void *targ_mem_desc)
  161. {
  162. #ifdef HOST_NONSHM_PLUGIN
  163. /* "Asynchronous" launches are executed synchronously on the (non-SHM) host,
  164. so there's no point in delaying host-side cleanup -- just do it now. */
  165. GOMP_PLUGIN_async_unmap_vars (targ_mem_desc);
  166. #endif
  167. }
  168. STATIC void
  169. GOMP_OFFLOAD_openacc_async_set_async (int async __attribute__ ((unused)))
  170. {
  171. }
  172. STATIC int
  173. GOMP_OFFLOAD_openacc_async_test (int async __attribute__ ((unused)))
  174. {
  175. return 1;
  176. }
  177. STATIC int
  178. GOMP_OFFLOAD_openacc_async_test_all (void)
  179. {
  180. return 1;
  181. }
  182. STATIC void
  183. GOMP_OFFLOAD_openacc_async_wait (int async __attribute__ ((unused)))
  184. {
  185. }
  186. STATIC void
  187. GOMP_OFFLOAD_openacc_async_wait_all (void)
  188. {
  189. }
  190. STATIC void
  191. GOMP_OFFLOAD_openacc_async_wait_async (int async1 __attribute__ ((unused)),
  192. int async2 __attribute__ ((unused)))
  193. {
  194. }
  195. STATIC void
  196. GOMP_OFFLOAD_openacc_async_wait_all_async (int async __attribute__ ((unused)))
  197. {
  198. }
  199. STATIC void *
  200. GOMP_OFFLOAD_openacc_create_thread_data (int ord
  201. __attribute__ ((unused)))
  202. {
  203. #ifdef HOST_NONSHM_PLUGIN
  204. struct nonshm_thread *thd
  205. = GOMP_PLUGIN_malloc (sizeof (struct nonshm_thread));
  206. thd->nonshm_exec = false;
  207. return thd;
  208. #else
  209. return NULL;
  210. #endif
  211. }
  212. STATIC void
  213. GOMP_OFFLOAD_openacc_destroy_thread_data (void *tls_data)
  214. {
  215. #ifdef HOST_NONSHM_PLUGIN
  216. free (tls_data);
  217. #endif
  218. }