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;
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");