17 #ifndef KOKKOS_EXPERIMENTAL_ERROR_REPORTER_HPP
18 #define KOKKOS_EXPERIMENTAL_ERROR_REPORTER_HPP
19 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
20 #define KOKKOS_IMPL_PUBLIC_INCLUDE
21 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_ERRORREPORTER
25 #include <Kokkos_Core.hpp>
26 #include <Kokkos_View.hpp>
30 namespace Experimental {
32 template <
typename ReportType,
typename DeviceType>
35 using report_type = ReportType;
36 using device_type = DeviceType;
37 using execution_space =
typename device_type::execution_space;
39 ErrorReporter(
int max_results)
40 : m_numReportsAttempted(
""),
41 m_reports(
"", max_results),
42 m_reporters(
"", max_results) {
46 int getCapacity()
const {
return m_reports.h_view.extent(0); }
50 int getNumReportAttempts();
52 void getReports(std::vector<int> &reporters_out,
53 std::vector<report_type> &reports_out);
56 typename DeviceType::execution_space>::HostMirror
59 typename DeviceType::execution_space>::HostMirror
64 void resize(
const size_t new_size);
66 bool full() {
return (getNumReportAttempts() >= getCapacity()); }
68 KOKKOS_INLINE_FUNCTION
69 bool add_report(
int reporter_id, report_type report)
const {
70 int idx = Kokkos::atomic_fetch_add(&m_numReportsAttempted(), 1);
72 if (idx >= 0 && (idx < static_cast<int>(m_reports.d_view.extent(0)))) {
73 m_reporters.d_view(idx) = reporter_id;
74 m_reports.d_view(idx) = report;
83 using reports_dualview_t = Kokkos::DualView<report_type *, device_type>;
85 using host_mirror_space =
typename reports_dualview_t::host_mirror_space;
87 reports_dualview_t m_reports;
88 Kokkos::DualView<int *, device_type> m_reporters;
91 template <
typename ReportType,
typename DeviceType>
92 inline int ErrorReporter<ReportType, DeviceType>::getNumReports() {
94 Kokkos::deep_copy(num_reports, m_numReportsAttempted);
95 if (num_reports > static_cast<int>(m_reports.h_view.extent(0))) {
96 num_reports = m_reports.h_view.extent(0);
101 template <
typename ReportType,
typename DeviceType>
102 inline int ErrorReporter<ReportType, DeviceType>::getNumReportAttempts() {
104 Kokkos::deep_copy(num_reports, m_numReportsAttempted);
108 template <
typename ReportType,
typename DeviceType>
109 void ErrorReporter<ReportType, DeviceType>::getReports(
110 std::vector<int> &reporters_out, std::vector<report_type> &reports_out) {
111 int num_reports = getNumReports();
112 reporters_out.clear();
113 reporters_out.reserve(num_reports);
115 reports_out.reserve(num_reports);
117 if (num_reports > 0) {
118 m_reports.template sync<host_mirror_space>();
119 m_reporters.template sync<host_mirror_space>();
121 for (
int i = 0; i < num_reports; ++i) {
122 reporters_out.push_back(m_reporters.h_view(i));
123 reports_out.push_back(m_reports.h_view(i));
128 template <
typename ReportType,
typename DeviceType>
129 void ErrorReporter<ReportType, DeviceType>::getReports(
131 int *,
typename DeviceType::execution_space>::HostMirror &reporters_out,
133 typename DeviceType::execution_space>::HostMirror
135 int num_reports = getNumReports();
137 "ErrorReport::reporters_out", num_reports);
139 "ErrorReport::reports_out", num_reports);
141 if (num_reports > 0) {
142 m_reports.template sync<host_mirror_space>();
143 m_reporters.template sync<host_mirror_space>();
145 for (
int i = 0; i < num_reports; ++i) {
146 reporters_out(i) = m_reporters.h_view(i);
147 reports_out(i) = m_reports.h_view(i);
152 template <
typename ReportType,
typename DeviceType>
153 void ErrorReporter<ReportType, DeviceType>::clear() {
155 Kokkos::deep_copy(m_numReportsAttempted, num_reports);
156 m_reports.template modify<execution_space>();
157 m_reporters.template modify<execution_space>();
160 template <
typename ReportType,
typename DeviceType>
161 void ErrorReporter<ReportType, DeviceType>::resize(
const size_t new_size) {
162 m_reports.resize(new_size);
163 m_reporters.resize(new_size);
164 typename DeviceType::execution_space().fence(
165 "Kokkos::Experimental::ErrorReporter::resize: fence after resizing");
171 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_ERRORREPORTER
172 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
173 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_ERRORREPORTER
Declaration and definition of Kokkos::DualView.
View to an array of data.
View< typename traits::non_const_data_type, typename traits::array_layout, Device< DefaultHostExecutionSpace, typename traits::host_mirror_space::memory_space >, typename traits::hooks_policy > HostMirror
Compatible HostMirror view.