chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
#ifndef TVM_SCRIPT_IR_BUILDER_IR_FRAME_H_
|
||||
#define TVM_SCRIPT_IR_BUILDER_IR_FRAME_H_
|
||||
|
||||
#include <tvm/ffi/reflection/registry.h>
|
||||
#include <tvm/ir/expr.h>
|
||||
#include <tvm/ir/function.h>
|
||||
#include <tvm/ir/module.h>
|
||||
#include <tvm/script/ir_builder/base.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace tvm {
|
||||
namespace script {
|
||||
namespace ir_builder {
|
||||
namespace ir {
|
||||
|
||||
/*!
|
||||
* \brief A frame that represents the IRModule frame with functions and global variables.
|
||||
*
|
||||
* \sa IRModuleFrame
|
||||
*/
|
||||
class IRModuleFrameNode : public IRBuilderFrameNode {
|
||||
public:
|
||||
/*! \brief A map from string names to global variables that ensures global uniqueness. */
|
||||
ffi::Map<ffi::String, GlobalVar> global_var_map;
|
||||
/*!
|
||||
* \brief A map from GlobalVar to all global functions.
|
||||
* \note Only defined functions are in the map, while declared functions are not included.
|
||||
*/
|
||||
ffi::Map<GlobalVar, BaseFunc> functions;
|
||||
/*! \brief IRModule's attributes. */
|
||||
ffi::Map<ffi::String, Any> attrs;
|
||||
/*! \brief IRModule's global_infos */
|
||||
ffi::Map<ffi::String, ffi::Array<GlobalInfo>> global_infos;
|
||||
|
||||
static void RegisterReflection() {
|
||||
namespace refl = tvm::ffi::reflection;
|
||||
refl::ObjectDef<IRModuleFrameNode>()
|
||||
.def_ro("global_vars", &IRModuleFrameNode::global_var_map)
|
||||
.def_ro("functions", &IRModuleFrameNode::functions)
|
||||
.def_ro("attrs", &IRModuleFrameNode::attrs)
|
||||
.def_ro("global_infos", &IRModuleFrameNode::global_infos);
|
||||
}
|
||||
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.IRModuleFrame", IRModuleFrameNode,
|
||||
IRBuilderFrameNode);
|
||||
|
||||
public:
|
||||
void ExitWithScope() final;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Managed reference to IRModuleFrameNode.
|
||||
*
|
||||
* \sa IRModuleFrameNode
|
||||
*/
|
||||
class IRModuleFrame : public IRBuilderFrame {
|
||||
public:
|
||||
explicit IRModuleFrame(ffi::ObjectPtr<IRModuleFrameNode> data) : IRBuilderFrame(data) {
|
||||
TVM_FFI_ICHECK(data != nullptr);
|
||||
}
|
||||
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(IRModuleFrame, IRBuilderFrame, IRModuleFrameNode);
|
||||
};
|
||||
|
||||
} // namespace ir
|
||||
} // namespace ir_builder
|
||||
} // namespace script
|
||||
} // namespace tvm
|
||||
|
||||
#endif // TVM_SCRIPT_IR_BUILDER_IR_FRAME_H_
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
#ifndef TVM_SCRIPT_IR_BUILDER_IR_IR_H_
|
||||
#define TVM_SCRIPT_IR_BUILDER_IR_IR_H_
|
||||
|
||||
#include <tvm/ir/expr.h>
|
||||
#include <tvm/ir/function.h>
|
||||
#include <tvm/script/ir_builder/ir/frame.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace tvm {
|
||||
namespace script {
|
||||
namespace ir_builder {
|
||||
namespace ir {
|
||||
|
||||
/*!
|
||||
* \brief The IRModule declaration statement.
|
||||
* \return The IRModuleFrame.
|
||||
*/
|
||||
TVM_DLL IRModuleFrame IRModule();
|
||||
|
||||
/*!
|
||||
* \brief Declare a Function without given the specific function implementation.
|
||||
* \note It is usually used in cross-function call. And we can specify the function by `DefFunction`
|
||||
* \param func_name The function unique name.
|
||||
* \param func_signature A Function w/o body, which used to specify the function signature
|
||||
* (i.e. func params and func return type/shape).
|
||||
* \return The corresponding GlobalVar.
|
||||
*/
|
||||
TVM_DLL GlobalVar DeclFunction(const ffi::String& func_name, const BaseFunc& func_signature);
|
||||
|
||||
/*!
|
||||
* \brief Define the function which is declared before.
|
||||
* \param func_name The function unique name.
|
||||
* \param func The given function implementation
|
||||
*/
|
||||
TVM_DLL void DefFunction(const ffi::String& func_name, const BaseFunc& func);
|
||||
|
||||
} // namespace ir
|
||||
} // namespace ir_builder
|
||||
} // namespace script
|
||||
} // namespace tvm
|
||||
|
||||
#endif // TVM_SCRIPT_IR_BUILDER_IR_IR_H_
|
||||
Reference in New Issue
Block a user