def test_error_if_target_missing(): with pytest.raises( TVMCException, match= "Passed --target-opencl-max_num_threads but did not specify opencl target", ): target_from_cli( "llvm", {"opencl": { "max_num_threads": 404 }}, )
def test_target_two_tvm_targets(): tvm_target, extra_targets = target_from_cli( "opencl -device=mali, llvm -mtriple=aarch64-linux-gnu") assert "opencl" in str(tvm_target) assert "llvm" in str(tvm_target.host) # No extra targets assert 0 == len(extra_targets)
def test_target_recombobulation_codegen(): tvm_target, extras = target_from_cli( "cmsis-nn, c -mcpu=cortex-m55", {"cmsis-nn": { "mcpu": "cortex-m55" }}, ) assert "-mcpu=cortex-m55" in str(tvm_target) assert len(extras) == 1 assert extras[0]["name"] == "cmsis-nn" assert extras[0]["opts"] == {"mcpu": "cortex-m55"}
def test_target_recombobulation_many(): tvm_target, _ = target_from_cli( "opencl -device=mali, llvm -mtriple=aarch64-linux-gnu", { "llvm": { "mcpu": "cortex-m3" }, "opencl": { "max_num_threads": 404 } }, ) assert "-max_num_threads=404" in str(tvm_target) assert "-device=mali" in str(tvm_target) assert "-mtriple=aarch64-linux-gnu" in str(tvm_target.host) assert "-mcpu=cortex-m3" in str(tvm_target.host)
def test_target_from_cli__error_target_not_found(): with pytest.raises(TVMCException): _ = target_from_cli("invalidtarget")
def test_target_invalid_more_than_two_tvm_targets(): with pytest.raises(TVMCException): _ = target_from_cli("cuda, opencl, llvm")
def test_target_from_cli__error_duplicate(): with pytest.raises(TVMCException): _ = target_from_cli("llvm, llvm")
def test_target_recombobulation_single(): tvm_target, _ = target_from_cli("llvm", {"llvm": {"mcpu": "cortex-m3"}}) assert str(tvm_target) == "llvm -keys=cpu -link-params=0 -mcpu=cortex-m3"
def test_target_from_cli__error_no_tvm_target(): with pytest.raises(TVMCException): _ = target_from_cli("ethos-n77")