24 #ifndef TVM_TOPI_DETAIL_EXTERN_H_
25 #define TVM_TOPI_DETAIL_EXTERN_H_
44 using FExtern = std::function<PrimExpr(ffi::Array<Buffer>, ffi::Array<Buffer>)>;
63 inline ffi::Array<Tensor> make_extern(
const ffi::Array<ffi::Array<PrimExpr>>& out_shapes,
64 const std::vector<DataType>& out_types,
65 const ffi::Array<Tensor>& inputs, FExtern fextern,
66 std::string name, std::string tag,
67 ::tvm::ffi::Map<ffi::String, ffi::Any> attrs) {
68 ICHECK_EQ(out_shapes.size(), out_types.size())
69 <<
"make_extern: out_shapes and out_types must have equal size";
71 ffi::Array<Buffer> input_placeholders;
72 for (
auto t : inputs) {
75 ffi::Array<Buffer> output_placeholders;
76 for (
size_t i = 0; i < out_shapes.size(); ++i) {
80 auto body = fextern(input_placeholders, output_placeholders);
83 auto op =
ExternOp(name, tag, attrs, inputs, input_placeholders, output_placeholders, body_stmt);
85 ffi::Array<Tensor> outputs;
86 for (
size_t i = 0; i < output_placeholders.size(); ++i) {
87 outputs.push_back(op.output(i));
100 inline PrimExpr pack_buffer(
Buffer buf) {
101 ICHECK_GT(buf->shape.size(), 0) <<
"buf shape must have at least one element";
105 if (buf->strides.size() > 0) {
111 ffi::Array<PrimExpr> pack_args{
130 inline PrimExpr call_packed(ffi::Array<PrimExpr> args) {
static DataType Int(int bits, int lanes=1)
Construct an int type.
Definition: data_type.h:274
static DataType Handle(int bits=64, int lanes=1)
Construct a handle type.
Definition: data_type.h:392
Managed reference to ExternOpNode.
Definition: operation.h:287
Buffer is a symbolic n-darray structure. It is a composition of primitive symbolic types,...
Definition: buffer.h:156
Managed reference to CallNode.
Definition: expr.h:745
void Evaluate(PrimExpr value)
Evaluate the input expression.
Tensor expression language DSL.
Definition: extracted_task.h:33
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.
PrimExpr make_const(DataType t, ValueType value, Span span=Span())
Make a const value with certain data type.
Definition: op.h:994
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:1960
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
Operation node can generate one or multiple Tensors.