28 #ifndef SPLA_CPU_M_REDUCE_HPP
29 #define SPLA_CPU_M_REDUCE_HPP
55 return "reduce matrix on cpu sequentially";
59 auto t = ctx.
task.template cast_safe<ScheduleTask_m_reduce>();
60 auto M = t->M.template cast_safe<TMatrix<T>>();
63 return execute_csr(ctx);
66 return execute_lil(ctx);
69 return execute_dok(ctx);
72 return execute_csr(ctx);
79 auto t = ctx.
task.template cast_safe<ScheduleTask_m_reduce>();
88 const CpuDok<T>* p_dok_M = M->template get<CpuDok<T>>();
89 auto& func_reduce = op_reduce->function;
91 T result = s->get_value();
93 for (
const auto& entry : p_dok_M->
Ax) {
94 result = func_reduce(result, entry.second);
97 r->get_value() = result;
102 Status execute_lil(
const DispatchContext& ctx) {
105 auto t = ctx.task.template cast_safe<ScheduleTask_m_reduce>();
107 ref_ptr<TScalar<T>> r = t->r.template cast_safe<TScalar<T>>();
108 ref_ptr<TScalar<T>> s = t->s.template cast_safe<TScalar<T>>();
109 ref_ptr<TMatrix<T>> M = t->M.template cast_safe<TMatrix<T>>();
110 ref_ptr<TOpBinary<T, T, T>> op_reduce = t->op_reduce.template cast_safe<TOpBinary<T, T, T>>();
114 const CpuLil<T>* p_lil_M = M->template get<CpuLil<T>>();
115 auto& func_reduce = op_reduce->function;
117 T result = s->get_value();
119 for (
const auto& row : p_lil_M->Ar) {
120 for (
const auto& entry : row) {
121 result = func_reduce(result, entry.second);
125 r->get_value() = result;
130 Status execute_csr(
const DispatchContext& ctx) {
133 auto t = ctx.task.template cast_safe<ScheduleTask_m_reduce>();
135 ref_ptr<TScalar<T>> r = t->r.template cast_safe<TScalar<T>>();
136 ref_ptr<TScalar<T>> s = t->s.template cast_safe<TScalar<T>>();
137 ref_ptr<TMatrix<T>> M = t->M.template cast_safe<TMatrix<T>>();
138 ref_ptr<TOpBinary<T, T, T>> op_reduce = t->op_reduce.template cast_safe<TOpBinary<T, T, T>>();
142 const CpuCsr<T>* p_csr_M = M->template get<CpuCsr<T>>();
143 auto& func_reduce = op_reduce->function;
145 T result = s->get_value();
147 for (
const auto v : p_csr_M->Ax) {
148 result = func_reduce(result, v);
151 r->get_value() = result;
Status of library operation execution.
Definition: cpu_m_reduce.hpp:46
std::string get_description() override
Definition: cpu_m_reduce.hpp:54
~Algo_m_reduce_cpu() override=default
std::string get_name() override
Definition: cpu_m_reduce.hpp:50
Status execute(const DispatchContext &ctx) override
Definition: cpu_m_reduce.hpp:58
Dictionary of keys sparse matrix format.
Definition: cpu_formats.hpp:128
robin_hood::unordered_flat_map< Key, T, pair_hash > Ax
Definition: cpu_formats.hpp:137
Algorithm suitable to process schedule task based on task string key.
Definition: registry.hpp:66
Automates reference counting and behaves as shared smart pointer.
Definition: ref.hpp:117
Definition: algorithm.hpp:37
Execution context of a single task.
Definition: dispatcher.hpp:46
ref_ptr< ScheduleTask > task
Definition: dispatcher.hpp:48
#define TIME_PROFILE_SCOPE(name)
Definition: time_profiler.hpp:92