diff --git a/python/tvm/contrib/hexagon/_ci_env_check.py b/python/tvm/contrib/hexagon/_ci_env_check.py new file mode 100644 index 000000000000..c1c70750e86a --- /dev/null +++ b/python/tvm/contrib/hexagon/_ci_env_check.py @@ -0,0 +1,62 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Hexagon environment checks for CI usage + +These may be required by either tvm.testing or +tvm.contrib.hexagon.pytest_plugin, and are separated here to avoid a +circular dependency. +""" + +import os + +import tvm + +ANDROID_SERIAL_NUMBER = "ANDROID_SERIAL_NUMBER" +HEXAGON_TOOLCHAIN = "HEXAGON_TOOLCHAIN" + + +def _compile_time_check(): + """Return True if compile-time support for Hexagon is present, otherwise + error string. + + Designed for use as a the ``compile_time_check`` argument to + `tvm.testing.Feature`. + """ + if ( + tvm.testing.utils._cmake_flag_enabled("USE_LLVM") + and tvm.target.codegen.llvm_version_major() < 7 + ): + return "Hexagon requires LLVM 7 or later" + + if "HEXAGON_TOOLCHAIN" not in os.environ: + return f"Missing environment variable {HEXAGON_TOOLCHAIN}." + + return True + + +def _run_time_check(): + """Return True if run-time support for Hexagon is present, otherwise + error string. + + Designed for use as a the ``run_time_check`` argument to + `tvm.testing.Feature`. + """ + if ANDROID_SERIAL_NUMBER not in os.environ: + return f"Missing environment variable {ANDROID_SERIAL_NUMBER}." + + return True diff --git a/python/tvm/contrib/hexagon/pytest_plugin.py b/python/tvm/contrib/hexagon/pytest_plugin.py index 2c62a0a0b569..278bd833da95 100644 --- a/python/tvm/contrib/hexagon/pytest_plugin.py +++ b/python/tvm/contrib/hexagon/pytest_plugin.py @@ -53,15 +53,7 @@ def _compose(args, decs): return decs -def requires_hexagon_toolchain(*args): - _requires_hexagon_toolchain = [ - pytest.mark.skipif( - os.environ.get(HEXAGON_TOOLCHAIN) is None, - reason=f"Missing environment variable {HEXAGON_TOOLCHAIN}.", - ), - ] - - return _compose(args, _requires_hexagon_toolchain) +requires_hexagon_toolchain = tvm.testing.requires_hexagon(support_required="compile-only") @tvm.testing.fixture diff --git a/python/tvm/testing/utils.py b/python/tvm/testing/utils.py index 939786c9294f..bf3cc94f5ddf 100644 --- a/python/tvm/testing/utils.py +++ b/python/tvm/testing/utils.py @@ -88,6 +88,7 @@ def test_something(): import tvm._ffi from tvm.contrib import nvcc, cudnn +import tvm.contrib.hexagon._ci_env_check as hexagon from tvm.error import TVMError @@ -937,11 +938,8 @@ def _any_gpu_exists(): "Hexagon", cmake_flag="USE_HEXAGON", target_kind_enabled="hexagon", - compile_time_check=lambda: ( - (_cmake_flag_enabled("USE_LLVM") and tvm.target.codegen.llvm_version_major() >= 7) - or "Hexagon requires LLVM 7 or later" - ), - target_kind_hardware="hexagon", + compile_time_check=hexagon._compile_time_check, + run_time_check=hexagon._run_time_check, parent_features="llvm", )