SCM Repository
View of /branches/vis12/src/clinfo/main.c
Parent Directory
|
Revision Log
Revision 2075 -
(download)
(as text)
(annotate)
Sat Nov 3 13:27:02 2012 UTC (9 years, 8 months ago) by jhr
File size: 4841 byte(s)
Sat Nov 3 13:27:02 2012 UTC (9 years, 8 months ago) by jhr
File size: 4841 byte(s)
Added clinfo command-line tool
/*! \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 <platform> -- 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 <platform> -- prints a list of the devices on the named platform * extensions <device> -- prints a list of extensions that are * supported by the device */ /* * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu) * All rights reserved. */ #include "Diderot/clinfo.h" #include <stdio.h> #include <string.h> #include <stdlib.h> #include <stdbool.h> #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 <cmd>\n"); fprintf (stderr, " where <cmd> 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 <platform> -- 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 <platform> -- prints a list of the devices on the named platform\n"); fprintf (stderr, " extensions <device> -- 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); }
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |