@@ -217,6 +217,11 @@ bool cl_check_external_memory_handle_type(
217
217
exit (EXIT_FAILURE );
218
218
}
219
219
220
+ cl_int opencl_version_is_major (cl_name_version * dev_name_version , cl_uint major )
221
+ {
222
+ return CL_VERSION_MAJOR (dev_name_version -> version ) == major ;
223
+ }
224
+
220
225
int main (int argc , char * argv [])
221
226
{
222
227
cl_int error = CL_SUCCESS ;
@@ -343,13 +348,32 @@ int main(int argc, char* argv[])
343
348
error , ker );
344
349
345
350
// The Khronos extension showcased requires OpenCL 3.0 version.
346
- char compiler_options [1023 ] = "" ;
347
- #if CL_HPP_TARGET_OPENCL_VERSION >= 300
348
- strcat (compiler_options , "-cl-std=CL3.0 " );
349
- #else
350
- fprintf (stderr , "\nError: OpenCL version must be at least 3.0\n" );
351
- exit (EXIT_FAILURE );
352
- #endif
351
+ // Get number of versions supported.
352
+ size_t versions_size = 0 ;
353
+ OCLERROR_RET (clGetDeviceInfo (cl_device , CL_DEVICE_OPENCL_C_ALL_VERSIONS , 0 ,
354
+ NULL , & versions_size ),
355
+ error , end );
356
+ size_t versions_count = versions_size / sizeof (cl_name_version );
357
+
358
+ // Get and check versions.
359
+ cl_name_version * dev_versions = (cl_name_version * )malloc (versions_size );
360
+ OCLERROR_RET (clGetDeviceInfo (cl_device , CL_DEVICE_OPENCL_C_ALL_VERSIONS ,
361
+ versions_size , dev_versions , NULL ),
362
+ error , end );
363
+ char compiler_options [1024 ] = "" ;
364
+ for (cl_uint i = 0 ; i < versions_count ; ++ i )
365
+ {
366
+ if (opencl_version_is_major (& dev_versions [i ], 3 ))
367
+ {
368
+ strcat (compiler_options , "-cl-std=CL3.0 " );
369
+ }
370
+ }
371
+
372
+ if (compiler_options [0 ] == '\0' )
373
+ {
374
+ fprintf (stderr , "\nError: OpenCL version must be at least 3.0\n" );
375
+ exit (EXIT_FAILURE );
376
+ }
353
377
354
378
OCLERROR_RET (cl_util_build_program (program , cl_device , compiler_options ),
355
379
error , prg );
0 commit comments