public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/c++-modules] libgomp: adjust nvptx_free callback context checking
@ 2020-08-28 15:57 Nathan Sidwell
0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2020-08-28 15:57 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:f9b9832837b65046a8f01c18597cf615ff61db40
commit f9b9832837b65046a8f01c18597cf615ff61db40
Author: Chung-Lin Tang <cltang@codesourcery.com>
Date: Thu Aug 20 07:18:51 2020 -0700
libgomp: adjust nvptx_free callback context checking
Change test for CUDA callback context in nvptx_free() from using
GOMP_PLUGIN_acc_thread () into checking for CUDA_ERROR_NOT_PERMITTED,
for the former only works for OpenACC, but not OpenMP offloading.
2020-08-20 Chung-Lin Tang <cltang@codesourcery.com>
libgomp/
* plugin/plugin-nvptx.c (nvptx_free):
Change "GOMP_PLUGIN_acc_thread () == NULL" test into check of
CUDA_ERROR_NOT_PERMITTED status for cuMemGetAddressRange. Adjust
comments.
Diff:
---
libgomp/plugin/plugin-nvptx.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c
index ec103a2f40b..390804ad1fa 100644
--- a/libgomp/plugin/plugin-nvptx.c
+++ b/libgomp/plugin/plugin-nvptx.c
@@ -1040,9 +1040,17 @@ goacc_profiling_acc_ev_free (struct goacc_thread *thr, void *p)
static bool
nvptx_free (void *p, struct ptx_device *ptx_dev)
{
- /* Assume callback context if this is null. */
- if (GOMP_PLUGIN_acc_thread () == NULL)
+ CUdeviceptr pb;
+ size_t ps;
+
+ CUresult r = CUDA_CALL_NOCHECK (cuMemGetAddressRange, &pb, &ps,
+ (CUdeviceptr) p);
+ if (r == CUDA_ERROR_NOT_PERMITTED)
{
+ /* We assume that this error indicates we are in a CUDA callback context,
+ where all CUDA calls are not allowed (see cuStreamAddCallback
+ documentation for description). Arrange to free this piece of device
+ memory later. */
struct ptx_free_block *n
= GOMP_PLUGIN_malloc (sizeof (struct ptx_free_block));
n->ptr = p;
@@ -1052,11 +1060,11 @@ nvptx_free (void *p, struct ptx_device *ptx_dev)
pthread_mutex_unlock (&ptx_dev->free_blocks_lock);
return true;
}
-
- CUdeviceptr pb;
- size_t ps;
-
- CUDA_CALL (cuMemGetAddressRange, &pb, &ps, (CUdeviceptr) p);
+ else if (r != CUDA_SUCCESS)
+ {
+ GOMP_PLUGIN_error ("cuMemGetAddressRange error: %s", cuda_error (r));
+ return false;
+ }
if ((CUdeviceptr) p != pb)
{
GOMP_PLUGIN_error ("invalid device address");
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-08-28 15:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-28 15:57 [gcc/devel/c++-modules] libgomp: adjust nvptx_free callback context checking Nathan Sidwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).