Skip to content

Handle memref.copy/subview ops & Add compiler pass pipeline#266

Merged
ShangkunLi merged 4 commits intocoredac:mainfrom
ShangkunLi:compiler-pass
Feb 10, 2026
Merged

Handle memref.copy/subview ops & Add compiler pass pipeline#266
ShangkunLi merged 4 commits intocoredac:mainfrom
ShangkunLi:compiler-pass

Conversation

@ShangkunLi
Copy link
Collaborator

@ShangkunLi ShangkunLi commented Feb 9, 2026

In this pr:

  1. Add two passes to handle the memref.copy and memref.subview ops
    For memref.subview ops, we transform such ops into affine.load/store directly, like:
// With memref.subview op
func.func @example(%arg0: memref<10x20xf32>) {
  %subview = memref.subview %arg0[2, 3][4, 5][1, 1] 
      : memref<10x20xf32> to memref<4x5xf32, strided<[20, 1], offset: 43>>
  
  affine.for %i = 0 to 4 {
    affine.for %j = 0 to 5 {
      %val = affine.load %subview[%i, %j] : memref<4x5xf32, strided<[20, 1], offset: 43>>
      // use %val
    }
  }
  return
}

// memref.subview folded
func.func @example(%arg0: memref<10x20xf32>) {
  affine.for %i = 0 to 4 {
    affine.for %j = 0 to 5 {
      // Index adjustment: [%i, %j] + offset [2, 3] = [%i+2, %j+3]
      %val = affine.load %arg0[%i + 2, %j + 3] : memref<10x20xf32>
      // use %val
    }
  }
  return
}

For memref.copy ops, we transform it to affine.for with affine.load/store, like:

// With memref.copy
func.func @copy_example(%src: memref<8x8xf32>, %dst: memref<8x8xf32>) {
  memref.copy %src, %dst : memref<8x8xf32> to memref<8x8xf32>
  return
}

// After transformation
func.func @copy_example(%src: memref<8x8xf32>, %dst: memref<8x8xf32>) {
  affine.for %i = 0 to 8 {
    affine.for %j = 0 to 8 {
      %val = affine.load %src[%i, %j] : memref<8x8xf32>
      affine.store %val, %dst[%i, %j] : memref<8x8xf32>
    }
  }
  return
}
  1. Add two compiler pass pipeline:
  • --tosa-to-affine-conversion: lowers from tosa dialect to affine dialect
  • --taskflow-conversion: converts affine dialects to taskflow.task + neura.kernel

@ShangkunLi ShangkunLi linked an issue Feb 9, 2026 that may be closed by this pull request
@tancheng
Copy link
Contributor

tancheng commented Feb 9, 2026

Plz elaborate on "handle the memref.copy and memref.subview ops". How are they handled?

--taskflow-conversion: converts affine dialects to taskflow.task + neura.kernel

I thought at least two passes/stages needed for affine -> taskflow -> neura, why single pass can perform this?

@ShangkunLi
Copy link
Collaborator Author

ShangkunLi commented Feb 10, 2026

Plz elaborate on "handle the memref.copy and memref.subview ops". How are they handled?

--taskflow-conversion: converts affine dialects to taskflow.task + neura.kernel

I thought at least two passes/stages needed for affine -> taskflow -> neura, why single pass can perform this?

I have updated the description of how we handle memref.copy and memref.subview in the pr summary.

As for --taskflow-conversion, it is a pass pipeline that integrates the following 4 passes:

// This pass pipeline can convert affine dialect into taskflow dialect with neura.kernel op.
void mlir::taskflow::registerTaskflowConversionPassPipeline() {
  PassPipelineRegistration<>(
      "taskflow-conversion",
      "Converts affine dialects to taskflow dialect with neura.kernel ops.",
      [](OpPassManager &pm) {
        pm.addPass(mlir::createConvertAffineToTaskflowPass());
        pm.addPass(mlir::taskflow::createConstructHyperblockFromTaskPass());
        pm.addPass(mlir::taskflow::createClassifyCountersPass());
        pm.addPass(mlir::createConvertTaskflowToNeuraPass());
      });
}

@tancheng
Copy link
Contributor

affine.load/store will later be lowered to what?

@ShangkunLi
Copy link
Collaborator Author

affine.load/store will later be lowered to what?

They will be handled by the neura lowering process. They can be either lowered to neura.load_index/stroe_idnex, or lowered to llvm.gep + llvm.load/store.

@ShangkunLi ShangkunLi merged commit 1ac92f7 into coredac:main Feb 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1] Integrating Taskflow-related Passes into the Compiler

2 participants

Comments