Skip to content

Commit 6d1e297

Browse files
alexeyvoronov-intelvladimirlaz
authored andcommitted
[SYCL] Use context passed to queue instead of new one.
Before this patch, the context passed to queue constructor was ignored, and a new context created from the device was stored inside the queue. Signed-off-by: Voronov, Alexey <[email protected]> Signed-off-by: Vladimir Lazarev <[email protected]>
1 parent 540fe39 commit 6d1e297

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

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

100644100755
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ class queue_impl {
2727
public:
2828
queue_impl(const device &SyclDevice, async_handler AsyncHandler,
2929
const property_list &PropList)
30-
: m_Device(SyclDevice), m_Context(m_Device), m_AsyncHandler(AsyncHandler),
30+
: queue_impl(SyclDevice, context(SyclDevice), AsyncHandler, PropList){};
31+
32+
queue_impl(const device &SyclDevice, const context &Context,
33+
async_handler AsyncHandler, const property_list &PropList)
34+
: m_Device(SyclDevice), m_Context(Context), m_AsyncHandler(AsyncHandler),
3135
m_PropList(PropList), m_HostQueue(m_Device.is_host()) {
3236
m_OpenCLInterop = !m_HostQueue;
3337
if (!m_HostQueue) {
@@ -160,8 +164,7 @@ class queue_impl {
160164
if (m_Queues.empty()) {
161165
m_Queues.push_back(m_CommandQueue);
162166
return m_CommandQueue;
163-
}
164-
else if (m_Queues.size() < MaxNumQueues) {
167+
} else if (m_Queues.size() < MaxNumQueues) {
165168
m_Queues.push_back(createQueue());
166169
return m_Queues.back();
167170
}

sycl/source/queue.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ queue::queue(const context &syclContext, const device_selector &deviceSelector,
2020
return deviceSelector(d1) < deviceSelector(d2);
2121
};
2222

23-
*this = queue(*std::max_element(Devs.begin(), Devs.end(), Comp), asyncHandler,
24-
propList);
23+
const device &syclDevice = *std::max_element(Devs.begin(), Devs.end(), Comp);
24+
impl = std::make_shared<detail::queue_impl>(syclDevice, syclContext,
25+
asyncHandler, propList);
2526
}
2627

2728
queue::queue(const device &syclDevice, const async_handler &asyncHandler,

sycl/test/basic_tests/queue.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,18 @@ int main() {
8888
queue Queue(pl);
8989
try {
9090
Queue.throw_asynchronous();
91-
}
92-
catch (const std::bad_function_call& e) {
93-
std::cout << "Default asynchronous handler call failed: " << e.what() << std::endl;
91+
} catch (const std::bad_function_call &e) {
92+
std::cout << "Default asynchronous handler call failed: " << e.what()
93+
<< std::endl;
9494
throw;
9595
}
9696
}
97+
98+
{
99+
default_selector Selector;
100+
device Device = Selector.select_device();
101+
context Context(Device);
102+
queue Queue(Context, Selector);
103+
assert(Context == Queue.get_context());
104+
}
97105
}

0 commit comments

Comments
 (0)