|
| 1 | +/* |
| 2 | +// Copyright (c) 2019-2020 Ben Ashbaugh |
| 3 | +// |
| 4 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | +// of this software and associated documentation files (the "Software"), to deal |
| 6 | +// in the Software without restriction, including without limitation the rights |
| 7 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | +// copies of the Software, and to permit persons to whom the Software is |
| 9 | +// furnished to do so, subject to the following conditions: |
| 10 | +// |
| 11 | +// The above copyright notice and this permission notice shall be included in all |
| 12 | +// copies or substantial portions of the Software. |
| 13 | +// |
| 14 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | +// SOFTWARE. |
| 21 | +*/ |
| 22 | + |
| 23 | +#include <stdio.h> |
| 24 | +#include <vector> |
| 25 | +#include <popl/popl.hpp> |
| 26 | + |
| 27 | +#include <CL/cl.h> |
| 28 | + |
| 29 | +typedef cl_uint cl_icdl_info; |
| 30 | + |
| 31 | +#define CL_ICDL_OCL_VERSION 1 |
| 32 | +#define CL_ICDL_VERSION 2 |
| 33 | +#define CL_ICDL_NAME 3 |
| 34 | +#define CL_ICDL_VENDOR 4 |
| 35 | + |
| 36 | +typedef cl_int (*pfn_clGetICDLoaderInfoOCLICD)(cl_icdl_info, size_t, void*, size_t*); |
| 37 | +pfn_clGetICDLoaderInfoOCLICD clGetICDLoaderInfoOCLICD = NULL; |
| 38 | + |
| 39 | +static void PrintLoaderInfo(const char* label, cl_icdl_info info) |
| 40 | +{ |
| 41 | + size_t sz = 0; |
| 42 | + clGetICDLoaderInfoOCLICD(info, 0, nullptr, &sz); |
| 43 | + |
| 44 | + std::vector<char> str(sz); |
| 45 | + clGetICDLoaderInfoOCLICD(info, sz, str.data(), nullptr); |
| 46 | + |
| 47 | + printf("Query for for %s (size = %zu) returned: %s\n", label, sz, str.data()); |
| 48 | +} |
| 49 | + |
| 50 | +int main( |
| 51 | + int argc, |
| 52 | + char** argv ) |
| 53 | +{ |
| 54 | + { |
| 55 | + popl::OptionParser op("Supported Options"); |
| 56 | + |
| 57 | + bool printUsage = false; |
| 58 | + try { |
| 59 | + op.parse(argc, argv); |
| 60 | + } catch (std::exception& e) { |
| 61 | + fprintf(stderr, "Error: %s\n\n", e.what()); |
| 62 | + printUsage = true; |
| 63 | + } |
| 64 | + |
| 65 | + if (printUsage || !op.unknown_options().empty() || !op.non_option_args().empty()) { |
| 66 | + fprintf(stderr, |
| 67 | + "Usage: loaderinfo [options]\n" |
| 68 | + "%s", op.help().c_str()); |
| 69 | + return -1; |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + |
| 74 | + clGetICDLoaderInfoOCLICD = (pfn_clGetICDLoaderInfoOCLICD) |
| 75 | + clGetExtensionFunctionAddress("clGetICDLoaderInfoOCLICD"); |
| 76 | + |
| 77 | + if (clGetICDLoaderInfoOCLICD == NULL) { |
| 78 | + printf("Couldn't get function pointer to clGetICDLoaderInfoOCLICD!\n"); |
| 79 | + printf("This is normal and some ICD loaders do not support this functionality.\n"); |
| 80 | + printf("Exiting...\n"); |
| 81 | + return 0; |
| 82 | + } |
| 83 | + |
| 84 | + #define QUERY_AND_PRINT_LOADER_INFO(_info) \ |
| 85 | + PrintLoaderInfo(#_info, _info); |
| 86 | + |
| 87 | + QUERY_AND_PRINT_LOADER_INFO(CL_ICDL_OCL_VERSION); |
| 88 | + QUERY_AND_PRINT_LOADER_INFO(CL_ICDL_VERSION); |
| 89 | + QUERY_AND_PRINT_LOADER_INFO(CL_ICDL_NAME); |
| 90 | + QUERY_AND_PRINT_LOADER_INFO(CL_ICDL_VENDOR); |
| 91 | + |
| 92 | + return 0; |
| 93 | +} |
0 commit comments