oacc-cuda.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* OpenACC Runtime Library: CUDA support glue.
  2. Copyright (C) 2014-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. #include "openacc.h"
  22. #include "config.h"
  23. #include "libgomp.h"
  24. #include "oacc-int.h"
  25. void *
  26. acc_get_current_cuda_device (void)
  27. {
  28. struct goacc_thread *thr = goacc_thread ();
  29. if (thr && thr->dev && thr->dev->openacc.cuda.get_current_device_func)
  30. return thr->dev->openacc.cuda.get_current_device_func ();
  31. return NULL;
  32. }
  33. void *
  34. acc_get_current_cuda_context (void)
  35. {
  36. struct goacc_thread *thr = goacc_thread ();
  37. if (thr && thr->dev && thr->dev->openacc.cuda.get_current_context_func)
  38. return thr->dev->openacc.cuda.get_current_context_func ();
  39. return NULL;
  40. }
  41. void *
  42. acc_get_cuda_stream (int async)
  43. {
  44. struct goacc_thread *thr = goacc_thread ();
  45. if (async < 0)
  46. return NULL;
  47. if (thr && thr->dev && thr->dev->openacc.cuda.get_stream_func)
  48. return thr->dev->openacc.cuda.get_stream_func (async);
  49. return NULL;
  50. }
  51. int
  52. acc_set_cuda_stream (int async, void *stream)
  53. {
  54. struct goacc_thread *thr;
  55. if (async < 0 || stream == NULL)
  56. return 0;
  57. goacc_lazy_initialize ();
  58. thr = goacc_thread ();
  59. if (thr && thr->dev && thr->dev->openacc.cuda.set_stream_func)
  60. return thr->dev->openacc.cuda.set_stream_func (async, stream);
  61. return -1;
  62. }