1*38fd1498Szrj /* OpenACC Runtime Library: CUDA support glue.
2*38fd1498Szrj
3*38fd1498Szrj Copyright (C) 2014-2018 Free Software Foundation, Inc.
4*38fd1498Szrj
5*38fd1498Szrj Contributed by Mentor Embedded.
6*38fd1498Szrj
7*38fd1498Szrj This file is part of the GNU Offloading and Multi Processing Library
8*38fd1498Szrj (libgomp).
9*38fd1498Szrj
10*38fd1498Szrj Libgomp is free software; you can redistribute it and/or modify it
11*38fd1498Szrj under the terms of the GNU General Public License as published by
12*38fd1498Szrj the Free Software Foundation; either version 3, or (at your option)
13*38fd1498Szrj any later version.
14*38fd1498Szrj
15*38fd1498Szrj Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
16*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17*38fd1498Szrj FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18*38fd1498Szrj more details.
19*38fd1498Szrj
20*38fd1498Szrj Under Section 7 of GPL version 3, you are granted additional
21*38fd1498Szrj permissions described in the GCC Runtime Library Exception, version
22*38fd1498Szrj 3.1, as published by the Free Software Foundation.
23*38fd1498Szrj
24*38fd1498Szrj You should have received a copy of the GNU General Public License and
25*38fd1498Szrj a copy of the GCC Runtime Library Exception along with this program;
26*38fd1498Szrj see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
27*38fd1498Szrj <http://www.gnu.org/licenses/>. */
28*38fd1498Szrj
29*38fd1498Szrj #include "openacc.h"
30*38fd1498Szrj #include "config.h"
31*38fd1498Szrj #include "libgomp.h"
32*38fd1498Szrj #include "oacc-int.h"
33*38fd1498Szrj
34*38fd1498Szrj void *
acc_get_current_cuda_device(void)35*38fd1498Szrj acc_get_current_cuda_device (void)
36*38fd1498Szrj {
37*38fd1498Szrj struct goacc_thread *thr = goacc_thread ();
38*38fd1498Szrj
39*38fd1498Szrj if (thr && thr->dev && thr->dev->openacc.cuda.get_current_device_func)
40*38fd1498Szrj return thr->dev->openacc.cuda.get_current_device_func ();
41*38fd1498Szrj
42*38fd1498Szrj return NULL;
43*38fd1498Szrj }
44*38fd1498Szrj
45*38fd1498Szrj void *
acc_get_current_cuda_context(void)46*38fd1498Szrj acc_get_current_cuda_context (void)
47*38fd1498Szrj {
48*38fd1498Szrj struct goacc_thread *thr = goacc_thread ();
49*38fd1498Szrj
50*38fd1498Szrj if (thr && thr->dev && thr->dev->openacc.cuda.get_current_context_func)
51*38fd1498Szrj return thr->dev->openacc.cuda.get_current_context_func ();
52*38fd1498Szrj
53*38fd1498Szrj return NULL;
54*38fd1498Szrj }
55*38fd1498Szrj
56*38fd1498Szrj void *
acc_get_cuda_stream(int async)57*38fd1498Szrj acc_get_cuda_stream (int async)
58*38fd1498Szrj {
59*38fd1498Szrj struct goacc_thread *thr = goacc_thread ();
60*38fd1498Szrj
61*38fd1498Szrj if (async < 0)
62*38fd1498Szrj return NULL;
63*38fd1498Szrj
64*38fd1498Szrj if (thr && thr->dev && thr->dev->openacc.cuda.get_stream_func)
65*38fd1498Szrj return thr->dev->openacc.cuda.get_stream_func (async);
66*38fd1498Szrj
67*38fd1498Szrj return NULL;
68*38fd1498Szrj }
69*38fd1498Szrj
70*38fd1498Szrj int
acc_set_cuda_stream(int async,void * stream)71*38fd1498Szrj acc_set_cuda_stream (int async, void *stream)
72*38fd1498Szrj {
73*38fd1498Szrj struct goacc_thread *thr;
74*38fd1498Szrj
75*38fd1498Szrj if (async < 0 || stream == NULL)
76*38fd1498Szrj return 0;
77*38fd1498Szrj
78*38fd1498Szrj goacc_lazy_initialize ();
79*38fd1498Szrj
80*38fd1498Szrj thr = goacc_thread ();
81*38fd1498Szrj
82*38fd1498Szrj if (thr && thr->dev && thr->dev->openacc.cuda.set_stream_func)
83*38fd1498Szrj return thr->dev->openacc.cuda.set_stream_func (async, stream);
84*38fd1498Szrj
85*38fd1498Szrj return -1;
86*38fd1498Szrj }
87