1 /* OpenACC Runtime initialization routines
3 Copyright (C) 2013-2020 Free Software Foundation, Inc.
5 Contributed by Mentor Embedded.
7 This file is part of the GNU Offloading and Multi Processing Library
10 Libgomp is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3, or (at your option)
15 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20 Under Section 7 of GPL version 3, you are granted additional
21 permissions described in the GCC Runtime Library Exception, version
22 3.1, as published by the Free Software Foundation.
24 You should have received a copy of the GNU General Public License and
25 a copy of the GCC Runtime Library Exception along with this program;
26 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
27 <http://www.gnu.org/licenses/>. */
38 /* This lock is used to protect access to cached_base_dev, dispatchers and
39 the (abstract) initialisation state of attached offloading devices. */
41 static gomp_mutex_t acc_device_lock
;
43 /* A cached version of the dispatcher for the global "current" accelerator type,
44 e.g. used as the default when creating new host threads. This is the
45 device-type equivalent of goacc_device_num (which specifies which device to
46 use out of potentially several of the same type). If there are several
47 devices of a given type, this points at the first one. */
49 static struct gomp_device_descr
*cached_base_dev
= NULL
;
51 #if defined HAVE_TLS || defined USE_EMUTLS
52 __thread
struct goacc_thread
*goacc_tls_data
;
54 pthread_key_t goacc_tls_key
;
56 static pthread_key_t goacc_cleanup_key
;
58 static struct goacc_thread
*goacc_threads
;
59 static gomp_mutex_t goacc_thread_lock
;
61 /* An array of dispatchers for device types, indexed by the type. This array
62 only references "base" devices, and other instances of the same type are
63 found by simply indexing from each such device (which are stored linearly,
64 grouped by device in target.c:devices). */
65 static struct gomp_device_descr
*dispatchers
[_ACC_device_hwm
] = { 0 };
68 goacc_register (struct gomp_device_descr
*disp
)
70 /* Only register the 0th device here. */
71 if (disp
->target_id
!= 0)
74 gomp_mutex_lock (&acc_device_lock
);
76 assert (acc_device_type (disp
->type
) != acc_device_none
77 && acc_device_type (disp
->type
) != acc_device_default
78 && acc_device_type (disp
->type
) != acc_device_not_host
);
79 assert (!dispatchers
[disp
->type
]);
80 dispatchers
[disp
->type
] = disp
;
82 gomp_mutex_unlock (&acc_device_lock
);
86 known_device_type_p (acc_device_t d
)
88 return d
>= 0 && d
< _ACC_device_hwm
;
92 unknown_device_type_error (acc_device_t invalid_type
)
94 gomp_fatal ("unknown device type %u", invalid_type
);
97 /* OpenACC names some things a little differently. */
100 get_openacc_name (const char *name
)
102 if (strcmp (name
, "nvptx") == 0)
109 name_of_acc_device_t (enum acc_device_t type
)
113 case acc_device_none
: return "none";
114 case acc_device_default
: return "default";
115 case acc_device_host
: return "host";
116 case acc_device_not_host
: return "not_host";
117 case acc_device_nvidia
: return "nvidia";
118 case acc_device_radeon
: return "radeon";
119 default: unknown_device_type_error (type
);
121 __builtin_unreachable ();
124 /* ACC_DEVICE_LOCK must be held before calling this function. If FAIL_IS_ERROR
125 is true, this function raises an error if there are no devices of type D,
126 otherwise it returns NULL in that case. */
128 static struct gomp_device_descr
*
129 resolve_device (acc_device_t d
, bool fail_is_error
)
131 acc_device_t d_arg
= d
;
135 case acc_device_default
:
137 if (goacc_device_type
)
139 /* Lookup the named device. */
140 while (known_device_type_p (++d
))
142 && !strcasecmp (goacc_device_type
,
143 get_openacc_name (dispatchers
[d
]->name
))
144 && dispatchers
[d
]->get_num_devices_func () > 0)
149 gomp_mutex_unlock (&acc_device_lock
);
150 gomp_fatal ("device type %s not supported", goacc_device_type
);
156 /* No default device specified, so start scanning for any non-host
157 device that is available. */
158 d
= acc_device_not_host
;
162 case acc_device_not_host
:
163 /* Find the first available device after acc_device_not_host. */
164 while (known_device_type_p (++d
))
165 if (dispatchers
[d
] && dispatchers
[d
]->get_num_devices_func () > 0)
167 if (d_arg
== acc_device_default
)
174 gomp_mutex_unlock (&acc_device_lock
);
175 gomp_fatal ("no device found");
181 case acc_device_host
:
185 if (!known_device_type_p (d
))
188 goto unsupported_device
;
196 assert (d
!= acc_device_none
197 && d
!= acc_device_default
198 && d
!= acc_device_not_host
);
200 if (dispatchers
[d
] == NULL
&& fail_is_error
)
203 gomp_mutex_unlock (&acc_device_lock
);
204 gomp_fatal ("device type %s not supported", name_of_acc_device_t (d
));
207 return dispatchers
[d
];
210 /* Emit a suitable error if no device of a particular type is available, or
211 the given device number is out-of-range. */
213 acc_dev_num_out_of_range (acc_device_t d
, int ord
, int ndevs
)
216 gomp_fatal ("no devices of type %s available", name_of_acc_device_t (d
));
218 gomp_fatal ("device %u out of range", ord
);
221 /* This is called when plugins have been initialized, and serves to call
222 (indirectly) the target's device_init hook. Calling multiple times without
223 an intervening acc_shutdown_1 call is an error. ACC_DEVICE_LOCK must be
224 held before calling this function. */
226 static struct gomp_device_descr
*
227 acc_init_1 (acc_device_t d
, acc_construct_t parent_construct
, int implicit
)
229 bool check_not_nested_p
;
232 /* In the implicit case, there should (TODO: must?) already be something
233 have been set up for an outer construct. */
234 check_not_nested_p
= false;
238 check_not_nested_p
= true;
239 /* TODO: should we set 'thr->prof_info' etc. in this case ('acc_init')?
240 The problem is, that we don't have 'thr' yet? (So,
241 'check_not_nested_p = true' also is pointless actually.) */
243 bool profiling_p
= GOACC_PROFILING_DISPATCH_P (check_not_nested_p
);
245 acc_prof_info prof_info
;
248 prof_info
.event_type
= acc_ev_device_init_start
;
249 prof_info
.valid_bytes
= _ACC_PROF_INFO_VALID_BYTES
;
250 prof_info
.version
= _ACC_PROF_INFO_VERSION
;
251 prof_info
.device_type
= d
;
252 prof_info
.device_number
= goacc_device_num
;
253 prof_info
.thread_id
= -1;
254 prof_info
.async
= acc_async_sync
;
255 prof_info
.async_queue
= prof_info
.async
;
256 prof_info
.src_file
= NULL
;
257 prof_info
.func_name
= NULL
;
258 prof_info
.line_no
= -1;
259 prof_info
.end_line_no
= -1;
260 prof_info
.func_line_no
= -1;
261 prof_info
.func_end_line_no
= -1;
263 acc_event_info device_init_event_info
;
266 device_init_event_info
.other_event
.event_type
= prof_info
.event_type
;
267 device_init_event_info
.other_event
.valid_bytes
268 = _ACC_OTHER_EVENT_INFO_VALID_BYTES
;
269 device_init_event_info
.other_event
.parent_construct
= parent_construct
;
270 device_init_event_info
.other_event
.implicit
= implicit
;
271 device_init_event_info
.other_event
.tool_info
= NULL
;
273 acc_api_info api_info
;
276 api_info
.device_api
= acc_device_api_none
;
277 api_info
.valid_bytes
= _ACC_API_INFO_VALID_BYTES
;
278 api_info
.device_type
= prof_info
.device_type
;
279 api_info
.vendor
= -1;
280 api_info
.device_handle
= NULL
;
281 api_info
.context_handle
= NULL
;
282 api_info
.async_handle
= NULL
;
286 goacc_profiling_dispatch (&prof_info
, &device_init_event_info
, &api_info
);
288 struct gomp_device_descr
*base_dev
, *acc_dev
;
291 base_dev
= resolve_device (d
, true);
293 ndevs
= base_dev
->get_num_devices_func ();
295 if (ndevs
<= 0 || goacc_device_num
>= ndevs
)
296 acc_dev_num_out_of_range (d
, goacc_device_num
, ndevs
);
298 acc_dev
= &base_dev
[goacc_device_num
];
300 gomp_mutex_lock (&acc_dev
->lock
);
301 if (acc_dev
->state
== GOMP_DEVICE_INITIALIZED
)
303 gomp_mutex_unlock (&acc_dev
->lock
);
304 gomp_fatal ("device already active");
307 gomp_init_device (acc_dev
);
308 gomp_mutex_unlock (&acc_dev
->lock
);
312 prof_info
.event_type
= acc_ev_device_init_end
;
313 device_init_event_info
.other_event
.event_type
= prof_info
.event_type
;
314 goacc_profiling_dispatch (&prof_info
, &device_init_event_info
,
321 /* ACC_DEVICE_LOCK must be held before calling this function. */
324 acc_shutdown_1 (acc_device_t d
)
326 struct gomp_device_descr
*base_dev
;
327 struct goacc_thread
*walk
;
329 bool devices_active
= false;
331 /* Get the base device for this device type. */
332 base_dev
= resolve_device (d
, true);
334 ndevs
= base_dev
->get_num_devices_func ();
336 /* Unload all the devices of this type that have been opened. */
337 for (i
= 0; i
< ndevs
; i
++)
339 struct gomp_device_descr
*acc_dev
= &base_dev
[i
];
341 gomp_mutex_lock (&acc_dev
->lock
);
342 gomp_unload_device (acc_dev
);
343 gomp_mutex_unlock (&acc_dev
->lock
);
346 gomp_mutex_lock (&goacc_thread_lock
);
348 /* Free target-specific TLS data and close all devices. */
349 for (walk
= goacc_threads
; walk
!= NULL
; walk
= walk
->next
)
351 if (walk
->target_tls
)
352 base_dev
->openacc
.destroy_thread_data_func (walk
->target_tls
);
354 walk
->target_tls
= NULL
;
356 /* This would mean the user is shutting down OpenACC in the middle of an
357 "acc data" pragma. Likely not intentional. */
358 if (walk
->mapped_data
)
360 gomp_mutex_unlock (&goacc_thread_lock
);
361 gomp_fatal ("shutdown in 'acc data' region");
364 /* Similarly, if this happens then user code has done something weird. */
365 if (walk
->saved_bound_dev
)
367 gomp_mutex_unlock (&goacc_thread_lock
);
368 gomp_fatal ("shutdown during host fallback");
373 gomp_mutex_lock (&walk
->dev
->lock
);
375 while (walk
->dev
->mem_map
.root
)
377 splay_tree_key k
= &walk
->dev
->mem_map
.root
->key
;
379 k
->aux
->link_key
= NULL
;
380 gomp_remove_var (walk
->dev
, k
);
383 gomp_mutex_unlock (&walk
->dev
->lock
);
386 walk
->base_dev
= NULL
;
390 gomp_mutex_unlock (&goacc_thread_lock
);
392 /* Close all the devices of this type that have been opened. */
394 for (i
= 0; i
< ndevs
; i
++)
396 struct gomp_device_descr
*acc_dev
= &base_dev
[i
];
397 gomp_mutex_lock (&acc_dev
->lock
);
398 if (acc_dev
->state
== GOMP_DEVICE_INITIALIZED
)
400 devices_active
= true;
401 ret
&= gomp_fini_device (acc_dev
);
402 acc_dev
->state
= GOMP_DEVICE_UNINITIALIZED
;
404 gomp_mutex_unlock (&acc_dev
->lock
);
408 gomp_fatal ("device finalization failed");
411 gomp_fatal ("no device initialized");
414 static struct goacc_thread
*
415 goacc_new_thread (void)
417 struct goacc_thread
*thr
= gomp_malloc (sizeof (struct goacc_thread
));
419 #if defined HAVE_TLS || defined USE_EMUTLS
420 goacc_tls_data
= thr
;
422 pthread_setspecific (goacc_tls_key
, thr
);
425 pthread_setspecific (goacc_cleanup_key
, thr
);
427 gomp_mutex_lock (&goacc_thread_lock
);
428 thr
->next
= goacc_threads
;
430 gomp_mutex_unlock (&goacc_thread_lock
);
436 goacc_destroy_thread (void *data
)
438 struct goacc_thread
*thr
= data
, *walk
, *prev
;
440 gomp_mutex_lock (&goacc_thread_lock
);
444 struct gomp_device_descr
*acc_dev
= thr
->dev
;
446 if (acc_dev
&& thr
->target_tls
)
448 acc_dev
->openacc
.destroy_thread_data_func (thr
->target_tls
);
449 thr
->target_tls
= NULL
;
452 assert (!thr
->mapped_data
);
454 /* Remove from thread list. */
455 for (prev
= NULL
, walk
= goacc_threads
; walk
;
456 prev
= walk
, walk
= walk
->next
)
460 goacc_threads
= walk
->next
;
462 prev
->next
= walk
->next
;
472 gomp_mutex_unlock (&goacc_thread_lock
);
475 /* Use the ORD'th device instance for the current host thread (or -1 for the
476 current global default). The device (and the runtime) must be initialised
477 before calling this function. */
480 goacc_attach_host_thread_to_device (int ord
)
482 struct goacc_thread
*thr
= goacc_thread ();
483 struct gomp_device_descr
*acc_dev
= NULL
, *base_dev
= NULL
;
486 if (thr
&& thr
->dev
&& (thr
->dev
->target_id
== ord
|| ord
< 0))
490 ord
= goacc_device_num
;
492 /* Decide which type of device to use. If the current thread has a device
493 type already (e.g. set by acc_set_device_type), use that, else use the
495 if (thr
&& thr
->base_dev
)
496 base_dev
= thr
->base_dev
;
499 assert (cached_base_dev
);
500 base_dev
= cached_base_dev
;
503 num_devices
= base_dev
->get_num_devices_func ();
504 if (num_devices
<= 0 || ord
>= num_devices
)
505 acc_dev_num_out_of_range (acc_device_type (base_dev
->type
), ord
,
509 thr
= goacc_new_thread ();
511 thr
->base_dev
= base_dev
;
512 thr
->dev
= acc_dev
= &base_dev
[ord
];
513 thr
->saved_bound_dev
= NULL
;
514 thr
->mapped_data
= NULL
;
515 thr
->prof_info
= NULL
;
516 thr
->api_info
= NULL
;
517 /* Initially, all callbacks for all events are enabled. */
518 thr
->prof_callbacks_enabled
= true;
521 = acc_dev
->openacc
.create_thread_data_func (ord
);
524 /* OpenACC 2.0a (3.2.12, 3.2.13) doesn't specify whether the serialization of
525 init/shutdown is per-process or per-thread. We choose per-process. */
528 acc_init (acc_device_t d
)
530 if (!known_device_type_p (d
))
531 unknown_device_type_error (d
);
533 gomp_init_targets_once ();
535 gomp_mutex_lock (&acc_device_lock
);
536 cached_base_dev
= acc_init_1 (d
, acc_construct_runtime_api
, 0);
537 gomp_mutex_unlock (&acc_device_lock
);
539 goacc_attach_host_thread_to_device (-1);
545 acc_shutdown (acc_device_t d
)
547 if (!known_device_type_p (d
))
548 unknown_device_type_error (d
);
550 gomp_init_targets_once ();
552 gomp_mutex_lock (&acc_device_lock
);
556 gomp_mutex_unlock (&acc_device_lock
);
559 ialias (acc_shutdown
)
562 acc_get_num_devices (acc_device_t d
)
564 if (!known_device_type_p (d
))
565 unknown_device_type_error (d
);
568 struct gomp_device_descr
*acc_dev
;
570 if (d
== acc_device_none
)
573 gomp_init_targets_once ();
575 gomp_mutex_lock (&acc_device_lock
);
576 acc_dev
= resolve_device (d
, false);
577 gomp_mutex_unlock (&acc_device_lock
);
582 n
= acc_dev
->get_num_devices_func ();
589 ialias (acc_get_num_devices
)
591 /* Set the device type for the current thread only (using the current global
592 default device number), initialising that device if necessary. Also set the
593 default device type for new threads to D. */
596 acc_set_device_type (acc_device_t d
)
598 if (!known_device_type_p (d
))
599 unknown_device_type_error (d
);
601 struct gomp_device_descr
*base_dev
, *acc_dev
;
602 struct goacc_thread
*thr
= goacc_thread ();
604 acc_prof_info prof_info
;
605 acc_api_info api_info
;
606 bool profiling_p
= GOACC_PROFILING_SETUP_P (thr
, &prof_info
, &api_info
);
608 prof_info
.device_type
= d
;
610 gomp_init_targets_once ();
612 gomp_mutex_lock (&acc_device_lock
);
614 cached_base_dev
= base_dev
= resolve_device (d
, true);
615 acc_dev
= &base_dev
[goacc_device_num
];
617 gomp_mutex_lock (&acc_dev
->lock
);
618 if (acc_dev
->state
== GOMP_DEVICE_UNINITIALIZED
)
619 gomp_init_device (acc_dev
);
620 gomp_mutex_unlock (&acc_dev
->lock
);
622 gomp_mutex_unlock (&acc_device_lock
);
624 /* We're changing device type: invalidate the current thread's dev and
625 base_dev pointers. */
626 if (thr
&& thr
->base_dev
!= base_dev
)
628 thr
->base_dev
= thr
->dev
= NULL
;
629 if (thr
->mapped_data
)
630 gomp_fatal ("acc_set_device_type in 'acc data' region");
633 goacc_attach_host_thread_to_device (-1);
637 thr
->prof_info
= NULL
;
638 thr
->api_info
= NULL
;
642 ialias (acc_set_device_type
)
645 acc_get_device_type (void)
647 acc_device_t res
= acc_device_none
;
648 struct gomp_device_descr
*dev
;
649 struct goacc_thread
*thr
= goacc_thread ();
651 if (thr
&& thr
->base_dev
)
652 res
= acc_device_type (thr
->base_dev
->type
);
655 acc_prof_info prof_info
;
656 acc_api_info api_info
;
657 bool profiling_p
= GOACC_PROFILING_SETUP_P (thr
, &prof_info
, &api_info
);
659 gomp_init_targets_once ();
661 gomp_mutex_lock (&acc_device_lock
);
662 dev
= resolve_device (acc_device_default
, true);
663 gomp_mutex_unlock (&acc_device_lock
);
664 res
= acc_device_type (dev
->type
);
668 thr
->prof_info
= NULL
;
669 thr
->api_info
= NULL
;
673 assert (res
!= acc_device_default
674 && res
!= acc_device_not_host
675 && res
!= acc_device_current
);
680 ialias (acc_get_device_type
)
683 acc_get_device_num (acc_device_t d
)
685 if (!known_device_type_p (d
))
686 unknown_device_type_error (d
);
688 const struct gomp_device_descr
*dev
;
689 struct goacc_thread
*thr
= goacc_thread ();
691 acc_prof_info prof_info
;
692 acc_api_info api_info
;
693 bool profiling_p
= GOACC_PROFILING_SETUP_P (thr
, &prof_info
, &api_info
);
695 prof_info
.device_type
= d
;
697 gomp_init_targets_once ();
699 gomp_mutex_lock (&acc_device_lock
);
700 dev
= resolve_device (d
, true);
701 gomp_mutex_unlock (&acc_device_lock
);
705 thr
->prof_info
= NULL
;
706 thr
->api_info
= NULL
;
709 if (thr
&& thr
->base_dev
== dev
&& thr
->dev
)
710 return thr
->dev
->target_id
;
712 return goacc_device_num
;
715 ialias (acc_get_device_num
)
718 acc_set_device_num (int ord
, acc_device_t d
)
720 if (!known_device_type_p (d
))
721 unknown_device_type_error (d
);
723 struct gomp_device_descr
*base_dev
, *acc_dev
;
726 gomp_init_targets_once ();
729 ord
= goacc_device_num
;
732 /* Set whatever device is being used by the current host thread to use
733 device instance ORD. It's unclear if this is supposed to affect other
734 host threads too (OpenACC 2.0 (3.2.4) acc_set_device_num). */
735 goacc_attach_host_thread_to_device (ord
);
738 gomp_mutex_lock (&acc_device_lock
);
740 cached_base_dev
= base_dev
= resolve_device (d
, true);
742 num_devices
= base_dev
->get_num_devices_func ();
744 if (num_devices
<= 0 || ord
>= num_devices
)
745 acc_dev_num_out_of_range (d
, ord
, num_devices
);
747 acc_dev
= &base_dev
[ord
];
749 gomp_mutex_lock (&acc_dev
->lock
);
750 if (acc_dev
->state
== GOMP_DEVICE_UNINITIALIZED
)
751 gomp_init_device (acc_dev
);
752 gomp_mutex_unlock (&acc_dev
->lock
);
754 gomp_mutex_unlock (&acc_device_lock
);
756 goacc_attach_host_thread_to_device (ord
);
759 goacc_device_num
= ord
;
762 ialias (acc_set_device_num
)
764 static union goacc_property_value
765 get_property_any (int ord
, acc_device_t d
, acc_device_property_t prop
)
767 goacc_lazy_initialize ();
768 struct goacc_thread
*thr
= goacc_thread ();
770 if (d
== acc_device_current
&& thr
&& thr
->dev
)
771 return thr
->dev
->openacc
.get_property_func (thr
->dev
->target_id
, prop
);
773 gomp_mutex_lock (&acc_device_lock
);
775 struct gomp_device_descr
*dev
= resolve_device (d
, true);
777 int num_devices
= dev
->get_num_devices_func ();
779 if (num_devices
<= 0 || ord
>= num_devices
)
780 acc_dev_num_out_of_range (d
, ord
, num_devices
);
784 gomp_mutex_lock (&dev
->lock
);
785 if (dev
->state
== GOMP_DEVICE_UNINITIALIZED
)
786 gomp_init_device (dev
);
787 gomp_mutex_unlock (&dev
->lock
);
789 gomp_mutex_unlock (&acc_device_lock
);
793 return dev
->openacc
.get_property_func (dev
->target_id
, prop
);
797 acc_get_property (int ord
, acc_device_t d
, acc_device_property_t prop
)
799 if (!known_device_type_p (d
))
800 unknown_device_type_error(d
);
802 if (prop
& GOACC_PROPERTY_STRING_MASK
)
805 return get_property_any (ord
, d
, prop
).val
;
808 ialias (acc_get_property
)
811 acc_get_property_string (int ord
, acc_device_t d
, acc_device_property_t prop
)
813 if (!known_device_type_p (d
))
814 unknown_device_type_error(d
);
816 if (prop
& GOACC_PROPERTY_STRING_MASK
)
817 return get_property_any (ord
, d
, prop
).ptr
;
822 ialias (acc_get_property_string
)
824 /* For -O and higher, the compiler always attempts to expand acc_on_device, but
825 if the user disables the builtin, or calls it via a pointer, we'll need this
828 Compile this with optimization, so that the compiler expands
829 this, rather than generating infinitely recursive code.
831 The function just forwards its argument to __builtin_acc_on_device. It does
832 not verify that the argument is a valid acc_device_t enumeration value. */
834 int __attribute__ ((__optimize__ ("O2")))
835 acc_on_device (acc_device_t dev
)
837 return __builtin_acc_on_device (dev
);
840 ialias (acc_on_device
)
842 attribute_hidden
void
843 goacc_runtime_initialize (void)
845 gomp_mutex_init (&acc_device_lock
);
847 #if !(defined HAVE_TLS || defined USE_EMUTLS)
848 pthread_key_create (&goacc_tls_key
, NULL
);
851 pthread_key_create (&goacc_cleanup_key
, goacc_destroy_thread
);
853 cached_base_dev
= NULL
;
855 goacc_threads
= NULL
;
856 gomp_mutex_init (&goacc_thread_lock
);
858 /* Initialize and register the 'host' device type. */
862 static void __attribute__((destructor
))
863 goacc_runtime_deinitialize (void)
865 #if !(defined HAVE_TLS || defined USE_EMUTLS)
866 pthread_key_delete (goacc_tls_key
);
868 pthread_key_delete (goacc_cleanup_key
);
871 /* Compiler helper functions */
873 attribute_hidden
void
874 goacc_save_and_set_bind (acc_device_t d
)
876 struct goacc_thread
*thr
= goacc_thread ();
878 assert (!thr
->saved_bound_dev
);
880 thr
->saved_bound_dev
= thr
->dev
;
881 thr
->dev
= dispatchers
[d
];
884 attribute_hidden
void
885 goacc_restore_bind (void)
887 struct goacc_thread
*thr
= goacc_thread ();
889 thr
->dev
= thr
->saved_bound_dev
;
890 thr
->saved_bound_dev
= NULL
;
893 /* This is called from any OpenACC support function that may need to implicitly
894 initialize the libgomp runtime, either globally or from a new host thread.
895 On exit "goacc_thread" will return a valid & populated thread block. */
897 attribute_hidden
void
898 goacc_lazy_initialize (void)
900 struct goacc_thread
*thr
= goacc_thread ();
905 gomp_init_targets_once ();
907 gomp_mutex_lock (&acc_device_lock
);
908 if (!cached_base_dev
)
909 cached_base_dev
= acc_init_1 (acc_device_default
,
910 acc_construct_parallel
, 1);
911 gomp_mutex_unlock (&acc_device_lock
);
913 goacc_attach_host_thread_to_device (-1);