MCPcopy Create free account
hub / github.com/KhronosGroup/OpenCL-CTS / init_cl

Function init_cl

test_conformance/allocations/main.cpp:44–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42cl_uint checksum;
43
44test_status init_cl(cl_device_id device)
45{
46 int error;
47
48 g_max_individual_allocation_size =
49 get_device_info_max_mem_alloc_size(device);
50 g_global_mem_size = get_device_info_global_mem_size(device);
51
52 log_info("Device reports CL_DEVICE_MAX_MEM_ALLOC_SIZE=%llu bytes (%gMB), "
53 "CL_DEVICE_GLOBAL_MEM_SIZE=%llu bytes (%gMB).\n",
54 llu(g_max_individual_allocation_size),
55 toMB(g_max_individual_allocation_size), llu(g_global_mem_size),
56 toMB(g_global_mem_size));
57
58 if (g_global_mem_size > (cl_ulong)SIZE_MAX)
59 {
60 g_global_mem_size = (cl_ulong)SIZE_MAX;
61 }
62
63 if (g_max_individual_allocation_size > g_global_mem_size)
64 {
65 log_error("FAILURE: CL_DEVICE_MAX_MEM_ALLOC_SIZE (%llu) is greater "
66 "than the CL_DEVICE_GLOBAL_MEM_SIZE (%llu)\n",
67 llu(g_max_individual_allocation_size),
68 llu(g_global_mem_size));
69 return TEST_FAIL;
70 }
71
72 // We may need to back off the global_mem_size on unified memory devices to
73 // leave room for application and operating system code and associated data
74 // in the working set, so we dont start pathologically paging. Check to see
75 // if we are a unified memory device
76 cl_bool hasUnifiedMemory = CL_FALSE;
77 if ((error = clGetDeviceInfo(device, CL_DEVICE_HOST_UNIFIED_MEMORY,
78 sizeof(hasUnifiedMemory), &hasUnifiedMemory,
79 NULL)))
80 {
81 print_error(error,
82 "clGetDeviceInfo failed for CL_DEVICE_HOST_UNIFIED_MEMORY");
83 return TEST_FAIL;
84 }
85 // we share unified memory so back off to 1/2 the global memory size.
86 if (CL_TRUE == hasUnifiedMemory)
87 {
88 g_global_mem_size -= g_global_mem_size / 2;
89 log_info(
90 "Device shares memory with the host, so backing off the maximum "
91 "combined allocation size to be %gMB to avoid rampant paging.\n",
92 toMB(g_global_mem_size));
93 }
94 else
95 {
96 // Lets just use 60% of total available memory as framework/driver may
97 // not allow using all of it e.g. vram on GPU is used by window server
98 // and even for this test, we need some space for context, queue, kernel
99 // code on GPU.
100 g_global_mem_size *= 0.60;
101 }

Callers

nothing calls this directly

Calls 4

toMBFunction · 0.85
RandomSeedClass · 0.85

Tested by

no test coverage detected