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);
static CLScheduler & get()
Access the scheduler singleton.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
void schedule_kernel_on_ctx(CLRuntimeContext *ctx, ICLKernel *kernel, bool flush=true)
Schedules a kernel using the context if not nullptr else uses the legacy scheduling flow.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
std::tuple< cl::Context, cl::Device, cl_int > create_opencl_context_and_device(CLBackendType cl_backend_type)
This function creates an OpenCL context and a device.
SimpleTensor< T > copy(const SimpleTensor< T > &src, const TensorShape &output_shape)
Common interface for all the OpenCL kernels.
Copyright (c) 2017-2021 Arm Limited.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
void enqueue(ICLKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.
CLBackendType
List the possible OpenCL backends.
bool device_supports_extension(const cl::Device &device, const char *extension_name)
Helper function to check whether a given extension is supported.
cl::Platform select_preferable_platform(CLBackendType cl_backend_type)
This function selects the OpenCL platform based on the backend type.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
CLScheduler * gpu_scheduler()
bool opencl_is_available()
Check if OpenCL is available.