mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-26 08:49:02 +00:00
Separate out device information functions
Signed-off-by: Stuart Brady <stuart.brady@arm.com>
This commit is contained in:
committed by
Kévin Petit
parent
f15178ca91
commit
4d891b67bd
@@ -18,6 +18,7 @@ set(HARNESS_SOURCES
|
|||||||
harness/genericThread.cpp
|
harness/genericThread.cpp
|
||||||
harness/imageHelpers.cpp
|
harness/imageHelpers.cpp
|
||||||
harness/kernelHelpers.c
|
harness/kernelHelpers.c
|
||||||
|
harness/deviceInfo.cpp
|
||||||
harness/os_helpers.cpp
|
harness/os_helpers.cpp
|
||||||
harness/parseParameters.cpp
|
harness/parseParameters.cpp
|
||||||
harness/testHarness.c
|
harness/testHarness.c
|
||||||
|
|||||||
78
test_common/harness/deviceInfo.cpp
Normal file
78
test_common/harness/deviceInfo.cpp
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) 2017-2019 The Khronos Group Inc.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
#include "deviceInfo.h"
|
||||||
|
#include "errorHelpers.h"
|
||||||
|
#include "typeWrappers.h"
|
||||||
|
|
||||||
|
/* Helper to allocate and return a buffer containing device information for the specified device info parameter. */
|
||||||
|
static void *alloc_and_get_device_info( cl_device_id device, cl_device_info param_name, const char *param_description )
|
||||||
|
{
|
||||||
|
void *buffer;
|
||||||
|
size_t size = 0;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
if ((err = clGetDeviceInfo(device, param_name, 0, NULL, &size)) != CL_SUCCESS)
|
||||||
|
{
|
||||||
|
log_error("Error: failed to determine size of device %s at %s:%d (err = %d)\n",
|
||||||
|
param_description, __FILE__, __LINE__, err);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == size)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
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)) != CL_SUCCESS)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Determines 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)
|
||||||
|
{
|
||||||
|
/* An error message will have already been printed by alloc_and_get_device_info(),
|
||||||
|
* so we can just return, here. */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferOwningPtr<char> extStringBuf(extString);
|
||||||
|
|
||||||
|
return strstr(extString, extensionName) != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Returns a newly allocated C string containing the supported extensions list for a device. */
|
||||||
|
char *alloc_and_get_device_extensions_string(cl_device_id device)
|
||||||
|
{
|
||||||
|
return (char *) alloc_and_get_device_info(device, CL_DEVICE_EXTENSIONS, "extensions string");
|
||||||
|
}
|
||||||
38
test_common/harness/deviceInfo.h
Normal file
38
test_common/harness/deviceInfo.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) 2017-2019 The Khronos Group Inc.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
#ifndef _deviceInfo_h
|
||||||
|
#define _deviceInfo_h
|
||||||
|
|
||||||
|
// Configuration
|
||||||
|
#include "../config.hpp"
|
||||||
|
|
||||||
|
#include <CL/opencl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
/* Determines if an extension is supported by a device. */
|
||||||
|
int is_extension_available(cl_device_id device, const char *extensionName);
|
||||||
|
|
||||||
|
/* Returns a newly allocated C string containing the supported extensions list for a device. */
|
||||||
|
char *alloc_and_get_device_extensions_string(cl_device_id device);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
#endif // _deviceInfo_h
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
//
|
//
|
||||||
#include "crc32.h"
|
#include "crc32.h"
|
||||||
#include "kernelHelpers.h"
|
#include "kernelHelpers.h"
|
||||||
|
#include "deviceInfo.h"
|
||||||
#include "errorHelpers.h"
|
#include "errorHelpers.h"
|
||||||
#include "imageHelpers.h"
|
#include "imageHelpers.h"
|
||||||
#include "typeWrappers.h"
|
#include "typeWrappers.h"
|
||||||
@@ -1118,66 +1119,6 @@ int get_max_common_3D_work_group_size( cl_context context, cl_kernel kernel,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper to allocate and return a buffer containing device information for the specified device info parameter */
|
|
||||||
static void *alloc_and_get_device_info( cl_device_id device, cl_device_info param_name, const char *param_description )
|
|
||||||
{
|
|
||||||
void *buffer;
|
|
||||||
size_t size = 0;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
if(( err = clGetDeviceInfo(device, param_name, 0, NULL, &size) ))
|
|
||||||
{
|
|
||||||
log_error( "Error: failed to determine size of device %s at %s:%d (err = %d)\n",
|
|
||||||
param_description, __FILE__, __LINE__, err );
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( 0 == size )
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
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 )
|
|
||||||
{
|
|
||||||
/* An error message will have already been printed by alloc_and_get_device_info(),
|
|
||||||
* so we can just return, here. */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferOwningPtr<char> extStringBuf(extString);
|
|
||||||
|
|
||||||
return strstr( extString, extensionName ) != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Helper to determine if a device supports an image format */
|
/* Helper to determine if a device supports an image format */
|
||||||
int is_image_format_supported( cl_context context, cl_mem_flags flags, cl_mem_object_type image_type, const cl_image_format *fmt )
|
int is_image_format_supported( cl_context context, cl_mem_flags flags, cl_mem_object_type image_type, const cl_image_format *fmt )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,6 +37,8 @@
|
|||||||
#include <CL/opencl.h>
|
#include <CL/opencl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "deviceInfo.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
@@ -131,9 +133,6 @@ extern int get_max_allowed_work_group_size( cl_context context, cl_kernel kernel
|
|||||||
/* Helper to obtain the biggest allowed 1D work group size on a given device */
|
/* Helper to obtain the biggest allowed 1D work group size on a given device */
|
||||||
extern int get_max_allowed_1d_work_group_size_on_device( cl_device_id device, cl_kernel kernel, size_t *outSize );
|
extern int get_max_allowed_1d_work_group_size_on_device( cl_device_id device, cl_kernel kernel, size_t *outSize );
|
||||||
|
|
||||||
/* Helper to determine if an extension is supported by a device */
|
|
||||||
extern int is_extension_available( cl_device_id device, const char *extensionName );
|
|
||||||
|
|
||||||
/* Helper to determine if a device supports an image format */
|
/* Helper to determine if a device supports an image format */
|
||||||
extern int is_image_format_supported( cl_context context, cl_mem_flags flags, cl_mem_object_type image_type, const cl_image_format *fmt );
|
extern int is_image_format_supported( cl_context context, cl_mem_flags flags, cl_mem_object_type image_type, const cl_image_format *fmt );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user