Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly handle loop with arbitrary bounds #42

Open
kumasento opened this issue Oct 29, 2020 · 1 comment
Open

Properly handle loop with arbitrary bounds #42

kumasento opened this issue Oct 29, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@kumasento
Copy link
Owner

kumasento commented Oct 29, 2020

It would be pretty common in real-world test cases.

Test code -

func @matmul(%A: memref<?x?xf32>, %B: memref<?x?xf32>, %C: memref<?x?xf32>) {
  %c0 = constant 0 : index
  %c1 = constant 1 : index

  %M = dim %A, %c0 : memref<?x?xf32>
  %N = dim %B, %c0 : memref<?x?xf32>
  %K = dim %A, %c1 : memref<?x?xf32>

  affine.for %i = 0 to %M {
    affine.for %j = 0 to %N {
      affine.for %k = 0 to %K {
        %0 = affine.load %A[%i, %k] : memref<?x?xf32>
        %1 = affine.load %B[%k, %j] : memref<?x?xf32>
        %2 = mulf %0, %1 : f32
        %3 = affine.load %C[%i, %j] : memref<?x?xf32>
        %4 = addf %2, %3 : f32
        affine.store %4, %C[%i, %j] : memref<?x?xf32>
      }
    }
  }

  return 
}

func @main() {
  %M = constant 64 : index
  %N = constant 64 : index
  %K = constant 64 : index

  %A = alloc(%M, %K) : memref<?x?xf32>
  %B = alloc(%N, %K) : memref<?x?xf32>
  %C = alloc(%M, %N) : memref<?x?xf32>

  call @matmul(%A, %B, %C)
   : (memref<?x?xf32>, memref<?x?xf32>, memref<?x?xf32>) -> ()

  return
}
@kumasento
Copy link
Owner Author

Will be merged from the impact branch pretty soon, but the key idea is: we will recreate those dim operations in the new piece of code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant