FreeTensor
Loading...
Searching...
No Matches
normalize_threads.h
Go to the documentation of this file.
1#ifndef FREE_TENSOR_GPU_NORMALIZE_THREADS_H
2#define FREE_TENSOR_GPU_NORMALIZE_THREADS_H
3
4#ifdef FT_WITH_CUDA
5
6#include <unordered_map>
7
8#include <func.h>
9#include <mutator.h>
10#include <pass/shrink_for.h>
11
12namespace freetensor {
13
14namespace gpu {
15
16class NormalizeThreads : public Mutator {
17 Stmt root_;
18 std::unordered_map<std::string, std::string> varMap_;
19 std::unordered_map<ParallelScope, int>
20 inside_; // Multiple nested `threadIdx.x`s are possible. See the
21 // doc-string of schedule/parallelize
22 std::unordered_map<ParallelScope, std::vector<ID>> loops_;
23 bool inKernel_ = false;
24
25 public:
26 NormalizeThreads(const Stmt &root) : root_(root) {}
27
28 private:
29 Stmt makeParallelScopes(const Stmt &body);
30
31 Stmt doVisitFor(const For &op);
32 Stmt doVisitStmt(const Stmt &op);
33
34 protected:
35 Expr visit(const Var &op) override;
36 Stmt visit(const For &op) override;
37 Stmt visit(const VarDef &op) override;
38 Stmt visit(const Store &op) override;
39 Stmt visit(const ReduceTo &op) override;
40 Stmt visit(const Eval &op) override;
41};
42
43class ShrinkNormalizedThreads : public ShrinkFor {
44 typedef ShrinkFor BaseClass;
45
46 std::unordered_set<For> openLoopsInKernel_;
47 bool inKernel_ = false;
48
49 protected:
50 bool filterLoop(const For &op) override;
51
52 std::unordered_set<std::string>
53 filterNames(const std::unordered_set<std::string> &names) override;
54
55 protected:
56 using BaseClass::visit;
57 Stmt visit(const For &op) override;
58};
59
67Stmt normalizeThreads(const Stmt &op);
68
69DEFINE_PASS_FOR_FUNC(normalizeThreads)
70
71} // namespace gpu
72
73} // namespace freetensor
74
75#endif // FT_WITH_CUDA
76
77#endif // FREE_TENSOR_GPU_NORMALIZE_THREADS_H
#define DEFINE_PASS_FOR_FUNC(pass)
Definition: func.h:88
Definition: allocator.h:9
Ref< StmtNode > Stmt
Definition: ast.h:152
Ref< ExprNode > Expr
Definition: ast.h:184