Skip to content

Commit d4ee6ba

Browse files
authored
Fix some type conversion warnings on MSVC. (#4009)
``` [build] D:\dev\projects\iree\third_party\torch-mlir\lib\Conversion\TorchToTosa\TorchToTosa.cpp(3498): warning C4305: 'argument': truncation from 'double' to 'const T' [build] with [build] [ [build] T=float [build] ] [build] D:\dev\projects\iree\third_party\torch-mlir\lib\Conversion\TorchToTosa\TorchToTosa.cpp(3504): warning C4305: 'argument': truncation from 'double' to 'const T' [build] with [build] [ [build] T=float [build] ] ``` (Not sure why the half/one/three lines were warning free, might as well fix them too.
1 parent a4f5beb commit d4ee6ba

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/Conversion/TorchToTosa/TorchToTosa.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3447,29 +3447,32 @@ LogicalResult ConvertAtenOp<AtenGeluOp>::matchAndRewrite(
34473447
std::multiplies<int64_t>());
34483448

34493449
Value half = tosa::getConstTensor<float>(rewriter, op,
3450-
SmallVector<float>(numElem, 0.5),
3450+
SmallVector<float>(numElem, 0.5f),
34513451
selfShape, selfElemTy)
34523452
.value();
34533453
Value one = tosa::getConstTensor<float>(rewriter, op,
3454-
SmallVector<float>(numElem, 1.0),
3454+
SmallVector<float>(numElem, 1.0f),
34553455
selfShape, selfElemTy)
34563456
.value();
34573457
Value three = tosa::getConstTensor<float>(rewriter, op,
3458-
SmallVector<float>(numElem, 3.0),
3458+
SmallVector<float>(numElem, 3.0f),
34593459
selfShape, selfElemTy)
34603460
.value();
34613461

34623462
// 0.044715
3463-
Value magicNumber = tosa::getConstTensor<float>(
3464-
rewriter, op, SmallVector<float>(numElem, 0.044715),
3465-
selfShape, selfElemTy)
3466-
.value();
3463+
Value magicNumber =
3464+
tosa::getConstTensor<float>(rewriter, op,
3465+
SmallVector<float>(numElem, 0.044715f),
3466+
selfShape, selfElemTy)
3467+
.value();
34673468

34683469
// From <cmath> header: M_2_PI = 2 / pi
3469-
Value twoOverPi = tosa::getConstTensor<float>(
3470-
rewriter, op, SmallVector<float>(numElem, M_2_PI),
3471-
selfShape, selfElemTy)
3472-
.value();
3470+
Value twoOverPi =
3471+
tosa::getConstTensor<float>(
3472+
rewriter, op,
3473+
SmallVector<float>(numElem, static_cast<float>(M_2_PI)), selfShape,
3474+
selfElemTy)
3475+
.value();
34733476

34743477
// 0.5 * x
34753478
auto halfInput = rewriter.create<tosa::MulOp>(op->getLoc(), resultType,

0 commit comments

Comments
 (0)