Hi Chung-Lin, Tom! It's been a while: On 2018-09-25T21:11:58+0800, Chung-Lin Tang wrote: > [...] NVPTX/CUDA-specific implementation > of the new-style goacc_asyncqueues. In an OpenACC 'async' setting, where the device kernel (expectedly) crashes because of "an illegal memory access was encountered", I'm running into a deadlock here: > --- a/libgomp/plugin/plugin-nvptx.c > +++ b/libgomp/plugin/plugin-nvptx.c > +static void > +cuda_callback_wrapper (CUstream stream, CUresult res, void *ptr) > +{ > + if (res != CUDA_SUCCESS) > + GOMP_PLUGIN_fatal ("%s error: %s", __FUNCTION__, cuda_error (res)); > + struct nvptx_callback *cb = (struct nvptx_callback *) ptr; > + cb->fn (cb->ptr); > + free (ptr); > +} > + > +void > +GOMP_OFFLOAD_openacc_async_queue_callback (struct goacc_asyncqueue *aq, > + void (*callback_fn)(void *), > + void *userptr) > +{ > + struct nvptx_callback *b = GOMP_PLUGIN_malloc (sizeof (*b)); > + b->fn = callback_fn; > + b->ptr = userptr; > + b->aq = aq; > + CUDA_CALL_ASSERT (cuStreamAddCallback, aq->cuda_stream, > + cuda_callback_wrapper, (void *) b, 0); > +} In my case, 'cuda_callback_wrapper' (expectedly) gets invoked with 'res != CUDA_SUCCESS' ("an illegal memory access was encountered"). When we invoke 'GOMP_PLUGIN_fatal', this attempts to shut down the device (..., which deadlocks); that's generally problematic: per "'cuStreamAddCallback' [...] Callbacks must not make any CUDA API calls". Given that eventually we must reach a host/device synchronization point (latest when the device is shut down at program termination), and the non-'CUDA_SUCCESS' will be upheld until then, it does seem safe to replace this 'GOMP_PLUGIN_fatal' with 'GOMP_PLUGIN_error' as per the "nvptx: Avoid deadlock in 'cuStreamAddCallback' callback, error case" attached. OK to push? (Might we even skip 'GOMP_PLUGIN_error' here, understanding that the error will be caught and reported at the next host/device synchronization point? But I've not verified that.) Grüße Thomas ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955