Skip to content

Commit

Permalink
[TVMC] Only load extra targets when there are workspace pools (#12253)
Browse files Browse the repository at this point in the history
After #11427, `tvmc compile` wouldn't work for external codegens that
don't have a `Target` registered by `TVM_REGISTER_TARGET_KIND`. Such
external codegens can be expected to have no workspace pools and may not
always have a target associated as their implementation predates this
mechanism. While it is likely a `Target` is specified for all external
codegens in the future, we should still support external codegens
without an associated `Target` until this is enforced.

Co-authored-by: Chris Sidebottom <[email protected]>
  • Loading branch information
lhutton1 and Mousius authored Aug 2, 2022
1 parent a9df801 commit 759a648
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
20 changes: 10 additions & 10 deletions python/tvm/driver/tvmc/workspace_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,6 @@ def workspace_pools_recombobulate(parsed, targets, extra_target):
"workspace_pools_target_burst_bytes",
]

# Load extra targets from CLI
additional_targets = []

for t in extra_target:
additional_targets.append(Target(t["raw"], host=targets[0].host or targets[0]))

target = targets + additional_targets
if targets[0].host:
target.append(targets[0].host)

workspace_pools = _split_pools_to_pool_names(parsed.workspace_pools)
if not workspace_pools:
return None
Expand All @@ -186,6 +176,16 @@ def workspace_pools_recombobulate(parsed, targets, extra_target):
for workspace_pool_param in WORKSPACE_POOL_TARGET_PARAMS
}

# Load extra targets from CLI
additional_targets = []

for t in extra_target:
additional_targets.append(Target(t["raw"], host=targets[0].host or targets[0]))

target = targets + additional_targets
if targets[0].host:
target.append(targets[0].host)

return WorkspaceMemoryPools(
[
WorkspacePoolInfo(
Expand Down
16 changes: 16 additions & 0 deletions tests/python/driver/tvmc/test_workspace_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import pytest
import argparse

import tvm
from tvm.driver.tvmc.workspace_pools import (
generate_workspace_pools_args,
workspace_pools_recombobulate,
Expand Down Expand Up @@ -402,3 +403,18 @@ def test_workspace_pools_recombobulate_single_pool_overrides():

assert len(memory_pools.pools[0].targets) == 2
assert len(memory_pools.pools[1].targets) == 1


@tvm.testing.requires_ethosn
def test_workspace_pools_recombobulate_ext_codegen():
"""No error should occur when using an external code generator without an attached Target"""

parser = argparse.ArgumentParser()
generate_workspace_pools_args(parser)
parsed, _ = parser.parse_known_args([])

targets = [Target("llvm")]
extra_targets = [{"raw": "ethos-n"}]

memory_pools = workspace_pools_recombobulate(parsed, targets, extra_targets)
assert memory_pools is None

0 comments on commit 759a648

Please sign in to comment.