You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by co...@apache.org on 2021/03/12 18:04:18 UTC

[tvm] branch main updated: [TVMC] Allow options on --target to contain dots. (#7651)

This is an automated email from the ASF dual-hosted git repository.

comaniac pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new fe25b9e  [TVMC] Allow options on --target to contain dots. (#7651)
fe25b9e is described below

commit fe25b9e7c5f9c95d211f63ae544a9532eb50b398
Author: Leandro Nunes <le...@arm.com>
AuthorDate: Fri Mar 12 18:03:53 2021 +0000

    [TVMC] Allow options on --target to contain dots. (#7651)
    
    * Allow tvmc compile --target options to accept dots
     * Adds testing for dot separator in quoted and unquoted
       values
     * Add an "unquoting" conditional so that quoted and
       unquoted strings look the same when parsed
---
 python/tvm/driver/tvmc/common.py             |  7 ++++++-
 tests/python/driver/tvmc/test_tvmc_common.py | 21 +++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/python/tvm/driver/tvmc/common.py b/python/tvm/driver/tvmc/common.py
index 71bf42a..c5cb5f2 100644
--- a/python/tvm/driver/tvmc/common.py
+++ b/python/tvm/driver/tvmc/common.py
@@ -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\.]+[\"])*|,)"
     )
 
     return re.findall(target_pattern, target)
@@ -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}'")
 
diff --git a/tests/python/driver/tvmc/test_tvmc_common.py b/tests/python/driver/tvmc/test_tvmc_common.py
index b272cec..23ea4f4 100644
--- a/tests/python/driver/tvmc/test_tvmc_common.py
+++ b/tests/python/driver/tvmc/test_tvmc_common.py
@@ -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():
+    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"]