24 #ifndef TVM_TOPI_DETAIL_EXTERN_H_
25 #define TVM_TOPI_DETAIL_EXTERN_H_
45 using FExtern = std::function<PrimExpr(ffi::Array<Buffer>, ffi::Array<Buffer>)>;
64 inline ffi::Array<Tensor> make_extern(
const ffi::Array<ffi::Array<PrimExpr>>& out_shapes,
65 const std::vector<PrimType>& out_types,
66 const ffi::Array<Tensor>& inputs, FExtern fextern,
67 std::string name, std::string tag,
68 ::tvm::ffi::Map<ffi::String, ffi::Any> attrs) {
69 TVM_FFI_ICHECK_EQ(out_shapes.size(), out_types.size())
70 <<
"make_extern: out_shapes and out_types must have equal size";
72 ffi::Array<Buffer> input_placeholders;
73 for (
auto t : inputs) {
76 ffi::Array<Buffer> output_placeholders;
77 for (
size_t i = 0; i < out_shapes.size(); ++i) {
81 auto body = fextern(input_placeholders, output_placeholders);
84 auto op =
ExternOp(name, tag, attrs, inputs, input_placeholders, output_placeholders, body_stmt);
86 ffi::Array<Tensor> outputs;
87 for (
size_t i = 0; i < output_placeholders.size(); ++i) {
88 outputs.push_back(op.output(i));
102 TVM_FFI_ICHECK_GT(buf->shape.size(), 0) <<
"buf shape must have at least one element";
106 if (buf->strides.size() > 0) {
110 strides = PrimExpr(0);
112 ffi::Array<Expr> pack_args{buf->data,
130 inline PrimExpr call_packed(ffi::Array<Expr> args) {
132 .as_or_throw<PrimExpr>();
static IntImm Int32(int64_t value, Span span=Span())
Construct a scalar int32 constant.
Definition: expr.h:402
static PointerType VoidPointerTy(ffi::String storage_scope="")
Construct an opaque pointer with void element type.
static PrimType Int(int bits, int lanes=1)
Construct a signed integer type with fixed lanes.
Managed reference to ExternOpNode.
Definition: operation.h:289
Buffer is a symbolic n-darray structure. It is a composition of primitive symbolic types,...
Definition: buffer.h:187
tvm::Expr Expr
Definition: type.h:41
void Evaluate(Expr value)
Evaluate the input expression.
Tensor expression language DSL.
Definition: extracted_task.h:32
const Op & tvm_stack_make_array()
Allocate a Tensor(DLTensor) on stack, return the handle.
const Op & tvm_call_packed()
See pesudo code.
const Op & tvm_stack_make_shape()
Allocate a shape tuple on stack, return the handle.
Buffer decl_buffer(ffi::Array< PrimExpr > shape, PrimType dtype=PrimType::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.
PrimExpr MakeConst(PrimType dtype, ValueType value, Span span=Span())
Make a const value with certain data type.
Definition: op.h:1012
Tensor shape(const Tensor &src, PrimType dtype, const std::string name="T_shape", const std::string tag=kInjective)
Get the shape of input tensor.
Definition: transform.h:2010
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:40
Operation node can generate one or multiple Tensors.