Skip to content

Commit f473546

Browse files
authored
Limit buffers sizes to leave some memory for the platform (KhronosGroup#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.
1 parent 995e465 commit f473546

File tree

10 files changed

+179
-163
lines changed

10 files changed

+179
-163
lines changed

test_common/harness/deviceInfo.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,42 @@ size_t get_max_param_size(cl_device_id device)
132132
}
133133
return ret;
134134
}
135+
136+
static cl_ulong get_device_info_max_size(cl_device_id device,
137+
cl_device_info info,
138+
unsigned int divisor)
139+
{
140+
cl_ulong max_size;
141+
142+
if (divisor == 0)
143+
{
144+
throw std::runtime_error("Allocation divisor should not be 0\n");
145+
}
146+
147+
if (clGetDeviceInfo(device, info, sizeof(max_size), &max_size, NULL)
148+
!= CL_SUCCESS)
149+
{
150+
throw std::runtime_error("clGetDeviceInfo failed\n");
151+
}
152+
return max_size / divisor;
153+
}
154+
155+
cl_ulong get_device_info_max_mem_alloc_size(cl_device_id device,
156+
unsigned int divisor)
157+
{
158+
return get_device_info_max_size(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE,
159+
divisor);
160+
}
161+
162+
cl_ulong get_device_info_global_mem_size(cl_device_id device,
163+
unsigned int divisor)
164+
{
165+
return get_device_info_max_size(device, CL_DEVICE_GLOBAL_MEM_SIZE, divisor);
166+
}
167+
168+
cl_ulong get_device_info_max_constant_buffer_size(cl_device_id device,
169+
unsigned int divisor)
170+
{
171+
return get_device_info_max_size(device, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE,
172+
divisor);
173+
}

test_common/harness/deviceInfo.h

+12
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,16 @@ std::string get_device_name(cl_device_id device);
4848
// Returns the maximum size in bytes for Kernel Parameters
4949
size_t get_max_param_size(cl_device_id device);
5050

51+
/* We need to use a portion of available alloc size,
52+
* divide it to leave some memory for the platform. */
53+
#define MAX_DEVICE_MEMORY_SIZE_DIVISOR (2)
54+
55+
/* Get max allocation size. */
56+
cl_ulong get_device_info_max_mem_alloc_size(cl_device_id device,
57+
unsigned int divisor = 1);
58+
cl_ulong get_device_info_global_mem_size(cl_device_id device,
59+
unsigned int divisor = 1);
60+
cl_ulong get_device_info_max_constant_buffer_size(cl_device_id device,
61+
unsigned int divisor = 1);
62+
5163
#endif // _deviceInfo_h

test_conformance/allocations/allocation_functions.cpp

+3-15
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,15 @@ int allocate_size(cl_context context, cl_command_queue *queue,
188188
// one we don't end up returning a garbage value
189189
*number_of_mems = 0;
190190

191-
error = clGetDeviceInfo(device_id, CL_DEVICE_MAX_MEM_ALLOC_SIZE,
192-
sizeof(max_individual_allocation_size),
193-
&max_individual_allocation_size, NULL);
194-
test_error_abort(error,
195-
"clGetDeviceInfo failed for CL_DEVICE_MAX_MEM_ALLOC_SIZE");
196-
error = clGetDeviceInfo(device_id, CL_DEVICE_GLOBAL_MEM_SIZE,
197-
sizeof(global_mem_size), &global_mem_size, NULL);
198-
test_error_abort(error,
199-
"clGetDeviceInfo failed for CL_DEVICE_GLOBAL_MEM_SIZE");
191+
max_individual_allocation_size =
192+
get_device_info_max_mem_alloc_size(device_id);
193+
global_mem_size = get_device_info_global_mem_size(device_id);
200194

201195
if (global_mem_size > (cl_ulong)SIZE_MAX)
202196
{
203197
global_mem_size = (cl_ulong)SIZE_MAX;
204198
}
205199

206-
// log_info("Device reports CL_DEVICE_MAX_MEM_ALLOC_SIZE=%llu bytes (%gMB),
207-
// CL_DEVICE_GLOBAL_MEM_SIZE=%llu bytes (%gMB).\n",
208-
// max_individual_allocation_size,
209-
// toMB(max_individual_allocation_size), global_mem_size,
210-
// toMB(global_mem_size));
211-
212200
if (size_to_allocate > global_mem_size)
213201
{
214202
log_error("Can not allocate more than the global memory size.\n");

test_conformance/allocations/main.cpp

+6-19
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424

2525
typedef long long unsigned llu;
2626

27+
#define REDUCTION_PERCENTAGE_DEFAULT 50
28+
2729
int g_repetition_count = 1;
28-
int g_reduction_percentage = 100;
30+
int g_reduction_percentage = REDUCTION_PERCENTAGE_DEFAULT;
2931
int g_write_allocations = 1;
3032
int g_multiple_allocations = 0;
3133
int g_execute_kernel = 1;
@@ -44,24 +46,9 @@ test_status init_cl(cl_device_id device)
4446
{
4547
int error;
4648

47-
error = clGetDeviceInfo(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE,
48-
sizeof(g_max_individual_allocation_size),
49-
&g_max_individual_allocation_size, NULL);
50-
if (error)
51-
{
52-
print_error(error,
53-
"clGetDeviceInfo failed for CL_DEVICE_MAX_MEM_ALLOC_SIZE");
54-
return TEST_FAIL;
55-
}
56-
error =
57-
clGetDeviceInfo(device, CL_DEVICE_GLOBAL_MEM_SIZE,
58-
sizeof(g_global_mem_size), &g_global_mem_size, NULL);
59-
if (error)
60-
{
61-
print_error(error,
62-
"clGetDeviceInfo failed for CL_DEVICE_GLOBAL_MEM_SIZE");
63-
return TEST_FAIL;
64-
}
49+
g_max_individual_allocation_size =
50+
get_device_info_max_mem_alloc_size(device);
51+
g_global_mem_size = get_device_info_global_mem_size(device);
6552

6653
log_info("Device reports CL_DEVICE_MAX_MEM_ALLOC_SIZE=%llu bytes (%gMB), "
6754
"CL_DEVICE_GLOBAL_MEM_SIZE=%llu bytes (%gMB).\n",

0 commit comments

Comments
 (0)