`AffineIf` inside a linalg operations

Hi all,
I am trying to play with affine.if operations inside Linalg. I have a block that in principle looks like:

func.func @linalg_block() {
  affine.for %n0 = 0 to 7 {
     %dim = func.call @linalg.index() : () -> (index)
     affine.if #set1(%dim) {}
  }
  return
}

But this returns the following error:

error: 'affine.if' op operand cannot be used as a dimension id

In the above snippet, if I move the func.call operation outside the loop, everything works fine.

But I don’t have this option in Linalg (I think). So the main questions are:

  • Why the above snippet gives the error?
  • Is there a way to use affine.if ops inside Linalg generic operations?

Thanks,
Giuseppe

I noticed there was a lot of discussion about this here: Should linalg.indexed_generic allow for affine operations on its body? - #16 by bondhugula

I (hopefully) got away by adding an AffineScope as a linalg trait (like @agostini01 suggested in the post).

@nicolasvasilache @bondhugula I see that there is an on-going review that might fix this issue and I was wondering if there were any updates about it.

Thank you so much to all,
Giuseppe

Thanks for raising, I commented with a possible solution to unblock this, let’s see where this goes.

1 Like