24 #ifndef TVM_TIRX_BUFFER_H_
25 #define TVM_TIRX_BUFFER_H_
27 #include <tvm/ffi/container/array.h>
28 #include <tvm/ffi/reflection/registry.h>
29 #include <tvm/ffi/string.h>
40 #ifndef TVM_INDEX_DEFAULT_I64
41 #define TVM_INDEX_DEFAULT_I64 1
45 #if TVM_INDEX_DEFAULT_I64
127 namespace refl = tvm::ffi::reflection;
128 refl::ObjectDef<BufferNode>()
134 refl::AttachFieldFlag::SEqHashDef())
159 ffi::Array<PrimExpr>
ElemOffset(ffi::Array<PrimExpr> index,
bool inner =
false)
const;
177 PrimExpr elem_offset, ffi::String name,
int data_alignment,
int offset_factor,
179 Span span =
Span(), ffi::Optional<Layout> layout = std::nullopt,
180 ffi::Array<PrimExpr> allocated_addr = {});
196 TVM_DLL
Buffer MakeSlice(ffi::Array<PrimExpr> begins, ffi::Array<PrimExpr> extents)
const;
207 ffi::Optional<PrimExpr> input_extent = std::nullopt)
const;
216 ffi::Optional<PrimExpr> predicate = std::nullopt)
const;
225 ffi::Optional<PrimExpr> predicate = std::nullopt)
const;
238 ffi::Array<PrimExpr>
OffsetOf(ffi::Array<PrimExpr> index)
const;
262 TVM_DLL
bool IsScalar(
bool alloc_or_decl =
true)
const;
290 ffi::String name =
"buffer", ffi::String storage_scope =
"",
351 std::string name,
int data_alignment,
352 int offset_factor,
bool compact,
353 std::string memory_scope =
"");
Managed reference class to IntImmNode.
Definition: expr.h:511
Base class for other IR constructs that can be converted to PrimExpr. This is useful for the FFI to c...
Definition: expr.h:156
Managed reference to PrimExprConvertibleNode.
Definition: expr.h:167
Reference to PrimExprNode.
Definition: expr.h:126
Definition: source_map.h:111
Runtime primitive data type.
Definition: data_type.h:45
static DataType Float(int bits, int lanes=1)
Construct an float type.
Definition: data_type.h:293
static DataType Int(int bits, int lanes=1)
Construct an int type.
Definition: data_type.h:276
static DataType Handle(int bits=64, int lanes=1)
Construct a handle type.
Definition: data_type.h:394
Node to represent a buffer.
Definition: buffer.h:63
BufferNode()
constructor
Definition: buffer.h:124
Var data
The pointer to the head of the data.
Definition: buffer.h:70
Span span
Span that points to the original source code. Reserved debug information.
Definition: buffer.h:112
ffi::Array< PrimExpr > shape
The type of the buffer prior to flattening.
Definition: buffer.h:79
static void RegisterReflection()
Definition: buffer.h:126
DataType dtype
data type in the content of the tensor
Definition: buffer.h:72
ffi::String name
optional name of the buffer
Definition: buffer.h:98
TVM_OBJECT_ENABLE_SCRIPT_PRINTER()
DataType DefaultIndexType() const
Definition: buffer.h:146
int offset_factor
Factor of elem_offset field, elem_offset is guaranteed to be multiple of offset_factor.
Definition: buffer.h:105
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: buffer.h:161
PrimExpr elem_offset
The offset in terms of number of dtype elements (including lanes)
Definition: buffer.h:95
ffi::Array< PrimExpr > allocated_addr
The allocated address of the buffer. The address might be multi-dimensional based on its scope....
Definition: buffer.h:121
ffi::Optional< Layout > layout
The layout of the buffer.
Definition: buffer.h:115
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.Buffer", BufferNode, ffi::Object)
ffi::Array< PrimExpr > ElemOffset(ffi::Array< PrimExpr > index, bool inner=false) const
Determine the offset in the buffer of the given index.
ffi::Array< IntImm > axis_separators
Separators between input axes when generating flattened output axes.
Definition: buffer.h:88
ffi::Array< PrimExpr > strides
The strides of each dimension This can be an empty array, indicating array is contiguous.
Definition: buffer.h:93
int data_alignment
Alignment requirement of data pointer in bytes.
Definition: buffer.h:100
BufferType buffer_type
buffer type
Definition: buffer.h:107
Buffer is a symbolic n-darray structure. It is a composition of primitive symbolic types,...
Definition: buffer.h:172
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Buffer, ffi::ObjectRef, BufferNode)
Buffer(Var data, DataType dtype, ffi::Array< PrimExpr > shape, ffi::Array< PrimExpr > strides, PrimExpr elem_offset, ffi::String name, int data_alignment, int offset_factor, BufferType buffer_type, ffi::Array< IntImm > axis_separators={}, Span span=Span(), ffi::Optional< Layout > layout=std::nullopt, ffi::Array< PrimExpr > allocated_addr={})
Buffer MakeSlice(ffi::Array< PrimExpr > begins, ffi::Array< PrimExpr > extents) const
Make a new symbolic buffer representing a slice of the buffer.
Buffer with_data(Var data) const
Return a new buffer with the data.
Buffer with_allocated_addr(ffi::Array< PrimExpr > allocated_addr) const
Return a new buffer with the allocated address.
Buffer with_dtype(DataType dtype) const
Return a new buffer with the dtype.
PrimExpr OffsetOf_p(const ffi::Array< PrimExpr > &indices) const
Get the buffer_offset op for the given index.
bool IsScalar(bool alloc_or_decl=true) const
Return true if the buffer is a scalar.
PrimExpr vload(ffi::Array< PrimExpr > begin, DataType dtype, ffi::Optional< PrimExpr > predicate=std::nullopt) const
Create an Expr that does a vector load at begin index.
PrimExpr access_ptr(int access_mask, DataType ptr_type=DataType::Handle(), int content_lanes=1, PrimExpr offset=IntImm(DataType::Int(32), 0), ffi::Optional< PrimExpr > input_extent=std::nullopt) const
Get access ptr to the entire buffer.
Buffer MakeStrideView() const
Return a new buffer that is equivalent with current one but always add stride field.
TVM_DEFINE_OBJECT_REF_COW_METHOD(BufferNode)
ffi::Array< PrimExpr > OffsetOf(ffi::Array< PrimExpr > index) const
Determine the offset in the buffer of the given index.
ffi::String scope() const
Return the storage scope associated with this buffer.
Buffer GetFlattenedBuffer() const
Get a flattened version of the buffer.
Stmt vstore(ffi::Array< PrimExpr > begin, PrimExpr value, ffi::Optional< PrimExpr > predicate=std::nullopt) const
Create a Stmt that does a vector store at begin index.
Base node for data producers.
Definition: buffer.h:306
virtual DataType GetDataType() const =0
Get the data type of the result.
virtual ffi::Array< PrimExpr > GetShape() const =0
Get the shape of the result.
virtual ~DataProducerNode()
destructor.
Definition: buffer.h:309
virtual ffi::String GetNameHint() const =0
Get the name hint of the data producer.
TVM_FFI_DECLARE_OBJECT_INFO("tirx.DataProducer", DataProducerNode, PrimExprConvertibleNode)
Managed reference to DataProducerNode.
Definition: buffer.h:332
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(DataProducer, PrimExprConvertible, DataProducerNode)
Container of all statements.
Definition: stmt.h:67
a named variable in TIR
Definition: var.h:77
Printer class to print repr string of each AST/IR nodes.
constexpr const char * axis_separators
Marks the physical axis separators.
Definition: stmt.h:233
tirx::Buffer BufferWithOffsetAlignment(ffi::Array< PrimExpr > shape, DataType dtype, std::string name, int data_alignment, int offset_factor, bool compact, std::string memory_scope="")
Creates TIR Buffer for provided parameters.
DataType DefaultIndexType()
if TVM_INDEX_DEFAULT_I64 is set, return int64, otherwise return int32
Definition: buffer.h:44
BufferType
buffer type
Definition: buffer.h:56
@ kDefault
Definition: buffer.h:57
@ kAutoBroadcast
Definition: buffer.h:59
Buffer decl_buffer(ffi::Array< PrimExpr > shape, DataType dtype=DataType::Float(32), ffi::String name="buffer", ffi::String storage_scope="", ffi::Optional< ffi::Array< IntImm >> axis_separators=std::nullopt, Span span=Span())
Construct a new buffer given shape, and dtype.
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:1981
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:37