2 // Copyright (c) 2018 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #include "command_queues_builder.h"
19 #include "error_handler.h"
21 namespace cldnn { namespace gpu{
23 command_queues_builder::command_queues_builder(const cl::Context& context, const cl::Device& device, const cl_platform_id& platform_id)
26 , _platform_id(platform_id)
27 , _priority_mode(cldnn_priority_disabled)
28 , _throttle_mode(cldnn_throttle_disabled)
31 cl_command_queue_properties command_queues_builder::get_properties()
33 cl_command_queue_properties ret = ((_profiling ? CL_QUEUE_PROFILING_ENABLE : 0) | (_out_of_order ? CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE : 0));
37 void command_queues_builder::build()
39 auto properties = get_properties();
41 if (_priority_mode == cldnn_priority_disabled &&
42 _throttle_mode == cldnn_throttle_disabled)
44 _queue = cl::CommandQueue(_context, _device, properties);
48 unsigned cl_queue_priority_value = CL_QUEUE_PRIORITY_MED_KHR;
50 switch (_priority_mode)
52 case cldnn_priority_high:
53 cl_queue_priority_value = CL_QUEUE_PRIORITY_HIGH_KHR;
55 case cldnn_priority_low:
56 cl_queue_priority_value = CL_QUEUE_PRIORITY_LOW_KHR;
62 unsigned cl_queue_throttle_value = CL_QUEUE_THROTTLE_MED_KHR;
64 switch (_throttle_mode)
66 case cldnn_throttle_high:
67 cl_queue_throttle_value = CL_QUEUE_THROTTLE_HIGH_KHR;
69 case cldnn_throttle_low:
70 cl_queue_throttle_value = CL_QUEUE_THROTTLE_LOW_KHR;
76 cl_int error_code = CL_SUCCESS;
78 if (_priority_mode != cldnn_priority_disabled &&
79 _throttle_mode != cldnn_throttle_disabled)
81 cl_queue_properties properties_low[] = {
82 CL_QUEUE_PRIORITY_KHR, cl_queue_priority_value,
83 CL_QUEUE_THROTTLE_KHR, cl_queue_throttle_value,
84 CL_QUEUE_PROPERTIES, properties,
87 _queue = clCreateCommandQueueWithProperties(
93 else if (_priority_mode != cldnn_priority_disabled)
95 cl_queue_properties properties_low[] = {
96 CL_QUEUE_PRIORITY_KHR, cl_queue_priority_value,
97 CL_QUEUE_PROPERTIES, properties,
100 _queue = clCreateCommandQueueWithProperties(
106 else if (_throttle_mode != cldnn_throttle_disabled)
108 cl_queue_properties properties_low[] = {
109 CL_QUEUE_THROTTLE_KHR, cl_queue_throttle_value,
110 CL_QUEUE_PROPERTIES, properties,
113 _queue = clCreateCommandQueueWithProperties(
120 if (error_code != CL_SUCCESS) {
121 CLDNN_ERROR_MESSAGE("Command queues builders", "clCreateCommandQueueWithPropertiesINTEL error " + std::to_string(error_code));
125 void command_queues_builder::set_priority_mode(cldnn_priority_mode_type priority, bool extension_support)
127 if (priority != cldnn_priority_disabled && !extension_support)
130 "Command queues builders - priority_mode",
131 "The param priority_mode is set in engine_configuration,\
132 but cl_khr_priority_hints or cl_khr_create_command_queue\
133 is not supported by current OpenCL implementation.");
135 _priority_mode = priority;
138 void command_queues_builder::set_throttle_mode(cldnn_throttle_mode_type throttle, bool extension_support)
140 if (throttle != cldnn_throttle_disabled && !extension_support)
143 "Command queues builders - throttle_mode",
144 "The param throttle_mode is set in engine_configuration,\
145 but cl_khr_throttle_hints is not supported by current OpenCL implementation.");
147 _throttle_mode = throttle;