lower-bitint: Fix up handle_operand_addr for 0 constants [PR112771]
[official-gcc.git] / libgomp / oacc-cuda.c
blob314b2da592d29074a80cc7d418b9f05b2efc24db
1 /* OpenACC Runtime Library: CUDA support glue.
3 Copyright (C) 2014-2023 Free Software Foundation, Inc.
5 Contributed by Mentor Embedded.
7 This file is part of the GNU Offloading and Multi Processing Library
8 (libgomp).
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)
13 any later version.
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
18 more details.
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/>. */
29 #include "openacc.h"
30 #include "libgomp.h"
31 #include "oacc-int.h"
32 #include <assert.h>
34 void *
35 acc_get_current_cuda_device (void)
37 struct goacc_thread *thr = goacc_thread ();
39 void *ret = NULL;
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 ();
48 if (profiling_p)
50 thr->prof_info = NULL;
51 thr->api_info = NULL;
55 return ret;
58 void *
59 acc_get_current_cuda_context (void)
61 struct goacc_thread *thr = goacc_thread ();
63 void *ret = NULL;
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 ();
72 if (profiling_p)
74 thr->prof_info = NULL;
75 thr->api_info = NULL;
79 return ret;
82 void *
83 acc_get_cuda_stream (int async)
85 struct goacc_thread *thr = goacc_thread ();
87 if (!async_valid_p (async))
88 return NULL;
90 void *ret = NULL;
91 if (thr && thr->dev && thr->dev->openacc.cuda.get_stream_func)
93 goacc_aq aq = lookup_goacc_asyncqueue (thr, false, async);
94 if (!aq)
95 return ret;
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);
100 if (profiling_p)
102 prof_info.async = async;
103 prof_info.async_queue = prof_info.async;
106 ret = thr->dev->openacc.cuda.get_stream_func (aq);
108 if (profiling_p)
110 thr->prof_info = NULL;
111 thr->api_info = NULL;
115 return ret;
119 acc_set_cuda_stream (int async, void *stream)
121 struct goacc_thread *thr;
123 if (!async_valid_p (async) || stream == NULL)
124 return 0;
126 goacc_lazy_initialize ();
128 thr = goacc_thread ();
130 int ret = -1;
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);
136 if (profiling_p)
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". */
145 if (!aq)
147 assert (async == acc_async_sync);
148 gomp_debug (0, "Refusing request to set CUDA stream associated"
149 " with \"acc_async_sync\"\n");
150 ret = 0;
151 goto out_prof;
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);
157 out_prof:
158 if (profiling_p)
160 thr->prof_info = NULL;
161 thr->api_info = NULL;
165 return ret;