Skip to content

Commit

Permalink
Add a operand type check for Corr2D op and a test
Browse files Browse the repository at this point in the history
  - Make sure that input, kernel, output and constant have the same
    value and use as inferred type
  - Adding a negative lit test to check params of the op
  • Loading branch information
ArtemSkrebkov committed Aug 1, 2022
1 parent 815bfb9 commit 2a25644
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/Conversion/LowerDIP/LowerDIPPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,16 @@ class DIPCorr2DOpLowering : public OpRewritePattern<dip::Corr2DOp> {
auto boundaryOptionAttr = op.boundary_option();
Value strideVal = rewriter.create<ConstantIndexOp>(loc, stride);

auto memRefTy = input.getType().cast<MemRefType>();
auto elemTy = memRefTy.getElementType();
auto inElemTy = input.getType().cast<MemRefType>().getElementType();
auto kElemTy = kernel.getType().cast<MemRefType>().getElementType();
auto outElemTy = output.getType().cast<MemRefType>().getElementType();
auto constElemTy = constantValue.getType();
if (inElemTy != kElemTy || kElemTy != outElemTy || outElemTy != constElemTy) {
return op->emitOpError() << "input, kernel, output and constant must have the same element type";
}
// NB: we can infer element type for all operation to be the same as input
// since we verified that the operand types are the same
auto elemTy = inElemTy;

IntegerType i1 = IntegerType::get(ctx, 1);

Expand All @@ -99,6 +107,7 @@ class DIPCorr2DOpLowering : public OpRewritePattern<dip::Corr2DOp> {
FloatType f32 = FloatType::getF32(ctx);
IntegerType i32 = IntegerType::get(ctx, 32);
Value zeroPaddingElem = {};
// TODO: extend for other types and add a check for supported types
if (elemTy.isF32()) {
zeroPaddingElem = rewriter.create<ConstantFloatOp>(loc, (APFloat)(float)0, f32);
} else if (elemTy.isInteger(32)) {
Expand Down

0 comments on commit 2a25644

Please sign in to comment.