Skip to content

Commit

Permalink
[TVMC] add the support of the cross compiler options
Browse files Browse the repository at this point in the history
Add the possibility to provide the cross compiler options when using the
tvmc compile functionality.
With some cross compiler toolchains --sysroot option (at least) need to be
defined.

Signed-off-by: Vincent ABRIOU <[email protected]>
  • Loading branch information
vinceab committed Apr 26, 2021
1 parent 9514e9e commit 9e6dcf3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions python/tvm/driver/tvmc/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def add_compile_parser(subparsers):
default="",
help="the cross compiler to generate target libraries, e.g. 'aarch64-linux-gnu-gcc'",
)
parser.add_argument(
"--cross-compiler-options",
default="",
help="the cross compiler options to generate target libraries, e.g. '-mthumb -mfpu=neon-vfpv4'",
)
parser.add_argument(
"--desired-layout",
choices=["NCHW", "NHWC"],
Expand Down Expand Up @@ -133,7 +138,7 @@ def drive_compile(args):
if dumps:
save_dumps(args.output, dumps)

save_module(args.output, graph, lib, params, args.cross_compiler)
save_module(args.output, graph, lib, params, args.cross_compiler, args.cross_compiler_options)
return 0


Expand Down Expand Up @@ -253,7 +258,8 @@ def compile_model(
return graph_module.get_json(), graph_module.get_lib(), graph_module.get_params(), dumps


def save_module(module_path, graph, lib, params, cross=None):
def save_module(module_path, graph, lib, params, cross=None,
cross_options=None):
"""
Create a tarball containing the generated TVM graph,
exported library and parameters
Expand All @@ -271,7 +277,7 @@ def save_module(module_path, graph, lib, params, cross=None):
The parameters (weights) for the TVM module.
cross : str or callable object, optional
Function that performs the actual compilation
cross_options : sst of cross compilation options
"""
lib_name = "mod.so"
graph_name = "mod.json"
Expand All @@ -283,7 +289,7 @@ def save_module(module_path, graph, lib, params, cross=None):
lib.export_library(path_lib)
else:
logger.debug("exporting library to %s , using cross compiler %s", path_lib, cross)
lib.export_library(path_lib, cc.cross_compiler(cross))
lib.export_library(path_lib, cc.cross_compiler(cross, options=cross_options.split(' ')))

with open(temp.relpath(graph_name), "w") as graph_file:
logger.debug("writing graph to file to %s", graph_file.name)
Expand Down

0 comments on commit 9e6dcf3

Please sign in to comment.