34 #if defined(ARM_COMPUTE_ASSERTS_ENABLED)
35 void printf_callback(
const char *buffer,
unsigned int len,
size_t complete,
void *user_data)
38 printf(
"%.*s", len, buffer);
53 void initialise_context_properties(
const cl::Platform &platform,
const cl::Device &device, std::array<cl_context_properties, 7> &prop)
56 #if defined(ARM_COMPUTE_ASSERTS_ENABLED)
61 std::array<cl_context_properties, 7> properties_printf =
63 CL_CONTEXT_PLATFORM,
reinterpret_cast<cl_context_properties
>(platform()),
65 CL_PRINTF_CALLBACK_ARM,
reinterpret_cast<cl_context_properties
>(printf_callback),
68 CL_PRINTF_BUFFERSIZE_ARM, 0x1000,
71 prop = properties_printf;
74 #endif // defined(ARM_COMPUTE_ASSERTS_ENABLED)
76 std::array<cl_context_properties, 3> properties =
78 CL_CONTEXT_PLATFORM,
reinterpret_cast<cl_context_properties
>(platform()),
81 std::copy(properties.begin(), properties.end(), prop.begin());
90 std::vector<cl::Platform> platforms;
91 cl::Platform::get(&platforms);
94 cl::Platform selected_platform{
nullptr };
97 switch(cl_backend_type)
100 selected_platform = platforms[0];
103 for(
auto p : platforms)
105 std::string res = p.getInfo<CL_PLATFORM_NAME>();
106 if(res.find(
"clvk") != std::string::npos)
108 selected_platform = p;
117 if(!selected_platform())
122 return selected_platform;
125 std::tuple<cl::Context, cl::Device, cl_int>
131 std::vector<cl::Device> platform_devices;
132 p.getDevices(CL_DEVICE_TYPE_DEFAULT, &platform_devices);
134 device = platform_devices[0];
135 cl_int err = CL_SUCCESS;
136 std::array<cl_context_properties, 7> properties = { 0, 0, 0, 0, 0, 0, 0 };
137 initialise_context_properties(p, device, properties);
138 cl::Context cl_context = cl::Context(device, properties.data(),
nullptr,
nullptr, &err);
140 return std::make_tuple(cl_context, device, err);