2 Copyright (c) 2012, Brice Videau <brice.videau@imag.fr>
3 Copyright (c) 2012, Vincent Danjean <Vincent.Danjean@ens-lyon.org>
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice, this
10 list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright notice,
12 this list of conditions and the following disclaimer in the documentation
13 and/or other materials provided with the distribution.
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "ocl_icd_debug.h"
28 #include "libdummy_icd.h"
29 #include "libdummy_icd_gen.h"
33 #define NUM_PLATFORMS 1
36 typeof(INT##f) f __attribute__ ((alias ("INT" #f), visibility("default")))
38 #pragma GCC visibility push(hidden)
40 int debug_ocl_icd_mask;
42 cl_uint const num_master_platforms = NUM_PLATFORMS;
43 struct _cl_platform_id master_platforms[NUM_PLATFORMS] = { {&master_dispatch} };
45 static cl_int _GetPlatformIDs(
47 cl_platform_id *platforms,
48 cl_uint *num_platforms) {
50 if( platforms == NULL && num_platforms == NULL )
51 return CL_INVALID_VALUE;
52 if( num_entries == 0 && platforms != NULL )
53 return CL_INVALID_VALUE;
54 if( num_master_platforms == 0)
55 return CL_PLATFORM_NOT_FOUND_KHR;
56 if( num_platforms != NULL ){
57 debug(D_LOG, " asked num_platforms");
58 *num_platforms = num_master_platforms; }
59 if( platforms != NULL ) {
60 debug(D_LOG, " asked %i platforms", num_entries);
62 for( i=0; i<(num_master_platforms<num_entries?num_master_platforms:num_entries); i++)
63 platforms[i] = &master_platforms[i];
68 CL_API_ENTRY cl_int CL_API_CALL INTclGetPlatformIDs(
70 cl_platform_id *platforms,
71 cl_uint *num_platforms) {
74 return _GetPlatformIDs(num_entries, platforms, num_platforms);
76 SYMB(clGetPlatformIDs);
78 CL_API_ENTRY cl_int CL_API_CALL INTclIcdGetPlatformIDsKHR(
80 cl_platform_id *platforms,
81 cl_uint *num_platforms) {
84 return _GetPlatformIDs(num_entries, platforms, num_platforms);
86 SYMB(clIcdGetPlatformIDsKHR);
88 /*CL_API_ENTRY void * CL_API_CALL clGetExtensionFunctionAddressForPlatform(
89 cl_platform_id platform,
90 const char * func_name) CL_API_SUFFIX__VERSION_1_2 {
93 CL_API_ENTRY void * CL_API_CALL INTclGetExtensionFunctionAddress(
94 const char * func_name) CL_API_SUFFIX__VERSION_1_0 {
97 debug(D_LOG, "request address for %s", func_name);
98 if( func_name != NULL && strcmp("clIcdGetPlatformIDsKHR", func_name) == 0 )
99 return (void *)_GetPlatformIDs;
102 SYMB(clGetExtensionFunctionAddress);
105 # define ICD_SUFFIX ""
108 CL_API_ENTRY cl_int CL_API_CALL INTclGetPlatformInfo(
109 cl_platform_id platform,
110 cl_platform_info param_name,
111 size_t param_value_size,
113 size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 {
116 debug(D_LOG, "request info for 0x%x", param_name);
118 char cl_platform_profile[] = "FULL_PROFILE";
119 char cl_platform_version[] = "OpenCL 1.2";
120 char cl_platform_name[] = "DummyCL" ICD_SUFFIX;
121 char cl_platform_vendor[] = "ocl-icd ICD test" ICD_SUFFIX
122 #ifdef ICD_WITHOUT_EXTENSION
126 char cl_platform_extensions[] =
127 #ifdef ICD_WITHOUT_EXTENSION
133 char cl_platform_icd_suffix_khr[] = "LIG";
136 if( platform != NULL ) {
139 for(i=0; i<num_master_platforms; i++) {
140 if( platform == &master_platforms[i] )
144 return CL_INVALID_PLATFORM;
146 switch ( param_name ) {
147 case CL_PLATFORM_PROFILE:
148 string_p = cl_platform_profile;
149 size_string = sizeof(cl_platform_profile);
151 case CL_PLATFORM_VERSION:
152 string_p = cl_platform_version;
153 size_string = sizeof(cl_platform_version);
155 case CL_PLATFORM_NAME:
156 string_p = cl_platform_name;
157 size_string = sizeof(cl_platform_name);
159 case CL_PLATFORM_VENDOR:
160 string_p = cl_platform_vendor;
161 size_string = sizeof(cl_platform_vendor);
163 case CL_PLATFORM_EXTENSIONS:
164 #ifdef ICD_WITHOUT_EXTENSION
165 if (getenv("EMULATE_INTEL_ICD")) {
169 string_p = cl_platform_extensions;
170 size_string = sizeof(cl_platform_extensions);
172 case CL_PLATFORM_ICD_SUFFIX_KHR:
173 string_p = cl_platform_icd_suffix_khr;
174 size_string = sizeof(cl_platform_icd_suffix_khr);
177 return CL_INVALID_VALUE;
180 if( param_value != NULL ) {
181 if( size_string > param_value_size )
182 return CL_INVALID_VALUE;
183 memcpy(param_value, string_p, size_string);
185 if( param_value_size_ret != NULL )
186 *param_value_size_ret = size_string;
189 SYMB(clGetPlatformInfo);
191 #pragma GCC visibility pop