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

add docstring skip in hybrid script #1668

Merged
merged 2 commits into from
Aug 27, 2018
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
4 changes: 2 additions & 2 deletions python/tvm/hybrid/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ast
import operator
import sys
from .util import make_nop, halide_imm_types
from .util import make_nop, halide_imm_types, is_docstring
from .intrin import LOOP_INTRIN, MATH_INTRIN
from .var_decl import determine_variable_usage
from ..api import thread_axis
Expand All @@ -15,7 +15,7 @@

def list_to_block(visit, lst):
"""Convert a list of Python IR nodes to HalideIR Block"""
lst = list(map(visit, lst))
lst = [visit(stmt) for stmt in lst if not is_docstring(stmt)]
lst = [stmt for stmt in lst if not _ir_pass.Equal(stmt, make_nop())]
if not lst:
return make_nop()
Expand Down
6 changes: 6 additions & 0 deletions python/tvm/hybrid/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Internal utilities for parsing Python subset to HalideIR"""

import ast
import inspect
import numpy
from .intrin import HYBRID_GLOBALS
Expand All @@ -22,6 +23,11 @@ def make_nop():
return _make.Evaluate(_api.const(0, dtype='int32'))


def is_docstring(node):
"""Checks if a Python AST node is a docstring"""
return isinstance(node, ast.Expr) and isinstance(node.value, ast.Str)


def _pruned_source(func):
"""Prune source code's extra leading spaces"""
lines = inspect.getsource(func).split('\n')
Expand Down
1 change: 1 addition & 0 deletions tests/python/unittest/test_hybrid_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def tvm_val_2_py_val(val):

@script
def outer_product(n, m, a, b, c):
"""This is a simple outer product"""
for i in range(n):
for j in range(m):
c[i, j] = a[i] * b[j]
Expand Down