diff options
author | Thomas White <taw@physics.org> | 2017-07-06 17:22:11 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2017-07-06 17:24:59 +0200 |
commit | 5292f57d4434c7267e8d945871513d742ff42427 (patch) | |
tree | d460aa5cef5a501516876850ef243cfc27313d5a /src/diffraction-gpu.c | |
parent | 48d4a6b8e82cce81222ec58fdfb488ed79ce0bcf (diff) | |
parent | dc3395900fc3ce0d3961757628ff83ad6456be19 (diff) |
Merge branch 'master' into taketwo
Diffstat (limited to 'src/diffraction-gpu.c')
-rw-r--r-- | src/diffraction-gpu.c | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/src/diffraction-gpu.c b/src/diffraction-gpu.c index 331170ae..22abcfd2 100644 --- a/src/diffraction-gpu.c +++ b/src/diffraction-gpu.c @@ -379,6 +379,7 @@ struct gpu_context *setup_gpu(int no_sfac, float *flags_ptr; size_t maxwgsize; int i; + int have_ctx = 0; char cflags[512] = ""; char *insert_stuff = NULL; @@ -393,16 +394,37 @@ struct gpu_context *setup_gpu(int no_sfac, ERROR("Couldn't find at least one platform!\n"); return NULL; } - prop[0] = CL_CONTEXT_PLATFORM; - prop[1] = (cl_context_properties)platforms[0]; - prop[2] = 0; - gctx = malloc(sizeof(*gctx)); - gctx->ctx = clCreateContextFromType(prop, CL_DEVICE_TYPE_GPU, - NULL, NULL, &err); - if ( err != CL_SUCCESS ) { - ERROR("Couldn't create OpenCL context: %i\n", err); - free(gctx); + /* Find a GPU platform in the list */ + for ( i=0; i<nplat; i++ ) { + + prop[0] = CL_CONTEXT_PLATFORM; + prop[1] = (cl_context_properties)platforms[i]; + prop[2] = 0; + + gctx = malloc(sizeof(*gctx)); + gctx->ctx = clCreateContextFromType(prop, CL_DEVICE_TYPE_GPU, + NULL, NULL, &err); + + if ( err != CL_SUCCESS ) { + if ( err == CL_DEVICE_NOT_FOUND ) { + /* No GPU device in this platform */ + continue; /* Try next platform */ + } else { + ERROR("Couldn't create OpenCL context: %s (%i)\n", + clError(err), err); + free(gctx); + return NULL; + } + } else { + STATUS("Using OpenCL platform %i (%i total)\n", i, nplat); + have_ctx = 1; + break; + } + } + + if ( !have_ctx ) { + ERROR("Couldn't find a GPU device in any platform.\n"); return NULL; } |