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] use target_host when it is set #6855

Merged
merged 7 commits into from
Dec 1, 2020
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
6 changes: 3 additions & 3 deletions python/tvm/driver/tvmc/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,18 @@ def compile_model(
mod = common.convert_graph_layout(mod, alter_layout)

tvm_target = common.target_from_cli(target)
target_host = target_host or ""
target_host = tvm_target if not target_host else target_host

if tuning_records and os.path.exists(tuning_records):
logger.debug("tuning records file provided: %s", tuning_records)
with autotvm.apply_history_best(tuning_records):
with tvm.transform.PassContext(opt_level=3):
logger.debug("building relay graph with tuning records")
graph_module = relay.build(mod, tvm_target, params=params, target_host=tvm_target)
graph_module = relay.build(mod, tvm_target, params=params, target_host=target_host)
else:
with tvm.transform.PassContext(opt_level=3):
logger.debug("building relay graph (no tuning records provided)")
graph_module = relay.build(mod, tvm_target, params=params, target_host=tvm_target)
graph_module = relay.build(mod, tvm_target, params=params, target_host=target_host)

# Generate output dump files with sources
dump_code = dump_code or []
Expand Down
13 changes: 13 additions & 0 deletions tests/python/driver/tvmc/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,16 @@ def imagenet_cat(tmpdir_factory):
np.savez(cat_file_full_path, input=image_data)

return cat_file_full_path


@pytest.fixture(scope="session")
def tflite_mobilenet_v1_0_25_128(tmpdir_factory):
base_url = "https://storage.googleapis.com/download.tensorflow.org/models"
model_url = "mobilenet_v1_2018_02_22/mobilenet_v1_0.25_128.tgz"
model_file = download_and_untar(
"{}/{}".format(base_url, model_url),
"mobilenet_v1_0.25_128.tflite",
temp_dir=tmpdir_factory.mktemp("data"),
)

return model_file
18 changes: 18 additions & 0 deletions tests/python/driver/tvmc/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,21 @@ def test_cross_compile_aarch64_onnx_module(onnx_resnet50):
assert type(params) is dict
assert type(dumps) is dict
assert "asm" in dumps.keys()


@tvm.testing.requires_opencl
def test_compile_opencl(tflite_mobilenet_v1_0_25_128):
pytest.importorskip("tflite")

graph, lib, params, dumps = tvmc.compiler.compile_model(
tflite_mobilenet_v1_0_25_128,
target="opencl",
target_host="llvm",
alter_layout="NCHW",
)

# check for output types
assert type(graph) is str
assert type(lib) is tvm.runtime.module.Module
assert type(params) is dict
assert type(dumps) is dict
Comment on lines +166 to +170
Copy link
Contributor

@comaniac comaniac Nov 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those checks look not cover anything special? To me, as long as you can compile the model without errors, then you should have used the right target host.