Skip to content

Commit 272ca00

Browse files
cdai2bader
authored andcommitted
[SYCL] use OOO queues and will fall back to use in-order queue if OOO queue creation fails
1, SYCL runtime will try to create out-of-order queue first. 2, If it's created successfully, use this out-of-order queue. 3, If not, fallback to the emulation approach with in-order queue. Signed-off-by: Chunyang Dai <[email protected]>
1 parent e4c79bb commit 272ca00

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

sycl/include/CL/sycl/detail/queue_impl.hpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ class queue_impl {
6060

6161
cl_command_queue get() {
6262
if (m_OpenCLInterop) {
63-
CHECK_OCL_CODE(clRetainCommandQueue(m_CommandQueue));
64-
return m_CommandQueue;
63+
cl_command_queue command_queue = getHandleRef();
64+
CHECK_OCL_CODE(clRetainCommandQueue(command_queue));
65+
return command_queue;
6566
}
6667
throw invalid_object_error(
6768
"This instance of queue doesn't support OpenCL interoperability");
@@ -120,11 +121,10 @@ class queue_impl {
120121
m_Exceptions.clear();
121122
}
122123

123-
cl_command_queue createQueue() const {
124+
cl_command_queue createQueue() {
124125
cl_command_queue_properties CreationFlags = 0;
125126

126-
// FPGA RT can't handle out of order queue - create in order queue instead
127-
if (!m_Device.is_accelerator()) {
127+
if (m_SupportOOO) {
128128
CreationFlags = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE;
129129
}
130130

@@ -145,7 +145,15 @@ class queue_impl {
145145
Queue = clCreateCommandQueue(ClContext, m_Device.get(),
146146
CreationFlags, &Error);
147147
#endif
148-
CHECK_OCL_CODE(Error);
148+
// Tf creating out-of-order queue failed and this property is not
149+
// supported(for example, on FPGA), it will return
150+
// CL_INVALID_QUEUE_PROPERTIES and will try to create in-order queue.
151+
if (m_SupportOOO && Error == CL_INVALID_QUEUE_PROPERTIES) {
152+
m_SupportOOO = false;
153+
Queue = createQueue();
154+
} else {
155+
CHECK_OCL_CODE(Error);
156+
}
149157
// TODO catch an exception and put it to list of asynchronous exceptions
150158

151159
return Queue;
@@ -171,7 +179,7 @@ class queue_impl {
171179
}
172180

173181
cl_command_queue &getHandleRef() {
174-
if (!m_Device.is_accelerator()) {
182+
if (m_SupportOOO) {
175183
return m_CommandQueue;
176184
}
177185

@@ -218,6 +226,8 @@ class queue_impl {
218226

219227
bool m_OpenCLInterop = false;
220228
bool m_HostQueue = false;
229+
// Assume OOO support by default.
230+
bool m_SupportOOO = true;
221231
};
222232

223233
} // namespace detail

sycl/test/fpga_tests/fpga_queue.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ void GetCLQueue(event sycl_event, std::set<cl_command_queue>& cl_queues) {
3434
}
3535
}
3636

37+
int getExpectedQueueNumber(cl_device_id device_id, int default_value) {
38+
cl_command_queue_properties reportedProps;
39+
cl_int iRet = clGetDeviceInfo(device_id,
40+
CL_DEVICE_QUEUE_ON_HOST_PROPERTIES,
41+
sizeof(reportedProps),
42+
&reportedProps,
43+
NULL);
44+
assert(CL_SUCCESS == iRet && "Failed to obtain queue info from ocl device");
45+
return (reportedProps & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE)
46+
? 1 : default_value;
47+
}
48+
3749
int main() {
3850
int data[dataSize] = {0};
3951

@@ -98,11 +110,11 @@ int main() {
98110

99111
int result = cl_queues.size();
100112
device dev = Queue.get_device();
101-
int expected_result = dev.is_accelerator() ? 3 : dev.is_host() ? 0 : 1;
113+
int expected_result = dev.is_host() ? 0 : getExpectedQueueNumber(dev.get(), 3);
102114

103115
if (expected_result != result) {
104116
std::cout << "Result Num of queues = " << result << std::endl
105-
<< "Expected Num of queues = 3" << std::endl;
117+
<< "Expected Num of queues = "<< expected_result << std::endl;
106118

107119
return -1;
108120
}
@@ -140,12 +152,11 @@ int main() {
140152

141153
int result = cl_queues.size();
142154
device dev = Queue.get_device();
143-
int expected_result = dev.is_accelerator() ? maxNumQueues :
144-
dev.is_host() ? 0 : 1;
155+
int expected_result = dev.is_host() ? 0 : getExpectedQueueNumber(dev.get(), maxNumQueues);
145156

146157
if (expected_result != result) {
147158
std::cout << "Result Num of queues = " << result << std::endl
148-
<< "Expected Num of queues = " << maxNumQueues << std::endl;
159+
<< "Expected Num of queues = " << expected_result << std::endl;
149160

150161
return -1;
151162
}

0 commit comments

Comments
 (0)