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

[TVMC] Allow options on --target to contain dots. #7651

Merged
merged 1 commit into from
Mar 12, 2021
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
7 changes: 6 additions & 1 deletion python/tvm/driver/tvmc/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def tokenize_target(target):

target_pattern = (
r"(\-{0,2}[\w\-]+\=?"
r"(?:[\w\+\-]+(?:,[\w\+\-])*|[\'][\w\+\-,\s]+[\']|[\"][\w\+\-,\s]+[\"])*|,)"
r"(?:[\w\+\-\.]+(?:,[\w\+\-\.])*|[\'][\w\+\-,\s\.]+[\']|[\"][\w\+\-,\s\.]+[\"])*|,)"
leandron marked this conversation as resolved.
Show resolved Hide resolved
)

return re.findall(target_pattern, target)
Expand Down Expand Up @@ -223,6 +223,11 @@ def parse_target(target):
else:
opt = opt[1:] if opt.startswith("-") else opt
opt_name, opt_value = opt.split("=", maxsplit=1)

# remove quotes from the value: quotes are only parsed if they match,
# so it is safe to assume that if the string starts with quote, it ends
# with quote.
opt_value = opt_value[1:-1] if opt_value[0] in ('"', "'") else opt_value
except ValueError:
raise ValueError(f"Error when parsing '{opt}'")

Expand Down
21 changes: 21 additions & 0 deletions tests/python/driver/tvmc/test_tvmc_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,24 @@ def test_parse_multiple_target_with_opts():
assert "myopt" in targets[0]["opts"]
assert "value" == targets[0]["opts"]["myopt"]
assert "llvm" == targets[1]["name"]


def test_parse_multiple_separators_on_target():
leandron marked this conversation as resolved.
Show resolved Hide resolved
targets = tvmc.common.parse_target("foo -option1=+v1.0x,+value,+bar")

assert len(targets) == 1
assert "+v1.0x,+value,+bar" == targets[0]["opts"]["option1"]


def test_parse_single_quoted_multiple_separators_on_target():
targets = tvmc.common.parse_target("foo -option1='+v1.0x,+value'")

assert len(targets) == 1
assert "+v1.0x,+value" == targets[0]["opts"]["option1"]


def test_parse_double_quoted_multiple_separators_on_target():
targets = tvmc.common.parse_target('foo -option1="+v1.0x,+value"')

assert len(targets) == 1
assert "+v1.0x,+value" == targets[0]["opts"]["option1"]