|
21 | 21 | #include <boost/compute/config.hpp> |
22 | 22 | #include <boost/compute/exception.hpp> |
23 | 23 | #include <boost/compute/types/fundamental.hpp> |
| 24 | +#include <boost/compute/detail/duration.hpp> |
24 | 25 | #include <boost/compute/detail/get_object_info.hpp> |
25 | 26 | #include <boost/compute/detail/assert_cl_success.hpp> |
26 | 27 |
|
@@ -395,6 +396,85 @@ class device |
395 | 396 | } |
396 | 397 | #endif // BOOST_COMPUTE_CL_VERSION_1_2 |
397 | 398 |
|
| 399 | + #if defined(BOOST_COMPUTE_CL_VERSION_2_1) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED) |
| 400 | + /// Returns the current value of the host clock as seen by device |
| 401 | + /// in nanoseconds. |
| 402 | + /// |
| 403 | + /// \see_opencl_ref{clGetHostTimer} |
| 404 | + /// |
| 405 | + /// \opencl_version_warning{2,1} |
| 406 | + ulong_ get_host_timer() const |
| 407 | + { |
| 408 | + ulong_ host_timestamp = 0; |
| 409 | + cl_int ret = clGetHostTimer(m_id, &host_timestamp); |
| 410 | + if(ret != CL_SUCCESS){ |
| 411 | + BOOST_THROW_EXCEPTION(opencl_error(ret)); |
| 412 | + } |
| 413 | + return host_timestamp; |
| 414 | + } |
| 415 | + |
| 416 | + /// Returns a reasonably synchronized pair of timestamps from the device timer |
| 417 | + /// and the host timer as seen by device in nanoseconds. The first of returned |
| 418 | + /// std::pair is a device timer timestamp, the second is a host timer timestamp. |
| 419 | + /// |
| 420 | + /// \see_opencl_ref{clGetDeviceAndHostTimer} |
| 421 | + /// |
| 422 | + /// \opencl_version_warning{2,1} |
| 423 | + std::pair<ulong_, ulong_> get_device_and_host_timer() const |
| 424 | + { |
| 425 | + ulong_ host_timestamp; |
| 426 | + ulong_ device_timestamp; |
| 427 | + cl_int ret = clGetDeviceAndHostTimer( |
| 428 | + m_id, &device_timestamp, &host_timestamp |
| 429 | + ); |
| 430 | + if(ret != CL_SUCCESS){ |
| 431 | + BOOST_THROW_EXCEPTION(opencl_error(ret)); |
| 432 | + } |
| 433 | + return std::make_pair( |
| 434 | + device_timestamp, host_timestamp |
| 435 | + ); |
| 436 | + } |
| 437 | + |
| 438 | + #if !defined(BOOST_COMPUTE_NO_HDR_CHRONO) || !defined(BOOST_COMPUTE_NO_BOOST_CHRONO) |
| 439 | + /// Returns the current value of the host clock as seen by device |
| 440 | + /// as duration. |
| 441 | + /// |
| 442 | + /// For example, to print the current value of the host clock as seen by device |
| 443 | + /// in milliseconds: |
| 444 | + /// \code |
| 445 | + /// std::cout << device.get_host_timer<std::chrono::milliseconds>().count() << " ms"; |
| 446 | + /// \endcode |
| 447 | + /// |
| 448 | + /// \see_opencl_ref{clGetHostTimer} |
| 449 | + /// |
| 450 | + /// \opencl_version_warning{2,1} |
| 451 | + template<class Duration> |
| 452 | + Duration get_host_timer() const |
| 453 | + { |
| 454 | + const ulong_ nanoseconds = this->get_host_timer(); |
| 455 | + return detail::make_duration_from_nanoseconds(Duration(), nanoseconds); |
| 456 | + } |
| 457 | + |
| 458 | + /// Returns a reasonably synchronized pair of timestamps from the device timer |
| 459 | + /// and the host timer as seen by device as a std::pair<Duration, Duration> value. |
| 460 | + /// The first of returned std::pair is a device timer timestamp, the second is |
| 461 | + /// a host timer timestamp. |
| 462 | + /// |
| 463 | + /// \see_opencl_ref{clGetDeviceAndHostTimer} |
| 464 | + /// |
| 465 | + /// \opencl_version_warning{2,1} |
| 466 | + template<class Duration> |
| 467 | + std::pair<Duration, Duration> get_device_and_host_timer() const |
| 468 | + { |
| 469 | + const std::pair<ulong_, ulong_> timestamps = this->get_device_and_host_timer(); |
| 470 | + return std::make_pair( |
| 471 | + detail::make_duration_from_nanoseconds(Duration(), timestamps.first), |
| 472 | + detail::make_duration_from_nanoseconds(Duration(), timestamps.second) |
| 473 | + ); |
| 474 | + } |
| 475 | + #endif // !defined(BOOST_COMPUTE_NO_HDR_CHRONO) || !defined(BOOST_COMPUTE_NO_BOOST_CHRONO) |
| 476 | + #endif // BOOST_COMPUTE_CL_VERSION_2_1 |
| 477 | + |
398 | 478 | /// Returns \c true if the device is the same at \p other. |
399 | 479 | bool operator==(const device &other) const |
400 | 480 | { |
@@ -579,6 +659,14 @@ BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(device, |
579 | 659 | ) |
580 | 660 | #endif // BOOST_COMPUTE_CL_VERSION_2_0 |
581 | 661 |
|
| 662 | +#ifdef BOOST_COMPUTE_CL_VERSION_2_1 |
| 663 | +BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(device, |
| 664 | + ((std::string, CL_DEVICE_IL_VERSION)) |
| 665 | + ((cl_uint, CL_DEVICE_MAX_NUM_SUB_GROUPS)) |
| 666 | + ((bool, CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS)) |
| 667 | +) |
| 668 | +#endif // BOOST_COMPUTE_CL_VERSION_2_1 |
| 669 | + |
582 | 670 | } // end compute namespace |
583 | 671 | } // end boost namespace |
584 | 672 |
|
|
0 commit comments