FreeTensor
Loading...
Searching...
No Matches
native_code.h
Go to the documentation of this file.
1#ifndef FREE_TENSOR_NATIVE_CODE_H
2#define FREE_TENSOR_NATIVE_CODE_H
3
4#include <optional>
5#include <string>
6
7#include <driver/array.h>
8#include <driver/target.h>
9#include <func.h>
10#include <type/access_type.h>
11#include <type/data_type.h>
12#include <type/mem_type.h>
13
14namespace freetensor {
15
31 std::string name_;
32 std::optional<DataType> dtype_;
34 std::optional<MemType> mtype_;
37
38 bool isInClosure() const { return closure_.isValid(); }
39
40 NativeCodeParam(const std::string &name,
41 const std::optional<DataType> &dtype,
42 const AccessType &atype,
43 const std::optional<MemType> &mtype,
44 const Ref<Ref<Array>> &closure, bool updateClosure)
45 : name_(name), dtype_(dtype), atype_(atype), mtype_(mtype),
46 closure_(closure), updateClosure_(updateClosure) {}
47};
48
49std::ostream &operator<<(std::ostream &os, const NativeCodeParam &p);
50
57 std::string name_;
61
62 bool isInClosure() const { return closure_.isValid(); }
63
64 NativeCodeRet(const std::string &name, const DataType &dtype,
65 const Ref<Ref<Array>> &closure, bool returnClosure)
66 : name_(name), dtype_(dtype), closure_(closure),
67 returnClosure_(returnClosure) {}
68};
69
70std::ostream &operator<<(std::ostream &os, const NativeCodeRet &r);
71
72struct StaticInfo {
74};
75
80 std::string name_;
81 std::vector<NativeCodeParam> params_;
82 std::vector<NativeCodeRet>
83 returns_; // NOTE: multiple items in `returns_` may share the same name.
84 // In this case, one variable should be returned to multiple
85 // positions
86 std::string code_;
87 std::string entry_;
88 Ref<Target> target_;
89 StaticInfo staticInfo_;
90
91 public:
92 NativeCode() {} // Uninitialized
93 NativeCode(const std::string &name,
94 const std::vector<NativeCodeParam> &params,
95 const std::vector<NativeCodeRet> &returns,
96 const std::string &code, const std::string &entry,
97 const Ref<Target> &target,
99 : name_(name), params_(params), returns_(returns), code_(code),
100 entry_(entry), target_(target), staticInfo_(staticInfo) {}
101
102 static NativeCode fromFunc(const Func &func, const std::string &code,
103 const std::string &entry,
104 const Ref<Target> &target,
105 const StaticInfo &staticInfo = StaticInfo{});
106
107 const auto &name() const { return name_; }
108 const auto &params() const { return params_; }
109 const auto &returns() const { return returns_; }
110 const auto &code() const { return code_; }
111 const auto &entry() const { return entry_; }
112 const auto &target() const { return target_; }
113 const auto &staticInfo() const { return staticInfo_; }
114};
115
116} // namespace freetensor
117
118#endif // FREE_TENSOR_NATIVE_CODE_H
Definition: data_type.h:106
Definition: native_code.h:79
static NativeCode fromFunc(const Func &func, const std::string &code, const std::string &entry, const Ref< Target > &target, const StaticInfo &staticInfo=StaticInfo{})
Definition: native_code.cc:83
NativeCode()
Definition: native_code.h:92
const auto & entry() const
Definition: native_code.h:111
const auto & code() const
Definition: native_code.h:110
const auto & target() const
Definition: native_code.h:112
const auto & name() const
Definition: native_code.h:107
const auto & params() const
Definition: native_code.h:108
const auto & returns() const
Definition: native_code.h:109
const auto & staticInfo() const
Definition: native_code.h:113
NativeCode(const std::string &name, const std::vector< NativeCodeParam > &params, const std::vector< NativeCodeRet > &returns, const std::string &code, const std::string &entry, const Ref< Target > &target, const StaticInfo &staticInfo=StaticInfo{})
Definition: native_code.h:93
Definition: ref.h:24
Definition: allocator.h:9
AccessType
Definition: access_type.h:42
Ref< FuncNode > Func
Definition: func.h:64
std::ostream & operator<<(std::ostream &os, const Dependence &dep)
Definition: deps.cc:1404
Definition: native_code.h:30
std::string name_
Definition: native_code.h:31
std::optional< DataType > dtype_
Definition: native_code.h:32
AccessType atype_
Null if atype_ == Bypass.
Definition: native_code.h:33
bool isInClosure() const
Accept user input even if there is a closure.
Definition: native_code.h:38
NativeCodeParam(const std::string &name, const std::optional< DataType > &dtype, const AccessType &atype, const std::optional< MemType > &mtype, const Ref< Ref< Array > > &closure, bool updateClosure)
Definition: native_code.h:40
std::optional< MemType > mtype_
Definition: native_code.h:34
bool updateClosure_
Data bound to this parameter.
Definition: native_code.h:36
Ref< Ref< Array > > closure_
Null if atype_ == Bypass.
Definition: native_code.h:35
Definition: native_code.h:56
bool returnClosure_
Data bound to this return value.
Definition: native_code.h:60
Ref< Ref< Array > > closure_
Definition: native_code.h:59
bool isInClosure() const
Return even if there is a closure.
Definition: native_code.h:62
DataType dtype_
Definition: native_code.h:58
std::string name_
Definition: native_code.h:57
NativeCodeRet(const std::string &name, const DataType &dtype, const Ref< Ref< Array > > &closure, bool returnClosure)
Definition: native_code.h:64
Definition: native_code.h:72
uint64_t gpuGlobalStaticPoolSize_
Definition: native_code.h:73