FreeTensor
Loading...
Searching...
No Matches
for_property.h
Go to the documentation of this file.
1#ifndef FREE_TENSOR_FOR_PROPERTY_H
2#define FREE_TENSOR_FOR_PROPERTY_H
3
4#include <expr.h>
5#include <parallel_scope.h>
6#include <reduce_op.h>
7#include <sub_tree.h>
8
9namespace freetensor {
10
11struct ReductionItem : public ASTPart {
13 std::string var_;
15 ends_ = ChildOf{this};
21
22 void compHash() override;
23};
24
25template <class Tbegins, class Tends>
27 Tbegins &&begins, Tends &&ends,
28 bool syncFlush) {
29 auto r = Ref<ReductionItem>::make();
30 r->op_ = op;
31 r->var_ = var;
32 r->begins_ = std::forward<Tbegins>(begins);
33 r->ends_ = std::forward<Tends>(ends);
34 r->syncFlush_ = syncFlush;
35 return r;
36}
37
38struct ForProperty : public ASTPart {
42 std::vector<std::string> noDeps_; // vars that are explicitly marked to have
43 // no dependences over this loop
44 bool preferLibs_; // Aggresively transform to external library calls in
45 // auto-schedule
46
48 : parallel_(), unroll_(false), vectorize_(false), preferLibs_(false) {}
49
51 auto ret = Ref<ForProperty>::make(*this);
52 ret->parallel_ = parallel;
53 return ret;
54 }
56 auto ret = Ref<ForProperty>::make(*this);
57 ret->unroll_ = unroll;
58 return ret;
59 }
61 auto ret = Ref<ForProperty>::make(*this);
62 ret->vectorize_ = vectorize;
63 return ret;
64 }
65 Ref<ForProperty> withNoDeps(const std::vector<std::string> &noDeps) {
66 auto ret = Ref<ForProperty>::make(*this);
67 ret->noDeps_ = noDeps;
68 return ret;
69 }
70 Ref<ForProperty> withPreferLibs(bool preferLibs = true) {
71 auto ret = Ref<ForProperty>::make(*this);
72 ret->preferLibs_ = preferLibs;
73 return ret;
74 }
75
76 void compHash() override;
77};
78
80 std::vector<Expr> begins, ends;
81 begins.reserve(r->begins_.size());
82 ends.reserve(r->ends_.size());
83 for (auto &&item : r->begins_) {
84 begins.emplace_back(deepCopy(item));
85 }
86 for (auto &&item : r->ends_) {
87 ends.emplace_back(deepCopy(item));
88 }
89 return makeReductionItem(r->op_, r->var_, std::move(begins),
90 std::move(ends), r->syncFlush_);
91}
92
94 auto p = Ref<ForProperty>::make();
95 p->parallel_ = _p->parallel_;
96 p->unroll_ = _p->unroll_;
97 p->vectorize_ = _p->vectorize_;
98 p->reductions_ = _p->reductions_;
99 p->noDeps_ = _p->noDeps_;
100 p->preferLibs_ = _p->preferLibs_;
101 return p;
102}
103
104} // namespace freetensor
105
106#endif // FREE_TENSOR_FOR_PROPERTY_H
Definition: sub_tree.h:50
Definition: ref.h:24
static Ref make()
Definition: ref.h:105
Definition: sub_tree.h:305
Definition: allocator.h:9
Ref< ReductionItem > makeReductionItem(ReduceOp op, const std::string &var, Tbegins &&begins, Tends &&ends, bool syncFlush)
Definition: for_property.h:26
Stmt unroll(const Stmt &ast, const ID &loop, bool immediate)
Definition: unroll.cc:64
std::variant< SerialScope, OpenMPScope, CUDAStreamScope, CUDAScope > ParallelScope
Definition: parallel_scope.h:73
Expr deepCopy(const Expr &op)
Definition: ast.cc:364
ReduceOp
Definition: reduce_op.h:30
Stmt vectorize(const Stmt &ast, const ID &loop)
Definition: vectorize.cc:19
Definition: sub_tree.h:20
Definition: for_property.h:38
Ref< ForProperty > withNoDeps(const std::vector< std::string > &noDeps)
Definition: for_property.h:65
ForProperty()
Definition: for_property.h:47
std::vector< std::string > noDeps_
Definition: for_property.h:42
Ref< ForProperty > withParallel(const ParallelScope &parallel)
Definition: for_property.h:50
bool unroll_
Definition: for_property.h:40
Ref< ForProperty > withPreferLibs(bool preferLibs=true)
Definition: for_property.h:70
Ref< ForProperty > withVectorize(bool vectorize=true)
Definition: for_property.h:60
bool preferLibs_
Definition: for_property.h:44
ParallelScope parallel_
Definition: for_property.h:39
Ref< ForProperty > withUnroll(bool unroll=true)
Definition: for_property.h:55
SubTreeList< ReductionItem > reductions_
Definition: for_property.h:41
void compHash() override
Definition: for_property.cc:8
bool vectorize_
Definition: for_property.h:40
Definition: for_property.h:11
SubTreeList< ExprNode > begins_
Definition: for_property.h:14
ReduceOp op_
Definition: for_property.h:12
void compHash() override
Definition: for_property.cc:6
SubTreeList< ExprNode > ends_
Definition: for_property.h:15
bool syncFlush_
[begins_, ends_)
Definition: for_property.h:16
std::string var_
Definition: for_property.h:13