Skip to content
Merged
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions lib/Conversion/TorchToTosa/TosaLegalizeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,16 @@ std::optional<Value> tosaCastTensorToType(PatternRewriter &rewriter, Value src,
// if (failed(checkValidityOfCast(srcElemTy, destElemTy)))
// return std::nullopt;

// Check if the source and destination types are boolean or floating-point
if ((srcElemTy.isInteger(1) && llvm::isa<FloatType>(destElemTy)) ||
(llvm::isa<FloatType>(srcElemTy) && destElemTy.isInteger(1))) {
// TOSA does not support casting between float<->i8.
// Instead, we cast to i8 and then to the destination type.
TensorType midType = srcType.clone(rewriter.getIntegerType(8));
Value mid = rewriter.create<tosa::CastOp>(op->getLoc(), midType, src);
return tosaCastTensorToType(rewriter, mid, destType); // recurse once
}

if (srcElemTy == destElemTy)
return src;

Expand Down