Skip to content

Commit 08e00e3

Browse files
authored
Merge pull request #729 from jszuppe/pr_default_device_queue
Default device queue
2 parents ed2fadb + 97b91bf commit 08e00e3

File tree

6 files changed

+82
-9
lines changed

6 files changed

+82
-9
lines changed

doc/Jamfile.v2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ---------------------------------------------------------------------------
22
# Copyright (c) 2013 Kyle Lutz <[email protected]>
3-
#
3+
#
44
# Distributed under the Boost Software License, Version 1.0
55
# See accompanying file LICENSE_1_0.txt or copy at
66
# http://www.boost.org/LICENSE_1_0.txt
@@ -95,6 +95,8 @@ doxygen autodoc
9595
see_opencl_ref{1}=\"See the documentation for \\opencl_ref{\\1} for more information.\" \\
9696
opencl2_ref{1}=\"<a href=\"http://www.khronos.org/registry/cl/sdk/2.0/docs/man/xhtml/\\1.html\">\\1()</a>\" \\
9797
see_opencl2_ref{1}=\"See the documentation for \\opencl2_ref{\\1} for more information.\" \\
98+
opencl21_ref{1}=\"<a href=\"http://www.khronos.org/registry/cl/sdk/2.1/docs/man/xhtml/\\1.html\">\\1()</a>\" \\
99+
see_opencl21_ref{1}=\"See the documentation for \\opencl21_ref{\\1} for more information.\" \\
98100
opencl_version_warning{2}=\"\\warning This method is only available if the OpenCL version is \\1.\\2 or later.\" \\
99101
"
100102
<xsl:param>"boost.doxygen.reftitle=Header Reference"

include/boost/compute/command_queue.hpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,35 @@ class command_queue
253253
return get_info<cl_command_queue_properties>(CL_QUEUE_PROPERTIES);
254254
}
255255

256+
#if defined(BOOST_COMPUTE_CL_VERSION_2_1) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
257+
/// Returns the current default device command queue for the underlying device.
258+
///
259+
/// \opencl_version_warning{2,1}
260+
command_queue get_default_device_queue() const
261+
{
262+
return command_queue(get_info<cl_command_queue>(CL_QUEUE_DEVICE_DEFAULT));
263+
}
264+
265+
/// Replaces the default device command queue for the underlying device
266+
/// with this command queue. Command queue must have been created
267+
/// with CL_QUEUE_ON_DEVICE flag.
268+
///
269+
/// \see_opencl21_ref{clSetDefaultDeviceCommandQueue}
270+
///
271+
/// \opencl_version_warning{2,1}
272+
void set_as_default_device_queue() const
273+
{
274+
cl_int ret = clSetDefaultDeviceCommandQueue(
275+
this->get_context().get(),
276+
this->get_device().get(),
277+
m_queue
278+
);
279+
if(ret != CL_SUCCESS){
280+
BOOST_THROW_EXCEPTION(opencl_error(ret));
281+
}
282+
}
283+
#endif // BOOST_COMPUTE_CL_VERSION_2_1
284+
256285
/// Enqueues a command to read data from \p buffer to host memory.
257286
///
258287
/// \see_opencl_ref{clEnqueueReadBuffer}
@@ -1886,6 +1915,12 @@ BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(command_queue,
18861915
((cl_command_queue_properties, CL_QUEUE_PROPERTIES))
18871916
)
18881917

1918+
#ifdef BOOST_COMPUTE_CL_VERSION_2_1
1919+
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(command_queue,
1920+
((cl_command_queue, CL_QUEUE_DEVICE_DEFAULT))
1921+
)
1922+
#endif // BOOST_COMPUTE_CL_VERSION_2_1
1923+
18891924
} // end compute namespace
18901925
} // end boost namespace
18911926

include/boost/compute/device.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class device
400400
/// Returns the current value of the host clock as seen by device
401401
/// in nanoseconds.
402402
///
403-
/// \see_opencl_ref{clGetHostTimer}
403+
/// \see_opencl21_ref{clGetHostTimer}
404404
///
405405
/// \opencl_version_warning{2,1}
406406
ulong_ get_host_timer() const
@@ -417,7 +417,7 @@ class device
417417
/// and the host timer as seen by device in nanoseconds. The first of returned
418418
/// std::pair is a device timer timestamp, the second is a host timer timestamp.
419419
///
420-
/// \see_opencl_ref{clGetDeviceAndHostTimer}
420+
/// \see_opencl21_ref{clGetDeviceAndHostTimer}
421421
///
422422
/// \opencl_version_warning{2,1}
423423
std::pair<ulong_, ulong_> get_device_and_host_timer() const
@@ -445,7 +445,7 @@ class device
445445
/// std::cout << device.get_host_timer<std::chrono::milliseconds>().count() << " ms";
446446
/// \endcode
447447
///
448-
/// \see_opencl_ref{clGetHostTimer}
448+
/// \see_opencl21_ref{clGetHostTimer}
449449
///
450450
/// \opencl_version_warning{2,1}
451451
template<class Duration>
@@ -460,7 +460,7 @@ class device
460460
/// The first of returned std::pair is a device timer timestamp, the second is
461461
/// a host timer timestamp.
462462
///
463-
/// \see_opencl_ref{clGetDeviceAndHostTimer}
463+
/// \see_opencl21_ref{clGetDeviceAndHostTimer}
464464
///
465465
/// \opencl_version_warning{2,1}
466466
template<class Duration>

include/boost/compute/kernel.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class kernel
134134
///
135135
/// \opencl_version_warning{2,1}
136136
///
137-
/// \see_opencl_ref{clCloneKernel}
137+
/// \see_opencl21_ref{clCloneKernel}
138138
kernel clone()
139139
{
140140
cl_int ret = 0;
@@ -233,7 +233,8 @@ class kernel
233233
/// for cl_khr_subgroups extension.
234234
///
235235
/// \opencl_version_warning{2,1}
236-
/// \see_opencl_ref{clGetKernelSubGroupInfo}
236+
/// \see_opencl21_ref{clGetKernelSubGroupInfo}
237+
/// \see_opencl2_ref{clGetKernelSubGroupInfoKHR}
237238
template<class T>
238239
boost::optional<T> get_sub_group_info(const device &device, cl_kernel_sub_group_info info,
239240
const size_t input_size, const void * input) const
@@ -288,7 +289,7 @@ class kernel
288289
/// optional if cl_khr_subgroups extension is not supported by \p device.
289290
///
290291
/// \opencl_version_warning{2,0}
291-
/// \see_opencl_ref{clGetKernelSubGroupInfoKHR}
292+
/// \see_opencl2_ref{clGetKernelSubGroupInfoKHR}
292293
template<class T>
293294
boost::optional<T> get_sub_group_info(const device &device, cl_kernel_sub_group_info info,
294295
const size_t input_size, const void * input) const

include/boost/compute/program.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ class program
587587
///
588588
/// \opencl_version_warning{2,1}
589589
///
590-
/// \see_opencl_ref{clCreateProgramWithIL}
590+
/// \see_opencl21_ref{clCreateProgramWithIL}
591591
static program create_with_il(const void * il_binary,
592592
const size_t il_size,
593593
const context &context)

test/test_command_queue.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,39 @@ BOOST_AUTO_TEST_CASE(enqueue_kernel_with_extents)
314314
}
315315
#endif // BOOST_COMPUTE_NO_HDR_INITIALIZER_LIST
316316

317+
#ifdef BOOST_COMPUTE_CL_VERSION_2_1
318+
BOOST_AUTO_TEST_CASE(get_default_device_queue)
319+
{
320+
REQUIRES_OPENCL_VERSION(2, 1);
321+
322+
boost::compute::command_queue default_device_queue(
323+
context, device,
324+
boost::compute::command_queue::on_device |
325+
boost::compute::command_queue::on_device_default |
326+
boost::compute::command_queue::enable_out_of_order_execution
327+
);
328+
BOOST_CHECK_NO_THROW(queue.get_info<CL_QUEUE_DEVICE_DEFAULT>());
329+
BOOST_CHECK_EQUAL(
330+
queue.get_default_device_queue(),
331+
default_device_queue
332+
);
333+
}
334+
335+
BOOST_AUTO_TEST_CASE(set_as_default_device_queue)
336+
{
337+
REQUIRES_OPENCL_VERSION(2, 1);
338+
339+
boost::compute::command_queue new_default_device_queue(
340+
context, device,
341+
boost::compute::command_queue::on_device |
342+
boost::compute::command_queue::enable_out_of_order_execution
343+
);
344+
new_default_device_queue.set_as_default_device_queue();
345+
BOOST_CHECK_EQUAL(
346+
queue.get_default_device_queue(),
347+
new_default_device_queue
348+
);
349+
}
350+
#endif
351+
317352
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)