mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-25 08:19:02 +00:00
Refactor is_extension_available()
This change splits up is_extension_available() so that the bulk of it can be reused for fetching other items of variable-length device information, such as CL_DEVICE_VERSION.
This commit is contained in:
committed by
Kévin Petit
parent
cc2f77b651
commit
5a4a051206
@@ -488,40 +488,64 @@ int get_max_common_3D_work_group_size( cl_context context, cl_kernel kernel,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper to determine if an extension is supported by a device */
|
/* Helper to allocate and return a buffer containing device information for the specified device info parameter */
|
||||||
int is_extension_available( cl_device_id device, const char *extensionName )
|
static void *alloc_and_get_device_info( cl_device_id device, cl_device_info param_name, const char *param_description )
|
||||||
{
|
{
|
||||||
char *extString;
|
void *buffer;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
int err;
|
int err;
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
if(( err = clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 0, NULL, &size) ))
|
if(( err = clGetDeviceInfo(device, param_name, 0, NULL, &size) ))
|
||||||
{
|
{
|
||||||
log_error( "Error: failed to determine size of device extensions string at %s:%d (err = %d)\n", __FILE__, __LINE__, err );
|
log_error( "Error: failed to determine size of device %s at %s:%d (err = %d)\n",
|
||||||
return 0;
|
param_description, __FILE__, __LINE__, err );
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( 0 == size )
|
if( 0 == size )
|
||||||
return 0;
|
return NULL;
|
||||||
|
|
||||||
extString = (char*) malloc( size );
|
buffer = malloc( size );
|
||||||
|
|
||||||
|
if( NULL == buffer )
|
||||||
|
{
|
||||||
|
log_error( "Error: unable to allocate %zu byte buffer for device %s at %s:%d (err = %d)\n",
|
||||||
|
size, param_description, __FILE__, __LINE__, err );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(( err = clGetDeviceInfo(device, param_name, size, buffer, NULL) ))
|
||||||
|
{
|
||||||
|
free(buffer);
|
||||||
|
log_error( "Error: failed to obtain device %s at %s:%d (err = %d)\n",
|
||||||
|
param_description, __FILE__, __LINE__, err );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Helper to return a newly allocated C string containing the supported extensions list for a device */
|
||||||
|
static char *alloc_and_get_device_extensions_string( cl_device_id device )
|
||||||
|
{
|
||||||
|
return (char *) alloc_and_get_device_info( device, CL_DEVICE_EXTENSIONS, "extensions string" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Helper to determine if an extension is supported by a device */
|
||||||
|
int is_extension_available( cl_device_id device, const char *extensionName )
|
||||||
|
{
|
||||||
|
char *extString = alloc_and_get_device_extensions_string( device );
|
||||||
|
|
||||||
if( NULL == extString )
|
if( NULL == extString )
|
||||||
{
|
{
|
||||||
log_error( "Error: unable to allocate %ld byte buffer for extension string at %s:%d (err = %d)\n", size, __FILE__, __LINE__, err );
|
/* An error message will have already been printed by alloc_and_get_device_info(),
|
||||||
return 0;
|
* so we can just return, here. */
|
||||||
}
|
|
||||||
BufferOwningPtr<char> extStringBuf(extString);
|
|
||||||
|
|
||||||
if(( err = clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, size, extString, NULL) ))
|
|
||||||
{
|
|
||||||
log_error( "Error: failed to obtain device extensions string at %s:%d (err = %d)\n", __FILE__, __LINE__, err );
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( strstr( extString, extensionName ) )
|
int result = strstr( extString, extensionName ) != NULL;
|
||||||
result = 1;
|
|
||||||
|
free(extString);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user