/*! \file main.c * * \author John Reppy * * \brief This program is used to determine properties of the host machine's * OpenCL support. * * Usage: * clinfo cmd [args] * * where cmd is one of * all -- prints all of the info about the available OpenCL * platforms and devices. * platforms -- prints a list of OpenCL platforms supported by the * host. * version -- prints version of OpenCL supported by the platform. The * format is "OpenCL major.minor ..." * devices all -- prints a list of all of the devices * devices -- prints a list of the devices on the named platform * extensions -- prints a list of extensions that are * supported by the device */ /* * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu) * * COPYRIGHT (c) 2015 The University of Chicago * All rights reserved. */ #include "Diderot/clinfo.h" #include #include #include #include #define MAX_PLATFORMS 16 static void usage (); static PlatformInfo_t *GetPlatformByName (const CLInfo_t *info, const char *name); int main (int argc, const char **argv) { if (argc < 2) { usage(); } // get CL info CLInfo_t *info = Diderot_GetCLInfo (); // process command-line options if ((strcmp(argv[1], "all") == 0) && (argc == 2)) { Diderot_PrintCLInfo (stdout, info); } else if ((strcmp(argv[1], "platforms") == 0) && (argc == 2)) { for (int i = 0; i < info->numPlatforms; i++) { printf ("%s\n", info->platforms[i].name); } } else if ((strcmp(argv[1], "version") == 0) && (argc == 3)) { char buf[256]; PlatformInfo_t *platform = GetPlatformByName(info, argv[2]); clGetPlatformInfo (platform->id, CL_PLATFORM_VERSION, sizeof(buf), buf, 0); printf ("%s\n", buf); } else if ((strcmp(argv[1], "devices") == 0) && (argc == 3)) { if (strcmp(argv[2], "all") == 0) { // list all devices for (int i = 0; i < info->numPlatforms; i++) { PlatformInfo_t *plat = &(info->platforms[i]); for (int j = 0; j < plat->numDevices; j++) { DeviceInfo_t *dev = &(plat->devices[j]); if (dev->isAvail) printf ("%d.%d: %s\n", i, j, dev->name); else printf ("%d.%d: %s **UNAVAILABLE**\n", i, j, dev->name); } } } else { PlatformInfo_t *plat = GetPlatformByName(info, argv[2]); for (int i = 0; i < plat->numDevices; i++) { DeviceInfo_t *dev = &(plat->devices[i]); printf ("%d.%d: %s%s\n", dev->index[0], dev->index[1], dev->name, dev->isAvail ? "" : " **UNAVAILABLE**"); } } } else if ((strcmp(argv[1], "extensions") == 0) && (argc == 3)) { PlatformInfo_t *platform = GetPlatformByName(info, argv[2]); size_t bufSz; // get the size of the extensions buffer clGetPlatformInfo (platform->id, CL_PLATFORM_EXTENSIONS, 0, 0, &bufSz); char *buf = (char *)malloc(bufSz); clGetPlatformInfo (platform->id, CL_PLATFORM_EXTENSIONS, bufSz, buf, 0); char *p = buf; while (p != 0) { p = strchr(p, ' '); if (p != 0) *p = '\n'; } printf ("%s", buf); free (buf); } else usage(); } static void usage () { fprintf (stderr, "usage: clinfo \n"); fprintf (stderr, " where is one of:\n"); fprintf (stderr, " all -- prints all of the info about the available OpenCL\n"); fprintf (stderr, " platforms and devices.\n"); fprintf (stderr, " platforms -- prints a list of OpenCL platforms supported by the\n"); fprintf (stderr, " host.\n"); fprintf (stderr, " version -- prints version of OpenCL supported by the platform. The\n"); fprintf (stderr, " format is \"OpenCL major.minor ...\"\n"); fprintf (stderr, " devices all -- prints a list of all of the devices\n"); fprintf (stderr, " devices -- prints a list of the devices on the named platform\n"); fprintf (stderr, " extensions -- prints a list of extensions that are\n"); fprintf (stderr, " supported by the device\n"); exit (1); } static PlatformInfo_t *GetPlatformByName (const CLInfo_t *info, const char *name) { for (cl_uint i = 0; i < info->numPlatforms; i++) { if (strcmp(info->platforms[i].name, name) == 0) return &(info->platforms[i]); } fprintf (stderr, "platform %s not found\n", name); exit (1); }
Click to toggle
does not end with </html> tag
does not end with </body> tag
The output has ended thus: (info->platforms[i]); } fprintf (stderr, "platform %s not found\n", name); exit (1); }