Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TVMScript] Consolidate folder structure #13841

Merged
merged 2 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ tvm_file_glob(GLOB_RECURSE COMPILER_SRCS
src/tir/*.cc
src/topi/*.cc
src/driver/*.cc
src/parser/*.cc
src/support/*.cc
src/script/*.cc
)
Expand Down Expand Up @@ -317,6 +316,7 @@ tvm_file_glob(GLOB RELAY_BACKEND_SRCS
tvm_file_glob(GLOB_RECURSE RELAY_IR_SRCS
src/relay/ir/*.cc
src/relay/printer/*.cc
src/relay/parser/*.cc
)
tvm_file_glob(GLOB_RECURSE RELAY_QNN_SRCS
src/relay/qnn/*.cc
Expand Down
2 changes: 0 additions & 2 deletions include/tvm/ir/diagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@
#define TVM_IR_DIAGNOSTIC_H_

#include <tvm/ir/module.h>
#include <tvm/parser/source_map.h>

#include <sstream>
#include <string>

namespace tvm {

using tvm::parser::SourceMap;
using tvm::runtime::TypedPackedFunc;

/*! \brief The diagnostic level, controls the printing of the message. */
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/ir/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#ifndef TVM_IR_EXPR_H_
#define TVM_IR_EXPR_H_

#include <tvm/ir/span.h>
#include <tvm/ir/source_map.h>
#include <tvm/ir/type.h>
#include <tvm/node/node.h>
#include <tvm/runtime/container/string.h>
Expand Down
6 changes: 3 additions & 3 deletions include/tvm/ir/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include <tvm/ir/adt.h>
#include <tvm/ir/expr.h>
#include <tvm/ir/function.h>
#include <tvm/ir/source_map.h>
#include <tvm/ir/type.h>
#include <tvm/parser/source_map.h>
#include <tvm/runtime/container/array.h>
#include <tvm/runtime/container/map.h>
#include <tvm/runtime/container/string.h>
Expand Down Expand Up @@ -60,7 +60,7 @@ class IRModuleNode : public Object {
/*! \brief A map from global type vars to ADT type data. */
Map<GlobalTypeVar, TypeData> type_definitions;
/*! \brief The source map for the module. */
parser::SourceMap source_map;
SourceMap source_map;
/* \brief Additional attributes storing meta-data about the module. */
DictAttrs attrs;
/*!
Expand Down Expand Up @@ -357,7 +357,7 @@ class IRModule : public ObjectRef {
*/
TVM_DLL explicit IRModule(Map<GlobalVar, BaseFunc> functions,
Map<GlobalTypeVar, TypeData> type_definitions = {},
std::unordered_set<String> import_set = {}, parser::SourceMap map = {},
std::unordered_set<String> import_set = {}, SourceMap map = {},
DictAttrs attrs = {});

/*! \brief default constructor */
Expand Down
96 changes: 90 additions & 6 deletions include/tvm/ir/span.h → include/tvm/ir/source_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,25 @@
* specific language governing permissions and limitations
* under the License.
*/

/*!
* \file tvm/ir/span.h
* \brief Span information for debugging purposes.
* \file source_map.h
* \brief A map from source names to source code.
*/
#ifndef TVM_IR_SPAN_H_
#define TVM_IR_SPAN_H_
#ifndef TVM_IR_SOURCE_MAP_H_
#define TVM_IR_SOURCE_MAP_H_

#include <tvm/node/node.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>
#include <tvm/runtime/registry.h>

#include <fstream>
#include <string>
#include <utility>
#include <vector>

namespace tvm {

/*!
* \brief The source name in the Span
* \sa SourceNameNode, Span
Expand Down Expand Up @@ -122,5 +127,84 @@ class Span : public ObjectRef {
TVM_DEFINE_OBJECT_REF_METHODS(Span, ObjectRef, SpanNode);
};

/*! \brief A program source in any language.
*
* Could represent the source from an ML framework or a source
* representing a tvm::IRModule.
*/
class Source;

class SourceNode : public Object {
public:
/*! \brief The source name. */
SourceName source_name;

/*! \brief The raw source. */
String source;

/*! \brief A mapping of line breaks into the raw source. */
std::vector<std::pair<int, int>> line_map;

// override attr visitor
void VisitAttrs(AttrVisitor* v) {
v->Visit("source_name", &source_name);
v->Visit("source", &source);
}

static constexpr const char* _type_key = "Source";
TVM_DECLARE_FINAL_OBJECT_INFO(SourceNode, Object);
};

class Source : public ObjectRef {
public:
TVM_DLL Source(SourceName src_name, std::string source);
TVM_DLL tvm::String GetLine(int line);

TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(Source, ObjectRef, SourceNode);
};

/*!
* \brief A mapping from a unique source name to source fragment.
*/
class SourceMap;
/*!
* \brief Stores locations in frontend source that generated a node.
*/
class SourceMapNode : public Object {
public:
/*! \brief The source mapping. */
Map<SourceName, Source> source_map;

// override attr visitor
void VisitAttrs(AttrVisitor* v) { v->Visit("source_map", &source_map); }

bool SEqualReduce(const SourceMapNode* other, SEqualReducer equal) const {
return equal(source_map, other->source_map);
}

static constexpr const char* _type_key = "SourceMap";
TVM_DECLARE_FINAL_OBJECT_INFO(SourceMapNode, Object);
};

class SourceMap : public ObjectRef {
public:
explicit SourceMap(Map<SourceName, Source> source_map);

explicit SourceMap(std::initializer_list<std::pair<SourceName, Source>> source_map)
: SourceMap(Map<SourceName, Source>(source_map)) {}

SourceMap() : SourceMap(Map<SourceName, Source>()) {}

void Add(const Source& source);

SourceMapNode* operator->() {
ICHECK(get() != nullptr);
return static_cast<SourceMapNode*>(get_mutable());
}

TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(SourceMap, ObjectRef, SourceMapNode);
};

} // namespace tvm
#endif // TVM_IR_SPAN_H_

#endif // TVM_IR_SOURCE_MAP_H_
2 changes: 1 addition & 1 deletion include/tvm/ir/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#ifndef TVM_IR_TYPE_H_
#define TVM_IR_TYPE_H_

#include <tvm/ir/span.h>
#include <tvm/ir/source_map.h>
#include <tvm/node/node.h>
#include <tvm/runtime/container/array.h>
#include <tvm/runtime/data_type.h>
Expand Down
119 changes: 0 additions & 119 deletions include/tvm/parser/source_map.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/tvm/relay/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#ifndef TVM_RELAY_BASE_H_
#define TVM_RELAY_BASE_H_

#include <tvm/ir/span.h>
#include <tvm/ir/source_map.h>
#include <tvm/node/node.h>
#include <tvm/tir/expr.h>

Expand Down
3 changes: 1 addition & 2 deletions include/tvm/relay/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define TVM_RELAY_ERROR_H_

#include <tvm/ir/module.h>
#include <tvm/ir/span.h>

#include <sstream>
#include <string>
Expand All @@ -31,7 +30,7 @@ namespace tvm {
namespace relay {
/*!
* \brief A wrapper around std::stringstream to build error.
*
*include/tvm/ir/type.h
* Can be consumed by CompileError to construct an error.
*
* \code
Expand Down
16 changes: 6 additions & 10 deletions include/tvm/parser/parser.h → include/tvm/relay/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
#ifndef TVM_RELAY_PARSER_H_
#define TVM_RELAY_PARSER_H_

#ifndef TVM_PARSER_PARSER_H_
#define TVM_PARSER_PARSER_H_
/*!
* \file include/tvm/parser/parser.h
* \brief A parser for TVM IR.
*/
#include <tvm/ir/module.h>
#include <tvm/ir/transform.h>
#include <tvm/runtime/packed_func.h>
Expand All @@ -32,7 +28,7 @@
#include <string>

namespace tvm {
namespace parser {
namespace relay {

using MetaTable = Map<String, Array<ObjectRef>>;

Expand All @@ -45,9 +41,9 @@ IRModule ParseModule(const std::string& file_name, const std::string& file_conte
* for all Relay sub-expressions. This improves error and debugging diagnostics downstream for
* modules constructed programaticaly rather than textually.
*/
transform::Pass AnnotateSpans();
tvm::transform::Pass AnnotateSpans();

} // namespace parser
} // namespace relay
} // namespace tvm

#endif // TVM_PARSER_PARSER_H_
#endif // TVM_RELAY_PARSER_H_
5 changes: 4 additions & 1 deletion include/tvm/runtime/metadata_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
#ifndef TVM_RUNTIME_METADATA_BASE_H_
#define TVM_RUNTIME_METADATA_BASE_H_

#include <tvm/ir/expr.h>
#include <tvm/runtime/container/array.h>
#include <tvm/runtime/container/string.h>
#include <tvm/runtime/data_type.h>
#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/object.h>

#include <memory>
Expand Down
Loading