Skip to content
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: 3 additions & 1 deletion include/tvm/runtime/data_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ class DataType {
/*! \return whether type is a bool vector type. */
bool is_vector_bool() const { return is_scalable_or_fixed_length_vector() && bits() == 1; }
/*! \return whether type is a Void type. */
bool is_void() const { return code() == DataType::kHandle && bits() == 0 && lanes() == 0; }
bool is_void() const {
return code() == DataType::kHandle && bits() == 0 && static_cast<int16_t>(data_.lanes) == 0;
}
/*!
* \brief Create a new data type by change lanes to a specified value.
* \param lanes The target number of lanes.
Expand Down
8 changes: 6 additions & 2 deletions src/target/llvm/codegen_llvm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2274,9 +2274,11 @@ void CodeGenLLVM::AddDebugInformation(llvm::Value* llvm_value, const Var& tir_va
#if TVM_LLVM_VERSION >= 50
if (!di_subprogram_) return;

auto dbg_dtype = GetDebugType(GetType(tir_var));
// no invalid dtypes
if (!dbg_dtype) return;
auto local_var = dbg_info_->di_builder_->createAutoVariable(
di_subprogram_, std::string(tir_var->name_hint), dbg_info_->file_, 0,
GetDebugType(GetType(tir_var)));
di_subprogram_, std::string(tir_var->name_hint), dbg_info_->file_, 0, dbg_dtype);

auto* di_loc = llvm::DILocation::get(*llvm_target_->GetContext(), 0, 0, di_subprogram_);

Expand Down Expand Up @@ -2330,6 +2332,8 @@ llvm::DIType* CodeGenLLVM::GetDebugType(const Type& ty_tir, llvm::Type* ty_llvm)
return nullptr;
}

if (dtype.is_scalable_vector()) return nullptr;

return dbg_info_->di_builder_->createBasicType(DLDataTypeToString(dtype).operator std::string(),
dtype.bits() * dtype.lanes(), dwarf_type);

Expand Down
27 changes: 27 additions & 0 deletions tests/python/codegen/test_target_codegen_riscv.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import pytest
import tvm
import tvm.testing
from tvm.script import tir as T
Expand Down Expand Up @@ -46,5 +47,31 @@ def load_vec(A: T.Buffer((N,), "int8")):
check_rvv_presence(16, 32)


@tvm.testing.requires_llvm_minimum_version(14)
@tvm.testing.parametrize_targets(
"llvm -device=riscv_cpu -mtriple=riscv32-linux-gnu -mcpu=generic-rv32 -mattr=+i,+m,+v",
"llvm -device=riscv_cpu -mtriple=riscv64-linux-gnu -mcpu=generic-rv64 -mattr=+64bit,+a,+c,+d,+f,+m,+v",
)
def test_rvv_vscale_llvm_dbginfo(target):
# fmt: off
@T.prim_func
def rvv_with_vscale(A_handle: T.handle, B_handle: T.handle, C_handle: T.handle):
A = T.match_buffer(A_handle, (8,), dtype="float32", align=4, offset_factor=1)
B = T.match_buffer(B_handle, (4, 8), dtype="float32", align=4, offset_factor=1, strides=[8, 1])
C = T.match_buffer(C_handle, (4,), dtype="float32", align=4, offset_factor=1)
with T.block("root"):
T.reads(A[0:8], B[0:4, 0:8])
zero = T.call_llvm_intrin("float32xvscalex2", "llvm.riscv.vfmv.v.f", T.Broadcast(T.float32(0.0), T.vscale() * 2), C[0], T.uint64(1))
vec_A = T.call_llvm_intrin("float32xvscalex4", "llvm.riscv.vle", T.Broadcast(T.float32(0.0), T.vscale() * 4), T.tvm_access_ptr(T.type_annotation("float32"), A.data, 0, 8, 1), T.int64(8))
vec_B = T.call_llvm_intrin("float32xvscalex4", "llvm.riscv.vle", T.Broadcast(T.float32(0.0), T.vscale() * 4), T.tvm_access_ptr(T.type_annotation("float32"), B.data, 0 * 8, 8, 1), T.int64(8))
prod = T.call_llvm_intrin("float32xvscalex4", "llvm.riscv.vfmul", T.Broadcast(T.float32(0.0), T.vscale() * 4), vec_A, vec_B, T.uint64(7), T.uint64(8))
redsum = T.call_llvm_intrin("float32xvscalex2", "llvm.riscv.vfredusum", T.Broadcast(T.float32(0.0), T.vscale() * 2), prod, zero, T.uint64(7), T.uint64(8))
# fmt: on

# tvm.error.InternalError: Can't fetch the lanes of a scalable vector at a compile time.
with tvm.target.Target(target):
f = tvm.tir.build(rvv_with_vscale, target)


if __name__ == "__main__":
tvm.testing.main()
Loading