SCM Repository
Annotation of /trunk/src/clinfo/main.c
Parent Directory
|
Revision Log
Revision 1671 - (view) (download) (as text)
1 : | jhr | 1671 | /*! \file main.c |
2 : | jhr | 1640 | * |
3 : | * \author John Reppy | ||
4 : | * | ||
5 : | * \brief This program is used to determine properties of the host machine's | ||
6 : | * OpenCL support. | ||
7 : | * | ||
8 : | * Usage: | ||
9 : | * clinfo cmd [args] | ||
10 : | * | ||
11 : | * where cmd is one of | ||
12 : | * platforms -- prints a list of OpenCL platforms supported by the | ||
13 : | * host. | ||
14 : | * version platform -- prints version of OpenCL supported by the platform. The | ||
15 : | * format is "OpenCL major.minor ..." | ||
16 : | * devices platform -- prints a list of devices | ||
17 : | * extensions device -- prints a list of extensions that are | ||
18 : | * supported by the device | ||
19 : | */ | ||
20 : | |||
21 : | /* | ||
22 : | * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu) | ||
23 : | * All rights reserved. | ||
24 : | */ | ||
25 : | |||
26 : | jhr | 1671 | #include "clinfo.h" |
27 : | jhr | 1640 | #include <stdio.h> |
28 : | #include <string.h> | ||
29 : | #include <stdlib.h> | ||
30 : | |||
31 : | #define MAX_PLATFORMS 16 | ||
32 : | |||
33 : | static void usage (); | ||
34 : | jhr | 1671 | static PlatformInfo_t *GetPlatformByName (const CLInfo_t *info, const char *name); |
35 : | jhr | 1640 | |
36 : | int main (int argc, const char **argv) | ||
37 : | { | ||
38 : | if (argc < 2) { | ||
39 : | usage(); | ||
40 : | } | ||
41 : | |||
42 : | jhr | 1671 | // get CL info |
43 : | CLInfo_t *info = GetCLInfo (); | ||
44 : | |||
45 : | jhr | 1640 | // process command-line options |
46 : | if ((strcmp(argv[1], "platforms") == 0) && (argc == 2)) { | ||
47 : | jhr | 1671 | for (int i = 0; i < info->numPlatforms; i++) { |
48 : | printf ("%s\n", info->platforms[i].name); | ||
49 : | jhr | 1640 | } |
50 : | } | ||
51 : | else if ((strcmp(argv[1], "version") == 0) && (argc == 3)) { | ||
52 : | char buf[256]; | ||
53 : | jhr | 1671 | cl_platform_id id = GetPlatformByName(info, argv[2]); |
54 : | jhr | 1640 | clGetPlatformInfo (id, CL_PLATFORM_VERSION, sizeof(buf), buf, 0); |
55 : | printf ("%s\n", buf); | ||
56 : | } | ||
57 : | else if ((strcmp(argv[1], "devices") == 0) && (argc == 3)) { | ||
58 : | cl_platform_id id = GetPlatformByName(argv[2]); | ||
59 : | cl_device_id *devs; | ||
60 : | char buf[256]; | ||
61 : | int numDevs = GetDevices (id, CL_DEVICE_TYPE_ALL, &devs); | ||
62 : | for (int i = 0; i < numDevs; i++) { | ||
63 : | clGetDeviceInfo (devs[i], CL_DEVICE_NAME, sizeof(buf), buf, 0); | ||
64 : | printf ("%s\n", buf); | ||
65 : | } | ||
66 : | } | ||
67 : | else if ((strcmp(argv[1], "extensions") == 0) && (argc == 3)) { | ||
68 : | cl_platform_id id = GetPlatformByName(argv[2]); | ||
69 : | size_t bufSz; | ||
70 : | // get the size of the extensions buffer | ||
71 : | clGetPlatformInfo (id, CL_PLATFORM_EXTENSIONS, 0, 0, &bufSz); | ||
72 : | char *buf = (char *)malloc(bufSz); | ||
73 : | clGetPlatformInfo (id, CL_PLATFORM_EXTENSIONS, bufSz, buf, 0); | ||
74 : | char *p = buf; | ||
75 : | while (p != 0) { | ||
76 : | p = strchr(p, ' '); | ||
77 : | if (p != 0) *p = '\n'; | ||
78 : | } | ||
79 : | printf ("%s", buf); | ||
80 : | free (buf); | ||
81 : | } | ||
82 : | else | ||
83 : | usage(); | ||
84 : | |||
85 : | } | ||
86 : | |||
87 : | static void usage () | ||
88 : | { | ||
89 : | exit (1); | ||
90 : | } | ||
91 : | |||
92 : | jhr | 1671 | static PlatformInfo_t *GetPlatformByName (const CLInfo_t *info, const char *name) |
93 : | jhr | 1640 | { |
94 : | jhr | 1671 | for (cl_uint i = 0; i < info->numPlatforms; i++) { |
95 : | if (strcmp(info->platforms[i].name, name) == 0) | ||
96 : | return &(info->platforms[i]); | ||
97 : | jhr | 1640 | } |
98 : | |||
99 : | fprintf (stderr, "platform %s not found\n", name); | ||
100 : | exit (1); | ||
101 : | |||
102 : | } |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |