45 #ifndef KOKKOS_EXPERIMENTAL_ERROR_REPORTER_HPP
46 #define KOKKOS_EXPERIMENTAL_ERROR_REPORTER_HPP
49 #include <Kokkos_Core.hpp>
50 #include <Kokkos_View.hpp>
54 namespace Experimental {
56 template <
typename ReportType,
typename DeviceType>
59 typedef ReportType report_type;
60 typedef DeviceType device_type;
61 typedef typename device_type::execution_space execution_space;
63 ErrorReporter(
int max_results)
64 : m_numReportsAttempted(
""),
65 m_reports(
"", max_results),
66 m_reporters(
"", max_results) {
70 int getCapacity()
const {
return m_reports.h_view.extent(0); }
74 int getNumReportAttempts();
76 void getReports(std::vector<int> &reporters_out,
77 std::vector<report_type> &reports_out);
80 typename DeviceType::execution_space>::HostMirror
83 typename DeviceType::execution_space>::HostMirror
88 void resize(
const size_t new_size);
90 bool full() {
return (getNumReportAttempts() >= getCapacity()); }
92 KOKKOS_INLINE_FUNCTION
93 bool add_report(
int reporter_id, report_type report)
const {
94 int idx = Kokkos::atomic_fetch_add(&m_numReportsAttempted(), 1);
96 if (idx >= 0 && (idx < static_cast<int>(m_reports.d_view.extent(0)))) {
97 m_reporters.d_view(idx) = reporter_id;
98 m_reports.d_view(idx) = report;
107 typedef Kokkos::DualView<report_type *, execution_space> reports_dualview_t;
109 typedef typename reports_dualview_t::host_mirror_space host_mirror_space;
111 reports_dualview_t m_reports;
112 Kokkos::DualView<int *, execution_space> m_reporters;
115 template <
typename ReportType,
typename DeviceType>
116 inline int ErrorReporter<ReportType, DeviceType>::getNumReports() {
119 if (num_reports > static_cast<int>(m_reports.h_view.extent(0))) {
120 num_reports = m_reports.h_view.extent(0);
125 template <
typename ReportType,
typename DeviceType>
126 inline int ErrorReporter<ReportType, DeviceType>::getNumReportAttempts() {
132 template <
typename ReportType,
typename DeviceType>
133 void ErrorReporter<ReportType, DeviceType>::getReports(
134 std::vector<int> &reporters_out, std::vector<report_type> &reports_out) {
135 int num_reports = getNumReports();
136 reporters_out.clear();
137 reporters_out.reserve(num_reports);
139 reports_out.reserve(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.push_back(m_reporters.h_view(i));
147 reports_out.push_back(m_reports.h_view(i));
152 template <
typename ReportType,
typename DeviceType>
153 void ErrorReporter<ReportType, DeviceType>::getReports(
155 int *,
typename DeviceType::execution_space>::HostMirror &reporters_out,
157 typename DeviceType::execution_space>::HostMirror
159 int num_reports = getNumReports();
162 HostMirror(
"ErrorReport::reporters_out", num_reports);
165 "ErrorReport::reports_out", num_reports);
167 if (num_reports > 0) {
168 m_reports.template sync<host_mirror_space>();
169 m_reporters.template sync<host_mirror_space>();
171 for (
int i = 0; i < num_reports; ++i) {
172 reporters_out(i) = m_reporters.h_view(i);
173 reports_out(i) = m_reports.h_view(i);
178 template <
typename ReportType,
typename DeviceType>
179 void ErrorReporter<ReportType, DeviceType>::clear() {
182 m_reports.template modify<execution_space>();
183 m_reporters.template modify<execution_space>();
186 template <
typename ReportType,
typename DeviceType>
187 void ErrorReporter<ReportType, DeviceType>::resize(
const size_t new_size) {
188 m_reports.resize(new_size);
189 m_reporters.resize(new_size);
190 typename DeviceType::execution_space().fence();
Declaration and definition of Kokkos::DualView.
void deep_copy(const View< DT, DP...> &dst, typename ViewTraits< DT, DP...>::const_value_type &value, typename std::enable_if< std::is_same< typename ViewTraits< DT, DP...>::specialize, void >::value >::type *=nullptr)
Deep copy a value from Host memory into a view.
View< typename traits::non_const_data_type, typename traits::array_layout, Device< DefaultHostExecutionSpace, typename traits::host_mirror_space::memory_space > > HostMirror
Compatible HostMirror view.
View to an array of data.
std::enable_if< std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutLeft >::value||std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutRight >::value >::type resize(Kokkos::View< T, P...> &v, const size_t n0=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n1=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n2=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n3=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n4=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n5=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n6=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n7=KOKKOS_IMPL_CTOR_DEFAULT_ARG)
Resize a view with copying old data to new data at the corresponding indices.