mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
Limit buffers sizes to leave some memory for the platform (#1172)
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.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -48,4 +48,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
|
||||
|
||||
Reference in New Issue
Block a user