FreeTensor
Loading...
Searching...
No Matches
buffer.h
Go to the documentation of this file.
1#ifndef FREE_TENSOR_BUFFER_H
2#define FREE_TENSOR_BUFFER_H
3
4#include <sub_tree.h>
5#include <tensor.h>
6#include <type/access_type.h>
7#include <type/mem_type.h>
8
9namespace freetensor {
10
11class Buffer : public ASTPart {
12 template <class T> friend Ref<Buffer> makeBuffer(T &&, AccessType, MemType);
13
14 SubTree<Tensor> tensor_ = ChildOf{this};
15 AccessType atype_;
16 MemType mtype_;
17
18 public:
19 const auto &tensor() const { return tensor_; }
20 auto &tensor() { return tensor_; }
21
22 void setAtype(AccessType atype) { atype_ = atype; }
23 AccessType atype() const { return atype_; }
24
25 void setMtype(MemType mtype) { mtype_ = mtype; }
26 MemType mtype() const { return mtype_; }
27
28 void compHash() override;
29};
30
31template <class T>
32Ref<Buffer> makeBuffer(T &&tensor, AccessType atype, MemType mtype) {
33 auto b = Ref<Buffer>::make();
34 b->tensor_ = std::forward<T>(tensor);
35 b->atype_ = atype;
36 b->mtype_ = mtype;
37 return b;
38}
39
41 return makeBuffer(b->tensor(), b->atype(), b->mtype());
42}
43
44} // namespace freetensor
45
46#endif // FREE_TENSOR_BUFFER_H
Definition: sub_tree.h:50
Definition: buffer.h:11
auto & tensor()
Definition: buffer.h:20
void compHash() override
Definition: buffer.cc:6
MemType mtype() const
Definition: buffer.h:26
void setMtype(MemType mtype)
Definition: buffer.h:25
friend Ref< Buffer > makeBuffer(T &&, AccessType, MemType)
Definition: buffer.h:32
const auto & tensor() const
Definition: buffer.h:19
AccessType atype() const
Definition: buffer.h:23
void setAtype(AccessType atype)
Definition: buffer.h:22
Definition: ref.h:24
static Ref make()
Definition: ref.h:105
Definition: sub_tree.h:134
Definition: allocator.h:9
Ref< Buffer > makeBuffer(T &&tensor, AccessType atype, MemType mtype)
Definition: buffer.h:32
Expr deepCopy(const Expr &op)
Definition: ast.cc:364
AccessType
Definition: access_type.h:42
MemType
Definition: mem_type.h:14
Definition: sub_tree.h:20