2 Copyright (c) 2012, Brice Videau <brice.videau@imag.fr>
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include <CL/opencl.h>
31 void print_error(cl_int error) {
33 case CL_SUCCESS: break ;
34 case CL_PLATFORM_NOT_FOUND_KHR:
35 printf("No platforms found!\n");
37 case CL_INVALID_PLATFORM:
38 printf("Invalid platform\n");
41 printf("OpenCL error: %i\n", error);
45 void show_platform(cl_platform_id pid, int show_extensions) {
46 char *platform_vendor;
47 size_t param_value_size_ret;
50 error = clGetPlatformInfo(pid, CL_PLATFORM_VENDOR, 0, NULL, ¶m_value_size_ret );
52 if (error != CL_SUCCESS)
55 platform_vendor = (char *)malloc(param_value_size_ret);
56 clGetPlatformInfo(pid, CL_PLATFORM_VENDOR, param_value_size_ret, platform_vendor, NULL );
58 printf("%s\n",platform_vendor);
59 free(platform_vendor);
61 if (show_extensions) {
62 error = clGetPlatformInfo(pid, CL_PLATFORM_EXTENSIONS, 0, NULL, ¶m_value_size_ret );
65 platform_vendor = (char *)malloc(param_value_size_ret);
66 clGetPlatformInfo(pid, CL_PLATFORM_EXTENSIONS, param_value_size_ret, platform_vendor, NULL );
68 printf("Extensions: %s\n",platform_vendor);
69 free(platform_vendor);
73 int main(int argc, char* argv[]) {
74 cl_platform_id *platforms;
75 cl_uint num_platforms;
78 int show_extensions=0;
79 if (argc >= 2 && strcmp(argv[1], "--show-extensions")==0) {
84 int default_platform=0;
85 if (argc >= 2 && strcmp(argv[1], "--default-platform")==0) {
89 error = clGetPlatformIDs(0, NULL, &num_platforms);
90 if( error == CL_SUCCESS ) {
91 printf("Found %u platforms!\n", num_platforms);
92 } else if( error == CL_PLATFORM_NOT_FOUND_KHR ) {
94 if (default_platform) {
95 show_platform(NULL, show_extensions);
102 platforms = (cl_platform_id *)malloc(sizeof(cl_platform_id *) * num_platforms);
103 error = clGetPlatformIDs(num_platforms, platforms, NULL);
106 for(i=0; i<num_platforms; i++){
107 show_platform(platforms[i], show_extensions);
109 if (default_platform) {
110 show_platform(NULL, show_extensions);