|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | +import pytest |
| 18 | + |
| 19 | +import tvm |
| 20 | +from tvm.target import _ffi_api, codegen, Target |
| 21 | +from tvm.target.codegen import target_has_features, llvm_get_vector_width |
| 22 | + |
| 23 | +LLVM_VERSION = codegen.llvm_version_major() |
| 24 | + |
| 25 | +# fmt: off |
| 26 | +min_llvm_version, tvm_target, vec_width = tvm.testing.parameters( |
| 27 | + # generic, no-vec -> (default 256) |
| 28 | + (-1, "llvm -device=riscv_cpu -mtriple=riscv64-linux-gnu -mcpu=generic-rv64 -mattr=+i,+m", 256), |
| 29 | + (-1, "llvm -device=riscv_cpu -mtriple=riscv32-linux-gnu -mcpu=generic-rv32 -mattr=+64bit,+a,+c,+d,+f,+m", 256), |
| 30 | + # generic, with-vec -> (default 256) |
| 31 | + (-1, "llvm -device=riscv_cpu -mtriple=riscv32-linux-gnu -mcpu=generic-rv32 -mattr=+i,+m,+v", 256), |
| 32 | + (-1, "llvm -device=riscv_cpu -mtriple=riscv64-linux-gnu -mcpu=generic-rv64 -mattr=+64bit,+a,+c,+d,+f,+m,+v", 256), |
| 33 | + # explicit -vector-width |
| 34 | + (-1, "llvm -device=riscv_cpu -vector-width=128 -mtriple=riscv32-linux-gnu -mcpu=generic-rv32 -mattr=+i,+m,+v", 128), |
| 35 | + (-1, "llvm -device=riscv_cpu -vector-width=128 -mtriple=riscv64-linux-gnu -mcpu=generic-rv64 -mattr=+64bit,+a,+c,+d,+f,+m,+v", 128), |
| 36 | + (-1, "llvm -device=riscv_cpu -vector-width=512 -mtriple=riscv32-linux-gnu -mcpu=generic-rv32 -mattr=+i,+m,+v", 512), |
| 37 | + (-1, "llvm -device=riscv_cpu -vector-width=512 -mtriple=riscv64-linux-gnu -mcpu=generic-rv64 -mattr=+64bit,+a,+c,+d,+f,+m,+v", 512), |
| 38 | + # explicit +zvlXXXb |
| 39 | + (14, "llvm -device=riscv_cpu -mtriple=riscv32-linux-gnu -mcpu=generic-rv32 -mattr=+i,+m,+v,+zvl64b", 64), |
| 40 | + (14, "llvm -device=riscv_cpu -mtriple=riscv64-linux-gnu -mcpu=generic-rv64 -mattr=+64bit,+a,+c,+d,+f,+m,+v,+zvl64b", 64), |
| 41 | + # vendor CPU |
| 42 | + (17, "llvm -device=riscv_cpu -mtriple=riscv64-linux-gnu -mcpu=sifive-x280", 512), |
| 43 | + (18, "llvm -device=riscv_cpu -mtriple=riscv64-linux-gnu -mcpu=sifive-p670", 128), |
| 44 | + (19, "llvm -device=riscv_cpu -mtriple=riscv64-linux-gnu -mcpu=spacemit-x60", 256), |
| 45 | +) # fmt: on |
| 46 | + |
| 47 | + |
| 48 | +def test_riscv_rvv_features(min_llvm_version, tvm_target, vec_width): |
| 49 | + """Test RVV features support for different targets. |
| 50 | +
|
| 51 | + Parameters |
| 52 | + ---------- |
| 53 | + min_llvm_version : int |
| 54 | + Minimal LLVM version. |
| 55 | + tvm_target : str |
| 56 | + TVM target. |
| 57 | + vec_width : bool |
| 58 | + Expected vector width. |
| 59 | + """ |
| 60 | + |
| 61 | + # skip test on llvm_version |
| 62 | + if LLVM_VERSION < min_llvm_version: |
| 63 | + return |
| 64 | + |
| 65 | + with Target(tvm_target): |
| 66 | + assert llvm_get_vector_width() == vec_width |
0 commit comments