Skip to content

Commit

Permalink
Limit buffers sizes to leave some memory for the platform
Browse files Browse the repository at this point in the history
Some conformance tests use directly the size returned by the runtime
for max memory size to allocate buffers.
This doesn't leave enough memory for the system to run the tests.
  • Loading branch information
ouakheli authored and ahesham-arm committed Oct 31, 2023
1 parent 7e4b59d commit 6579c70
Show file tree
Hide file tree
Showing 10 changed files with 878 additions and 564 deletions.
39 changes: 39 additions & 0 deletions test_common/harness/deviceInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
12 changes: 12 additions & 0 deletions test_common/harness/deviceInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 3 additions & 8 deletions test_conformance/allocations/allocation_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,14 @@ int allocate_size(cl_context context, cl_command_queue *queue, cl_device_id devi
// Set the number of mems used to 0 so if we fail to create even a single 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");
return FAILED_ABORT;
Expand Down
23 changes: 12 additions & 11 deletions test_conformance/allocations/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,16 +45,9 @@ static void printUsage( const char *execName );
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",
llu( g_max_individual_allocation_size ), toMB( g_max_individual_allocation_size ),
Expand Down Expand Up @@ -94,6 +89,12 @@ test_status init_cl( cl_device_id device ) {
g_global_mem_size *= 0.60;
}

/* Cap the allocation size as the global size was deduced */
if (g_max_individual_allocation_size > g_global_mem_size)
{
g_max_individual_allocation_size = g_global_mem_size;
}

if( gReSeed )
{
g_seed = RandomSeed( gRandomSeed );
Expand Down
Loading

0 comments on commit 6579c70

Please sign in to comment.