19 #ifndef TVM_SCRIPT_IR_BUILDER_TIR_IR_H_ 20 #define TVM_SCRIPT_IR_BUILDER_TIR_IR_H_ 28 namespace ir_builder {
51 Optional<Array<PrimExpr>> strides, Optional<PrimExpr> elem_offset,
52 String storage_scope,
int align,
int offset_factor, String buffer_type,
67 Var
Arg(String name, Var
var);
75 Buffer
Arg(String name, Buffer buffer);
87 void FuncAttrs(Map<String, ObjectRef> attrs);
112 Optional<Var> data =
NullOpt, Array<PrimExpr> strides = {},
113 PrimExpr elem_offset = PrimExpr(), String storage_scope =
"global",
114 int align = -1,
int offset_factor = 0, String buffer_type =
"default",
123 BlockFrame
Block(String name,
bool no_realize =
false);
129 BlockInitFrame
Init();
135 void Where(PrimExpr predicate);
141 void Reads(Array<ObjectRef> buffer_slices);
147 void Writes(Array<ObjectRef> buffer_slices);
153 void BlockAttrs(Map<String, ObjectRef> attrs);
170 Optional<Var> data =
NullOpt, Array<PrimExpr> strides = {},
171 PrimExpr elem_offset = PrimExpr(), String storage_scope =
"",
int align = -1,
172 int offset_factor = 0, String buffer_type =
"default",
173 Array<IntImm> axis_separators = {});
382 int offset_factor,
String buffer_type,
437 String storage_scope =
"global",
438 bool is_size_var =
false) {
439 Type type_annotation{
nullptr};
440 if (dtype.
is_void() && storage_scope ==
"global") {
448 #define TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST(FuncName, DType) \ 449 inline PrimExpr FuncName(Optional<PrimExpr> expr = NullOpt, bool is_size_var = false) { \ 450 DataType dtype = DType; \ 451 return expr.defined() \ 452 ? tvm::cast(dtype, expr.value()) \ 453 : (is_size_var ? tvm::tir::SizeVar("", dtype) : tvm::tir::Var("", dtype)); \ 456 #define TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST_SIZES(DType, FDType) \ 457 TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST(DType##8, FDType(8)); \ 458 TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST(DType##16, FDType(16)); \ 459 TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST(DType##32, FDType(32)); \ 460 TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST(DType##64, FDType(64)); 466 #define TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST_LANES(FuncName, FDType, Size) \ 467 TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST(FuncName##x4, FDType(Size, 4)); \ 468 TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST(FuncName##x8, FDType(Size, 8)); \ 469 TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST(FuncName##x16, FDType(Size, 16)); \ 470 TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST(FuncName##x32, FDType(Size, 32)); \ 471 TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST(FuncName##x64, FDType(Size, 64)); 473 #define TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST_SIZES_LANES(DType, FDType) \ 474 TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST_LANES(DType##8, FDType, 8); \ 475 TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST_LANES(DType##16, FDType, 16); \ 476 TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST_LANES(DType##32, FDType, 32); \ 477 TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST_LANES(DType##64, FDType, 64); 485 #undef TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST 492 #endif // TVM_SCRIPT_IR_BUILDER_TIR_IR_H_ ForFrame Unroll(PrimExpr start, PrimExpr stop, Optional< Map< String, ObjectRef >> annotations=NullOpt)
The unrolled For statement.
Managed reference to IfFrameNode.
Definition: frame.h:650
ForFrame ThreadBinding(PrimExpr start, PrimExpr stop, String thread, Optional< Map< String, ObjectRef >> annotations=NullOpt)
The thread-binding For statement.
Buffer AllocBuffer(Array< PrimExpr > shape, DataType dtype=DataType::Float(32), Optional< Var > data=NullOpt, Array< PrimExpr > strides={}, PrimExpr elem_offset=PrimExpr(), String storage_scope="", int align=-1, int offset_factor=0, String buffer_type="default", Array< IntImm > axis_separators={})
The buffer allocation function.
RealizeFrame Realize(tvm::tir::BufferRegion buffer_slice, String storage_scope, PrimExpr condition)
The realization.
#define TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST(FuncName, DType)
Definition: ir.h:448
void BlockAttrs(Map< String, ObjectRef > attrs)
The block annotation statement.
Var Opaque(Range dom, PrimExpr binding, DataType dtype=DataType::Int(32))
The opaque block axis defining function.
Managed reference to LaunchThreadFrameNode.
Definition: frame.h:388
Managed reference to AllocateConstFrameNode.
Definition: frame.h:530
static DataType Void()
Construct a Void type.
Definition: data_type.h:203
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Managed reference to RealizeFrameNode.
Definition: frame.h:431
Array< Var > Remap(String kinds, Array< PrimExpr > bindings, DataType dtype=DataType::Int(32))
The block axis remapping function.
Managed reference to WhileFrameNode.
Definition: frame.h:608
AssertFrame Assert(PrimExpr condition, String message)
The assertion statement.
a named variable in TIR
Definition: var.h:88
Var Arg(String name, Var var)
The PrimFunc variable arguments adding function.
PrimFuncFrame PrimFunc()
The primitive function statement.
#define TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST_SIZES(DType, FDType)
Definition: ir.h:456
void Prefetch(Buffer buffer, Array< Range > bounds)
The prefetch hint for a buffer.
void Writes(Array< ObjectRef > buffer_slices)
The block buffer region writing statement.
Managed reference to BufferRegionNode.
Definition: stmt.h:1099
AllocateConstFrame AllocateConst(NDArray data, DataType dtype, Array< PrimExpr > extents, Optional< Map< String, ObjectRef >> annotations=NullOpt)
The allocate constant node.
Common operators defined for Expr.
Managed NDArray. The array is backed by reference counted blocks.
Definition: ndarray.h:51
void FuncAttrs(Map< String, ObjectRef > attrs)
The PrimFunc annotation statement.
PrimExpr Void(Optional< PrimExpr > expr=NullOpt, bool is_size_var=false)
Definition: ir.h:483
PrimExpr Boolean(Optional< PrimExpr > expr=NullOpt, bool is_size_var=false)
Definition: ir.h:482
Managed reference to LetFrameNode.
Definition: frame.h:347
Range constainer.
Definition: expr.h:715
Var Spatial(Range dom, PrimExpr binding, DataType dtype=DataType::Int(32))
The spatial block axis defining function.
AllocateFrame Allocate(Array< PrimExpr > extents, DataType dtype, String storage_scope="", Optional< PrimExpr > condition=NullOpt, Optional< Map< String, ObjectRef >> annotations=NullOpt)
The allocate node.
AttrFrame Attr(ObjectRef node, String attr_key, PrimExpr value)
Create an attribute.
BlockFrame Block(String name, bool no_realize=false)
The block declaration statement.
Runtime primitive data type.
Definition: data_type.h:41
ForFrame Serial(PrimExpr start, PrimExpr stop, Optional< Map< String, ObjectRef >> annotations=NullOpt)
The serial For statement.
Managed reference to ForFrameNode.
Definition: frame.h:268
#define TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST_SIZES_LANES(DType, FDType)
Definition: ir.h:473
static DataType Float(int bits, int lanes=1)
Construct an float type.
Definition: data_type.h:178
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
static DataType Handle(int bits=64, int lanes=1)
Construct a handle type.
Definition: data_type.h:198
Var EnvThread(String thread_tag)
Bind a var to thread env.
ThenFrame Then()
Create a then.
void Reads(Array< ObjectRef > buffer_slices)
The block buffer region reading statement.
Type FuncRet(Type ret_type)
The PrimFunc return type statement.
void BufferStore(Buffer buffer, PrimExpr value, Array< PrimExpr > indices)
Store data in a buffer.
WhileFrame While(PrimExpr condition)
Create a while loop.
void Where(PrimExpr predicate)
The block predicate statement.
Reference to string objects.
Definition: string.h:98
Tensor shape(const Tensor &src, DataType dtype, const std::string name="T_shape", const std::string tag=kInjective)
Get the shape of input tensor.
Definition: transform.h:1768
ForFrame Parallel(PrimExpr start, PrimExpr stop, Optional< Map< String, ObjectRef >> annotations=NullOpt)
The parallel For statement.
tvm::Type Type
Definition: type.h:47
Var var(std::string name_hint, DataType t=DataType::Int(32))
Construct a new Var expression.
Buffer BufferDecl(Array< PrimExpr > shape, DataType dtype, String buffer_name, Optional< Var > data, Optional< Array< PrimExpr >> strides, Optional< PrimExpr > elem_offset, String storage_scope, int align, int offset_factor, String buffer_type, Optional< Array< IntImm >> axis_separators)
The buffer declaration function.
LetFrame LetStmt(PrimExpr value, Optional< Type > type_annotation=NullOpt, Optional< Var > var=NullOpt)
The let binding.
Base class of all object reference.
Definition: object.h:511
a named variable represents a tensor index size
Definition: var.h:144
bool is_void() const
Definition: data_type.h:109
Var Handle(runtime::DataType dtype=runtime::DataType::Void(), String storage_scope="global", bool is_size_var=false)
Create a TIR var that represents a pointer.
Definition: ir.h:436
Managed reference to AssertFrameNode.
Definition: frame.h:308
LaunchThreadFrame LaunchThread(Var var, PrimExpr extent)
Launch a thread.
constexpr const char * axis_separators
Marks the physical axis separators.
Definition: stmt.h:1391
Buffer is a symbolic n-darray structure. It is a composition of primitive symbolic types...
Definition: buffer.h:160
Buffer MatchBuffer(ObjectRef param, Array< PrimExpr > shape, DataType dtype=DataType::Float(32), Optional< Var > data=NullOpt, Array< PrimExpr > strides={}, PrimExpr elem_offset=PrimExpr(), String storage_scope="global", int align=-1, int offset_factor=0, String buffer_type="default", Array< IntImm > axis_separators={})
The buffer match statement.
Managed reference to ThenFrameNode.
Definition: frame.h:683
static DataType Bool(int lanes=1)
Construct a bool type.
Definition: data_type.h:191
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics, which means map is mutable but copy will happen when array is referenced in more than two places.
Definition: map.h:1271
DeclBufferFrame DeclBuffer(Array< PrimExpr > shape, DataType dtype, String buffer_name, Optional< Var > data, Optional< Array< PrimExpr >> strides, Optional< PrimExpr > elem_offset, String storage_scope, int align, int offset_factor, String buffer_type, Optional< Array< IntImm >> axis_separators)
The buffer declaration frame.
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Managed reference to TypeNode.
Definition: type.h:93
void Evaluate(PrimExpr value)
Evaluate the input expression.
Reference to PrimExprNode.
Definition: expr.h:114
constexpr runtime::NullOptType NullOpt
Definition: optional.h:160
Managed reference to AttrFrameNode.
Definition: frame.h:572
Managed reference to ElseFrameNode.
Definition: frame.h:716
BlockInitFrame Init()
The block initialization statement.
void FuncName(String name)
The PrimFunc naming statement.
Var Scan(Range dom, PrimExpr binding, DataType dtype=DataType::Int(32))
The scanning block axis defining function.
Managed reference to AllocateFrameNode.
Definition: frame.h:482
ElseFrame Else()
Create an else.
ForFrame Vectorized(PrimExpr start, PrimExpr stop, Optional< Map< String, ObjectRef >> annotations=NullOpt)
The vectorized For statement.
Var Reduce(Range dom, PrimExpr binding, DataType dtype=DataType::Int(32))
The reduced block axis defining function.
runtime::DataType DataType
Definition: data_type.h:398
static DataType UInt(int bits, int lanes=1)
Construct an uint type.
Definition: data_type.h:171
ForFrame Grid(Array< PrimExpr > extents)
The grid For statement.
IfFrame If(PrimExpr condition)
Create an if statement.
static DataType Int(int bits, int lanes=1)
Construct an int type.
Definition: data_type.h:164