/* * Copyright 2018 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * */ // // // #include #include #include // // // #include "find_cl.h" #include "assert_cl.h" #include "../macros.h" // // search platforms and devices for a match // cl_int clFindIdsByName(char const * const target_platform_substring, char const * const target_device_substring, cl_platform_id * const platform_id, cl_device_id * const device_id, size_t const matched_device_name_size, char * const matched_device_name, size_t * const matched_device_name_size_ret, bool const is_verbose) { bool match_platform=false, match_device=false; // // get number of platforms // cl_uint platform_count; cl(GetPlatformIDs(0,NULL,&platform_count)); cl_platform_id * const platform_ids = ALLOCA_MACRO(sizeof(*platform_ids) * platform_count); cl(GetPlatformIDs(platform_count,platform_ids,NULL)); // // search platforms // for (cl_uint ii=0; ii= 1) matched_device_name[matched_device_name_size-1] = 0; if (matched_device_name_size > 1) { bytes = MIN_MACRO(device_name_size,matched_device_name_size-1); memcpy(matched_device_name,device_name,bytes); } if (matched_device_name_size_ret != NULL) *matched_device_name_size_ret = bytes; } if (is_verbose) { fprintf(stdout," >>>"); } } else if (is_verbose) { fprintf(stdout," "); } if (is_verbose) { fprintf(stdout, " %1u: %s [ %s ]\n", jj, device_name, driver_version); } } } if (is_verbose) { fprintf(stdout,"\n"); } // // get target platform and device // if (!match_platform) { if (is_verbose) fprintf(stderr,"no match for target platform substring %s\n",target_platform_substring); return CL_INVALID_PLATFORM; } if (!match_device) { if (is_verbose) fprintf(stderr,"no match for target device substring %s\n",target_device_substring); return CL_DEVICE_NOT_FOUND; } return CL_SUCCESS; } // // //