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.

Change-Id: If49ce62baffe9d72e5a7a6cad85f0164c9dd881d
  • Loading branch information
ouakheli authored and ahesham-arm committed Jun 17, 2024
1 parent d379b58 commit d4b02e8
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 157 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
18 changes: 3 additions & 15 deletions test_conformance/allocations/allocation_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
25 changes: 6 additions & 19 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 @@ -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",
Expand Down
Loading

0 comments on commit d4b02e8

Please sign in to comment.