mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-25 08:19:02 +00:00
Add exceptions as errors in is_extension_available (#732)
is_extension_available is modified to handle errors by throwing exceptions. Contributes to #627 Change-Id: Ie9423df588892a0f8effa03d1cb48bf12400b983 Signed-off-by: Ellen Norris-Thompson <ellen.norris-thompson@arm.com>
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
|
#include <stdexcept>
|
||||||
#include "deviceInfo.h"
|
#include "deviceInfo.h"
|
||||||
#include "errorHelpers.h"
|
#include "errorHelpers.h"
|
||||||
#include "typeWrappers.h"
|
#include "typeWrappers.h"
|
||||||
@@ -20,35 +21,23 @@
|
|||||||
/* Helper to allocate and return a buffer containing device information for the specified device info parameter. */
|
/* 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 )
|
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;
|
size_t size = 0;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if ((err = clGetDeviceInfo(device, param_name, 0, NULL, &size)) != CL_SUCCESS)
|
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",
|
throw std::runtime_error("clGetDeviceInfo failed\n");
|
||||||
param_description, __FILE__, __LINE__, err);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 == size)
|
if (0 == size)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
buffer = malloc(size);
|
auto buffer = new uint8_t[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)
|
if ((err = clGetDeviceInfo(device, param_name, size, buffer, NULL)) != CL_SUCCESS)
|
||||||
{
|
{
|
||||||
free(buffer);
|
delete [] buffer;
|
||||||
log_error( "Error: failed to obtain device %s at %s:%d (err = %d)\n",
|
throw std::runtime_error("clGetDeviceInfo failed\n");
|
||||||
param_description, __FILE__, __LINE__, err );
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
@@ -59,13 +48,6 @@ int is_extension_available(cl_device_id device, const char *extensionName)
|
|||||||
{
|
{
|
||||||
char *extString = alloc_and_get_device_extensions_string(device);
|
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);
|
BufferOwningPtr<char> extStringBuf(extString);
|
||||||
|
|
||||||
return strstr(extString, extensionName) != NULL;
|
return strstr(extString, extensionName) != NULL;
|
||||||
|
|||||||
@@ -359,8 +359,6 @@ static cl_int get_cl_device_info_str(const cl_device_id device, const cl_uint de
|
|||||||
char *extensionsString = alloc_and_get_device_extensions_string(device);
|
char *extensionsString = alloc_and_get_device_extensions_string(device);
|
||||||
if ( NULL == extensionsString )
|
if ( NULL == extensionsString )
|
||||||
{
|
{
|
||||||
/* An error message will have already been printed by alloc_and_get_device_info(),
|
|
||||||
* so we can just return, here. */
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,8 +367,6 @@ static cl_int get_cl_device_info_str(const cl_device_id device, const cl_uint de
|
|||||||
char *versionString = alloc_and_get_device_version_string(device);
|
char *versionString = alloc_and_get_device_version_string(device);
|
||||||
if ( NULL == versionString )
|
if ( NULL == versionString )
|
||||||
{
|
{
|
||||||
/* An error message will have already been printed by alloc_and_get_device_info(),
|
|
||||||
* so we can just return, here. */
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,17 +375,15 @@ static cl_int get_cl_device_info_str(const cl_device_id device, const cl_uint de
|
|||||||
std::ostringstream clDeviceInfoStream;
|
std::ostringstream clDeviceInfoStream;
|
||||||
std::string file_type = get_offline_compilation_file_type_str(compilationMode);
|
std::string file_type = get_offline_compilation_file_type_str(compilationMode);
|
||||||
clDeviceInfoStream << "# OpenCL device info affecting " << file_type << " offline compilation:" << std::endl
|
clDeviceInfoStream << "# OpenCL device info affecting " << file_type << " offline compilation:" << std::endl
|
||||||
<< "CL_DEVICE_ADDRESS_BITS=" << device_address_space_size << std::endl
|
<< "CL_DEVICE_ADDRESS_BITS=" << device_address_space_size << std::endl
|
||||||
<< "CL_DEVICE_EXTENSIONS=\"" << extensionsString << "\"" << std::endl;
|
<< "CL_DEVICE_EXTENSIONS=\"" << extensionsString << "\"" << std::endl;
|
||||||
/* We only need the device's supported IL version(s) when compiling IL
|
/* We only need the device's supported IL version(s) when compiling IL
|
||||||
* that will be loaded with clCreateProgramWithIL() */
|
* that will be loaded with clCreateProgramWithIL() */
|
||||||
if (compilationMode == kSpir_v)
|
if (compilationMode == kSpir_v)
|
||||||
{
|
{
|
||||||
char *ilVersionString = alloc_and_get_device_il_version_string(device);
|
char *ilVersionString = alloc_and_get_device_il_version_string(device);
|
||||||
if ( NULL == ilVersionString )
|
if ( NULL == ilVersionString )
|
||||||
{
|
{
|
||||||
/* An error message will have already been printed by alloc_and_get_device_info(),
|
|
||||||
* so we can just return, here. */
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,6 +394,7 @@ static cl_int get_cl_device_info_str(const cl_device_id device, const cl_uint de
|
|||||||
clDeviceInfoStream << "CL_DEVICE_VERSION=\"" << versionString << "\"" << std::endl;
|
clDeviceInfoStream << "CL_DEVICE_VERSION=\"" << versionString << "\"" << std::endl;
|
||||||
|
|
||||||
clDeviceInfo = clDeviceInfoStream.str();
|
clDeviceInfo = clDeviceInfoStream.str();
|
||||||
|
|
||||||
return CL_SUCCESS;
|
return CL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user