Files
apache--tvm/python/tvm/parser/__init__.py
T
Mark Shields 163322cc92 [Relay] Prepare for new plan_devices.cc (part II) (#9130)
* Prepare for new plan_devices.cc (part II)

These changes came from changing https://github.com/apache/tvm/pull/9038 to use
tvm.parser.fromtext instead of manual AST construction.

- Demote FunctionOnDeviceAttrs to just a pair of DictAttrs entries so
  that the parser will understand them on Function definitions.
- Connect some special operators to their attributes so parsing understands them
  at call sites.
- Don't silently ignore attributes during parsing.
- Implement OptFunctionOnDevice so won't add device annotations for kUnknownDeviceType.
- Allow the parser to be given an initial metadata map to support examples which
  need constants.
- More DLOG -> VLOG conversions to reduce debug clutter.

* [checkpoint] Keep existing ParseModule ffi to simplify rust bindings

* [checkpoint] Address Christopher's comments.

* [checkpoint] Andrew's comments from #9038

* [checkpoint] Jared's comments from #9038

* [checkpoint] Woops, forgot rename.
2021-09-28 10:27:23 -07:00

46 lines
1.6 KiB
Python

# 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.
# pylint: disable=invalid-name
"""The under development unified IR parsing infrastructure."""
from .. import _ffi, Object
from . import _ffi_api
@_ffi.register_object("SourceMap")
class SourceMap(Object):
def add(self, name, content):
return _ffi.get_global_func("SourceMapAdd")(self, name, content)
def parse(source, source_name="from_string", init_module=None, init_meta_table=None):
if init_meta_table is None:
init_meta_table = {}
return _ffi_api.ParseModuleInContext(source_name, source, init_module, init_meta_table)
def parse_expr(source):
return _ffi_api.ParseExpr("string", source)
def fromtext(source, source_name="from_string"):
return parse(source, source_name)
def SpanCheck():
"""A debugging utility for reporting missing span information."""
return _ffi_api.SpanCheck()