comaniac commented on a change in pull request #6302: URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r473169129
########## File path: python/tvm/driver/tvmc/compiler.py ########## @@ -0,0 +1,407 @@ +# 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. +""" +Provides support to compile networks both AOT and JIT. +""" +import argparse +import logging +import tarfile +from pathlib import Path + +import tvm +from tvm import autotvm +from tvm import relay +from tvm._ffi.runtime_ctypes import TVMContext +from tvm.contrib import cc +from tvm.contrib import util +from tvm.relay.op.contrib import get_pattern_table + +from . import common, frontends +from .main import register_parser + +# A dictionary of target aliases to simplify the command lines provided by end users +TARGET_ALIASES = { + "aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon" +} + +# A list of valid targets (including aliases) to be used in "--target" +VALID_TARGETS = ["aarch64", "llvm"] + +DEFAULT_TARGET = "llvm" +DUMP_FORMATS = ["relay", "ll", "asm"] + + +def parse_target(targets_str): + """ Parsing function for comma separated target syntax. """ + targets = targets_str.split(",") + for target in targets: + if target not in VALID_TARGETS: + raise argparse.ArgumentTypeError(f"unrecognized target: {target}") + return targets + + +@register_parser +def add_compile_parser(subparsers): + """ Include parser for 'compile' subcommand """ + + parser = subparsers.add_parser("compile", help="compile a model") + parser.set_defaults(func=drive_compile) + parser.add_argument( + "--cross-compiler", + default="", + help="the cross compiler to use to generate target libraries", Review comment: Better to add example in the help to illustrate what is the expected value. ########## File path: python/tvm/driver/tvmc/__init__.py ########## @@ -14,3 +14,8 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +""" +TVMC - TVM driver command-line interface +""" + +from .compiler import add_compile_parser Review comment: It looks weird to expose `add_compile_parser`. If your just want to trigger the decorator for registration, `import compile` should be sufficient? ########## File path: python/tvm/driver/tvmc/compiler.py ########## @@ -0,0 +1,407 @@ +# 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. +""" +Provides support to compile networks both AOT and JIT. +""" +import argparse +import logging +import tarfile +from pathlib import Path + +import tvm +from tvm import autotvm +from tvm import relay +from tvm._ffi.runtime_ctypes import TVMContext +from tvm.contrib import cc +from tvm.contrib import util +from tvm.relay.op.contrib import get_pattern_table + +from . import common, frontends +from .main import register_parser + +# A dictionary of target aliases to simplify the command lines provided by end users +TARGET_ALIASES = { + "aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon" +} + +# A list of valid targets (including aliases) to be used in "--target" +VALID_TARGETS = ["aarch64", "llvm"] + +DEFAULT_TARGET = "llvm" Review comment: IMO, we should not have a default target. We expect users to explicitly provide the target to make sure they know what they are doing. ########## File path: python/tvm/driver/tvmc/compiler.py ########## @@ -0,0 +1,407 @@ +# 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. +""" +Provides support to compile networks both AOT and JIT. +""" +import argparse +import logging +import tarfile +from pathlib import Path + +import tvm +from tvm import autotvm +from tvm import relay +from tvm._ffi.runtime_ctypes import TVMContext +from tvm.contrib import cc +from tvm.contrib import util +from tvm.relay.op.contrib import get_pattern_table + +from . import common, frontends +from .main import register_parser + +# A dictionary of target aliases to simplify the command lines provided by end users +TARGET_ALIASES = { + "aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon" +} + +# A list of valid targets (including aliases) to be used in "--target" +VALID_TARGETS = ["aarch64", "llvm"] + +DEFAULT_TARGET = "llvm" +DUMP_FORMATS = ["relay", "ll", "asm"] + + +def parse_target(targets_str): + """ Parsing function for comma separated target syntax. """ + targets = targets_str.split(",") + for target in targets: + if target not in VALID_TARGETS: + raise argparse.ArgumentTypeError(f"unrecognized target: {target}") + return targets + + +@register_parser +def add_compile_parser(subparsers): + """ Include parser for 'compile' subcommand """ + + parser = subparsers.add_parser("compile", help="compile a model") + parser.set_defaults(func=drive_compile) + parser.add_argument( + "--cross-compiler", + default="", + help="the cross compiler to use to generate target libraries", + ) + parser.add_argument( + "--dump-codegen", default="", choices=DUMP_FORMATS, help="dump generated code" + ) + parser.add_argument( + "--language", Review comment: The naming is confusing. Based on its use cases, it is the file format of the input model file. I won't say "keras", "onnx", or "pytorch" are languages. ########## File path: python/tvm/driver/tvmc/compiler.py ########## @@ -0,0 +1,407 @@ +# 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. +""" +Provides support to compile networks both AOT and JIT. +""" +import argparse +import logging +import tarfile +from pathlib import Path + +import tvm +from tvm import autotvm +from tvm import relay +from tvm._ffi.runtime_ctypes import TVMContext +from tvm.contrib import cc +from tvm.contrib import util +from tvm.relay.op.contrib import get_pattern_table + +from . import common, frontends +from .main import register_parser + +# A dictionary of target aliases to simplify the command lines provided by end users +TARGET_ALIASES = { + "aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon" +} + +# A list of valid targets (including aliases) to be used in "--target" +VALID_TARGETS = ["aarch64", "llvm"] + +DEFAULT_TARGET = "llvm" +DUMP_FORMATS = ["relay", "ll", "asm"] + + +def parse_target(targets_str): + """ Parsing function for comma separated target syntax. """ + targets = targets_str.split(",") + for target in targets: + if target not in VALID_TARGETS: + raise argparse.ArgumentTypeError(f"unrecognized target: {target}") + return targets + + +@register_parser +def add_compile_parser(subparsers): + """ Include parser for 'compile' subcommand """ + + parser = subparsers.add_parser("compile", help="compile a model") + parser.set_defaults(func=drive_compile) + parser.add_argument( + "--cross-compiler", + default="", + help="the cross compiler to use to generate target libraries", + ) + parser.add_argument( + "--dump-codegen", default="", choices=DUMP_FORMATS, help="dump generated code" + ) + parser.add_argument( + "--language", + choices=frontends.get_frontends(), + help="specify input language", + ) + parser.add_argument( + "--input-shape", + type=common.parse_input_shapes, + metavar="INPUT_SHAPE,[INPUT_SHAPE]...", + help="for pytorch, e.g. '(1,3,224,224)'", + ) + parser.add_argument( + "-o", + "--output", + default="a.tar", + help="output the compiled module to an archive", + ) + parser.add_argument( + "--sanitize-diagnostics", + action="store_true", + default=True, + dest="sanitize_diagnostics", + help="enable diagnostic sanitization", + ) + parser.add_argument( + "--no-sanitize-diagnostics", + action="store_false", + dest="sanitize_diagnostics", + help="disable diagnostic sanitization", + ) + parser.add_argument( + "--target", + type=parse_target, + action="append", + metavar="TARGET[,TARGET]...", + help=f"compilation target(s): {', '.join(VALID_TARGETS)}, default llvm", + ) + parser.add_argument("--tuner-file", default="", help="tuner file") + parser.add_argument( + "--alter-layout", Review comment: It could be just `--desire-layout` from users' perspective. ########## File path: python/tvm/driver/tvmc/compiler.py ########## @@ -0,0 +1,407 @@ +# 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. +""" +Provides support to compile networks both AOT and JIT. +""" +import argparse +import logging +import tarfile +from pathlib import Path + +import tvm +from tvm import autotvm +from tvm import relay +from tvm._ffi.runtime_ctypes import TVMContext +from tvm.contrib import cc +from tvm.contrib import util +from tvm.relay.op.contrib import get_pattern_table + +from . import common, frontends +from .main import register_parser + +# A dictionary of target aliases to simplify the command lines provided by end users +TARGET_ALIASES = { + "aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon" +} Review comment: We should reuse TVM target (`python/tvm/target/target.py`) instead of maintaining a duplicate list here. cc @junrushao1994 for comments as this is also related to the target tag. ########## File path: python/tvm/driver/tvmc/compiler.py ########## @@ -0,0 +1,407 @@ +# 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. +""" +Provides support to compile networks both AOT and JIT. +""" +import argparse +import logging +import tarfile +from pathlib import Path + +import tvm +from tvm import autotvm +from tvm import relay +from tvm._ffi.runtime_ctypes import TVMContext +from tvm.contrib import cc +from tvm.contrib import util +from tvm.relay.op.contrib import get_pattern_table + +from . import common, frontends +from .main import register_parser + +# A dictionary of target aliases to simplify the command lines provided by end users +TARGET_ALIASES = { + "aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon" +} + +# A list of valid targets (including aliases) to be used in "--target" +VALID_TARGETS = ["aarch64", "llvm"] + +DEFAULT_TARGET = "llvm" +DUMP_FORMATS = ["relay", "ll", "asm"] + + +def parse_target(targets_str): Review comment: Ditto. Should not maintain a duplicated function. ########## File path: python/tvm/driver/tvmc/compiler.py ########## @@ -0,0 +1,407 @@ +# 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. +""" +Provides support to compile networks both AOT and JIT. +""" +import argparse +import logging +import tarfile +from pathlib import Path + +import tvm +from tvm import autotvm +from tvm import relay +from tvm._ffi.runtime_ctypes import TVMContext +from tvm.contrib import cc +from tvm.contrib import util +from tvm.relay.op.contrib import get_pattern_table + +from . import common, frontends +from .main import register_parser + +# A dictionary of target aliases to simplify the command lines provided by end users +TARGET_ALIASES = { + "aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon" +} + +# A list of valid targets (including aliases) to be used in "--target" +VALID_TARGETS = ["aarch64", "llvm"] + +DEFAULT_TARGET = "llvm" +DUMP_FORMATS = ["relay", "ll", "asm"] + + +def parse_target(targets_str): + """ Parsing function for comma separated target syntax. """ + targets = targets_str.split(",") + for target in targets: + if target not in VALID_TARGETS: + raise argparse.ArgumentTypeError(f"unrecognized target: {target}") + return targets + + +@register_parser +def add_compile_parser(subparsers): + """ Include parser for 'compile' subcommand """ + + parser = subparsers.add_parser("compile", help="compile a model") + parser.set_defaults(func=drive_compile) + parser.add_argument( + "--cross-compiler", + default="", + help="the cross compiler to use to generate target libraries", + ) + parser.add_argument( + "--dump-codegen", default="", choices=DUMP_FORMATS, help="dump generated code" + ) + parser.add_argument( + "--language", + choices=frontends.get_frontends(), + help="specify input language", + ) + parser.add_argument( + "--input-shape", + type=common.parse_input_shapes, + metavar="INPUT_SHAPE,[INPUT_SHAPE]...", + help="for pytorch, e.g. '(1,3,224,224)'", + ) + parser.add_argument( + "-o", + "--output", + default="a.tar", + help="output the compiled module to an archive", + ) + parser.add_argument( + "--sanitize-diagnostics", + action="store_true", + default=True, Review comment: The default should be False if the action is `store_true`? ########## File path: python/tvm/driver/tvmc/compiler.py ########## @@ -0,0 +1,407 @@ +# 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. +""" +Provides support to compile networks both AOT and JIT. +""" +import argparse +import logging +import tarfile +from pathlib import Path + +import tvm +from tvm import autotvm +from tvm import relay +from tvm._ffi.runtime_ctypes import TVMContext +from tvm.contrib import cc +from tvm.contrib import util +from tvm.relay.op.contrib import get_pattern_table + +from . import common, frontends +from .main import register_parser + +# A dictionary of target aliases to simplify the command lines provided by end users +TARGET_ALIASES = { + "aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon" +} + +# A list of valid targets (including aliases) to be used in "--target" +VALID_TARGETS = ["aarch64", "llvm"] + +DEFAULT_TARGET = "llvm" +DUMP_FORMATS = ["relay", "ll", "asm"] + + +def parse_target(targets_str): + """ Parsing function for comma separated target syntax. """ + targets = targets_str.split(",") + for target in targets: + if target not in VALID_TARGETS: + raise argparse.ArgumentTypeError(f"unrecognized target: {target}") + return targets + + +@register_parser +def add_compile_parser(subparsers): + """ Include parser for 'compile' subcommand """ + + parser = subparsers.add_parser("compile", help="compile a model") + parser.set_defaults(func=drive_compile) + parser.add_argument( + "--cross-compiler", + default="", + help="the cross compiler to use to generate target libraries", + ) + parser.add_argument( + "--dump-codegen", default="", choices=DUMP_FORMATS, help="dump generated code" + ) + parser.add_argument( + "--language", + choices=frontends.get_frontends(), + help="specify input language", + ) + parser.add_argument( + "--input-shape", + type=common.parse_input_shapes, + metavar="INPUT_SHAPE,[INPUT_SHAPE]...", + help="for pytorch, e.g. '(1,3,224,224)'", Review comment: - Did you consider the case that input name is different? - Why it's "for pytorch"? How about other frontends? ########## File path: python/tvm/driver/tvmc/compiler.py ########## @@ -0,0 +1,407 @@ +# 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. +""" +Provides support to compile networks both AOT and JIT. +""" +import argparse +import logging +import tarfile +from pathlib import Path + +import tvm +from tvm import autotvm +from tvm import relay +from tvm._ffi.runtime_ctypes import TVMContext +from tvm.contrib import cc +from tvm.contrib import util +from tvm.relay.op.contrib import get_pattern_table + +from . import common, frontends +from .main import register_parser + +# A dictionary of target aliases to simplify the command lines provided by end users +TARGET_ALIASES = { + "aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon" +} + +# A list of valid targets (including aliases) to be used in "--target" +VALID_TARGETS = ["aarch64", "llvm"] + +DEFAULT_TARGET = "llvm" +DUMP_FORMATS = ["relay", "ll", "asm"] + + +def parse_target(targets_str): + """ Parsing function for comma separated target syntax. """ + targets = targets_str.split(",") + for target in targets: + if target not in VALID_TARGETS: + raise argparse.ArgumentTypeError(f"unrecognized target: {target}") + return targets + + +@register_parser +def add_compile_parser(subparsers): + """ Include parser for 'compile' subcommand """ + + parser = subparsers.add_parser("compile", help="compile a model") + parser.set_defaults(func=drive_compile) + parser.add_argument( + "--cross-compiler", + default="", + help="the cross compiler to use to generate target libraries", + ) + parser.add_argument( + "--dump-codegen", default="", choices=DUMP_FORMATS, help="dump generated code" + ) + parser.add_argument( + "--language", + choices=frontends.get_frontends(), + help="specify input language", + ) + parser.add_argument( + "--input-shape", + type=common.parse_input_shapes, + metavar="INPUT_SHAPE,[INPUT_SHAPE]...", + help="for pytorch, e.g. '(1,3,224,224)'", + ) + parser.add_argument( + "-o", + "--output", + default="a.tar", + help="output the compiled module to an archive", + ) + parser.add_argument( + "--sanitize-diagnostics", + action="store_true", + default=True, + dest="sanitize_diagnostics", + help="enable diagnostic sanitization", + ) + parser.add_argument( + "--no-sanitize-diagnostics", + action="store_false", + dest="sanitize_diagnostics", + help="disable diagnostic sanitization", + ) + parser.add_argument( + "--target", + type=parse_target, + action="append", + metavar="TARGET[,TARGET]...", + help=f"compilation target(s): {', '.join(VALID_TARGETS)}, default llvm", + ) + parser.add_argument("--tuner-file", default="", help="tuner file") Review comment: What's `tuner-file`? ########## File path: python/tvm/driver/tvmc/compiler.py ########## @@ -0,0 +1,407 @@ +# 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. +""" +Provides support to compile networks both AOT and JIT. +""" +import argparse +import logging +import tarfile +from pathlib import Path + +import tvm +from tvm import autotvm +from tvm import relay +from tvm._ffi.runtime_ctypes import TVMContext +from tvm.contrib import cc +from tvm.contrib import util +from tvm.relay.op.contrib import get_pattern_table + +from . import common, frontends +from .main import register_parser + +# A dictionary of target aliases to simplify the command lines provided by end users +TARGET_ALIASES = { + "aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon" +} + +# A list of valid targets (including aliases) to be used in "--target" +VALID_TARGETS = ["aarch64", "llvm"] + +DEFAULT_TARGET = "llvm" +DUMP_FORMATS = ["relay", "ll", "asm"] + + +def parse_target(targets_str): + """ Parsing function for comma separated target syntax. """ + targets = targets_str.split(",") + for target in targets: + if target not in VALID_TARGETS: + raise argparse.ArgumentTypeError(f"unrecognized target: {target}") + return targets + + +@register_parser +def add_compile_parser(subparsers): + """ Include parser for 'compile' subcommand """ + + parser = subparsers.add_parser("compile", help="compile a model") + parser.set_defaults(func=drive_compile) + parser.add_argument( + "--cross-compiler", + default="", + help="the cross compiler to use to generate target libraries", + ) + parser.add_argument( + "--dump-codegen", default="", choices=DUMP_FORMATS, help="dump generated code" Review comment: - `--dump-codegen` sounds like dumping a "codegen" instead of the generated code. Maybe `--dump-code` or something else. - It seems to me that the code format is not determined by users but the target. The list choices are also confusing. ########## File path: python/tvm/driver/tvmc/compiler.py ########## @@ -0,0 +1,407 @@ +# 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. +""" +Provides support to compile networks both AOT and JIT. +""" +import argparse +import logging +import tarfile +from pathlib import Path + +import tvm +from tvm import autotvm +from tvm import relay +from tvm._ffi.runtime_ctypes import TVMContext +from tvm.contrib import cc +from tvm.contrib import util +from tvm.relay.op.contrib import get_pattern_table + +from . import common, frontends +from .main import register_parser + +# A dictionary of target aliases to simplify the command lines provided by end users +TARGET_ALIASES = { + "aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon" +} + +# A list of valid targets (including aliases) to be used in "--target" +VALID_TARGETS = ["aarch64", "llvm"] Review comment: Ditto. It's improper to maintain those tables in CLI. ########## File path: python/tvm/driver/tvmc/compiler.py ########## @@ -0,0 +1,407 @@ +# 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. +""" +Provides support to compile networks both AOT and JIT. +""" +import argparse +import logging +import tarfile +from pathlib import Path + +import tvm +from tvm import autotvm +from tvm import relay +from tvm._ffi.runtime_ctypes import TVMContext +from tvm.contrib import cc +from tvm.contrib import util +from tvm.relay.op.contrib import get_pattern_table + +from . import common, frontends +from .main import register_parser + +# A dictionary of target aliases to simplify the command lines provided by end users +TARGET_ALIASES = { + "aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon" +} + +# A list of valid targets (including aliases) to be used in "--target" +VALID_TARGETS = ["aarch64", "llvm"] + +DEFAULT_TARGET = "llvm" +DUMP_FORMATS = ["relay", "ll", "asm"] + + +def parse_target(targets_str): + """ Parsing function for comma separated target syntax. """ + targets = targets_str.split(",") + for target in targets: + if target not in VALID_TARGETS: + raise argparse.ArgumentTypeError(f"unrecognized target: {target}") + return targets + + +@register_parser +def add_compile_parser(subparsers): + """ Include parser for 'compile' subcommand """ + + parser = subparsers.add_parser("compile", help="compile a model") + parser.set_defaults(func=drive_compile) + parser.add_argument( + "--cross-compiler", + default="", + help="the cross compiler to use to generate target libraries", + ) + parser.add_argument( + "--dump-codegen", default="", choices=DUMP_FORMATS, help="dump generated code" + ) + parser.add_argument( + "--language", + choices=frontends.get_frontends(), + help="specify input language", + ) + parser.add_argument( + "--input-shape", + type=common.parse_input_shapes, + metavar="INPUT_SHAPE,[INPUT_SHAPE]...", + help="for pytorch, e.g. '(1,3,224,224)'", + ) + parser.add_argument( + "-o", + "--output", + default="a.tar", + help="output the compiled module to an archive", + ) + parser.add_argument( + "--sanitize-diagnostics", + action="store_true", + default=True, + dest="sanitize_diagnostics", + help="enable diagnostic sanitization", + ) + parser.add_argument( + "--no-sanitize-diagnostics", + action="store_false", + dest="sanitize_diagnostics", + help="disable diagnostic sanitization", + ) + parser.add_argument( + "--target", Review comment: It seems to me that we only need one target at each time, especially we only have one output tar file. If users need to compile one model for multiple targets, they should call the CLI multiple times. ########## File path: python/tvm/driver/tvmc/compiler.py ########## @@ -0,0 +1,407 @@ +# 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. +""" +Provides support to compile networks both AOT and JIT. +""" +import argparse +import logging +import tarfile +from pathlib import Path + +import tvm +from tvm import autotvm +from tvm import relay +from tvm._ffi.runtime_ctypes import TVMContext +from tvm.contrib import cc +from tvm.contrib import util +from tvm.relay.op.contrib import get_pattern_table + +from . import common, frontends +from .main import register_parser + +# A dictionary of target aliases to simplify the command lines provided by end users +TARGET_ALIASES = { + "aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon" +} + +# A list of valid targets (including aliases) to be used in "--target" +VALID_TARGETS = ["aarch64", "llvm"] + +DEFAULT_TARGET = "llvm" +DUMP_FORMATS = ["relay", "ll", "asm"] + + +def parse_target(targets_str): + """ Parsing function for comma separated target syntax. """ + targets = targets_str.split(",") + for target in targets: + if target not in VALID_TARGETS: + raise argparse.ArgumentTypeError(f"unrecognized target: {target}") + return targets + + +@register_parser +def add_compile_parser(subparsers): + """ Include parser for 'compile' subcommand """ + + parser = subparsers.add_parser("compile", help="compile a model") + parser.set_defaults(func=drive_compile) + parser.add_argument( + "--cross-compiler", + default="", + help="the cross compiler to use to generate target libraries", + ) + parser.add_argument( + "--dump-codegen", default="", choices=DUMP_FORMATS, help="dump generated code" + ) + parser.add_argument( + "--language", + choices=frontends.get_frontends(), + help="specify input language", + ) + parser.add_argument( + "--input-shape", + type=common.parse_input_shapes, + metavar="INPUT_SHAPE,[INPUT_SHAPE]...", + help="for pytorch, e.g. '(1,3,224,224)'", + ) + parser.add_argument( + "-o", + "--output", + default="a.tar", + help="output the compiled module to an archive", + ) + parser.add_argument( + "--sanitize-diagnostics", + action="store_true", + default=True, + dest="sanitize_diagnostics", + help="enable diagnostic sanitization", + ) + parser.add_argument( + "--no-sanitize-diagnostics", + action="store_false", + dest="sanitize_diagnostics", + help="disable diagnostic sanitization", Review comment: Why we need two mutual exclusive arguments? ########## File path: python/tvm/driver/tvmc/compiler.py ########## @@ -0,0 +1,407 @@ +# 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. +""" +Provides support to compile networks both AOT and JIT. +""" +import argparse +import logging +import tarfile +from pathlib import Path + +import tvm +from tvm import autotvm +from tvm import relay +from tvm._ffi.runtime_ctypes import TVMContext +from tvm.contrib import cc +from tvm.contrib import util +from tvm.relay.op.contrib import get_pattern_table + +from . import common, frontends +from .main import register_parser + +# A dictionary of target aliases to simplify the command lines provided by end users +TARGET_ALIASES = { + "aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon" +} + +# A list of valid targets (including aliases) to be used in "--target" +VALID_TARGETS = ["aarch64", "llvm"] + +DEFAULT_TARGET = "llvm" +DUMP_FORMATS = ["relay", "ll", "asm"] + + +def parse_target(targets_str): + """ Parsing function for comma separated target syntax. """ + targets = targets_str.split(",") + for target in targets: + if target not in VALID_TARGETS: + raise argparse.ArgumentTypeError(f"unrecognized target: {target}") + return targets + + +@register_parser +def add_compile_parser(subparsers): + """ Include parser for 'compile' subcommand """ + + parser = subparsers.add_parser("compile", help="compile a model") + parser.set_defaults(func=drive_compile) + parser.add_argument( + "--cross-compiler", + default="", + help="the cross compiler to use to generate target libraries", + ) + parser.add_argument( + "--dump-codegen", default="", choices=DUMP_FORMATS, help="dump generated code" + ) + parser.add_argument( + "--language", + choices=frontends.get_frontends(), + help="specify input language", + ) + parser.add_argument( + "--input-shape", + type=common.parse_input_shapes, + metavar="INPUT_SHAPE,[INPUT_SHAPE]...", + help="for pytorch, e.g. '(1,3,224,224)'", + ) + parser.add_argument( + "-o", + "--output", + default="a.tar", Review comment: `a.tar` is not a good default even gcc uses `a.out` for decades. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
