Hi Julian! On Tue, 19 May 2015 11:36:58 +0100, Julian Brown <jul...@codesourcery.com> wrote: > This patch fixes an oversight whereby if the CUDA libraries are > available for some reason on a system that doesn't actually contain an > nVidia card, an OpenACC program will raise an error if the NVPTX > backend is picked as a default instead of falling back to some other > device instead.
Thanks for fixing this! (Has already been committed to trunk in r223352, and to gomp-4_0-branch in r223351.) Your patch: > --- a/libgomp/plugin/plugin-nvptx.c > +++ b/libgomp/plugin/plugin-nvptx.c > @@ -781,7 +781,13 @@ nvptx_get_num_devices (void) > until cuInit has been called. Just call it now (but don't yet do any > further initialization). */ > if (instantiated_devices == 0) > - cuInit (0); > + { > + r = cuInit (0); > + /* This is not an error: e.g. we may have CUDA libraries installed but > + no devices available. */ > + if (r != CUDA_SUCCESS) > + return 0; > + } > > r = cuDeviceGetCount (&n); > if (r!= CUDA_SUCCESS) In early March, I had noticed the same problem, and came up with the following patch -- but :-( unfortunately never got around to pushing it upstream. I'm now posting my patch just for completeness; I think yours is sufficient/better: no safe-guard should be needed to the cuInit call in nvptx_init, because when that is called, we're rightfully expecting to be able to initialize a PTX device, and in nvptx_get_num_devices, yours is "more conservative" in doing the right thing ("no PTX offloading device available") for all kinds of cuInit errors. commit 6032dde185d0d45d779a1bbf0a5baee7131c0b8c Author: Thomas Schwinge <tho...@codesourcery.com> Date: Sun Mar 1 14:36:02 2015 +0100 libgomp nvptx plugin: Gracefully handle CUDA_ERROR_NO_DEVICE. --- libgomp/plugin/plugin-nvptx.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git libgomp/plugin/plugin-nvptx.c libgomp/plugin/plugin-nvptx.c index 78e705f..0c1e826 100644 --- libgomp/plugin/plugin-nvptx.c +++ libgomp/plugin/plugin-nvptx.c @@ -592,6 +592,8 @@ nvptx_init (void) return -1; r = cuInit (0); + if (r == CUDA_ERROR_NO_DEVICE) + r = CUDA_SUCCESS; if (r != CUDA_SUCCESS) GOMP_PLUGIN_fatal ("cuInit error: %s", cuda_error (r)); @@ -715,7 +717,13 @@ nvptx_get_num_devices (void) until cuInit has been called. Just call it now (but don't yet do any further initialization). */ if (!ptx_inited) - cuInit (0); + { + r = cuInit (0); + if (r == CUDA_ERROR_NO_DEVICE) + return 0; + if (r != CUDA_SUCCESS) + GOMP_PLUGIN_fatal ("cuInit error: %s", cuda_error (r)); + } r = cuDeviceGetCount (&n); if (r!= CUDA_SUCCESS) Grüße, Thomas
signature.asc
Description: PGP signature