SCM Repository
Annotation of /trunk/src/clinfo/main.c
Parent Directory
|
Revision Log
Revision 3349 - (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 : | jhr | 3349 | * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu) |
23 : | * | ||
24 : | * COPYRIGHT (c) 2015 The University of Chicago | ||
25 : | jhr | 1640 | * All rights reserved. |
26 : | */ | ||
27 : | |||
28 : | jhr | 1671 | #include "clinfo.h" |
29 : | jhr | 1640 | #include <stdio.h> |
30 : | #include <string.h> | ||
31 : | #include <stdlib.h> | ||
32 : | |||
33 : | #define MAX_PLATFORMS 16 | ||
34 : | |||
35 : | static void usage (); | ||
36 : | jhr | 1671 | static PlatformInfo_t *GetPlatformByName (const CLInfo_t *info, const char *name); |
37 : | jhr | 1640 | |
38 : | int main (int argc, const char **argv) | ||
39 : | { | ||
40 : | if (argc < 2) { | ||
41 : | usage(); | ||
42 : | } | ||
43 : | |||
44 : | jhr | 1671 | // get CL info |
45 : | CLInfo_t *info = GetCLInfo (); | ||
46 : | |||
47 : | jhr | 1640 | // process command-line options |
48 : | if ((strcmp(argv[1], "platforms") == 0) && (argc == 2)) { | ||
49 : | jhr | 1671 | for (int i = 0; i < info->numPlatforms; i++) { |
50 : | printf ("%s\n", info->platforms[i].name); | ||
51 : | jhr | 1640 | } |
52 : | } | ||
53 : | else if ((strcmp(argv[1], "version") == 0) && (argc == 3)) { | ||
54 : | char buf[256]; | ||
55 : | jhr | 1671 | cl_platform_id id = GetPlatformByName(info, argv[2]); |
56 : | jhr | 1640 | clGetPlatformInfo (id, CL_PLATFORM_VERSION, sizeof(buf), buf, 0); |
57 : | printf ("%s\n", buf); | ||
58 : | } | ||
59 : | else if ((strcmp(argv[1], "devices") == 0) && (argc == 3)) { | ||
60 : | cl_platform_id id = GetPlatformByName(argv[2]); | ||
61 : | cl_device_id *devs; | ||
62 : | char buf[256]; | ||
63 : | int numDevs = GetDevices (id, CL_DEVICE_TYPE_ALL, &devs); | ||
64 : | for (int i = 0; i < numDevs; i++) { | ||
65 : | clGetDeviceInfo (devs[i], CL_DEVICE_NAME, sizeof(buf), buf, 0); | ||
66 : | printf ("%s\n", buf); | ||
67 : | } | ||
68 : | } | ||
69 : | else if ((strcmp(argv[1], "extensions") == 0) && (argc == 3)) { | ||
70 : | cl_platform_id id = GetPlatformByName(argv[2]); | ||
71 : | size_t bufSz; | ||
72 : | // get the size of the extensions buffer | ||
73 : | clGetPlatformInfo (id, CL_PLATFORM_EXTENSIONS, 0, 0, &bufSz); | ||
74 : | char *buf = (char *)malloc(bufSz); | ||
75 : | clGetPlatformInfo (id, CL_PLATFORM_EXTENSIONS, bufSz, buf, 0); | ||
76 : | char *p = buf; | ||
77 : | while (p != 0) { | ||
78 : | p = strchr(p, ' '); | ||
79 : | if (p != 0) *p = '\n'; | ||
80 : | } | ||
81 : | printf ("%s", buf); | ||
82 : | free (buf); | ||
83 : | } | ||
84 : | else | ||
85 : | usage(); | ||
86 : | |||
87 : | } | ||
88 : | |||
89 : | static void usage () | ||
90 : | { | ||
91 : | exit (1); | ||
92 : | } | ||
93 : | |||
94 : | jhr | 1671 | static PlatformInfo_t *GetPlatformByName (const CLInfo_t *info, const char *name) |
95 : | jhr | 1640 | { |
96 : | jhr | 1671 | for (cl_uint i = 0; i < info->numPlatforms; i++) { |
97 : | if (strcmp(info->platforms[i].name, name) == 0) | ||
98 : | return &(info->platforms[i]); | ||
99 : | jhr | 1640 | } |
100 : | |||
101 : | fprintf (stderr, "platform %s not found\n", name); | ||
102 : | exit (1); | ||
103 : | |||
104 : | } |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |