spla
Loading...
Searching...
No Matches
cpu_v_count_mf.hpp
Go to the documentation of this file.
1/**********************************************************************************/
2/* This file is part of spla project */
3/* https://github.com/JetBrains-Research/spla */
4/**********************************************************************************/
5/* MIT License */
6/* */
7/* Copyright (c) 2023 SparseLinearAlgebra */
8/* */
9/* Permission is hereby granted, free of charge, to any person obtaining a copy */
10/* of this software and associated documentation files (the "Software"), to deal */
11/* in the Software without restriction, including without limitation the rights */
12/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
13/* copies of the Software, and to permit persons to whom the Software is */
14/* furnished to do so, subject to the following conditions: */
15/* */
16/* The above copyright notice and this permission notice shall be included in all */
17/* copies or substantial portions of the Software. */
18/* */
19/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
20/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
21/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
22/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
23/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
24/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
25/* SOFTWARE. */
26/**********************************************************************************/
27
28#ifndef SPLA_CPU_V_COUNT_MF_HPP
29#define SPLA_CPU_V_COUNT_MF_HPP
30
32
33#include <core/dispatcher.hpp>
34#include <core/registry.hpp>
35#include <core/top.hpp>
36#include <core/tscalar.hpp>
37#include <core/ttype.hpp>
38#include <core/tvector.hpp>
39
40namespace spla {
41
42 template<typename T>
43 class Algo_v_count_mf_cpu final : public RegistryAlgo {
44 public:
45 ~Algo_v_count_mf_cpu() override = default;
46
47 std::string get_name() override {
48 return "v_count_mf";
49 }
50
51 std::string get_description() override {
52 return "sequential count mf";
53 }
54
55 Status execute(const DispatchContext& ctx) override {
56 auto t = ctx.task.template cast_safe<ScheduleTask_v_count_mf>();
57 ref_ptr<TVector<T>> v = t->v.template cast_safe<TVector<T>>();
58
59 if (v->is_valid(FormatVector::CpuDok))
60 return execute_dok(ctx);
61 if (v->is_valid(FormatVector::CpuCoo))
62 return execute_coo(ctx);
63 if (v->is_valid(FormatVector::CpuDense))
64 return execute_dense(ctx);
65
66 return execute_coo(ctx);
67 }
68
69 private:
70 Status execute_dok(const DispatchContext& ctx) {
71 TIME_PROFILE_SCOPE("cpu/v_count_mf_dok");
72
73 auto t = ctx.task.template cast_safe<ScheduleTask_v_count_mf>();
74 ref_ptr<TVector<T>> v = t->v.template cast_safe<TVector<T>>();
75 CpuDokVec<T>* dec_v = v->template get<CpuDokVec<T>>();
76
77 t->r->set_uint(dec_v->values);
78
79 return Status::Ok;
80 }
81 Status execute_coo(const DispatchContext& ctx) {
82 TIME_PROFILE_SCOPE("cpu/v_count_mf_coo");
83
84 auto t = ctx.task.template cast_safe<ScheduleTask_v_count_mf>();
85 ref_ptr<TVector<T>> v = t->v.template cast_safe<TVector<T>>();
86 CpuCooVec<T>* dec_v = v->template get<CpuCooVec<T>>();
87
88 t->r->set_uint(dec_v->values);
89
90 return Status::Ok;
91 }
92 Status execute_dense(const DispatchContext& ctx) {
93 TIME_PROFILE_SCOPE("cpu/v_count_mf_dense");
94
95 auto t = ctx.task.template cast_safe<ScheduleTask_v_count_mf>();
96 ref_ptr<TVector<T>> v = t->v.template cast_safe<TVector<T>>();
97 CpuDenseVec<T>* dec_v = v->template get<CpuDenseVec<T>>();
98
99 uint values = 0;
100 const T ref = v->get_fill_value();
101
102 for (uint i = 0; i < v->get_n_rows(); i++) {
103 if (dec_v->Ax[i] != ref) {
104 values += 1;
105 }
106 }
107
108 t->r->set_uint(values);
109
110 return Status::Ok;
111 }
112 };
113
114}// namespace spla
115
116
117#endif//SPLA_CPU_V_COUNT_MF_HPP
Status of library operation execution.
Definition cpu_v_count_mf.hpp:43
std::string get_description() override
Definition cpu_v_count_mf.hpp:51
~Algo_v_count_mf_cpu() override=default
Status execute(const DispatchContext &ctx) override
Definition cpu_v_count_mf.hpp:55
std::string get_name() override
Definition cpu_v_count_mf.hpp:47
Definition cpu_formats.hpp:55
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
std::uint32_t uint
Library index and size type.
Definition config.hpp:56
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