/* * cl-utils.c * * OpenCL utility functions * * Copyright © 2012-2021 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: * 2010-2020 Thomas White * * This file is part of CrystFEL. * * CrystFEL is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * CrystFEL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with CrystFEL. If not, see . * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #define CL_TARGET_OPENCL_VERSION 220 #ifdef HAVE_CL_CL_H #include #else #include #endif #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= num_devs ) { ERROR("Device ID out of range\n"); return 0; } if ( n < 0 ) { STATUS("Available devices:\n"); for ( i=0; i