|
Packit |
6d72ef |
/**
|
|
Packit |
6d72ef |
Copyright (c) 2012, Brice Videau <brice.videau@imag.fr>
|
|
Packit |
6d72ef |
All rights reserved.
|
|
Packit |
6d72ef |
|
|
Packit |
6d72ef |
Redistribution and use in source and binary forms, with or without
|
|
Packit |
6d72ef |
modification, are permitted provided that the following conditions are met:
|
|
Packit |
6d72ef |
|
|
Packit |
6d72ef |
1. Redistributions of source code must retain the above copyright notice, this
|
|
Packit |
6d72ef |
list of conditions and the following disclaimer.
|
|
Packit |
6d72ef |
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
Packit |
6d72ef |
this list of conditions and the following disclaimer in the documentation
|
|
Packit |
6d72ef |
and/or other materials provided with the distribution.
|
|
Packit |
6d72ef |
|
|
Packit |
6d72ef |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
Packit |
6d72ef |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
Packit |
6d72ef |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
Packit |
6d72ef |
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
Packit |
6d72ef |
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
Packit |
6d72ef |
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
Packit |
6d72ef |
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
Packit |
6d72ef |
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
Packit |
6d72ef |
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
Packit |
6d72ef |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
6d72ef |
*/
|
|
Packit |
6d72ef |
|
|
Packit |
6d72ef |
#include <CL/opencl.h>
|
|
Packit |
6d72ef |
#include <stdio.h>
|
|
Packit |
6d72ef |
#include <stdlib.h>
|
|
Packit |
6d72ef |
#include <string.h>
|
|
Packit |
6d72ef |
|
|
Packit |
6d72ef |
void print_error(cl_int error) {
|
|
Packit |
6d72ef |
switch (error) {
|
|
Packit |
6d72ef |
case CL_SUCCESS: break ;
|
|
Packit |
6d72ef |
case CL_PLATFORM_NOT_FOUND_KHR:
|
|
Packit |
6d72ef |
printf("No platforms found!\n");
|
|
Packit |
6d72ef |
break;
|
|
Packit |
6d72ef |
case CL_INVALID_PLATFORM:
|
|
Packit |
6d72ef |
printf("Invalid platform\n");
|
|
Packit |
6d72ef |
break;
|
|
Packit |
6d72ef |
default:
|
|
Packit |
6d72ef |
printf("OpenCL error: %i\n", error);
|
|
Packit |
6d72ef |
}
|
|
Packit |
6d72ef |
}
|
|
Packit |
6d72ef |
|
|
Packit |
6d72ef |
void show_platform(cl_platform_id pid, int show_extensions) {
|
|
Packit |
6d72ef |
char *platform_vendor;
|
|
Packit |
6d72ef |
size_t param_value_size_ret;
|
|
Packit |
6d72ef |
cl_int error;
|
|
Packit |
6d72ef |
|
|
Packit |
6d72ef |
error = clGetPlatformInfo(pid, CL_PLATFORM_VENDOR, 0, NULL, ¶m_value_size_ret );
|
|
Packit |
6d72ef |
print_error(error);
|
|
Packit |
6d72ef |
if (error != CL_SUCCESS)
|
|
Packit |
6d72ef |
return;
|
|
Packit |
6d72ef |
|
|
Packit |
6d72ef |
platform_vendor = (char *)malloc(param_value_size_ret);
|
|
Packit |
6d72ef |
clGetPlatformInfo(pid, CL_PLATFORM_VENDOR, param_value_size_ret, platform_vendor, NULL );
|
|
Packit |
6d72ef |
|
|
Packit |
6d72ef |
printf("%s\n",platform_vendor);
|
|
Packit |
6d72ef |
free(platform_vendor);
|
|
Packit |
6d72ef |
|
|
Packit |
6d72ef |
if (show_extensions) {
|
|
Packit |
6d72ef |
error = clGetPlatformInfo(pid, CL_PLATFORM_EXTENSIONS, 0, NULL, ¶m_value_size_ret );
|
|
Packit |
6d72ef |
print_error(error);
|
|
Packit |
6d72ef |
|
|
Packit |
6d72ef |
platform_vendor = (char *)malloc(param_value_size_ret);
|
|
Packit |
6d72ef |
clGetPlatformInfo(pid, CL_PLATFORM_EXTENSIONS, param_value_size_ret, platform_vendor, NULL );
|
|
Packit |
6d72ef |
|
|
Packit |
6d72ef |
printf("Extensions: %s\n",platform_vendor);
|
|
Packit |
6d72ef |
free(platform_vendor);
|
|
Packit |
6d72ef |
}
|
|
Packit |
6d72ef |
}
|
|
Packit |
6d72ef |
|
|
Packit |
6d72ef |
int main(int argc, char* argv[]) {
|
|
Packit |
6d72ef |
cl_platform_id *platforms;
|
|
Packit |
6d72ef |
cl_uint num_platforms;
|
|
Packit |
6d72ef |
cl_int error;
|
|
Packit |
6d72ef |
|
|
Packit |
6d72ef |
int show_extensions=0;
|
|
Packit |
6d72ef |
if (argc >= 2 && strcmp(argv[1], "--show-extensions")==0) {
|
|
Packit |
6d72ef |
show_extensions=1;
|
|
Packit |
6d72ef |
argv++;
|
|
Packit |
6d72ef |
}
|
|
Packit |
6d72ef |
|
|
Packit |
6d72ef |
int default_platform=0;
|
|
Packit |
6d72ef |
if (argc >= 2 && strcmp(argv[1], "--default-platform")==0) {
|
|
Packit |
6d72ef |
default_platform=1;
|
|
Packit |
6d72ef |
}
|
|
Packit |
6d72ef |
|
|
Packit |
6d72ef |
error = clGetPlatformIDs(0, NULL, &num_platforms);
|
|
Packit |
6d72ef |
if( error == CL_SUCCESS ) {
|
|
Packit |
6d72ef |
printf("Found %u platforms!\n", num_platforms);
|
|
Packit |
6d72ef |
} else if( error == CL_PLATFORM_NOT_FOUND_KHR ) {
|
|
Packit |
6d72ef |
print_error(error);
|
|
Packit |
6d72ef |
if (default_platform) {
|
|
Packit |
6d72ef |
show_platform(NULL, show_extensions);
|
|
Packit |
6d72ef |
}
|
|
Packit |
6d72ef |
exit(0);
|
|
Packit |
6d72ef |
} else {
|
|
Packit |
6d72ef |
print_error(error);
|
|
Packit |
6d72ef |
exit(-1);
|
|
Packit |
6d72ef |
}
|
|
Packit |
6d72ef |
platforms = (cl_platform_id *)malloc(sizeof(cl_platform_id *) * num_platforms);
|
|
Packit |
6d72ef |
error = clGetPlatformIDs(num_platforms, platforms, NULL);
|
|
Packit |
6d72ef |
print_error(error);
|
|
Packit |
6d72ef |
cl_uint i;
|
|
Packit |
6d72ef |
for(i=0; i
|
|
Packit |
6d72ef |
show_platform(platforms[i], show_extensions);
|
|
Packit |
6d72ef |
}
|
|
Packit |
6d72ef |
if (default_platform) {
|
|
Packit |
6d72ef |
show_platform(NULL, show_extensions);
|
|
Packit |
6d72ef |
}
|
|
Packit |
6d72ef |
return 0;
|
|
Packit |
6d72ef |
}
|