tensorflow / mlir

"Multi-Level Intermediate Representation" Compiler Infrastructure
1.73k stars 257 forks source link

No transformation / debug output from -affine-vectorize #242

Open bondhugula opened 4 years ago

bondhugula commented 4 years ago

I notice that for this simple loop nest, -affine-vectorize does nothing, and emits nothing with its -debug-only= option either. I didn't dig any deeper, but at least the second part is an issue. (It probably only tries innermost loop vectorization, but that should be clarified on the top-level comment on Vectorize.cpp.)

$ cat foo.mlir

func @vec(%arg0: memref<1024x1024xf32>, %arg1: memref<1024x1024xf32>, %arg2: memref<1024x1024xf32>) {
  affine.for %i = 0 to 1024 {
    affine.for %j = 0 to 1024 {
      affine.for %k = 0 to 1024 {
        %5 = affine.load %arg0[%i, %k] : memref<1024x1024xf32>
        %6 = affine.load %arg1[%k, %j] : memref<1024x1024xf32>
        %7 = affine.load %arg2[%i, %j] : memref<1024x1024xf32>
        %8 = mulf %5, %6 : f32
        %9 = addf %7, %8 : f32
        affine.store %9, %arg2[%i, %j] : memref<1024x1024xf32>
      }
    }
  }
  return
}

Same output with

$ mlir-opt -affine-vectorize -debug-only=early-vect /tmp/vec.mlir

On a minor note, s/early-vect/affine-vectorize - early-vect is really not meaningful here.

bondhugula commented 4 years ago

The issue here is that that the cl flag(s) involved (clVirtualVectorSize) don't have a default value/initialization, nor are they mandatory; as a result, nothing happens by default silently.