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

[Hexagon]Use requires_hexagon instead of requires_hexagon_toolchain if running on hexagon target #11294

Merged
merged 4 commits into from
May 17, 2022
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
4 changes: 4 additions & 0 deletions python/tvm/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ def _get_targets(target_str=None):
if target_kind == "cuda" and "cudnn" in tvm.target.Target(target).attrs.get("libs", []):
is_enabled = tvm.support.libinfo()["USE_CUDNN"].lower() in ["on", "true", "1"]
is_runnable = is_enabled and cudnn.exists()
elif target_kind == "hexagon":
is_enabled = tvm.support.libinfo()["USE_HEXAGON"].lower() in ["on", "true", "1"]
# If Hexagon has compile-time support, we can always fall back
is_runnable = is_enabled and "ANDROID_SERIAL_NUMBER" in os.environ
else:
is_enabled = tvm.runtime.enabled(target_kind)
is_runnable = is_enabled and tvm.device(target_kind).exist
Expand Down
12 changes: 3 additions & 9 deletions tests/python/contrib/test_hexagon/benchmark_hexagon.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@

import tvm.testing
from tvm import te
from tvm import relay
from tvm.relay.backend import Executor, Runtime
from tvm.contrib import utils, ndk
from tvm.contrib.hexagon.build import HexagonLauncher
import tvm.contrib.hexagon as hexagon

from .conftest import requires_hexagon_toolchain
from tvm.contrib.hexagon.build import HexagonLauncherRPC

RPC_SERVER_PORT = 7070

Expand All @@ -47,8 +41,8 @@
# server to bind to the same port until the wait time elapses.


@requires_hexagon_toolchain
def test_elemwise_add(android_serial_number, hexagon_launcher):
@tvm.testing.requires_hexagon
def test_elemwise_add(hexagon_launcher: HexagonLauncherRPC):
"""
Starting with an elementwise-add computation, try various schedules / optimizations to
see the impact they have on performance.
Expand Down
10 changes: 7 additions & 3 deletions tests/python/contrib/test_hexagon/test_2d_physical_buffers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import contextlib
import sys
import tempfile
import pathlib

import pytest
import numpy as np
Expand Down Expand Up @@ -272,6 +270,12 @@ def test_lower(self, schedule_args):

@requires_hexagon_toolchain
def test_build(self, schedule_args, target_host, input_layout, working_layout, output_layout):
"""Testing build success/failure

* On Hexagon targets, build must succeed for both 1-d and 2-d memory.
* On non-Hexagon targets, build must succeed 1-d memory.
* On non-Hexagon targets, build must fail and report an error for 2-d memory.
"""
# contextlib.nullcontext wasn't added until python3.7, and the
# CI currently runs on python3.6. Therefore, using ExitStack
# to manage an optional context instead.
Expand All @@ -292,7 +296,7 @@ def runtime_module(self, schedule_args, target_host):

return tvm.build(*schedule_args, target=target_host)

@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_execute(
self,
runtime_module,
Expand Down
16 changes: 7 additions & 9 deletions tests/python/contrib/test_hexagon/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
from tvm.relay.backend import Executor, Runtime
from tvm.contrib.hexagon.session import Session

from .conftest import requires_hexagon_toolchain


@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_add(hexagon_session: Session):
dtype = "int8"
A = tvm.te.placeholder((2,), dtype=dtype)
Expand All @@ -53,7 +51,7 @@ def test_add(hexagon_session: Session):
assert (C_data.numpy() == np.array([6, 7])).all()


@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_add_vtcm(hexagon_session: Session):
dtype = "int8"
A = tvm.te.placeholder((2,), dtype=dtype)
Expand Down Expand Up @@ -87,7 +85,7 @@ class TestMatMul:
N = tvm.testing.parameter(32)
K = tvm.testing.parameter(32)

@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_matmul(self, hexagon_session, M, N, K):
X = te.placeholder((M, K), dtype="float32")
Y = te.placeholder((K, N), dtype="float32")
Expand Down Expand Up @@ -122,7 +120,7 @@ def test_matmul(self, hexagon_session, M, N, K):
tvm.testing.assert_allclose(zt.numpy(), ztcpu.numpy(), rtol=1e-4)


@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_graph_executor(hexagon_session: Session):
dtype = "float32"
data = relay.var("data", relay.TensorType((1, 64, 64, 3), dtype))
Expand Down Expand Up @@ -178,7 +176,7 @@ def test_graph_executor(hexagon_session: Session):
tvm.testing.assert_allclose(hexagon_output, expected_output, rtol=1e-4, atol=1e-5)


@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_graph_executor_multiple_conv2d(hexagon_session: Session):
dtype = "float32"
input_shape = (1, 8, 8, 3)
Expand Down Expand Up @@ -255,7 +253,7 @@ def test_graph_executor_multiple_conv2d(hexagon_session: Session):
tvm.testing.assert_allclose(hexagon_output, expected_output, rtol=1e-4, atol=1e-5)


@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_aot_executor(hexagon_session: Session, aot_host_target, aot_target):
dtype = "float32"
input_shape = (1, 128, 128, 3)
Expand Down Expand Up @@ -314,7 +312,7 @@ def test_aot_executor(hexagon_session: Session, aot_host_target, aot_target):
tvm.testing.assert_allclose(hexagon_output, expected_output, rtol=1e-4, atol=1e-5)


@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_aot_executor_multiple_conv2d(hexagon_session: Session, aot_host_target, aot_target):
dtype = "float32"
input_shape = (1, 8, 8, 3)
Expand Down
6 changes: 2 additions & 4 deletions tests/python/contrib/test_hexagon/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
from tvm.relay.backend import Executor, Runtime
from tvm.contrib.hexagon.session import Session

from .conftest import requires_hexagon_toolchain


def get_mobilenet():
"""Download and import mobilenet model with ONNX"""
Expand All @@ -38,7 +36,7 @@ def get_mobilenet():
return onnx.load(model_path)


@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_mobilenet(hexagon_session: Session):
dtype = "float32"
onnx_model = get_mobilenet()
Expand Down Expand Up @@ -88,7 +86,7 @@ def test_mobilenet(hexagon_session: Session):
enable_usmp = tvm.testing.parameter(False, True)


@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_mobilenet_aot(hexagon_session: Session, aot_host_target, aot_target, enable_usmp):
if hexagon_session._launcher._serial_number == "simulator":
pytest.skip(msg="Skip on simulator due to long runtime.")
Expand Down
9 changes: 5 additions & 4 deletions tests/python/contrib/test_hexagon/test_run_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@
import os
import pytest
import numpy as np
from tvm.contrib.hexagon.build import HexagonLauncher
from .conftest import requires_hexagon_toolchain

import tvm
from tvm.contrib.hexagon.session import Session


# use pytest -sv to observe gtest output
# use --gtest_args to pass arguments to gtest
# for example to run all "foo" tests twice and observe gtest output run
# pytest -sv <this file> --gtests_args="--gtest_filter=*foo* --gtest_repeat=2"
@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
@pytest.mark.skipif(
os.environ.get("HEXAGON_GTEST") == None,
reason="Test requires environment variable HEXAGON_GTEST set with a path to a Hexagon gtest version normally located at /path/to/hexagon/sdk/utils/googletest/gtest",
)
def test_run_unit_tests(hexagon_session, gtest_args):
def test_run_unit_tests(hexagon_session: Session, gtest_args):
try:
func = hexagon_session._rpc.get_function("hexagon.run_unit_tests")
except:
Expand Down
13 changes: 3 additions & 10 deletions tests/python/contrib/test_hexagon/test_thread_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import tvm.testing
from tvm import te

from .conftest import requires_hexagon_toolchain
from tvm.script import tir as T


Expand Down Expand Up @@ -67,11 +66,8 @@ def benchmark_func(mod, name, args, hexagon_session):
return evaluator(a, b, c, n).mean


@requires_hexagon_toolchain
def test_speedup(hexagon_session, capsys):
if hexagon_session is None:
pytest.skip(msg="Skip hardware test, ANDROID_SERIAL_NUMBER is not set.")

@tvm.testing.requires_hexagon
def test_speedup(hexagon_session: Session, capsys):
target_hexagon = tvm.target.hexagon("v68", link_params=True)
func = tvm.build(
ElemwiseSumIRModule, target=tvm.target.Target(target_hexagon, host=target_hexagon)
Expand All @@ -85,11 +81,8 @@ def test_speedup(hexagon_session, capsys):
print("... speedup of {:.2f}".format(serial_mean / parallel_mean), end=" ")


@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_elemwise_sum_parallel(hexagon_session: Session):
if hexagon_session is None:
pytest.skip(msg="Skip hardware test, ANDROID_SERIAL_NUMBER is not set.")

target_hexagon = tvm.target.hexagon("v68", link_params=True)
func = tvm.build(
ElemwiseSumIRModule, target=tvm.target.Target(target_hexagon, host=target_hexagon)
Expand Down
6 changes: 3 additions & 3 deletions tests/python/contrib/test_hexagon/topi/test_batch_matmul.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
from tvm.contrib.hexagon.session import Session
import tvm.topi.testing
from tvm.topi.utils import get_const_tuple
from tvm.contrib.hexagon.session import Session

from ..conftest import requires_hexagon_toolchain

dtype = tvm.testing.parameter(
"float32",
Expand All @@ -46,7 +46,7 @@ class TestMatMulFloat:
)

# TODO(mehrdadh): add dynamic testing
@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_batch_matmul(self, hexagon_session: Session, x_batch, y_batch, M, N, K, dtype):
if dtype == "float16":
pytest.xfail("float16 is not supported.")
Expand Down Expand Up @@ -98,7 +98,7 @@ class TestMatMulInt8:
(5, 1, 16, 16, 32),
)

@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_batch_matmul_int8(self, hexagon_session: Session, x_batch, y_batch, M, N, K):
dtype = "int8"
out_dtype = "int8"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

import tvm.testing
from tvm import te

from ..conftest import requires_hexagon_toolchain
from tvm.contrib.hexagon.session import Session


def intrin_mem_copy(shape, dtype, dst_scope, src_scope):
Expand Down Expand Up @@ -98,7 +97,7 @@ def verify(hexagon_session: Session, s, x, y, z, size):
np.testing.assert_equal(zt.numpy(), ref)


@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_cache_read_write(hexagon_session: Session):
size = 128
outer_shape = (size,)
Expand Down Expand Up @@ -140,7 +139,7 @@ def layout_transform_2d(n):
return [n // 16, te.AXIS_SEPARATOR, n % 16]


@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_cache_read_write_2d(hexagon_session: Session):
size = 128
outer_shape = (size,)
Expand Down
4 changes: 1 addition & 3 deletions tests/python/contrib/test_hexagon/topi/test_conv2d_nchw.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
from tvm.topi.utils import get_const_tuple
from tvm.topi.nn.utils import get_pad_tuple

from ..conftest import requires_hexagon_toolchain


dtype = tvm.testing.parameter("float32")
random_seed = tvm.testing.parameter(0)
Expand Down Expand Up @@ -91,7 +89,7 @@ class BaseConv2DTests:
dilation = tvm.testing.parameter(1)
batch = tvm.testing.parameter(1)

@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_conv2d_nchw(
self,
hexagon_session: Session,
Expand Down
5 changes: 1 addition & 4 deletions tests/python/contrib/test_hexagon/topi/test_conv2d_nhwc.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
from tvm.contrib.hexagon.session import Session
import tvm.topi.testing
from tvm.topi.utils import get_const_tuple
from tvm.topi.nn.utils import get_pad_tuple

from ..conftest import requires_hexagon_toolchain

dtype = tvm.testing.parameter("float32")

Expand All @@ -46,7 +43,7 @@ def ref_data(dtype, batch, in_channel, in_size, num_filter, kernel, stride, padd


class BaseConv2DTests:
@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_conv2d_nhwc(
self,
hexagon_session: Session,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
from tvm import te
from tvm import topi
import tvm.topi.testing
from tvm.contrib.pickle_memoize import memoize
from tvm.topi.utils import get_const_tuple
from ..conftest import requires_hexagon_toolchain


# TODO Should add kernal to tvm.testing.fixture
Expand Down Expand Up @@ -68,7 +66,7 @@ def shift_shape(output_padding):


class BaseConv2DTransposeTests:
@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_conv2d(
self,
hexagon_session: Session,
Expand Down
4 changes: 1 addition & 3 deletions tests/python/contrib/test_hexagon/topi/test_dense.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import tvm.topi.testing
from tvm.topi.utils import get_const_tuple

from ..conftest import requires_hexagon_toolchain

random_seed = tvm.testing.parameter(0)

use_bias = tvm.testing.parameter(True, False)
Expand Down Expand Up @@ -68,7 +66,7 @@ def dense_ref_data(random_seed, batch_size, in_dim, out_dim, use_bias, in_dtype,
return (a_np, b_np, c_np, d_np)


@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_dense(
hexagon_session: Session,
batch_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from tvm import te, topi
from tvm.topi.utils import get_const_tuple
from tvm.topi.nn.utils import get_pad_tuple
from ..conftest import requires_hexagon_toolchain


random_seed = tvm.testing.parameter(0)
Expand Down Expand Up @@ -155,7 +154,7 @@ class BaseDepthwiseConv2D:
(e.g. implemented only for llvm).
"""

@requires_hexagon_toolchain
@tvm.testing.requires_hexagon
def test_conv2d(
self,
hexagon_session: Session,
Expand Down
Loading