1 /* OpenACC Runtime Library: CUDA support glue.
3 Copyright (C) 2014-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/>. */
35 acc_get_current_cuda_device (void)
37 struct goacc_thread
*thr
= goacc_thread ();
40 if (thr
&& thr
->dev
&& thr
->dev
->openacc
.cuda
.get_current_device_func
)
42 acc_prof_info prof_info
;
43 acc_api_info api_info
;
44 bool profiling_p
= GOACC_PROFILING_SETUP_P (thr
, &prof_info
, &api_info
);
46 ret
= thr
->dev
->openacc
.cuda
.get_current_device_func ();
50 thr
->prof_info
= NULL
;
59 acc_get_current_cuda_context (void)
61 struct goacc_thread
*thr
= goacc_thread ();
64 if (thr
&& thr
->dev
&& thr
->dev
->openacc
.cuda
.get_current_context_func
)
66 acc_prof_info prof_info
;
67 acc_api_info api_info
;
68 bool profiling_p
= GOACC_PROFILING_SETUP_P (thr
, &prof_info
, &api_info
);
70 ret
= thr
->dev
->openacc
.cuda
.get_current_context_func ();
74 thr
->prof_info
= NULL
;
83 acc_get_cuda_stream (int async
)
85 struct goacc_thread
*thr
= goacc_thread ();
87 if (!async_valid_p (async
))
91 if (thr
&& thr
->dev
&& thr
->dev
->openacc
.cuda
.get_stream_func
)
93 goacc_aq aq
= lookup_goacc_asyncqueue (thr
, false, async
);
97 acc_prof_info prof_info
;
98 acc_api_info api_info
;
99 bool profiling_p
= GOACC_PROFILING_SETUP_P (thr
, &prof_info
, &api_info
);
102 prof_info
.async
= async
;
103 prof_info
.async_queue
= prof_info
.async
;
106 ret
= thr
->dev
->openacc
.cuda
.get_stream_func (aq
);
110 thr
->prof_info
= NULL
;
111 thr
->api_info
= NULL
;
119 acc_set_cuda_stream (int async
, void *stream
)
121 struct goacc_thread
*thr
;
123 if (!async_valid_p (async
) || stream
== NULL
)
126 goacc_lazy_initialize ();
128 thr
= goacc_thread ();
131 if (thr
&& thr
->dev
&& thr
->dev
->openacc
.cuda
.set_stream_func
)
133 acc_prof_info prof_info
;
134 acc_api_info api_info
;
135 bool profiling_p
= GOACC_PROFILING_SETUP_P (thr
, &prof_info
, &api_info
);
138 prof_info
.async
= async
;
139 prof_info
.async_queue
= prof_info
.async
;
142 goacc_aq aq
= get_goacc_asyncqueue (async
);
143 /* Due to not using an asyncqueue for "acc_async_sync", this cannot be
144 used to change the CUDA stream associated with "acc_async_sync". */
147 assert (async
== acc_async_sync
);
148 gomp_debug (0, "Refusing request to set CUDA stream associated"
149 " with \"acc_async_sync\"\n");
153 gomp_mutex_lock (&thr
->dev
->openacc
.async
.lock
);
154 ret
= thr
->dev
->openacc
.cuda
.set_stream_func (aq
, stream
);
155 gomp_mutex_unlock (&thr
->dev
->openacc
.async
.lock
);
160 thr
->prof_info
= NULL
;
161 thr
->api_info
= NULL
;