diff --git a/test_common/harness/deviceInfo.cpp b/test_common/harness/deviceInfo.cpp index 97ab8c8553..5b1e7e030e 100644 --- a/test_common/harness/deviceInfo.cpp +++ b/test_common/harness/deviceInfo.cpp @@ -132,3 +132,42 @@ size_t get_max_param_size(cl_device_id device) } return ret; } + +static cl_ulong get_device_info_max_size(cl_device_id device, + cl_device_info info, + unsigned int divisor) +{ + cl_ulong max_size; + + if (divisor == 0) + { + throw std::runtime_error("Allocation divisor should not be 0\n"); + } + + if (clGetDeviceInfo(device, info, sizeof(max_size), &max_size, NULL) + != CL_SUCCESS) + { + throw std::runtime_error("clGetDeviceInfo failed\n"); + } + return max_size / divisor; +} + +cl_ulong get_device_info_max_mem_alloc_size(cl_device_id device, + unsigned int divisor) +{ + return get_device_info_max_size(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, + divisor); +} + +cl_ulong get_device_info_global_mem_size(cl_device_id device, + unsigned int divisor) +{ + return get_device_info_max_size(device, CL_DEVICE_GLOBAL_MEM_SIZE, divisor); +} + +cl_ulong get_device_info_max_constant_buffer_size(cl_device_id device, + unsigned int divisor) +{ + return get_device_info_max_size(device, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, + divisor); +} diff --git a/test_common/harness/deviceInfo.h b/test_common/harness/deviceInfo.h index 912dd198ac..c56f8b58cf 100644 --- a/test_common/harness/deviceInfo.h +++ b/test_common/harness/deviceInfo.h @@ -51,4 +51,16 @@ std::string get_device_name(cl_device_id device); // Returns the maximum size in bytes for Kernel Parameters size_t get_max_param_size(cl_device_id device); +/* We need to use a portion of available alloc size, + * divide it to leave some memory for the platform. */ +#define MAX_DEVICE_MEMORY_SIZE_DIVISOR (2) + +/* Get max allocation size. */ +cl_ulong get_device_info_max_mem_alloc_size(cl_device_id device, + unsigned int divisor = 1); +cl_ulong get_device_info_global_mem_size(cl_device_id device, + unsigned int divisor = 1); +cl_ulong get_device_info_max_constant_buffer_size(cl_device_id device, + unsigned int divisor = 1); + #endif // _deviceInfo_h diff --git a/test_conformance/allocations/allocation_functions.cpp b/test_conformance/allocations/allocation_functions.cpp index ec0c83a17e..dc44224f9b 100644 --- a/test_conformance/allocations/allocation_functions.cpp +++ b/test_conformance/allocations/allocation_functions.cpp @@ -188,27 +188,15 @@ int allocate_size(cl_context context, cl_command_queue *queue, // one we don't end up returning a garbage value *number_of_mems = 0; - error = clGetDeviceInfo(device_id, CL_DEVICE_MAX_MEM_ALLOC_SIZE, - sizeof(max_individual_allocation_size), - &max_individual_allocation_size, NULL); - test_error_abort(error, - "clGetDeviceInfo failed for CL_DEVICE_MAX_MEM_ALLOC_SIZE"); - error = clGetDeviceInfo(device_id, CL_DEVICE_GLOBAL_MEM_SIZE, - sizeof(global_mem_size), &global_mem_size, NULL); - test_error_abort(error, - "clGetDeviceInfo failed for CL_DEVICE_GLOBAL_MEM_SIZE"); + max_individual_allocation_size = + get_device_info_max_mem_alloc_size(device_id); + global_mem_size = get_device_info_global_mem_size(device_id); if (global_mem_size > (cl_ulong)SIZE_MAX) { global_mem_size = (cl_ulong)SIZE_MAX; } - // log_info("Device reports CL_DEVICE_MAX_MEM_ALLOC_SIZE=%llu bytes (%gMB), - // CL_DEVICE_GLOBAL_MEM_SIZE=%llu bytes (%gMB).\n", - // max_individual_allocation_size, - // toMB(max_individual_allocation_size), global_mem_size, - // toMB(global_mem_size)); - if (size_to_allocate > global_mem_size) { log_error("Can not allocate more than the global memory size.\n"); @@ -281,112 +269,115 @@ int allocate_size(cl_context context, cl_command_queue *queue, (int)max_image_args); max_to_allocate = max_image_args; } - } - // Try to allocate the requested amount. - while (amount_allocated != size_to_allocate - && current_allocation < max_to_allocate) - { - - // Determine how much more is needed - allocation_this_time = size_to_allocate - amount_allocated; + // Try to allocate the requested amount. + while (amount_allocated != size_to_allocate + && current_allocation < max_to_allocate) + { - // Bound by the individual allocation size - if (allocation_this_time > max_individual_allocation_size) - allocation_this_time = (size_t)max_individual_allocation_size; + // Determine how much more is needed + allocation_this_time = size_to_allocate - amount_allocated; - // Allocate the largest object possible - result = FAILED_TOO_BIG; - // log_info("\t\tTrying sub-allocation %d at size %gMB.\n", - // current_allocation, toMB(allocation_this_time)); - while (result == FAILED_TOO_BIG && allocation_this_time != 0) - { + // Bound by the individual allocation size + if (allocation_this_time > max_individual_allocation_size) + allocation_this_time = (size_t)max_individual_allocation_size; - // Create the object - result = - do_allocation(context, queue, device_id, allocation_this_time, - type, &mems[current_allocation]); - if (result == SUCCEEDED) + // Allocate the largest object possible + result = FAILED_TOO_BIG; + // log_info("\t\tTrying sub-allocation %d at size %gMB.\n", + // current_allocation, toMB(allocation_this_time)); + while (result == FAILED_TOO_BIG && allocation_this_time != 0) { - // Allocation succeeded, another memory object was added to the - // array - *number_of_mems = (current_allocation + 1); - - // Verify the size is correct to within 1MB. - actual_allocation = - get_actual_allocation_size(mems[current_allocation]); - if (fabs((double)allocation_this_time - - (double)actual_allocation) - > 1024.0 * 1024.0) + + // Create the object + result = do_allocation(context, queue, device_id, + allocation_this_time, type, + &mems[current_allocation]); + if (result == SUCCEEDED) { - log_error("Allocation not of expected size. Expected %gMB, " - "got %gMB.\n", - toMB(allocation_this_time), - toMB(actual_allocation)); - return FAILED_ABORT; + // Allocation succeeded, another memory object was added to + // the array + *number_of_mems = (current_allocation + 1); + + // Verify the size is correct to within 1MB. + actual_allocation = + get_actual_allocation_size(mems[current_allocation]); + if (fabs((double)allocation_this_time + - (double)actual_allocation) + > 1024.0 * 1024.0) + { + log_error( + "Allocation not of expected size. Expected %gMB, " + "got %gMB.\n", + toMB(allocation_this_time), + toMB(actual_allocation)); + return FAILED_ABORT; + } + + // If we are filling the allocation for verification do so + if (force_fill) + { + // log_info("\t\t\tWriting random values to object and + // calculating checksum.\n"); + cl_bool blocking_write = true; + if (type == BUFFER_NON_BLOCKING + || type == IMAGE_READ_NON_BLOCKING + || type == IMAGE_WRITE_NON_BLOCKING) + { + blocking_write = false; + } + result = fill_mem_with_data(context, device_id, queue, + mems[current_allocation], d, + blocking_write); + } } - // If we are filling the allocation for verification do so - if (force_fill) + // If creation failed, try to create a smaller object + if (result == FAILED_TOO_BIG) { - // log_info("\t\t\tWriting random values to object and - // calculating checksum.\n"); - cl_bool blocking_write = true; - if (type == BUFFER_NON_BLOCKING - || type == IMAGE_READ_NON_BLOCKING - || type == IMAGE_WRITE_NON_BLOCKING) + // log_info("\t\t\tAllocation %d failed at size %gMB. Trying + // smaller.\n", current_allocation, + // toMB(allocation_this_time)); + if (allocation_this_time > reduction_amount) + allocation_this_time -= reduction_amount; + else if (reduction_amount > 1) { - blocking_write = false; + reduction_amount /= 2; + } + else + { + allocation_this_time = 0; } - result = fill_mem_with_data(context, device_id, queue, - mems[current_allocation], d, - blocking_write); } } - // If creation failed, try to create a smaller object - if (result == FAILED_TOO_BIG) + if (result == FAILED_ABORT) { - // log_info("\t\t\tAllocation %d failed at size %gMB. Trying - // smaller.\n", current_allocation, toMB(allocation_this_time)); - if (allocation_this_time > reduction_amount) - allocation_this_time -= reduction_amount; - else if (reduction_amount > 1) - { - reduction_amount /= 2; - } - else - { - allocation_this_time = 0; - } + log_error("\t\tAllocation failed.\n"); + return FAILED_ABORT; } - } - - if (result == FAILED_ABORT) - { - log_error("\t\tAllocation failed.\n"); - return FAILED_ABORT; - } - if (!allocation_this_time) - { - log_info("\t\tFailed to allocate %gMB across several objects.\n", - toMB(size_to_allocate)); - return FAILED_TOO_BIG; - } + if (!allocation_this_time) + { + log_info( + "\t\tFailed to allocate %gMB across several objects.\n", + toMB(size_to_allocate)); + return FAILED_TOO_BIG; + } - // Otherwise we succeeded - if (result != SUCCEEDED) - { - log_error("Test logic error."); - exit(-1); - } - amount_allocated += allocation_this_time; + // Otherwise we succeeded + if (result != SUCCEEDED) + { + log_error("Test logic error."); + exit(-1); + } + amount_allocated += allocation_this_time; - *final_size = amount_allocated; + *final_size = amount_allocated; - current_allocation++; + current_allocation++; + } } log_info("\t\tSucceeded in allocating %gMB using %d memory objects.\n", diff --git a/test_conformance/allocations/main.cpp b/test_conformance/allocations/main.cpp index 65d2699f3b..80a5ed2e1f 100644 --- a/test_conformance/allocations/main.cpp +++ b/test_conformance/allocations/main.cpp @@ -24,8 +24,10 @@ typedef long long unsigned llu; +#define REDUCTION_PERCENTAGE_DEFAULT 50 + int g_repetition_count = 1; -int g_reduction_percentage = 100; +int g_reduction_percentage = REDUCTION_PERCENTAGE_DEFAULT; int g_write_allocations = 1; int g_multiple_allocations = 0; int g_execute_kernel = 1; @@ -44,24 +46,9 @@ test_status init_cl(cl_device_id device) { int error; - error = clGetDeviceInfo(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, - sizeof(g_max_individual_allocation_size), - &g_max_individual_allocation_size, NULL); - if (error) - { - print_error(error, - "clGetDeviceInfo failed for CL_DEVICE_MAX_MEM_ALLOC_SIZE"); - return TEST_FAIL; - } - error = - clGetDeviceInfo(device, CL_DEVICE_GLOBAL_MEM_SIZE, - sizeof(g_global_mem_size), &g_global_mem_size, NULL); - if (error) - { - print_error(error, - "clGetDeviceInfo failed for CL_DEVICE_GLOBAL_MEM_SIZE"); - return TEST_FAIL; - } + g_max_individual_allocation_size = + get_device_info_max_mem_alloc_size(device); + g_global_mem_size = get_device_info_global_mem_size(device); log_info("Device reports CL_DEVICE_MAX_MEM_ALLOC_SIZE=%llu bytes (%gMB), " "CL_DEVICE_GLOBAL_MEM_SIZE=%llu bytes (%gMB).\n", diff --git a/test_conformance/api/test_api_min_max.cpp b/test_conformance/api/test_api_min_max.cpp index 3ced8927a2..9a0c2a9e03 100644 --- a/test_conformance/api/test_api_min_max.cpp +++ b/test_conformance/api/test_api_min_max.cpp @@ -112,6 +112,8 @@ const char *sample_const_max_arg_kernel_pattern = "\n" "}\n"; +#define MAX_REDUCTION_FACTOR 4 + int test_min_max_thread_dimensions(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) { @@ -564,7 +566,7 @@ int test_min_max_mem_alloc_size(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) { int error; - cl_ulong maxAllocSize, memSize, minSizeToTry; + cl_ulong maxAllocSize, memSize, minSizeToTry, currentSize; clMemWrapper memHdl; cl_ulong requiredAllocSize; @@ -574,14 +576,19 @@ int test_min_max_mem_alloc_size(cl_device_id deviceID, cl_context context, else requiredAllocSize = 128 * 1024 * 1024; - /* Get the max mem alloc size */ - error = clGetDeviceInfo(deviceID, CL_DEVICE_MAX_MEM_ALLOC_SIZE, - sizeof(maxAllocSize), &maxAllocSize, NULL); - test_error(error, "Unable to get max mem alloc size from device"); + /* Get the max mem alloc size, limit the alloc to half of the available + * memory */ + maxAllocSize = get_device_info_max_mem_alloc_size( + deviceID, MAX_DEVICE_MEMORY_SIZE_DIVISOR); + memSize = get_device_info_global_mem_size(deviceID, + MAX_DEVICE_MEMORY_SIZE_DIVISOR); - error = clGetDeviceInfo(deviceID, CL_DEVICE_GLOBAL_MEM_SIZE, - sizeof(memSize), &memSize, NULL); - test_error(error, "Unable to get global memory size from device"); + if (memSize < maxAllocSize) + { + log_info("Global memory size is less than max allocation size, using " + "that.\n"); + maxAllocSize = memSize; + } if (memSize > (cl_ulong)SIZE_MAX) { @@ -590,69 +597,36 @@ int test_min_max_mem_alloc_size(cl_device_id deviceID, cl_context context, if (maxAllocSize < requiredAllocSize) { - log_error("ERROR: Reported max allocation size is less than required " - "%lldMB! (%llu or %lluMB, from a total mem size of %lldMB)\n", - (requiredAllocSize / 1024) / 1024, maxAllocSize, - (maxAllocSize / 1024) / 1024, (memSize / 1024) / 1024); - return -1; - } - - requiredAllocSize = ((memSize / 4) > (1024 * 1024 * 1024)) - ? 1024 * 1024 * 1024 - : memSize / 4; - - if (gIsEmbedded) - requiredAllocSize = (requiredAllocSize < 1 * 1024 * 1024) - ? 1 * 1024 * 1024 - : requiredAllocSize; - else - requiredAllocSize = (requiredAllocSize < 128 * 1024 * 1024) - ? 128 * 1024 * 1024 - : requiredAllocSize; - - if (maxAllocSize < requiredAllocSize) - { - log_error( - "ERROR: Reported max allocation size is less than required of " - "total memory! (%llu or %lluMB, from a total mem size of %lluMB)\n", - maxAllocSize, (maxAllocSize / 1024) / 1024, - (requiredAllocSize / 1024) / 1024); + log_error("ERROR: Reported max allocation size is less than required"); return -1; } log_info("Reported max allocation size of %lld bytes (%gMB) and global mem " "size of %lld bytes (%gMB).\n", - maxAllocSize, maxAllocSize / (1024.0 * 1024.0), requiredAllocSize, - requiredAllocSize / (1024.0 * 1024.0)); - - if (memSize < maxAllocSize) - { - log_info("Global memory size is less than max allocation size, using " - "that.\n"); - maxAllocSize = memSize; - } + maxAllocSize, maxAllocSize / (1024.0 * 1024.0), memSize, + memSize / (1024.0 * 1024.0)); minSizeToTry = maxAllocSize / 16; - while (maxAllocSize > (maxAllocSize / 4)) + currentSize = maxAllocSize; + while (currentSize >= maxAllocSize / MAX_REDUCTION_FACTOR) { - log_info("Trying to create a buffer of size of %lld bytes (%gMB).\n", - maxAllocSize, (double)maxAllocSize / (1024.0 * 1024.0)); - memHdl = clCreateBuffer(context, CL_MEM_READ_ONLY, (size_t)maxAllocSize, + currentSize, (double)currentSize / (1024.0 * 1024.0)); + memHdl = clCreateBuffer(context, CL_MEM_READ_ONLY, (size_t)currentSize, NULL, &error); if (error == CL_MEM_OBJECT_ALLOCATION_FAILURE || error == CL_OUT_OF_RESOURCES || error == CL_OUT_OF_HOST_MEMORY) { log_info("\tAllocation failed at size of %lld bytes (%gMB).\n", - maxAllocSize, (double)maxAllocSize / (1024.0 * 1024.0)); - maxAllocSize -= minSizeToTry; + currentSize, (double)currentSize / (1024.0 * 1024.0)); + currentSize -= minSizeToTry; continue; } test_error(error, "clCreateBuffer failed for maximum sized buffer."); return 0; } - log_error("Failed to allocate even %lld bytes (%gMB).\n", maxAllocSize, - (double)maxAllocSize / (1024.0 * 1024.0)); + log_error("Failed to allocate even %lld bytes (%gMB).\n", currentSize, + (double)currentSize / (1024.0 * 1024.0)); return -1; } @@ -709,9 +683,8 @@ int test_min_max_image_2d_width(cl_device_id deviceID, cl_context context, } /* Verify that we can actually allocate an image that large */ - error = clGetDeviceInfo(deviceID, CL_DEVICE_MAX_MEM_ALLOC_SIZE, - sizeof(maxAllocSize), &maxAllocSize, NULL); - test_error(error, "Unable to get CL_DEVICE_MAX_MEM_ALLOC_SIZE."); + maxAllocSize = get_device_info_max_mem_alloc_size( + deviceID, MAX_DEVICE_MEMORY_SIZE_DIVISOR); if ((cl_ulong)maxDimension * 1 * 4 > maxAllocSize) { log_error("Can not allocate a large enough image (min size: %lld " @@ -787,9 +760,8 @@ int test_min_max_image_2d_height(cl_device_id deviceID, cl_context context, } /* Verify that we can actually allocate an image that large */ - error = clGetDeviceInfo(deviceID, CL_DEVICE_MAX_MEM_ALLOC_SIZE, - sizeof(maxAllocSize), &maxAllocSize, NULL); - test_error(error, "Unable to get CL_DEVICE_MAX_MEM_ALLOC_SIZE."); + maxAllocSize = get_device_info_max_mem_alloc_size( + deviceID, MAX_DEVICE_MEMORY_SIZE_DIVISOR); if ((cl_ulong)maxDimension * 1 * 4 > maxAllocSize) { log_error("Can not allocate a large enough image (min size: %lld " @@ -855,9 +827,8 @@ int test_min_max_image_3d_width(cl_device_id deviceID, cl_context context, } /* Verify that we can actually allocate an image that large */ - error = clGetDeviceInfo(deviceID, CL_DEVICE_MAX_MEM_ALLOC_SIZE, - sizeof(maxAllocSize), &maxAllocSize, NULL); - test_error(error, "Unable to get CL_DEVICE_MAX_MEM_ALLOC_SIZE."); + maxAllocSize = get_device_info_max_mem_alloc_size( + deviceID, MAX_DEVICE_MEMORY_SIZE_DIVISOR); if ((cl_ulong)maxDimension * 2 * 4 > maxAllocSize) { log_error("Can not allocate a large enough image (min size: %lld " @@ -924,9 +895,8 @@ int test_min_max_image_3d_height(cl_device_id deviceID, cl_context context, } /* Verify that we can actually allocate an image that large */ - error = clGetDeviceInfo(deviceID, CL_DEVICE_MAX_MEM_ALLOC_SIZE, - sizeof(maxAllocSize), &maxAllocSize, NULL); - test_error(error, "Unable to get CL_DEVICE_MAX_MEM_ALLOC_SIZE."); + maxAllocSize = get_device_info_max_mem_alloc_size( + deviceID, MAX_DEVICE_MEMORY_SIZE_DIVISOR); if ((cl_ulong)maxDimension * 2 * 4 > maxAllocSize) { log_error("Can not allocate a large enough image (min size: %lld " @@ -994,9 +964,8 @@ int test_min_max_image_3d_depth(cl_device_id deviceID, cl_context context, } /* Verify that we can actually allocate an image that large */ - error = clGetDeviceInfo(deviceID, CL_DEVICE_MAX_MEM_ALLOC_SIZE, - sizeof(maxAllocSize), &maxAllocSize, NULL); - test_error(error, "Unable to get CL_DEVICE_MAX_MEM_ALLOC_SIZE."); + maxAllocSize = get_device_info_max_mem_alloc_size( + deviceID, MAX_DEVICE_MEMORY_SIZE_DIVISOR); if ((cl_ulong)maxDimension * 1 * 4 > maxAllocSize) { log_error("Can not allocate a large enough image (min size: %lld " @@ -1063,9 +1032,8 @@ int test_min_max_image_array_size(cl_device_id deviceID, cl_context context, } /* Verify that we can actually allocate an image that large */ - error = clGetDeviceInfo(deviceID, CL_DEVICE_MAX_MEM_ALLOC_SIZE, - sizeof(maxAllocSize), &maxAllocSize, NULL); - test_error(error, "Unable to get CL_DEVICE_MAX_MEM_ALLOC_SIZE."); + maxAllocSize = get_device_info_max_mem_alloc_size( + deviceID, MAX_DEVICE_MEMORY_SIZE_DIVISOR); if ((cl_ulong)maxDimension * 1 * 4 > maxAllocSize) { log_error("Can not allocate a large enough image (min size: %lld " @@ -1105,10 +1073,9 @@ int test_min_max_image_buffer_size(cl_device_id deviceID, cl_context context, PASSIVE_REQUIRE_IMAGE_SUPPORT(deviceID); - /* Get the max memory allocation size */ - error = clGetDeviceInfo(deviceID, CL_DEVICE_MAX_MEM_ALLOC_SIZE, - sizeof(maxAllocSize), &maxAllocSize, NULL); - test_error(error, "Unable to get CL_DEVICE_MAX_MEM_ALLOC_SIZE."); + /* Get the max memory allocation size, divide it */ + maxAllocSize = get_device_info_max_mem_alloc_size( + deviceID, MAX_DEVICE_MEMORY_SIZE_DIVISOR); /* Get the max image array width */ error = @@ -1559,7 +1526,6 @@ int test_min_max_samplers(cl_device_id deviceID, cl_context context, return 0; } -#define PASSING_FRACTION 4 int test_min_max_constant_buffer_size(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) { @@ -1575,9 +1541,8 @@ int test_min_max_constant_buffer_size(cl_device_id deviceID, cl_context context, MTdata d; /* Verify our test buffer won't be bigger than allowed */ - error = clGetDeviceInfo(deviceID, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, - sizeof(maxSize), &maxSize, 0); - test_error(error, "Unable to get max constant buffer size"); + maxSize = get_device_info_max_constant_buffer_size( + deviceID, MAX_DEVICE_MEMORY_SIZE_DIVISOR); if ((0 == gIsEmbedded && maxSize < 64L * 1024L) || maxSize < 1L * 1024L) { @@ -1589,16 +1554,14 @@ int test_min_max_constant_buffer_size(cl_device_id deviceID, cl_context context, log_info("Reported max constant buffer size of %lld bytes.\n", maxSize); - // Limit test buffer size to 1/8 of CL_DEVICE_GLOBAL_MEM_SIZE - error = clGetDeviceInfo(deviceID, CL_DEVICE_GLOBAL_MEM_SIZE, - sizeof(maxGlobalSize), &maxGlobalSize, 0); - test_error(error, "Unable to get CL_DEVICE_GLOBAL_MEM_SIZE"); + /* We have four buffers allocations */ + maxGlobalSize = get_device_info_global_mem_size( + deviceID, MAX_DEVICE_MEMORY_SIZE_DIVISOR * 4); - if (maxSize > maxGlobalSize / 8) maxSize = maxGlobalSize / 8; + if (maxSize > maxGlobalSize) maxSize = maxGlobalSize; - error = clGetDeviceInfo(deviceID, CL_DEVICE_MAX_MEM_ALLOC_SIZE, - sizeof(maxAllocSize), &maxAllocSize, 0); - test_error(error, "Unable to get CL_DEVICE_MAX_MEM_ALLOC_SIZE "); + maxAllocSize = get_device_info_max_mem_alloc_size( + deviceID, MAX_DEVICE_MEMORY_SIZE_DIVISOR); if (maxSize > maxAllocSize) maxSize = maxAllocSize; @@ -1615,7 +1578,7 @@ int test_min_max_constant_buffer_size(cl_device_id deviceID, cl_context context, currentSize = maxSize; int allocPassed = 0; d = init_genrand(gRandomSeed); - while (!allocPassed && currentSize >= maxSize / PASSING_FRACTION) + while (!allocPassed && currentSize >= maxSize / MAX_REDUCTION_FACTOR) { log_info("Attempting to allocate constant buffer of size %lld bytes\n", maxSize); @@ -1741,7 +1704,7 @@ int test_min_max_constant_buffer_size(cl_device_id deviceID, cl_context context, if (allocPassed) { - if (currentSize < maxSize / PASSING_FRACTION) + if (currentSize < maxSize / MAX_REDUCTION_FACTOR) { log_error("Failed to allocate at least 1/8 of the reported " "constant size.\n"); @@ -1808,10 +1771,9 @@ int test_min_max_constant_args(cl_device_id deviceID, cl_context context, return -1; } - error = clGetDeviceInfo(deviceID, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, - sizeof(maxSize), &maxSize, 0); - test_error(error, "Unable to get max constant buffer size"); - individualBufferSize = (maxSize / 2) / maxArgs; + maxSize = get_device_info_max_constant_buffer_size( + deviceID, MAX_DEVICE_MEMORY_SIZE_DIVISOR); + individualBufferSize = ((int)maxSize / 2) / maxArgs; log_info( "Reported max constant arg count of %u and max constant buffer " diff --git a/test_conformance/api/test_kernels.cpp b/test_conformance/api/test_kernels.cpp index d25410ba2f..82bebabc9d 100644 --- a/test_conformance/api/test_kernels.cpp +++ b/test_conformance/api/test_kernels.cpp @@ -389,8 +389,8 @@ int test_set_kernel_arg_constant(cl_device_id deviceID, cl_context context, cl_c std::vector randomTestDataB(num_elements); /* Verify our test buffer won't be bigger than allowed */ - error = clGetDeviceInfo( deviceID, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, sizeof( maxSize ), &maxSize, 0 ); - test_error( error, "Unable to get max constant buffer size" ); + maxSize = get_device_info_max_constant_buffer_size( + deviceID, MAX_DEVICE_MEMORY_SIZE_DIVISOR); if (maxSize < sizeof(cl_int) * num_elements) { log_error( "ERROR: Unable to test constant argument to kernel: max size of constant buffer is reported as %d!\n", (int)maxSize ); diff --git a/test_conformance/images/clGetInfo/test_1D.cpp b/test_conformance/images/clGetInfo/test_1D.cpp index 7e044856f3..577916a08f 100644 --- a/test_conformance/images/clGetInfo/test_1D.cpp +++ b/test_conformance/images/clGetInfo/test_1D.cpp @@ -1,6 +1,6 @@ // // Copyright (c) 2017 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 @@ -15,79 +15,106 @@ // #include "../testBase.h" -extern int test_get_image_info_single( cl_context context, image_descriptor *imageInfo, MTdata d, cl_mem_flags flags, size_t row_pitch, size_t slice_pitch ); +extern int test_get_image_info_single(cl_context context, + image_descriptor *imageInfo, MTdata d, + cl_mem_flags flags, size_t row_pitch, + size_t slice_pitch); -int test_get_image_info_1D( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags ) +int test_get_image_info_1D(cl_device_id device, cl_context context, + cl_image_format *format, cl_mem_flags flags) { size_t maxWidth; cl_ulong maxAllocSize, memSize; image_descriptor imageInfo = { 0 }; - RandomSeed seed( gRandomSeed ); + RandomSeed seed(gRandomSeed); size_t pixelSize; - cl_mem_flags all_host_ptr_flags[5] = { - flags, - CL_MEM_ALLOC_HOST_PTR | flags, - CL_MEM_COPY_HOST_PTR | flags, - CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | flags, - CL_MEM_USE_HOST_PTR | flags - }; + cl_mem_flags all_host_ptr_flags[5] = { flags, CL_MEM_ALLOC_HOST_PTR | flags, + CL_MEM_COPY_HOST_PTR | flags, + CL_MEM_ALLOC_HOST_PTR + | CL_MEM_COPY_HOST_PTR | flags, + CL_MEM_USE_HOST_PTR | flags }; memset(&imageInfo, 0x0, sizeof(image_descriptor)); imageInfo.type = CL_MEM_OBJECT_IMAGE1D; imageInfo.format = format; - pixelSize = get_pixel_size( imageInfo.format ); + pixelSize = get_pixel_size(imageInfo.format); + + int error = clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_WIDTH, + sizeof(maxWidth), &maxWidth, NULL); + test_error(error, "Unable to get max image 1D size from device"); - int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL ); - test_error( error, "Unable to get max image 1D size from device" ); + /* Reduce the size used by the test by half */ + maxAllocSize = get_device_info_max_mem_alloc_size( + device, MAX_DEVICE_MEMORY_SIZE_DIVISOR); + memSize = + get_device_info_global_mem_size(device, MAX_DEVICE_MEMORY_SIZE_DIVISOR); - if (memSize > (cl_ulong)SIZE_MAX) { - memSize = (cl_ulong)SIZE_MAX; - maxAllocSize = (cl_ulong)SIZE_MAX; - } + if (memSize > (cl_ulong)SIZE_MAX) + { + memSize = (cl_ulong)SIZE_MAX; + } - if( gTestSmallImages ) + if (gTestSmallImages) { - for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ ) + for (imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++) { imageInfo.rowPitch = imageInfo.width * pixelSize; - for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++) + for (unsigned int j = 0; + j < sizeof(all_host_ptr_flags) / sizeof(cl_mem_flags); j++) { - if( gDebugTrace ) - log_info( " at size %d (flags[%u] 0x%x pitch %d)\n", (int)imageInfo.width, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch ); - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) ) + if (gDebugTrace) + log_info(" at size %d (flags[%u] 0x%x pitch %d)\n", + (int)imageInfo.width, j, + (unsigned int)all_host_ptr_flags[j], + (int)imageInfo.rowPitch); + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], 0, 0)) return -1; - if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) ) + if (all_host_ptr_flags[j] + & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) + { // skip test when host_ptr is NULL + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], + imageInfo.rowPitch, 0)) return -1; } } } } - else if( gTestMaxImages ) + else if (gTestMaxImages) { // Try a specific set of maximum sizes size_t numbeOfSizes; size_t sizes[100][3]; - get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, 1, 1, 1, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE1D, imageInfo.format); + get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, 1, 1, 1, + maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE1D, + imageInfo.format); - for( size_t idx = 0; idx < numbeOfSizes; idx++ ) + for (size_t idx = 0; idx < numbeOfSizes; idx++) { - imageInfo.width = sizes[ idx ][ 0 ]; + imageInfo.width = sizes[idx][0]; imageInfo.rowPitch = imageInfo.width * pixelSize; - log_info( "Testing %d x 1\n", (int)sizes[ idx ][ 0 ]); - for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++) + log_info("Testing %d x 1\n", (int)sizes[idx][0]); + for (unsigned int j = 0; + j < sizeof(all_host_ptr_flags) / sizeof(cl_mem_flags); j++) { - if( gDebugTrace ) - log_info( " at max size %d (flags[%u] 0x%x pitch %d)\n", (int)imageInfo.width, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch ); - if( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) ) + if (gDebugTrace) + log_info(" at max size %d (flags[%u] 0x%x pitch %d)\n", + (int)imageInfo.width, j, + (unsigned int)all_host_ptr_flags[j], + (int)imageInfo.rowPitch); + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], 0, 0)) return -1; - if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL - if( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) ) + if (all_host_ptr_flags[j] + & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) + { // skip test when host_ptr is NULL + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], + imageInfo.rowPitch, 0)) return -1; } } @@ -95,35 +122,48 @@ int test_get_image_info_1D( cl_device_id device, cl_context context, cl_image_fo } else { - for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ ) + for (int i = 0; i < NUM_IMAGE_ITERATIONS; i++) { cl_ulong size; - // Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that - // image, the result array, plus offset arrays, will fit in the global ram space + // Loop until we get a size that a) will fit in the max alloc size + // and b) that an allocation of that image, the result array, plus + // offset arrays, will fit in the global ram space do { - imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed ); + imageInfo.width = + (size_t)random_log_in_range(16, (int)maxWidth / 32, seed); imageInfo.rowPitch = imageInfo.width * pixelSize; - size_t extraWidth = (int)random_log_in_range( 0, 64, seed ); + size_t extraWidth = (int)random_log_in_range(0, 64, seed); imageInfo.rowPitch += extraWidth; - do { + do + { extraWidth++; imageInfo.rowPitch += extraWidth; } while ((imageInfo.rowPitch % pixelSize) != 0); size = (cl_ulong)imageInfo.rowPitch * 4; - } while( size > maxAllocSize || ( size * 3 ) > memSize ); + } while (size > maxAllocSize || (size * 3) > memSize); - for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++) + for (unsigned int j = 0; + j < sizeof(all_host_ptr_flags) / sizeof(cl_mem_flags); j++) { - if( gDebugTrace ) - log_info( " at size %d (flags[%u] 0x%x pitch %d) out of %d\n", (int)imageInfo.width, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch, (int)maxWidth ); - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) ) + if (gDebugTrace) + log_info( + " at size %d (flags[%u] 0x%x pitch %d) out of %d\n", + (int)imageInfo.width, j, + (unsigned int)all_host_ptr_flags[j], + (int)imageInfo.rowPitch, (int)maxWidth); + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], 0, 0)) return -1; - if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) ) + if (all_host_ptr_flags[j] + & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) + { // skip test when host_ptr is NULL + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], + imageInfo.rowPitch, 0)) return -1; } } diff --git a/test_conformance/images/clGetInfo/test_1D_2D_array.cpp b/test_conformance/images/clGetInfo/test_1D_2D_array.cpp index c35bf22b1c..fa3aaa08d5 100644 --- a/test_conformance/images/clGetInfo/test_1D_2D_array.cpp +++ b/test_conformance/images/clGetInfo/test_1D_2D_array.cpp @@ -1,6 +1,6 @@ // // Copyright (c) 2017 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 @@ -15,120 +15,167 @@ // #include "../testBase.h" -extern int test_get_image_info_single( cl_context context, image_descriptor *imageInfo, MTdata d, cl_mem_flags flags, size_t row_pitch, size_t slice_pitch ); +extern int test_get_image_info_single(cl_context context, + image_descriptor *imageInfo, MTdata d, + cl_mem_flags flags, size_t row_pitch, + size_t slice_pitch); -int test_get_image_info_1D_array( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags ) +int test_get_image_info_1D_array(cl_device_id device, cl_context context, + cl_image_format *format, cl_mem_flags flags) { size_t maxWidth, maxArraySize; cl_ulong maxAllocSize, memSize; image_descriptor imageInfo = { 0 }; - RandomSeed seed( gRandomSeed ); + RandomSeed seed(gRandomSeed); - cl_mem_flags all_host_ptr_flags[5] = { - flags, - CL_MEM_ALLOC_HOST_PTR | flags, - CL_MEM_COPY_HOST_PTR | flags, - CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | flags, - CL_MEM_USE_HOST_PTR | flags - }; + cl_mem_flags all_host_ptr_flags[5] = { flags, CL_MEM_ALLOC_HOST_PTR | flags, + CL_MEM_COPY_HOST_PTR | flags, + CL_MEM_ALLOC_HOST_PTR + | CL_MEM_COPY_HOST_PTR | flags, + CL_MEM_USE_HOST_PTR | flags }; memset(&imageInfo, 0x0, sizeof(image_descriptor)); imageInfo.format = format; imageInfo.type = CL_MEM_OBJECT_IMAGE1D_ARRAY; - int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, sizeof( maxArraySize ), &maxArraySize, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL ); - test_error( error, "Unable to get max image 1D array size from device" ); + int error = clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_WIDTH, + sizeof(maxWidth), &maxWidth, NULL); + error |= clGetDeviceInfo(device, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, + sizeof(maxArraySize), &maxArraySize, NULL); + test_error(error, "Unable to get max image 1D array size from device"); + + /* Reduce the size used by the test by half */ + maxAllocSize = get_device_info_max_mem_alloc_size( + device, MAX_DEVICE_MEMORY_SIZE_DIVISOR); + memSize = + get_device_info_global_mem_size(device, MAX_DEVICE_MEMORY_SIZE_DIVISOR); - if (memSize > (cl_ulong)SIZE_MAX) { - memSize = (cl_ulong)SIZE_MAX; - maxAllocSize = (cl_ulong)SIZE_MAX; - } + if (memSize > (cl_ulong)SIZE_MAX) + { + memSize = (cl_ulong)SIZE_MAX; + } - if( gTestSmallImages ) + if (gTestSmallImages) { - for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ ) + for (imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++) { - imageInfo.rowPitch = imageInfo.width * get_pixel_size( imageInfo.format ); + imageInfo.rowPitch = + imageInfo.width * get_pixel_size(imageInfo.format); imageInfo.slicePitch = imageInfo.rowPitch; - for( imageInfo.arraySize = 2; imageInfo.arraySize < 9; imageInfo.arraySize++ ) + for (imageInfo.arraySize = 2; imageInfo.arraySize < 9; + imageInfo.arraySize++) { - for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++) + for (unsigned int j = 0; + j < sizeof(all_host_ptr_flags) / sizeof(cl_mem_flags); j++) { - if( gDebugTrace ) - log_info( " at size %d,%d (flags[%u] 0x%x pitch %d)\n", (int)imageInfo.width, (int)imageInfo.arraySize, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch ); - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) ) + if (gDebugTrace) + log_info(" at size %d,%d (flags[%u] 0x%x pitch %d)\n", + (int)imageInfo.width, (int)imageInfo.arraySize, + j, (unsigned int)all_host_ptr_flags[j], + (int)imageInfo.rowPitch); + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], 0, 0)) return -1; - if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) ) + if (all_host_ptr_flags[j] + & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) + { // skip test when host_ptr is NULL + if (test_get_image_info_single( + context, &imageInfo, seed, + all_host_ptr_flags[j], imageInfo.rowPitch, 0)) return -1; } } } } } - else if( gTestMaxImages ) + else if (gTestMaxImages) { // Try a specific set of maximum sizes size_t numbeOfSizes; size_t sizes[100][3]; - get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, 1, 1, maxArraySize, maxAllocSize, memSize, - CL_MEM_OBJECT_IMAGE1D_ARRAY, imageInfo.format); + get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, 1, 1, maxArraySize, + maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE1D_ARRAY, + imageInfo.format); - for( size_t idx = 0; idx < numbeOfSizes; idx++ ) + for (size_t idx = 0; idx < numbeOfSizes; idx++) { - imageInfo.width = sizes[ idx ][ 0 ]; - imageInfo.arraySize = sizes [ idx] [ 2 ]; - imageInfo.rowPitch = imageInfo.width * get_pixel_size( imageInfo.format ); + imageInfo.width = sizes[idx][0]; + imageInfo.arraySize = sizes[idx][2]; + imageInfo.rowPitch = + imageInfo.width * get_pixel_size(imageInfo.format); imageInfo.slicePitch = imageInfo.rowPitch; - log_info( "Testing %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 2 ] ); - for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++) + log_info("Testing %d x %d\n", (int)sizes[idx][0], + (int)sizes[idx][2]); + for (unsigned int j = 0; + j < sizeof(all_host_ptr_flags) / sizeof(cl_mem_flags); j++) { - if( gDebugTrace ) - log_info( " at max size %d,%d (flags[%u] 0x%x pitch %d)\n", (int)imageInfo.width, (int)imageInfo.arraySize, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch ); - if( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) ) - return -1; - if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL - if( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) ) - return -1; - } + if (gDebugTrace) + log_info(" at max size %d,%d (flags[%u] 0x%x pitch %d)\n", + (int)imageInfo.width, (int)imageInfo.arraySize, j, + (unsigned int)all_host_ptr_flags[j], + (int)imageInfo.rowPitch); + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], 0, 0)) + return -1; + if (all_host_ptr_flags[j] + & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) + { // skip test when host_ptr is NULL + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], + imageInfo.rowPitch, 0)) + return -1; + } } - } + } } else { - for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ ) + for (int i = 0; i < NUM_IMAGE_ITERATIONS; i++) { cl_ulong size; - // Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that - // image, the result array, plus offset arrays, will fit in the global ram space + // Loop until we get a size that a) will fit in the max alloc size + // and b) that an allocation of that image, the result array, plus + // offset arrays, will fit in the global ram space do { - imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed ); - imageInfo.arraySize = (size_t)random_log_in_range( 16, (int)maxArraySize / 32, seed ); + imageInfo.width = + (size_t)random_log_in_range(16, (int)maxWidth / 32, seed); + imageInfo.arraySize = (size_t)random_log_in_range( + 16, (int)maxArraySize / 32, seed); - imageInfo.rowPitch = imageInfo.width * get_pixel_size( imageInfo.format ); + imageInfo.rowPitch = + imageInfo.width * get_pixel_size(imageInfo.format); - size_t extraWidth = (int)random_log_in_range( 0, 64, seed ); + size_t extraWidth = (int)random_log_in_range(0, 64, seed); imageInfo.rowPitch += extraWidth; imageInfo.slicePitch = imageInfo.rowPitch; - size = (cl_ulong)imageInfo.slicePitch * (cl_ulong)imageInfo.arraySize * 4 * 4; - } while( size > maxAllocSize || ( size * 3 ) > memSize ); + size = (cl_ulong)imageInfo.slicePitch + * (cl_ulong)imageInfo.arraySize * 4 * 4; + } while (size > maxAllocSize || (size * 3) > memSize); - for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++) + for (unsigned int j = 0; + j < sizeof(all_host_ptr_flags) / sizeof(cl_mem_flags); j++) { - if( gDebugTrace ) - log_info( " at size %d,%d (flags[%u] 0x%x pitch %d) out of %d,%d\n", (int)imageInfo.width, (int)imageInfo.arraySize, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch, (int)maxWidth, (int)maxArraySize ); - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) ) + if (gDebugTrace) + log_info(" at size %d,%d (flags[%u] 0x%x pitch %d) out " + "of %d,%d\n", + (int)imageInfo.width, (int)imageInfo.arraySize, j, + (unsigned int)all_host_ptr_flags[j], + (int)imageInfo.rowPitch, (int)maxWidth, + (int)maxArraySize); + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], 0, 0)) return -1; - if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) ) + if (all_host_ptr_flags[j] + & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) + { // skip test when host_ptr is NULL + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], + imageInfo.rowPitch, 0)) return -1; } } @@ -139,58 +186,80 @@ int test_get_image_info_1D_array( cl_device_id device, cl_context context, cl_im } -int test_get_image_info_2D_array( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags ) +int test_get_image_info_2D_array(cl_device_id device, cl_context context, + cl_image_format *format, cl_mem_flags flags) { size_t maxWidth, maxHeight, maxArraySize; cl_ulong maxAllocSize, memSize; image_descriptor imageInfo = { 0 }; - RandomSeed seed( gRandomSeed ); + RandomSeed seed(gRandomSeed); size_t pixelSize; - cl_mem_flags all_host_ptr_flags[5] = { - flags, - CL_MEM_ALLOC_HOST_PTR | flags, - CL_MEM_COPY_HOST_PTR | flags, - CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | flags, - CL_MEM_USE_HOST_PTR | flags - }; + cl_mem_flags all_host_ptr_flags[5] = { flags, CL_MEM_ALLOC_HOST_PTR | flags, + CL_MEM_COPY_HOST_PTR | flags, + CL_MEM_ALLOC_HOST_PTR + | CL_MEM_COPY_HOST_PTR | flags, + CL_MEM_USE_HOST_PTR | flags }; memset(&imageInfo, 0x0, sizeof(image_descriptor)); imageInfo.format = format; imageInfo.type = CL_MEM_OBJECT_IMAGE2D_ARRAY; - pixelSize = get_pixel_size( imageInfo.format ); - - int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_HEIGHT, sizeof( maxHeight ), &maxHeight, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, sizeof( maxArraySize ), &maxArraySize, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL ); - test_error( error, "Unable to get max image 1D array size from device" ); - - if (memSize > (cl_ulong)SIZE_MAX) { - memSize = (cl_ulong)SIZE_MAX; - maxAllocSize = (cl_ulong)SIZE_MAX; - } + pixelSize = get_pixel_size(imageInfo.format); + + int error = clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_WIDTH, + sizeof(maxWidth), &maxWidth, NULL); + error |= clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_HEIGHT, + sizeof(maxHeight), &maxHeight, NULL); + error |= clGetDeviceInfo(device, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, + sizeof(maxArraySize), &maxArraySize, NULL); + test_error(error, "Unable to get max image 1D array size from device"); + + /* Reduce the size used by the test by half */ + maxAllocSize = get_device_info_max_mem_alloc_size( + device, MAX_DEVICE_MEMORY_SIZE_DIVISOR); + memSize = + get_device_info_global_mem_size(device, MAX_DEVICE_MEMORY_SIZE_DIVISOR); + + if (memSize > (cl_ulong)SIZE_MAX) + { + memSize = (cl_ulong)SIZE_MAX; + } - if( gTestSmallImages ) + if (gTestSmallImages) { - for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ ) + for (imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++) { imageInfo.rowPitch = imageInfo.width * pixelSize; - for( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ ) + for (imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++) { imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height; - for( imageInfo.arraySize = 2; imageInfo.arraySize < 9; imageInfo.arraySize++ ) + for (imageInfo.arraySize = 2; imageInfo.arraySize < 9; + imageInfo.arraySize++) { - for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++) + for (unsigned int j = 0; + j < sizeof(all_host_ptr_flags) / sizeof(cl_mem_flags); + j++) { - if( gDebugTrace ) - log_info( " at size %d,%d,%d (flags[%u] 0x%x pitch %d)\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.arraySize, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch ); - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) ) + if (gDebugTrace) + log_info(" at size %d,%d,%d (flags[%u] 0x%x " + "pitch %d)\n", + (int)imageInfo.width, + (int)imageInfo.height, + (int)imageInfo.arraySize, j, + (unsigned int)all_host_ptr_flags[j], + (int)imageInfo.rowPitch); + if (test_get_image_info_single( + context, &imageInfo, seed, + all_host_ptr_flags[j], 0, 0)) return -1; - if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) ) + if (all_host_ptr_flags[j] + & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) + { // skip test when host_ptr is NULL + if (test_get_image_info_single( + context, &imageInfo, seed, + all_host_ptr_flags[j], imageInfo.rowPitch, + 0)) return -1; } } @@ -198,74 +267,107 @@ int test_get_image_info_2D_array( cl_device_id device, cl_context context, cl_im } } } - else if( gTestMaxImages ) + else if (gTestMaxImages) { // Try a specific set of maximum sizes size_t numbeOfSizes; size_t sizes[100][3]; - get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, maxHeight, 1, maxArraySize, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE2D_ARRAY, imageInfo.format); + get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, maxHeight, 1, + maxArraySize, maxAllocSize, memSize, + CL_MEM_OBJECT_IMAGE2D_ARRAY, imageInfo.format); - for( size_t idx = 0; idx < numbeOfSizes; idx++ ) + for (size_t idx = 0; idx < numbeOfSizes; idx++) { - imageInfo.width = sizes[ idx ][ 0 ]; - imageInfo.height = sizes[ idx ][ 1 ]; - imageInfo.arraySize = sizes[ idx ][ 2 ]; + imageInfo.width = sizes[idx][0]; + imageInfo.height = sizes[idx][1]; + imageInfo.arraySize = sizes[idx][2]; imageInfo.rowPitch = imageInfo.width * pixelSize; imageInfo.slicePitch = imageInfo.height * imageInfo.rowPitch; - log_info( "Testing %d x %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] ); - for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++) + log_info("Testing %d x %d x %d\n", (int)sizes[idx][0], + (int)sizes[idx][1], (int)sizes[idx][2]); + for (unsigned int j = 0; + j < sizeof(all_host_ptr_flags) / sizeof(cl_mem_flags); j++) { - if( gDebugTrace ) - log_info( " at max size %d,%d,%d (flags[%u] 0x%x pitch %d)\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.arraySize, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch ); - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) ) - return -1; - if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) ) - return -1; - } + if (gDebugTrace) + log_info( + " at max size %d,%d,%d (flags[%u] 0x%x pitch %d)\n", + (int)imageInfo.width, (int)imageInfo.height, + (int)imageInfo.arraySize, j, + (unsigned int)all_host_ptr_flags[j], + (int)imageInfo.rowPitch); + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], 0, 0)) + return -1; + if (all_host_ptr_flags[j] + & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) + { // skip test when host_ptr is NULL + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], + imageInfo.rowPitch, 0)) + return -1; + } } } } else { - for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ ) + for (int i = 0; i < NUM_IMAGE_ITERATIONS; i++) { cl_ulong size; - // Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that - // image, the result array, plus offset arrays, will fit in the global ram space + // Loop until we get a size that a) will fit in the max alloc size + // and b) that an allocation of that image, the result array, plus + // offset arrays, will fit in the global ram space do { - imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed ); - imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed ); - imageInfo.arraySize = (size_t)random_log_in_range( 16, (int)maxArraySize / 32, seed ); + imageInfo.width = + (size_t)random_log_in_range(16, (int)maxWidth / 32, seed); + imageInfo.height = + (size_t)random_log_in_range(16, (int)maxHeight / 32, seed); + imageInfo.arraySize = (size_t)random_log_in_range( + 16, (int)maxArraySize / 32, seed); imageInfo.rowPitch = imageInfo.width * pixelSize; imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height; - size_t extraWidth = (int)random_log_in_range( 0, 64, seed ); + size_t extraWidth = (int)random_log_in_range(0, 64, seed); imageInfo.rowPitch += extraWidth; - do { + do + { extraWidth++; imageInfo.rowPitch += extraWidth; } while ((imageInfo.rowPitch % pixelSize) != 0); - size_t extraHeight = (int)random_log_in_range( 0, 8, seed ); - imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + extraHeight); + size_t extraHeight = (int)random_log_in_range(0, 8, seed); + imageInfo.slicePitch = + imageInfo.rowPitch * (imageInfo.height + extraHeight); - size = (cl_ulong)imageInfo.slicePitch * (cl_ulong)imageInfo.arraySize * 4 * 4; - } while( size > maxAllocSize || ( size * 3 ) > memSize ); + size = (cl_ulong)imageInfo.slicePitch + * (cl_ulong)imageInfo.arraySize * 4 * 4; + } while (size > maxAllocSize || (size * 3) > memSize); - for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++) + for (unsigned int j = 0; + j < sizeof(all_host_ptr_flags) / sizeof(cl_mem_flags); j++) { - if( gDebugTrace ) - log_info( " at size %d,%d,%d (flags[%u] 0x%x pitch %d) out of %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.arraySize, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch, (int)maxWidth, (int)maxHeight, (int)maxArraySize ); - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) ) + if (gDebugTrace) + log_info(" at size %d,%d,%d (flags[%u] 0x%x pitch %d) " + "out of %d,%d,%d\n", + (int)imageInfo.width, (int)imageInfo.height, + (int)imageInfo.arraySize, j, + (unsigned int)all_host_ptr_flags[j], + (int)imageInfo.rowPitch, (int)maxWidth, + (int)maxHeight, (int)maxArraySize); + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], 0, 0)) return -1; - if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) ) + if (all_host_ptr_flags[j] + & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) + { // skip test when host_ptr is NULL + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], + imageInfo.rowPitch, 0)) return -1; } } diff --git a/test_conformance/images/clGetInfo/test_2D.cpp b/test_conformance/images/clGetInfo/test_2D.cpp index 12c1202678..e2969486d4 100644 --- a/test_conformance/images/clGetInfo/test_2D.cpp +++ b/test_conformance/images/clGetInfo/test_2D.cpp @@ -1,6 +1,6 @@ // // Copyright (c) 2017 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 @@ -15,7 +15,9 @@ // #include "../testBase.h" -int test_get_image_info_single( cl_context context, image_descriptor *imageInfo, MTdata d, cl_mem_flags flags, size_t row_pitch, size_t slice_pitch ) +int test_get_image_info_single(cl_context context, image_descriptor *imageInfo, + MTdata d, cl_mem_flags flags, size_t row_pitch, + size_t slice_pitch) { int error; clMemWrapper image; @@ -25,9 +27,10 @@ int test_get_image_info_single( cl_context context, image_descriptor *imageInfo, // Generate some data to test against BufferOwningPtr imageValues; - generate_random_image_data( imageInfo, imageValues, d ); + generate_random_image_data(imageInfo, imageValues, d); - if (flags & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { + if (flags & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) + { host_ptr = (char *)imageValues; } @@ -41,34 +44,54 @@ int test_get_image_info_single( cl_context context, image_descriptor *imageInfo, imageDesc.image_slice_pitch = slice_pitch; // Construct testing source - // Note: for now, just reset the pitches, since they only can actually be different - // if we use CL_MEM_USE_HOST_PTR or CL_MEM_COPY_HOST_PTR - imageInfo->rowPitch = imageInfo->width * get_pixel_size( imageInfo->format ); + // Note: for now, just reset the pitches, since they only can actually be + // different if we use CL_MEM_USE_HOST_PTR or CL_MEM_COPY_HOST_PTR + imageInfo->rowPitch = imageInfo->width * get_pixel_size(imageInfo->format); imageInfo->slicePitch = 0; switch (imageInfo->type) { case CL_MEM_OBJECT_IMAGE1D: - if ( gDebugTrace ) - log_info( " - Creating 1D image %d with flags=0x%lx row_pitch=%d slice_pitch=%d host_ptr=%p...\n", (int)imageInfo->width, (unsigned long)flags, (int)row_pitch, (int)slice_pitch, host_ptr ); + if (gDebugTrace) + log_info(" - Creating 1D image %d with flags=0x%lx " + "row_pitch=%d slice_pitch=%d host_ptr=%p...\n", + (int)imageInfo->width, (unsigned long)flags, + (int)row_pitch, (int)slice_pitch, host_ptr); break; case CL_MEM_OBJECT_IMAGE2D: - if ( gDebugTrace ) - log_info( " - Creating 2D image %d by %d with flags=0x%lx row_pitch=%d slice_pitch=%d host_ptr=%p...\n", (int)imageInfo->width, (int)imageInfo->height, (unsigned long)flags, (int)row_pitch, (int)slice_pitch, host_ptr ); + if (gDebugTrace) + log_info(" - Creating 2D image %d by %d with flags=0x%lx " + "row_pitch=%d slice_pitch=%d host_ptr=%p...\n", + (int)imageInfo->width, (int)imageInfo->height, + (unsigned long)flags, (int)row_pitch, (int)slice_pitch, + host_ptr); break; case CL_MEM_OBJECT_IMAGE3D: imageInfo->slicePitch = imageInfo->rowPitch * imageInfo->height; - if ( gDebugTrace ) - log_info( " - Creating 3D image %d by %d by %d with flags=0x%lx row_pitch=%d slice_pitch=%d host_ptr=%p...\n", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->depth, (unsigned long)flags, (int)row_pitch, (int)slice_pitch, host_ptr ); + if (gDebugTrace) + log_info(" - Creating 3D image %d by %d by %d with flags=0x%lx " + "row_pitch=%d slice_pitch=%d host_ptr=%p...\n", + (int)imageInfo->width, (int)imageInfo->height, + (int)imageInfo->depth, (unsigned long)flags, + (int)row_pitch, (int)slice_pitch, host_ptr); break; case CL_MEM_OBJECT_IMAGE1D_ARRAY: imageInfo->slicePitch = imageInfo->rowPitch; - if ( gDebugTrace ) - log_info( " - Creating 1D image array %d by %d with flags=0x%lx row_pitch=%d slice_pitch=%d host_ptr=%p...\n", (int)imageInfo->width, (int)imageInfo->arraySize, (unsigned long)flags, (int)row_pitch, (int)slice_pitch, host_ptr ); + if (gDebugTrace) + log_info(" - Creating 1D image array %d by %d with flags=0x%lx " + "row_pitch=%d slice_pitch=%d host_ptr=%p...\n", + (int)imageInfo->width, (int)imageInfo->arraySize, + (unsigned long)flags, (int)row_pitch, (int)slice_pitch, + host_ptr); break; case CL_MEM_OBJECT_IMAGE2D_ARRAY: imageInfo->slicePitch = imageInfo->rowPitch * imageInfo->height; - if ( gDebugTrace ) - log_info( " - Creating 2D image array %d by %d by %d with flags=0x%lx row_pitch=%d slice_pitch=%d host_ptr=%p...\n", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->arraySize, (unsigned long)flags, (int)row_pitch, (int)slice_pitch, host_ptr ); + if (gDebugTrace) + log_info( + " - Creating 2D image array %d by %d by %d with " + "flags=0x%lx row_pitch=%d slice_pitch=%d host_ptr=%p...\n", + (int)imageInfo->width, (int)imageInfo->height, + (int)imageInfo->arraySize, (unsigned long)flags, + (int)row_pitch, (int)slice_pitch, host_ptr); break; case CL_MEM_OBJECT_IMAGE1D_BUFFER: if (gDebugTrace) @@ -90,26 +113,40 @@ int test_get_image_info_single( cl_context context, image_descriptor *imageInfo, break; } - image = clCreateImage(context, flags, imageInfo->format, &imageDesc, host_ptr, &error); - if( image == NULL ) + image = clCreateImage(context, flags, imageInfo->format, &imageDesc, + host_ptr, &error); + if (image == NULL) { switch (imageInfo->type) { case CL_MEM_OBJECT_IMAGE1D: - log_error( "ERROR: Unable to create 1D image of size %d (%s)", (int)imageInfo->width, IGetErrorString( error ) ); + log_error("ERROR: Unable to create 1D image of size %d (%s)", + (int)imageInfo->width, IGetErrorString(error)); break; case CL_MEM_OBJECT_IMAGE2D: - log_error( "ERROR: Unable to create 2D image of size %d x %d (%s)", (int)imageInfo->width, (int)imageInfo->height, IGetErrorString( error ) ); + log_error( + "ERROR: Unable to create 2D image of size %d x %d (%s)", + (int)imageInfo->width, (int)imageInfo->height, + IGetErrorString(error)); break; case CL_MEM_OBJECT_IMAGE3D: - log_error( "ERROR: Unable to create 3D image of size %d x %d x %d (%s)", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->depth, IGetErrorString( error ) ); + log_error("ERROR: Unable to create 3D image of size %d x %d x " + "%d (%s)", + (int)imageInfo->width, (int)imageInfo->height, + (int)imageInfo->depth, IGetErrorString(error)); break; case CL_MEM_OBJECT_IMAGE1D_ARRAY: - log_error( "ERROR: Unable to create 1D image array of size %d x %d (%s)", (int)imageInfo->width, (int)imageInfo->arraySize, IGetErrorString( error ) ); + log_error("ERROR: Unable to create 1D image array of size %d x " + "%d (%s)", + (int)imageInfo->width, (int)imageInfo->arraySize, + IGetErrorString(error)); break; break; case CL_MEM_OBJECT_IMAGE2D_ARRAY: - log_error( "ERROR: Unable to create 2D image array of size %d x %d x %d (%s)", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->arraySize, IGetErrorString( error ) ); + log_error("ERROR: Unable to create 2D image array of size %d x " + "%d x %d (%s)", + (int)imageInfo->width, (int)imageInfo->height, + (int)imageInfo->arraySize, IGetErrorString(error)); break; case CL_MEM_OBJECT_IMAGE1D_BUFFER: log_error( @@ -122,275 +159,345 @@ int test_get_image_info_single( cl_context context, image_descriptor *imageInfo, // Get info of the image and verify each item is correct cl_image_format outFormat; - error = clGetImageInfo( image, CL_IMAGE_FORMAT, sizeof( outFormat ), &outFormat, NULL ); - test_error( error, "Unable to get image info (format)" ); - if( outFormat.image_channel_order != imageInfo->format->image_channel_order || - outFormat.image_channel_data_type != imageInfo->format->image_channel_data_type ) + error = clGetImageInfo(image, CL_IMAGE_FORMAT, sizeof(outFormat), + &outFormat, NULL); + test_error(error, "Unable to get image info (format)"); + if (outFormat.image_channel_order != imageInfo->format->image_channel_order + || outFormat.image_channel_data_type + != imageInfo->format->image_channel_data_type) { - log_error( "ERROR: image format returned is invalid! (expected %s:%s, got %s:%s (%d:%d))\n", - GetChannelOrderName( imageInfo->format->image_channel_order ), GetChannelTypeName( imageInfo->format->image_channel_data_type ), - GetChannelOrderName( outFormat.image_channel_order ), GetChannelTypeName( outFormat.image_channel_data_type ), - (int)outFormat.image_channel_order, (int)outFormat.image_channel_data_type ); + log_error( + "ERROR: image format returned is invalid! (expected %s:%s, got " + "%s:%s (%d:%d))\n", + GetChannelOrderName(imageInfo->format->image_channel_order), + GetChannelTypeName(imageInfo->format->image_channel_data_type), + GetChannelOrderName(outFormat.image_channel_order), + GetChannelTypeName(outFormat.image_channel_data_type), + (int)outFormat.image_channel_order, + (int)outFormat.image_channel_data_type); return 1; } size_t outElementSize; - error = clGetImageInfo( image, CL_IMAGE_ELEMENT_SIZE, sizeof( outElementSize ), &outElementSize, NULL ); - test_error( error, "Unable to get image info (element size)" ); - if( outElementSize != get_pixel_size( imageInfo->format ) ) + error = clGetImageInfo(image, CL_IMAGE_ELEMENT_SIZE, sizeof(outElementSize), + &outElementSize, NULL); + test_error(error, "Unable to get image info (element size)"); + if (outElementSize != get_pixel_size(imageInfo->format)) { - log_error( "ERROR: image element size returned is invalid! (expected %d, got %d)\n", - (int)get_pixel_size( imageInfo->format ), (int)outElementSize ); + log_error("ERROR: image element size returned is invalid! (expected " + "%d, got %d)\n", + (int)get_pixel_size(imageInfo->format), (int)outElementSize); return 1; } size_t outRowPitch; - error = clGetImageInfo( image, CL_IMAGE_ROW_PITCH, sizeof( outRowPitch ), &outRowPitch, NULL ); - test_error( error, "Unable to get image info (row pitch)" ); - - size_t outSlicePitch; - error = clGetImageInfo( image, CL_IMAGE_SLICE_PITCH, sizeof( outSlicePitch ), &outSlicePitch, NULL ); - test_error( error, "Unable to get image info (slice pitch)" ); - if( imageInfo->type == CL_MEM_OBJECT_IMAGE1D && outSlicePitch != 0 ) + error = clGetImageInfo(image, CL_IMAGE_ROW_PITCH, sizeof(outRowPitch), + &outRowPitch, NULL); + test_error(error, "Unable to get image info (row pitch)"); + + size_t outSlicePitch; + error = clGetImageInfo(image, CL_IMAGE_SLICE_PITCH, sizeof(outSlicePitch), + &outSlicePitch, NULL); + test_error(error, "Unable to get image info (slice pitch)"); + if (imageInfo->type == CL_MEM_OBJECT_IMAGE1D && outSlicePitch != 0) { - log_error( "ERROR: slice pitch returned is invalid! (expected %d, got %d)\n", - (int)0, (int)outSlicePitch ); + log_error( + "ERROR: slice pitch returned is invalid! (expected %d, got %d)\n", + (int)0, (int)outSlicePitch); return 1; } size_t outWidth; - error = clGetImageInfo( image, CL_IMAGE_WIDTH, sizeof( outWidth ), &outWidth, NULL ); - test_error( error, "Unable to get image info (width)" ); - if( outWidth != imageInfo->width ) + error = clGetImageInfo(image, CL_IMAGE_WIDTH, sizeof(outWidth), &outWidth, + NULL); + test_error(error, "Unable to get image info (width)"); + if (outWidth != imageInfo->width) { - log_error( "ERROR: image width returned is invalid! (expected %d, got %d)\n", - (int)imageInfo->width, (int)outWidth ); + log_error( + "ERROR: image width returned is invalid! (expected %d, got %d)\n", + (int)imageInfo->width, (int)outWidth); return 1; } - size_t required_height; - switch (imageInfo->type) - { - case CL_MEM_OBJECT_IMAGE1D: - case CL_MEM_OBJECT_IMAGE1D_BUFFER: - case CL_MEM_OBJECT_IMAGE1D_ARRAY: - required_height = 0; - break; - case CL_MEM_OBJECT_IMAGE2D: - case CL_MEM_OBJECT_IMAGE2D_ARRAY: - case CL_MEM_OBJECT_IMAGE3D: - required_height = imageInfo->height; - break; - } + size_t required_height; + switch (imageInfo->type) + { + case CL_MEM_OBJECT_IMAGE1D: + case CL_MEM_OBJECT_IMAGE1D_BUFFER: + case CL_MEM_OBJECT_IMAGE1D_ARRAY: required_height = 0; break; + case CL_MEM_OBJECT_IMAGE2D: + case CL_MEM_OBJECT_IMAGE2D_ARRAY: + case CL_MEM_OBJECT_IMAGE3D: required_height = imageInfo->height; break; + } size_t outHeight; - error = clGetImageInfo( image, CL_IMAGE_HEIGHT, sizeof( outHeight ), &outHeight, NULL ); - test_error( error, "Unable to get image info (height)" ); - if( outHeight != required_height ) - { - log_error( "ERROR: image height returned is invalid! (expected %d, got %d)\n", - (int)required_height, (int)outHeight ); - return 1; - } - - size_t required_depth; - switch (imageInfo->type) - { - case CL_MEM_OBJECT_IMAGE1D: - case CL_MEM_OBJECT_IMAGE2D: - case CL_MEM_OBJECT_IMAGE1D_ARRAY: - case CL_MEM_OBJECT_IMAGE2D_ARRAY: - case CL_MEM_OBJECT_IMAGE1D_BUFFER: required_depth = 0; break; - case CL_MEM_OBJECT_IMAGE3D: - required_depth = imageInfo->depth; - break; - } - - size_t outDepth; - error = clGetImageInfo( image, CL_IMAGE_DEPTH, sizeof( outDepth ), &outDepth, NULL ); - test_error( error, "Unable to get image info (depth)" ); - if( outDepth != required_depth ) - { - log_error( "ERROR: image depth returned is invalid! (expected %d, got %d)\n", - (int)required_depth, (int)outDepth ); - return 1; - } - - size_t required_array_size; - switch (imageInfo->type) - { - case CL_MEM_OBJECT_IMAGE1D: - case CL_MEM_OBJECT_IMAGE2D: - case CL_MEM_OBJECT_IMAGE3D: - case CL_MEM_OBJECT_IMAGE1D_BUFFER: required_array_size = 0; break; - case CL_MEM_OBJECT_IMAGE1D_ARRAY: - case CL_MEM_OBJECT_IMAGE2D_ARRAY: - required_array_size = imageInfo->arraySize; - break; - } - - size_t outArraySize; - error = clGetImageInfo( image, CL_IMAGE_ARRAY_SIZE, sizeof( outArraySize ), &outArraySize, NULL ); - test_error( error, "Unable to get image info (array size)" ); - if( outArraySize != required_array_size ) - { - log_error( "ERROR: image array size returned is invalid! (expected %d, got %d)\n", - (int)required_array_size, (int)outArraySize ); - return 1; - } - - cl_mem outBuffer; - error = clGetImageInfo( image, CL_IMAGE_BUFFER, sizeof( outBuffer ), &outBuffer, NULL ); - test_error( error, "Unable to get image info (buffer)" ); - if (imageInfo->type == CL_MEM_OBJECT_IMAGE1D_BUFFER) { - if (outBuffer != imageInfo->buffer) { - log_error( "ERROR: cl_mem returned is invalid! (expected %p, got %p)\n", - imageInfo->buffer, outBuffer ); - return 1; - } - } else { - if (outBuffer != (cl_mem)NULL) { - log_error( "ERROR: cl_mem returned is invalid! (expected %p, got %p)\n", - (cl_mem)NULL, outBuffer ); - return 1; - } - } + error = clGetImageInfo(image, CL_IMAGE_HEIGHT, sizeof(outHeight), + &outHeight, NULL); + test_error(error, "Unable to get image info (height)"); + if (outHeight != required_height) + { + log_error( + "ERROR: image height returned is invalid! (expected %d, got %d)\n", + (int)required_height, (int)outHeight); + return 1; + } + + size_t required_depth; + switch (imageInfo->type) + { + case CL_MEM_OBJECT_IMAGE1D: + case CL_MEM_OBJECT_IMAGE2D: + case CL_MEM_OBJECT_IMAGE1D_ARRAY: + case CL_MEM_OBJECT_IMAGE2D_ARRAY: + case CL_MEM_OBJECT_IMAGE1D_BUFFER: required_depth = 0; break; + case CL_MEM_OBJECT_IMAGE3D: required_depth = imageInfo->depth; break; + } + + size_t outDepth; + error = clGetImageInfo(image, CL_IMAGE_DEPTH, sizeof(outDepth), &outDepth, + NULL); + test_error(error, "Unable to get image info (depth)"); + if (outDepth != required_depth) + { + log_error( + "ERROR: image depth returned is invalid! (expected %d, got %d)\n", + (int)required_depth, (int)outDepth); + return 1; + } + + size_t required_array_size; + switch (imageInfo->type) + { + case CL_MEM_OBJECT_IMAGE1D: + case CL_MEM_OBJECT_IMAGE2D: + case CL_MEM_OBJECT_IMAGE3D: + case CL_MEM_OBJECT_IMAGE1D_BUFFER: required_array_size = 0; break; + case CL_MEM_OBJECT_IMAGE1D_ARRAY: + case CL_MEM_OBJECT_IMAGE2D_ARRAY: + required_array_size = imageInfo->arraySize; + break; + } + + size_t outArraySize; + error = clGetImageInfo(image, CL_IMAGE_ARRAY_SIZE, sizeof(outArraySize), + &outArraySize, NULL); + test_error(error, "Unable to get image info (array size)"); + if (outArraySize != required_array_size) + { + log_error("ERROR: image array size returned is invalid! (expected %d, " + "got %d)\n", + (int)required_array_size, (int)outArraySize); + return 1; + } + + cl_mem outBuffer; + error = clGetImageInfo(image, CL_IMAGE_BUFFER, sizeof(outBuffer), + &outBuffer, NULL); + test_error(error, "Unable to get image info (buffer)"); + if (imageInfo->type == CL_MEM_OBJECT_IMAGE1D_BUFFER) + { + if (outBuffer != imageInfo->buffer) + { + log_error( + "ERROR: cl_mem returned is invalid! (expected %p, got %p)\n", + imageInfo->buffer, outBuffer); + return 1; + } + } + else + { + if (outBuffer != (cl_mem)NULL) + { + log_error( + "ERROR: cl_mem returned is invalid! (expected %p, got %p)\n", + (cl_mem)NULL, outBuffer); + return 1; + } + } cl_uint numMipLevels; - error = clGetImageInfo( image, CL_IMAGE_NUM_MIP_LEVELS, sizeof( numMipLevels ), &numMipLevels, NULL ); - test_error( error, "Unable to get image info (num mip levels)" ); - if( numMipLevels != 0 ) + error = clGetImageInfo(image, CL_IMAGE_NUM_MIP_LEVELS, sizeof(numMipLevels), + &numMipLevels, NULL); + test_error(error, "Unable to get image info (num mip levels)"); + if (numMipLevels != 0) { - log_error( "ERROR: image num_mip_levels returned is invalid! (expected %d, got %d)\n", - (int)0, (int)numMipLevels ); + log_error("ERROR: image num_mip_levels returned is invalid! (expected " + "%d, got %d)\n", + (int)0, (int)numMipLevels); return 1; } cl_uint numSamples; - error = clGetImageInfo( image, CL_IMAGE_NUM_SAMPLES, sizeof( numSamples ), &numSamples, NULL ); - test_error( error, "Unable to get image info (num samples)" ); - if( numSamples != 0 ) + error = clGetImageInfo(image, CL_IMAGE_NUM_SAMPLES, sizeof(numSamples), + &numSamples, NULL); + test_error(error, "Unable to get image info (num samples)"); + if (numSamples != 0) { - log_error( "ERROR: image num_samples returned is invalid! (expected %d, got %d)\n", - (int)0, (int)numSamples ); + log_error("ERROR: image num_samples returned is invalid! (expected %d, " + "got %d)\n", + (int)0, (int)numSamples); return 1; } return 0; } -int test_get_image_info_2D( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags ) +int test_get_image_info_2D(cl_device_id device, cl_context context, + cl_image_format *format, cl_mem_flags flags) { size_t maxWidth, maxHeight; cl_ulong maxAllocSize, memSize; image_descriptor imageInfo = { 0 }; - RandomSeed seed( gRandomSeed ); + RandomSeed seed(gRandomSeed); size_t pixelSize; - cl_mem_flags all_host_ptr_flags[5] = { - flags, - CL_MEM_ALLOC_HOST_PTR | flags, - CL_MEM_COPY_HOST_PTR | flags, - CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | flags, - CL_MEM_USE_HOST_PTR | flags - }; + cl_mem_flags all_host_ptr_flags[5] = { flags, CL_MEM_ALLOC_HOST_PTR | flags, + CL_MEM_COPY_HOST_PTR | flags, + CL_MEM_ALLOC_HOST_PTR + | CL_MEM_COPY_HOST_PTR | flags, + CL_MEM_USE_HOST_PTR | flags }; memset(&imageInfo, 0x0, sizeof(image_descriptor)); imageInfo.format = format; imageInfo.type = CL_MEM_OBJECT_IMAGE2D; - pixelSize = get_pixel_size( imageInfo.format ); - - int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_HEIGHT, sizeof( maxHeight ), &maxHeight, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL ); - test_error( error, "Unable to get max image 2D width or max image 3D height or max memory allocation size or global memory size from device" ); - - if (memSize > (cl_ulong)SIZE_MAX) { - memSize = (cl_ulong)SIZE_MAX; - maxAllocSize = (cl_ulong)SIZE_MAX; - } + pixelSize = get_pixel_size(imageInfo.format); + + int error = clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_WIDTH, + sizeof(maxWidth), &maxWidth, NULL); + error |= clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_HEIGHT, + sizeof(maxHeight), &maxHeight, NULL); + test_error(error, + "Unable to get max image 2D width or max image 3D height or max " + "memory allocation size or global memory size from device"); + + /* Reduce the size used by the test by half */ + maxAllocSize = get_device_info_max_mem_alloc_size( + device, MAX_DEVICE_MEMORY_SIZE_DIVISOR); + memSize = + get_device_info_global_mem_size(device, MAX_DEVICE_MEMORY_SIZE_DIVISOR); + + if (memSize > (cl_ulong)SIZE_MAX) + { + memSize = (cl_ulong)SIZE_MAX; + } - if( gTestSmallImages ) + if (gTestSmallImages) { - for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ ) + for (imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++) { imageInfo.rowPitch = imageInfo.width * pixelSize; - for( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ ) + for (imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++) { - for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++) + for (unsigned int j = 0; + j < sizeof(all_host_ptr_flags) / sizeof(cl_mem_flags); j++) { - if( gDebugTrace ) - log_info( " at size %d,%d (flags[%u] 0x%x pitch %d)\n", (int)imageInfo.width, (int)imageInfo.height, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch ); - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) ) + if (gDebugTrace) + log_info(" at size %d,%d (flags[%u] 0x%x pitch %d)\n", + (int)imageInfo.width, (int)imageInfo.height, j, + (unsigned int)all_host_ptr_flags[j], + (int)imageInfo.rowPitch); + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], 0, 0)) return -1; - if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) ) + if (all_host_ptr_flags[j] + & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) + { // skip test when host_ptr is NULL + if (test_get_image_info_single( + context, &imageInfo, seed, + all_host_ptr_flags[j], imageInfo.rowPitch, 0)) return -1; } } } } } - else if( gTestMaxImages ) + else if (gTestMaxImages) { // Try a specific set of maximum sizes size_t numbeOfSizes; size_t sizes[100][3]; - get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, maxHeight, 1, 1, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE2D, imageInfo.format); + get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, maxHeight, 1, 1, + maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE2D, + imageInfo.format); - for( size_t idx = 0; idx < numbeOfSizes; idx++ ) + for (size_t idx = 0; idx < numbeOfSizes; idx++) { - imageInfo.width = sizes[ idx ][ 0 ]; - imageInfo.height = sizes[ idx ][ 1 ]; + imageInfo.width = sizes[idx][0]; + imageInfo.height = sizes[idx][1]; imageInfo.rowPitch = imageInfo.width * pixelSize; - log_info( "Testing %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ] ); - for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++) + log_info("Testing %d x %d\n", (int)sizes[idx][0], + (int)sizes[idx][1]); + for (unsigned int j = 0; + j < sizeof(all_host_ptr_flags) / sizeof(cl_mem_flags); j++) { - if( gDebugTrace ) - log_info( " at max size %d,%d (flags[%u] 0x%x pitch %d)\n", (int)imageInfo.width, (int)imageInfo.height, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch ); - if( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) ) + if (gDebugTrace) + log_info(" at max size %d,%d (flags[%u] 0x%x pitch %d)\n", + (int)imageInfo.width, (int)imageInfo.height, j, + (unsigned int)all_host_ptr_flags[j], + (int)imageInfo.rowPitch); + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], 0, 0)) return -1; - if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL - if( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) ) + if (all_host_ptr_flags[j] + & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) + { // skip test when host_ptr is NULL + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], + imageInfo.rowPitch, 0)) return -1; - } + } } } } else { - for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ ) + for (int i = 0; i < NUM_IMAGE_ITERATIONS; i++) { cl_ulong size; - // Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that - // image, the result array, plus offset arrays, will fit in the global ram space + // Loop until we get a size that a) will fit in the max alloc size + // and b) that an allocation of that image, the result array, plus + // offset arrays, will fit in the global ram space do { - imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed ); - imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed ); + imageInfo.width = + (size_t)random_log_in_range(16, (int)maxWidth / 32, seed); + imageInfo.height = + (size_t)random_log_in_range(16, (int)maxHeight / 32, seed); imageInfo.rowPitch = imageInfo.width * pixelSize; - size_t extraWidth = (int)random_log_in_range( 0, 64, seed ); + size_t extraWidth = (int)random_log_in_range(0, 64, seed); imageInfo.rowPitch += extraWidth; - do { + do + { extraWidth++; imageInfo.rowPitch += extraWidth; } while ((imageInfo.rowPitch % pixelSize) != 0); - size = (cl_ulong)imageInfo.rowPitch * (cl_ulong)imageInfo.height * 4; - } while( size > maxAllocSize || ( size * 3 ) > memSize ); + size = (cl_ulong)imageInfo.rowPitch * (cl_ulong)imageInfo.height + * 4; + } while (size > maxAllocSize || (size * 3) > memSize); - for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++) + for (unsigned int j = 0; + j < sizeof(all_host_ptr_flags) / sizeof(cl_mem_flags); j++) { - if( gDebugTrace ) - log_info( " at size %d,%d (flags[%u] 0x%x pitch %d) out of %d,%d\n", (int)imageInfo.width, (int)imageInfo.height, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch, (int)maxWidth, (int)maxHeight ); - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) ) + if (gDebugTrace) + log_info(" at size %d,%d (flags[%u] 0x%x pitch %d) out " + "of %d,%d\n", + (int)imageInfo.width, (int)imageInfo.height, j, + (unsigned int)all_host_ptr_flags[j], + (int)imageInfo.rowPitch, (int)maxWidth, + (int)maxHeight); + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], 0, 0)) return -1; - if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) ) + if (all_host_ptr_flags[j] + & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) + { // skip test when host_ptr is NULL + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], + imageInfo.rowPitch, 0)) return -1; } } diff --git a/test_conformance/images/clGetInfo/test_3D.cpp b/test_conformance/images/clGetInfo/test_3D.cpp index e1261863cc..40b727cdc7 100644 --- a/test_conformance/images/clGetInfo/test_3D.cpp +++ b/test_conformance/images/clGetInfo/test_3D.cpp @@ -1,6 +1,6 @@ // // Copyright (c) 2017 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 @@ -15,60 +15,86 @@ // #include "../testBase.h" -extern int test_get_image_info_single( cl_context context, image_descriptor *imageInfo, MTdata d, cl_mem_flags flags, size_t row_pitch, size_t slice_pitch ); +extern int test_get_image_info_single(cl_context context, + image_descriptor *imageInfo, MTdata d, + cl_mem_flags flags, size_t row_pitch, + size_t slice_pitch); -int test_get_image_info_3D( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags ) +int test_get_image_info_3D(cl_device_id device, cl_context context, + cl_image_format *format, cl_mem_flags flags) { size_t maxWidth, maxHeight, maxDepth; cl_ulong maxAllocSize, memSize; image_descriptor imageInfo = { 0 }; - RandomSeed seed( gRandomSeed ); + RandomSeed seed(gRandomSeed); size_t pixelSize; - cl_mem_flags all_host_ptr_flags[] = { - flags, - CL_MEM_ALLOC_HOST_PTR | flags, - CL_MEM_COPY_HOST_PTR | flags, - CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | flags, - CL_MEM_USE_HOST_PTR | flags - }; + cl_mem_flags all_host_ptr_flags[] = { flags, CL_MEM_ALLOC_HOST_PTR | flags, + CL_MEM_COPY_HOST_PTR | flags, + CL_MEM_ALLOC_HOST_PTR + | CL_MEM_COPY_HOST_PTR | flags, + CL_MEM_USE_HOST_PTR | flags }; memset(&imageInfo, 0x0, sizeof(image_descriptor)); imageInfo.format = format; imageInfo.type = CL_MEM_OBJECT_IMAGE3D; - pixelSize = get_pixel_size( imageInfo.format ); - - int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_HEIGHT, sizeof( maxHeight ), &maxHeight, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_DEPTH, sizeof( maxDepth ), &maxDepth, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL ); - test_error( error, "Unable to get max image 3D size from device" ); - - if (memSize > (cl_ulong)SIZE_MAX) { - memSize = (cl_ulong)SIZE_MAX; - maxAllocSize = (cl_ulong)SIZE_MAX; - } + pixelSize = get_pixel_size(imageInfo.format); + + int error = clGetDeviceInfo(device, CL_DEVICE_IMAGE3D_MAX_WIDTH, + sizeof(maxWidth), &maxWidth, NULL); + error |= clGetDeviceInfo(device, CL_DEVICE_IMAGE3D_MAX_HEIGHT, + sizeof(maxHeight), &maxHeight, NULL); + error |= clGetDeviceInfo(device, CL_DEVICE_IMAGE3D_MAX_DEPTH, + sizeof(maxDepth), &maxDepth, NULL); + test_error(error, "Unable to get max image 3D size from device"); + + /* Reduce the size used by the test by half */ + maxAllocSize = get_device_info_max_mem_alloc_size( + device, MAX_DEVICE_MEMORY_SIZE_DIVISOR); + memSize = + get_device_info_global_mem_size(device, MAX_DEVICE_MEMORY_SIZE_DIVISOR); + + if (memSize > (cl_ulong)SIZE_MAX) + { + memSize = (cl_ulong)SIZE_MAX; + } - if( gTestSmallImages ) + if (gTestSmallImages) { - for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ ) + for (imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++) { imageInfo.rowPitch = imageInfo.width * pixelSize; - for( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ ) + for (imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++) { imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height; - for( imageInfo.depth = 2; imageInfo.depth < 9; imageInfo.depth++ ) + for (imageInfo.depth = 2; imageInfo.depth < 9; + imageInfo.depth++) { - for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++) + for (unsigned int j = 0; + j < sizeof(all_host_ptr_flags) / sizeof(cl_mem_flags); + j++) { - if( gDebugTrace ) - log_info( " at size %d,%d,%d (flags[%u] 0x%lx pitch %d,%d)\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.depth, j, (unsigned long)all_host_ptr_flags[j], (int)imageInfo.rowPitch, (int)imageInfo.slicePitch ); - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) ) + if (gDebugTrace) + log_info(" at size %d,%d,%d (flags[%u] 0x%lx " + "pitch %d,%d)\n", + (int)imageInfo.width, + (int)imageInfo.height, + (int)imageInfo.depth, j, + (unsigned long)all_host_ptr_flags[j], + (int)imageInfo.rowPitch, + (int)imageInfo.slicePitch); + if (test_get_image_info_single( + context, &imageInfo, seed, + all_host_ptr_flags[j], 0, 0)) return -1; - if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, imageInfo.slicePitch ) ) + if (all_host_ptr_flags[j] + & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) + { // skip test when host_ptr is NULL + if (test_get_image_info_single( + context, &imageInfo, seed, + all_host_ptr_flags[j], imageInfo.rowPitch, + imageInfo.slicePitch)) return -1; } } @@ -76,31 +102,46 @@ int test_get_image_info_3D( cl_device_id device, cl_context context, cl_image_fo } } } - else if( gTestMaxImages ) + else if (gTestMaxImages) { // Try a specific set of maximum sizes size_t numbeOfSizes; size_t sizes[100][3]; - get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, maxHeight, maxDepth, 1, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE3D, imageInfo.format); + get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, maxHeight, maxDepth, + 1, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE3D, + imageInfo.format); - for( size_t idx = 0; idx < numbeOfSizes; idx++ ) + for (size_t idx = 0; idx < numbeOfSizes; idx++) { - imageInfo.width = sizes[ idx ][ 0 ]; - imageInfo.height = sizes[ idx ][ 1 ]; - imageInfo.depth = sizes[ idx ][ 2 ]; + imageInfo.width = sizes[idx][0]; + imageInfo.height = sizes[idx][1]; + imageInfo.depth = sizes[idx][2]; imageInfo.rowPitch = imageInfo.width * pixelSize; imageInfo.slicePitch = imageInfo.height * imageInfo.rowPitch; - log_info( "Testing %d x %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] ); - for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++) + log_info("Testing %d x %d x %d\n", (int)sizes[idx][0], + (int)sizes[idx][1], (int)sizes[idx][2]); + for (unsigned int j = 0; + j < sizeof(all_host_ptr_flags) / sizeof(cl_mem_flags); j++) { - if( gDebugTrace ) - log_info( " at max size %d,%d,%d (flags[%u] 0x%lx pitch %d,%d)\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ], j, (unsigned long)all_host_ptr_flags[j], (int)imageInfo.rowPitch, (int)imageInfo.slicePitch ); - if( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) ) + if (gDebugTrace) + log_info(" at max size %d,%d,%d (flags[%u] 0x%lx pitch " + "%d,%d)\n", + (int)sizes[idx][0], (int)sizes[idx][1], + (int)sizes[idx][2], j, + (unsigned long)all_host_ptr_flags[j], + (int)imageInfo.rowPitch, + (int)imageInfo.slicePitch); + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], 0, 0)) return -1; - if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL - if( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, imageInfo.slicePitch ) ) + if (all_host_ptr_flags[j] + & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) + { // skip test when host_ptr is NULL + if (test_get_image_info_single( + context, &imageInfo, seed, all_host_ptr_flags[j], + imageInfo.rowPitch, imageInfo.slicePitch)) return -1; } } @@ -108,42 +149,61 @@ int test_get_image_info_3D( cl_device_id device, cl_context context, cl_image_fo } else { - for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ ) + for (int i = 0; i < NUM_IMAGE_ITERATIONS; i++) { cl_ulong size; - // Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that - // image, the result array, plus offset arrays, will fit in the global ram space + // Loop until we get a size that a) will fit in the max alloc size + // and b) that an allocation of that image, the result array, plus + // offset arrays, will fit in the global ram space do { - imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed ); - imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed ); - imageInfo.depth = (size_t)random_log_in_range( 16, (int)maxDepth / 32, seed ); + imageInfo.width = + (size_t)random_log_in_range(16, (int)maxWidth / 32, seed); + imageInfo.height = + (size_t)random_log_in_range(16, (int)maxHeight / 32, seed); + imageInfo.depth = + (size_t)random_log_in_range(16, (int)maxDepth / 32, seed); imageInfo.rowPitch = imageInfo.width * pixelSize; imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height; - size_t extraWidth = (int)random_log_in_range( 0, 64, seed ); + size_t extraWidth = (int)random_log_in_range(0, 64, seed); imageInfo.rowPitch += extraWidth; - do { + do + { extraWidth++; imageInfo.rowPitch += extraWidth; } while ((imageInfo.rowPitch % pixelSize) != 0); - size_t extraHeight = (int)random_log_in_range( 0, 8, seed ); - imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + extraHeight); + size_t extraHeight = (int)random_log_in_range(0, 8, seed); + imageInfo.slicePitch = + imageInfo.rowPitch * (imageInfo.height + extraHeight); - size = (cl_ulong)imageInfo.slicePitch * (cl_ulong)imageInfo.depth * 4 * 4; - } while( size > maxAllocSize || ( size * 3 ) > memSize ); + size = (cl_ulong)imageInfo.slicePitch + * (cl_ulong)imageInfo.depth * 4 * 4; + } while (size > maxAllocSize || (size * 3) > memSize); - for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++) + for (unsigned int j = 0; + j < sizeof(all_host_ptr_flags) / sizeof(cl_mem_flags); j++) { - if( gDebugTrace ) - log_info( " at size %d,%d,%d (flags[%u] 0x%lx pitch %d,%d) out of %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.depth, j, (unsigned long) all_host_ptr_flags[i], (int)imageInfo.rowPitch, (int)imageInfo.slicePitch, (int)maxWidth, (int)maxHeight, (int)maxDepth ); - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) ) + if (gDebugTrace) + log_info(" at size %d,%d,%d (flags[%u] 0x%lx pitch " + "%d,%d) out of %d,%d,%d\n", + (int)imageInfo.width, (int)imageInfo.height, + (int)imageInfo.depth, j, + (unsigned long)all_host_ptr_flags[i], + (int)imageInfo.rowPitch, (int)imageInfo.slicePitch, + (int)maxWidth, (int)maxHeight, (int)maxDepth); + if (test_get_image_info_single(context, &imageInfo, seed, + all_host_ptr_flags[j], 0, 0)) return -1; - if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL - if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, imageInfo.slicePitch ) ) + if (all_host_ptr_flags[j] + & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) + { // skip test when host_ptr is NULL + if (test_get_image_info_single( + context, &imageInfo, seed, all_host_ptr_flags[j], + imageInfo.rowPitch, imageInfo.slicePitch)) return -1; } }