diff --git a/test_common/harness/deviceInfo.cpp b/test_common/harness/deviceInfo.cpp index aeb5607b..7eb13bde 100644 --- a/test_common/harness/deviceInfo.cpp +++ b/test_common/harness/deviceInfo.cpp @@ -13,6 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // +#include #include "deviceInfo.h" #include "errorHelpers.h" #include "typeWrappers.h" @@ -20,35 +21,23 @@ /* 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; + throw std::runtime_error("clGetDeviceInfo failed\n"); } 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; - } + auto buffer = new uint8_t[size]; 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; + delete [] buffer; + throw std::runtime_error("clGetDeviceInfo failed\n"); } 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); - 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 extStringBuf(extString); return strstr(extString, extensionName) != NULL; diff --git a/test_common/harness/kernelHelpers.cpp b/test_common/harness/kernelHelpers.cpp index 34da3d2f..cc2817d8 100644 --- a/test_common/harness/kernelHelpers.cpp +++ b/test_common/harness/kernelHelpers.cpp @@ -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); 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; } @@ -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); 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; } @@ -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::string file_type = get_offline_compilation_file_type_str(compilationMode); clDeviceInfoStream << "# OpenCL device info affecting " << file_type << " offline compilation:" << std::endl - << "CL_DEVICE_ADDRESS_BITS=" << device_address_space_size << std::endl - << "CL_DEVICE_EXTENSIONS=\"" << extensionsString << "\"" << std::endl; + << "CL_DEVICE_ADDRESS_BITS=" << device_address_space_size << std::endl + << "CL_DEVICE_EXTENSIONS=\"" << extensionsString << "\"" << std::endl; /* 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) { char *ilVersionString = alloc_and_get_device_il_version_string(device); 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; } @@ -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; clDeviceInfo = clDeviceInfoStream.str(); + return CL_SUCCESS; }