-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DRIVER] Add simulator, unify testcase to unittest (#25)
- Loading branch information
Showing
19 changed files
with
1,217 additions
and
541 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"""Testing utilities, this namespace is not imported by default.""" | ||
|
||
from . util import run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Utilities to start simulator.""" | ||
import os | ||
import ctypes | ||
import json | ||
import tvm | ||
|
||
def _load_lib(): | ||
"""Load local library, assuming they are simulator.""" | ||
# pylint: disable=unused-variable | ||
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) | ||
dll_path = [ | ||
os.path.abspath(os.path.join(curr_path, "../../../lib/libvta.so")), | ||
os.path.abspath(os.path.join(curr_path, "../../../lib/libvta_runtime.so")) | ||
] | ||
runtime_dll = [] | ||
if not all(os.path.exists(f) for f in dll_path): | ||
return [] | ||
try: | ||
for fname in dll_path: | ||
runtime_dll.append(ctypes.CDLL(fname, ctypes.RTLD_GLOBAL)) | ||
return runtime_dll | ||
except OSError: | ||
return [] | ||
|
||
|
||
def enabled(): | ||
"""Check if simulator is enabled.""" | ||
f = tvm.get_global_func("vta.simulator.profiler_clear", True) | ||
return f is not None | ||
|
||
|
||
def clear_stats(): | ||
"""Clear profiler statistics""" | ||
f = tvm.get_global_func("vta.simulator.profiler_clear", True) | ||
if f: | ||
f() | ||
|
||
|
||
def stats(): | ||
"""Clear profiler statistics | ||
Returns | ||
------- | ||
stats : dict | ||
Current profiler statistics | ||
""" | ||
x = tvm.get_global_func("vta.simulator.profiler_status")() | ||
return json.loads(x) | ||
|
||
|
||
LIBS = _load_lib() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Test Utilities""" | ||
from __future__ import absolute_import as _abs | ||
|
||
import os | ||
from tvm.contrib import rpc | ||
from ..environment import get_env | ||
from . import simulator | ||
|
||
|
||
def run(run_func): | ||
"""Run test function on all available env. | ||
Parameters | ||
---------- | ||
run_func : function(env, remote) | ||
""" | ||
env = get_env() | ||
# run on simulator | ||
if simulator.enabled(): | ||
env.TARGET = "sim" | ||
run_func(env, rpc.LocalSession()) | ||
|
||
# Run on PYNQ if env variable exists | ||
pynq_host = os.environ.get("VTA_PYNQ_RPC_HOST", None) | ||
if pynq_host: | ||
env.TARGET = "pynq" | ||
port = os.environ.get("VTA_PYNQ_RPC_PORT", "9091") | ||
port = int(port) | ||
remote = rpc.connect(pynq_host, port) | ||
run_func(env, remote) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.