From 8b34a55cfc9881ea5af01c35b3d69b4d871ff930 Mon Sep 17 00:00:00 2001 From: Stuart Brady Date: Wed, 3 Jul 2019 16:53:20 +0100 Subject: [PATCH] Refactor code for getting CL_DEVICE_ADDRESS_BITS --- test_common/harness/kernelHelpers.c | 73 +++++++++++++++-------------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/test_common/harness/kernelHelpers.c b/test_common/harness/kernelHelpers.c index 16ebb28d..5783b5ea 100644 --- a/test_common/harness/kernelHelpers.c +++ b/test_common/harness/kernelHelpers.c @@ -200,6 +200,40 @@ std::string add_build_options(const std::string &baseName, const char *options) return get_file_name(baseName, i, ""); } +static cl_int get_device_address_bits(cl_context context, cl_uint &device_address_space_size) +{ + cl_uint numDevices = 0; + cl_int error = clGetContextInfo(context, CL_CONTEXT_NUM_DEVICES, sizeof(cl_uint), &numDevices, NULL); + if (error != CL_SUCCESS) + { + print_error(error, "clGetContextInfo failed getting CL_CONTEXT_NUM_DEVICES"); + return error; + } + + std::vector devices(numDevices, 0); + error = clGetContextInfo(context, CL_CONTEXT_DEVICES, numDevices*sizeof(cl_device_id), &devices[0], NULL); + if (error != CL_SUCCESS) + { + print_error(error, "clGetContextInfo failed getting CL_CONTEXT_DEVICES"); + return error; + } + + error = clGetDeviceInfo(devices[0], CL_DEVICE_ADDRESS_BITS, sizeof(cl_uint), &device_address_space_size, NULL); + if (error != CL_SUCCESS) + { + print_error(error, "Unable to obtain device address bits"); + return error; + } + + if (device_address_space_size != 32 && device_address_space_size != 64) + { + print_error(error, "Unexpected number of device address bits"); + return -1; + } + + return CL_SUCCESS; +} + int create_single_kernel_helper_create_program(cl_context context, cl_program *outProgram, unsigned int numKernelLines, @@ -238,44 +272,13 @@ int create_single_kernel_helper_create_program(cl_context context, cl_uint device_address_space_size = 0; if (gOfflineCompilerOutputType == kSpir_v) { - cl_device_id device; - cl_uint numDevices = 0; - cl_int error = clGetContextInfo(context, CL_CONTEXT_NUM_DEVICES, sizeof(cl_uint), &numDevices, 0); + cl_int error = get_device_address_bits(context, device_address_space_size); if (error != CL_SUCCESS) - { - print_error(error, "clGetContextInfo failed"); return error; - } - std::vector devices(numDevices, 0); - error = clGetContextInfo(context, CL_CONTEXT_DEVICES, numDevices*sizeof(cl_device_id), &devices[0], 0); - if (error != CL_SUCCESS) - { - print_error(error, "clGetContextInfo failed"); - return error; - } - - error = clGetContextInfo(context, CL_CONTEXT_DEVICES, numDevices*sizeof(cl_device_id), &devices[0], NULL); - if (error != CL_SUCCESS) - { - print_error(error, "clGetContextInfo failed"); - return error; - } - - if ((0 == device_address_space_size) && ((error = clGetDeviceInfo(devices[0], CL_DEVICE_ADDRESS_BITS, sizeof(cl_uint), &device_address_space_size, NULL)))) - { - print_error(error, "Unable to obtain device address bits"); - return -1; - } - - if (device_address_space_size == 32) - { - outputFilename += ".spv32"; - } - else if (device_address_space_size == 64) - { - outputFilename += ".spv64"; - } + std::ostringstream extension; + extension << ".spv" << device_address_space_size; + outputFilename += extension.str(); } // try to read cached output file when test is run with gForceSpirVGenerate = false