From 8aff8c658925f0c7522555ff5907632bcafe4554 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 13 May 2019 15:41:54 +0200 Subject: gpu_sim_check: Succeed if GPU not available On recent OSes, OpenCL (the API) is always available, but a GPU device not always. Therefore, this test will always be built, and shouldn't fail just because a GPU isn't present. --- src/cl-utils.c | 38 ++++++++++++++++++++++++++++++++++++-- src/cl-utils.h | 11 +++++++++-- tests/gpu_sim_check.c | 10 ++++++++-- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/cl-utils.c b/src/cl-utils.c index fee2b53e..7c069ed1 100644 --- a/src/cl-utils.c +++ b/src/cl-utils.c @@ -3,11 +3,11 @@ * * OpenCL utility functions * - * Copyright © 2012-2018 Deutsches Elektronen-Synchrotron DESY, + * Copyright © 2012-2019 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: - * 2010-2018 Thomas White + * 2010-2019 Thomas White * * This file is part of CrystFEL. * @@ -43,6 +43,40 @@ #include "utils.h" +/* Return 1 if a GPU device is present, 0 if not, 2 on error. */ +int have_gpu_device() +{ + cl_uint nplat; + cl_platform_id platforms[8]; + cl_context_properties prop[3]; + cl_int err; + int i; + + err = clGetPlatformIDs(8, platforms, &nplat); + if ( err != CL_SUCCESS ) return 2; + if ( nplat == 0 ) return 0; + + /* Find a GPU platform in the list */ + for ( i=0; i + * 2010-2019 Thomas White * * This file is part of CrystFEL. * @@ -34,6 +34,13 @@ #endif +#ifdef HAVE_CL_CL_H +#include +#else +#include +#endif + +extern int have_gpu_device(void); extern const char *clError(cl_int err); extern cl_device_id get_cl_dev(cl_context ctx, int n); extern cl_program load_program_from_string(const char *source_in, size_t len, diff --git a/tests/gpu_sim_check.c b/tests/gpu_sim_check.c index aee7a068..e42bc68b 100644 --- a/tests/gpu_sim_check.c +++ b/tests/gpu_sim_check.c @@ -3,11 +3,11 @@ * * Check that GPU simulation agrees with CPU version * - * Copyright © 2012-2015 Deutsches Elektronen-Synchrotron DESY, + * Copyright © 2012-2019 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: - * 2012-2015 Thomas White + * 2012-2019 Thomas White * * This file is part of CrystFEL. * @@ -42,6 +42,7 @@ #include "../src/diffraction.h" #include "../src/diffraction-gpu.h" +#include "../src/cl-utils.h" #include #include #include @@ -90,6 +91,11 @@ int main(int argc, char *argv[]) SymOpList *sym; gsl_rng *rng; + if ( have_gpu_device() == 0 ) { + ERROR("No GPU device found - skipping test.\n"); + return 0; + } + rng = gsl_rng_alloc(gsl_rng_mt19937); gctx = setup_gpu(1, NULL, NULL, NULL, 0); -- cgit v1.2.3